Merge pull request #50 from Badbird5907/master

Seperate API to another module & use gradle + paper userdev
This commit is contained in:
Badbird5907
2022-06-24 21:48:17 -04:00
committed by GitHub
69 changed files with 1369 additions and 707 deletions

View File

@@ -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")
}

View File

@@ -0,0 +1,5 @@
package net.nuggetmc.tplus.api;
public interface AIManager {
void clearSession();
}

View File

@@ -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<Terminator> fetch();
Agent getAgent();
void add(Terminator bot);
Terminator getFirst(String name);
List<String> fetchNames();
void createBots(Player sender, String name, String skinName, int n);
void createBots(Player sender, String name, String skinName, int n, NeuralNetwork network);
Set<Terminator> createBots(Location loc, String name, String[] skin, List<NeuralNetwork> networks);
Set<Terminator> 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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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;
}
}

View File

@@ -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<BukkitRunnable> 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();

View File

@@ -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<Bot> bots = manager.fetch();
Set<Terminator> 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()

View File

@@ -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());

View File

@@ -1,4 +1,4 @@
package net.nuggetmc.tplus.bot.agent.botagent;
package net.nuggetmc.tplus.api.agent.botagent;
public enum VerticalDisplacement {
AT,

View File

@@ -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;

View File

@@ -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<Terminator> noFace = new HashSet<>();
public final Set<LivingEntity> noJump = new HashSet<>();
public final Set<Terminator> 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<Player, BukkitRunnable> miningAnim = new HashMap<>();
private final Map<LivingEntity, BukkitRunnable> miningAnim = new HashMap<>();
private final Set<Boat> boats = new HashSet<>();
private final Map<Player, Location> btList = new HashMap<>();
private final Map<Player, Boolean> btCheck = new HashMap<>();
private final Map<Player, Location> towerList = new HashMap<>();
private final Set<Bot> boatCooldown = new HashSet<>();
private final Map<LivingEntity, Location> btList = new HashMap<>();
private final Map<LivingEntity, Boolean> btCheck = new HashMap<>();
private final Map<LivingEntity, Location> towerList = new HashMap<>();
private final Set<Terminator> boatCooldown = new HashSet<>();
private final Map<Block, Short> crackList = new HashMap<>();
private final Map<BukkitRunnable, Byte> mining = new HashMap<>();
private final Set<Terminator> fallDamageCooldown = new HashSet<>();
public boolean offsets = true;
private EnumTargetGoal goal;
private final Set<Bot> fallDamageCooldown = new HashSet<>();
public LegacyAgent(BotManager manager, Plugin plugin) {
super(manager, plugin);
public final Set<Bot> noFace = new HashSet<>();
public final Set<Player> noJump = new HashSet<>();
this.goal = EnumTargetGoal.NEAREST_VULNERABLE_PLAYER;
this.blockCheck = new LegacyBlockCheck(this, plugin);
}
public final Set<Bot> 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<Boat> 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;
}
}

View File

@@ -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<Block> 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);
}

View File

@@ -1,4 +1,4 @@
package net.nuggetmc.tplus.bot.agent.legacyagent;
package net.nuggetmc.tplus.api.agent.legacyagent;
import org.bukkit.Material;

View File

@@ -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;

View File

@@ -1,4 +1,4 @@
package net.nuggetmc.tplus.bot.agent.legacyagent;
package net.nuggetmc.tplus.api.agent.legacyagent;
import org.bukkit.Material;

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -1,4 +1,4 @@
package net.nuggetmc.tplus.bot.agent.legacyagent.ai;
package net.nuggetmc.tplus.api.agent.legacyagent.ai;
public enum ActivationType {
TANH,

View File

@@ -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<BotDataType, Double> 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);
}

View File

@@ -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"),

View File

@@ -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)

View File

