diff --git a/TerminatorPlus-API/build.gradle.kts b/TerminatorPlus-API/build.gradle.kts new file mode 100644 index 0000000..644f10d --- /dev/null +++ b/TerminatorPlus-API/build.gradle.kts @@ -0,0 +1,22 @@ +plugins { + id("java") +} + +group = "net.nuggetmc" +version = "3.2-BETA" + +repositories { + mavenCentral() + maven { + url = uri("https://repo.papermc.io/repository/maven-public/") + } + maven { + name = "minecraft-repo" + url = uri("https://libraries.minecraft.net/") + } +} + +dependencies { + compileOnly("io.papermc.paper:paper-api:1.18.1-R0.1-SNAPSHOT") + compileOnly("com.mojang:authlib:3.2.38") +} diff --git a/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/AIManager.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/AIManager.java new file mode 100644 index 0000000..de3c6e2 --- /dev/null +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/AIManager.java @@ -0,0 +1,5 @@ +package net.nuggetmc.tplus.api; + +public interface AIManager { + void clearSession(); +} diff --git a/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/BotManager.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/BotManager.java new file mode 100644 index 0000000..71927c4 --- /dev/null +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/BotManager.java @@ -0,0 +1,50 @@ +package net.nuggetmc.tplus.api; + +import net.nuggetmc.tplus.api.agent.Agent; +import net.nuggetmc.tplus.api.agent.legacyagent.ai.NeuralNetwork; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.Set; +import java.util.UUID; + +public interface BotManager { + Set fetch(); + + Agent getAgent(); + + void add(Terminator bot); + + Terminator getFirst(String name); + + List fetchNames(); + + void createBots(Player sender, String name, String skinName, int n); + + void createBots(Player sender, String name, String skinName, int n, NeuralNetwork network); + + Set createBots(Location loc, String name, String[] skin, List networks); + + Set createBots(Location loc, String name, String[] skin, int n, NeuralNetwork network); + + void remove(Terminator bot); + + void reset(); + + /** + * Get a bot from a Player object + * + * @param player + * @return + * @deprecated Use {@link #getBot(UUID)} instead as this may no longer work + */ + @Deprecated + Terminator getBot(Player player); + + Terminator getBot(UUID uuid); + + Terminator getBot(int entityId); + + +} diff --git a/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/InternalBridge.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/InternalBridge.java new file mode 100644 index 0000000..35e9e27 --- /dev/null +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/InternalBridge.java @@ -0,0 +1,13 @@ +package net.nuggetmc.tplus.api; + +import org.bukkit.Sound; +import org.bukkit.block.Block; + +/** + * This class serves as a bridge between the API and internal code that interacts with NMS. + */ +public interface InternalBridge { + void sendBlockDestructionPacket(short entityId, int x, int y, int z, int progress); + + Sound breakBlockSound(Block block); +} diff --git a/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/Terminator.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/Terminator.java new file mode 100644 index 0000000..615b948 --- /dev/null +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/Terminator.java @@ -0,0 +1,113 @@ +package net.nuggetmc.tplus.api; + +import com.mojang.authlib.GameProfile; +import net.nuggetmc.tplus.api.agent.legacyagent.ai.NeuralNetwork; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; + +public interface Terminator { + + String getBotName(); + + int getEntityId(); + + GameProfile getGameProfile(); + + LivingEntity getBukkitEntity(); + + NeuralNetwork getNeuralNetwork(); + + void setNeuralNetwork(NeuralNetwork neuralNetwork); + + boolean hasNeuralNetwork(); + + Location getLocation(); + + boolean isBotAlive(); //Has to be named like this because paper re-obfuscates it + + float getBotHealth(); + + float getBotMaxHealth(); + + void ignite(); + + boolean isBotOnFire(); + + boolean isFalling(); + + boolean isBotBlocking(); + + void block(int length, int cooldown); + + boolean isBotInWater(); + + boolean isBotOnGround(); + + void setBotPitch(float pitch); + + default void setBotXRot(float pitch) { + setBotPitch(pitch); + } + + void jump(Vector velocity); + + void jump(); + + void walk(Vector velocity); + + void look(BlockFace face); + + void faceLocation(Location location); + + void attack(Entity target); + + void attemptBlockPlace(Location loc, Material type, boolean down); + + void punch(); + + void swim(); + + void sneak(); + + void stand(); + + void addFriction(double factor); + + void removeVisually(); + + void removeBot(); + + int getKills(); + + void incrementKills(); + + void setItem(ItemStack item); + + void setItem(ItemStack item, EquipmentSlot slot); + + void setItemOffhand(ItemStack item); + + void setDefaultItem(ItemStack item); + + Vector getOffset(); + + Vector getVelocity(); + + void setVelocity(Vector velocity); + + void addVelocity(Vector velocity); + + int getAliveTicks(); + + boolean tickDelay(int ticks); + + void renderBot(Object packetListener, boolean login); + + void setOnFirePackets(boolean onFire); +} diff --git a/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/TerminatorPlusAPI.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/TerminatorPlusAPI.java new file mode 100644 index 0000000..0a7022d --- /dev/null +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/TerminatorPlusAPI.java @@ -0,0 +1,22 @@ +package net.nuggetmc.tplus.api; + +public class TerminatorPlusAPI { + private static InternalBridge internalBridge; + private static BotManager botManager; + + public static InternalBridge getInternalBridge() { + return internalBridge; + } + + public static void setInternalBridge(InternalBridge internalBridge) { + TerminatorPlusAPI.internalBridge = internalBridge; + } + + public static BotManager getBotManager() { + return botManager; + } + + public static void setBotManager(BotManager botManager) { + TerminatorPlusAPI.botManager = botManager; + } +} diff --git a/src/main/java/net/nuggetmc/tplus/bot/agent/Agent.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/Agent.java similarity index 68% rename from src/main/java/net/nuggetmc/tplus/bot/agent/Agent.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/Agent.java index 926c650..6cbcd46 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/agent/Agent.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/Agent.java @@ -1,14 +1,14 @@ -package net.nuggetmc.tplus.bot.agent; +package net.nuggetmc.tplus.api.agent; -import net.nuggetmc.tplus.TerminatorPlus; -import net.nuggetmc.tplus.bot.Bot; -import net.nuggetmc.tplus.bot.BotManager; -import net.nuggetmc.tplus.bot.event.BotDamageByPlayerEvent; -import net.nuggetmc.tplus.bot.event.BotDeathEvent; -import net.nuggetmc.tplus.bot.event.BotFallDamageEvent; -import net.nuggetmc.tplus.bot.event.BotKilledByPlayerEvent; +import net.nuggetmc.tplus.api.BotManager; +import net.nuggetmc.tplus.api.Terminator; +import net.nuggetmc.tplus.api.event.BotDamageByPlayerEvent; +import net.nuggetmc.tplus.api.event.BotDeathEvent; +import net.nuggetmc.tplus.api.event.BotFallDamageEvent; +import net.nuggetmc.tplus.api.event.BotKilledByPlayerEvent; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitScheduler; @@ -18,7 +18,7 @@ import java.util.Set; public abstract class Agent { - protected final TerminatorPlus plugin; + protected final Plugin plugin; protected final BotManager manager; protected final BukkitScheduler scheduler; protected final Set taskList; @@ -29,8 +29,8 @@ public abstract class Agent { protected boolean drops; - public Agent(BotManager manager) { - this.plugin = TerminatorPlus.getInstance(); + public Agent(BotManager manager, Plugin plugin) { + this.plugin = plugin; this.manager = manager; this.scheduler = Bukkit.getScheduler(); this.taskList = new HashSet<>(); @@ -67,17 +67,20 @@ public abstract class Agent { protected abstract void tick(); - public void onFallDamage(BotFallDamageEvent event) { } + public void onFallDamage(BotFallDamageEvent event) { + } - public void onPlayerDamage(BotDamageByPlayerEvent event) { } + public void onPlayerDamage(BotDamageByPlayerEvent event) { + } - public void onBotDeath(BotDeathEvent event) { } + public void onBotDeath(BotDeathEvent event) { + } public void onBotKilledByPlayer(BotKilledByPlayerEvent event) { Player player = event.getPlayer(); scheduler.runTaskAsynchronously(plugin, () -> { - Bot bot = manager.getBot(player); + Terminator bot = manager.getBot(player); if (bot != null) { bot.incrementKills(); diff --git a/src/main/java/net/nuggetmc/tplus/bot/agent/botagent/BotAgent.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/botagent/BotAgent.java similarity index 83% rename from src/main/java/net/nuggetmc/tplus/bot/agent/botagent/BotAgent.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/botagent/BotAgent.java index 759beb0..bac02ec 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/agent/botagent/BotAgent.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/botagent/BotAgent.java @@ -1,13 +1,14 @@ -package net.nuggetmc.tplus.bot.agent.botagent; +package net.nuggetmc.tplus.api.agent.botagent; -import net.nuggetmc.tplus.bot.Bot; -import net.nuggetmc.tplus.bot.BotManager; -import net.nuggetmc.tplus.bot.agent.Agent; -import net.nuggetmc.tplus.utils.MathUtils; -import net.nuggetmc.tplus.utils.PlayerUtils; +import net.nuggetmc.tplus.api.BotManager; +import net.nuggetmc.tplus.api.Terminator; +import net.nuggetmc.tplus.api.agent.Agent; +import net.nuggetmc.tplus.api.utils.MathUtils; +import net.nuggetmc.tplus.api.utils.PlayerUtils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; import org.bukkit.util.Vector; import java.util.Set; @@ -22,20 +23,20 @@ public class BotAgent extends Agent { private int count; - public BotAgent(BotManager manager) { - super(manager); + public BotAgent(BotManager manager, Plugin plugin) { + super(manager, plugin); } @Override protected void tick() { - Set bots = manager.fetch(); + Set bots = manager.fetch(); count = bots.size(); bots.forEach(this::tickBot); } // This is where the code starts to get spicy - private void tickBot(Bot bot) { - if (!bot.isAlive()) return; + private void tickBot(Terminator bot) { + if (!bot.isBotAlive()) return; Location loc = bot.getLocation(); @@ -90,17 +91,18 @@ public class BotAgent extends Agent { if (bot.tickDelay(3)) attack(bot, player, loc); } - private void attack(Bot bot, Player player, Location loc) { - if (PlayerUtils.isInvincible(player.getGameMode()) || player.getNoDamageTicks() >= 5 || loc.distance(player.getLocation()) >= 4) return; + private void attack(Terminator bot, Player player, Location loc) { + if (PlayerUtils.isInvincible(player.getGameMode()) || player.getNoDamageTicks() >= 5 || loc.distance(player.getLocation()) >= 4) + return; bot.attack(player); } - private void move(Bot bot, Player player, Location loc, Location target) { + private void move(Terminator bot, Player player, Location loc, Location target) { Vector vel = target.toVector().subtract(loc.toVector()).normalize(); if (bot.tickDelay(5)) bot.faceLocation(player.getLocation()); - if (!bot.isOnGround()) return; // calling this a second time later on + if (!bot.isBotOnGround()) return; // calling this a second time later on bot.stand(); // eventually create a memory system so packets do not have to be sent every tick bot.setItem(null); // method to check item in main hand, bot.getItemInHand() diff --git a/src/main/java/net/nuggetmc/tplus/bot/agent/botagent/BotSituation.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/botagent/BotSituation.java similarity index 71% rename from src/main/java/net/nuggetmc/tplus/bot/agent/botagent/BotSituation.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/botagent/BotSituation.java index 2aded0e..f94a8d1 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/agent/botagent/BotSituation.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/botagent/BotSituation.java @@ -1,6 +1,6 @@ -package net.nuggetmc.tplus.bot.agent.botagent; +package net.nuggetmc.tplus.api.agent.botagent; -import net.nuggetmc.tplus.bot.Bot; +import net.nuggetmc.tplus.api.Terminator; import org.bukkit.Location; public class BotSituation { @@ -11,7 +11,7 @@ public class BotSituation { * aboveGround */ - public BotSituation(Bot bot, Location target) { + public BotSituation(Terminator bot, Location target) { Location loc = bot.getLocation(); this.disp = VerticalDisplacement.fetch(loc.getBlockY(), target.getBlockY()); diff --git a/src/main/java/net/nuggetmc/tplus/bot/agent/botagent/VerticalDisplacement.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/botagent/VerticalDisplacement.java similarity index 85% rename from src/main/java/net/nuggetmc/tplus/bot/agent/botagent/VerticalDisplacement.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/botagent/VerticalDisplacement.java index 709e679..57a3cbc 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/agent/botagent/VerticalDisplacement.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/botagent/VerticalDisplacement.java @@ -1,4 +1,4 @@ -package net.nuggetmc.tplus.bot.agent.botagent; +package net.nuggetmc.tplus.api.agent.botagent; public enum VerticalDisplacement { AT, diff --git a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/EnumTargetGoal.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/EnumTargetGoal.java similarity index 96% rename from src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/EnumTargetGoal.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/EnumTargetGoal.java index 1380953..1f9c71e 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/EnumTargetGoal.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/EnumTargetGoal.java @@ -1,4 +1,4 @@ -package net.nuggetmc.tplus.bot.agent.legacyagent; +package net.nuggetmc.tplus.api.agent.legacyagent; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/LegacyAgent.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyAgent.java similarity index 82% rename from src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/LegacyAgent.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyAgent.java index 6546b32..4a5f1af 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/LegacyAgent.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyAgent.java @@ -1,29 +1,23 @@ -package net.nuggetmc.tplus.bot.agent.legacyagent; +package net.nuggetmc.tplus.api.agent.legacyagent; -import net.minecraft.core.BlockPos; -import net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket; -import net.nuggetmc.tplus.bot.Bot; -import net.nuggetmc.tplus.bot.BotManager; -import net.nuggetmc.tplus.bot.agent.Agent; -import net.nuggetmc.tplus.bot.agent.legacyagent.ai.BotData; -import net.nuggetmc.tplus.bot.agent.legacyagent.ai.BotNode; -import net.nuggetmc.tplus.bot.agent.legacyagent.ai.NeuralNetwork; -import net.nuggetmc.tplus.bot.event.BotDamageByPlayerEvent; -import net.nuggetmc.tplus.bot.event.BotDeathEvent; -import net.nuggetmc.tplus.bot.event.BotFallDamageEvent; -import net.nuggetmc.tplus.utils.MathUtils; -import net.nuggetmc.tplus.utils.PlayerUtils; +import net.nuggetmc.tplus.api.BotManager; +import net.nuggetmc.tplus.api.Terminator; +import net.nuggetmc.tplus.api.TerminatorPlusAPI; +import net.nuggetmc.tplus.api.agent.Agent; +import net.nuggetmc.tplus.api.agent.legacyagent.ai.BotData; +import net.nuggetmc.tplus.api.agent.legacyagent.ai.BotNode; +import net.nuggetmc.tplus.api.agent.legacyagent.ai.NeuralNetwork; +import net.nuggetmc.tplus.api.event.BotDamageByPlayerEvent; +import net.nuggetmc.tplus.api.event.BotDeathEvent; +import net.nuggetmc.tplus.api.event.BotFallDamageEvent; +import net.nuggetmc.tplus.api.utils.MathUtils; +import net.nuggetmc.tplus.api.utils.PlayerUtils; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; -import org.bukkit.entity.Boat; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Mob; -import org.bukkit.entity.Monster; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; +import org.bukkit.entity.*; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; @@ -31,73 +25,71 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.regex.Pattern; // Yes, this code is very unoptimized, I know. public class LegacyAgent extends Agent { + private static final Pattern NAME_PATTERN = Pattern.compile("[^A-Za-z]+"); + public final Set noFace = new HashSet<>(); + public final Set noJump = new HashSet<>(); + public final Set slow = new HashSet<>(); private final LegacyBlockCheck blockCheck; - - private EnumTargetGoal goal; - - public boolean offsets = true; - - public LegacyAgent(BotManager manager) { - super(manager); - - this.goal = EnumTargetGoal.NEAREST_VULNERABLE_PLAYER; - this.blockCheck = new LegacyBlockCheck(this); - } - - private final Map miningAnim = new HashMap<>(); + private final Map miningAnim = new HashMap<>(); private final Set boats = new HashSet<>(); - - private final Map btList = new HashMap<>(); - private final Map btCheck = new HashMap<>(); - private final Map towerList = new HashMap<>(); - - private final Set boatCooldown = new HashSet<>(); + private final Map btList = new HashMap<>(); + private final Map btCheck = new HashMap<>(); + private final Map towerList = new HashMap<>(); + private final Set boatCooldown = new HashSet<>(); private final Map crackList = new HashMap<>(); private final Map mining = new HashMap<>(); + private final Set fallDamageCooldown = new HashSet<>(); + public boolean offsets = true; + private EnumTargetGoal goal; - private final Set fallDamageCooldown = new HashSet<>(); + public LegacyAgent(BotManager manager, Plugin plugin) { + super(manager, plugin); - public final Set noFace = new HashSet<>(); - public final Set noJump = new HashSet<>(); + this.goal = EnumTargetGoal.NEAREST_VULNERABLE_PLAYER; + this.blockCheck = new LegacyBlockCheck(this, plugin); + } - public final Set slow = new HashSet<>(); + private static boolean checkSideBreak(Material type) { + return !LegacyMats.BREAK.contains(type);// && !LegacyMats.LEAVES.contains(type); + } @Override protected void tick() { manager.fetch().forEach(this::tickBot); } - private void center(Bot bot) { - if (bot == null || !bot.isAlive()) { + private void center(Terminator bot) { + if (bot == null || !bot.isBotAlive()) { return; } - final Player botPlayer = bot.getBukkitEntity(); + final LivingEntity botEntity = bot.getBukkitEntity(); Location prev = null; - if (btList.containsKey(botPlayer)) { - prev = btList.get(botPlayer); + if (btList.containsKey(botEntity)) { + prev = btList.get(botEntity); } - Location loc = botPlayer.getLocation(); + Location loc = botEntity.getLocation(); if (prev != null) { if (loc.getBlockX() == prev.getBlockX() && loc.getBlockZ() == prev.getBlockZ()) { - btCheck.put(botPlayer, true); + btCheck.put(botEntity, true); } else { - btCheck.put(botPlayer, false); + btCheck.put(botEntity, false); } } - btList.put(botPlayer, loc); + btList.put(botEntity, loc); } - private void tickBot(Bot bot) { - if (!bot.isAlive()) { + private void tickBot(Terminator bot) { + if (!bot.isBotAlive()) { return; } @@ -118,7 +110,7 @@ public class LegacyAgent extends Agent { fallDamageCheck(bot); miscellaneousChecks(bot, livingTarget); - Player botPlayer = bot.getBukkitEntity(); + LivingEntity botPlayer = bot.getBukkitEntity(); Location target = offsets ? livingTarget.getLocation().add(bot.getOffset()) : livingTarget.getLocation(); boolean ai = bot.hasNeuralNetwork(); @@ -152,7 +144,7 @@ public class LegacyAgent extends Agent { if (btCheck.containsKey(botPlayer)) sameXZ = btCheck.get(botPlayer); - if (waterGround || bot.isOnGround() || onBoat(botPlayer)) { + if (waterGround || bot.isBotOnGround() || onBoat(botPlayer)) { byte sideResult = 1; if (towerList.containsKey(botPlayer)) { @@ -190,19 +182,17 @@ public class LegacyAgent extends Agent { case 2: if (!waterGround) move(bot, livingTarget, loc, target, ai); } - } - - else if (LegacyMats.WATER.contains(loc.getBlock().getType())) { + } else if (LegacyMats.WATER.contains(loc.getBlock().getType())) { swim(bot, target, botPlayer, livingTarget, LegacyMats.WATER.contains(loc.clone().add(0, -1, 0).getBlock().getType())); } } - private void move(Bot bot, LivingEntity livingTarget, Location loc, Location target, boolean ai) { + private void move(Terminator bot, LivingEntity livingTarget, Location loc, Location target, boolean ai) { Vector position = loc.toVector(); Vector vel = target.toVector().subtract(position).normalize(); if (bot.tickDelay(5)) bot.faceLocation(livingTarget.getLocation()); - if (!bot.isOnGround()) return; // calling this a second time later on + if (!bot.isBotOnGround()) return; // calling this a second time later on bot.stand(); // eventually create a memory system so packets do not have to be sent every tick bot.setItem(null); // method to check item in main hand, bot.getItemInHand() @@ -237,7 +227,7 @@ public class LegacyAgent extends Agent { NeuralNetwork network = bot.getNeuralNetwork(); if (network.dynamicLR()) { - if (bot.isBlocking()) { + if (bot.isBotBlocking()) { vel.multiply(0.6); } @@ -259,13 +249,11 @@ public class LegacyAgent extends Agent { return; } - } - - else { + } else { boolean left = network.check(BotNode.LEFT); boolean right = network.check(BotNode.RIGHT); - if (bot.isBlocking()) { + if (bot.isBotBlocking()) { vel.multiply(0.6); } @@ -294,7 +282,7 @@ public class LegacyAgent extends Agent { bot.jump(vel); } - private void fallDamageCheck(Bot bot) { + private void fallDamageCheck(Terminator bot) { if (bot.isFalling()) { bot.look(BlockFace.DOWN); @@ -319,13 +307,13 @@ public class LegacyAgent extends Agent { @Override public void onPlayerDamage(BotDamageByPlayerEvent event) { - Bot bot = event.getBot(); + Terminator bot = event.getBot(); Location loc = bot.getLocation(); Player player = event.getPlayer(); double dot = loc.toVector().subtract(player.getLocation().toVector()).normalize().dot(loc.getDirection()); - if (bot.isBlocking() && dot >= -0.1) { + if (bot.isBotBlocking() && dot >= -0.1) { player.getWorld().playSound(bot.getLocation(), Sound.ITEM_SHIELD_BLOCK, 1, 1); event.setCancelled(true); } @@ -333,7 +321,7 @@ public class LegacyAgent extends Agent { @Override public void onFallDamage(BotFallDamageEvent event) { - Bot bot = event.getBot(); + Terminator bot = event.getBot(); World world = bot.getBukkitEntity().getWorld(); bot.look(BlockFace.DOWN); @@ -380,8 +368,10 @@ public class LegacyAgent extends Agent { } } - private void swim(Bot bot, Location loc, Player playerNPC, LivingEntity target, boolean anim) { - playerNPC.setSneaking(false); + private void swim(Terminator bot, Location loc, LivingEntity playerNPC, LivingEntity target, boolean anim) { + if (playerNPC instanceof Player) { + ((Player) playerNPC).setSneaking(false); + } Location at = bot.getLocation(); @@ -412,8 +402,8 @@ public class LegacyAgent extends Agent { bot.addVelocity(vector); } - private void stopMining(Bot bot) { - Player playerNPC = bot.getBukkitEntity(); + private void stopMining(Terminator bot) { + LivingEntity playerNPC = bot.getBukkitEntity(); if (miningAnim.containsKey(playerNPC)) { BukkitRunnable task = miningAnim.get(playerNPC); if (task != null) { @@ -423,7 +413,7 @@ public class LegacyAgent extends Agent { } } - private byte checkSide(Bot npc, LivingEntity target, Player playerNPC) { // make it so they don't jump when checking side + private byte checkSide(Terminator npc, LivingEntity target, LivingEntity playerNPC) { // make it so they don't jump when checking side Location a = playerNPC.getEyeLocation(); Location b = target.getLocation().add(0, 1, 0); @@ -444,8 +434,8 @@ public class LegacyAgent extends Agent { } } - private LegacyLevel checkNearby(LivingEntity target, Bot npc) { - Player player = npc.getBukkitEntity(); + private LegacyLevel checkNearby(LivingEntity target, Terminator npc) { + LivingEntity player = npc.getBukkitEntity(); npc.faceLocation(target.getLocation()); @@ -508,11 +498,7 @@ public class LegacyAgent extends Agent { return level; } - private static boolean checkSideBreak(Material type) { - return !LegacyMats.BREAK.contains(type);// && !LegacyMats.LEAVES.contains(type); - } - - private boolean checkUp(Bot npc, LivingEntity target, Player playerNPC, Location loc, boolean c) { + private boolean checkUp(Terminator npc, LivingEntity target, LivingEntity playerNPC, Location loc, boolean c) { Location a = playerNPC.getLocation(); Location b = target.getLocation(); @@ -586,7 +572,7 @@ public class LegacyAgent extends Agent { } }, 5); - if (npc.isOnGround()) { + if (npc.isBotOnGround()) { if (target.getLocation().distance(playerNPC.getLocation()) < 16) { if (noJump.contains(playerNPC)) { @@ -607,7 +593,7 @@ public class LegacyAgent extends Agent { return true; } } else { - if (npc.isOnGround()) { + if (npc.isBotOnGround()) { Location locBlock = playerNPC.getLocation(); locBlock.setX(locBlock.getBlockX() + 0.5); locBlock.setZ(locBlock.getBlockZ() + 0.5); @@ -630,7 +616,7 @@ public class LegacyAgent extends Agent { npc.look(BlockFace.UP); preBreak(npc, playerNPC, block, LegacyLevel.ABOVE); - if (npc.isOnGround()) { + if (npc.isBotOnGround()) { Location locBlock = playerNPC.getLocation(); locBlock.setX(locBlock.getBlockX() + 0.5); locBlock.setZ(locBlock.getBlockZ() + 0.5); @@ -650,9 +636,10 @@ public class LegacyAgent extends Agent { return false; } - private boolean checkDown(Bot npc, Player player, Location loc, boolean c) { // possibly a looser check for c + private boolean checkDown(Terminator npc, LivingEntity player, Location loc, boolean c) { // possibly a looser check for c - if (LegacyUtils.checkFreeSpace(npc.getLocation(), loc) || LegacyUtils.checkFreeSpace(player.getEyeLocation(), loc)) return false; + if (LegacyUtils.checkFreeSpace(npc.getLocation(), loc) || LegacyUtils.checkFreeSpace(player.getEyeLocation(), loc)) + return false; if (c && npc.getLocation().getBlockY() > loc.getBlockY() + 1) { Block block = npc.getLocation().add(0, -1, 0).getBlock(); @@ -661,9 +648,7 @@ public class LegacyAgent extends Agent { downMine(npc, player, block); preBreak(npc, player, block, LegacyLevel.BELOW); return true; - } - - else { + } else { Location a = loc.clone(); Location b = player.getLocation(); @@ -684,7 +669,7 @@ public class LegacyAgent extends Agent { } } - private void downMine(Bot npc, Player player, Block block) { + private void downMine(Terminator npc, LivingEntity player, Block block) { if (!LegacyMats.NO_CRACK.contains(block.getType())) { Location locBlock = player.getLocation(); locBlock.setX(locBlock.getBlockX() + 0.5); @@ -697,7 +682,7 @@ public class LegacyAgent extends Agent { npc.setVelocity(vector); } - if (npc.isInWater()) { + if (npc.isBotInWater()) { Location locBlock = player.getLocation(); locBlock.setX(locBlock.getBlockX() + 0.5); locBlock.setZ(locBlock.getBlockZ() + 0.5); @@ -719,7 +704,7 @@ public class LegacyAgent extends Agent { } } - private boolean checkFence(Bot bot, Block block, Player player) { + private boolean checkFence(Terminator bot, Block block, LivingEntity player) { if (LegacyMats.FENCE.contains(block.getType())) { preBreak(bot, player, block, LegacyLevel.AT_D); return true; @@ -728,7 +713,7 @@ public class LegacyAgent extends Agent { return false; } - private boolean checkAt(Bot bot, Block block, Player player) { + private boolean checkAt(Terminator bot, Block block, LivingEntity player) { if (LegacyMats.BREAK.contains(block.getType())) { return false; } else { @@ -737,7 +722,7 @@ public class LegacyAgent extends Agent { } } - private void preBreak(Bot bot, Player player, Block block, LegacyLevel level) { + private void preBreak(Terminator bot, LivingEntity player, Block block, LegacyLevel level) { Material item; Material type = block.getType(); @@ -752,7 +737,7 @@ public class LegacyAgent extends Agent { bot.setItem(new ItemStack(item)); if (level == LegacyLevel.EAST_D || level == LegacyLevel.NORTH_D || level == LegacyLevel.SOUTH_D || level == LegacyLevel.WEST_D) { - bot.setXRot(69); + bot.setBotPitch(69); scheduler.runTaskLater(plugin, () -> { btCheck.put(player, true); @@ -768,7 +753,7 @@ public class LegacyAgent extends Agent { @Override public void run() { - bot.punch(); + bot.punch(); } }; @@ -780,7 +765,7 @@ public class LegacyAgent extends Agent { blockBreakEffect(player, block, level); } - private void blockBreakEffect(Player player, Block block, LegacyLevel level) { + private void blockBreakEffect(LivingEntity player, Block block, LegacyLevel level) { if (LegacyMats.NO_CRACK.contains(block.getType())) return; @@ -832,26 +817,10 @@ public class LegacyAgent extends Agent { // wow this repeated code is so bad lmao - if (player.isDead()) { + if (player.isDead() || (!block.equals(cur) || block.getType() != cur.getType())) { this.cancel(); - ClientboundBlockDestructionPacket crack = new ClientboundBlockDestructionPacket(crackList.get(block), new BlockPos(block.getX(), block.getY(), block.getZ()), -1); - for (Player all : Bukkit.getOnlinePlayers()) { - ((CraftPlayer) all).getHandle().connection.send(crack); - } - - crackList.remove(block); - mining.remove(this); - return; - } - - if (!block.equals(cur) || block.getType() != cur.getType()) { - this.cancel(); - - ClientboundBlockDestructionPacket crack = new ClientboundBlockDestructionPacket(crackList.get(block), new BlockPos(block.getX(), block.getY(), block.getZ()), -1); - for (Player all : Bukkit.getOnlinePlayers()) { - ((CraftPlayer) all).getHandle().connection.send(crack); - } + TerminatorPlusAPI.getInternalBridge().sendBlockDestructionPacket(crackList.get(block), block.getX(), block.getY(), block.getZ(), -1); crackList.remove(block); mining.remove(this); @@ -863,13 +832,12 @@ public class LegacyAgent extends Agent { if (i == 9) { this.cancel(); - ClientboundBlockDestructionPacket crack = new ClientboundBlockDestructionPacket(crackList.get(block), new BlockPos(block.getX(), block.getY(), block.getZ()), -1); - for (Player all : Bukkit.getOnlinePlayers()) { - ((CraftPlayer) all).getHandle().connection.send(crack); - } + TerminatorPlusAPI.getInternalBridge().sendBlockDestructionPacket(crackList.get(block), block.getX(), block.getY(), block.getZ(), -1); + if (sound != null) { - for (Player all : Bukkit.getOnlinePlayers()) all.playSound(block.getLocation(), sound, SoundCategory.BLOCKS, 1, 1); + for (Player all : Bukkit.getOnlinePlayers()) + all.playSound(block.getLocation(), sound, SoundCategory.BLOCKS, 1, 1); } block.breakNaturally(); @@ -888,15 +856,14 @@ public class LegacyAgent extends Agent { } if (sound != null) { - for (Player all : Bukkit.getOnlinePlayers()) all.playSound(block.getLocation(), sound, SoundCategory.BLOCKS, (float) 0.3, 1); + for (Player all : Bukkit.getOnlinePlayers()) + all.playSound(block.getLocation(), sound, SoundCategory.BLOCKS, (float) 0.3, 1); } - if (block.getType() == Material.BARRIER || block.getType() == Material.BEDROCK || block.getType() == Material.END_PORTAL_FRAME) return; + if (block.getType() == Material.BARRIER || block.getType() == Material.BEDROCK || block.getType() == Material.END_PORTAL_FRAME) + return; - ClientboundBlockDestructionPacket crack = new ClientboundBlockDestructionPacket(crackList.get(block), new BlockPos(block.getX(), block.getY(), block.getZ()), i); - for (Player all : Bukkit.getOnlinePlayers()) { - ((CraftPlayer) all).getHandle().connection.send(crack); - } + TerminatorPlusAPI.getInternalBridge().sendBlockDestructionPacket(crackList.get(block), block.getX(), block.getY(), block.getZ(), i); mining.put(this, (byte) (i + 1)); } @@ -909,7 +876,7 @@ public class LegacyAgent extends Agent { } } - private void placeWaterDown(Bot bot, World world, Location loc) { + private void placeWaterDown(Terminator bot, World world, Location loc) { if (loc.getBlock().getType() == Material.WATER) return; bot.look(BlockFace.DOWN); @@ -930,13 +897,13 @@ public class LegacyAgent extends Agent { }, 5); } - private void miscellaneousChecks(Bot bot, LivingEntity target) { - Player botPlayer = bot.getBukkitEntity(); + private void miscellaneousChecks(Terminator bot, LivingEntity target) { + LivingEntity botPlayer = bot.getBukkitEntity(); World world = botPlayer.getWorld(); String worldName = world.getName(); Location loc = bot.getLocation(); - if (bot.isOnFire()) { + if (bot.isBotOnFire()) { if (bot.getBukkitEntity().getWorld().getEnvironment() != World.Environment.NETHER) { placeWaterDown(bot, world, loc); } @@ -1068,7 +1035,7 @@ public class LegacyAgent extends Agent { scheduler.runTaskLater(plugin, () -> { boatCooldown.remove(bot); - if (bot.isAlive()) { + if (bot.isBotAlive()) { bot.faceLocation(target.getLocation()); } }, 5); @@ -1076,7 +1043,7 @@ public class LegacyAgent extends Agent { } } - private void resetHand(Bot npc, LivingEntity target, Player playerNPC) { + private void resetHand(Terminator npc, LivingEntity target, LivingEntity playerNPC) { if (!noFace.contains(npc)) { // LESSLAG if there is no if statement here npc.faceLocation(target.getLocation()); } @@ -1094,7 +1061,7 @@ public class LegacyAgent extends Agent { npc.setItem(null); } - private boolean onBoat(Player player) { + private boolean onBoat(LivingEntity player) { Set cache = new HashSet<>(); boolean check = false; @@ -1118,8 +1085,9 @@ public class LegacyAgent extends Agent { return check; } - private void attack(Bot bot, LivingEntity target, Location loc) { - if ((target instanceof Player && PlayerUtils.isInvincible(((Player) target).getGameMode())) || target.getNoDamageTicks() >= 5 || loc.distance(target.getLocation()) >= 4) return; + private void attack(Terminator bot, LivingEntity target, Location loc) { + if ((target instanceof Player && PlayerUtils.isInvincible(((Player) target).getGameMode())) || target.getNoDamageTicks() >= 5 || loc.distance(target.getLocation()) >= 4) + return; bot.attack(target); } @@ -1128,7 +1096,7 @@ public class LegacyAgent extends Agent { this.goal = goal; } - public LivingEntity locateTarget(Bot bot, Location loc) { + public LivingEntity locateTarget(Terminator bot, Location loc) { LivingEntity result = null; switch (goal) { @@ -1154,7 +1122,7 @@ public class LegacyAgent extends Agent { break; } - + case NEAREST_HOSTILE: { for (LivingEntity entity : bot.getBukkitEntity().getWorld().getLivingEntities()) { if (entity instanceof Monster && validateCloserEntity(entity, loc, result)) { @@ -1164,11 +1132,11 @@ public class LegacyAgent extends Agent { break; } - + case NEAREST_MOB: { for (LivingEntity entity : bot.getBukkitEntity().getWorld().getLivingEntities()) { if (entity instanceof Mob && validateCloserEntity(entity, loc, result)) { - result = entity; + result = entity; } } @@ -1176,9 +1144,9 @@ public class LegacyAgent extends Agent { } case NEAREST_BOT: { - for (Bot otherBot : manager.fetch()) { + for (Terminator otherBot : manager.fetch()) { if (bot != otherBot) { - Player player = otherBot.getBukkitEntity(); + LivingEntity player = otherBot.getBukkitEntity(); if (validateCloserEntity(player, loc, result)) { result = player; @@ -1190,13 +1158,13 @@ public class LegacyAgent extends Agent { } case NEAREST_BOT_DIFFER: { - String name = bot.getName().getString(); + String name = bot.getBotName(); - for (Bot otherBot : manager.fetch()) { + for (Terminator otherBot : manager.fetch()) { if (bot != otherBot) { - Player player = otherBot.getBukkitEntity(); + LivingEntity player = otherBot.getBukkitEntity(); - if (!name.equals(otherBot.getName()) && validateCloserEntity(player, loc, result)) { + if (!name.equals(otherBot.getBotName()) && validateCloserEntity(player, loc, result)) { result = player; } } @@ -1206,13 +1174,13 @@ public class LegacyAgent extends Agent { } case NEAREST_BOT_DIFFER_ALPHA: { - String name = bot.getName().getString().replaceAll("[^A-Za-z]+", ""); + String name = NAME_PATTERN.matcher(bot.getBotName()).replaceAll(""); - for (Bot otherBot : manager.fetch()) { + for (Terminator otherBot : manager.fetch()) { if (bot != otherBot) { - Player player = otherBot.getBukkitEntity(); + LivingEntity player = otherBot.getBukkitEntity(); - if (!name.equals(otherBot.getName().getString().replaceAll("[^A-Za-z]+", "")) && validateCloserEntity(player, loc, result)) { + if (!name.equals(NAME_PATTERN.matcher(otherBot.getBotName()).replaceAll("")) && validateCloserEntity(player, loc, result)) { result = player; } } diff --git a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/LegacyBlockCheck.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyBlockCheck.java similarity index 80% rename from src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/LegacyBlockCheck.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyBlockCheck.java index 543390c..a9c2d12 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/LegacyBlockCheck.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyBlockCheck.java @@ -1,13 +1,13 @@ -package net.nuggetmc.tplus.bot.agent.legacyagent; +package net.nuggetmc.tplus.api.agent.legacyagent; -import net.nuggetmc.tplus.TerminatorPlus; -import net.nuggetmc.tplus.bot.Bot; +import net.nuggetmc.tplus.api.Terminator; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; import java.util.Arrays; import java.util.HashSet; @@ -15,17 +15,18 @@ import java.util.Set; public class LegacyBlockCheck { - private final TerminatorPlus plugin; + private final Plugin plugin; private final LegacyAgent agent; - public LegacyBlockCheck(LegacyAgent agent) { - this.plugin = TerminatorPlus.getInstance(); + public LegacyBlockCheck(LegacyAgent agent, Plugin plugin) { + this.plugin = plugin; this.agent = agent; } - private void placeFinal(Bot bot, Player player, Location loc) { + private void placeFinal(Terminator bot, LivingEntity player, Location loc) { if (loc.getBlock().getType() != Material.COBBLESTONE) { - for (Player all : Bukkit.getOnlinePlayers()) all.playSound(loc, Sound.BLOCK_STONE_PLACE, SoundCategory.BLOCKS, 1, 1); + for (Player all : Bukkit.getOnlinePlayers()) + all.playSound(loc, Sound.BLOCK_STONE_PLACE, SoundCategory.BLOCKS, 1, 1); bot.setItem(new ItemStack(Material.COBBLESTONE)); loc.getBlock().setType(Material.COBBLESTONE); @@ -36,7 +37,7 @@ public class LegacyBlockCheck { } } - public void placeBlock(Bot bot, Player player, Block block) { + public void placeBlock(Terminator bot, LivingEntity player, Block block) { Location loc = block.getLocation(); @@ -116,23 +117,26 @@ public class LegacyBlockCheck { Bukkit.getScheduler().runTaskLater(plugin, () -> { Block b2 = loc.clone().add(0, -1, 0).getBlock(); if (LegacyMats.SPAWN.contains(b2.getType())) { - for (Player all : Bukkit.getOnlinePlayers()) all.playSound(loc, Sound.BLOCK_STONE_PLACE, SoundCategory.BLOCKS, 1, 1); + for (Player all : Bukkit.getOnlinePlayers()) + all.playSound(loc, Sound.BLOCK_STONE_PLACE, SoundCategory.BLOCKS, 1, 1); placeFinal(bot, player, b2.getLocation()); } }, 1); Bukkit.getScheduler().runTaskLater(plugin, () -> { - for (Player all : Bukkit.getOnlinePlayers()) all.playSound(loc, Sound.BLOCK_STONE_PLACE, SoundCategory.BLOCKS, 1, 1); + for (Player all : Bukkit.getOnlinePlayers()) + all.playSound(loc, Sound.BLOCK_STONE_PLACE, SoundCategory.BLOCKS, 1, 1); placeFinal(bot, player, block.getLocation()); }, 3); return; } - for (Player all : Bukkit.getOnlinePlayers()) all.playSound(loc, Sound.BLOCK_STONE_PLACE, SoundCategory.BLOCKS, 1, 1); + for (Player all : Bukkit.getOnlinePlayers()) + all.playSound(loc, Sound.BLOCK_STONE_PLACE, SoundCategory.BLOCKS, 1, 1); placeFinal(bot, player, block.getLocation()); } - public void clutch(Bot bot, LivingEntity target) { + public void clutch(Terminator bot, LivingEntity target) { Location botLoc = bot.getLocation(); Material type = botLoc.clone().add(0, -1, 0).getBlock().getType(); @@ -144,10 +148,10 @@ public class LegacyBlockCheck { Location loc = botLoc.clone().add(0, -1, 0); Set face = new HashSet<>(Arrays.asList( - loc.clone().add(1, 0, 0).getBlock(), - loc.clone().add(-1, 0, 0).getBlock(), - loc.clone().add(0, 0, 1).getBlock(), - loc.clone().add(0, 0, -1).getBlock() + loc.clone().add(1, 0, 0).getBlock(), + loc.clone().add(-1, 0, 0).getBlock(), + loc.clone().add(0, 0, 1).getBlock(), + loc.clone().add(0, 0, -1).getBlock() )); Location at = null; @@ -181,7 +185,8 @@ public class LegacyBlockCheck { bot.punch(); bot.sneak(); - for (Player all : Bukkit.getOnlinePlayers()) all.playSound(loc, Sound.BLOCK_STONE_PLACE, SoundCategory.BLOCKS, 1, 1); + for (Player all : Bukkit.getOnlinePlayers()) + all.playSound(loc, Sound.BLOCK_STONE_PLACE, SoundCategory.BLOCKS, 1, 1); bot.setItem(new ItemStack(Material.COBBLESTONE)); loc.getBlock().setType(Material.COBBLESTONE); } diff --git a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/LegacyItems.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyItems.java similarity index 83% rename from src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/LegacyItems.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyItems.java index c2edda4..2b307d5 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/LegacyItems.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyItems.java @@ -1,4 +1,4 @@ -package net.nuggetmc.tplus.bot.agent.legacyagent; +package net.nuggetmc.tplus.api.agent.legacyagent; import org.bukkit.Material; diff --git a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/LegacyLevel.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyLevel.java similarity index 91% rename from src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/LegacyLevel.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyLevel.java index e0a89f2..b4f622e 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/LegacyLevel.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyLevel.java @@ -1,4 +1,4 @@ -package net.nuggetmc.tplus.bot.agent.legacyagent; +package net.nuggetmc.tplus.api.agent.legacyagent; import java.util.Arrays; import java.util.HashSet; diff --git a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/LegacyMats.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyMats.java similarity index 99% rename from src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/LegacyMats.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyMats.java index c3e2b8f..53b2a5e 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/LegacyMats.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyMats.java @@ -1,4 +1,4 @@ -package net.nuggetmc.tplus.bot.agent.legacyagent; +package net.nuggetmc.tplus.api.agent.legacyagent; import org.bukkit.Material; diff --git a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/LegacyUtils.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyUtils.java similarity index 52% rename from src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/LegacyUtils.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyUtils.java index 24c2db7..d7c00b7 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/LegacyUtils.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyUtils.java @@ -1,17 +1,11 @@ -package net.nuggetmc.tplus.bot.agent.legacyagent; +package net.nuggetmc.tplus.api.agent.legacyagent; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.world.level.block.state.BlockState; +import net.nuggetmc.tplus.api.TerminatorPlusAPI; import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; import org.bukkit.util.Vector; -import java.lang.reflect.Field; - public class LegacyUtils { public static boolean checkFreeSpace(Location a, Location b) { @@ -38,12 +32,6 @@ public class LegacyUtils { } public static Sound breakBlockSound(Block block) { - Level nmsWorld = ((CraftWorld) block.getWorld()).getHandle(); - BlockState blockState = nmsWorld.getBlockState(new BlockPos(block.getX(), block.getY(), block.getZ())); - net.minecraft.world.level.block.Block nmsBlock = blockState.getBlock(); - - SoundType soundEffectType = nmsBlock.getSoundType(blockState); - - return Sound.valueOf( soundEffectType.getBreakSound().getLocation().getPath().replace(".", "_").toUpperCase()); + return TerminatorPlusAPI.getInternalBridge().breakBlockSound(block); } } diff --git a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/LegacyWorldManager.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyWorldManager.java similarity index 89% rename from src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/LegacyWorldManager.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyWorldManager.java index 549d3ed..45c67af 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/LegacyWorldManager.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyWorldManager.java @@ -1,4 +1,4 @@ -package net.nuggetmc.tplus.bot.agent.legacyagent; +package net.nuggetmc.tplus.api.agent.legacyagent; import org.bukkit.Location; import org.bukkit.Material; diff --git a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/ai/ActivationType.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/ai/ActivationType.java similarity index 62% rename from src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/ai/ActivationType.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/ai/ActivationType.java index 76bae1c..d16832d 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/ai/ActivationType.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/ai/ActivationType.java @@ -1,4 +1,4 @@ -package net.nuggetmc.tplus.bot.agent.legacyagent.ai; +package net.nuggetmc.tplus.api.agent.legacyagent.ai; public enum ActivationType { TANH, diff --git a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/ai/BotData.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/ai/BotData.java similarity index 78% rename from src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/ai/BotData.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/ai/BotData.java index 9be0ba9..4552196 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/ai/BotData.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/ai/BotData.java @@ -1,7 +1,7 @@ -package net.nuggetmc.tplus.bot.agent.legacyagent.ai; +package net.nuggetmc.tplus.api.agent.legacyagent.ai; -import net.nuggetmc.tplus.bot.Bot; -import net.nuggetmc.tplus.utils.MathUtils; +import net.nuggetmc.tplus.api.Terminator; +import net.nuggetmc.tplus.api.utils.MathUtils; import org.apache.commons.lang.StringUtils; import org.bukkit.Location; import org.bukkit.entity.LivingEntity; @@ -14,21 +14,21 @@ public class BotData { private final Map values; - private BotData(Bot bot, LivingEntity target) { + private BotData(Terminator bot, LivingEntity target) { this.values = new HashMap<>(); Location a = bot.getLocation(); Location b = target.getLocation(); - float health = bot.getHealth(); + float health = bot.getBotHealth(); values.put(BotDataType.CRITICAL_HEALTH, health >= 5 ? 0 : 5D - health); values.put(BotDataType.DISTANCE_XZ, Math.sqrt(MathUtils.square(a.getX() - b.getX()) + MathUtils.square(a.getZ() - b.getZ()))); values.put(BotDataType.DISTANCE_Y, b.getY() - a.getY()); - values.put(BotDataType.ENEMY_BLOCKING, target instanceof Player && ((Player)target).isBlocking() ? 1D : 0); + values.put(BotDataType.ENEMY_BLOCKING, target instanceof Player && ((Player) target).isBlocking() ? 1D : 0); } - public static BotData generate(Bot bot, LivingEntity target) { + public static BotData generate(Terminator bot, LivingEntity target) { return new BotData(bot, target); } diff --git a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/ai/BotDataType.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/ai/BotDataType.java similarity index 85% rename from src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/ai/BotDataType.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/ai/BotDataType.java index 5145a45..c6ab0fd 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/ai/BotDataType.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/ai/BotDataType.java @@ -1,4 +1,4 @@ -package net.nuggetmc.tplus.bot.agent.legacyagent.ai; +package net.nuggetmc.tplus.api.agent.legacyagent.ai; public enum BotDataType { CRITICAL_HEALTH("h"), diff --git a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/ai/BotNode.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/ai/BotNode.java similarity index 77% rename from src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/ai/BotNode.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/ai/BotNode.java index 6569d46..a168b53 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/ai/BotNode.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/ai/BotNode.java @@ -1,4 +1,4 @@ -package net.nuggetmc.tplus.bot.agent.legacyagent.ai; +package net.nuggetmc.tplus.api.agent.legacyagent.ai; public enum BotNode { BLOCK, // block (can't attack while blocking) diff --git a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/ai/IntelligenceAgent.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/ai/IntelligenceAgent.java similarity index 86% rename from src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/ai/IntelligenceAgent.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/ai/IntelligenceAgent.java index b7efe26..a45b9b4 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/ai/IntelligenceAgent.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/ai/IntelligenceAgent.java @@ -1,21 +1,20 @@ -package net.nuggetmc.tplus.bot.agent.legacyagent.ai; +package net.nuggetmc.tplus.api.agent.legacyagent.ai; -import net.minecraft.world.entity.LivingEntity; -import net.nuggetmc.tplus.TerminatorPlus; -import net.nuggetmc.tplus.bot.Bot; -import net.nuggetmc.tplus.bot.BotManager; -import net.nuggetmc.tplus.bot.agent.legacyagent.EnumTargetGoal; -import net.nuggetmc.tplus.bot.agent.legacyagent.LegacyAgent; -import net.nuggetmc.tplus.command.commands.AICommand; -import net.nuggetmc.tplus.utils.ChatUtils; -import net.nuggetmc.tplus.utils.MathUtils; -import net.nuggetmc.tplus.utils.MojangAPI; -import net.nuggetmc.tplus.utils.PlayerUtils; +import net.nuggetmc.tplus.api.AIManager; +import net.nuggetmc.tplus.api.BotManager; +import net.nuggetmc.tplus.api.Terminator; +import net.nuggetmc.tplus.api.agent.legacyagent.EnumTargetGoal; +import net.nuggetmc.tplus.api.agent.legacyagent.LegacyAgent; +import net.nuggetmc.tplus.api.utils.ChatUtils; +import net.nuggetmc.tplus.api.utils.MathUtils; +import net.nuggetmc.tplus.api.utils.MojangAPI; +import net.nuggetmc.tplus.api.utils.PlayerUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitScheduler; import java.text.NumberFormat; @@ -32,9 +31,9 @@ public class IntelligenceAgent { * default anchor location, /ai relocateanchor */ - private final TerminatorPlus plugin; + private final Plugin plugin; private final BotManager manager; - private final AICommand aiManager; + private final AIManager aiManager; private final BukkitScheduler scheduler; private LegacyAgent agent; @@ -47,7 +46,7 @@ public class IntelligenceAgent { private final String botSkin; private final int cutoff; - private final Map bots; + private final Map bots; private int populationSize; private int generation; @@ -57,9 +56,9 @@ public class IntelligenceAgent { private final Set users; private final Map>>> genProfiles; - public IntelligenceAgent(AICommand aiManager, int populationSize, String name, String skin) { - this.plugin = TerminatorPlus.getInstance(); - this.manager = plugin.getManager(); + public IntelligenceAgent(AIManager aiManager, int populationSize, String name, String skin, Plugin plugin, BotManager manager) { + this.plugin = plugin; + this.manager = manager; this.aiManager = aiManager; this.scheduler = Bukkit.getScheduler(); this.name = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss").format(Calendar.getInstance().getTime()); @@ -122,7 +121,7 @@ public class IntelligenceAgent { Location loc = PlayerUtils.findAbove(primary.getLocation(), 20); scheduler.runTask(plugin, () -> { - Set bots; + Set bots; if (loadedProfiles == null) { bots = manager.createBots(loc, botName, skinData, populationSize, NeuralNetwork.RANDOM); @@ -141,7 +140,7 @@ public class IntelligenceAgent { } bots.forEach(bot -> { - String name = bot.getName().getString(); + String name = bot.getBotName(); while (this.bots.containsKey(name)) { name += "_"; @@ -166,22 +165,22 @@ public class IntelligenceAgent { print("Generation " + ChatColor.RED + generation + ChatColor.RESET + " has ended."); - HashMap values = new HashMap<>(); + HashMap values = new HashMap<>(); - for (Bot bot : bots.values()) { + for (Terminator bot : bots.values()) { values.put(bot, bot.getAliveTicks()); } - List> sorted = MathUtils.sortByValue(values); - Set winners = new HashSet<>(); + List> sorted = MathUtils.sortByValue(values); + Set winners = new HashSet<>(); int i = 1; - for (Map.Entry entry : sorted) { - Bot bot = entry.getKey(); + for (Map.Entry entry : sorted) { + Terminator bot = entry.getKey(); boolean check = i <= cutoff; if (check) { - print(ChatColor.GRAY + "[" + ChatColor.YELLOW + "#" + i + ChatColor.GRAY + "] " + ChatColor.GREEN + bot.getName() + print(ChatColor.GRAY + "[" + ChatColor.YELLOW + "#" + i + ChatColor.GRAY + "] " + ChatColor.GREEN + bot.getBotName() + ChatUtils.BULLET_FORMATTED + ChatColor.RED + bot.getKills() + " kills"); winners.add(bot); } @@ -245,7 +244,7 @@ public class IntelligenceAgent { } private int aliveCount() { - return (int) bots.values().stream().filter(LivingEntity::isAlive).count(); + return (int) bots.values().stream().filter(Terminator::isBotAlive).count(); } private void close() { @@ -327,7 +326,7 @@ public class IntelligenceAgent { if (!bots.isEmpty()) { print("Removing all cached bots..."); - bots.values().forEach(Bot::removeVisually); + bots.values().forEach(Terminator::removeBot); bots.clear(); } diff --git a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/ai/NeuralNetwork.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/ai/NeuralNetwork.java similarity index 95% rename from src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/ai/NeuralNetwork.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/ai/NeuralNetwork.java index 4e95195..3e4d638 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/ai/NeuralNetwork.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/ai/NeuralNetwork.java @@ -1,8 +1,8 @@ -package net.nuggetmc.tplus.bot.agent.legacyagent.ai; +package net.nuggetmc.tplus.api.agent.legacyagent.ai; import net.md_5.bungee.api.ChatColor; -import net.nuggetmc.tplus.utils.MathUtils; -import net.nuggetmc.tplus.utils.ChatUtils; +import net.nuggetmc.tplus.api.utils.ChatUtils; +import net.nuggetmc.tplus.api.utils.MathUtils; import org.apache.commons.lang.StringUtils; import java.util.*; diff --git a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/ai/NodeConnections.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/ai/NodeConnections.java similarity index 97% rename from src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/ai/NodeConnections.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/ai/NodeConnections.java index f9f2221..d809d16 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/agent/legacyagent/ai/NodeConnections.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/ai/NodeConnections.java @@ -1,4 +1,4 @@ -package net.nuggetmc.tplus.bot.agent.legacyagent.ai; +package net.nuggetmc.tplus.api.agent.legacyagent.ai; import java.util.Arrays; import java.util.HashMap; diff --git a/src/main/java/net/nuggetmc/tplus/bot/event/BotDamageByPlayerEvent.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/event/BotDamageByPlayerEvent.java similarity index 74% rename from src/main/java/net/nuggetmc/tplus/bot/event/BotDamageByPlayerEvent.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/event/BotDamageByPlayerEvent.java index eeea05c..ee7886f 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/event/BotDamageByPlayerEvent.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/event/BotDamageByPlayerEvent.java @@ -1,24 +1,24 @@ -package net.nuggetmc.tplus.bot.event; +package net.nuggetmc.tplus.api.event; -import net.nuggetmc.tplus.bot.Bot; +import net.nuggetmc.tplus.api.Terminator; import org.bukkit.entity.Player; public class BotDamageByPlayerEvent { - private final Bot bot; + private final Terminator bot; private final Player player; private float damage; private boolean cancelled; - public BotDamageByPlayerEvent(Bot bot, Player player, float damage) { + public BotDamageByPlayerEvent(Terminator bot, Player player, float damage) { this.bot = bot; this.player = player; this.damage = damage; } - public Bot getBot() { + public Terminator getBot() { return bot; } diff --git a/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/event/BotDeathEvent.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/event/BotDeathEvent.java new file mode 100644 index 0000000..cd407ce --- /dev/null +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/event/BotDeathEvent.java @@ -0,0 +1,18 @@ +package net.nuggetmc.tplus.api.event; + +import net.nuggetmc.tplus.api.Terminator; +import org.bukkit.event.entity.EntityDeathEvent; + +public class BotDeathEvent extends EntityDeathEvent { + + private final Terminator bot; + + public BotDeathEvent(EntityDeathEvent event, Terminator bot) { + super(event.getEntity(), event.getDrops(), event.getDroppedExp()); + this.bot = bot; + } + + public Terminator getBot() { + return bot; + } +} diff --git a/src/main/java/net/nuggetmc/tplus/bot/event/BotFallDamageEvent.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/event/BotFallDamageEvent.java similarity index 59% rename from src/main/java/net/nuggetmc/tplus/bot/event/BotFallDamageEvent.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/event/BotFallDamageEvent.java index 4b710d6..d46f7d3 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/event/BotFallDamageEvent.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/event/BotFallDamageEvent.java @@ -1,26 +1,26 @@ -package net.nuggetmc.tplus.bot.event; +package net.nuggetmc.tplus.api.event; -import net.nuggetmc.tplus.bot.Bot; +import net.nuggetmc.tplus.api.Terminator; public class BotFallDamageEvent { - private final Bot bot; + private final Terminator bot; private boolean cancelled; - public BotFallDamageEvent(Bot bot) { + public BotFallDamageEvent(Terminator bot) { this.bot = bot; } - public Bot getBot() { + public Terminator getBot() { return bot; } - public void setCancelled(boolean cancelled) { - this.cancelled = cancelled; - } - public boolean isCancelled() { return cancelled; } + + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } } diff --git a/src/main/java/net/nuggetmc/tplus/bot/event/BotKilledByPlayerEvent.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/event/BotKilledByPlayerEvent.java similarity index 64% rename from src/main/java/net/nuggetmc/tplus/bot/event/BotKilledByPlayerEvent.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/event/BotKilledByPlayerEvent.java index 5c2d0ee..be1845f 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/event/BotKilledByPlayerEvent.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/event/BotKilledByPlayerEvent.java @@ -1,6 +1,6 @@ -package net.nuggetmc.tplus.bot.event; +package net.nuggetmc.tplus.api.event; -import net.nuggetmc.tplus.bot.Bot; +import net.nuggetmc.tplus.api.Terminator; import org.bukkit.entity.Player; public class BotKilledByPlayerEvent { @@ -8,15 +8,15 @@ public class BotKilledByPlayerEvent { // eventually also call this event for deaths from other damage causes within combat time // (like hitting the ground too hard) - private final Bot bot; + private final Terminator bot; private final Player player; - public BotKilledByPlayerEvent(Bot bot, Player player) { + public BotKilledByPlayerEvent(Terminator bot, Player player) { this.bot = bot; this.player = player; } - public Bot getBot() { + public Terminator getBot() { return bot; } diff --git a/src/main/java/net/nuggetmc/tplus/utils/BotUtils.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/BotUtils.java similarity index 97% rename from src/main/java/net/nuggetmc/tplus/utils/BotUtils.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/BotUtils.java index 8956f75..6349309 100644 --- a/src/main/java/net/nuggetmc/tplus/utils/BotUtils.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/BotUtils.java @@ -1,4 +1,4 @@ -package net.nuggetmc.tplus.utils; +package net.nuggetmc.tplus.api.utils; import org.bukkit.Location; import org.bukkit.Material; diff --git a/src/main/java/net/nuggetmc/tplus/utils/ChatUtils.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/ChatUtils.java similarity index 90% rename from src/main/java/net/nuggetmc/tplus/utils/ChatUtils.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/ChatUtils.java index 73623cb..a747398 100644 --- a/src/main/java/net/nuggetmc/tplus/utils/ChatUtils.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/ChatUtils.java @@ -1,4 +1,4 @@ -package net.nuggetmc.tplus.utils; +package net.nuggetmc.tplus.api.utils; import net.md_5.bungee.api.ChatColor; @@ -7,8 +7,8 @@ import java.util.Locale; public class ChatUtils { public static final String LINE = ChatColor.GRAY + "------------------------------------------------"; - public static final String BULLET = "▪"; - public static final String BULLET_FORMATTED = ChatColor.GRAY + " ▪ " + ChatColor.RESET; + public static final String BULLET = "\u25AA"; + public static final String BULLET_FORMATTED = ChatColor.GRAY + " \u25AA " + ChatColor.RESET; public static final String EXCEPTION_MESSAGE = ChatColor.RED + "An exception has occured. Please try again."; public static final NumberFormat NUMBER_FORMAT = NumberFormat.getNumberInstance(Locale.US); diff --git a/src/main/java/net/nuggetmc/tplus/bot/CustomGameProfile.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/CustomGameProfile.java similarity index 90% rename from src/main/java/net/nuggetmc/tplus/bot/CustomGameProfile.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/CustomGameProfile.java index 037f702..d7ac2fb 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/CustomGameProfile.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/CustomGameProfile.java @@ -1,8 +1,7 @@ -package net.nuggetmc.tplus.bot; +package net.nuggetmc.tplus.api.utils; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; -import net.nuggetmc.tplus.utils.MojangAPI; import java.util.UUID; diff --git a/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/DebugLogUtils.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/DebugLogUtils.java new file mode 100644 index 0000000..c2b6d8f --- /dev/null +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/DebugLogUtils.java @@ -0,0 +1,23 @@ +package net.nuggetmc.tplus.api.utils; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.permissions.ServerOperator; + +import java.util.Arrays; + +public class DebugLogUtils { + public static final String PREFIX = ChatColor.YELLOW + "[DEBUG] " + ChatColor.RESET; + + public static void log(Object... objects) { + String[] values = fromStringArray(objects); + String message = PREFIX + String.join(" ", values); + + Bukkit.getConsoleSender().sendMessage(message); + Bukkit.getOnlinePlayers().stream().filter(ServerOperator::isOp).forEach(p -> p.sendMessage(message)); + } + + public static String[] fromStringArray(Object[] objects) { + return Arrays.stream(objects).map(String::valueOf).toArray(String[]::new); + } +} diff --git a/src/main/java/net/nuggetmc/tplus/utils/ItemUtils.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/ItemUtils.java similarity index 97% rename from src/main/java/net/nuggetmc/tplus/utils/ItemUtils.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/ItemUtils.java index 7b8b691..c582351 100644 --- a/src/main/java/net/nuggetmc/tplus/utils/ItemUtils.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/ItemUtils.java @@ -1,4 +1,4 @@ -package net.nuggetmc.tplus.utils; +package net.nuggetmc.tplus.api.utils; import org.bukkit.inventory.ItemStack; diff --git a/src/main/java/net/nuggetmc/tplus/utils/MathUtils.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/MathUtils.java similarity index 92% rename from src/main/java/net/nuggetmc/tplus/utils/MathUtils.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/MathUtils.java index 8f2beea..a064d77 100644 --- a/src/main/java/net/nuggetmc/tplus/utils/MathUtils.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/MathUtils.java @@ -1,6 +1,6 @@ -package net.nuggetmc.tplus.utils; +package net.nuggetmc.tplus.api.utils; -import net.nuggetmc.tplus.bot.Bot; +import net.nuggetmc.tplus.api.Terminator; import org.bukkit.util.NumberConversions; import org.bukkit.util.Vector; @@ -22,9 +22,7 @@ public class MathUtils { if (x == 0.0D && z == 0.0D) { out[1] = (float) (dir.getY() > 0.0D ? -90 : 90); - } - - else { + } else { double theta = Math.atan2(-x, z); out[0] = (float) Math.toDegrees((theta + 6.283185307179586D) % 6.283185307179586D); @@ -45,9 +43,7 @@ public class MathUtils { if (x == 0.0D && z == 0.0D) { result = (float) (dir.getY() > 0.0D ? -90 : 90); - } - - else { + } else { double x2 = NumberConversions.square(x); double z2 = NumberConversions.square(z); double xz = Math.sqrt(x2 + z2); @@ -92,8 +88,8 @@ public class MathUtils { return FORMATTER_2.format(n); } - public static List> sortByValue(HashMap hm) { - List> list = new LinkedList<>(hm.entrySet()); + public static List> sortByValue(HashMap hm) { + List> list = new LinkedList<>(hm.entrySet()); list.sort(Map.Entry.comparingByValue()); Collections.reverse(list); return list; @@ -161,9 +157,9 @@ public class MathUtils { double dist = distribution(list, mid); double p = mutationSize * dist / Math.sqrt(list.size()); - return new double[] { - mid - p, - mid + p + return new double[]{ + mid - p, + mid + p }; } diff --git a/src/main/java/net/nuggetmc/tplus/utils/MojangAPI.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/MojangAPI.java similarity index 97% rename from src/main/java/net/nuggetmc/tplus/utils/MojangAPI.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/MojangAPI.java index f38996c..2c81f1c 100644 --- a/src/main/java/net/nuggetmc/tplus/utils/MojangAPI.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/MojangAPI.java @@ -1,4 +1,4 @@ -package net.nuggetmc.tplus.utils; +package net.nuggetmc.tplus.api.utils; import com.google.gson.JsonObject; import com.google.gson.JsonParser; diff --git a/src/main/java/net/nuggetmc/tplus/utils/PlayerUtils.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/PlayerUtils.java similarity index 87% rename from src/main/java/net/nuggetmc/tplus/utils/PlayerUtils.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/PlayerUtils.java index 002a851..909bdd9 100644 --- a/src/main/java/net/nuggetmc/tplus/utils/PlayerUtils.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/PlayerUtils.java @@ -1,6 +1,6 @@ -package net.nuggetmc.tplus.utils; +package net.nuggetmc.tplus.api.utils; -import net.nuggetmc.tplus.TerminatorPlus; +import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; import org.json.simple.JSONArray; @@ -15,12 +15,12 @@ import java.util.Set; public class PlayerUtils { + private static final Set USERNAME_CACHE = new HashSet<>(); + public static boolean isInvincible(GameMode mode) { return mode != GameMode.SURVIVAL && mode != GameMode.ADVENTURE && mode != null; } - private static final Set USERNAME_CACHE = new HashSet<>(); - public static String randomName() { if (USERNAME_CACHE.isEmpty()) { fillUsernameCache(); @@ -30,7 +30,7 @@ public class PlayerUtils { } public static void fillUsernameCache() { - String file = TerminatorPlus.getInstance().getServer().getWorldContainer().getAbsolutePath(); + String file = Bukkit.getServer().getWorldContainer().getAbsolutePath(); file = file.substring(0, file.length() - 1) + "usercache.json"; JSONParser parser = new JSONParser(); @@ -44,10 +44,8 @@ public class PlayerUtils { USERNAME_CACHE.add(username); } - } - - catch (IOException | ParseException e) { - Debugger.log("Failed to fetch from the usercache."); + } catch (IOException | ParseException e) { + DebugLogUtils.log("Failed to fetch from the usercache."); } } diff --git a/src/main/java/net/nuggetmc/tplus/utils/Singularity.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/Singularity.java similarity index 91% rename from src/main/java/net/nuggetmc/tplus/utils/Singularity.java rename to TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/Singularity.java index a336821..e649a83 100644 --- a/src/main/java/net/nuggetmc/tplus/utils/Singularity.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/utils/Singularity.java @@ -1,4 +1,4 @@ -package net.nuggetmc.tplus.utils; +package net.nuggetmc.tplus.api.utils; public class Singularity { diff --git a/TerminatorPlus-Plugin/build.gradle.kts b/TerminatorPlus-Plugin/build.gradle.kts new file mode 100644 index 0000000..2ba9e8e --- /dev/null +++ b/TerminatorPlus-Plugin/build.gradle.kts @@ -0,0 +1,56 @@ +plugins { + `java-library` + id("io.papermc.paperweight.userdev") version "1.3.7" +} + +group = "net.nuggetmc" +version = "3.2-BETA" +description = "TerminatorPlus" + +java { + // Configure the java toolchain. This allows gradle to auto-provision JDK 17 on systems that only have JDK 8 installed for example. + toolchain.languageVersion.set(JavaLanguageVersion.of(17)) +} + +dependencies { + paperDevBundle("1.18.1-R0.1-SNAPSHOT") + + //add the TerminatorPlus-API module + implementation(project(":TerminatorPlus-API")) + + // paperweightDevBundle("com.example.paperfork", "1.19-R0.1-SNAPSHOT") + + // You will need to manually specify the full dependency if using the groovy gradle dsl + // (paperDevBundle and paperweightDevBundle functions do not work in groovy) + // paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.19-R0.1-SNAPSHOT") +} + +tasks { + // Configure reobfJar to run when invoking the build task + assemble { + dependsOn(reobfJar) + } + + compileJava { + options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything + + // Set the release flag. This configures what version bytecode the compiler will emit, as well as what JDK APIs are usable. + // See https://openjdk.java.net/jeps/247 for more information. + options.release.set(17) + } + javadoc { + options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything + } + processResources { + filteringCharset = Charsets.UTF_8.name() // We want UTF-8 for everything + } + + /* + reobfJar { + // This is an example of how you might change the output location for reobfJar. It's recommended not to do this + // for a variety of reasons, however it's asked frequently enough that an example of how to do it is included here. + outputJar.set(layout.buildDirectory.file("libs/PaperweightTestPlugin-${project.version}.jar")) + } + */ +} + diff --git a/src/main/java/net/nuggetmc/tplus/TerminatorPlus.java b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/TerminatorPlus.java similarity index 74% rename from src/main/java/net/nuggetmc/tplus/TerminatorPlus.java rename to TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/TerminatorPlus.java index 4637b25..b217a5e 100644 --- a/src/main/java/net/nuggetmc/tplus/TerminatorPlus.java +++ b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/TerminatorPlus.java @@ -1,6 +1,8 @@ package net.nuggetmc.tplus; -import net.nuggetmc.tplus.bot.BotManager; +import net.nuggetmc.tplus.api.TerminatorPlusAPI; +import net.nuggetmc.tplus.bot.BotManagerImpl; +import net.nuggetmc.tplus.bridge.InternalBridgeImpl; import net.nuggetmc.tplus.command.CommandHandler; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; @@ -12,7 +14,7 @@ public class TerminatorPlus extends JavaPlugin { private static TerminatorPlus instance; private static String version; - private BotManager manager; + private BotManagerImpl manager; private CommandHandler handler; public static TerminatorPlus getInstance() { @@ -23,7 +25,7 @@ public class TerminatorPlus extends JavaPlugin { return version; } - public BotManager getManager() { + public BotManagerImpl getManager() { return manager; } @@ -37,9 +39,12 @@ public class TerminatorPlus extends JavaPlugin { version = getDescription().getVersion(); // Create Instances - this.manager = new BotManager(); + this.manager = new BotManagerImpl(); this.handler = new CommandHandler(this); + TerminatorPlusAPI.setBotManager(manager); + TerminatorPlusAPI.setInternalBridge(new InternalBridgeImpl()); + // Register event listeners this.registerEvents(manager); } diff --git a/src/main/java/net/nuggetmc/tplus/bot/Bot.java b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/bot/Bot.java similarity index 84% rename from src/main/java/net/nuggetmc/tplus/bot/Bot.java rename to TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/bot/Bot.java index 8bc6a1f..42e7c7b 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/Bot.java +++ b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/bot/Bot.java @@ -8,8 +8,6 @@ import net.minecraft.network.Connection; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.PacketFlow; import net.minecraft.network.protocol.game.*; -import net.minecraft.network.syncher.EntityDataAccessor; -import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; @@ -26,18 +24,17 @@ import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; import net.nuggetmc.tplus.TerminatorPlus; -import net.nuggetmc.tplus.bot.agent.Agent; -import net.nuggetmc.tplus.bot.agent.legacyagent.ai.NeuralNetwork; -import net.nuggetmc.tplus.bot.event.BotDamageByPlayerEvent; -import net.nuggetmc.tplus.bot.event.BotFallDamageEvent; -import net.nuggetmc.tplus.bot.event.BotKilledByPlayerEvent; -import net.nuggetmc.tplus.utils.*; -import org.bukkit.Material; -import org.bukkit.SoundCategory; -import org.bukkit.World; +import net.nuggetmc.tplus.api.Terminator; +import net.nuggetmc.tplus.api.agent.Agent; +import net.nuggetmc.tplus.api.agent.legacyagent.ai.NeuralNetwork; +import net.nuggetmc.tplus.api.event.BotDamageByPlayerEvent; +import net.nuggetmc.tplus.api.event.BotFallDamageEvent; +import net.nuggetmc.tplus.api.event.BotKilledByPlayerEvent; +import net.nuggetmc.tplus.api.utils.*; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.craftbukkit.v1_18_R1.CraftEquipmentSlot; import org.bukkit.craftbukkit.v1_18_R1.CraftServer; import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; @@ -46,7 +43,6 @@ import org.bukkit.entity.Damageable; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitScheduler; -import org.bukkit.util.BoundingBox; import org.bukkit.util.Vector; import javax.annotation.Nullable; @@ -55,47 +51,27 @@ import java.util.Collections; import java.util.Objects; import java.util.UUID; -public class Bot extends ServerPlayer { +public class Bot extends ServerPlayer implements Terminator { private final TerminatorPlus plugin; private final BukkitScheduler scheduler; private final Agent agent; - - private NeuralNetwork network; - - public NeuralNetwork getNeuralNetwork() { - return network; - } - - public void setNeuralNetwork(NeuralNetwork network) { - this.network = network; - } - - public boolean hasNeuralNetwork() { - return network != null; - } - + private final Vector offset; public ItemStack defaultItem; - + private NeuralNetwork network; private boolean shield; private boolean blocking; private boolean blockUse; - private Vector velocity; private Vector oldVelocity; - private boolean removeOnDeath; - private int aliveTicks; private int kills; - - private byte fireTicks; + private byte fireTicks; // Fire animation isn't played? Bot still takes damage. private byte groundTicks; private byte jumpTicks; private byte noFallTicks; - private final Vector offset; - private Bot(MinecraftServer minecraftServer, ServerLevel worldServer, GameProfile profile) { super(minecraftServer, worldServer, profile); @@ -139,15 +115,40 @@ public class Bot extends ServerPlayer { bot.setRot(loc.getYaw(), loc.getPitch()); bot.getBukkitEntity().setNoDamageTicks(0); Bukkit.getOnlinePlayers().forEach(p -> ((CraftPlayer) p).getHandle().connection.send( - new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, bot))); + new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, bot))); nmsWorld.addFreshEntity(bot); bot.renderAll(); - + TerminatorPlus.getInstance().getManager().add(bot); return bot; } + @Override + public String getBotName() { + return displayName; + } + + @Override + public int getEntityId() { + return getId(); + } + + @Override + public NeuralNetwork getNeuralNetwork() { + return network; + } + + @Override + public void setNeuralNetwork(NeuralNetwork network) { + this.network = network; + } + + @Override + public boolean hasNeuralNetwork() { + return network != null; + } + private void renderAll() { Packet[] packets = getRenderPacketsNoInfo(); Bukkit.getOnlinePlayers().forEach(p -> renderNoInfo(((CraftPlayer) p).getHandle().connection, packets, false)); @@ -164,7 +165,7 @@ public class Bot extends ServerPlayer { connection.send(packets[3]); } } - + private void renderNoInfo(ServerGamePacketListenerImpl connection, Packet[] packets, boolean login) { connection.send(packets[0]); connection.send(packets[1]); @@ -180,39 +181,52 @@ public class Bot extends ServerPlayer { render(connection, getRenderPackets(), login); } - private Packet[] getRenderPackets() { - return new Packet[] { - new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, this), - new ClientboundAddPlayerPacket(this), - new ClientboundSetEntityDataPacket(this.getId(), this.entityData, true), - new ClientboundRotateHeadPacket(this, (byte) ((this.yHeadRot * 256f) / 360f)) - }; + @Override + public void renderBot(Object packetListener, boolean login) { + if (!(packetListener instanceof ServerGamePacketListenerImpl)) { + throw new IllegalArgumentException("packetListener must be a instance of ServerGamePacketListenerImpl"); + } + render((ServerGamePacketListenerImpl) packetListener, login); } - - private Packet[] getRenderPacketsNoInfo() { - return new Packet[] { - new ClientboundAddPlayerPacket(this), - new ClientboundSetEntityDataPacket(this.getId(), this.entityData, true), - new ClientboundRotateHeadPacket(this, (byte) ((this.yHeadRot * 256f) / 360f)) + + private Packet[] getRenderPackets() { + return new Packet[]{ + new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, this), + new ClientboundAddPlayerPacket(this), + new ClientboundSetEntityDataPacket(this.getId(), this.entityData, true), + new ClientboundRotateHeadPacket(this, (byte) ((this.yHeadRot * 256f) / 360f)) }; } + private Packet[] getRenderPacketsNoInfo() { + return new Packet[]{ + new ClientboundAddPlayerPacket(this), + new ClientboundSetEntityDataPacket(this.getId(), this.entityData, true), + new ClientboundRotateHeadPacket(this, (byte) ((this.yHeadRot * 256f) / 360f)) + }; + } + + @Override public void setDefaultItem(ItemStack item) { this.defaultItem = item; } + @Override public Vector getOffset() { return offset; } + @Override public Vector getVelocity() { return velocity.clone(); } + @Override public void setVelocity(Vector vector) { this.velocity = vector; } + @Override public void addVelocity(Vector vector) { // This can cause lag? (maybe i fixed it with the new static method) if (MathUtils.isNotFinite(vector)) { velocity = vector; @@ -222,10 +236,12 @@ public class Bot extends ServerPlayer { velocity.add(vector); } + @Override public int getAliveTicks() { return aliveTicks; } + @Override public boolean tickDelay(int i) { return aliveTicks % i == 0; } @@ -234,6 +250,21 @@ public class Bot extends ServerPlayer { Bukkit.getOnlinePlayers().forEach(p -> ((CraftPlayer) p).getHandle().connection.send(packet)); } + @Override + public boolean isBotAlive() { + return isAlive(); + } + + @Override + public float getBotHealth() { + return getHealth(); + } + + @Override + public float getBotMaxHealth() { + return getMaxHealth(); + } + @Override public void tick() { loadChunks(); @@ -272,8 +303,8 @@ public class Bot extends ServerPlayer { fireDamageCheck(); fallDamageCheck(); - - if(position().y < -64) { + + if (position().y < -64) { die(DamageSource.OUT_OF_WORLD); } @@ -328,17 +359,20 @@ public class Bot extends ServerPlayer { } } + @Override public void ignite() { if (fireTicks <= 1) setOnFirePackets(true); fireTicks = 100; } + @Override public void setOnFirePackets(boolean onFire) { //entityData.set(new EntityDataAccessor<>(0, EntityDataSerializers.BYTE), onFire ? (byte) 1 : (byte) 0); //sendPacket(new ClientboundSetEntityDataPacket(getId(), entityData, false)); } - public boolean isOnFire() { + @Override + public boolean isBotOnFire() { return fireTicks != 0; } @@ -354,10 +388,12 @@ public class Bot extends ServerPlayer { } } + @Override public boolean isFalling() { return velocity.getY() < -0.8; } + @Override public void block(int blockLength, int cooldown) { if (!shield || blockUse) return; startBlocking(); @@ -378,14 +414,14 @@ public class Bot extends ServerPlayer { sendPacket(new ClientboundSetEntityDataPacket(getId(), entityData, true)); } - public boolean isBlocking() { - return blocking; + @Override + public boolean isBotBlocking() { + return isBlocking(); } public void setShield(boolean enabled) { this.shield = enabled; - System.out.println("set shield"); setItemOffhand(new org.bukkit.inventory.ItemStack(enabled ? Material.SHIELD : Material.AIR)); } @@ -394,13 +430,11 @@ public class Bot extends ServerPlayer { MathUtils.clean(velocity); // TODO lag???? - if (isInWater()) { + if (isBotInWater()) { y = Math.min(velocity.getY() + 0.1, 0.1); addFriction(0.8); velocity.setY(y); - } - - else { + } else { if (groundTicks != 0) { velocity.setY(0); addFriction(0.5); @@ -415,7 +449,7 @@ public class Bot extends ServerPlayer { } @Override - public boolean isInWater() { + public boolean isBotInWater() { Location loc = getLocation(); for (int i = 0; i <= 2; i++) { @@ -431,6 +465,7 @@ public class Bot extends ServerPlayer { return false; } + @Override public void jump(Vector vel) { if (jumpTicks == 0 && groundTicks > 1) { jumpTicks = 4; @@ -438,10 +473,12 @@ public class Bot extends ServerPlayer { } } + @Override public void jump() { jump(new Vector(0, 0.5, 0)); } + @Override public void walk(Vector vel) { double max = 0.4; @@ -451,6 +488,7 @@ public class Bot extends ServerPlayer { velocity = sum; } + @Override public void attack(org.bukkit.entity.Entity entity) { faceLocation(entity.getLocation()); punch(); @@ -462,6 +500,7 @@ public class Bot extends ServerPlayer { } } + @Override public void punch() { swing(InteractionHand.MAIN_HAND); } @@ -476,14 +515,14 @@ public class Bot extends ServerPlayer { World world = getBukkitEntity().getWorld(); AABB box = getBoundingBox(); - double[] xVals = new double[] { - box.minX, - box.maxX + double[] xVals = new double[]{ + box.minX, + box.maxX }; - double[] zVals = new double[] { - box.minZ, - box.maxZ + double[] zVals = new double[]{ + box.minZ, + box.maxZ }; for (double x : xVals) { @@ -501,10 +540,11 @@ public class Bot extends ServerPlayer { } @Override - public boolean isOnGround() { + public boolean isBotOnGround() { return groundTicks != 0; } + @Override public void addFriction(double factor) { double frictionMin = 0.01; @@ -515,11 +555,22 @@ public class Bot extends ServerPlayer { velocity.setZ(Math.abs(z) < frictionMin ? 0 : z * factor); } + @Override public void removeVisually() { this.removeTab(); this.setDead(); } + @Override + public void removeBot() { + if (Bukkit.isPrimaryThread()) { + this.remove(RemovalReason.DISCARDED); + } else { + scheduler.runTask(plugin, () -> this.remove(RemovalReason.DISCARDED)); + } + this.removeVisually(); + } + private void removeTab() { sendPacket(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER, this)); } @@ -635,27 +686,37 @@ public class Bot extends ServerPlayer { private void kb(Location loc1, Location loc2) { Vector vel = loc1.toVector().subtract(loc2.toVector()).setY(0).normalize().multiply(0.3); - if (isOnGround()) vel.multiply(0.8).setY(0.4); + if (isBotOnGround()) vel.multiply(0.8).setY(0.4); velocity = vel; } + @Override public int getKills() { return kills; } + @Override public void incrementKills() { kills++; } + @Override public Location getLocation() { return getBukkitEntity().getLocation(); } + @Override + public void setBotPitch(float pitch) { + super.setXRot(pitch); + } + + @Override public void faceLocation(Location loc) { look(loc.toVector().subtract(getLocation().toVector()), false); } + @Override public void look(BlockFace face) { look(face.getDirection(), face == BlockFace.DOWN || face == BlockFace.UP); } @@ -677,6 +738,7 @@ public class Bot extends ServerPlayer { setRot(yaw, pitch); } + @Override public void attemptBlockPlace(Location loc, Material type, boolean down) { if (down) { look(BlockFace.DOWN); @@ -696,42 +758,52 @@ public class Bot extends ServerPlayer { } } + @Override public void setItem(org.bukkit.inventory.ItemStack item) { setItem(item, EquipmentSlot.MAINHAND); } + @Override public void setItemOffhand(org.bukkit.inventory.ItemStack item) { setItem(item, EquipmentSlot.OFFHAND); - System.out.println("set offhand"); + } + + @Override + public void setItem(ItemStack item, org.bukkit.inventory.EquipmentSlot slot) { + EquipmentSlot nmsSlot = CraftEquipmentSlot.getNMS(slot); + setItem(item, nmsSlot); } public void setItem(org.bukkit.inventory.ItemStack item, EquipmentSlot slot) { if (item == null) item = defaultItem; - System.out.println("set"); + //System.out.println("set"); if (slot == EquipmentSlot.MAINHAND) { getBukkitEntity().getInventory().setItemInMainHand(item); } else if (slot == EquipmentSlot.OFFHAND) { getBukkitEntity().getInventory().setItemInOffHand(item); } - System.out.println("slot = " + slot); - System.out.println("item = " + item); + //System.out.println("slot = " + slot); + //System.out.println("item = " + item); sendPacket(new ClientboundSetEquipmentPacket(getId(), new ArrayList<>(Collections.singletonList( - new Pair<>(slot, CraftItemStack.asNMSCopy(item)) + new Pair<>(slot, CraftItemStack.asNMSCopy(item)) )))); } + @Override public void swim() { getBukkitEntity().setSwimming(true); registerPose(Pose.SWIMMING); } + @Override public void sneak() { getBukkitEntity().setSneaking(true); registerPose(Pose.CROUCHING); } + @Override public void stand() { Player player = getBukkitEntity(); player.setSneaking(false); diff --git a/src/main/java/net/nuggetmc/tplus/bot/BotManager.java b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/bot/BotManagerImpl.java similarity index 60% rename from src/main/java/net/nuggetmc/tplus/bot/BotManager.java rename to TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/bot/BotManagerImpl.java index a1326a4..ea283ee 100644 --- a/src/main/java/net/nuggetmc/tplus/bot/BotManager.java +++ b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/bot/BotManagerImpl.java @@ -1,17 +1,22 @@ package net.nuggetmc.tplus.bot; import net.minecraft.server.network.ServerGamePacketListenerImpl; -import net.nuggetmc.tplus.bot.agent.Agent; -import net.nuggetmc.tplus.bot.agent.legacyagent.LegacyAgent; -import net.nuggetmc.tplus.bot.agent.legacyagent.ai.NeuralNetwork; -import net.nuggetmc.tplus.bot.event.BotDeathEvent; -import net.nuggetmc.tplus.utils.MojangAPI; +import net.nuggetmc.tplus.TerminatorPlus; +import net.nuggetmc.tplus.api.BotManager; +import net.nuggetmc.tplus.api.Terminator; +import net.nuggetmc.tplus.api.agent.Agent; +import net.nuggetmc.tplus.api.agent.legacyagent.LegacyAgent; +import net.nuggetmc.tplus.api.agent.legacyagent.ai.NeuralNetwork; +import net.nuggetmc.tplus.api.event.BotDeathEvent; +import net.nuggetmc.tplus.api.utils.MojangAPI; import org.bukkit.*; import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; @@ -21,35 +26,38 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; -public class BotManager implements Listener { +public class BotManagerImpl implements BotManager, Listener { private final Agent agent; - private final Set bots; + private final Set bots; private final NumberFormat numberFormat; public boolean joinMessages = false; - public BotManager() { - this.agent = new LegacyAgent(this); + public BotManagerImpl() { + this.agent = new LegacyAgent(this, TerminatorPlus.getInstance()); this.bots = ConcurrentHashMap.newKeySet(); //should fix concurrentmodificationexception this.numberFormat = NumberFormat.getInstance(Locale.US); } - public Set fetch() { + @Override + public Set fetch() { return bots; } - public void add(Bot bot) { + @Override + public void add(Terminator bot) { if (joinMessages) { - Bukkit.broadcastMessage(ChatColor.YELLOW + (bot.getName() + " joined the game")); + Bukkit.broadcastMessage(ChatColor.YELLOW + (bot.getBotName() + " joined the game")); } bots.add(bot); } - public Bot getFirst(String name) { - for (Bot bot : bots) { - if (name.equals(bot.getName())) { + @Override + public Terminator getFirst(String name) { + for (Terminator bot : bots) { + if (name.equals(bot.getBotName())) { return bot; } } @@ -57,18 +65,26 @@ public class BotManager implements Listener { return null; } + @Override public List fetchNames() { - return bots.stream().map(Bot::getName).map(component -> component.getString()).collect(Collectors.toList()); + //return bots.stream().map(Bot::getBotName).map(component -> component.getString()).collect(Collectors.toList()); + return bots.stream().map(terminator -> { + if (terminator instanceof Bot bot) return bot.getName().getString(); + else return terminator.getBotName(); + }).collect(Collectors.toList()); } + @Override public Agent getAgent() { return agent; } + @Override public void createBots(Player sender, String name, String skinName, int n) { createBots(sender, name, skinName, n, null); } + @Override public void createBots(Player sender, String name, String skinName, int n, NeuralNetwork network) { long timestamp = System.currentTimeMillis(); @@ -86,7 +102,8 @@ public class BotManager implements Listener { sender.sendMessage("Process completed (" + ChatColor.RED + ((System.currentTimeMillis() - timestamp) / 1000D) + "s" + ChatColor.RESET + ")."); } - public Set createBots(Location loc, String name, String[] skin, int n, NeuralNetwork network) { + @Override + public Set createBots(Location loc, String name, String[] skin, int n, NeuralNetwork network) { List networks = new ArrayList<>(); for (int i = 0; i < n; i++) { @@ -96,8 +113,9 @@ public class BotManager implements Listener { return createBots(loc, name, skin, networks); } - public Set createBots(Location loc, String name, String[] skin, List networks) { - Set bots = new HashSet<>(); + @Override + public Set createBots(Location loc, String name, String[] skin, List networks) { + Set bots = new HashSet<>(); World world = loc.getWorld(); int n = networks.size(); @@ -136,45 +154,55 @@ public class BotManager implements Listener { return new Vector(Math.random() - 0.5, 0.5, Math.random() - 0.5).normalize(); } - public void remove(Bot bot) { + @Override + public void remove(Terminator bot) { bots.remove(bot); } + @Override public void reset() { if (!bots.isEmpty()) { - bots.forEach(Bot::removeVisually); + bots.forEach(Terminator::removeVisually); bots.clear(); // Not always necessary, but a good security measure } agent.stopAllTasks(); } - public Bot getBot(Player player) { // potentially memory intensive - Bot bot = null; + @Override + public Terminator getBot(Player player) { // potentially memory intensive int id = player.getEntityId(); + return getBot(id); + } - for (Bot b : bots) { - if (id == b.getId()) { - bot = b; - break; + @Override + public Terminator getBot(UUID uuid) { + Entity entity = Bukkit.getEntity(uuid); + if (entity == null) return null; + return getBot(entity.getEntityId()); + } + + @Override + public Terminator getBot(int entityId) { + for (Terminator bot : bots) { + if (bot.getEntityId() == entityId) { + return bot; } } - - return bot; + return null; } @EventHandler public void onJoin(PlayerJoinEvent event) { ServerGamePacketListenerImpl connection = ((CraftPlayer) event.getPlayer()).getHandle().connection; - bots.forEach(bot -> bot.render(connection, true)); + bots.forEach(bot -> bot.renderBot(connection, true)); } @EventHandler - public void onDeath(PlayerDeathEvent event) { - Player player = event.getEntity(); - Bot bot = getBot(player); - + public void onDeath(EntityDeathEvent event) { + LivingEntity bukkitEntity = event.getEntity(); + Terminator bot = getBot(bukkitEntity.getEntityId()); if (bot != null) { agent.onBotDeath(new BotDeathEvent(event, bot)); } diff --git a/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/bridge/InternalBridgeImpl.java b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/bridge/InternalBridgeImpl.java new file mode 100644 index 0000000..6dfdb35 --- /dev/null +++ b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/bridge/InternalBridgeImpl.java @@ -0,0 +1,35 @@ +package net.nuggetmc.tplus.bridge; + +import net.minecraft.core.BlockPos; +import net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; +import net.nuggetmc.tplus.api.InternalBridge; +import org.bukkit.Bukkit; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; + +public class InternalBridgeImpl implements InternalBridge { + @Override + public void sendBlockDestructionPacket(short entityId, int x, int y, int z, int progress) { + ClientboundBlockDestructionPacket crack = new ClientboundBlockDestructionPacket(entityId, new BlockPos(x, y, z), progress); + for (Player all : Bukkit.getOnlinePlayers()) { + ((CraftPlayer) all).getHandle().connection.send(crack); + } + } + + @Override + public Sound breakBlockSound(Block block) { + Level nmsWorld = ((CraftWorld) block.getWorld()).getHandle(); + BlockState blockState = nmsWorld.getBlockState(new BlockPos(block.getX(), block.getY(), block.getZ())); + net.minecraft.world.level.block.Block nmsBlock = blockState.getBlock(); + + SoundType soundEffectType = nmsBlock.getSoundType(blockState); + + return Sound.valueOf(soundEffectType.getBreakSound().getLocation().getPath().replace(".", "_").toUpperCase()); + } +} diff --git a/src/main/java/net/nuggetmc/tplus/command/CommandHandler.java b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/CommandHandler.java similarity index 96% rename from src/main/java/net/nuggetmc/tplus/command/CommandHandler.java rename to TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/CommandHandler.java index f915fe9..e723ba6 100644 --- a/src/main/java/net/nuggetmc/tplus/command/CommandHandler.java +++ b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/CommandHandler.java @@ -2,13 +2,13 @@ package net.nuggetmc.tplus.command; import com.google.common.collect.Sets; import net.nuggetmc.tplus.TerminatorPlus; +import net.nuggetmc.tplus.api.utils.ChatUtils; +import net.nuggetmc.tplus.api.utils.DebugLogUtils; import net.nuggetmc.tplus.command.annotation.Command; import net.nuggetmc.tplus.command.annotation.Require; import net.nuggetmc.tplus.command.commands.AICommand; import net.nuggetmc.tplus.command.commands.BotCommand; import net.nuggetmc.tplus.command.commands.MainCommand; -import net.nuggetmc.tplus.utils.ChatUtils; -import net.nuggetmc.tplus.utils.Debugger; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.command.SimpleCommandMap; @@ -62,7 +62,7 @@ public class CommandHandler { try { method.setAccessible(true); } catch (SecurityException e) { - Debugger.log("Failed to access method " + method.getName() + "."); + DebugLogUtils.log("Failed to access method " + method.getName() + "."); continue; } diff --git a/src/main/java/net/nuggetmc/tplus/command/CommandInstance.java b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/CommandInstance.java similarity index 99% rename from src/main/java/net/nuggetmc/tplus/command/CommandInstance.java rename to TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/CommandInstance.java index bbfd799..5f66a5f 100644 --- a/src/main/java/net/nuggetmc/tplus/command/CommandInstance.java +++ b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/CommandInstance.java @@ -1,13 +1,13 @@ package net.nuggetmc.tplus.command; import net.md_5.bungee.api.ChatColor; +import net.nuggetmc.tplus.api.utils.ChatUtils; import net.nuggetmc.tplus.command.annotation.Arg; import net.nuggetmc.tplus.command.annotation.OptArg; import net.nuggetmc.tplus.command.annotation.TextArg; import net.nuggetmc.tplus.command.exception.ArgCountException; import net.nuggetmc.tplus.command.exception.ArgParseException; import net.nuggetmc.tplus.command.exception.NonPlayerException; -import net.nuggetmc.tplus.utils.ChatUtils; import org.apache.commons.lang.StringUtils; import org.bukkit.command.CommandSender; import org.bukkit.command.defaults.BukkitCommand; diff --git a/src/main/java/net/nuggetmc/tplus/command/CommandMethod.java b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/CommandMethod.java similarity index 100% rename from src/main/java/net/nuggetmc/tplus/command/CommandMethod.java rename to TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/CommandMethod.java diff --git a/src/main/java/net/nuggetmc/tplus/command/annotation/Arg.java b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/annotation/Arg.java similarity index 100% rename from src/main/java/net/nuggetmc/tplus/command/annotation/Arg.java rename to TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/annotation/Arg.java diff --git a/src/main/java/net/nuggetmc/tplus/command/annotation/Autofill.java b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/annotation/Autofill.java similarity index 100% rename from src/main/java/net/nuggetmc/tplus/command/annotation/Autofill.java rename to TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/annotation/Autofill.java diff --git a/src/main/java/net/nuggetmc/tplus/command/annotation/Command.java b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/annotation/Command.java similarity index 100% rename from src/main/java/net/nuggetmc/tplus/command/annotation/Command.java rename to TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/annotation/Command.java diff --git a/src/main/java/net/nuggetmc/tplus/command/annotation/OptArg.java b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/annotation/OptArg.java similarity index 100% rename from src/main/java/net/nuggetmc/tplus/command/annotation/OptArg.java rename to TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/annotation/OptArg.java diff --git a/src/main/java/net/nuggetmc/tplus/command/annotation/Require.java b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/annotation/Require.java similarity index 100% rename from src/main/java/net/nuggetmc/tplus/command/annotation/Require.java rename to TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/annotation/Require.java diff --git a/src/main/java/net/nuggetmc/tplus/command/annotation/TextArg.java b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/annotation/TextArg.java similarity index 100% rename from src/main/java/net/nuggetmc/tplus/command/annotation/TextArg.java rename to TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/annotation/TextArg.java diff --git a/src/main/java/net/nuggetmc/tplus/command/commands/AICommand.java b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/commands/AICommand.java similarity index 83% rename from src/main/java/net/nuggetmc/tplus/command/commands/AICommand.java rename to TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/commands/AICommand.java index adfa74f..4b95949 100644 --- a/src/main/java/net/nuggetmc/tplus/command/commands/AICommand.java +++ b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/commands/AICommand.java @@ -1,18 +1,19 @@ package net.nuggetmc.tplus.command.commands; import net.nuggetmc.tplus.TerminatorPlus; -import net.nuggetmc.tplus.bot.Bot; -import net.nuggetmc.tplus.bot.BotManager; -import net.nuggetmc.tplus.bot.agent.legacyagent.ai.IntelligenceAgent; -import net.nuggetmc.tplus.bot.agent.legacyagent.ai.NeuralNetwork; +import net.nuggetmc.tplus.api.AIManager; +import net.nuggetmc.tplus.api.Terminator; +import net.nuggetmc.tplus.api.agent.legacyagent.ai.IntelligenceAgent; +import net.nuggetmc.tplus.api.agent.legacyagent.ai.NeuralNetwork; +import net.nuggetmc.tplus.api.utils.ChatUtils; +import net.nuggetmc.tplus.api.utils.MathUtils; +import net.nuggetmc.tplus.bot.BotManagerImpl; import net.nuggetmc.tplus.command.CommandHandler; import net.nuggetmc.tplus.command.CommandInstance; import net.nuggetmc.tplus.command.annotation.Arg; import net.nuggetmc.tplus.command.annotation.Autofill; import net.nuggetmc.tplus.command.annotation.Command; import net.nuggetmc.tplus.command.annotation.OptArg; -import net.nuggetmc.tplus.utils.ChatUtils; -import net.nuggetmc.tplus.utils.MathUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -22,7 +23,7 @@ import org.bukkit.scheduler.BukkitScheduler; import java.util.ArrayList; import java.util.List; -public class AICommand extends CommandInstance { +public class AICommand extends CommandInstance implements AIManager { /* * ideas @@ -31,7 +32,7 @@ public class AICommand extends CommandInstance { */ private final TerminatorPlus plugin; - private final BotManager manager; + private final BotManagerImpl manager; private final BukkitScheduler scheduler; private IntelligenceAgent agent; @@ -62,6 +63,10 @@ public class AICommand extends CommandInstance { desc = "Begin an AI training session." ) public void reinforcement(Player sender, @Arg("population-size") int populationSize, @Arg("name") String name, @OptArg("skin") String skin) { + //FIXME: Sometimes, bots will become invisible, or just stop working if they're the last one alive, this has been partially fixed (invis part) see Terminator#removeBot, which removes the bot. + //This seems to fix it for the most part, but its still buggy, as the bot will sometimes still freeze + //see https://cdn.carbonhost.cloud/6201479d7b237373ab269385/screenshots/javaw_DluMN4m0FR.png + //Blocks are also not placeable where bots have died if (agent != null) { sender.sendMessage("A session is already active."); return; @@ -69,7 +74,7 @@ public class AICommand extends CommandInstance { sender.sendMessage("Starting a new session..."); - agent = new IntelligenceAgent(this, populationSize, name, skin); + agent = new IntelligenceAgent(this, populationSize, name, skin, plugin, plugin.getManager()); agent.addUser(sender); } @@ -94,6 +99,7 @@ public class AICommand extends CommandInstance { scheduler.runTaskLater(plugin, () -> sender.sendMessage("The session " + ChatColor.YELLOW + name + ChatColor.RESET + " has been closed."), 10); } + @Override public void clearSession() { if (agent != null) { agent.stop(); @@ -115,7 +121,7 @@ public class AICommand extends CommandInstance { scheduler.runTaskAsynchronously(plugin, () -> { try { - Bot bot = manager.getFirst(name); + Terminator bot = manager.getFirst(name); if (bot == null) { sender.sendMessage("Could not find bot " + ChatColor.GREEN + name + ChatColor.RESET + "!"); diff --git a/src/main/java/net/nuggetmc/tplus/command/commands/BotCommand.java b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/commands/BotCommand.java similarity index 72% rename from src/main/java/net/nuggetmc/tplus/command/commands/BotCommand.java rename to TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/commands/BotCommand.java index 8dfffc6..ccb6db1 100644 --- a/src/main/java/net/nuggetmc/tplus/command/commands/BotCommand.java +++ b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/commands/BotCommand.java @@ -1,18 +1,17 @@ package net.nuggetmc.tplus.command.commands; -import net.minecraft.world.entity.EquipmentSlot; import net.nuggetmc.tplus.TerminatorPlus; -import net.nuggetmc.tplus.bot.Bot; -import net.nuggetmc.tplus.bot.BotManager; -import net.nuggetmc.tplus.bot.agent.legacyagent.EnumTargetGoal; -import net.nuggetmc.tplus.bot.agent.legacyagent.LegacyAgent; +import net.nuggetmc.tplus.api.Terminator; +import net.nuggetmc.tplus.api.agent.legacyagent.EnumTargetGoal; +import net.nuggetmc.tplus.api.agent.legacyagent.LegacyAgent; +import net.nuggetmc.tplus.api.utils.ChatUtils; +import net.nuggetmc.tplus.bot.BotManagerImpl; import net.nuggetmc.tplus.command.CommandHandler; import net.nuggetmc.tplus.command.CommandInstance; import net.nuggetmc.tplus.command.annotation.Arg; import net.nuggetmc.tplus.command.annotation.Autofill; import net.nuggetmc.tplus.command.annotation.Command; import net.nuggetmc.tplus.command.annotation.OptArg; -import net.nuggetmc.tplus.utils.ChatUtils; import net.nuggetmc.tplus.utils.Debugger; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -20,6 +19,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.util.Vector; @@ -31,11 +31,11 @@ public class BotCommand extends CommandInstance { private final TerminatorPlus plugin; private final CommandHandler handler; - private final BotManager manager; + private final BotManagerImpl manager; private final LegacyAgent agent; private final BukkitScheduler scheduler; private final DecimalFormat formatter; - + private final Map armorTiers; private AICommand aiManager; public BotCommand(CommandHandler handler, String name, String description, String... aliases) { @@ -58,24 +58,24 @@ public class BotCommand extends CommandInstance { } @Command( - name = "create", - desc = "Create a bot." + name = "create", + desc = "Create a bot." ) public void create(Player sender, @Arg("name") String name, @OptArg("skin") String skin) { manager.createBots(sender, name, skin, 1); } @Command( - name = "multi", - desc = "Create multiple bots at once." + name = "multi", + desc = "Create multiple bots at once." ) public void multi(Player sender, @Arg("amount") int amount, @Arg("name") String name, @OptArg("skin") String skin) { manager.createBots(sender, name, skin, amount); } @Command( - name = "give", - desc = "Gives a specified item to all bots." + name = "give", + desc = "Gives a specified item to all bots." ) public void give(CommandSender sender, @Arg("item-name") String itemName) { Material type = Material.matchMaterial(itemName); @@ -92,56 +92,54 @@ public class BotCommand extends CommandInstance { sender.sendMessage("Successfully set the default item to " + ChatColor.YELLOW + item.getType() + ChatColor.RESET + " for all current bots."); } - private final Map armorTiers; - private void armorTierSetup() { - armorTiers.put("leather", new ItemStack[] { - new ItemStack(Material.LEATHER_BOOTS), - new ItemStack(Material.LEATHER_LEGGINGS), - new ItemStack(Material.LEATHER_CHESTPLATE), - new ItemStack(Material.LEATHER_HELMET), + armorTiers.put("leather", new ItemStack[]{ + new ItemStack(Material.LEATHER_BOOTS), + new ItemStack(Material.LEATHER_LEGGINGS), + new ItemStack(Material.LEATHER_CHESTPLATE), + new ItemStack(Material.LEATHER_HELMET), }); - armorTiers.put("chain", new ItemStack[] { - new ItemStack(Material.CHAINMAIL_BOOTS), - new ItemStack(Material.CHAINMAIL_LEGGINGS), - new ItemStack(Material.CHAINMAIL_CHESTPLATE), - new ItemStack(Material.CHAINMAIL_HELMET), + armorTiers.put("chain", new ItemStack[]{ + new ItemStack(Material.CHAINMAIL_BOOTS), + new ItemStack(Material.CHAINMAIL_LEGGINGS), + new ItemStack(Material.CHAINMAIL_CHESTPLATE), + new ItemStack(Material.CHAINMAIL_HELMET), }); - armorTiers.put("gold", new ItemStack[] { - new ItemStack(Material.GOLDEN_BOOTS), - new ItemStack(Material.GOLDEN_LEGGINGS), - new ItemStack(Material.GOLDEN_CHESTPLATE), - new ItemStack(Material.GOLDEN_HELMET), + armorTiers.put("gold", new ItemStack[]{ + new ItemStack(Material.GOLDEN_BOOTS), + new ItemStack(Material.GOLDEN_LEGGINGS), + new ItemStack(Material.GOLDEN_CHESTPLATE), + new ItemStack(Material.GOLDEN_HELMET), }); - armorTiers.put("iron", new ItemStack[] { - new ItemStack(Material.IRON_BOOTS), - new ItemStack(Material.IRON_LEGGINGS), - new ItemStack(Material.IRON_CHESTPLATE), - new ItemStack(Material.IRON_HELMET), + armorTiers.put("iron", new ItemStack[]{ + new ItemStack(Material.IRON_BOOTS), + new ItemStack(Material.IRON_LEGGINGS), + new ItemStack(Material.IRON_CHESTPLATE), + new ItemStack(Material.IRON_HELMET), }); - armorTiers.put("diamond", new ItemStack[] { - new ItemStack(Material.DIAMOND_BOOTS), - new ItemStack(Material.DIAMOND_LEGGINGS), - new ItemStack(Material.DIAMOND_CHESTPLATE), - new ItemStack(Material.DIAMOND_HELMET), + armorTiers.put("diamond", new ItemStack[]{ + new ItemStack(Material.DIAMOND_BOOTS), + new ItemStack(Material.DIAMOND_LEGGINGS), + new ItemStack(Material.DIAMOND_CHESTPLATE), + new ItemStack(Material.DIAMOND_HELMET), }); - armorTiers.put("netherite", new ItemStack[] { - new ItemStack(Material.NETHERITE_BOOTS), - new ItemStack(Material.NETHERITE_LEGGINGS), - new ItemStack(Material.NETHERITE_CHESTPLATE), - new ItemStack(Material.NETHERITE_HELMET), + armorTiers.put("netherite", new ItemStack[]{ + new ItemStack(Material.NETHERITE_BOOTS), + new ItemStack(Material.NETHERITE_LEGGINGS), + new ItemStack(Material.NETHERITE_CHESTPLATE), + new ItemStack(Material.NETHERITE_HELMET), }); } @Command( - name = "armor", - desc = "Gives all bots an armor set.", - autofill = "armorAutofill" + name = "armor", + desc = "Gives all bots an armor set.", + autofill = "armorAutofill" ) @SuppressWarnings("deprecation") public void armor(CommandSender sender, @Arg("armor-tier") String armorTier) { @@ -156,14 +154,17 @@ public class BotCommand extends CommandInstance { ItemStack[] armor = armorTiers.get(tier); manager.fetch().forEach(bot -> { - bot.getBukkitEntity().getInventory().setArmorContents(armor); - bot.getBukkitEntity().updateInventory(); + if (bot.getBukkitEntity() instanceof Player) { + Player botPlayer = (Player) bot.getBukkitEntity(); + botPlayer.getInventory().setArmorContents(armor); + botPlayer.updateInventory(); - // packet sending to ensure - bot.setItem(armor[0], EquipmentSlot.FEET); - bot.setItem(armor[1], EquipmentSlot.LEGS); - bot.setItem(armor[2], EquipmentSlot.CHEST); - bot.setItem(armor[3], EquipmentSlot.HEAD); + // packet sending to ensure + bot.setItem(armor[0], EquipmentSlot.FEET); + bot.setItem(armor[1], EquipmentSlot.LEGS); + bot.setItem(armor[2], EquipmentSlot.CHEST); + bot.setItem(armor[3], EquipmentSlot.HEAD); + } }); sender.sendMessage("Successfully set the armor tier to " + ChatColor.YELLOW + tier + ChatColor.RESET + " for all current bots."); @@ -175,9 +176,9 @@ public class BotCommand extends CommandInstance { } @Command( - name = "info", - desc = "Information about loaded bots.", - autofill = "infoAutofill" + name = "info", + desc = "Information about loaded bots.", + autofill = "infoAutofill" ) public void info(CommandSender sender, @Arg("bot-name") String name) { if (name == null) { @@ -189,7 +190,7 @@ public class BotCommand extends CommandInstance { scheduler.runTaskAsynchronously(plugin, () -> { try { - Bot bot = manager.getFirst(name); + Terminator bot = manager.getFirst(name); if (bot == null) { sender.sendMessage("Could not find bot " + ChatColor.GREEN + name + ChatColor.RESET + "!"); @@ -207,7 +208,7 @@ public class BotCommand extends CommandInstance { * neural network values (network name if loaded, otherwise RANDOM) */ - String botName = bot.getName().getString(); + String botName = bot.getBotName(); String world = ChatColor.YELLOW + bot.getBukkitEntity().getWorld().getName(); Location loc = bot.getLocation(); String strLoc = ChatColor.YELLOW + formatter.format(loc.getBlockX()) + ", " + formatter.format(loc.getBlockY()) + ", " + formatter.format(loc.getBlockZ()); @@ -220,9 +221,7 @@ public class BotCommand extends CommandInstance { sender.sendMessage(ChatUtils.BULLET_FORMATTED + "Position: " + strLoc); sender.sendMessage(ChatUtils.BULLET_FORMATTED + "Velocity: " + strVel); sender.sendMessage(ChatUtils.LINE); - } - - catch (Exception e) { + } catch (Exception e) { sender.sendMessage(ChatUtils.EXCEPTION_MESSAGE); } }); @@ -234,8 +233,8 @@ public class BotCommand extends CommandInstance { } @Command( - name = "reset", - desc = "Remove all loaded bots." + name = "reset", + desc = "Remove all loaded bots." ) public void reset(CommandSender sender) { sender.sendMessage("Removing every bot..."); @@ -257,10 +256,10 @@ public class BotCommand extends CommandInstance { * basically, in the @Command annotation, you can include a "parent" for the command, so it will be a subcommand under the specified parent */ @Command( - name = "settings", - desc = "Make changes to the global configuration file and bot-specific settings.", - aliases = "options", - autofill = "settingsAutofill" + name = "settings", + desc = "Make changes to the global configuration file and bot-specific settings.", + aliases = "options", + autofill = "settingsAutofill" ) public void settings(CommandSender sender, List args) { String arg1 = args.isEmpty() ? null : args.get(0); @@ -307,9 +306,7 @@ public class BotCommand extends CommandInstance { if (args.length == 2) { output.add("setgoal"); - } - - else if (args.length == 3) { + } else if (args.length == 3) { if (args[1].equalsIgnoreCase("setgoal")) { Arrays.stream(EnumTargetGoal.values()).forEach(goal -> output.add(goal.name().replace("_", "").toLowerCase())); } @@ -319,9 +316,9 @@ public class BotCommand extends CommandInstance { } @Command( - name = "debug", - desc = "Debug plugin code.", - visible = false + name = "debug", + desc = "Debug plugin code.", + visible = false ) public void debug(CommandSender sender, @Arg("expression") String expression) { new Debugger(sender).execute(expression); diff --git a/src/main/java/net/nuggetmc/tplus/command/commands/MainCommand.java b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/commands/MainCommand.java similarity index 98% rename from src/main/java/net/nuggetmc/tplus/command/commands/MainCommand.java rename to TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/commands/MainCommand.java index 59ad796..571ef79 100644 --- a/src/main/java/net/nuggetmc/tplus/command/commands/MainCommand.java +++ b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/commands/MainCommand.java @@ -6,10 +6,10 @@ import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.hover.content.Text; import net.nuggetmc.tplus.TerminatorPlus; +import net.nuggetmc.tplus.api.utils.ChatUtils; import net.nuggetmc.tplus.command.CommandHandler; import net.nuggetmc.tplus.command.CommandInstance; import net.nuggetmc.tplus.command.annotation.Command; -import net.nuggetmc.tplus.utils.ChatUtils; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; diff --git a/src/main/java/net/nuggetmc/tplus/command/exception/ArgCountException.java b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/exception/ArgCountException.java similarity index 100% rename from src/main/java/net/nuggetmc/tplus/command/exception/ArgCountException.java rename to TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/exception/ArgCountException.java diff --git a/src/main/java/net/nuggetmc/tplus/command/exception/ArgParseException.java b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/exception/ArgParseException.java similarity index 100% rename from src/main/java/net/nuggetmc/tplus/command/exception/ArgParseException.java rename to TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/exception/ArgParseException.java diff --git a/src/main/java/net/nuggetmc/tplus/command/exception/NonPlayerException.java b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/exception/NonPlayerException.java similarity index 100% rename from src/main/java/net/nuggetmc/tplus/command/exception/NonPlayerException.java rename to TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/exception/NonPlayerException.java diff --git a/src/main/java/net/nuggetmc/tplus/command/nms/TPCommand.java b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/nms/TPCommand.java similarity index 100% rename from src/main/java/net/nuggetmc/tplus/command/nms/TPCommand.java rename to TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/command/nms/TPCommand.java diff --git a/src/main/java/net/nuggetmc/tplus/utils/Debugger.java b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/utils/Debugger.java similarity index 83% rename from src/main/java/net/nuggetmc/tplus/utils/Debugger.java rename to TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/utils/Debugger.java index 2dac5ad..42a5caf 100644 --- a/src/main/java/net/nuggetmc/tplus/utils/Debugger.java +++ b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/utils/Debugger.java @@ -1,12 +1,17 @@ package net.nuggetmc.tplus.utils; -import net.minecraft.world.entity.LivingEntity; +import net.minecraft.server.network.ServerGamePacketListenerImpl; import net.nuggetmc.tplus.TerminatorPlus; +import net.nuggetmc.tplus.api.Terminator; +import net.nuggetmc.tplus.api.agent.Agent; +import net.nuggetmc.tplus.api.agent.legacyagent.LegacyAgent; +import net.nuggetmc.tplus.api.agent.legacyagent.ai.IntelligenceAgent; +import net.nuggetmc.tplus.api.agent.legacyagent.ai.NeuralNetwork; +import net.nuggetmc.tplus.api.utils.DebugLogUtils; +import net.nuggetmc.tplus.api.utils.MathUtils; +import net.nuggetmc.tplus.api.utils.MojangAPI; +import net.nuggetmc.tplus.api.utils.PlayerUtils; import net.nuggetmc.tplus.bot.Bot; -import net.nuggetmc.tplus.bot.agent.Agent; -import net.nuggetmc.tplus.bot.agent.legacyagent.LegacyAgent; -import net.nuggetmc.tplus.bot.agent.legacyagent.ai.IntelligenceAgent; -import net.nuggetmc.tplus.bot.agent.legacyagent.ai.NeuralNetwork; import net.nuggetmc.tplus.command.commands.AICommand; import org.bukkit.*; import org.bukkit.command.CommandSender; @@ -23,28 +28,15 @@ import java.util.stream.Collectors; public class Debugger { - private static final String PREFIX = ChatColor.YELLOW + "[DEBUG] " + ChatColor.RESET; - private final CommandSender sender; public Debugger(CommandSender sender) { this.sender = sender; } - public static void log(Object... objects) { - String[] values = formStringArray(objects); - String message = PREFIX + String.join(" ", values); - - Bukkit.getConsoleSender().sendMessage(message); - Bukkit.getOnlinePlayers().stream().filter(ServerOperator::isOp).forEach(p -> p.sendMessage(message)); - } - - private static String[] formStringArray(Object[] objects) { - return Arrays.stream(objects).map(String::valueOf).toArray(String[]::new); - } private void print(Object... objects) { - sender.sendMessage(PREFIX + String.join(" ", formStringArray(objects))); + sender.sendMessage(DebugLogUtils.PREFIX + String.join(" ", DebugLogUtils.fromStringArray(objects))); } public void execute(String cmd) { @@ -60,9 +52,7 @@ public class Debugger { Statement statement = new Statement(this, name, args); print("Running the expression \"" + ChatColor.AQUA + cmd + ChatColor.RESET + "\"..."); statement.execute(); - } - - catch (Exception e) { + } catch (Exception e) { print("Error: the expression \"" + ChatColor.AQUA + cmd + ChatColor.RESET + "\" failed to execute."); print(e.toString()); } @@ -80,11 +70,13 @@ public class Debugger { try { obj = Double.parseDouble(value); - } catch (NumberFormatException ignored) { } + } catch (NumberFormatException ignored) { + } try { obj = Integer.parseInt(value); - } catch (NumberFormatException ignored) { } + } catch (NumberFormatException ignored) { + } if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) { obj = Boolean.parseBoolean(value); @@ -187,6 +179,17 @@ public class Debugger { } } + public void renderBots() { + int rendered = 0; + for (Terminator fetch : TerminatorPlus.getInstance().getManager().fetch()) { + rendered++; + Bot bot = (Bot) fetch; + ServerGamePacketListenerImpl connection = bot.getBukkitEntity().getHandle().connection; + fetch.renderBot(connection, true); + } + print("Rendered " + rendered + " bots."); + } + public void lol(String name, String skinName) { String[] skin = MojangAPI.getSkin(skinName); @@ -222,7 +225,7 @@ public class Debugger { public void tpall() { Player player = (Player) sender; - TerminatorPlus.getInstance().getManager().fetch().stream().filter(LivingEntity::isAlive).forEach(bot -> bot.getBukkitEntity().teleport(player)); + TerminatorPlus.getInstance().getManager().fetch().stream().filter(Terminator::isBotAlive).forEach(bot -> bot.getBukkitEntity().teleport(player)); } public void viewsession() { @@ -244,9 +247,7 @@ public class Debugger { LegacyAgent legacyAgent = (LegacyAgent) agent; legacyAgent.offsets = b; - print("Bot target offsets are now " - + (legacyAgent.offsets ? ChatColor.GREEN + "ENABLED" : ChatColor.RED + "DISABLED") - + ChatColor.RESET + "."); + print("Bot target offsets are now " + (legacyAgent.offsets ? ChatColor.GREEN + "ENABLED" : ChatColor.RED + "DISABLED") + ChatColor.RESET + "."); } public void confuse(int n) { @@ -269,12 +270,7 @@ public class Debugger { } public void dreamsmp() { - spawnBots(Arrays.asList( - "Dream", "GeorgeNotFound", "Callahan", "Sapnap", "awesamdude", "Ponk", "BadBoyHalo", "TommyInnit", "Tubbo_", "ItsFundy", "Punz", - "Purpled", "WilburSoot", "Jschlatt", "Skeppy", "The_Eret", "JackManifoldTV", "Nihachu", "Quackity", "KarlJacobs", "HBomb94", - "Technoblade", "Antfrost", "Ph1LzA", "ConnorEatsPants", "CaptainPuffy", "Vikkstar123", "LazarCodeLazar", "Ranboo", "FoolishG", - "hannahxxrose", "Slimecicle", "Michaelmcchill" - )); + spawnBots(Arrays.asList("Dream", "GeorgeNotFound", "Callahan", "Sapnap", "awesamdude", "Ponk", "BadBoyHalo", "TommyInnit", "Tubbo_", "ItsFundy", "Punz", "Purpled", "WilburSoot", "Jschlatt", "Skeppy", "The_Eret", "JackManifoldTV", "Nihachu", "Quackity", "KarlJacobs", "HBomb94", "Technoblade", "Antfrost", "Ph1LzA", "ConnorEatsPants", "CaptainPuffy", "Vikkstar123", "LazarCodeLazar", "Ranboo", "FoolishG", "hannahxxrose", "Slimecicle", "Michaelmcchill")); } private void spawnBots(List players) { @@ -319,9 +315,7 @@ public class Debugger { print("Done."); }); - } - - catch (Exception e) { + } catch (Exception e) { print(e); } }); @@ -352,14 +346,14 @@ public class Debugger { } public void tp() { - Bot bot = MathUtils.getRandomSetElement(TerminatorPlus.getInstance().getManager().fetch().stream().filter(LivingEntity::isAlive).collect(Collectors.toSet())); + Terminator bot = MathUtils.getRandomSetElement(TerminatorPlus.getInstance().getManager().fetch().stream().filter(Terminator::isBotAlive).collect(Collectors.toSet())); if (bot == null) { print("Failed to locate a bot."); return; } - print("Located bot", (ChatColor.GREEN.toString() + bot.getName() + ChatColor.RESET.toString() + ".")); + print("Located bot", (ChatColor.GREEN + bot.getBotName() + ChatColor.RESET + ".")); if (sender instanceof Player) { print("Teleporting..."); @@ -386,9 +380,9 @@ public class Debugger { } public void hideNametags() { // this works for some reason - Set bots = TerminatorPlus.getInstance().getManager().fetch(); + Set bots = TerminatorPlus.getInstance().getManager().fetch(); - for (Bot bot : bots) { + for (Terminator bot : bots) { Location loc = bot.getLocation(); World world = loc.getWorld(); @@ -409,9 +403,9 @@ public class Debugger { } public void sit() { - Set bots = TerminatorPlus.getInstance().getManager().fetch(); + Set bots = TerminatorPlus.getInstance().getManager().fetch(); - for (Bot bot : bots) { + for (Terminator bot : bots) { Location loc = bot.getLocation(); World world = loc.getWorld(); @@ -440,7 +434,7 @@ public class Debugger { Player player = (Player) sender; - for (Bot bot : TerminatorPlus.getInstance().getManager().fetch()) { + for (Terminator bot : TerminatorPlus.getInstance().getManager().fetch()) { bot.faceLocation(player.getEyeLocation()); } } @@ -451,8 +445,6 @@ public class Debugger { boolean b = agent.isEnabled(); agent.setEnabled(!b); - 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 + "."); } } diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..8948a51 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,45 @@ +plugins { + id("java") +} + +group = "net.nuggetmc" +version = "3.2-BETA" + +val jarName = "TerminatorPlus-" + version; + +repositories { + mavenCentral() +} + +dependencies { + implementation(project(":TerminatorPlus-Plugin", "reobf")) + implementation(project(":TerminatorPlus-API")) +} + +tasks.processResources { + val props = mapOf("version" to version) + inputs.properties(props) + filteringCharset = Charsets.UTF_8.name() // We want UTF-8 for everything + filesMatching("plugin.yml") { + expand(props) + } +} + +tasks.jar { + from(configurations.compileClasspath.get().map { if (it.isDirectory()) it else zipTree(it) }) + archiveFileName.set(jarName + ".jar") +} + +//TODO currently, the resources are in src/main/resources, because gradle is stubborn and won't include the resources in TerminatorPlus-Plugin/src/main/resources, will need to fix + +/* +task copyPlugin(type: Copy) { + from 'build/libs/' + jarName + '.jar' + into 'run/plugins' +} + */ + +tasks.register("copyPlugin", Copy::class.java) { + from("build/libs/" + jarName + ".jar") + into("run/plugins") +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..41d9927 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..41dfb87 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..1b6c787 --- /dev/null +++ b/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 9deaa4b..0000000 --- a/pom.xml +++ /dev/null @@ -1,118 +0,0 @@ - - - 4.0.0 - net.nuggetmc - TerminatorPlus - 3.1-BETA - TerminatorPlus - - - UTF-8 - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - 8 - 8 - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - - - true - shaded - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.3.1 - - - net.md-5 - specialsource-maven-plugin - 1.2.2 - - - package - - remap - - remap-obf - - org.spigotmc:minecraft-server:1.18.1-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:1.18.1-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:jar:remapped-obf - - - - - - - - src/main/resources - true - - - - - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - - dre-repo - https://erethon.de/repo/ - - - - - - - org.spigotmc - spigot - 1.18.1-R0.1-SNAPSHOT - remapped-mojang - provided - - - diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..480e09f --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,10 @@ +pluginManagement { + repositories { + gradlePluginPortal() + maven("https://repo.papermc.io/repository/maven-public/") + } +} + +rootProject.name = "TerminatorPlus" +include("TerminatorPlus-Plugin") +include("TerminatorPlus-API") diff --git a/src/main/java/net/nuggetmc/tplus/bot/event/BotDeathEvent.java b/src/main/java/net/nuggetmc/tplus/bot/event/BotDeathEvent.java deleted file mode 100644 index 40e04f5..0000000 --- a/src/main/java/net/nuggetmc/tplus/bot/event/BotDeathEvent.java +++ /dev/null @@ -1,18 +0,0 @@ -package net.nuggetmc.tplus.bot.event; - -import net.nuggetmc.tplus.bot.Bot; -import org.bukkit.event.entity.PlayerDeathEvent; - -public class BotDeathEvent extends PlayerDeathEvent { - - private final Bot bot; - - public BotDeathEvent(PlayerDeathEvent event, Bot bot) { - super(event.getEntity(), event.getDrops(), event.getDroppedExp(), event.getDeathMessage()); - this.bot = bot; - } - - public Bot getBot() { - return bot; - } -} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 47b5f6c..0804d01 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: TerminatorPlus main: net.nuggetmc.tplus.TerminatorPlus -version: ${project.version} +version: ${version} api-version: 1.16 author: HorseNuggets @@ -12,4 +12,4 @@ permissions: terminatorplus.manage: true terminatorplus.manage: description: Allows for TerminatorPlus bot management. - default: op \ No newline at end of file + default: op