Code formatting fixes
Not all formatting issues were fixed
This commit is contained in:
@@ -56,7 +56,7 @@ public class LegacyAgent extends Agent {
|
|||||||
private double regionWeightX;
|
private double regionWeightX;
|
||||||
private double regionWeightY;
|
private double regionWeightY;
|
||||||
private double regionWeightZ;
|
private double regionWeightZ;
|
||||||
|
|
||||||
public static final Set<EntityType> CUSTOM_MOB_LIST = new HashSet<>();
|
public static final Set<EntityType> CUSTOM_MOB_LIST = new HashSet<>();
|
||||||
public static String customListMode = "custom";
|
public static String customListMode = "custom";
|
||||||
|
|
||||||
@@ -1469,7 +1469,7 @@ public class LegacyAgent extends Agent {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case NEAREST_RAIDER: {
|
case NEAREST_RAIDER: {
|
||||||
for (LivingEntity entity : bot.getBukkitEntity().getWorld().getLivingEntities()) {
|
for (LivingEntity entity : bot.getBukkitEntity().getWorld().getLivingEntities()) {
|
||||||
boolean raider = entity instanceof Raider || (entity instanceof Vex vex && vex.getSummoner() instanceof Raider);
|
boolean raider = entity instanceof Raider || (entity instanceof Vex vex && vex.getSummoner() instanceof Raider);
|
||||||
@@ -1536,17 +1536,17 @@ public class LegacyAgent extends Agent {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case CUSTOM_LIST: {
|
case CUSTOM_LIST: {
|
||||||
for (LivingEntity entity : bot.getBukkitEntity().getWorld().getLivingEntities()) {
|
for (LivingEntity entity : bot.getBukkitEntity().getWorld().getLivingEntities()) {
|
||||||
if (customListMode.equals("custom") && CUSTOM_MOB_LIST.contains(entity.getType()) && validateCloserEntity(entity, loc, result)) {
|
if (customListMode.equals("custom") && CUSTOM_MOB_LIST.contains(entity.getType()) && validateCloserEntity(entity, loc, result)) {
|
||||||
result = entity;
|
result = entity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case PLAYER: {
|
case PLAYER: {
|
||||||
if (bot.getTargetPlayer() != null) {
|
if (bot.getTargetPlayer() != null) {
|
||||||
Player player = Bukkit.getPlayer(bot.getTargetPlayer());
|
Player player = Bukkit.getPlayer(bot.getTargetPlayer());
|
||||||
@@ -1554,7 +1554,7 @@ public class LegacyAgent extends Agent {
|
|||||||
result = player;
|
result = player;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1563,28 +1563,28 @@ public class LegacyAgent extends Agent {
|
|||||||
if (event.isCancelled()) return null;
|
if (event.isCancelled()) return null;
|
||||||
return event.getTarget();
|
return event.getTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateCloserEntity(LivingEntity entity, Location loc, LivingEntity result) {
|
private boolean validateCloserEntity(LivingEntity entity, Location loc, LivingEntity result) {
|
||||||
double regionDistEntity = getWeightedRegionDist(entity.getLocation());
|
double regionDistEntity = getWeightedRegionDist(entity.getLocation());
|
||||||
if (regionDistEntity == Double.MAX_VALUE)
|
if (regionDistEntity == Double.MAX_VALUE)
|
||||||
return false;
|
return false;
|
||||||
double regionDistResult = result == null ? 0 : getWeightedRegionDist(result.getLocation());
|
double regionDistResult = result == null ? 0 : getWeightedRegionDist(result.getLocation());
|
||||||
return loc.getWorld() == entity.getWorld() && !entity.isDead()
|
return loc.getWorld() == entity.getWorld() && !entity.isDead()
|
||||||
&& (result == null || (loc.distanceSquared(entity.getLocation()) + regionDistEntity) < (loc.distanceSquared(result.getLocation())) + regionDistResult);
|
&& (result == null || (loc.distanceSquared(entity.getLocation()) + regionDistEntity) < (loc.distanceSquared(result.getLocation())) + regionDistResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getWeightedRegionDist(Location loc) {
|
private double getWeightedRegionDist(Location loc) {
|
||||||
if (region == null)
|
if (region == null)
|
||||||
return 0;
|
return 0;
|
||||||
double diffX = Math.max(0, Math.abs(region.getCenterX() - loc.getX()) - region.getWidthX() * 0.5);
|
double diffX = Math.max(0, Math.abs(region.getCenterX() - loc.getX()) - region.getWidthX() * 0.5);
|
||||||
double diffY = Math.max(0, Math.abs(region.getCenterY() - loc.getY()) - region.getHeight() * 0.5);
|
double diffY = Math.max(0, Math.abs(region.getCenterY() - loc.getY()) - region.getHeight() * 0.5);
|
||||||
double diffZ = Math.max(0, Math.abs(region.getCenterZ() - loc.getZ()) - region.getWidthZ() * 0.5);
|
double diffZ = Math.max(0, Math.abs(region.getCenterZ() - loc.getZ()) - region.getWidthZ() * 0.5);
|
||||||
if (regionWeightX == 0 && regionWeightY == 0 && regionWeightZ == 0)
|
if (regionWeightX == 0 && regionWeightY == 0 && regionWeightZ == 0)
|
||||||
if (diffX > 0 || diffY > 0 || diffZ > 0)
|
if (diffX > 0 || diffY > 0 || diffZ > 0)
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
return diffX * diffX * regionWeightX + diffY * diffY * regionWeightY + diffZ * diffZ * regionWeightZ;
|
return diffX * diffX * regionWeightX + diffY * diffY * regionWeightY + diffZ * diffZ * regionWeightZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopAllTasks() {
|
public void stopAllTasks() {
|
||||||
super.stopAllTasks();
|
super.stopAllTasks();
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ public class BotFallDamageEvent {
|
|||||||
public Terminator getBot() {
|
public Terminator getBot() {
|
||||||
return bot;
|
return bot;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Block> getStandingOn() {
|
public List<Block> getStandingOn() {
|
||||||
return standingOn;
|
return standingOn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
|
|||||||
@@ -34,12 +34,12 @@ public class BotUtils {
|
|||||||
|
|
||||||
return randomSteveUUID();
|
return randomSteveUUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean overlaps(BoundingBox playerBox, BoundingBox blockBox) {
|
public static boolean overlaps(BoundingBox playerBox, BoundingBox blockBox) {
|
||||||
return playerBox.overlaps(blockBox);
|
return playerBox.overlaps(blockBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getHorizSqDist(Location blockLoc, Location pLoc) {
|
public static double getHorizSqDist(Location blockLoc, Location pLoc) {
|
||||||
return NumberConversions.square(blockLoc.getX() + 0.5 - pLoc.getX()) + NumberConversions.square(blockLoc.getZ() + 0.5 - pLoc.getZ());
|
return NumberConversions.square(blockLoc.getX() + 0.5 - pLoc.getX()) + NumberConversions.square(blockLoc.getZ() + 0.5 - pLoc.getZ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ public class Bot extends ServerPlayer implements Terminator {
|
|||||||
|
|
||||||
// Magma fix - In case a mod causes the Bukkit entity to be created too early
|
// Magma fix - In case a mod causes the Bukkit entity to be created too early
|
||||||
try {
|
try {
|
||||||
getClass().getMethod("resetBukkitEntity").invoke(this);
|
getClass().getMethod("resetBukkitEntity").invoke(this);
|
||||||
} catch (ReflectiveOperationException e) {}
|
} catch (ReflectiveOperationException e) {}
|
||||||
|
|
||||||
//this.entityData.set(new EntityDataAccessor<>(16, EntityDataSerializers.BYTE), (byte) 0xFF);
|
//this.entityData.set(new EntityDataAccessor<>(16, EntityDataSerializers.BYTE), (byte) 0xFF);
|
||||||
@@ -124,11 +124,11 @@ public class Bot extends ServerPlayer implements Terminator {
|
|||||||
bot.getBukkitEntity().setNoDamageTicks(0);
|
bot.getBukkitEntity().setNoDamageTicks(0);
|
||||||
if (addPlayerList) {
|
if (addPlayerList) {
|
||||||
Bukkit.getOnlinePlayers().forEach(p -> ((CraftPlayer) p).getHandle().connection.send(
|
Bukkit.getOnlinePlayers().forEach(p -> ((CraftPlayer) p).getHandle().connection.send(
|
||||||
ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(bot))));
|
ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(bot))));
|
||||||
nmsWorld.addNewPlayer(bot);
|
nmsWorld.addNewPlayer(bot);
|
||||||
} else {
|
} else {
|
||||||
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)));
|
||||||
nmsWorld.addFreshEntity(bot);
|
nmsWorld.addFreshEntity(bot);
|
||||||
}
|
}
|
||||||
bot.renderAll();
|
bot.renderAll();
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public abstract class CommandInstance extends BukkitCommand {
|
|||||||
protected void addMethod(String name, CommandMethod method) {
|
protected void addMethod(String name, CommandMethod method) {
|
||||||
methods.put(name, method);
|
methods.put(name, method);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addAlias(String alias, String name) {
|
protected void addAlias(String alias, String name) {
|
||||||
aliasesToNames.put(alias, name);
|
aliasesToNames.put(alias, name);
|
||||||
}
|
}
|
||||||
@@ -237,9 +237,9 @@ public abstract class CommandInstance extends BukkitCommand {
|
|||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
List<String> result = methods.keySet().stream().filter(c -> !c.isEmpty() && c.contains(args[0])).collect(Collectors.toList());
|
List<String> result = methods.keySet().stream().filter(c -> !c.isEmpty() && c.contains(args[0])).collect(Collectors.toList());
|
||||||
if (result.isEmpty()) {
|
if (result.isEmpty()) {
|
||||||
// Add aliases also
|
// Add aliases also
|
||||||
methods.forEach((s, m) -> result.addAll(m.getAliases()));
|
methods.forEach((s, m) -> result.addAll(m.getAliases()));
|
||||||
return result.stream().filter(c -> c.contains(args[0])).collect(Collectors.toList());
|
return result.stream().filter(c -> c.contains(args[0])).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -247,7 +247,7 @@ public abstract class CommandInstance extends BukkitCommand {
|
|||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
CommandMethod commandMethod = methods.get(args[0]);
|
CommandMethod commandMethod = methods.get(args[0]);
|
||||||
if (commandMethod == null)
|
if (commandMethod == null)
|
||||||
commandMethod = methods.values().stream().filter(m -> m.getAliases().contains(args[0])).findFirst().orElse(null);
|
commandMethod = methods.values().stream().filter(m -> m.getAliases().contains(args[0])).findFirst().orElse(null);
|
||||||
if (commandMethod == null) return new ArrayList<>();
|
if (commandMethod == null) return new ArrayList<>();
|
||||||
Method autofiller = commandMethod.getAutofiller();
|
Method autofiller = commandMethod.getAutofiller();
|
||||||
|
|
||||||
|
|||||||
@@ -188,6 +188,6 @@ public class AICommand extends CommandInstance implements AIManager {
|
|||||||
|
|
||||||
@Autofill
|
@Autofill
|
||||||
public List<String> infoAutofill(CommandSender sender, String[] args) {
|
public List<String> infoAutofill(CommandSender sender, String[] args) {
|
||||||
return args.length == 2 ? manager.fetchNames() : new ArrayList<>();
|
return args.length == 2 ? manager.fetchNames() : new ArrayList<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -536,7 +536,7 @@ public class BotCommand extends CommandInstance {
|
|||||||
|
|
||||||
@Autofill
|
@Autofill
|
||||||
public List<String> debugAutofill(CommandSender sender, String[] args) {
|
public List<String> debugAutofill(CommandSender sender, String[] args) {
|
||||||
return args.length == 2 ? new ArrayList<>(Debugger.AUTOFILL_METHODS) : new ArrayList<>();
|
return args.length == 2 ? new ArrayList<>(Debugger.AUTOFILL_METHODS) : new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private double parseDoubleOrRelative(String pos, Location loc, int type) {
|
private double parseDoubleOrRelative(String pos, Location loc, int type) {
|
||||||
|
|||||||
@@ -34,397 +34,397 @@ import net.nuggetmc.tplus.command.annotation.OptArg;
|
|||||||
|
|
||||||
public class BotEnvironmentCommand extends CommandInstance {
|
public class BotEnvironmentCommand extends CommandInstance {
|
||||||
|
|
||||||
private static final Set<String> LOADED_MODS = new HashSet<>();
|
private static final Set<String> LOADED_MODS = new HashSet<>();
|
||||||
private static boolean loaded;
|
private static boolean loaded;
|
||||||
|
|
||||||
public BotEnvironmentCommand(CommandHandler handler, String name, String description, String... aliases) {
|
public BotEnvironmentCommand(CommandHandler handler, String name, String description, String... aliases) {
|
||||||
super(handler, name, description, aliases);
|
super(handler, name, description, aliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command
|
@Command
|
||||||
public void root(CommandSender sender, List<String> args) {
|
public void root(CommandSender sender, List<String> args) {
|
||||||
commandHandler.sendRootInfo(this, sender);
|
commandHandler.sendRootInfo(this, sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
name = "help",
|
name = "help",
|
||||||
desc = "Help for /botenvironment.",
|
desc = "Help for /botenvironment.",
|
||||||
autofill = "autofill"
|
autofill = "autofill"
|
||||||
)
|
)
|
||||||
public void help(CommandSender sender, List<String> args) {
|
public void help(CommandSender sender, List<String> args) {
|
||||||
if (args.size() > 0 && args.get(0).equals("blocks")) {
|
if (args.size() > 0 && args.get(0).equals("blocks")) {
|
||||||
sender.sendMessage(ChatUtils.LINE);
|
sender.sendMessage(ChatUtils.LINE);
|
||||||
sender.sendMessage("If you are running this plugin on a Magma server, keep in mind that blocks added by mods are not considered solid.");
|
sender.sendMessage("If you are running this plugin on a Magma server, keep in mind that blocks added by mods are not considered solid.");
|
||||||
sender.sendMessage("You must manually add solid blocks added by mods with " + ChatColor.YELLOW + "/botenvironment addSolid <material>" + ChatColor.RESET + ".");
|
sender.sendMessage("You must manually add solid blocks added by mods with " + ChatColor.YELLOW + "/botenvironment addSolid <material>" + ChatColor.RESET + ".");
|
||||||
sender.sendMessage("The material name is the mod ID and the block name concatted with a \"_\", converted to uppercase.");
|
sender.sendMessage("The material name is the mod ID and the block name concatted with a \"_\", converted to uppercase.");
|
||||||
sender.sendMessage("For example, if mod \"examplemod\" adds a block \"custom_block\", the material name is EXAMPLEMOD_CUSTOM_BLOCK.");
|
sender.sendMessage("For example, if mod \"examplemod\" adds a block \"custom_block\", the material name is EXAMPLEMOD_CUSTOM_BLOCK.");
|
||||||
sender.sendMessage("Additionally, you may use " + ChatColor.YELLOW + "/botenvironment addSolidGroup <modid>" + ChatColor.RESET + ", where modid is the uppercase MODID plus a \"_\"");
|
sender.sendMessage("Additionally, you may use " + ChatColor.YELLOW + "/botenvironment addSolidGroup <modid>" + ChatColor.RESET + ", where modid is the uppercase MODID plus a \"_\"");
|
||||||
sender.sendMessage(ChatUtils.LINE);
|
sender.sendMessage(ChatUtils.LINE);
|
||||||
} else if (args.size() > 0 && args.get(0).equals("mobs")) {
|
} else if (args.size() > 0 && args.get(0).equals("mobs")) {
|
||||||
sender.sendMessage(ChatUtils.LINE);
|
sender.sendMessage(ChatUtils.LINE);
|
||||||
sender.sendMessage("The custom mob list is a user-defined list of mobs.");
|
sender.sendMessage("The custom mob list is a user-defined list of mobs.");
|
||||||
sender.sendMessage("Use " + ChatColor.YELLOW + "/botenvironment addCustomMob <name>" + ChatColor.RESET + " to add mob types to the list.");
|
sender.sendMessage("Use " + ChatColor.YELLOW + "/botenvironment addCustomMob <name>" + ChatColor.RESET + " to add mob types to the list.");
|
||||||
sender.sendMessage("The list can be used in the CUSTOM_LIST targeting option, and can also be appended to the hostile, raider, or mob targeting options.");
|
sender.sendMessage("The list can be used in the CUSTOM_LIST targeting option, and can also be appended to the hostile, raider, or mob targeting options.");
|
||||||
sender.sendMessage("When appending, the mobs predefined as well as the mobs in the custom list will be considered.");
|
sender.sendMessage("When appending, the mobs predefined as well as the mobs in the custom list will be considered.");
|
||||||
sender.sendMessage("Use " + ChatColor.YELLOW + "/botenvironment mobListType" + ChatColor.RESET + " to change the behavior of the custom mob list.");
|
sender.sendMessage("Use " + ChatColor.YELLOW + "/botenvironment mobListType" + ChatColor.RESET + " to change the behavior of the custom mob list.");
|
||||||
sender.sendMessage(ChatUtils.LINE);
|
sender.sendMessage(ChatUtils.LINE);
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("Do " + ChatColor.YELLOW + "/botenvironment help blocks " + ChatColor.RESET + "for more information on adding solid blocks.");
|
sender.sendMessage("Do " + ChatColor.YELLOW + "/botenvironment help blocks " + ChatColor.RESET + "for more information on adding solid blocks.");
|
||||||
sender.sendMessage("Do " + ChatColor.YELLOW + "/botenvironment help mobs " + ChatColor.RESET + "for more information on creating a custom mob list.");
|
sender.sendMessage("Do " + ChatColor.YELLOW + "/botenvironment help mobs " + ChatColor.RESET + "for more information on creating a custom mob list.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
name = "getMaterial",
|
name = "getMaterial",
|
||||||
desc = "Prints out the current material at the specified location.",
|
desc = "Prints out the current material at the specified location.",
|
||||||
aliases = {"getmat", "getMat", "getmaterial"}
|
aliases = {"getmat", "getMat", "getmaterial"}
|
||||||
)
|
)
|
||||||
public void getMaterial(Player sender, @Arg("x") String x, @Arg("y") String y, @Arg("z") String z) {
|
public void getMaterial(Player sender, @Arg("x") String x, @Arg("y") String y, @Arg("z") String z) {
|
||||||
Location loc = sender.getLocation().clone();
|
Location loc = sender.getLocation().clone();
|
||||||
try {
|
try {
|
||||||
loc.setX(parseDoubleOrRelative(x, loc, 0));
|
loc.setX(parseDoubleOrRelative(x, loc, 0));
|
||||||
loc.setY(parseDoubleOrRelative(y, loc, 1));
|
loc.setY(parseDoubleOrRelative(y, loc, 1));
|
||||||
loc.setZ(parseDoubleOrRelative(z, loc, 2));
|
loc.setZ(parseDoubleOrRelative(z, loc, 2));
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
sender.sendMessage("A valid location must be provided!");
|
sender.sendMessage("A valid location must be provided!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!isLocationLoaded(loc)) {
|
if (!isLocationLoaded(loc)) {
|
||||||
sender.sendMessage(String.format("The location at " + ChatColor.BLUE + "(%d, %d, %d)" + ChatColor.RESET + " is not loaded.",
|
sender.sendMessage(String.format("The location at " + ChatColor.BLUE + "(%d, %d, %d)" + ChatColor.RESET + " is not loaded.",
|
||||||
loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Math.abs(loc.getX() - sender.getLocation().getX()) > 250 || Math.abs(loc.getZ() - sender.getLocation().getZ()) > 250) {
|
if (Math.abs(loc.getX() - sender.getLocation().getX()) > 250 || Math.abs(loc.getZ() - sender.getLocation().getZ()) > 250) {
|
||||||
sender.sendMessage(String.format("The location at " + ChatColor.BLUE + "(%d, %d, %d)" + ChatColor.RESET + " is too far away.",
|
sender.sendMessage(String.format("The location at " + ChatColor.BLUE + "(%d, %d, %d)" + ChatColor.RESET + " is too far away.",
|
||||||
loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Material mat = loc.getBlock().getType();
|
Material mat = loc.getBlock().getType();
|
||||||
sender.sendMessage(String.format("Material at " + ChatColor.BLUE + "(%d, %d, %d)" + ChatColor.RESET + ": " + ChatColor.GREEN + "%s" + ChatColor.RESET,
|
sender.sendMessage(String.format("Material at " + ChatColor.BLUE + "(%d, %d, %d)" + ChatColor.RESET + ": " + ChatColor.GREEN + "%s" + ChatColor.RESET,
|
||||||
loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), mat.name()));
|
loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), mat.name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
name = "addSolidGroup",
|
name = "addSolidGroup",
|
||||||
desc = "Adds every block starting with a prefix to the list of solid materials.",
|
desc = "Adds every block starting with a prefix to the list of solid materials.",
|
||||||
aliases = {"addsolidgroup"},
|
aliases = {"addsolidgroup"},
|
||||||
autofill = "autofill"
|
autofill = "autofill"
|
||||||
)
|
)
|
||||||
public void addSolidGroup(CommandSender sender, @Arg("prefix") String prefix, @OptArg("includeNonSolid") boolean includeNonSolid) {
|
public void addSolidGroup(CommandSender sender, @Arg("prefix") String prefix, @OptArg("includeNonSolid") boolean includeNonSolid) {
|
||||||
try {
|
try {
|
||||||
Field byName = Material.class.getDeclaredField("BY_NAME");
|
Field byName = Material.class.getDeclaredField("BY_NAME");
|
||||||
byName.setAccessible(true);
|
byName.setAccessible(true);
|
||||||
Map<String, Material> map = (Map<String, Material>) byName.get(null);
|
Map<String, Material> map = (Map<String, Material>) byName.get(null);
|
||||||
Map<Material, Block> materialsToBlocks = new HashMap<>();
|
Map<Material, Block> materialsToBlocks = new HashMap<>();
|
||||||
if (!includeNonSolid) {
|
if (!includeNonSolid) {
|
||||||
// Build material -> block map using ForgeRegistries
|
// Build material -> block map using ForgeRegistries
|
||||||
Object blocksRegistry = Class.forName("net.minecraftforge.registries.ForgeRegistries").getDeclaredField("BLOCKS").get(null);
|
Object blocksRegistry = Class.forName("net.minecraftforge.registries.ForgeRegistries").getDeclaredField("BLOCKS").get(null);
|
||||||
Set<Entry<ResourceKey<Block>, Block>> blockSet = (Set<Entry<ResourceKey<Block>, Block>>) Class.forName("net.minecraftforge.registries.IForgeRegistry").getMethod("getEntries").invoke(blocksRegistry);
|
Set<Entry<ResourceKey<Block>, Block>> blockSet = (Set<Entry<ResourceKey<Block>, Block>>) Class.forName("net.minecraftforge.registries.IForgeRegistry").getMethod("getEntries").invoke(blocksRegistry);
|
||||||
|
|
||||||
for (Entry<ResourceKey<Block>, Block> entry : blockSet) {
|
for (Entry<ResourceKey<Block>, Block> entry : blockSet) {
|
||||||
String result = (String) Class.forName("org.magmafoundation.magma.util.ResourceLocationUtil").getMethod("standardize", ResourceLocation.class).invoke(null, entry.getKey().location());
|
String result = (String) Class.forName("org.magmafoundation.magma.util.ResourceLocationUtil").getMethod("standardize", ResourceLocation.class).invoke(null, entry.getKey().location());
|
||||||
Material material = Material.getMaterial(result);
|
Material material = Material.getMaterial(result);
|
||||||
if (material != null)
|
if (material != null)
|
||||||
materialsToBlocks.put(material, entry.getValue());
|
materialsToBlocks.put(material, entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int added = 0;
|
int added = 0;
|
||||||
for (Entry<String, Material> entry : map.entrySet()) {
|
for (Entry<String, Material> entry : map.entrySet()) {
|
||||||
boolean valid = entry.getValue().isBlock() && entry.getKey().startsWith(prefix);
|
boolean valid = entry.getValue().isBlock() && entry.getKey().startsWith(prefix);
|
||||||
if (valid && !includeNonSolid)
|
if (valid && !includeNonSolid)
|
||||||
if (!materialsToBlocks.containsKey(entry.getValue())) {
|
if (!materialsToBlocks.containsKey(entry.getValue())) {
|
||||||
sender.sendMessage("Warning: The material " + ChatColor.GREEN + entry.getValue().name() + ChatColor.RESET
|
sender.sendMessage("Warning: The material " + ChatColor.GREEN + entry.getValue().name() + ChatColor.RESET
|
||||||
+ " was not found in the Forge registries, this should not happen!");
|
+ " was not found in the Forge registries, this should not happen!");
|
||||||
} else {
|
} else {
|
||||||
// Check if block is solid
|
// Check if block is solid
|
||||||
Block block = materialsToBlocks.get(entry.getValue());
|
Block block = materialsToBlocks.get(entry.getValue());
|
||||||
valid = block.defaultBlockState().blocksMotion();
|
valid = block.defaultBlockState().blocksMotion();
|
||||||
}
|
}
|
||||||
if (valid && LegacyMats.SOLID_MATERIALS.add(entry.getValue()))
|
if (valid && LegacyMats.SOLID_MATERIALS.add(entry.getValue()))
|
||||||
added++;
|
added++;
|
||||||
}
|
}
|
||||||
sender.sendMessage("Successfully added " + ChatColor.BLUE + added + ChatColor.RESET + " materials with prefix " + ChatColor.GREEN + prefix + ChatColor.RESET);
|
sender.sendMessage("Successfully added " + ChatColor.BLUE + added + ChatColor.RESET + " materials with prefix " + ChatColor.GREEN + prefix + ChatColor.RESET);
|
||||||
} catch(ReflectiveOperationException e) {
|
} catch(ReflectiveOperationException e) {
|
||||||
sender.sendMessage("This command only works on Magma servers!");
|
sender.sendMessage("This command only works on Magma servers!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
name = "addSolid",
|
name = "addSolid",
|
||||||
desc = "Adds a material to the list of solid materials.",
|
desc = "Adds a material to the list of solid materials.",
|
||||||
aliases = {"addsolid"},
|
aliases = {"addsolid"},
|
||||||
autofill = "autofill"
|
autofill = "autofill"
|
||||||
)
|
)
|
||||||
public void addSolid(CommandSender sender, List<String> args) {
|
public void addSolid(CommandSender sender, List<String> args) {
|
||||||
Material mat;
|
Material mat;
|
||||||
if (args.size() == 1)
|
if (args.size() == 1)
|
||||||
mat = Material.getMaterial(args.get(0));
|
mat = Material.getMaterial(args.get(0));
|
||||||
else if (args.size() == 3) {
|
else if (args.size() == 3) {
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
sender.sendMessage("You must be a player to specify coordinates!");
|
sender.sendMessage("You must be a player to specify coordinates!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Location loc = ((Player)sender).getLocation().clone();
|
Location loc = ((Player)sender).getLocation().clone();
|
||||||
try {
|
try {
|
||||||
loc.setX(parseDoubleOrRelative(args.get(0), loc, 0));
|
loc.setX(parseDoubleOrRelative(args.get(0), loc, 0));
|
||||||
loc.setY(parseDoubleOrRelative(args.get(1), loc, 1));
|
loc.setY(parseDoubleOrRelative(args.get(1), loc, 1));
|
||||||
loc.setZ(parseDoubleOrRelative(args.get(2), loc, 2));
|
loc.setZ(parseDoubleOrRelative(args.get(2), loc, 2));
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
sender.sendMessage("A valid location must be provided! " + ChatColor.YELLOW + "/bot addSolid <x> <y> <z>" + ChatColor.RESET);
|
sender.sendMessage("A valid location must be provided! " + ChatColor.YELLOW + "/bot addSolid <x> <y> <z>" + ChatColor.RESET);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!isLocationLoaded(loc)) {
|
if (!isLocationLoaded(loc)) {
|
||||||
sender.sendMessage(String.format("The location at " + ChatColor.BLUE + "(%d, %d, %d)" + ChatColor.RESET + " is not loaded.",
|
sender.sendMessage(String.format("The location at " + ChatColor.BLUE + "(%d, %d, %d)" + ChatColor.RESET + " is not loaded.",
|
||||||
loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Math.abs(loc.getX() - ((Player)sender).getLocation().getX()) > 250 || Math.abs(loc.getZ() - ((Player)sender).getLocation().getZ()) > 250) {
|
if (Math.abs(loc.getX() - ((Player)sender).getLocation().getX()) > 250 || Math.abs(loc.getZ() - ((Player)sender).getLocation().getZ()) > 250) {
|
||||||
sender.sendMessage(String.format("The location at " + ChatColor.BLUE + "(%d, %d, %d)" + ChatColor.RESET + " is too far away.",
|
sender.sendMessage(String.format("The location at " + ChatColor.BLUE + "(%d, %d, %d)" + ChatColor.RESET + " is too far away.",
|
||||||
loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mat = loc.getBlock().getType();
|
mat = loc.getBlock().getType();
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("Invalid syntax!");
|
sender.sendMessage("Invalid syntax!");
|
||||||
sender.sendMessage("To specify a material: " + ChatColor.YELLOW + "/bot addSolid <material>" + ChatColor.RESET);
|
sender.sendMessage("To specify a material: " + ChatColor.YELLOW + "/bot addSolid <material>" + ChatColor.RESET);
|
||||||
sender.sendMessage("To specify a location containing a material: " + ChatColor.YELLOW + "/bot addSolid <x> <y> <z>" + ChatColor.RESET);
|
sender.sendMessage("To specify a location containing a material: " + ChatColor.YELLOW + "/bot addSolid <x> <y> <z>" + ChatColor.RESET);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mat == null) {
|
if (mat == null) {
|
||||||
sender.sendMessage("The material you specified does not exist!");
|
sender.sendMessage("The material you specified does not exist!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (LegacyMats.SOLID_MATERIALS.add(mat))
|
if (LegacyMats.SOLID_MATERIALS.add(mat))
|
||||||
sender.sendMessage("Successfully added " + ChatColor.BLUE + mat.name() + ChatColor.RESET + " to the list.");
|
sender.sendMessage("Successfully added " + ChatColor.BLUE + mat.name() + ChatColor.RESET + " to the list.");
|
||||||
else
|
else
|
||||||
sender.sendMessage(ChatColor.BLUE + mat.name() + ChatColor.RESET + " already exists in the list!");
|
sender.sendMessage(ChatColor.BLUE + mat.name() + ChatColor.RESET + " already exists in the list!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
name = "removeSolid",
|
name = "removeSolid",
|
||||||
desc = "Removes a material from the list of solid materials.",
|
desc = "Removes a material from the list of solid materials.",
|
||||||
aliases = {"removesolid"},
|
aliases = {"removesolid"},
|
||||||
autofill = "autofill"
|
autofill = "autofill"
|
||||||
)
|
)
|
||||||
public void removeSolid(CommandSender sender, List<String> args) {
|
public void removeSolid(CommandSender sender, List<String> args) {
|
||||||
Material mat;
|
Material mat;
|
||||||
if (args.size() == 1)
|
if (args.size() == 1)
|
||||||
mat = Material.getMaterial(args.get(0));
|
mat = Material.getMaterial(args.get(0));
|
||||||
else if (args.size() == 3) {
|
else if (args.size() == 3) {
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
sender.sendMessage("You must be a player to specify coordinates!");
|
sender.sendMessage("You must be a player to specify coordinates!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Location loc = ((Player)sender).getLocation().clone();
|
Location loc = ((Player)sender).getLocation().clone();
|
||||||
try {
|
try {
|
||||||
loc.setX(parseDoubleOrRelative(args.get(0), loc, 0));
|
loc.setX(parseDoubleOrRelative(args.get(0), loc, 0));
|
||||||
loc.setY(parseDoubleOrRelative(args.get(1), loc, 1));
|
loc.setY(parseDoubleOrRelative(args.get(1), loc, 1));
|
||||||
loc.setZ(parseDoubleOrRelative(args.get(2), loc, 2));
|
loc.setZ(parseDoubleOrRelative(args.get(2), loc, 2));
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
sender.sendMessage("A valid location must be provided! " + ChatColor.YELLOW + "/bot removeSolid <x> <y> <z>" + ChatColor.RESET);
|
sender.sendMessage("A valid location must be provided! " + ChatColor.YELLOW + "/bot removeSolid <x> <y> <z>" + ChatColor.RESET);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!isLocationLoaded(loc)) {
|
if (!isLocationLoaded(loc)) {
|
||||||
sender.sendMessage(String.format("The location at " + ChatColor.BLUE + "(%d, %d, %d)" + ChatColor.RESET + " is not loaded.",
|
sender.sendMessage(String.format("The location at " + ChatColor.BLUE + "(%d, %d, %d)" + ChatColor.RESET + " is not loaded.",
|
||||||
loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Math.abs(loc.getX() - ((Player)sender).getLocation().getX()) > 250 || Math.abs(loc.getZ() - ((Player)sender).getLocation().getZ()) > 250) {
|
if (Math.abs(loc.getX() - ((Player)sender).getLocation().getX()) > 250 || Math.abs(loc.getZ() - ((Player)sender).getLocation().getZ()) > 250) {
|
||||||
sender.sendMessage(String.format("The location at " + ChatColor.BLUE + "(%d, %d, %d)" + ChatColor.RESET + " is too far away.",
|
sender.sendMessage(String.format("The location at " + ChatColor.BLUE + "(%d, %d, %d)" + ChatColor.RESET + " is too far away.",
|
||||||
loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mat = loc.getBlock().getType();
|
mat = loc.getBlock().getType();
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("Invalid syntax!");
|
sender.sendMessage("Invalid syntax!");
|
||||||
sender.sendMessage("To specify a material: " + ChatColor.YELLOW + "/bot removeSolid <material>" + ChatColor.RESET);
|
sender.sendMessage("To specify a material: " + ChatColor.YELLOW + "/bot removeSolid <material>" + ChatColor.RESET);
|
||||||
sender.sendMessage("To specify a location containing a material: " + ChatColor.YELLOW + "/bot removeSolid <x> <y> <z>" + ChatColor.RESET);
|
sender.sendMessage("To specify a location containing a material: " + ChatColor.YELLOW + "/bot removeSolid <x> <y> <z>" + ChatColor.RESET);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mat == null) {
|
if (mat == null) {
|
||||||
sender.sendMessage("The material you specified does not exist!");
|
sender.sendMessage("The material you specified does not exist!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (LegacyMats.SOLID_MATERIALS.remove(mat))
|
if (LegacyMats.SOLID_MATERIALS.remove(mat))
|
||||||
sender.sendMessage("Successfully removed " + ChatColor.BLUE + mat.name() + ChatColor.RESET + " from the list.");
|
sender.sendMessage("Successfully removed " + ChatColor.BLUE + mat.name() + ChatColor.RESET + " from the list.");
|
||||||
else
|
else
|
||||||
sender.sendMessage(ChatColor.BLUE + mat.name() + ChatColor.RESET + " does not exist in the list!");
|
sender.sendMessage(ChatColor.BLUE + mat.name() + ChatColor.RESET + " does not exist in the list!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
name = "listSolids",
|
name = "listSolids",
|
||||||
desc = "Displays the list of solid materials manually added.",
|
desc = "Displays the list of solid materials manually added.",
|
||||||
aliases = {"listsolids"}
|
aliases = {"listsolids"}
|
||||||
)
|
)
|
||||||
public void listSolids(CommandSender sender) {
|
public void listSolids(CommandSender sender) {
|
||||||
sender.sendMessage(ChatUtils.LINE);
|
sender.sendMessage(ChatUtils.LINE);
|
||||||
for (Material mat : LegacyMats.SOLID_MATERIALS)
|
for (Material mat : LegacyMats.SOLID_MATERIALS)
|
||||||
sender.sendMessage(ChatColor.GREEN + mat.name() + ChatColor.RESET);
|
sender.sendMessage(ChatColor.GREEN + mat.name() + ChatColor.RESET);
|
||||||
sender.sendMessage("Total items: " + ChatColor.BLUE + LegacyMats.SOLID_MATERIALS.size() + ChatColor.RESET);
|
sender.sendMessage("Total items: " + ChatColor.BLUE + LegacyMats.SOLID_MATERIALS.size() + ChatColor.RESET);
|
||||||
sender.sendMessage(ChatUtils.LINE);
|
sender.sendMessage(ChatUtils.LINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
name = "clearSolids",
|
name = "clearSolids",
|
||||||
desc = "Clears the list of solid materials manually added.",
|
desc = "Clears the list of solid materials manually added.",
|
||||||
aliases = {"clearsolids"}
|
aliases = {"clearsolids"}
|
||||||
)
|
)
|
||||||
public void clearSolids(CommandSender sender) {
|
public void clearSolids(CommandSender sender) {
|
||||||
int size = LegacyMats.SOLID_MATERIALS.size();
|
int size = LegacyMats.SOLID_MATERIALS.size();
|
||||||
LegacyMats.SOLID_MATERIALS.clear();
|
LegacyMats.SOLID_MATERIALS.clear();
|
||||||
sender.sendMessage("Removed all " + ChatColor.BLUE + size + ChatColor.RESET + " item(s) from the list.");
|
sender.sendMessage("Removed all " + ChatColor.BLUE + size + ChatColor.RESET + " item(s) from the list.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
name = "addCustomMob",
|
name = "addCustomMob",
|
||||||
desc = "Adds a mob to the custom list.",
|
desc = "Adds a mob to the custom list.",
|
||||||
aliases = {"addcustommob"},
|
aliases = {"addcustommob"},
|
||||||
autofill = "autofill"
|
autofill = "autofill"
|
||||||
)
|
)
|
||||||
public void addCustomMob(CommandSender sender, @Arg("mobName") String mobName) {
|
public void addCustomMob(CommandSender sender, @Arg("mobName") String mobName) {
|
||||||
EntityType type = EntityType.fromName(mobName);
|
EntityType type = EntityType.fromName(mobName);
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
sender.sendMessage("The entity type you specified does not exist!");
|
sender.sendMessage("The entity type you specified does not exist!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (LegacyAgent.CUSTOM_MOB_LIST.add(type))
|
if (LegacyAgent.CUSTOM_MOB_LIST.add(type))
|
||||||
sender.sendMessage("Successfully added " + ChatColor.BLUE + type.name() + ChatColor.RESET + " to the list.");
|
sender.sendMessage("Successfully added " + ChatColor.BLUE + type.name() + ChatColor.RESET + " to the list.");
|
||||||
else
|
else
|
||||||
sender.sendMessage(ChatColor.BLUE + type.name() + ChatColor.RESET + " already exists in the list!");
|
sender.sendMessage(ChatColor.BLUE + type.name() + ChatColor.RESET + " already exists in the list!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
name = "removeCustomMob",
|
name = "removeCustomMob",
|
||||||
desc = "Removes a mob from the custom list.",
|
desc = "Removes a mob from the custom list.",
|
||||||
aliases = {"removecustommob"},
|
aliases = {"removecustommob"},
|
||||||
autofill = "autofill"
|
autofill = "autofill"
|
||||||
)
|
)
|
||||||
public void removeCustomMob(CommandSender sender, @Arg("mobName") String mobName) {
|
public void removeCustomMob(CommandSender sender, @Arg("mobName") String mobName) {
|
||||||
EntityType type = EntityType.fromName(mobName);
|
EntityType type = EntityType.fromName(mobName);
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
sender.sendMessage("The entity type you specified does not exist!");
|
sender.sendMessage("The entity type you specified does not exist!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (LegacyAgent.CUSTOM_MOB_LIST.remove(type))
|
if (LegacyAgent.CUSTOM_MOB_LIST.remove(type))
|
||||||
sender.sendMessage("Successfully removed " + ChatColor.BLUE + type.name() + ChatColor.RESET + " from the list.");
|
sender.sendMessage("Successfully removed " + ChatColor.BLUE + type.name() + ChatColor.RESET + " from the list.");
|
||||||
else
|
else
|
||||||
sender.sendMessage(ChatColor.BLUE + type.name() + ChatColor.RESET + " does not exist in the list!");
|
sender.sendMessage(ChatColor.BLUE + type.name() + ChatColor.RESET + " does not exist in the list!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
name = "listCustomMobs",
|
name = "listCustomMobs",
|
||||||
desc = "Displays the custom list of mobs.",
|
desc = "Displays the custom list of mobs.",
|
||||||
aliases = {"listcustommobs"}
|
aliases = {"listcustommobs"}
|
||||||
)
|
)
|
||||||
public void listCustomMobs(CommandSender sender) {
|
public void listCustomMobs(CommandSender sender) {
|
||||||
sender.sendMessage(ChatUtils.LINE);
|
sender.sendMessage(ChatUtils.LINE);
|
||||||
for (EntityType type : LegacyAgent.CUSTOM_MOB_LIST)
|
for (EntityType type : LegacyAgent.CUSTOM_MOB_LIST)
|
||||||
sender.sendMessage(ChatColor.GREEN + type.name() + ChatColor.RESET);
|
sender.sendMessage(ChatColor.GREEN + type.name() + ChatColor.RESET);
|
||||||
sender.sendMessage("Total items: " + ChatColor.BLUE + LegacyAgent.CUSTOM_MOB_LIST.size() + ChatColor.RESET);
|
sender.sendMessage("Total items: " + ChatColor.BLUE + LegacyAgent.CUSTOM_MOB_LIST.size() + ChatColor.RESET);
|
||||||
sender.sendMessage(ChatUtils.LINE);
|
sender.sendMessage(ChatUtils.LINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
name = "clearCustomMobs",
|
name = "clearCustomMobs",
|
||||||
desc = "Clears the custom list of mobs.",
|
desc = "Clears the custom list of mobs.",
|
||||||
aliases = {"clearcustommobs"}
|
aliases = {"clearcustommobs"}
|
||||||
)
|
)
|
||||||
public void clearCustomMobs(CommandSender sender) {
|
public void clearCustomMobs(CommandSender sender) {
|
||||||
int size = LegacyAgent.CUSTOM_MOB_LIST.size();
|
int size = LegacyAgent.CUSTOM_MOB_LIST.size();
|
||||||
LegacyAgent.CUSTOM_MOB_LIST.clear();
|
LegacyAgent.CUSTOM_MOB_LIST.clear();
|
||||||
sender.sendMessage("Removed all " + ChatColor.BLUE + size + ChatColor.RESET + " item(s) from the list.");
|
sender.sendMessage("Removed all " + ChatColor.BLUE + size + ChatColor.RESET + " item(s) from the list.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
name = "mobListType",
|
name = "mobListType",
|
||||||
desc = "Changes the behavior of the custom mob list.",
|
desc = "Changes the behavior of the custom mob list.",
|
||||||
aliases = {"moblisttype"},
|
aliases = {"moblisttype"},
|
||||||
autofill = "autofill"
|
autofill = "autofill"
|
||||||
)
|
)
|
||||||
public void mobListType(CommandSender sender, List<String> args) {
|
public void mobListType(CommandSender sender, List<String> args) {
|
||||||
if (args.isEmpty()) {
|
if (args.isEmpty()) {
|
||||||
sender.sendMessage("The custom mob list type is " + ChatColor.BLUE + LegacyAgent.customListMode + ChatColor.RESET + ".");
|
sender.sendMessage("The custom mob list type is " + ChatColor.BLUE + LegacyAgent.customListMode + ChatColor.RESET + ".");
|
||||||
} else if (args.size() > 0 && (args.get(0).equals("hostile") || args.get(0).equals("raider")
|
} else if (args.size() > 0 && (args.get(0).equals("hostile") || args.get(0).equals("raider")
|
||||||
|| args.get(0).equals("mob") || args.get(0).equals("custom"))) {
|
|| args.get(0).equals("mob") || args.get(0).equals("custom"))) {
|
||||||
LegacyAgent.customListMode = args.get(0);
|
LegacyAgent.customListMode = args.get(0);
|
||||||
sender.sendMessage(
|
sender.sendMessage(
|
||||||
"Successfully set the custom mob list type to " + ChatColor.BLUE + args.get(0) + ChatColor.RESET + ".");
|
"Successfully set the custom mob list type to " + ChatColor.BLUE + args.get(0) + ChatColor.RESET + ".");
|
||||||
} else
|
} else
|
||||||
sender.sendMessage("Usage: " + ChatColor.YELLOW + "/botenvironment mobListType (hostile|raider|mob|custom)" + ChatColor.RESET);
|
sender.sendMessage("Usage: " + ChatColor.YELLOW + "/botenvironment mobListType (hostile|raider|mob|custom)" + ChatColor.RESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autofill
|
@Autofill
|
||||||
public List<String> autofill(CommandSender sender, String[] args) {
|
public List<String> autofill(CommandSender sender, String[] args) {
|
||||||
List<String> output = new ArrayList<>();
|
List<String> output = new ArrayList<>();
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
if (args[0].equals("help")) {
|
if (args[0].equals("help")) {
|
||||||
output.add("blocks");
|
output.add("blocks");
|
||||||
output.add("mobs");
|
output.add("mobs");
|
||||||
} else if (matches(args[0], "addSolidGroup")) {
|
} else if (matches(args[0], "addSolidGroup")) {
|
||||||
output.addAll(getLoadedMods());
|
output.addAll(getLoadedMods());
|
||||||
} else if (matches(args[0], "addSolid") || matches(args[0], "removeSolid")) {
|
} else if (matches(args[0], "addSolid") || matches(args[0], "removeSolid")) {
|
||||||
for (Material mat : Material.values())
|
for (Material mat : Material.values())
|
||||||
if (!mat.isLegacy())
|
if (!mat.isLegacy())
|
||||||
output.add(mat.name());
|
output.add(mat.name());
|
||||||
} else if (matches(args[0], "addCustomMob") || matches(args[0], "removeCustomMob")) {
|
} else if (matches(args[0], "addCustomMob") || matches(args[0], "removeCustomMob")) {
|
||||||
for (EntityType type : EntityType.values())
|
for (EntityType type : EntityType.values())
|
||||||
if (type != EntityType.UNKNOWN)
|
if (type != EntityType.UNKNOWN)
|
||||||
output.add(type.name());
|
output.add(type.name());
|
||||||
} else if (matches(args[0], "mobListType")) {
|
} else if (matches(args[0], "mobListType")) {
|
||||||
output.add("hostile");
|
output.add("hostile");
|
||||||
output.add("raider");
|
output.add("raider");
|
||||||
output.add("mob");
|
output.add("mob");
|
||||||
output.add("custom");
|
output.add("custom");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean matches(String input, String check) {
|
private boolean matches(String input, String check) {
|
||||||
return input.equals(check) || input.equals(check.toLowerCase(Locale.ENGLISH));
|
return input.equals(check) || input.equals(check.toLowerCase(Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isLocationLoaded(Location loc) {
|
private boolean isLocationLoaded(Location loc) {
|
||||||
return loc.getWorld().isChunkLoaded(Location.locToBlock(loc.getX()) >> 4, Location.locToBlock(loc.getZ()) >> 4);
|
return loc.getWorld().isChunkLoaded(Location.locToBlock(loc.getX()) >> 4, Location.locToBlock(loc.getZ()) >> 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<String> getLoadedMods() {
|
private static Set<String> getLoadedMods() {
|
||||||
if (!loaded) {
|
if (!loaded) {
|
||||||
try {
|
try {
|
||||||
Object blocksRegistry = Class.forName("net.minecraftforge.registries.ForgeRegistries").getDeclaredField("BLOCKS").get(null);
|
Object blocksRegistry = Class.forName("net.minecraftforge.registries.ForgeRegistries").getDeclaredField("BLOCKS").get(null);
|
||||||
Set<Entry<ResourceKey<Block>, Block>> blockSet = (Set<Entry<ResourceKey<Block>, Block>>) Class.forName("net.minecraftforge.registries.IForgeRegistry").getMethod("getEntries").invoke(blocksRegistry);
|
Set<Entry<ResourceKey<Block>, Block>> blockSet = (Set<Entry<ResourceKey<Block>, Block>>) Class.forName("net.minecraftforge.registries.IForgeRegistry").getMethod("getEntries").invoke(blocksRegistry);
|
||||||
for (Entry<ResourceKey<Block>, Block> entry : blockSet) {
|
for (Entry<ResourceKey<Block>, Block> entry : blockSet) {
|
||||||
String namespace = entry.getKey().location().getNamespace();
|
String namespace = entry.getKey().location().getNamespace();
|
||||||
if (!namespace.equals(NamespacedKey.MINECRAFT))
|
if (!namespace.equals(NamespacedKey.MINECRAFT))
|
||||||
LOADED_MODS.add(namespace.toUpperCase() + "_");
|
LOADED_MODS.add(namespace.toUpperCase() + "_");
|
||||||
}
|
}
|
||||||
|
|
||||||
Object itemsRegistry = Class.forName("net.minecraftforge.registries.ForgeRegistries").getDeclaredField("ITEMS").get(null);
|
Object itemsRegistry = Class.forName("net.minecraftforge.registries.ForgeRegistries").getDeclaredField("ITEMS").get(null);
|
||||||
Set<Entry<ResourceKey<Item>, Item>> itemSet = (Set<Entry<ResourceKey<Item>, Item>>) Class.forName("net.minecraftforge.registries.IForgeRegistry").getMethod("getEntries").invoke(itemsRegistry);
|
Set<Entry<ResourceKey<Item>, Item>> itemSet = (Set<Entry<ResourceKey<Item>, Item>>) Class.forName("net.minecraftforge.registries.IForgeRegistry").getMethod("getEntries").invoke(itemsRegistry);
|
||||||
for (Entry<ResourceKey<Item>, Item> entry : itemSet) {
|
for (Entry<ResourceKey<Item>, Item> entry : itemSet) {
|
||||||
String namespace = entry.getKey().location().getNamespace();
|
String namespace = entry.getKey().location().getNamespace();
|
||||||
if (!namespace.equals(NamespacedKey.MINECRAFT))
|
if (!namespace.equals(NamespacedKey.MINECRAFT))
|
||||||
LOADED_MODS.add(namespace.toUpperCase() + "_");
|
LOADED_MODS.add(namespace.toUpperCase() + "_");
|
||||||
}
|
}
|
||||||
} catch (ReflectiveOperationException e) {}
|
} catch (ReflectiveOperationException e) {}
|
||||||
loaded = true;
|
loaded = true;
|
||||||
}
|
}
|
||||||
return LOADED_MODS;
|
return LOADED_MODS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,18 +35,18 @@ public class Debugger {
|
|||||||
public static final Set<String> AUTOFILL_METHODS = new HashSet<>();
|
public static final Set<String> AUTOFILL_METHODS = new HashSet<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
for (Method method : Debugger.class.getDeclaredMethods()) {
|
for (Method method : Debugger.class.getDeclaredMethods()) {
|
||||||
if (!method.getName().equals("print") && !method.getName().equals("execute") && !method.getName().equals("buildObjects")
|
if (!method.getName().equals("print") && !method.getName().equals("execute") && !method.getName().equals("buildObjects")
|
||||||
&& !method.getName().startsWith("lambda$")) {
|
&& !method.getName().startsWith("lambda$")) {
|
||||||
String autofill = method.getName() + "(";
|
String autofill = method.getName() + "(";
|
||||||
for (Parameter par : method.getParameters()) {
|
for (Parameter par : method.getParameters()) {
|
||||||
autofill += par.getType().getSimpleName() + ",";
|
autofill += par.getType().getSimpleName() + ",";
|
||||||
}
|
}
|
||||||
autofill = method.getParameters().length > 0 ? autofill.substring(0, autofill.length() - 1) : autofill;
|
autofill = method.getParameters().length > 0 ? autofill.substring(0, autofill.length() - 1) : autofill;
|
||||||
autofill += ")";
|
autofill += ")";
|
||||||
AUTOFILL_METHODS.add(autofill);
|
AUTOFILL_METHODS.add(autofill);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Debugger(CommandSender sender) {
|
public Debugger(CommandSender sender) {
|
||||||
@@ -478,7 +478,7 @@ public class Debugger {
|
|||||||
|
|
||||||
print("The Bot Agent is now " + (b ? ChatColor.RED + "DISABLED" : ChatColor.GREEN + "ENABLED") + ChatColor.RESET + ".");
|
print("The Bot Agent is now " + (b ? ChatColor.RED + "DISABLED" : ChatColor.GREEN + "ENABLED") + ChatColor.RESET + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printSurroundingMobs(double dist) {
|
public void printSurroundingMobs(double dist) {
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
print("You must be a player to call this.");
|
print("You must be a player to call this.");
|
||||||
@@ -488,10 +488,10 @@ public class Debugger {
|
|||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
double distSq = Math.pow(dist, 2);
|
double distSq = Math.pow(dist, 2);
|
||||||
for (Entity en : player.getWorld().getEntities()) {
|
for (Entity en : player.getWorld().getEntities()) {
|
||||||
Location loc = en.getLocation();
|
Location loc = en.getLocation();
|
||||||
if (loc.distanceSquared(player.getLocation()) < distSq)
|
if (loc.distanceSquared(player.getLocation()) < distSq)
|
||||||
print(String.format("Entity at " + ChatColor.BLUE + "(%d, %d, %d)" + ChatColor.RESET + ": Type " + ChatColor.GREEN + "%s" + ChatColor.RESET,
|
print(String.format("Entity at " + ChatColor.BLUE + "(%d, %d, %d)" + ChatColor.RESET + ": Type " + ChatColor.GREEN + "%s" + ChatColor.RESET,
|
||||||
loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), en.getType().toString()));
|
loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), en.getType().toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user