commit
0fb4f73ac6
@ -6,7 +6,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'me.skymc'
|
||||
version = '5.16'
|
||||
version = '5.17'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
|
@ -10,7 +10,7 @@ import java.util.Arrays;
|
||||
*/
|
||||
public enum Version {
|
||||
|
||||
v1_7(10700), v1_8(10800), v1_9(10900), v1_10(11000), v1_11(11100), v1_12(11200), v1_13(11300), v1_14(11400), v1_15(11500), vNull(0);
|
||||
v1_7(10700), v1_8(10800), v1_9(10900), v1_10(11000), v1_11(11100), v1_12(11200), v1_13(11300), v1_14(11400), v1_15(11500), v1_16(11600), vNull(0);
|
||||
|
||||
private int versionInt;
|
||||
|
||||
|
@ -18,8 +18,8 @@ import java.util.UUID;
|
||||
*/
|
||||
public class CommandBuilder {
|
||||
|
||||
public static final CompleterTab EMPTY_COMPLETER_TAB = ((sender, args) -> new ArrayList<>());
|
||||
public static final CompleterCommand EMPTY_COMPLETER_COMMAND = ((sender, args) -> {});
|
||||
public static final CompleterCommand EMPTY_COMPLETER_COMMAND = ((sender, args) -> {
|
||||
});
|
||||
|
||||
private String command;
|
||||
private Plugin plugin;
|
||||
@ -28,7 +28,7 @@ public class CommandBuilder {
|
||||
private List<String> aliases;
|
||||
private String permission;
|
||||
private String permissionMessage;
|
||||
private CompleterTab completerTab = EMPTY_COMPLETER_TAB;
|
||||
private CompleterTab completerTab;
|
||||
private CompleterCommand completerCommand = EMPTY_COMPLETER_COMMAND;
|
||||
private boolean forceRegister;
|
||||
private boolean build;
|
||||
@ -106,7 +106,6 @@ public class CommandBuilder {
|
||||
Preconditions.checkNotNull(plugin, "缺少 \"plugin\" 部分");
|
||||
Preconditions.checkNotNull(command, "缺少 \"command\" 部分");
|
||||
Preconditions.checkNotNull(completerCommand, "缺少 \"CompleterCommand\" 部分");
|
||||
Preconditions.checkNotNull(completerTab, "缺少 \"CompleterTab\" 部分");
|
||||
if (forceRegister) {
|
||||
TCommandHandler.getKnownCommands().remove(command);
|
||||
}
|
||||
@ -118,18 +117,20 @@ public class CommandBuilder {
|
||||
aliases,
|
||||
permission,
|
||||
permissionMessage,
|
||||
(sender, command, s, args) -> {
|
||||
completerCommand.execute(sender, args);
|
||||
return true;
|
||||
},
|
||||
(sender, command, s, args) -> {
|
||||
try {
|
||||
return completerTab.execute(sender, args);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
});
|
||||
completerCommand == null ? null :
|
||||
(sender, command, s, args) -> {
|
||||
completerCommand.execute(sender, args);
|
||||
return true;
|
||||
},
|
||||
completerTab == null ? null :
|
||||
(sender, command, s, args) -> {
|
||||
try {
|
||||
return completerTab.execute(sender, args);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
});
|
||||
build = true;
|
||||
return this;
|
||||
}
|
||||
|
@ -7,11 +7,14 @@ import io.izzel.taboolib.module.nms.nbt.Attribute;
|
||||
import io.izzel.taboolib.module.nms.nbt.NBTAttribute;
|
||||
import io.izzel.taboolib.module.nms.nbt.NBTCompound;
|
||||
import io.izzel.taboolib.module.nms.nbt.NBTList;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
@ -78,4 +81,8 @@ public abstract class NMS {
|
||||
abstract public Position fromBlockPosition(Object blockPosition);
|
||||
|
||||
abstract public void openSignEditor(Player player, Block block);
|
||||
|
||||
abstract public boolean inBoundingBox(Entity entity, Vector vector);
|
||||
|
||||
abstract public Location getLastLocation(ProjectileHitEvent event);
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import net.minecraft.server.v1_13_R2.IRegistry;
|
||||
import net.minecraft.server.v1_8_R3.NBTBase;
|
||||
import net.minecraft.server.v1_8_R3.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
@ -28,8 +29,10 @@ import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
@ -404,4 +407,43 @@ public class NMSImpl extends NMS {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inBoundingBox(Entity entity, Vector vector) {
|
||||
if (Version.isAfter(Version.v1_14)) {
|
||||
return ((org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity) entity).getHandle().getBoundingBox().c(new net.minecraft.server.v1_14_R1.Vec3D(vector.getX(), vector.getY(), vector.getZ()));
|
||||
} else {
|
||||
return ((org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity) entity).getHandle().getBoundingBox().b(new net.minecraft.server.v1_12_R1.Vec3D(vector.getX(), vector.getY(), vector.getZ()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLastLocation(ProjectileHitEvent event) {
|
||||
Vector vector = event.getEntity().getVelocity().normalize().multiply(0.1);
|
||||
Vector vectorEntity = event.getEntity().getLocation().toVector();
|
||||
if (event.getHitBlock() != null) {
|
||||
double i = 0;
|
||||
double length = event.getHitBlock().getLocation().add(0.5, 0.5, 0.5).distance(event.getEntity().getLocation()) * 2;
|
||||
while (i < length) {
|
||||
Location location = vectorEntity.toLocation(event.getHitBlock().getWorld());
|
||||
if (location.getBlock().getLocation().equals(event.getHitBlock().getLocation())) {
|
||||
return location;
|
||||
}
|
||||
vectorEntity.add(vector);
|
||||
i += 0.1;
|
||||
}
|
||||
}
|
||||
if (event.getHitEntity() != null) {
|
||||
double i = 0;
|
||||
double length = event.getHitEntity().getLocation().distance(event.getEntity().getLocation()) * 2;
|
||||
while (i < length) {
|
||||
if (inBoundingBox(event.getHitEntity(), vectorEntity)) {
|
||||
return vectorEntity.toLocation(event.getHitEntity().getWorld());
|
||||
}
|
||||
vectorEntity.add(vector);
|
||||
i += 0.1;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -319,6 +319,15 @@ public class Files {
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeAppend(File file, WriteHandle writeHandle) {
|
||||
try (FileWriter fileWriter = new FileWriter(file, true); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter)) {
|
||||
writeHandle.write(bufferedWriter);
|
||||
bufferedWriter.flush();
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void write(OutputStream out, WriteHandle writeHandle) {
|
||||
try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(out); BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter)) {
|
||||
writeHandle.write(bufferedWriter);
|
||||
|
@ -10,11 +10,13 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.util.NumberConversions;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* @Author sky
|
||||
@ -81,6 +83,28 @@ public class Effects {
|
||||
return Particle.FLAME;
|
||||
}
|
||||
|
||||
public static void buildLine(Location locA, Location locB, Consumer<Location> action) {
|
||||
buildLine(locA, locB, action, 0.25);
|
||||
}
|
||||
|
||||
public static void buildLine(Location locA, Location locB, Consumer<Location> action, double interval) {
|
||||
Vector vectorAB = locB.clone().subtract(locA).toVector();
|
||||
double vectorLength = vectorAB.length();
|
||||
vectorAB.normalize();
|
||||
for (double i = 0; i < vectorLength; i += interval) {
|
||||
action.accept(locA.clone().add(vectorAB.clone().multiply(i)));
|
||||
}
|
||||
}
|
||||
|
||||
public static void buildPolygon(Location center, double range, double interval, Consumer<Location> action) {
|
||||
for (double i = 0; i < 360; i += (360 / interval)) {
|
||||
double radians = Math.toRadians(i);
|
||||
double cos = Math.cos(radians) * range;
|
||||
double sin = Math.sin(radians) * range;
|
||||
action.accept(center.clone().add(cos, 0, sin));
|
||||
}
|
||||
}
|
||||
|
||||
Effects() {
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user