@@ -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<String, Bot> bots;
private final Map<String, Terminator> bots;
private int populationSize;
private int generation;
@@ -57,9 +56,9 @@ public class IntelligenceAgent {
private final Set<CommandSender> users;
private final Map<Integer, Set<Map<BotNode, Map<BotDataType, Double>>>> 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<Bot> bots;
Set<Terminator> 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<Bot, Integer> values = new HashMap<>();
HashMap<Terminator, Integer> values = new HashMap<>();
for (Bot bot : bots.values()) {
for (Terminator bot : bots.values()) {
values.put(bot, bot.getAliveTicks());
}
List<Map.Entry<Bot, Integer>> sorted = MathUtils.sortByValue(values);
Set<Bot> winners = new HashSet<>();
List<Map.Entry<Terminator, Integer>> sorted = MathUtils.sortByValue(values);
Set<Terminator> winners = new HashSet<>();
int i = 1;
for (Map.Entry<Bot, Integer> entry : sorted) {
Bot bot = entry.getKey();
for (Map.Entry<Terminator, Integer> 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();
}

View File

@@ -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.*;

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -1,4 +1,4 @@
package net.nuggetmc.tplus.utils;
package net.nuggetmc.tplus.api.utils;
import org.bukkit.Location;
import org.bukkit.Material;

View File

@@ -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);

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -1,4 +1,4 @@
package net.nuggetmc.tplus.utils;
package net.nuggetmc.tplus.api.utils;
import org.bukkit.inventory.ItemStack;

View File

@@ -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<Map.Entry<Bot, Integer>> sortByValue(HashMap<Bot, Integer> hm) {
List<Map.Entry<Bot, Integer>> list = new LinkedList<>(hm.entrySet());
public static List<Map.Entry<Terminator, Integer>> sortByValue(HashMap<Terminator, Integer> hm) {
List<Map.Entry<Terminator, Integer>> 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
};
}

View File

@@ -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;

View File

@@ -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<String> USERNAME_CACHE = new HashSet<>();
public static boolean isInvincible(GameMode mode) {
return mode != GameMode.SURVIVAL && mode != GameMode.ADVENTURE && mode != null;
}
private static final Set<String> 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.");
}
}

View File

@@ -1,4 +1,4 @@
package net.nuggetmc.tplus.utils;
package net.nuggetmc.tplus.api.utils;
public class Singularity {

View File

@@ -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"))
}
*/
}

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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<Bot> bots;
private final Set<Terminator> 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<Bot> fetch() {
@Override
public Set<Terminator> 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<String> 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<Bot> createBots(Location loc, String name, String[] skin, int n, NeuralNetwork network) {
@Override
public Set<Terminator> createBots(Location loc, String name, String[] skin, int n, NeuralNetwork network) {
List<NeuralNetwork> 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<Bot> createBots(Location loc, String name, String[] skin, List<NeuralNetwork> networks) {
Set<Bot> bots = new HashSet<>();
@Override
public Set<Terminator> createBots(Location loc, String name, String[] skin, List<NeuralNetwork> networks) {
Set<Terminator> 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));
}

View File

@@ -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());
}
}

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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 + "!");

View File

@@ -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<String, ItemStack[]> 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<String, ItemStack[]> 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<String> 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);

View File

@@ -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;

View File

@@ -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<String> 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<Bot> bots = TerminatorPlus.getInstance().getManager().fetch();
Set<Terminator> 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<Bot> bots = TerminatorPlus.getInstance().getManager().fetch();
Set<Terminator> 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 + ".");
}
}

45
build.gradle.kts Normal file
View File

@@ -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")
}

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@@ -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

234
gradlew vendored Normal file
View File

@@ -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" "$@"

89
gradlew.bat vendored Normal file
View File

@@ -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

118
pom.xml
View File

@@ -1,118 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.nuggetmc</groupId>
<artifactId>TerminatorPlus</artifactId>
<version>3.1-BETA</version>
<name>TerminatorPlus</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>shaded</shadedClassifierName>
<!--
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
-->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
</plugin>
<plugin>
<groupId>net.md-5</groupId>
<artifactId>specialsource-maven-plugin</artifactId>
<version>1.2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-obf</id>
<configuration>
<srgIn>org.spigotmc:minecraft-server:1.18.1-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
<reverse>true</reverse>
<remappedDependencies>org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
<remappedArtifactAttached>true</remappedArtifactAttached>
<remappedClassifierName>remapped-obf</remappedClassifierName>
</configuration>
</execution>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-spigot</id>
<configuration>
<inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
<srgIn>org.spigotmc:minecraft-server:1.18.1-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
<remappedDependencies>org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
<!-- Spigot Repo -->
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<!-- Advanced Spigot Repo -->
<repository>
<id>dre-repo</id>
<url>https://erethon.de/repo/</url>
</repository>
</repositories>
<dependencies>
<!--Spigot + Bukkit -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version>
<classifier>remapped-mojang</classifier>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

10
settings.gradle.kts Normal file
View File

@@ -0,0 +1,10 @@
pluginManagement {
repositories {
gradlePluginPortal()
maven("https://repo.papermc.io/repository/maven-public/")
}
}
rootProject.name = "TerminatorPlus"
include("TerminatorPlus-Plugin")
include("TerminatorPlus-API")

View File

@@ -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;
}
}

View File

@@ -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
default: op