code reformat
This commit is contained in:
@@ -31,6 +31,14 @@ public class TerminatorPlus extends JavaPlugin {
|
||||
return version;
|
||||
}
|
||||
|
||||
public static boolean isCorrectVersion() {
|
||||
return correctVersion;
|
||||
}
|
||||
|
||||
public static String getMcVersion() {
|
||||
return mcVersion;
|
||||
}
|
||||
|
||||
public BotManagerImpl getManager() {
|
||||
return manager;
|
||||
}
|
||||
@@ -81,12 +89,4 @@ public class TerminatorPlus extends JavaPlugin {
|
||||
private void registerEvents(Listener... listeners) {
|
||||
Arrays.stream(listeners).forEach(li -> this.getServer().getPluginManager().registerEvents(li, this));
|
||||
}
|
||||
|
||||
public static boolean isCorrectVersion() {
|
||||
return correctVersion;
|
||||
}
|
||||
|
||||
public static String getMcVersion() {
|
||||
return mcVersion;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,11 @@ package net.nuggetmc.tplus.bot;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.PacketSendListener;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
import net.minecraft.network.protocol.game.*;
|
||||
import net.minecraft.network.syncher.SynchedEntityData;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
@@ -52,7 +50,6 @@ import org.bukkit.util.BoundingBox;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
|
||||
public class Bot extends ServerPlayer implements Terminator {
|
||||
@@ -128,9 +125,9 @@ public class Bot extends ServerPlayer implements Terminator {
|
||||
Bukkit.getOnlinePlayers().forEach(p -> ((CraftPlayer) p).getHandle().connection.send(
|
||||
new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER, bot)));
|
||||
if (addPlayerList)
|
||||
nmsWorld.addNewPlayer(bot);
|
||||
nmsWorld.addNewPlayer(bot);
|
||||
else
|
||||
nmsWorld.addFreshEntity(bot);
|
||||
nmsWorld.addFreshEntity(bot);
|
||||
bot.renderAll();
|
||||
|
||||
TerminatorPlus.getInstance().getManager().add(bot);
|
||||
@@ -259,7 +256,7 @@ public class Bot extends ServerPlayer implements Terminator {
|
||||
|
||||
@Override
|
||||
public int getNoFallTicks() {
|
||||
return noFallTicks;
|
||||
return noFallTicks;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -382,19 +379,19 @@ public class Bot extends ServerPlayer implements Terminator {
|
||||
box.maxZ - 0.01
|
||||
};
|
||||
BoundingBox playerBox = new BoundingBox(box.minX, position().y - 0.01, box.minZ,
|
||||
box.maxX, position().y + getBbHeight(), box.maxZ);
|
||||
for (double x : xVals) {
|
||||
box.maxX, position().y + getBbHeight(), box.maxZ);
|
||||
for (double x : xVals) {
|
||||
for (double z : zVals) {
|
||||
Location loc = new Location(getBukkitEntity().getWorld(), Math.floor(x), getLocation().getY(), Math.floor(z));
|
||||
Block block = loc.getBlock();
|
||||
if (block.getBlockData() instanceof Waterlogged wl && wl.isWaterlogged())
|
||||
return true;
|
||||
if (BotUtils.NO_FALL.contains(loc.getBlock().getType()) && (BotUtils.overlaps(playerBox, loc.getBlock().getBoundingBox())
|
||||
|| loc.getBlock().getType() == Material.WATER || loc.getBlock().getType() == Material.LAVA))
|
||||
return true;
|
||||
Location loc = new Location(getBukkitEntity().getWorld(), Math.floor(x), getLocation().getY(), Math.floor(z));
|
||||
Block block = loc.getBlock();
|
||||
if (block.getBlockData() instanceof Waterlogged wl && wl.isWaterlogged())
|
||||
return true;
|
||||
if (BotUtils.NO_FALL.contains(loc.getBlock().getType()) && (BotUtils.overlaps(playerBox, loc.getBlock().getBoundingBox())
|
||||
|| loc.getBlock().getType() == Material.WATER || loc.getBlock().getType() == Material.LAVA))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -528,7 +525,7 @@ public class Bot extends ServerPlayer implements Terminator {
|
||||
}
|
||||
|
||||
public boolean checkStandingOn() {
|
||||
World world = getBukkitEntity().getWorld();
|
||||
World world = getBukkitEntity().getWorld();
|
||||
AABB box = getBoundingBox();
|
||||
|
||||
double[] xVals = new double[]{
|
||||
@@ -541,7 +538,7 @@ public class Bot extends ServerPlayer implements Terminator {
|
||||
box.maxZ
|
||||
};
|
||||
BoundingBox playerBox = new BoundingBox(box.minX, position().y - 0.01, box.minZ,
|
||||
box.maxX, position().y + getBbHeight(), box.maxZ);
|
||||
box.maxX, position().y + getBbHeight(), box.maxZ);
|
||||
List<Block> standingOn = new ArrayList<>();
|
||||
List<Location> locations = new ArrayList<>();
|
||||
|
||||
@@ -551,10 +548,10 @@ public class Bot extends ServerPlayer implements Terminator {
|
||||
Block block = world.getBlockAt(loc);
|
||||
|
||||
if ((block.getType().isSolid() || LegacyMats.canStandOn(block.getType())) && BotUtils.overlaps(playerBox, block.getBoundingBox())) {
|
||||
if (!locations.contains(block.getLocation())) {
|
||||
standingOn.add(block);
|
||||
locations.add(block.getLocation());
|
||||
}
|
||||
if (!locations.contains(block.getLocation())) {
|
||||
standingOn.add(block);
|
||||
locations.add(block.getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -566,21 +563,21 @@ public class Bot extends ServerPlayer implements Terminator {
|
||||
Block block = world.getBlockAt(loc);
|
||||
BoundingBox blockBox = loc.getBlock().getBoundingBox();
|
||||
BoundingBox modifiedBox = new BoundingBox(blockBox.getMinX(), blockBox.getMinY(), blockBox.getMinZ(), blockBox.getMaxX(),
|
||||
blockBox.getMinY() + 1.5, blockBox.getMaxZ());
|
||||
blockBox.getMinY() + 1.5, blockBox.getMaxZ());
|
||||
|
||||
if ((LegacyMats.FENCE.contains(block.getType()) || LegacyMats.GATES.contains(block.getType()))
|
||||
&& block.getType().isSolid() && BotUtils.overlaps(playerBox, modifiedBox)) {
|
||||
if (!locations.contains(block.getLocation())) {
|
||||
standingOn.add(block);
|
||||
locations.add(block.getLocation());
|
||||
}
|
||||
&& block.getType().isSolid() && BotUtils.overlaps(playerBox, modifiedBox)) {
|
||||
if (!locations.contains(block.getLocation())) {
|
||||
standingOn.add(block);
|
||||
locations.add(block.getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Closest block comes first
|
||||
Collections.sort(standingOn, (a, b) ->
|
||||
Double.compare(BotUtils.getHorizSqDist(a.getLocation(), getLocation()), BotUtils.getHorizSqDist(b.getLocation(), getLocation())));
|
||||
Double.compare(BotUtils.getHorizSqDist(a.getLocation(), getLocation()), BotUtils.getHorizSqDist(b.getLocation(), getLocation())));
|
||||
|
||||
this.standingOn = standingOn;
|
||||
return !standingOn.isEmpty();
|
||||
@@ -588,7 +585,7 @@ public class Bot extends ServerPlayer implements Terminator {
|
||||
|
||||
@Override
|
||||
public List<Block> getStandingOn() {
|
||||
return standingOn;
|
||||
return standingOn;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -622,7 +619,7 @@ public class Bot extends ServerPlayer implements Terminator {
|
||||
}
|
||||
this.removeVisually();
|
||||
if (inPlayerList)
|
||||
this.server.getPlayerList().getPlayers().remove(this);
|
||||
this.server.getPlayerList().getPlayers().remove(this);
|
||||
}
|
||||
|
||||
private void removeTab() {
|
||||
@@ -893,11 +890,11 @@ public class Bot extends ServerPlayer implements Terminator {
|
||||
|
||||
@Override
|
||||
public boolean isInPlayerList() {
|
||||
return inPlayerList;
|
||||
return inPlayerList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public World.Environment getDimension() {
|
||||
return getBukkitEntity().getWorld().getEnvironment();
|
||||
return getBukkitEntity().getWorld().getEnvironment();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,9 +41,9 @@ public class CommandHandler {
|
||||
|
||||
private void registerCommands() {
|
||||
registerCommands(
|
||||
new MainCommand(this, "terminatorplus", "The TerminatorPlus main command.", "tplus"),
|
||||
new BotCommand(this, "bot", "The root command for bot management.", "npc"),
|
||||
new AICommand(this, "ai", "The root command for bot AI training.")
|
||||
new MainCommand(this, "terminatorplus", "The TerminatorPlus main command.", "tplus"),
|
||||
new BotCommand(this, "bot", "The root command for bot management.", "npc"),
|
||||
new AICommand(this, "ai", "The root command for bot AI training.")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,13 +24,11 @@ import java.util.stream.Collectors;
|
||||
|
||||
public abstract class CommandInstance extends BukkitCommand {
|
||||
|
||||
private static final String MANAGE_PERMISSION = "terminatorplus.manage";
|
||||
protected final CommandHandler commandHandler;
|
||||
|
||||
private final Map<String, CommandMethod> methods;
|
||||
private final Map<String, String> aliasesToNames;
|
||||
|
||||
private static final String MANAGE_PERMISSION = "terminatorplus.manage";
|
||||
|
||||
public CommandInstance(CommandHandler handler, String name, String description, @Nullable String... aliases) {
|
||||
super(name, description, "", aliases == null ? new ArrayList<>() : Arrays.asList(aliases));
|
||||
|
||||
@@ -39,6 +37,24 @@ public abstract class CommandInstance extends BukkitCommand {
|
||||
this.aliasesToNames = new HashMap<>();
|
||||
}
|
||||
|
||||
public static String getArgumentName(Parameter parameter) {
|
||||
if (parameter.isAnnotationPresent(OptArg.class)) {
|
||||
OptArg arg = parameter.getAnnotation(OptArg.class);
|
||||
|
||||
if (!arg.value().isEmpty()) {
|
||||
return "[" + ChatUtils.camelToDashed(arg.value()) + "]";
|
||||
}
|
||||
} else if (parameter.isAnnotationPresent(Arg.class)) {
|
||||
Arg arg = parameter.getAnnotation(Arg.class);
|
||||
|
||||
if (!arg.value().isEmpty()) {
|
||||
return "<" + ChatUtils.camelToDashed(arg.value()) + ">";
|
||||
}
|
||||
}
|
||||
|
||||
return "<" + ChatUtils.camelToDashed(parameter.getName()) + ">";
|
||||
}
|
||||
|
||||
public Map<String, CommandMethod> getMethods() {
|
||||
return methods;
|
||||
}
|
||||
@@ -46,9 +62,9 @@ public abstract class CommandInstance extends BukkitCommand {
|
||||
protected void addMethod(String name, CommandMethod method) {
|
||||
methods.put(name, method);
|
||||
}
|
||||
|
||||
|
||||
protected void addAlias(String alias, String name) {
|
||||
aliasesToNames.put(alias, name);
|
||||
aliasesToNames.put(alias, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,9 +120,7 @@ public abstract class CommandInstance extends BukkitCommand {
|
||||
parsedArguments.add(sender);
|
||||
} else if (type == List.class) {
|
||||
parsedArguments.add(arguments);
|
||||
}
|
||||
|
||||
else {
|
||||
} else {
|
||||
if (parameter.isAnnotationPresent(TextArg.class)) {
|
||||
if (index >= arguments.size()) {
|
||||
parsedArguments.add("");
|
||||
@@ -182,27 +196,21 @@ public abstract class CommandInstance extends BukkitCommand {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch (NonPlayerException e) {
|
||||
} catch (NonPlayerException e) {
|
||||
sender.sendMessage("This is a player-only command.");
|
||||
return true;
|
||||
}
|
||||
|
||||
catch (ArgParseException e) {
|
||||
} catch (ArgParseException e) {
|
||||
Parameter parameter = e.getParameter();
|
||||
String name = getArgumentName(parameter);
|
||||
sender.sendMessage("The parameter " + ChatColor.YELLOW + name + ChatColor.RESET + " must be of type " + ChatColor.YELLOW + parameter.getType().toString() + ChatColor.RESET + ".");
|
||||
return true;
|
||||
}
|
||||
|
||||
catch (ArgCountException e) {
|
||||
} catch (ArgCountException e) {
|
||||
List<String> usageArgs = new ArrayList<>();
|
||||
|
||||
Arrays.stream(method.getMethod().getParameters()).forEach(parameter -> {
|
||||
Class<?> type = parameter.getType();
|
||||
|
||||
if (type != CommandSender.class && type != Player.class){
|
||||
if (type != CommandSender.class && type != Player.class) {
|
||||
usageArgs.add(getArgumentName(parameter));
|
||||
}
|
||||
});
|
||||
@@ -222,24 +230,6 @@ public abstract class CommandInstance extends BukkitCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String getArgumentName(Parameter parameter) {
|
||||
if (parameter.isAnnotationPresent(OptArg.class)) {
|
||||
OptArg arg = parameter.getAnnotation(OptArg.class);
|
||||
|
||||
if (!arg.value().isEmpty()) {
|
||||
return "[" + ChatUtils.camelToDashed(arg.value()) + "]";
|
||||
}
|
||||
} else if (parameter.isAnnotationPresent(Arg.class)) {
|
||||
Arg arg = parameter.getAnnotation(Arg.class);
|
||||
|
||||
if (!arg.value().isEmpty()) {
|
||||
return "<" + ChatUtils.camelToDashed(arg.value()) + ">";
|
||||
}
|
||||
}
|
||||
|
||||
return "<" + ChatUtils.camelToDashed(parameter.getName()) + ">";
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -291,16 +291,16 @@ public class BotCommand extends CommandInstance {
|
||||
}
|
||||
)
|
||||
public void count(CommandSender sender) {
|
||||
List<String> names = manager.fetchNames();
|
||||
Map<String, Integer> freqMap = names.stream().collect(Collectors.toMap(s -> s, s -> 1, Integer::sum));
|
||||
List<Entry<String, Integer>> entries = freqMap.entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(Collectors.toList());
|
||||
List<String> names = manager.fetchNames();
|
||||
Map<String, Integer> freqMap = names.stream().collect(Collectors.toMap(s -> s, s -> 1, Integer::sum));
|
||||
List<Entry<String, Integer>> entries = freqMap.entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(Collectors.toList());
|
||||
|
||||
sender.sendMessage(ChatUtils.LINE);
|
||||
entries.forEach(en -> sender.sendMessage(ChatColor.GREEN + en.getKey()
|
||||
+ ChatColor.RESET + " - " + ChatColor.BLUE + en.getValue().toString() + ChatColor.RESET));
|
||||
sender.sendMessage("Total bots: " + ChatColor.BLUE + freqMap.values().stream().reduce(0, Integer::sum) + ChatColor.RESET);
|
||||
sender.sendMessage(ChatUtils.LINE);
|
||||
entries.forEach(en -> sender.sendMessage(ChatColor.GREEN + en.getKey()
|
||||
+ ChatColor.RESET + " - " + ChatColor.BLUE + en.getValue().toString() + ChatColor.RESET));
|
||||
sender.sendMessage("Total bots: " + ChatColor.BLUE + freqMap.values().stream().reduce(0, Integer::sum) + ChatColor.RESET);
|
||||
sender.sendMessage(ChatUtils.LINE);
|
||||
}
|
||||
|
||||
@Command(
|
||||
@@ -339,7 +339,7 @@ public class BotCommand extends CommandInstance {
|
||||
String extra = ChatColor.GRAY + " [" + ChatColor.YELLOW + "/bot settings" + ChatColor.GRAY + "]";
|
||||
|
||||
if (arg1 == null || (!arg1.equalsIgnoreCase("setgoal") && !arg1.equalsIgnoreCase("mobtarget") && !arg1.equalsIgnoreCase("playertarget")
|
||||
&& !arg1.equalsIgnoreCase("addplayerlist") && !arg1.equalsIgnoreCase("region"))) {
|
||||
&& !arg1.equalsIgnoreCase("addplayerlist") && !arg1.equalsIgnoreCase("region"))) {
|
||||
sender.sendMessage(ChatUtils.LINE);
|
||||
sender.sendMessage(ChatColor.GOLD + "Bot Settings" + extra);
|
||||
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "setgoal" + ChatUtils.BULLET_FORMATTED + "Set the global bot target selection method.");
|
||||
@@ -349,13 +349,12 @@ public class BotCommand extends CommandInstance {
|
||||
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "region" + ChatUtils.BULLET_FORMATTED + "Sets a region for the bots to prioritize entities inside.");
|
||||
sender.sendMessage(ChatUtils.LINE);
|
||||
return;
|
||||
}
|
||||
else if (arg1.equalsIgnoreCase("setgoal")) {
|
||||
if (arg2 == null) {
|
||||
sender.sendMessage("The global bot goal is currently " + ChatColor.BLUE + agent.getTargetType() + ChatColor.RESET + ".");
|
||||
return;
|
||||
}
|
||||
EnumTargetGoal goal = EnumTargetGoal.from(arg2);
|
||||
} else if (arg1.equalsIgnoreCase("setgoal")) {
|
||||
if (arg2 == null) {
|
||||
sender.sendMessage("The global bot goal is currently " + ChatColor.BLUE + agent.getTargetType() + ChatColor.RESET + ".");
|
||||
return;
|
||||
}
|
||||
EnumTargetGoal goal = EnumTargetGoal.from(arg2);
|
||||
|
||||
if (goal == null) {
|
||||
sender.sendMessage(ChatUtils.LINE);
|
||||
@@ -368,18 +367,18 @@ public class BotCommand extends CommandInstance {
|
||||
agent.setTargetType(goal);
|
||||
sender.sendMessage("The global bot goal has been set to " + ChatColor.BLUE + goal.name() + ChatColor.RESET + ".");
|
||||
} else if (arg1.equalsIgnoreCase("mobtarget")) {
|
||||
if (arg2 == null) {
|
||||
sender.sendMessage("Mob targeting is currently " + (manager.isMobTarget() ? ChatColor.GREEN + "enabled" : ChatColor.RED + "disabled") + ChatColor.RESET + ".");
|
||||
return;
|
||||
}
|
||||
if (!arg2.equals("true") && !arg2.equals("false")) {
|
||||
sender.sendMessage(ChatColor.RED + "You must specify true or false!");
|
||||
return;
|
||||
}
|
||||
manager.setMobTarget(Boolean.parseBoolean(arg2));
|
||||
sender.sendMessage("Mob targeting is now " + (manager.isMobTarget() ? ChatColor.GREEN + "enabled" : ChatColor.RED + "disabled") + ChatColor.RESET + ".");
|
||||
if (arg2 == null) {
|
||||
sender.sendMessage("Mob targeting is currently " + (manager.isMobTarget() ? ChatColor.GREEN + "enabled" : ChatColor.RED + "disabled") + ChatColor.RESET + ".");
|
||||
return;
|
||||
}
|
||||
if (!arg2.equals("true") && !arg2.equals("false")) {
|
||||
sender.sendMessage(ChatColor.RED + "You must specify true or false!");
|
||||
return;
|
||||
}
|
||||
manager.setMobTarget(Boolean.parseBoolean(arg2));
|
||||
sender.sendMessage("Mob targeting is now " + (manager.isMobTarget() ? ChatColor.GREEN + "enabled" : ChatColor.RED + "disabled") + ChatColor.RESET + ".");
|
||||
} else if (arg1.equalsIgnoreCase("playertarget")) {
|
||||
if (args.size() < 2) {
|
||||
if (args.size() < 2) {
|
||||
sender.sendMessage(ChatColor.RED + "You must specify a player name!");
|
||||
return;
|
||||
}
|
||||
@@ -394,87 +393,87 @@ public class BotCommand extends CommandInstance {
|
||||
}
|
||||
sender.sendMessage("All spawned bots are now set to target " + ChatColor.BLUE + player.getName() + ChatColor.RESET + ". They will target the closest player if they can't be found.\nYou may need to set the goal to PLAYER.");
|
||||
} else if (arg1.equalsIgnoreCase("addplayerlist")) {
|
||||
if (arg2 == null) {
|
||||
sender.sendMessage("Adding bots to the player list is currently " + (manager.addToPlayerList() ? ChatColor.GREEN + "enabled" : ChatColor.RED + "disabled") + ChatColor.RESET + ".");
|
||||
return;
|
||||
}
|
||||
if (!arg2.equals("true") && !arg2.equals("false")) {
|
||||
sender.sendMessage(ChatColor.RED + "You must specify true or false!");
|
||||
return;
|
||||
}
|
||||
manager.setAddToPlayerList(Boolean.parseBoolean(arg2));
|
||||
sender.sendMessage("Adding bots to the player list is now " + (manager.addToPlayerList() ? ChatColor.GREEN + "enabled" : ChatColor.RED + "disabled") + ChatColor.RESET + ".");
|
||||
if (arg2 == null) {
|
||||
sender.sendMessage("Adding bots to the player list is currently " + (manager.addToPlayerList() ? ChatColor.GREEN + "enabled" : ChatColor.RED + "disabled") + ChatColor.RESET + ".");
|
||||
return;
|
||||
}
|
||||
if (!arg2.equals("true") && !arg2.equals("false")) {
|
||||
sender.sendMessage(ChatColor.RED + "You must specify true or false!");
|
||||
return;
|
||||
}
|
||||
manager.setAddToPlayerList(Boolean.parseBoolean(arg2));
|
||||
sender.sendMessage("Adding bots to the player list is now " + (manager.addToPlayerList() ? ChatColor.GREEN + "enabled" : ChatColor.RED + "disabled") + ChatColor.RESET + ".");
|
||||
} else if (arg1.equalsIgnoreCase("region")) {
|
||||
if (arg2 == null) {
|
||||
if (agent.getRegion() == null) {
|
||||
sender.sendMessage("No region has been set.");
|
||||
return;
|
||||
}
|
||||
sender.sendMessage("The current region is " + ChatColor.BLUE + agent.getRegion() + ChatColor.RESET + ".");
|
||||
if (agent.getRegionWeightX() == 0 && agent.getRegionWeightY() == 0 && agent.getRegionWeightZ() == 0)
|
||||
sender.sendMessage("Entities out of range will not be targeted.");
|
||||
else {
|
||||
sender.sendMessage("The region X weight is " + ChatColor.BLUE + agent.getRegionWeightX() + ChatColor.RESET + ".");
|
||||
sender.sendMessage("The region Y weight is " + ChatColor.BLUE + agent.getRegionWeightY() + ChatColor.RESET + ".");
|
||||
sender.sendMessage("The region Z weight is " + ChatColor.BLUE + agent.getRegionWeightZ() + ChatColor.RESET + ".");
|
||||
}
|
||||
return;
|
||||
if (agent.getRegion() == null) {
|
||||
sender.sendMessage("No region has been set.");
|
||||
return;
|
||||
}
|
||||
sender.sendMessage("The current region is " + ChatColor.BLUE + agent.getRegion() + ChatColor.RESET + ".");
|
||||
if (agent.getRegionWeightX() == 0 && agent.getRegionWeightY() == 0 && agent.getRegionWeightZ() == 0)
|
||||
sender.sendMessage("Entities out of range will not be targeted.");
|
||||
else {
|
||||
sender.sendMessage("The region X weight is " + ChatColor.BLUE + agent.getRegionWeightX() + ChatColor.RESET + ".");
|
||||
sender.sendMessage("The region Y weight is " + ChatColor.BLUE + agent.getRegionWeightY() + ChatColor.RESET + ".");
|
||||
sender.sendMessage("The region Z weight is " + ChatColor.BLUE + agent.getRegionWeightZ() + ChatColor.RESET + ".");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (arg2.equalsIgnoreCase("clear")) {
|
||||
agent.setRegion(null, 0, 0, 0);
|
||||
sender.sendMessage("The region has been cleared.");
|
||||
return;
|
||||
agent.setRegion(null, 0, 0, 0);
|
||||
sender.sendMessage("The region has been cleared.");
|
||||
return;
|
||||
}
|
||||
boolean strict = args.size() == 8 && args.get(7).equalsIgnoreCase("strict");
|
||||
if (args.size() != 10 && !strict) {
|
||||
sender.sendMessage(ChatUtils.LINE);
|
||||
sender.sendMessage(ChatColor.GOLD + "Bot Region Settings" + extra);
|
||||
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "<x1> <y1> <z1> <x2> <y2> <z2> <wX> <wY> <wZ>" + ChatUtils.BULLET_FORMATTED
|
||||
+ "Sets a region for bots to prioritize entities within.");
|
||||
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "<x1> <y1> <z1> <x2> <y2> <z2> strict" + ChatUtils.BULLET_FORMATTED
|
||||
+ "Sets a region so that the bots only target entities within the region.");
|
||||
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "clear" + ChatUtils.BULLET_FORMATTED
|
||||
+ "Clears the region.");
|
||||
sender.sendMessage("Without strict mode, the entity distance from the region is multiplied by the weight values if outside the region.");
|
||||
sender.sendMessage("The resulting value is added to the entity distance when selecting an entity.");
|
||||
sender.sendMessage(ChatUtils.LINE);
|
||||
return;
|
||||
sender.sendMessage(ChatUtils.LINE);
|
||||
sender.sendMessage(ChatColor.GOLD + "Bot Region Settings" + extra);
|
||||
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "<x1> <y1> <z1> <x2> <y2> <z2> <wX> <wY> <wZ>" + ChatUtils.BULLET_FORMATTED
|
||||
+ "Sets a region for bots to prioritize entities within.");
|
||||
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "<x1> <y1> <z1> <x2> <y2> <z2> strict" + ChatUtils.BULLET_FORMATTED
|
||||
+ "Sets a region so that the bots only target entities within the region.");
|
||||
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "clear" + ChatUtils.BULLET_FORMATTED
|
||||
+ "Clears the region.");
|
||||
sender.sendMessage("Without strict mode, the entity distance from the region is multiplied by the weight values if outside the region.");
|
||||
sender.sendMessage("The resulting value is added to the entity distance when selecting an entity.");
|
||||
sender.sendMessage(ChatUtils.LINE);
|
||||
return;
|
||||
}
|
||||
double x1, y1, z1, x2, y2, z2, wX, wY, wZ;
|
||||
try {
|
||||
Location loc = sender instanceof Player pl ? pl.getLocation() : null;
|
||||
x1 = parseDoubleOrRelative(args.get(1), loc, 0);
|
||||
y1 = parseDoubleOrRelative(args.get(2), loc, 1);
|
||||
z1 = parseDoubleOrRelative(args.get(3), loc, 2);
|
||||
x2 = parseDoubleOrRelative(args.get(4), loc, 0);
|
||||
y2 = parseDoubleOrRelative(args.get(5), loc, 1);
|
||||
z2 = parseDoubleOrRelative(args.get(6), loc, 2);
|
||||
if (strict)
|
||||
wX = wY = wZ = 0;
|
||||
else {
|
||||
wX = Double.parseDouble(args.get(7));
|
||||
wY = Double.parseDouble(args.get(8));
|
||||
wZ = Double.parseDouble(args.get(9));
|
||||
if (wX <= 0 || wY <= 0 || wZ <= 0) {
|
||||
sender.sendMessage("The region weights must be positive values!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
Location loc = sender instanceof Player pl ? pl.getLocation() : null;
|
||||
x1 = parseDoubleOrRelative(args.get(1), loc, 0);
|
||||
y1 = parseDoubleOrRelative(args.get(2), loc, 1);
|
||||
z1 = parseDoubleOrRelative(args.get(3), loc, 2);
|
||||
x2 = parseDoubleOrRelative(args.get(4), loc, 0);
|
||||
y2 = parseDoubleOrRelative(args.get(5), loc, 1);
|
||||
z2 = parseDoubleOrRelative(args.get(6), loc, 2);
|
||||
if (strict)
|
||||
wX = wY = wZ = 0;
|
||||
else {
|
||||
wX = Double.parseDouble(args.get(7));
|
||||
wY = Double.parseDouble(args.get(8));
|
||||
wZ = Double.parseDouble(args.get(9));
|
||||
if (wX <= 0 || wY <= 0 || wZ <= 0) {
|
||||
sender.sendMessage("The region weights must be positive values!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage("The region bounds and weights must be valid numbers!");
|
||||
sender.sendMessage("Correct syntax: " + ChatColor.YELLOW + "/bot settings region <x1> <y1> <z1> <x2> <y2> <z2> <wX> <wY> <wZ>"
|
||||
+ ChatColor.RESET);
|
||||
return;
|
||||
sender.sendMessage("The region bounds and weights must be valid numbers!");
|
||||
sender.sendMessage("Correct syntax: " + ChatColor.YELLOW + "/bot settings region <x1> <y1> <z1> <x2> <y2> <z2> <wX> <wY> <wZ>"
|
||||
+ ChatColor.RESET);
|
||||
return;
|
||||
}
|
||||
agent.setRegion(new BoundingBox(x1, y1, z1, x2, y2, z2), wX, wY, wZ);
|
||||
sender.sendMessage("The region has been set to " + ChatColor.BLUE + agent.getRegion() + ChatColor.RESET + ".");
|
||||
if (wX == 0 && wY == 0 && wZ == 0)
|
||||
sender.sendMessage("Entities out of range will not be targeted.");
|
||||
else {
|
||||
sender.sendMessage("The region X weight is " + ChatColor.BLUE + agent.getRegionWeightX() + ChatColor.RESET + ".");
|
||||
sender.sendMessage("The region Y weight is " + ChatColor.BLUE + agent.getRegionWeightY() + ChatColor.RESET + ".");
|
||||
sender.sendMessage("The region Z weight is " + ChatColor.BLUE + agent.getRegionWeightZ() + ChatColor.RESET + ".");
|
||||
}
|
||||
if (wX == 0 && wY == 0 && wZ == 0)
|
||||
sender.sendMessage("Entities out of range will not be targeted.");
|
||||
else {
|
||||
sender.sendMessage("The region X weight is " + ChatColor.BLUE + agent.getRegionWeightX() + ChatColor.RESET + ".");
|
||||
sender.sendMessage("The region Y weight is " + ChatColor.BLUE + agent.getRegionWeightY() + ChatColor.RESET + ".");
|
||||
sender.sendMessage("The region Z weight is " + ChatColor.BLUE + agent.getRegionWeightZ() + ChatColor.RESET + ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -505,9 +504,9 @@ public class BotCommand extends CommandInstance {
|
||||
output.add("false");
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("playertarget")) {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
output.add(player.getName());
|
||||
}
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
output.add(player.getName());
|
||||
}
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("addplayerlist")) {
|
||||
output.add("true");
|
||||
@@ -528,18 +527,18 @@ public class BotCommand extends CommandInstance {
|
||||
}
|
||||
|
||||
private double parseDoubleOrRelative(String pos, Location loc, int type) {
|
||||
if (loc == null || pos.length() == 0 || pos.charAt(0) != '~')
|
||||
return Double.parseDouble(pos);
|
||||
double relative = pos.length() == 1 ? 0 : Double.parseDouble(pos.substring(1));
|
||||
switch (type) {
|
||||
case 0:
|
||||
return relative + Math.round(loc.getX() * 1000) / 1000D;
|
||||
case 1:
|
||||
return relative + Math.round(loc.getY() * 1000) / 1000D;
|
||||
case 2:
|
||||
return relative + Math.round(loc.getZ() * 1000) / 1000D;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
if (loc == null || pos.length() == 0 || pos.charAt(0) != '~')
|
||||
return Double.parseDouble(pos);
|
||||
double relative = pos.length() == 1 ? 0 : Double.parseDouble(pos.substring(1));
|
||||
switch (type) {
|
||||
case 0:
|
||||
return relative + Math.round(loc.getX() * 1000) / 1000D;
|
||||
case 1:
|
||||
return relative + Math.round(loc.getY() * 1000) / 1000D;
|
||||
case 2:
|
||||
return relative + Math.round(loc.getZ() * 1000) / 1000D;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ public class MainCommand extends CommandInstance {
|
||||
|
||||
sender.spigot().sendMessage(rootInfo);
|
||||
}
|
||||
|
||||
@Command(
|
||||
name = "debuginfo",
|
||||
desc = "Upload debug info to mclo.gs"
|
||||
|
||||
@@ -33,7 +33,7 @@ public class MCLogs {
|
||||
====== TERMINATOR PLUS DEBUG INFO ======
|
||||
""";
|
||||
|
||||
public static String postInfo() throws IOException {
|
||||
public static String postInfo() throws IOException {
|
||||
String serverVersion = Bukkit.getVersion();
|
||||
String pluginVersion = TerminatorPlus.getVersion();
|
||||
String serverSoftware = Bukkit.getName();
|
||||
@@ -46,8 +46,8 @@ public class MCLogs {
|
||||
return pasteText(info);
|
||||
}
|
||||
|
||||
private static String pasteText(String text) throws IOException {
|
||||
URL url = new URL("https://api.mclo.gs/1/log"); // application/x-www-form-urlencoded
|
||||
private static String pasteText(String text) throws IOException {
|
||||
URL url = new URL("https://api.mclo.gs/1/log"); // application/x-www-form-urlencoded
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
@@ -60,5 +60,5 @@ public class MCLogs {
|
||||
String response = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine();
|
||||
JsonObject json = JsonParser.parseString(response).getAsJsonObject();
|
||||
return json.get("url").getAsString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.List;
|
||||
|
||||
public class NMSUtils {
|
||||
private static String itemsByIdFieldName;
|
||||
|
||||
static {
|
||||
// find a private final field in SynchedEntityData that is an Int2ObjectMap<SynchedEntityData.DataItem>
|
||||
Class<SynchedEntityData> clazz = SynchedEntityData.class;
|
||||
@@ -24,6 +25,7 @@ public class NMSUtils {
|
||||
throw new RuntimeException("Could not find itemsById field in SynchedEntityData");
|
||||
}
|
||||
}
|
||||
|
||||
public static List<SynchedEntityData.DataValue<?>> getEntityData(SynchedEntityData synchedEntityData) {
|
||||
Int2ObjectMap<SynchedEntityData.DataItem> map = null;
|
||||
try {
|
||||
@@ -35,7 +37,7 @@ public class NMSUtils {
|
||||
}
|
||||
List<SynchedEntityData.DataValue<?>> entityData = new ArrayList<>();
|
||||
for (SynchedEntityData.DataItem<?> dataItem : map.values()) {
|
||||
entityData.add(dataItem .value());
|
||||
entityData.add(dataItem.value());
|
||||
}
|
||||
return entityData;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user