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