Merge pull request #50 from Badbird5907/master
Seperate API to another module & use gradle + paper userdev
This commit is contained in:
22
TerminatorPlus-API/build.gradle.kts
Normal file
22
TerminatorPlus-API/build.gradle.kts
Normal 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")
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package net.nuggetmc.tplus.api;
|
||||||
|
|
||||||
|
public interface AIManager {
|
||||||
|
void clearSession();
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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.api.BotManager;
|
||||||
import net.nuggetmc.tplus.bot.Bot;
|
import net.nuggetmc.tplus.api.Terminator;
|
||||||
import net.nuggetmc.tplus.bot.BotManager;
|
import net.nuggetmc.tplus.api.event.BotDamageByPlayerEvent;
|
||||||
import net.nuggetmc.tplus.bot.event.BotDamageByPlayerEvent;
|
import net.nuggetmc.tplus.api.event.BotDeathEvent;
|
||||||
import net.nuggetmc.tplus.bot.event.BotDeathEvent;
|
import net.nuggetmc.tplus.api.event.BotFallDamageEvent;
|
||||||
import net.nuggetmc.tplus.bot.event.BotFallDamageEvent;
|
import net.nuggetmc.tplus.api.event.BotKilledByPlayerEvent;
|
||||||
import net.nuggetmc.tplus.bot.event.BotKilledByPlayerEvent;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
public abstract class Agent {
|
public abstract class Agent {
|
||||||
|
|
||||||
protected final TerminatorPlus plugin;
|
protected final Plugin plugin;
|
||||||
protected final BotManager manager;
|
protected final BotManager manager;
|
||||||
protected final BukkitScheduler scheduler;
|
protected final BukkitScheduler scheduler;
|
||||||
protected final Set<BukkitRunnable> taskList;
|
protected final Set<BukkitRunnable> taskList;
|
||||||
@@ -29,8 +29,8 @@ public abstract class Agent {
|
|||||||
|
|
||||||
protected boolean drops;
|
protected boolean drops;
|
||||||
|
|
||||||
public Agent(BotManager manager) {
|
public Agent(BotManager manager, Plugin plugin) {
|
||||||
this.plugin = TerminatorPlus.getInstance();
|
this.plugin = plugin;
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.scheduler = Bukkit.getScheduler();
|
this.scheduler = Bukkit.getScheduler();
|
||||||
this.taskList = new HashSet<>();
|
this.taskList = new HashSet<>();
|
||||||
@@ -67,17 +67,20 @@ public abstract class Agent {
|
|||||||
|
|
||||||
protected abstract void tick();
|
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) {
|
public void onBotKilledByPlayer(BotKilledByPlayerEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
scheduler.runTaskAsynchronously(plugin, () -> {
|
scheduler.runTaskAsynchronously(plugin, () -> {
|
||||||
Bot bot = manager.getBot(player);
|
Terminator bot = manager.getBot(player);
|
||||||
|
|
||||||
if (bot != null) {
|
if (bot != null) {
|
||||||
bot.incrementKills();
|
bot.incrementKills();
|
||||||
@@ -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.api.BotManager;
|
||||||
import net.nuggetmc.tplus.bot.BotManager;
|
import net.nuggetmc.tplus.api.Terminator;
|
||||||
import net.nuggetmc.tplus.bot.agent.Agent;
|
import net.nuggetmc.tplus.api.agent.Agent;
|
||||||
import net.nuggetmc.tplus.utils.MathUtils;
|
import net.nuggetmc.tplus.api.utils.MathUtils;
|
||||||
import net.nuggetmc.tplus.utils.PlayerUtils;
|
import net.nuggetmc.tplus.api.utils.PlayerUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -22,20 +23,20 @@ public class BotAgent extends Agent {
|
|||||||
|
|
||||||
private int count;
|
private int count;
|
||||||
|
|
||||||
public BotAgent(BotManager manager) {
|
public BotAgent(BotManager manager, Plugin plugin) {
|
||||||
super(manager);
|
super(manager, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tick() {
|
protected void tick() {
|
||||||
Set<Bot> bots = manager.fetch();
|
Set<Terminator> bots = manager.fetch();
|
||||||
count = bots.size();
|
count = bots.size();
|
||||||
bots.forEach(this::tickBot);
|
bots.forEach(this::tickBot);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is where the code starts to get spicy
|
// This is where the code starts to get spicy
|
||||||
private void tickBot(Bot bot) {
|
private void tickBot(Terminator bot) {
|
||||||
if (!bot.isAlive()) return;
|
if (!bot.isBotAlive()) return;
|
||||||
|
|
||||||
Location loc = bot.getLocation();
|
Location loc = bot.getLocation();
|
||||||
|
|
||||||
@@ -90,17 +91,18 @@ public class BotAgent extends Agent {
|
|||||||
if (bot.tickDelay(3)) attack(bot, player, loc);
|
if (bot.tickDelay(3)) attack(bot, player, loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void attack(Bot bot, Player player, Location loc) {
|
private void attack(Terminator bot, Player player, Location loc) {
|
||||||
if (PlayerUtils.isInvincible(player.getGameMode()) || player.getNoDamageTicks() >= 5 || loc.distance(player.getLocation()) >= 4) return;
|
if (PlayerUtils.isInvincible(player.getGameMode()) || player.getNoDamageTicks() >= 5 || loc.distance(player.getLocation()) >= 4)
|
||||||
|
return;
|
||||||
|
|
||||||
bot.attack(player);
|
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();
|
Vector vel = target.toVector().subtract(loc.toVector()).normalize();
|
||||||
|
|
||||||
if (bot.tickDelay(5)) bot.faceLocation(player.getLocation());
|
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.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()
|
bot.setItem(null); // method to check item in main hand, bot.getItemInHand()
|
||||||
@@ -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;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
public class BotSituation {
|
public class BotSituation {
|
||||||
@@ -11,7 +11,7 @@ public class BotSituation {
|
|||||||
* aboveGround
|
* aboveGround
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public BotSituation(Bot bot, Location target) {
|
public BotSituation(Terminator bot, Location target) {
|
||||||
Location loc = bot.getLocation();
|
Location loc = bot.getLocation();
|
||||||
|
|
||||||
this.disp = VerticalDisplacement.fetch(loc.getBlockY(), target.getBlockY());
|
this.disp = VerticalDisplacement.fetch(loc.getBlockY(), target.getBlockY());
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.nuggetmc.tplus.bot.agent.botagent;
|
package net.nuggetmc.tplus.api.agent.botagent;
|
||||||
|
|
||||||
public enum VerticalDisplacement {
|
public enum VerticalDisplacement {
|
||||||
AT,
|
AT,
|
||||||
@@ -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.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -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.nuggetmc.tplus.api.BotManager;
|
||||||
import net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket;
|
import net.nuggetmc.tplus.api.Terminator;
|
||||||
import net.nuggetmc.tplus.bot.Bot;
|
import net.nuggetmc.tplus.api.TerminatorPlusAPI;
|
||||||
import net.nuggetmc.tplus.bot.BotManager;
|
import net.nuggetmc.tplus.api.agent.Agent;
|
||||||
import net.nuggetmc.tplus.bot.agent.Agent;
|
import net.nuggetmc.tplus.api.agent.legacyagent.ai.BotData;
|
||||||
import net.nuggetmc.tplus.bot.agent.legacyagent.ai.BotData;
|
import net.nuggetmc.tplus.api.agent.legacyagent.ai.BotNode;
|
||||||
import net.nuggetmc.tplus.bot.agent.legacyagent.ai.BotNode;
|
import net.nuggetmc.tplus.api.agent.legacyagent.ai.NeuralNetwork;
|
||||||
import net.nuggetmc.tplus.bot.agent.legacyagent.ai.NeuralNetwork;
|
import net.nuggetmc.tplus.api.event.BotDamageByPlayerEvent;
|
||||||
import net.nuggetmc.tplus.bot.event.BotDamageByPlayerEvent;
|
import net.nuggetmc.tplus.api.event.BotDeathEvent;
|
||||||
import net.nuggetmc.tplus.bot.event.BotDeathEvent;
|
import net.nuggetmc.tplus.api.event.BotFallDamageEvent;
|
||||||
import net.nuggetmc.tplus.bot.event.BotFallDamageEvent;
|
import net.nuggetmc.tplus.api.utils.MathUtils;
|
||||||
import net.nuggetmc.tplus.utils.MathUtils;
|
import net.nuggetmc.tplus.api.utils.PlayerUtils;
|
||||||
import net.nuggetmc.tplus.utils.PlayerUtils;
|
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer;
|
import org.bukkit.entity.*;
|
||||||
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.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
@@ -31,73 +25,71 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
// Yes, this code is very unoptimized, I know.
|
// Yes, this code is very unoptimized, I know.
|
||||||
public class LegacyAgent extends Agent {
|
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 final LegacyBlockCheck blockCheck;
|
||||||
|
private final Map<LivingEntity, BukkitRunnable> miningAnim = new HashMap<>();
|
||||||
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 Set<Boat> boats = new HashSet<>();
|
private final Set<Boat> boats = new HashSet<>();
|
||||||
|
private final Map<LivingEntity, Location> btList = new HashMap<>();
|
||||||
private final Map<Player, Location> btList = new HashMap<>();
|
private final Map<LivingEntity, Boolean> btCheck = new HashMap<>();
|
||||||
private final Map<Player, Boolean> btCheck = new HashMap<>();
|
private final Map<LivingEntity, Location> towerList = new HashMap<>();
|
||||||
private final Map<Player, Location> towerList = new HashMap<>();
|
private final Set<Terminator> boatCooldown = new HashSet<>();
|
||||||
|
|
||||||
private final Set<Bot> boatCooldown = new HashSet<>();
|
|
||||||
private final Map<Block, Short> crackList = new HashMap<>();
|
private final Map<Block, Short> crackList = new HashMap<>();
|
||||||
private final Map<BukkitRunnable, Byte> mining = 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<>();
|
this.goal = EnumTargetGoal.NEAREST_VULNERABLE_PLAYER;
|
||||||
public final Set<Player> noJump = new HashSet<>();
|
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
|
@Override
|
||||||
protected void tick() {
|
protected void tick() {
|
||||||
manager.fetch().forEach(this::tickBot);
|
manager.fetch().forEach(this::tickBot);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void center(Bot bot) {
|
private void center(Terminator bot) {
|
||||||
if (bot == null || !bot.isAlive()) {
|
if (bot == null || !bot.isBotAlive()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Player botPlayer = bot.getBukkitEntity();
|
final LivingEntity botEntity = bot.getBukkitEntity();
|
||||||
|
|
||||||
Location prev = null;
|
Location prev = null;
|
||||||
if (btList.containsKey(botPlayer)) {
|
if (btList.containsKey(botEntity)) {
|
||||||
prev = btList.get(botPlayer);
|
prev = btList.get(botEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
Location loc = botPlayer.getLocation();
|
Location loc = botEntity.getLocation();
|
||||||
|
|
||||||
if (prev != null) {
|
if (prev != null) {
|
||||||
if (loc.getBlockX() == prev.getBlockX() && loc.getBlockZ() == prev.getBlockZ()) {
|
if (loc.getBlockX() == prev.getBlockX() && loc.getBlockZ() == prev.getBlockZ()) {
|
||||||
btCheck.put(botPlayer, true);
|
btCheck.put(botEntity, true);
|
||||||
} else {
|
} else {
|
||||||
btCheck.put(botPlayer, false);
|
btCheck.put(botEntity, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
btList.put(botPlayer, loc);
|
btList.put(botEntity, loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tickBot(Bot bot) {
|
private void tickBot(Terminator bot) {
|
||||||
if (!bot.isAlive()) {
|
if (!bot.isBotAlive()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +110,7 @@ public class LegacyAgent extends Agent {
|
|||||||
fallDamageCheck(bot);
|
fallDamageCheck(bot);
|
||||||
miscellaneousChecks(bot, livingTarget);
|
miscellaneousChecks(bot, livingTarget);
|
||||||
|
|
||||||
Player botPlayer = bot.getBukkitEntity();
|
LivingEntity botPlayer = bot.getBukkitEntity();
|
||||||
Location target = offsets ? livingTarget.getLocation().add(bot.getOffset()) : livingTarget.getLocation();
|
Location target = offsets ? livingTarget.getLocation().add(bot.getOffset()) : livingTarget.getLocation();
|
||||||
|
|
||||||
boolean ai = bot.hasNeuralNetwork();
|
boolean ai = bot.hasNeuralNetwork();
|
||||||
@@ -152,7 +144,7 @@ public class LegacyAgent extends Agent {
|
|||||||
|
|
||||||
if (btCheck.containsKey(botPlayer)) sameXZ = btCheck.get(botPlayer);
|
if (btCheck.containsKey(botPlayer)) sameXZ = btCheck.get(botPlayer);
|
||||||
|
|
||||||
if (waterGround || bot.isOnGround() || onBoat(botPlayer)) {
|
if (waterGround || bot.isBotOnGround() || onBoat(botPlayer)) {
|
||||||
byte sideResult = 1;
|
byte sideResult = 1;
|
||||||
|
|
||||||
if (towerList.containsKey(botPlayer)) {
|
if (towerList.containsKey(botPlayer)) {
|
||||||
@@ -190,19 +182,17 @@ public class LegacyAgent extends Agent {
|
|||||||
case 2:
|
case 2:
|
||||||
if (!waterGround) move(bot, livingTarget, loc, target, ai);
|
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()));
|
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 position = loc.toVector();
|
||||||
Vector vel = target.toVector().subtract(position).normalize();
|
Vector vel = target.toVector().subtract(position).normalize();
|
||||||
|
|
||||||
if (bot.tickDelay(5)) bot.faceLocation(livingTarget.getLocation());
|
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.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()
|
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();
|
NeuralNetwork network = bot.getNeuralNetwork();
|
||||||
|
|
||||||
if (network.dynamicLR()) {
|
if (network.dynamicLR()) {
|
||||||
if (bot.isBlocking()) {
|
if (bot.isBotBlocking()) {
|
||||||
vel.multiply(0.6);
|
vel.multiply(0.6);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,13 +249,11 @@ public class LegacyAgent extends Agent {
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
|
||||||
else {
|
|
||||||
boolean left = network.check(BotNode.LEFT);
|
boolean left = network.check(BotNode.LEFT);
|
||||||
boolean right = network.check(BotNode.RIGHT);
|
boolean right = network.check(BotNode.RIGHT);
|
||||||
|
|
||||||
if (bot.isBlocking()) {
|
if (bot.isBotBlocking()) {
|
||||||
vel.multiply(0.6);
|
vel.multiply(0.6);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,7 +282,7 @@ public class LegacyAgent extends Agent {
|
|||||||
bot.jump(vel);
|
bot.jump(vel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fallDamageCheck(Bot bot) {
|
private void fallDamageCheck(Terminator bot) {
|
||||||
if (bot.isFalling()) {
|
if (bot.isFalling()) {
|
||||||
bot.look(BlockFace.DOWN);
|
bot.look(BlockFace.DOWN);
|
||||||
|
|
||||||
@@ -319,13 +307,13 @@ public class LegacyAgent extends Agent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerDamage(BotDamageByPlayerEvent event) {
|
public void onPlayerDamage(BotDamageByPlayerEvent event) {
|
||||||
Bot bot = event.getBot();
|
Terminator bot = event.getBot();
|
||||||
Location loc = bot.getLocation();
|
Location loc = bot.getLocation();
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
double dot = loc.toVector().subtract(player.getLocation().toVector()).normalize().dot(loc.getDirection());
|
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);
|
player.getWorld().playSound(bot.getLocation(), Sound.ITEM_SHIELD_BLOCK, 1, 1);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
@@ -333,7 +321,7 @@ public class LegacyAgent extends Agent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFallDamage(BotFallDamageEvent event) {
|
public void onFallDamage(BotFallDamageEvent event) {
|
||||||
Bot bot = event.getBot();
|
Terminator bot = event.getBot();
|
||||||
World world = bot.getBukkitEntity().getWorld();
|
World world = bot.getBukkitEntity().getWorld();
|
||||||
|
|
||||||
bot.look(BlockFace.DOWN);
|
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) {
|
private void swim(Terminator bot, Location loc, LivingEntity playerNPC, LivingEntity target, boolean anim) {
|
||||||
playerNPC.setSneaking(false);
|
if (playerNPC instanceof Player) {
|
||||||
|
((Player) playerNPC).setSneaking(false);
|
||||||
|
}
|
||||||
|
|
||||||
Location at = bot.getLocation();
|
Location at = bot.getLocation();
|
||||||
|
|
||||||
@@ -412,8 +402,8 @@ public class LegacyAgent extends Agent {
|
|||||||
bot.addVelocity(vector);
|
bot.addVelocity(vector);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopMining(Bot bot) {
|
private void stopMining(Terminator bot) {
|
||||||
Player playerNPC = bot.getBukkitEntity();
|
LivingEntity playerNPC = bot.getBukkitEntity();
|
||||||
if (miningAnim.containsKey(playerNPC)) {
|
if (miningAnim.containsKey(playerNPC)) {
|
||||||
BukkitRunnable task = miningAnim.get(playerNPC);
|
BukkitRunnable task = miningAnim.get(playerNPC);
|
||||||
if (task != null) {
|
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 a = playerNPC.getEyeLocation();
|
||||||
Location b = target.getLocation().add(0, 1, 0);
|
Location b = target.getLocation().add(0, 1, 0);
|
||||||
|
|
||||||
@@ -444,8 +434,8 @@ public class LegacyAgent extends Agent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private LegacyLevel checkNearby(LivingEntity target, Bot npc) {
|
private LegacyLevel checkNearby(LivingEntity target, Terminator npc) {
|
||||||
Player player = npc.getBukkitEntity();
|
LivingEntity player = npc.getBukkitEntity();
|
||||||
|
|
||||||
npc.faceLocation(target.getLocation());
|
npc.faceLocation(target.getLocation());
|
||||||
|
|
||||||
@@ -508,11 +498,7 @@ public class LegacyAgent extends Agent {
|
|||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean checkSideBreak(Material type) {
|
private boolean checkUp(Terminator npc, LivingEntity target, LivingEntity playerNPC, Location loc, boolean c) {
|
||||||
return !LegacyMats.BREAK.contains(type);// && !LegacyMats.LEAVES.contains(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkUp(Bot npc, LivingEntity target, Player playerNPC, Location loc, boolean c) {
|
|
||||||
Location a = playerNPC.getLocation();
|
Location a = playerNPC.getLocation();
|
||||||
Location b = target.getLocation();
|
Location b = target.getLocation();
|
||||||
|
|
||||||
@@ -586,7 +572,7 @@ public class LegacyAgent extends Agent {
|
|||||||
}
|
}
|
||||||
}, 5);
|
}, 5);
|
||||||
|
|
||||||
if (npc.isOnGround()) {
|
if (npc.isBotOnGround()) {
|
||||||
if (target.getLocation().distance(playerNPC.getLocation()) < 16) {
|
if (target.getLocation().distance(playerNPC.getLocation()) < 16) {
|
||||||
if (noJump.contains(playerNPC)) {
|
if (noJump.contains(playerNPC)) {
|
||||||
|
|
||||||
@@ -607,7 +593,7 @@ public class LegacyAgent extends Agent {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (npc.isOnGround()) {
|
if (npc.isBotOnGround()) {
|
||||||
Location locBlock = playerNPC.getLocation();
|
Location locBlock = playerNPC.getLocation();
|
||||||
locBlock.setX(locBlock.getBlockX() + 0.5);
|
locBlock.setX(locBlock.getBlockX() + 0.5);
|
||||||
locBlock.setZ(locBlock.getBlockZ() + 0.5);
|
locBlock.setZ(locBlock.getBlockZ() + 0.5);
|
||||||
@@ -630,7 +616,7 @@ public class LegacyAgent extends Agent {
|
|||||||
npc.look(BlockFace.UP);
|
npc.look(BlockFace.UP);
|
||||||
preBreak(npc, playerNPC, block, LegacyLevel.ABOVE);
|
preBreak(npc, playerNPC, block, LegacyLevel.ABOVE);
|
||||||
|
|
||||||
if (npc.isOnGround()) {
|
if (npc.isBotOnGround()) {
|
||||||
Location locBlock = playerNPC.getLocation();
|
Location locBlock = playerNPC.getLocation();
|
||||||
locBlock.setX(locBlock.getBlockX() + 0.5);
|
locBlock.setX(locBlock.getBlockX() + 0.5);
|
||||||
locBlock.setZ(locBlock.getBlockZ() + 0.5);
|
locBlock.setZ(locBlock.getBlockZ() + 0.5);
|
||||||
@@ -650,9 +636,10 @@ public class LegacyAgent extends Agent {
|
|||||||
return false;
|
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) {
|
if (c && npc.getLocation().getBlockY() > loc.getBlockY() + 1) {
|
||||||
Block block = npc.getLocation().add(0, -1, 0).getBlock();
|
Block block = npc.getLocation().add(0, -1, 0).getBlock();
|
||||||
@@ -661,9 +648,7 @@ public class LegacyAgent extends Agent {
|
|||||||
downMine(npc, player, block);
|
downMine(npc, player, block);
|
||||||
preBreak(npc, player, block, LegacyLevel.BELOW);
|
preBreak(npc, player, block, LegacyLevel.BELOW);
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
|
|
||||||
else {
|
|
||||||
Location a = loc.clone();
|
Location a = loc.clone();
|
||||||
Location b = player.getLocation();
|
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())) {
|
if (!LegacyMats.NO_CRACK.contains(block.getType())) {
|
||||||
Location locBlock = player.getLocation();
|
Location locBlock = player.getLocation();
|
||||||
locBlock.setX(locBlock.getBlockX() + 0.5);
|
locBlock.setX(locBlock.getBlockX() + 0.5);
|
||||||
@@ -697,7 +682,7 @@ public class LegacyAgent extends Agent {
|
|||||||
npc.setVelocity(vector);
|
npc.setVelocity(vector);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (npc.isInWater()) {
|
if (npc.isBotInWater()) {
|
||||||
Location locBlock = player.getLocation();
|
Location locBlock = player.getLocation();
|
||||||
locBlock.setX(locBlock.getBlockX() + 0.5);
|
locBlock.setX(locBlock.getBlockX() + 0.5);
|
||||||
locBlock.setZ(locBlock.getBlockZ() + 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())) {
|
if (LegacyMats.FENCE.contains(block.getType())) {
|
||||||
preBreak(bot, player, block, LegacyLevel.AT_D);
|
preBreak(bot, player, block, LegacyLevel.AT_D);
|
||||||
return true;
|
return true;
|
||||||
@@ -728,7 +713,7 @@ public class LegacyAgent extends Agent {
|
|||||||
return false;
|
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())) {
|
if (LegacyMats.BREAK.contains(block.getType())) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} 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 item;
|
||||||
Material type = block.getType();
|
Material type = block.getType();
|
||||||
|
|
||||||
@@ -752,7 +737,7 @@ public class LegacyAgent extends Agent {
|
|||||||
bot.setItem(new ItemStack(item));
|
bot.setItem(new ItemStack(item));
|
||||||
|
|
||||||
if (level == LegacyLevel.EAST_D || level == LegacyLevel.NORTH_D || level == LegacyLevel.SOUTH_D || level == LegacyLevel.WEST_D) {
|
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, () -> {
|
scheduler.runTaskLater(plugin, () -> {
|
||||||
btCheck.put(player, true);
|
btCheck.put(player, true);
|
||||||
@@ -780,7 +765,7 @@ public class LegacyAgent extends Agent {
|
|||||||
blockBreakEffect(player, block, level);
|
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;
|
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
|
// wow this repeated code is so bad lmao
|
||||||
|
|
||||||
if (player.isDead()) {
|
if (player.isDead() || (!block.equals(cur) || block.getType() != cur.getType())) {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
|
|
||||||
ClientboundBlockDestructionPacket crack = new ClientboundBlockDestructionPacket(crackList.get(block), new BlockPos(block.getX(), block.getY(), block.getZ()), -1);
|
TerminatorPlusAPI.getInternalBridge().sendBlockDestructionPacket(crackList.get(block), 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
crackList.remove(block);
|
crackList.remove(block);
|
||||||
mining.remove(this);
|
mining.remove(this);
|
||||||
@@ -863,13 +832,12 @@ public class LegacyAgent extends Agent {
|
|||||||
if (i == 9) {
|
if (i == 9) {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
|
|
||||||
ClientboundBlockDestructionPacket crack = new ClientboundBlockDestructionPacket(crackList.get(block), new BlockPos(block.getX(), block.getY(), block.getZ()), -1);
|
TerminatorPlusAPI.getInternalBridge().sendBlockDestructionPacket(crackList.get(block), block.getX(), block.getY(), block.getZ(), -1);
|
||||||
for (Player all : Bukkit.getOnlinePlayers()) {
|
|
||||||
((CraftPlayer) all).getHandle().connection.send(crack);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sound != null) {
|
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();
|
block.breakNaturally();
|
||||||
@@ -888,15 +856,14 @@ public class LegacyAgent extends Agent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sound != null) {
|
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);
|
TerminatorPlusAPI.getInternalBridge().sendBlockDestructionPacket(crackList.get(block), block.getX(), block.getY(), block.getZ(), i);
|
||||||
for (Player all : Bukkit.getOnlinePlayers()) {
|
|
||||||
((CraftPlayer) all).getHandle().connection.send(crack);
|
|
||||||
}
|
|
||||||
|
|
||||||
mining.put(this, (byte) (i + 1));
|
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;
|
if (loc.getBlock().getType() == Material.WATER) return;
|
||||||
|
|
||||||
bot.look(BlockFace.DOWN);
|
bot.look(BlockFace.DOWN);
|
||||||
@@ -930,13 +897,13 @@ public class LegacyAgent extends Agent {
|
|||||||
}, 5);
|
}, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void miscellaneousChecks(Bot bot, LivingEntity target) {
|
private void miscellaneousChecks(Terminator bot, LivingEntity target) {
|
||||||
Player botPlayer = bot.getBukkitEntity();
|
LivingEntity botPlayer = bot.getBukkitEntity();
|
||||||
World world = botPlayer.getWorld();
|
World world = botPlayer.getWorld();
|
||||||
String worldName = world.getName();
|
String worldName = world.getName();
|
||||||
Location loc = bot.getLocation();
|
Location loc = bot.getLocation();
|
||||||
|
|
||||||
if (bot.isOnFire()) {
|
if (bot.isBotOnFire()) {
|
||||||
if (bot.getBukkitEntity().getWorld().getEnvironment() != World.Environment.NETHER) {
|
if (bot.getBukkitEntity().getWorld().getEnvironment() != World.Environment.NETHER) {
|
||||||
placeWaterDown(bot, world, loc);
|
placeWaterDown(bot, world, loc);
|
||||||
}
|
}
|
||||||
@@ -1068,7 +1035,7 @@ public class LegacyAgent extends Agent {
|
|||||||
|
|
||||||
scheduler.runTaskLater(plugin, () -> {
|
scheduler.runTaskLater(plugin, () -> {
|
||||||
boatCooldown.remove(bot);
|
boatCooldown.remove(bot);
|
||||||
if (bot.isAlive()) {
|
if (bot.isBotAlive()) {
|
||||||
bot.faceLocation(target.getLocation());
|
bot.faceLocation(target.getLocation());
|
||||||
}
|
}
|
||||||
}, 5);
|
}, 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
|
if (!noFace.contains(npc)) { // LESSLAG if there is no if statement here
|
||||||
npc.faceLocation(target.getLocation());
|
npc.faceLocation(target.getLocation());
|
||||||
}
|
}
|
||||||
@@ -1094,7 +1061,7 @@ public class LegacyAgent extends Agent {
|
|||||||
npc.setItem(null);
|
npc.setItem(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean onBoat(Player player) {
|
private boolean onBoat(LivingEntity player) {
|
||||||
Set<Boat> cache = new HashSet<>();
|
Set<Boat> cache = new HashSet<>();
|
||||||
|
|
||||||
boolean check = false;
|
boolean check = false;
|
||||||
@@ -1118,8 +1085,9 @@ public class LegacyAgent extends Agent {
|
|||||||
return check;
|
return check;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void attack(Bot bot, LivingEntity target, Location loc) {
|
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;
|
if ((target instanceof Player && PlayerUtils.isInvincible(((Player) target).getGameMode())) || target.getNoDamageTicks() >= 5 || loc.distance(target.getLocation()) >= 4)
|
||||||
|
return;
|
||||||
|
|
||||||
bot.attack(target);
|
bot.attack(target);
|
||||||
}
|
}
|
||||||
@@ -1128,7 +1096,7 @@ public class LegacyAgent extends Agent {
|
|||||||
this.goal = goal;
|
this.goal = goal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LivingEntity locateTarget(Bot bot, Location loc) {
|
public LivingEntity locateTarget(Terminator bot, Location loc) {
|
||||||
LivingEntity result = null;
|
LivingEntity result = null;
|
||||||
|
|
||||||
switch (goal) {
|
switch (goal) {
|
||||||
@@ -1176,9 +1144,9 @@ public class LegacyAgent extends Agent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case NEAREST_BOT: {
|
case NEAREST_BOT: {
|
||||||
for (Bot otherBot : manager.fetch()) {
|
for (Terminator otherBot : manager.fetch()) {
|
||||||
if (bot != otherBot) {
|
if (bot != otherBot) {
|
||||||
Player player = otherBot.getBukkitEntity();
|
LivingEntity player = otherBot.getBukkitEntity();
|
||||||
|
|
||||||
if (validateCloserEntity(player, loc, result)) {
|
if (validateCloserEntity(player, loc, result)) {
|
||||||
result = player;
|
result = player;
|
||||||
@@ -1190,13 +1158,13 @@ public class LegacyAgent extends Agent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case NEAREST_BOT_DIFFER: {
|
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) {
|
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;
|
result = player;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1206,13 +1174,13 @@ public class LegacyAgent extends Agent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case NEAREST_BOT_DIFFER_ALPHA: {
|
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) {
|
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;
|
result = player;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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.api.Terminator;
|
||||||
import net.nuggetmc.tplus.bot.Bot;
|
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -15,17 +15,18 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class LegacyBlockCheck {
|
public class LegacyBlockCheck {
|
||||||
|
|
||||||
private final TerminatorPlus plugin;
|
private final Plugin plugin;
|
||||||
private final LegacyAgent agent;
|
private final LegacyAgent agent;
|
||||||
|
|
||||||
public LegacyBlockCheck(LegacyAgent agent) {
|
public LegacyBlockCheck(LegacyAgent agent, Plugin plugin) {
|
||||||
this.plugin = TerminatorPlus.getInstance();
|
this.plugin = plugin;
|
||||||
this.agent = agent;
|
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) {
|
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));
|
bot.setItem(new ItemStack(Material.COBBLESTONE));
|
||||||
loc.getBlock().setType(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();
|
Location loc = block.getLocation();
|
||||||
|
|
||||||
@@ -116,23 +117,26 @@ public class LegacyBlockCheck {
|
|||||||
Bukkit.getScheduler().runTaskLater(plugin, () -> {
|
Bukkit.getScheduler().runTaskLater(plugin, () -> {
|
||||||
Block b2 = loc.clone().add(0, -1, 0).getBlock();
|
Block b2 = loc.clone().add(0, -1, 0).getBlock();
|
||||||
if (LegacyMats.SPAWN.contains(b2.getType())) {
|
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());
|
placeFinal(bot, player, b2.getLocation());
|
||||||
}
|
}
|
||||||
}, 1);
|
}, 1);
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(plugin, () -> {
|
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());
|
placeFinal(bot, player, block.getLocation());
|
||||||
}, 3);
|
}, 3);
|
||||||
return;
|
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());
|
placeFinal(bot, player, block.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clutch(Bot bot, LivingEntity target) {
|
public void clutch(Terminator bot, LivingEntity target) {
|
||||||
Location botLoc = bot.getLocation();
|
Location botLoc = bot.getLocation();
|
||||||
|
|
||||||
Material type = botLoc.clone().add(0, -1, 0).getBlock().getType();
|
Material type = botLoc.clone().add(0, -1, 0).getBlock().getType();
|
||||||
@@ -181,7 +185,8 @@ public class LegacyBlockCheck {
|
|||||||
|
|
||||||
bot.punch();
|
bot.punch();
|
||||||
bot.sneak();
|
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));
|
bot.setItem(new ItemStack(Material.COBBLESTONE));
|
||||||
loc.getBlock().setType(Material.COBBLESTONE);
|
loc.getBlock().setType(Material.COBBLESTONE);
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.nuggetmc.tplus.bot.agent.legacyagent;
|
package net.nuggetmc.tplus.api.agent.legacyagent;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
@@ -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.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.nuggetmc.tplus.bot.agent.legacyagent;
|
package net.nuggetmc.tplus.api.agent.legacyagent;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
@@ -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.nuggetmc.tplus.api.TerminatorPlusAPI;
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import net.minecraft.world.level.block.SoundType;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
|
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
public class LegacyUtils {
|
public class LegacyUtils {
|
||||||
|
|
||||||
public static boolean checkFreeSpace(Location a, Location b) {
|
public static boolean checkFreeSpace(Location a, Location b) {
|
||||||
@@ -38,12 +32,6 @@ public class LegacyUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Sound breakBlockSound(Block block) {
|
public static Sound breakBlockSound(Block block) {
|
||||||
Level nmsWorld = ((CraftWorld) block.getWorld()).getHandle();
|
return TerminatorPlusAPI.getInternalBridge().breakBlockSound(block);
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.nuggetmc.tplus.bot.agent.legacyagent.ai;
|
package net.nuggetmc.tplus.api.agent.legacyagent.ai;
|
||||||
|
|
||||||
public enum ActivationType {
|
public enum ActivationType {
|
||||||
TANH,
|
TANH,
|
||||||
@@ -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.api.Terminator;
|
||||||
import net.nuggetmc.tplus.utils.MathUtils;
|
import net.nuggetmc.tplus.api.utils.MathUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
@@ -14,13 +14,13 @@ public class BotData {
|
|||||||
|
|
||||||
private final Map<BotDataType, Double> values;
|
private final Map<BotDataType, Double> values;
|
||||||
|
|
||||||
private BotData(Bot bot, LivingEntity target) {
|
private BotData(Terminator bot, LivingEntity target) {
|
||||||
this.values = new HashMap<>();
|
this.values = new HashMap<>();
|
||||||
|
|
||||||
Location a = bot.getLocation();
|
Location a = bot.getLocation();
|
||||||
Location b = target.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.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_XZ, Math.sqrt(MathUtils.square(a.getX() - b.getX()) + MathUtils.square(a.getZ() - b.getZ())));
|
||||||
@@ -28,7 +28,7 @@ public class BotData {
|
|||||||
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);
|
return new BotData(bot, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.nuggetmc.tplus.bot.agent.legacyagent.ai;
|
package net.nuggetmc.tplus.api.agent.legacyagent.ai;
|
||||||
|
|
||||||
public enum BotDataType {
|
public enum BotDataType {
|
||||||
CRITICAL_HEALTH("h"),
|
CRITICAL_HEALTH("h"),
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.nuggetmc.tplus.bot.agent.legacyagent.ai;
|
package net.nuggetmc.tplus.api.agent.legacyagent.ai;
|
||||||
|
|
||||||
public enum BotNode {
|
public enum BotNode {
|
||||||
BLOCK, // block (can't attack while blocking)
|
BLOCK, // block (can't attack while blocking)
|
||||||
@@ -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.api.AIManager;
|
||||||
import net.nuggetmc.tplus.TerminatorPlus;
|
import net.nuggetmc.tplus.api.BotManager;
|
||||||
import net.nuggetmc.tplus.bot.Bot;
|
import net.nuggetmc.tplus.api.Terminator;
|
||||||
import net.nuggetmc.tplus.bot.BotManager;
|
import net.nuggetmc.tplus.api.agent.legacyagent.EnumTargetGoal;
|
||||||
import net.nuggetmc.tplus.bot.agent.legacyagent.EnumTargetGoal;
|
import net.nuggetmc.tplus.api.agent.legacyagent.LegacyAgent;
|
||||||
import net.nuggetmc.tplus.bot.agent.legacyagent.LegacyAgent;
|
import net.nuggetmc.tplus.api.utils.ChatUtils;
|
||||||
import net.nuggetmc.tplus.command.commands.AICommand;
|
import net.nuggetmc.tplus.api.utils.MathUtils;
|
||||||
import net.nuggetmc.tplus.utils.ChatUtils;
|
import net.nuggetmc.tplus.api.utils.MojangAPI;
|
||||||
import net.nuggetmc.tplus.utils.MathUtils;
|
import net.nuggetmc.tplus.api.utils.PlayerUtils;
|
||||||
import net.nuggetmc.tplus.utils.MojangAPI;
|
|
||||||
import net.nuggetmc.tplus.utils.PlayerUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
@@ -32,9 +31,9 @@ public class IntelligenceAgent {
|
|||||||
* default anchor location, /ai relocateanchor
|
* default anchor location, /ai relocateanchor
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private final TerminatorPlus plugin;
|
private final Plugin plugin;
|
||||||
private final BotManager manager;
|
private final BotManager manager;
|
||||||
private final AICommand aiManager;
|
private final AIManager aiManager;
|
||||||
private final BukkitScheduler scheduler;
|
private final BukkitScheduler scheduler;
|
||||||
|
|
||||||
private LegacyAgent agent;
|
private LegacyAgent agent;
|
||||||
@@ -47,7 +46,7 @@ public class IntelligenceAgent {
|
|||||||
private final String botSkin;
|
private final String botSkin;
|
||||||
private final int cutoff;
|
private final int cutoff;
|
||||||
|
|
||||||
private final Map<String, Bot> bots;
|
private final Map<String, Terminator> bots;
|
||||||
|
|
||||||
private int populationSize;
|
private int populationSize;
|
||||||
private int generation;
|
private int generation;
|
||||||
@@ -57,9 +56,9 @@ public class IntelligenceAgent {
|
|||||||
private final Set<CommandSender> users;
|
private final Set<CommandSender> users;
|
||||||
private final Map<Integer, Set<Map<BotNode, Map<BotDataType, Double>>>> genProfiles;
|
private final Map<Integer, Set<Map<BotNode, Map<BotDataType, Double>>>> genProfiles;
|
||||||
|
|
||||||
public IntelligenceAgent(AICommand aiManager, int populationSize, String name, String skin) {
|
public IntelligenceAgent(AIManager aiManager, int populationSize, String name, String skin, Plugin plugin, BotManager manager) {
|
||||||
this.plugin = TerminatorPlus.getInstance();
|
this.plugin = plugin;
|
||||||
this.manager = plugin.getManager();
|
this.manager = manager;
|
||||||
this.aiManager = aiManager;
|
this.aiManager = aiManager;
|
||||||
this.scheduler = Bukkit.getScheduler();
|
this.scheduler = Bukkit.getScheduler();
|
||||||
this.name = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss").format(Calendar.getInstance().getTime());
|
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);
|
Location loc = PlayerUtils.findAbove(primary.getLocation(), 20);
|
||||||
|
|
||||||
scheduler.runTask(plugin, () -> {
|
scheduler.runTask(plugin, () -> {
|
||||||
Set<Bot> bots;
|
Set<Terminator> bots;
|
||||||
|
|
||||||
if (loadedProfiles == null) {
|
if (loadedProfiles == null) {
|
||||||
bots = manager.createBots(loc, botName, skinData, populationSize, NeuralNetwork.RANDOM);
|
bots = manager.createBots(loc, botName, skinData, populationSize, NeuralNetwork.RANDOM);
|
||||||
@@ -141,7 +140,7 @@ public class IntelligenceAgent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bots.forEach(bot -> {
|
bots.forEach(bot -> {
|
||||||
String name = bot.getName().getString();
|
String name = bot.getBotName();
|
||||||
|
|
||||||
while (this.bots.containsKey(name)) {
|
while (this.bots.containsKey(name)) {
|
||||||
name += "_";
|
name += "_";
|
||||||
@@ -166,22 +165,22 @@ public class IntelligenceAgent {
|
|||||||
|
|
||||||
print("Generation " + ChatColor.RED + generation + ChatColor.RESET + " has ended.");
|
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());
|
values.put(bot, bot.getAliveTicks());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Map.Entry<Bot, Integer>> sorted = MathUtils.sortByValue(values);
|
List<Map.Entry<Terminator, Integer>> sorted = MathUtils.sortByValue(values);
|
||||||
Set<Bot> winners = new HashSet<>();
|
Set<Terminator> winners = new HashSet<>();
|
||||||
|
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
|
||||||
for (Map.Entry<Bot, Integer> entry : sorted) {
|
for (Map.Entry<Terminator, Integer> entry : sorted) {
|
||||||
Bot bot = entry.getKey();
|
Terminator bot = entry.getKey();
|
||||||
boolean check = i <= cutoff;
|
boolean check = i <= cutoff;
|
||||||
if (check) {
|
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");
|
+ ChatUtils.BULLET_FORMATTED + ChatColor.RED + bot.getKills() + " kills");
|
||||||
winners.add(bot);
|
winners.add(bot);
|
||||||
}
|
}
|
||||||
@@ -245,7 +244,7 @@ public class IntelligenceAgent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int aliveCount() {
|
private int aliveCount() {
|
||||||
return (int) bots.values().stream().filter(LivingEntity::isAlive).count();
|
return (int) bots.values().stream().filter(Terminator::isBotAlive).count();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void close() {
|
private void close() {
|
||||||
@@ -327,7 +326,7 @@ public class IntelligenceAgent {
|
|||||||
if (!bots.isEmpty()) {
|
if (!bots.isEmpty()) {
|
||||||
print("Removing all cached bots...");
|
print("Removing all cached bots...");
|
||||||
|
|
||||||
bots.values().forEach(Bot::removeVisually);
|
bots.values().forEach(Terminator::removeBot);
|
||||||
bots.clear();
|
bots.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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.md_5.bungee.api.ChatColor;
|
||||||
import net.nuggetmc.tplus.utils.MathUtils;
|
import net.nuggetmc.tplus.api.utils.ChatUtils;
|
||||||
import net.nuggetmc.tplus.utils.ChatUtils;
|
import net.nuggetmc.tplus.api.utils.MathUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -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.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -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;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class BotDamageByPlayerEvent {
|
public class BotDamageByPlayerEvent {
|
||||||
|
|
||||||
private final Bot bot;
|
private final Terminator bot;
|
||||||
private final Player player;
|
private final Player player;
|
||||||
|
|
||||||
private float damage;
|
private float damage;
|
||||||
|
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
public BotDamageByPlayerEvent(Bot bot, Player player, float damage) {
|
public BotDamageByPlayerEvent(Terminator bot, Player player, float damage) {
|
||||||
this.bot = bot;
|
this.bot = bot;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.damage = damage;
|
this.damage = damage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bot getBot() {
|
public Terminator getBot() {
|
||||||
return bot;
|
return bot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 {
|
public class BotFallDamageEvent {
|
||||||
|
|
||||||
private final Bot bot;
|
private final Terminator bot;
|
||||||
|
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
public BotFallDamageEvent(Bot bot) {
|
public BotFallDamageEvent(Terminator bot) {
|
||||||
this.bot = bot;
|
this.bot = bot;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bot getBot() {
|
public Terminator getBot() {
|
||||||
return bot;
|
return bot;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCancelled(boolean cancelled) {
|
|
||||||
this.cancelled = cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return cancelled;
|
return cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCancelled(boolean cancelled) {
|
||||||
|
this.cancelled = cancelled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class BotKilledByPlayerEvent {
|
public class BotKilledByPlayerEvent {
|
||||||
@@ -8,15 +8,15 @@ public class BotKilledByPlayerEvent {
|
|||||||
// eventually also call this event for deaths from other damage causes within combat time
|
// eventually also call this event for deaths from other damage causes within combat time
|
||||||
// (like hitting the ground too hard)
|
// (like hitting the ground too hard)
|
||||||
|
|
||||||
private final Bot bot;
|
private final Terminator bot;
|
||||||
private final Player player;
|
private final Player player;
|
||||||
|
|
||||||
public BotKilledByPlayerEvent(Bot bot, Player player) {
|
public BotKilledByPlayerEvent(Terminator bot, Player player) {
|
||||||
this.bot = bot;
|
this.bot = bot;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bot getBot() {
|
public Terminator getBot() {
|
||||||
return bot;
|
return bot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.nuggetmc.tplus.utils;
|
package net.nuggetmc.tplus.api.utils;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.nuggetmc.tplus.utils;
|
package net.nuggetmc.tplus.api.utils;
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
|
||||||
@@ -7,8 +7,8 @@ import java.util.Locale;
|
|||||||
|
|
||||||
public class ChatUtils {
|
public class ChatUtils {
|
||||||
public static final String LINE = ChatColor.GRAY + "------------------------------------------------";
|
public static final String LINE = ChatColor.GRAY + "------------------------------------------------";
|
||||||
public static final String BULLET = "▪";
|
public static final String BULLET = "\u25AA";
|
||||||
public static final String BULLET_FORMATTED = ChatColor.GRAY + " ▪ " + ChatColor.RESET;
|
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 String EXCEPTION_MESSAGE = ChatColor.RED + "An exception has occured. Please try again.";
|
||||||
|
|
||||||
public static final NumberFormat NUMBER_FORMAT = NumberFormat.getNumberInstance(Locale.US);
|
public static final NumberFormat NUMBER_FORMAT = NumberFormat.getNumberInstance(Locale.US);
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
package net.nuggetmc.tplus.bot;
|
package net.nuggetmc.tplus.api.utils;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
||||||
import net.nuggetmc.tplus.utils.MojangAPI;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.nuggetmc.tplus.utils;
|
package net.nuggetmc.tplus.api.utils;
|
||||||
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@@ -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.NumberConversions;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
@@ -22,9 +22,7 @@ public class MathUtils {
|
|||||||
|
|
||||||
if (x == 0.0D && z == 0.0D) {
|
if (x == 0.0D && z == 0.0D) {
|
||||||
out[1] = (float) (dir.getY() > 0.0D ? -90 : 90);
|
out[1] = (float) (dir.getY() > 0.0D ? -90 : 90);
|
||||||
}
|
} else {
|
||||||
|
|
||||||
else {
|
|
||||||
double theta = Math.atan2(-x, z);
|
double theta = Math.atan2(-x, z);
|
||||||
out[0] = (float) Math.toDegrees((theta + 6.283185307179586D) % 6.283185307179586D);
|
out[0] = (float) Math.toDegrees((theta + 6.283185307179586D) % 6.283185307179586D);
|
||||||
|
|
||||||
@@ -45,9 +43,7 @@ public class MathUtils {
|
|||||||
|
|
||||||
if (x == 0.0D && z == 0.0D) {
|
if (x == 0.0D && z == 0.0D) {
|
||||||
result = (float) (dir.getY() > 0.0D ? -90 : 90);
|
result = (float) (dir.getY() > 0.0D ? -90 : 90);
|
||||||
}
|
} else {
|
||||||
|
|
||||||
else {
|
|
||||||
double x2 = NumberConversions.square(x);
|
double x2 = NumberConversions.square(x);
|
||||||
double z2 = NumberConversions.square(z);
|
double z2 = NumberConversions.square(z);
|
||||||
double xz = Math.sqrt(x2 + z2);
|
double xz = Math.sqrt(x2 + z2);
|
||||||
@@ -92,8 +88,8 @@ public class MathUtils {
|
|||||||
return FORMATTER_2.format(n);
|
return FORMATTER_2.format(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Map.Entry<Bot, Integer>> sortByValue(HashMap<Bot, Integer> hm) {
|
public static List<Map.Entry<Terminator, Integer>> sortByValue(HashMap<Terminator, Integer> hm) {
|
||||||
List<Map.Entry<Bot, Integer>> list = new LinkedList<>(hm.entrySet());
|
List<Map.Entry<Terminator, Integer>> list = new LinkedList<>(hm.entrySet());
|
||||||
list.sort(Map.Entry.comparingByValue());
|
list.sort(Map.Entry.comparingByValue());
|
||||||
Collections.reverse(list);
|
Collections.reverse(list);
|
||||||
return list;
|
return list;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.nuggetmc.tplus.utils;
|
package net.nuggetmc.tplus.api.utils;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
@@ -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.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
@@ -15,12 +15,12 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class PlayerUtils {
|
public class PlayerUtils {
|
||||||
|
|
||||||
|
private static final Set<String> USERNAME_CACHE = new HashSet<>();
|
||||||
|
|
||||||
public static boolean isInvincible(GameMode mode) {
|
public static boolean isInvincible(GameMode mode) {
|
||||||
return mode != GameMode.SURVIVAL && mode != GameMode.ADVENTURE && mode != null;
|
return mode != GameMode.SURVIVAL && mode != GameMode.ADVENTURE && mode != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Set<String> USERNAME_CACHE = new HashSet<>();
|
|
||||||
|
|
||||||
public static String randomName() {
|
public static String randomName() {
|
||||||
if (USERNAME_CACHE.isEmpty()) {
|
if (USERNAME_CACHE.isEmpty()) {
|
||||||
fillUsernameCache();
|
fillUsernameCache();
|
||||||
@@ -30,7 +30,7 @@ public class PlayerUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void fillUsernameCache() {
|
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";
|
file = file.substring(0, file.length() - 1) + "usercache.json";
|
||||||
|
|
||||||
JSONParser parser = new JSONParser();
|
JSONParser parser = new JSONParser();
|
||||||
@@ -44,10 +44,8 @@ public class PlayerUtils {
|
|||||||
|
|
||||||
USERNAME_CACHE.add(username);
|
USERNAME_CACHE.add(username);
|
||||||
}
|
}
|
||||||
}
|
} catch (IOException | ParseException e) {
|
||||||
|
DebugLogUtils.log("Failed to fetch from the usercache.");
|
||||||
catch (IOException | ParseException e) {
|
|
||||||
Debugger.log("Failed to fetch from the usercache.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.nuggetmc.tplus.utils;
|
package net.nuggetmc.tplus.api.utils;
|
||||||
|
|
||||||
public class Singularity {
|
public class Singularity {
|
||||||
|
|
||||||
56
TerminatorPlus-Plugin/build.gradle.kts
Normal file
56
TerminatorPlus-Plugin/build.gradle.kts
Normal 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"))
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
package net.nuggetmc.tplus;
|
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 net.nuggetmc.tplus.command.CommandHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@@ -12,7 +14,7 @@ public class TerminatorPlus extends JavaPlugin {
|
|||||||
private static TerminatorPlus instance;
|
private static TerminatorPlus instance;
|
||||||
private static String version;
|
private static String version;
|
||||||
|
|
||||||
private BotManager manager;
|
private BotManagerImpl manager;
|
||||||
private CommandHandler handler;
|
private CommandHandler handler;
|
||||||
|
|
||||||
public static TerminatorPlus getInstance() {
|
public static TerminatorPlus getInstance() {
|
||||||
@@ -23,7 +25,7 @@ public class TerminatorPlus extends JavaPlugin {
|
|||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BotManager getManager() {
|
public BotManagerImpl getManager() {
|
||||||
return manager;
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,9 +39,12 @@ public class TerminatorPlus extends JavaPlugin {
|
|||||||
version = getDescription().getVersion();
|
version = getDescription().getVersion();
|
||||||
|
|
||||||
// Create Instances
|
// Create Instances
|
||||||
this.manager = new BotManager();
|
this.manager = new BotManagerImpl();
|
||||||
this.handler = new CommandHandler(this);
|
this.handler = new CommandHandler(this);
|
||||||
|
|
||||||
|
TerminatorPlusAPI.setBotManager(manager);
|
||||||
|
TerminatorPlusAPI.setInternalBridge(new InternalBridgeImpl());
|
||||||
|
|
||||||
// Register event listeners
|
// Register event listeners
|
||||||
this.registerEvents(manager);
|
this.registerEvents(manager);
|
||||||
}
|
}
|
||||||
@@ -8,8 +8,6 @@ import net.minecraft.network.Connection;
|
|||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
import net.minecraft.network.protocol.PacketFlow;
|
import net.minecraft.network.protocol.PacketFlow;
|
||||||
import net.minecraft.network.protocol.game.*;
|
import net.minecraft.network.protocol.game.*;
|
||||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
|
||||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
@@ -26,18 +24,17 @@ import net.minecraft.world.level.chunk.LevelChunk;
|
|||||||
import net.minecraft.world.phys.AABB;
|
import net.minecraft.world.phys.AABB;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.nuggetmc.tplus.TerminatorPlus;
|
import net.nuggetmc.tplus.TerminatorPlus;
|
||||||
import net.nuggetmc.tplus.bot.agent.Agent;
|
import net.nuggetmc.tplus.api.Terminator;
|
||||||
import net.nuggetmc.tplus.bot.agent.legacyagent.ai.NeuralNetwork;
|
import net.nuggetmc.tplus.api.agent.Agent;
|
||||||
import net.nuggetmc.tplus.bot.event.BotDamageByPlayerEvent;
|
import net.nuggetmc.tplus.api.agent.legacyagent.ai.NeuralNetwork;
|
||||||
import net.nuggetmc.tplus.bot.event.BotFallDamageEvent;
|
import net.nuggetmc.tplus.api.event.BotDamageByPlayerEvent;
|
||||||
import net.nuggetmc.tplus.bot.event.BotKilledByPlayerEvent;
|
import net.nuggetmc.tplus.api.event.BotFallDamageEvent;
|
||||||
import net.nuggetmc.tplus.utils.*;
|
import net.nuggetmc.tplus.api.event.BotKilledByPlayerEvent;
|
||||||
import org.bukkit.Material;
|
import net.nuggetmc.tplus.api.utils.*;
|
||||||
import org.bukkit.SoundCategory;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
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.CraftServer;
|
||||||
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
|
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
|
||||||
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer;
|
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.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.bukkit.util.BoundingBox;
|
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -55,47 +51,27 @@ import java.util.Collections;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class Bot extends ServerPlayer {
|
public class Bot extends ServerPlayer implements Terminator {
|
||||||
|
|
||||||
private final TerminatorPlus plugin;
|
private final TerminatorPlus plugin;
|
||||||
private final BukkitScheduler scheduler;
|
private final BukkitScheduler scheduler;
|
||||||
private final Agent agent;
|
private final Agent agent;
|
||||||
|
private final Vector offset;
|
||||||
private NeuralNetwork network;
|
|
||||||
|
|
||||||
public NeuralNetwork getNeuralNetwork() {
|
|
||||||
return network;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNeuralNetwork(NeuralNetwork network) {
|
|
||||||
this.network = network;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasNeuralNetwork() {
|
|
||||||
return network != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack defaultItem;
|
public ItemStack defaultItem;
|
||||||
|
private NeuralNetwork network;
|
||||||
private boolean shield;
|
private boolean shield;
|
||||||
private boolean blocking;
|
private boolean blocking;
|
||||||
private boolean blockUse;
|
private boolean blockUse;
|
||||||
|
|
||||||
private Vector velocity;
|
private Vector velocity;
|
||||||
private Vector oldVelocity;
|
private Vector oldVelocity;
|
||||||
|
|
||||||
private boolean removeOnDeath;
|
private boolean removeOnDeath;
|
||||||
|
|
||||||
private int aliveTicks;
|
private int aliveTicks;
|
||||||
private int kills;
|
private int kills;
|
||||||
|
private byte fireTicks; // Fire animation isn't played? Bot still takes damage.
|
||||||
private byte fireTicks;
|
|
||||||
private byte groundTicks;
|
private byte groundTicks;
|
||||||
private byte jumpTicks;
|
private byte jumpTicks;
|
||||||
private byte noFallTicks;
|
private byte noFallTicks;
|
||||||
|
|
||||||
private final Vector offset;
|
|
||||||
|
|
||||||
private Bot(MinecraftServer minecraftServer, ServerLevel worldServer, GameProfile profile) {
|
private Bot(MinecraftServer minecraftServer, ServerLevel worldServer, GameProfile profile) {
|
||||||
super(minecraftServer, worldServer, profile);
|
super(minecraftServer, worldServer, profile);
|
||||||
|
|
||||||
@@ -148,6 +124,31 @@ public class Bot extends ServerPlayer {
|
|||||||
return 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() {
|
private void renderAll() {
|
||||||
Packet<?>[] packets = getRenderPacketsNoInfo();
|
Packet<?>[] packets = getRenderPacketsNoInfo();
|
||||||
Bukkit.getOnlinePlayers().forEach(p -> renderNoInfo(((CraftPlayer) p).getHandle().connection, packets, false));
|
Bukkit.getOnlinePlayers().forEach(p -> renderNoInfo(((CraftPlayer) p).getHandle().connection, packets, false));
|
||||||
@@ -180,6 +181,14 @@ public class Bot extends ServerPlayer {
|
|||||||
render(connection, getRenderPackets(), login);
|
render(connection, getRenderPackets(), login);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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<?>[] getRenderPackets() {
|
private Packet<?>[] getRenderPackets() {
|
||||||
return new Packet[]{
|
return new Packet[]{
|
||||||
new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, this),
|
new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, this),
|
||||||
@@ -197,22 +206,27 @@ public class Bot extends ServerPlayer {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setDefaultItem(ItemStack item) {
|
public void setDefaultItem(ItemStack item) {
|
||||||
this.defaultItem = item;
|
this.defaultItem = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Vector getOffset() {
|
public Vector getOffset() {
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Vector getVelocity() {
|
public Vector getVelocity() {
|
||||||
return velocity.clone();
|
return velocity.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setVelocity(Vector vector) {
|
public void setVelocity(Vector vector) {
|
||||||
this.velocity = vector;
|
this.velocity = vector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void addVelocity(Vector vector) { // This can cause lag? (maybe i fixed it with the new static method)
|
public void addVelocity(Vector vector) { // This can cause lag? (maybe i fixed it with the new static method)
|
||||||
if (MathUtils.isNotFinite(vector)) {
|
if (MathUtils.isNotFinite(vector)) {
|
||||||
velocity = vector;
|
velocity = vector;
|
||||||
@@ -222,10 +236,12 @@ public class Bot extends ServerPlayer {
|
|||||||
velocity.add(vector);
|
velocity.add(vector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getAliveTicks() {
|
public int getAliveTicks() {
|
||||||
return aliveTicks;
|
return aliveTicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean tickDelay(int i) {
|
public boolean tickDelay(int i) {
|
||||||
return aliveTicks % i == 0;
|
return aliveTicks % i == 0;
|
||||||
}
|
}
|
||||||
@@ -234,6 +250,21 @@ public class Bot extends ServerPlayer {
|
|||||||
Bukkit.getOnlinePlayers().forEach(p -> ((CraftPlayer) p).getHandle().connection.send(packet));
|
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
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
loadChunks();
|
loadChunks();
|
||||||
@@ -328,17 +359,20 @@ public class Bot extends ServerPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void ignite() {
|
public void ignite() {
|
||||||
if (fireTicks <= 1) setOnFirePackets(true);
|
if (fireTicks <= 1) setOnFirePackets(true);
|
||||||
fireTicks = 100;
|
fireTicks = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setOnFirePackets(boolean onFire) {
|
public void setOnFirePackets(boolean onFire) {
|
||||||
//entityData.set(new EntityDataAccessor<>(0, EntityDataSerializers.BYTE), onFire ? (byte) 1 : (byte) 0);
|
//entityData.set(new EntityDataAccessor<>(0, EntityDataSerializers.BYTE), onFire ? (byte) 1 : (byte) 0);
|
||||||
//sendPacket(new ClientboundSetEntityDataPacket(getId(), entityData, false));
|
//sendPacket(new ClientboundSetEntityDataPacket(getId(), entityData, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOnFire() {
|
@Override
|
||||||
|
public boolean isBotOnFire() {
|
||||||
return fireTicks != 0;
|
return fireTicks != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,10 +388,12 @@ public class Bot extends ServerPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isFalling() {
|
public boolean isFalling() {
|
||||||
return velocity.getY() < -0.8;
|
return velocity.getY() < -0.8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void block(int blockLength, int cooldown) {
|
public void block(int blockLength, int cooldown) {
|
||||||
if (!shield || blockUse) return;
|
if (!shield || blockUse) return;
|
||||||
startBlocking();
|
startBlocking();
|
||||||
@@ -378,14 +414,14 @@ public class Bot extends ServerPlayer {
|
|||||||
sendPacket(new ClientboundSetEntityDataPacket(getId(), entityData, true));
|
sendPacket(new ClientboundSetEntityDataPacket(getId(), entityData, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBlocking() {
|
@Override
|
||||||
return blocking;
|
public boolean isBotBlocking() {
|
||||||
|
return isBlocking();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShield(boolean enabled) {
|
public void setShield(boolean enabled) {
|
||||||
this.shield = enabled;
|
this.shield = enabled;
|
||||||
|
|
||||||
System.out.println("set shield");
|
|
||||||
setItemOffhand(new org.bukkit.inventory.ItemStack(enabled ? Material.SHIELD : Material.AIR));
|
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????
|
MathUtils.clean(velocity); // TODO lag????
|
||||||
|
|
||||||
if (isInWater()) {
|
if (isBotInWater()) {
|
||||||
y = Math.min(velocity.getY() + 0.1, 0.1);
|
y = Math.min(velocity.getY() + 0.1, 0.1);
|
||||||
addFriction(0.8);
|
addFriction(0.8);
|
||||||
velocity.setY(y);
|
velocity.setY(y);
|
||||||
}
|
} else {
|
||||||
|
|
||||||
else {
|
|
||||||
if (groundTicks != 0) {
|
if (groundTicks != 0) {
|
||||||
velocity.setY(0);
|
velocity.setY(0);
|
||||||
addFriction(0.5);
|
addFriction(0.5);
|
||||||
@@ -415,7 +449,7 @@ public class Bot extends ServerPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInWater() {
|
public boolean isBotInWater() {
|
||||||
Location loc = getLocation();
|
Location loc = getLocation();
|
||||||
|
|
||||||
for (int i = 0; i <= 2; i++) {
|
for (int i = 0; i <= 2; i++) {
|
||||||
@@ -431,6 +465,7 @@ public class Bot extends ServerPlayer {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void jump(Vector vel) {
|
public void jump(Vector vel) {
|
||||||
if (jumpTicks == 0 && groundTicks > 1) {
|
if (jumpTicks == 0 && groundTicks > 1) {
|
||||||
jumpTicks = 4;
|
jumpTicks = 4;
|
||||||
@@ -438,10 +473,12 @@ public class Bot extends ServerPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void jump() {
|
public void jump() {
|
||||||
jump(new Vector(0, 0.5, 0));
|
jump(new Vector(0, 0.5, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void walk(Vector vel) {
|
public void walk(Vector vel) {
|
||||||
double max = 0.4;
|
double max = 0.4;
|
||||||
|
|
||||||
@@ -451,6 +488,7 @@ public class Bot extends ServerPlayer {
|
|||||||
velocity = sum;
|
velocity = sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void attack(org.bukkit.entity.Entity entity) {
|
public void attack(org.bukkit.entity.Entity entity) {
|
||||||
faceLocation(entity.getLocation());
|
faceLocation(entity.getLocation());
|
||||||
punch();
|
punch();
|
||||||
@@ -462,6 +500,7 @@ public class Bot extends ServerPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void punch() {
|
public void punch() {
|
||||||
swing(InteractionHand.MAIN_HAND);
|
swing(InteractionHand.MAIN_HAND);
|
||||||
}
|
}
|
||||||
@@ -501,10 +540,11 @@ public class Bot extends ServerPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOnGround() {
|
public boolean isBotOnGround() {
|
||||||
return groundTicks != 0;
|
return groundTicks != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void addFriction(double factor) {
|
public void addFriction(double factor) {
|
||||||
double frictionMin = 0.01;
|
double frictionMin = 0.01;
|
||||||
|
|
||||||
@@ -515,11 +555,22 @@ public class Bot extends ServerPlayer {
|
|||||||
velocity.setZ(Math.abs(z) < frictionMin ? 0 : z * factor);
|
velocity.setZ(Math.abs(z) < frictionMin ? 0 : z * factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void removeVisually() {
|
public void removeVisually() {
|
||||||
this.removeTab();
|
this.removeTab();
|
||||||
this.setDead();
|
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() {
|
private void removeTab() {
|
||||||
sendPacket(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER, this));
|
sendPacket(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER, this));
|
||||||
}
|
}
|
||||||
@@ -635,27 +686,37 @@ public class Bot extends ServerPlayer {
|
|||||||
private void kb(Location loc1, Location loc2) {
|
private void kb(Location loc1, Location loc2) {
|
||||||
Vector vel = loc1.toVector().subtract(loc2.toVector()).setY(0).normalize().multiply(0.3);
|
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;
|
velocity = vel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getKills() {
|
public int getKills() {
|
||||||
return kills;
|
return kills;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void incrementKills() {
|
public void incrementKills() {
|
||||||
kills++;
|
kills++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Location getLocation() {
|
public Location getLocation() {
|
||||||
return getBukkitEntity().getLocation();
|
return getBukkitEntity().getLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBotPitch(float pitch) {
|
||||||
|
super.setXRot(pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void faceLocation(Location loc) {
|
public void faceLocation(Location loc) {
|
||||||
look(loc.toVector().subtract(getLocation().toVector()), false);
|
look(loc.toVector().subtract(getLocation().toVector()), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void look(BlockFace face) {
|
public void look(BlockFace face) {
|
||||||
look(face.getDirection(), face == BlockFace.DOWN || face == BlockFace.UP);
|
look(face.getDirection(), face == BlockFace.DOWN || face == BlockFace.UP);
|
||||||
}
|
}
|
||||||
@@ -677,6 +738,7 @@ public class Bot extends ServerPlayer {
|
|||||||
setRot(yaw, pitch);
|
setRot(yaw, pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void attemptBlockPlace(Location loc, Material type, boolean down) {
|
public void attemptBlockPlace(Location loc, Material type, boolean down) {
|
||||||
if (down) {
|
if (down) {
|
||||||
look(BlockFace.DOWN);
|
look(BlockFace.DOWN);
|
||||||
@@ -696,42 +758,52 @@ public class Bot extends ServerPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setItem(org.bukkit.inventory.ItemStack item) {
|
public void setItem(org.bukkit.inventory.ItemStack item) {
|
||||||
setItem(item, EquipmentSlot.MAINHAND);
|
setItem(item, EquipmentSlot.MAINHAND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setItemOffhand(org.bukkit.inventory.ItemStack item) {
|
public void setItemOffhand(org.bukkit.inventory.ItemStack item) {
|
||||||
setItem(item, EquipmentSlot.OFFHAND);
|
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) {
|
public void setItem(org.bukkit.inventory.ItemStack item, EquipmentSlot slot) {
|
||||||
if (item == null) item = defaultItem;
|
if (item == null) item = defaultItem;
|
||||||
|
|
||||||
System.out.println("set");
|
//System.out.println("set");
|
||||||
if (slot == EquipmentSlot.MAINHAND) {
|
if (slot == EquipmentSlot.MAINHAND) {
|
||||||
getBukkitEntity().getInventory().setItemInMainHand(item);
|
getBukkitEntity().getInventory().setItemInMainHand(item);
|
||||||
} else if (slot == EquipmentSlot.OFFHAND) {
|
} else if (slot == EquipmentSlot.OFFHAND) {
|
||||||
getBukkitEntity().getInventory().setItemInOffHand(item);
|
getBukkitEntity().getInventory().setItemInOffHand(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("slot = " + slot);
|
//System.out.println("slot = " + slot);
|
||||||
System.out.println("item = " + item);
|
//System.out.println("item = " + item);
|
||||||
sendPacket(new ClientboundSetEquipmentPacket(getId(), new ArrayList<>(Collections.singletonList(
|
sendPacket(new ClientboundSetEquipmentPacket(getId(), new ArrayList<>(Collections.singletonList(
|
||||||
new Pair<>(slot, CraftItemStack.asNMSCopy(item))
|
new Pair<>(slot, CraftItemStack.asNMSCopy(item))
|
||||||
))));
|
))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void swim() {
|
public void swim() {
|
||||||
getBukkitEntity().setSwimming(true);
|
getBukkitEntity().setSwimming(true);
|
||||||
registerPose(Pose.SWIMMING);
|
registerPose(Pose.SWIMMING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void sneak() {
|
public void sneak() {
|
||||||
getBukkitEntity().setSneaking(true);
|
getBukkitEntity().setSneaking(true);
|
||||||
registerPose(Pose.CROUCHING);
|
registerPose(Pose.CROUCHING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void stand() {
|
public void stand() {
|
||||||
Player player = getBukkitEntity();
|
Player player = getBukkitEntity();
|
||||||
player.setSneaking(false);
|
player.setSneaking(false);
|
||||||
@@ -1,17 +1,22 @@
|
|||||||
package net.nuggetmc.tplus.bot;
|
package net.nuggetmc.tplus.bot;
|
||||||
|
|
||||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||||
import net.nuggetmc.tplus.bot.agent.Agent;
|
import net.nuggetmc.tplus.TerminatorPlus;
|
||||||
import net.nuggetmc.tplus.bot.agent.legacyagent.LegacyAgent;
|
import net.nuggetmc.tplus.api.BotManager;
|
||||||
import net.nuggetmc.tplus.bot.agent.legacyagent.ai.NeuralNetwork;
|
import net.nuggetmc.tplus.api.Terminator;
|
||||||
import net.nuggetmc.tplus.bot.event.BotDeathEvent;
|
import net.nuggetmc.tplus.api.agent.Agent;
|
||||||
import net.nuggetmc.tplus.utils.MojangAPI;
|
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.*;
|
||||||
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer;
|
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.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
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.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
@@ -21,35 +26,38 @@ import java.util.*;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class BotManager implements Listener {
|
public class BotManagerImpl implements BotManager, Listener {
|
||||||
|
|
||||||
private final Agent agent;
|
private final Agent agent;
|
||||||
private final Set<Bot> bots;
|
private final Set<Terminator> bots;
|
||||||
private final NumberFormat numberFormat;
|
private final NumberFormat numberFormat;
|
||||||
|
|
||||||
public boolean joinMessages = false;
|
public boolean joinMessages = false;
|
||||||
|
|
||||||
public BotManager() {
|
public BotManagerImpl() {
|
||||||
this.agent = new LegacyAgent(this);
|
this.agent = new LegacyAgent(this, TerminatorPlus.getInstance());
|
||||||
this.bots = ConcurrentHashMap.newKeySet(); //should fix concurrentmodificationexception
|
this.bots = ConcurrentHashMap.newKeySet(); //should fix concurrentmodificationexception
|
||||||
this.numberFormat = NumberFormat.getInstance(Locale.US);
|
this.numberFormat = NumberFormat.getInstance(Locale.US);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Bot> fetch() {
|
@Override
|
||||||
|
public Set<Terminator> fetch() {
|
||||||
return bots;
|
return bots;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Bot bot) {
|
@Override
|
||||||
|
public void add(Terminator bot) {
|
||||||
if (joinMessages) {
|
if (joinMessages) {
|
||||||
Bukkit.broadcastMessage(ChatColor.YELLOW + (bot.getName() + " joined the game"));
|
Bukkit.broadcastMessage(ChatColor.YELLOW + (bot.getBotName() + " joined the game"));
|
||||||
}
|
}
|
||||||
|
|
||||||
bots.add(bot);
|
bots.add(bot);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bot getFirst(String name) {
|
@Override
|
||||||
for (Bot bot : bots) {
|
public Terminator getFirst(String name) {
|
||||||
if (name.equals(bot.getName())) {
|
for (Terminator bot : bots) {
|
||||||
|
if (name.equals(bot.getBotName())) {
|
||||||
return bot;
|
return bot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,18 +65,26 @@ public class BotManager implements Listener {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<String> fetchNames() {
|
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() {
|
public Agent getAgent() {
|
||||||
return agent;
|
return agent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void createBots(Player sender, String name, String skinName, int n) {
|
public void createBots(Player sender, String name, String skinName, int n) {
|
||||||
createBots(sender, name, skinName, n, null);
|
createBots(sender, name, skinName, n, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void createBots(Player sender, String name, String skinName, int n, NeuralNetwork network) {
|
public void createBots(Player sender, String name, String skinName, int n, NeuralNetwork network) {
|
||||||
long timestamp = System.currentTimeMillis();
|
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 + ").");
|
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<>();
|
List<NeuralNetwork> networks = new ArrayList<>();
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
@@ -96,8 +113,9 @@ public class BotManager implements Listener {
|
|||||||
return createBots(loc, name, skin, networks);
|
return createBots(loc, name, skin, networks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Bot> createBots(Location loc, String name, String[] skin, List<NeuralNetwork> networks) {
|
@Override
|
||||||
Set<Bot> bots = new HashSet<>();
|
public Set<Terminator> createBots(Location loc, String name, String[] skin, List<NeuralNetwork> networks) {
|
||||||
|
Set<Terminator> bots = new HashSet<>();
|
||||||
World world = loc.getWorld();
|
World world = loc.getWorld();
|
||||||
|
|
||||||
int n = networks.size();
|
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();
|
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);
|
bots.remove(bot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void reset() {
|
public void reset() {
|
||||||
if (!bots.isEmpty()) {
|
if (!bots.isEmpty()) {
|
||||||
bots.forEach(Bot::removeVisually);
|
bots.forEach(Terminator::removeVisually);
|
||||||
bots.clear(); // Not always necessary, but a good security measure
|
bots.clear(); // Not always necessary, but a good security measure
|
||||||
}
|
}
|
||||||
|
|
||||||
agent.stopAllTasks();
|
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();
|
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
|
@EventHandler
|
||||||
public void onJoin(PlayerJoinEvent event) {
|
public void onJoin(PlayerJoinEvent event) {
|
||||||
ServerGamePacketListenerImpl connection = ((CraftPlayer) event.getPlayer()).getHandle().connection;
|
ServerGamePacketListenerImpl connection = ((CraftPlayer) event.getPlayer()).getHandle().connection;
|
||||||
bots.forEach(bot -> bot.render(connection, true));
|
bots.forEach(bot -> bot.renderBot(connection, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onDeath(PlayerDeathEvent event) {
|
public void onDeath(EntityDeathEvent event) {
|
||||||
Player player = event.getEntity();
|
LivingEntity bukkitEntity = event.getEntity();
|
||||||
Bot bot = getBot(player);
|
Terminator bot = getBot(bukkitEntity.getEntityId());
|
||||||
|
|
||||||
if (bot != null) {
|
if (bot != null) {
|
||||||
agent.onBotDeath(new BotDeathEvent(event, bot));
|
agent.onBotDeath(new BotDeathEvent(event, bot));
|
||||||
}
|
}
|
||||||
@@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,13 +2,13 @@ package net.nuggetmc.tplus.command;
|
|||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import net.nuggetmc.tplus.TerminatorPlus;
|
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.Command;
|
||||||
import net.nuggetmc.tplus.command.annotation.Require;
|
import net.nuggetmc.tplus.command.annotation.Require;
|
||||||
import net.nuggetmc.tplus.command.commands.AICommand;
|
import net.nuggetmc.tplus.command.commands.AICommand;
|
||||||
import net.nuggetmc.tplus.command.commands.BotCommand;
|
import net.nuggetmc.tplus.command.commands.BotCommand;
|
||||||
import net.nuggetmc.tplus.command.commands.MainCommand;
|
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.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.SimpleCommandMap;
|
import org.bukkit.command.SimpleCommandMap;
|
||||||
@@ -62,7 +62,7 @@ public class CommandHandler {
|
|||||||
try {
|
try {
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
Debugger.log("Failed to access method " + method.getName() + ".");
|
DebugLogUtils.log("Failed to access method " + method.getName() + ".");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
package net.nuggetmc.tplus.command;
|
package net.nuggetmc.tplus.command;
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
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.Arg;
|
||||||
import net.nuggetmc.tplus.command.annotation.OptArg;
|
import net.nuggetmc.tplus.command.annotation.OptArg;
|
||||||
import net.nuggetmc.tplus.command.annotation.TextArg;
|
import net.nuggetmc.tplus.command.annotation.TextArg;
|
||||||
import net.nuggetmc.tplus.command.exception.ArgCountException;
|
import net.nuggetmc.tplus.command.exception.ArgCountException;
|
||||||
import net.nuggetmc.tplus.command.exception.ArgParseException;
|
import net.nuggetmc.tplus.command.exception.ArgParseException;
|
||||||
import net.nuggetmc.tplus.command.exception.NonPlayerException;
|
import net.nuggetmc.tplus.command.exception.NonPlayerException;
|
||||||
import net.nuggetmc.tplus.utils.ChatUtils;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.defaults.BukkitCommand;
|
import org.bukkit.command.defaults.BukkitCommand;
|
||||||
@@ -1,18 +1,19 @@
|
|||||||
package net.nuggetmc.tplus.command.commands;
|
package net.nuggetmc.tplus.command.commands;
|
||||||
|
|
||||||
import net.nuggetmc.tplus.TerminatorPlus;
|
import net.nuggetmc.tplus.TerminatorPlus;
|
||||||
import net.nuggetmc.tplus.bot.Bot;
|
import net.nuggetmc.tplus.api.AIManager;
|
||||||
import net.nuggetmc.tplus.bot.BotManager;
|
import net.nuggetmc.tplus.api.Terminator;
|
||||||
import net.nuggetmc.tplus.bot.agent.legacyagent.ai.IntelligenceAgent;
|
import net.nuggetmc.tplus.api.agent.legacyagent.ai.IntelligenceAgent;
|
||||||
import net.nuggetmc.tplus.bot.agent.legacyagent.ai.NeuralNetwork;
|
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.CommandHandler;
|
||||||
import net.nuggetmc.tplus.command.CommandInstance;
|
import net.nuggetmc.tplus.command.CommandInstance;
|
||||||
import net.nuggetmc.tplus.command.annotation.Arg;
|
import net.nuggetmc.tplus.command.annotation.Arg;
|
||||||
import net.nuggetmc.tplus.command.annotation.Autofill;
|
import net.nuggetmc.tplus.command.annotation.Autofill;
|
||||||
import net.nuggetmc.tplus.command.annotation.Command;
|
import net.nuggetmc.tplus.command.annotation.Command;
|
||||||
import net.nuggetmc.tplus.command.annotation.OptArg;
|
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.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@@ -22,7 +23,7 @@ import org.bukkit.scheduler.BukkitScheduler;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AICommand extends CommandInstance {
|
public class AICommand extends CommandInstance implements AIManager {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ideas
|
* ideas
|
||||||
@@ -31,7 +32,7 @@ public class AICommand extends CommandInstance {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
private final TerminatorPlus plugin;
|
private final TerminatorPlus plugin;
|
||||||
private final BotManager manager;
|
private final BotManagerImpl manager;
|
||||||
private final BukkitScheduler scheduler;
|
private final BukkitScheduler scheduler;
|
||||||
|
|
||||||
private IntelligenceAgent agent;
|
private IntelligenceAgent agent;
|
||||||
@@ -62,6 +63,10 @@ public class AICommand extends CommandInstance {
|
|||||||
desc = "Begin an AI training session."
|
desc = "Begin an AI training session."
|
||||||
)
|
)
|
||||||
public void reinforcement(Player sender, @Arg("population-size") int populationSize, @Arg("name") String name, @OptArg("skin") String skin) {
|
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) {
|
if (agent != null) {
|
||||||
sender.sendMessage("A session is already active.");
|
sender.sendMessage("A session is already active.");
|
||||||
return;
|
return;
|
||||||
@@ -69,7 +74,7 @@ public class AICommand extends CommandInstance {
|
|||||||
|
|
||||||
sender.sendMessage("Starting a new session...");
|
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);
|
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);
|
scheduler.runTaskLater(plugin, () -> sender.sendMessage("The session " + ChatColor.YELLOW + name + ChatColor.RESET + " has been closed."), 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void clearSession() {
|
public void clearSession() {
|
||||||
if (agent != null) {
|
if (agent != null) {
|
||||||
agent.stop();
|
agent.stop();
|
||||||
@@ -115,7 +121,7 @@ public class AICommand extends CommandInstance {
|
|||||||
|
|
||||||
scheduler.runTaskAsynchronously(plugin, () -> {
|
scheduler.runTaskAsynchronously(plugin, () -> {
|
||||||
try {
|
try {
|
||||||
Bot bot = manager.getFirst(name);
|
Terminator bot = manager.getFirst(name);
|
||||||
|
|
||||||
if (bot == null) {
|
if (bot == null) {
|
||||||
sender.sendMessage("Could not find bot " + ChatColor.GREEN + name + ChatColor.RESET + "!");
|
sender.sendMessage("Could not find bot " + ChatColor.GREEN + name + ChatColor.RESET + "!");
|
||||||
@@ -1,18 +1,17 @@
|
|||||||
package net.nuggetmc.tplus.command.commands;
|
package net.nuggetmc.tplus.command.commands;
|
||||||
|
|
||||||
import net.minecraft.world.entity.EquipmentSlot;
|
|
||||||
import net.nuggetmc.tplus.TerminatorPlus;
|
import net.nuggetmc.tplus.TerminatorPlus;
|
||||||
import net.nuggetmc.tplus.bot.Bot;
|
import net.nuggetmc.tplus.api.Terminator;
|
||||||
import net.nuggetmc.tplus.bot.BotManager;
|
import net.nuggetmc.tplus.api.agent.legacyagent.EnumTargetGoal;
|
||||||
import net.nuggetmc.tplus.bot.agent.legacyagent.EnumTargetGoal;
|
import net.nuggetmc.tplus.api.agent.legacyagent.LegacyAgent;
|
||||||
import net.nuggetmc.tplus.bot.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.CommandHandler;
|
||||||
import net.nuggetmc.tplus.command.CommandInstance;
|
import net.nuggetmc.tplus.command.CommandInstance;
|
||||||
import net.nuggetmc.tplus.command.annotation.Arg;
|
import net.nuggetmc.tplus.command.annotation.Arg;
|
||||||
import net.nuggetmc.tplus.command.annotation.Autofill;
|
import net.nuggetmc.tplus.command.annotation.Autofill;
|
||||||
import net.nuggetmc.tplus.command.annotation.Command;
|
import net.nuggetmc.tplus.command.annotation.Command;
|
||||||
import net.nuggetmc.tplus.command.annotation.OptArg;
|
import net.nuggetmc.tplus.command.annotation.OptArg;
|
||||||
import net.nuggetmc.tplus.utils.ChatUtils;
|
|
||||||
import net.nuggetmc.tplus.utils.Debugger;
|
import net.nuggetmc.tplus.utils.Debugger;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@@ -20,6 +19,7 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
@@ -31,11 +31,11 @@ public class BotCommand extends CommandInstance {
|
|||||||
|
|
||||||
private final TerminatorPlus plugin;
|
private final TerminatorPlus plugin;
|
||||||
private final CommandHandler handler;
|
private final CommandHandler handler;
|
||||||
private final BotManager manager;
|
private final BotManagerImpl manager;
|
||||||
private final LegacyAgent agent;
|
private final LegacyAgent agent;
|
||||||
private final BukkitScheduler scheduler;
|
private final BukkitScheduler scheduler;
|
||||||
private final DecimalFormat formatter;
|
private final DecimalFormat formatter;
|
||||||
|
private final Map<String, ItemStack[]> armorTiers;
|
||||||
private AICommand aiManager;
|
private AICommand aiManager;
|
||||||
|
|
||||||
public BotCommand(CommandHandler handler, String name, String description, String... aliases) {
|
public BotCommand(CommandHandler handler, String name, String description, String... aliases) {
|
||||||
@@ -92,8 +92,6 @@ public class BotCommand extends CommandInstance {
|
|||||||
sender.sendMessage("Successfully set the default item to " + ChatColor.YELLOW + item.getType() + ChatColor.RESET + " for all current bots.");
|
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() {
|
private void armorTierSetup() {
|
||||||
armorTiers.put("leather", new ItemStack[]{
|
armorTiers.put("leather", new ItemStack[]{
|
||||||
new ItemStack(Material.LEATHER_BOOTS),
|
new ItemStack(Material.LEATHER_BOOTS),
|
||||||
@@ -156,14 +154,17 @@ public class BotCommand extends CommandInstance {
|
|||||||
ItemStack[] armor = armorTiers.get(tier);
|
ItemStack[] armor = armorTiers.get(tier);
|
||||||
|
|
||||||
manager.fetch().forEach(bot -> {
|
manager.fetch().forEach(bot -> {
|
||||||
bot.getBukkitEntity().getInventory().setArmorContents(armor);
|
if (bot.getBukkitEntity() instanceof Player) {
|
||||||
bot.getBukkitEntity().updateInventory();
|
Player botPlayer = (Player) bot.getBukkitEntity();
|
||||||
|
botPlayer.getInventory().setArmorContents(armor);
|
||||||
|
botPlayer.updateInventory();
|
||||||
|
|
||||||
// packet sending to ensure
|
// packet sending to ensure
|
||||||
bot.setItem(armor[0], EquipmentSlot.FEET);
|
bot.setItem(armor[0], EquipmentSlot.FEET);
|
||||||
bot.setItem(armor[1], EquipmentSlot.LEGS);
|
bot.setItem(armor[1], EquipmentSlot.LEGS);
|
||||||
bot.setItem(armor[2], EquipmentSlot.CHEST);
|
bot.setItem(armor[2], EquipmentSlot.CHEST);
|
||||||
bot.setItem(armor[3], EquipmentSlot.HEAD);
|
bot.setItem(armor[3], EquipmentSlot.HEAD);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
sender.sendMessage("Successfully set the armor tier to " + ChatColor.YELLOW + tier + ChatColor.RESET + " for all current bots.");
|
sender.sendMessage("Successfully set the armor tier to " + ChatColor.YELLOW + tier + ChatColor.RESET + " for all current bots.");
|
||||||
@@ -189,7 +190,7 @@ public class BotCommand extends CommandInstance {
|
|||||||
|
|
||||||
scheduler.runTaskAsynchronously(plugin, () -> {
|
scheduler.runTaskAsynchronously(plugin, () -> {
|
||||||
try {
|
try {
|
||||||
Bot bot = manager.getFirst(name);
|
Terminator bot = manager.getFirst(name);
|
||||||
|
|
||||||
if (bot == null) {
|
if (bot == null) {
|
||||||
sender.sendMessage("Could not find bot " + ChatColor.GREEN + name + ChatColor.RESET + "!");
|
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)
|
* 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();
|
String world = ChatColor.YELLOW + bot.getBukkitEntity().getWorld().getName();
|
||||||
Location loc = bot.getLocation();
|
Location loc = bot.getLocation();
|
||||||
String strLoc = ChatColor.YELLOW + formatter.format(loc.getBlockX()) + ", " + formatter.format(loc.getBlockY()) + ", " + formatter.format(loc.getBlockZ());
|
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 + "Position: " + strLoc);
|
||||||
sender.sendMessage(ChatUtils.BULLET_FORMATTED + "Velocity: " + strVel);
|
sender.sendMessage(ChatUtils.BULLET_FORMATTED + "Velocity: " + strVel);
|
||||||
sender.sendMessage(ChatUtils.LINE);
|
sender.sendMessage(ChatUtils.LINE);
|
||||||
}
|
} catch (Exception e) {
|
||||||
|
|
||||||
catch (Exception e) {
|
|
||||||
sender.sendMessage(ChatUtils.EXCEPTION_MESSAGE);
|
sender.sendMessage(ChatUtils.EXCEPTION_MESSAGE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -307,9 +306,7 @@ public class BotCommand extends CommandInstance {
|
|||||||
|
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
output.add("setgoal");
|
output.add("setgoal");
|
||||||
}
|
} else if (args.length == 3) {
|
||||||
|
|
||||||
else if (args.length == 3) {
|
|
||||||
if (args[1].equalsIgnoreCase("setgoal")) {
|
if (args[1].equalsIgnoreCase("setgoal")) {
|
||||||
Arrays.stream(EnumTargetGoal.values()).forEach(goal -> output.add(goal.name().replace("_", "").toLowerCase()));
|
Arrays.stream(EnumTargetGoal.values()).forEach(goal -> output.add(goal.name().replace("_", "").toLowerCase()));
|
||||||
}
|
}
|
||||||
@@ -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.HoverEvent;
|
||||||
import net.md_5.bungee.api.chat.hover.content.Text;
|
import net.md_5.bungee.api.chat.hover.content.Text;
|
||||||
import net.nuggetmc.tplus.TerminatorPlus;
|
import net.nuggetmc.tplus.TerminatorPlus;
|
||||||
|
import net.nuggetmc.tplus.api.utils.ChatUtils;
|
||||||
import net.nuggetmc.tplus.command.CommandHandler;
|
import net.nuggetmc.tplus.command.CommandHandler;
|
||||||
import net.nuggetmc.tplus.command.CommandInstance;
|
import net.nuggetmc.tplus.command.CommandInstance;
|
||||||
import net.nuggetmc.tplus.command.annotation.Command;
|
import net.nuggetmc.tplus.command.annotation.Command;
|
||||||
import net.nuggetmc.tplus.utils.ChatUtils;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
@@ -1,12 +1,17 @@
|
|||||||
package net.nuggetmc.tplus.utils;
|
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.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.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 net.nuggetmc.tplus.command.commands.AICommand;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@@ -23,28 +28,15 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public class Debugger {
|
public class Debugger {
|
||||||
|
|
||||||
private static final String PREFIX = ChatColor.YELLOW + "[DEBUG] " + ChatColor.RESET;
|
|
||||||
|
|
||||||
private final CommandSender sender;
|
private final CommandSender sender;
|
||||||
|
|
||||||
public Debugger(CommandSender sender) {
|
public Debugger(CommandSender sender) {
|
||||||
this.sender = 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) {
|
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) {
|
public void execute(String cmd) {
|
||||||
@@ -60,9 +52,7 @@ public class Debugger {
|
|||||||
Statement statement = new Statement(this, name, args);
|
Statement statement = new Statement(this, name, args);
|
||||||
print("Running the expression \"" + ChatColor.AQUA + cmd + ChatColor.RESET + "\"...");
|
print("Running the expression \"" + ChatColor.AQUA + cmd + ChatColor.RESET + "\"...");
|
||||||
statement.execute();
|
statement.execute();
|
||||||
}
|
} catch (Exception e) {
|
||||||
|
|
||||||
catch (Exception e) {
|
|
||||||
print("Error: the expression \"" + ChatColor.AQUA + cmd + ChatColor.RESET + "\" failed to execute.");
|
print("Error: the expression \"" + ChatColor.AQUA + cmd + ChatColor.RESET + "\" failed to execute.");
|
||||||
print(e.toString());
|
print(e.toString());
|
||||||
}
|
}
|
||||||
@@ -80,11 +70,13 @@ public class Debugger {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
obj = Double.parseDouble(value);
|
obj = Double.parseDouble(value);
|
||||||
} catch (NumberFormatException ignored) { }
|
} catch (NumberFormatException ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
obj = Integer.parseInt(value);
|
obj = Integer.parseInt(value);
|
||||||
} catch (NumberFormatException ignored) { }
|
} catch (NumberFormatException ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
|
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
|
||||||
obj = Boolean.parseBoolean(value);
|
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) {
|
public void lol(String name, String skinName) {
|
||||||
String[] skin = MojangAPI.getSkin(skinName);
|
String[] skin = MojangAPI.getSkin(skinName);
|
||||||
|
|
||||||
@@ -222,7 +225,7 @@ public class Debugger {
|
|||||||
|
|
||||||
public void tpall() {
|
public void tpall() {
|
||||||
Player player = (Player) sender;
|
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() {
|
public void viewsession() {
|
||||||
@@ -244,9 +247,7 @@ public class Debugger {
|
|||||||
LegacyAgent legacyAgent = (LegacyAgent) agent;
|
LegacyAgent legacyAgent = (LegacyAgent) agent;
|
||||||
legacyAgent.offsets = b;
|
legacyAgent.offsets = b;
|
||||||
|
|
||||||
print("Bot target offsets are now "
|
print("Bot target offsets are now " + (legacyAgent.offsets ? ChatColor.GREEN + "ENABLED" : ChatColor.RED + "DISABLED") + ChatColor.RESET + ".");
|
||||||
+ (legacyAgent.offsets ? ChatColor.GREEN + "ENABLED" : ChatColor.RED + "DISABLED")
|
|
||||||
+ ChatColor.RESET + ".");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void confuse(int n) {
|
public void confuse(int n) {
|
||||||
@@ -269,12 +270,7 @@ public class Debugger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void dreamsmp() {
|
public void dreamsmp() {
|
||||||
spawnBots(Arrays.asList(
|
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"));
|
||||||
"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) {
|
private void spawnBots(List<String> players) {
|
||||||
@@ -319,9 +315,7 @@ public class Debugger {
|
|||||||
|
|
||||||
print("Done.");
|
print("Done.");
|
||||||
});
|
});
|
||||||
}
|
} catch (Exception e) {
|
||||||
|
|
||||||
catch (Exception e) {
|
|
||||||
print(e);
|
print(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -352,14 +346,14 @@ public class Debugger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void tp() {
|
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) {
|
if (bot == null) {
|
||||||
print("Failed to locate a bot.");
|
print("Failed to locate a bot.");
|
||||||
return;
|
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) {
|
if (sender instanceof Player) {
|
||||||
print("Teleporting...");
|
print("Teleporting...");
|
||||||
@@ -386,9 +380,9 @@ public class Debugger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void hideNametags() { // this works for some reason
|
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();
|
Location loc = bot.getLocation();
|
||||||
World world = loc.getWorld();
|
World world = loc.getWorld();
|
||||||
|
|
||||||
@@ -409,9 +403,9 @@ public class Debugger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sit() {
|
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();
|
Location loc = bot.getLocation();
|
||||||
World world = loc.getWorld();
|
World world = loc.getWorld();
|
||||||
|
|
||||||
@@ -440,7 +434,7 @@ public class Debugger {
|
|||||||
|
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
|
|
||||||
for (Bot bot : TerminatorPlus.getInstance().getManager().fetch()) {
|
for (Terminator bot : TerminatorPlus.getInstance().getManager().fetch()) {
|
||||||
bot.faceLocation(player.getEyeLocation());
|
bot.faceLocation(player.getEyeLocation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -451,8 +445,6 @@ public class Debugger {
|
|||||||
boolean b = agent.isEnabled();
|
boolean b = agent.isEnabled();
|
||||||
agent.setEnabled(!b);
|
agent.setEnabled(!b);
|
||||||
|
|
||||||
print("The Bot Agent is now "
|
print("The Bot Agent is now " + (b ? ChatColor.RED + "DISABLED" : ChatColor.GREEN + "ENABLED") + ChatColor.RESET + ".");
|
||||||
+ (b ? ChatColor.RED + "DISABLED" : ChatColor.GREEN + "ENABLED")
|
|
||||||
+ ChatColor.RESET + ".");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
45
build.gradle.kts
Normal file
45
build.gradle.kts
Normal 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
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal 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
234
gradlew
vendored
Normal 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
89
gradlew.bat
vendored
Normal 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
118
pom.xml
@@ -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
10
settings.gradle.kts
Normal 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")
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
name: TerminatorPlus
|
name: TerminatorPlus
|
||||||
main: net.nuggetmc.tplus.TerminatorPlus
|
main: net.nuggetmc.tplus.TerminatorPlus
|
||||||
version: ${project.version}
|
version: ${version}
|
||||||
api-version: 1.16
|
api-version: 1.16
|
||||||
author: HorseNuggets
|
author: HorseNuggets
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user