refactored almost everything into the API module, and left NMS stuff in plugin module, and performance improvements
This commit is contained in:
@@ -1,52 +0,0 @@
|
||||
package net.nuggetmc.tplus.utils;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BotUtils {
|
||||
|
||||
public static final Set<Material> NO_FALL = new HashSet<>(Arrays.asList(
|
||||
Material.WATER,
|
||||
Material.LAVA,
|
||||
Material.TWISTING_VINES,
|
||||
Material.VINE
|
||||
));
|
||||
|
||||
public static UUID randomSteveUUID() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
|
||||
if (uuid.hashCode() % 2 == 0) {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
return randomSteveUUID();
|
||||
}
|
||||
|
||||
public static boolean solidAt(Location loc) { // not perfect, still cuts corners of fences
|
||||
Block block = loc.getBlock();
|
||||
BoundingBox box = block.getBoundingBox();
|
||||
Vector position = loc.toVector();
|
||||
|
||||
double x = position.getX();
|
||||
double y = position.getY();
|
||||
double z = position.getZ();
|
||||
|
||||
double minX = box.getMinX();
|
||||
double minY = box.getMinY();
|
||||
double minZ = box.getMinZ();
|
||||
|
||||
double maxX = box.getMaxX();
|
||||
double maxY = box.getMaxY();
|
||||
double maxZ = box.getMaxZ();
|
||||
|
||||
return x > minX && x < maxX && y > minY && y < maxY && z > minZ && z < maxZ;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,16 @@
|
||||
package net.nuggetmc.tplus.utils;
|
||||
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.nuggetmc.tplus.TerminatorPlus;
|
||||
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.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.command.commands.AICommand;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -23,28 +27,15 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class Debugger {
|
||||
|
||||
private static final String PREFIX = ChatColor.YELLOW + "[DEBUG] " + ChatColor.RESET;
|
||||
|
||||
private final CommandSender sender;
|
||||
|
||||
public Debugger(CommandSender sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public static void log(Object... objects) {
|
||||
String[] values = formStringArray(objects);
|
||||
String message = PREFIX + String.join(" ", values);
|
||||
|
||||
Bukkit.getConsoleSender().sendMessage(message);
|
||||
Bukkit.getOnlinePlayers().stream().filter(ServerOperator::isOp).forEach(p -> p.sendMessage(message));
|
||||
}
|
||||
|
||||
private static String[] formStringArray(Object[] objects) {
|
||||
return Arrays.stream(objects).map(String::valueOf).toArray(String[]::new);
|
||||
}
|
||||
|
||||
private void print(Object... objects) {
|
||||
sender.sendMessage(PREFIX + String.join(" ", formStringArray(objects)));
|
||||
sender.sendMessage(DebugLogUtils.PREFIX + String.join(" ", DebugLogUtils.fromStringArray(objects)));
|
||||
}
|
||||
|
||||
public void execute(String cmd) {
|
||||
@@ -60,9 +51,7 @@ public class Debugger {
|
||||
Statement statement = new Statement(this, name, args);
|
||||
print("Running the expression \"" + ChatColor.AQUA + cmd + ChatColor.RESET + "\"...");
|
||||
statement.execute();
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
print("Error: the expression \"" + ChatColor.AQUA + cmd + ChatColor.RESET + "\" failed to execute.");
|
||||
print(e.toString());
|
||||
}
|
||||
@@ -80,11 +69,13 @@ public class Debugger {
|
||||
|
||||
try {
|
||||
obj = Double.parseDouble(value);
|
||||
} catch (NumberFormatException ignored) { }
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
|
||||
try {
|
||||
obj = Integer.parseInt(value);
|
||||
} catch (NumberFormatException ignored) { }
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
|
||||
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
|
||||
obj = Boolean.parseBoolean(value);
|
||||
@@ -222,7 +213,7 @@ public class Debugger {
|
||||
|
||||
public void tpall() {
|
||||
Player player = (Player) sender;
|
||||
TerminatorPlus.getInstance().getManager().fetch().stream().filter(LivingEntity::isAlive).forEach(bot -> bot.getBukkitEntity().teleport(player));
|
||||
TerminatorPlus.getInstance().getManager().fetch().stream().filter(Terminator::isAlive).forEach(bot -> bot.getBukkitEntity().teleport(player));
|
||||
}
|
||||
|
||||
public void viewsession() {
|
||||
@@ -244,9 +235,7 @@ public class Debugger {
|
||||
LegacyAgent legacyAgent = (LegacyAgent) agent;
|
||||
legacyAgent.offsets = b;
|
||||
|
||||
print("Bot target offsets are now "
|
||||
+ (legacyAgent.offsets ? ChatColor.GREEN + "ENABLED" : ChatColor.RED + "DISABLED")
|
||||
+ ChatColor.RESET + ".");
|
||||
print("Bot target offsets are now " + (legacyAgent.offsets ? ChatColor.GREEN + "ENABLED" : ChatColor.RED + "DISABLED") + ChatColor.RESET + ".");
|
||||
}
|
||||
|
||||
public void confuse(int n) {
|
||||
@@ -269,12 +258,7 @@ public class Debugger {
|
||||
}
|
||||
|
||||
public void dreamsmp() {
|
||||
spawnBots(Arrays.asList(
|
||||
"Dream", "GeorgeNotFound", "Callahan", "Sapnap", "awesamdude", "Ponk", "BadBoyHalo", "TommyInnit", "Tubbo_", "ItsFundy", "Punz",
|
||||
"Purpled", "WilburSoot", "Jschlatt", "Skeppy", "The_Eret", "JackManifoldTV", "Nihachu", "Quackity", "KarlJacobs", "HBomb94",
|
||||
"Technoblade", "Antfrost", "Ph1LzA", "ConnorEatsPants", "CaptainPuffy", "Vikkstar123", "LazarCodeLazar", "Ranboo", "FoolishG",
|
||||
"hannahxxrose", "Slimecicle", "Michaelmcchill"
|
||||
));
|
||||
spawnBots(Arrays.asList("Dream", "GeorgeNotFound", "Callahan", "Sapnap", "awesamdude", "Ponk", "BadBoyHalo", "TommyInnit", "Tubbo_", "ItsFundy", "Punz", "Purpled", "WilburSoot", "Jschlatt", "Skeppy", "The_Eret", "JackManifoldTV", "Nihachu", "Quackity", "KarlJacobs", "HBomb94", "Technoblade", "Antfrost", "Ph1LzA", "ConnorEatsPants", "CaptainPuffy", "Vikkstar123", "LazarCodeLazar", "Ranboo", "FoolishG", "hannahxxrose", "Slimecicle", "Michaelmcchill"));
|
||||
}
|
||||
|
||||
private void spawnBots(List<String> players) {
|
||||
@@ -319,9 +303,7 @@ public class Debugger {
|
||||
|
||||
print("Done.");
|
||||
});
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
print(e);
|
||||
}
|
||||
});
|
||||
@@ -352,14 +334,14 @@ public class Debugger {
|
||||
}
|
||||
|
||||
public void tp() {
|
||||
Bot bot = MathUtils.getRandomSetElement(TerminatorPlus.getInstance().getManager().fetch().stream().filter(LivingEntity::isAlive).collect(Collectors.toSet()));
|
||||
Terminator bot = MathUtils.getRandomSetElement(TerminatorPlus.getInstance().getManager().fetch().stream().filter(Terminator::isAlive).collect(Collectors.toSet()));
|
||||
|
||||
if (bot == null) {
|
||||
print("Failed to locate a bot.");
|
||||
return;
|
||||
}
|
||||
|
||||
print("Located bot", (ChatColor.GREEN.toString() + bot.getName() + ChatColor.RESET.toString() + "."));
|
||||
print("Located bot", (ChatColor.GREEN + bot.getBotName() + ChatColor.RESET + "."));
|
||||
|
||||
if (sender instanceof Player) {
|
||||
print("Teleporting...");
|
||||
@@ -386,9 +368,9 @@ public class Debugger {
|
||||
}
|
||||
|
||||
public void hideNametags() { // this works for some reason
|
||||
Set<Bot> bots = TerminatorPlus.getInstance().getManager().fetch();
|
||||
Set<Terminator> bots = TerminatorPlus.getInstance().getManager().fetch();
|
||||
|
||||
for (Bot bot : bots) {
|
||||
for (Terminator bot : bots) {
|
||||
Location loc = bot.getLocation();
|
||||
World world = loc.getWorld();
|
||||
|
||||
@@ -409,9 +391,9 @@ public class Debugger {
|
||||
}
|
||||
|
||||
public void sit() {
|
||||
Set<Bot> bots = TerminatorPlus.getInstance().getManager().fetch();
|
||||
Set<Terminator> bots = TerminatorPlus.getInstance().getManager().fetch();
|
||||
|
||||
for (Bot bot : bots) {
|
||||
for (Terminator bot : bots) {
|
||||
Location loc = bot.getLocation();
|
||||
World world = loc.getWorld();
|
||||
|
||||
@@ -440,7 +422,7 @@ public class Debugger {
|
||||
|
||||
Player player = (Player) sender;
|
||||
|
||||
for (Bot bot : TerminatorPlus.getInstance().getManager().fetch()) {
|
||||
for (Terminator bot : TerminatorPlus.getInstance().getManager().fetch()) {
|
||||
bot.faceLocation(player.getEyeLocation());
|
||||
}
|
||||
}
|
||||
@@ -451,8 +433,6 @@ public class Debugger {
|
||||
boolean b = agent.isEnabled();
|
||||
agent.setEnabled(!b);
|
||||
|
||||
print("The Bot Agent is now "
|
||||
+ (b ? ChatColor.RED + "DISABLED" : ChatColor.GREEN + "ENABLED")
|
||||
+ ChatColor.RESET + ".");
|
||||
print("The Bot Agent is now " + (b ? ChatColor.RED + "DISABLED" : ChatColor.GREEN + "ENABLED") + ChatColor.RESET + ".");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
package net.nuggetmc.tplus.utils;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ItemUtils {
|
||||
|
||||
public static double getLegacyAttackDamage(ItemStack item) {
|
||||
switch (item.getType()) {
|
||||
default:
|
||||
return 0.25;
|
||||
|
||||
case WOODEN_SHOVEL:
|
||||
case GOLDEN_SHOVEL:
|
||||
case WOODEN_HOE:
|
||||
case GOLDEN_HOE:
|
||||
case STONE_HOE:
|
||||
case IRON_HOE:
|
||||
case DIAMOND_HOE:
|
||||
case NETHERITE_HOE:
|
||||
return 1;
|
||||
|
||||
case WOODEN_PICKAXE:
|
||||
case GOLDEN_PICKAXE:
|
||||
case STONE_SHOVEL:
|
||||
return 2;
|
||||
|
||||
case WOODEN_AXE:
|
||||
case GOLDEN_AXE:
|
||||
case STONE_PICKAXE:
|
||||
case IRON_SHOVEL:
|
||||
return 3;
|
||||
|
||||
case WOODEN_SWORD:
|
||||
case GOLDEN_SWORD:
|
||||
case STONE_AXE:
|
||||
case IRON_PICKAXE:
|
||||
case DIAMOND_SHOVEL:
|
||||
return 4;
|
||||
|
||||
case STONE_SWORD:
|
||||
case IRON_AXE:
|
||||
case DIAMOND_PICKAXE:
|
||||
case NETHERITE_SHOVEL:
|
||||
return 5;
|
||||
|
||||
case IRON_SWORD:
|
||||
case DIAMOND_AXE:
|
||||
case NETHERITE_PICKAXE:
|
||||
return 6;
|
||||
|
||||
case DIAMOND_SWORD:
|
||||
case NETHERITE_AXE:
|
||||
return 7;
|
||||
|
||||
case NETHERITE_SWORD:
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package net.nuggetmc.tplus.utils;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MojangAPI {
|
||||
|
||||
private static final boolean CACHE_ENABLED = false;
|
||||
|
||||
private static final Map<String, String[]> CACHE = new HashMap<>();
|
||||
|
||||
public static String[] getSkin(String name) {
|
||||
if (CACHE_ENABLED && CACHE.containsKey(name)) {
|
||||
return CACHE.get(name);
|
||||
}
|
||||
|
||||
String[] values = pullFromAPI(name);
|
||||
CACHE.put(name, values);
|
||||
return values;
|
||||
}
|
||||
|
||||
// CATCHING NULL ILLEGALSTATEEXCEPTION BAD!!!! eventually fix from the getAsJsonObject thingy
|
||||
public static String[] pullFromAPI(String name) {
|
||||
try {
|
||||
String uuid = new JsonParser().parse(new InputStreamReader(new URL("https://api.mojang.com/users/profiles/minecraft/" + name)
|
||||
.openStream())).getAsJsonObject().get("id").getAsString();
|
||||
JsonObject property = new JsonParser()
|
||||
.parse(new InputStreamReader(new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false")
|
||||
.openStream())).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject();
|
||||
return new String[] {property.get("value").getAsString(), property.get("signature").getAsString()};
|
||||
} catch (IOException | IllegalStateException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
package net.nuggetmc.tplus.utils;
|
||||
|
||||
import net.nuggetmc.tplus.TerminatorPlus;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class PlayerUtils {
|
||||
|
||||
public static boolean isInvincible(GameMode mode) {
|
||||
return mode != GameMode.SURVIVAL && mode != GameMode.ADVENTURE && mode != null;
|
||||
}
|
||||
|
||||
private static final Set<String> USERNAME_CACHE = new HashSet<>();
|
||||
|
||||
public static String randomName() {
|
||||
if (USERNAME_CACHE.isEmpty()) {
|
||||
fillUsernameCache();
|
||||
}
|
||||
|
||||
return MathUtils.getRandomSetElement(USERNAME_CACHE);
|
||||
}
|
||||
|
||||
public static void fillUsernameCache() {
|
||||
String file = TerminatorPlus.getInstance().getServer().getWorldContainer().getAbsolutePath();
|
||||
file = file.substring(0, file.length() - 1) + "usercache.json";
|
||||
|
||||
JSONParser parser = new JSONParser();
|
||||
|
||||
try {
|
||||
JSONArray array = (JSONArray) parser.parse(new FileReader(file));
|
||||
|
||||
for (Object obj : array) {
|
||||
JSONObject jsonOBJ = (JSONObject) obj;
|
||||
String username = (String) jsonOBJ.get("name");
|
||||
|
||||
USERNAME_CACHE.add(username);
|
||||
}
|
||||
}
|
||||
|
||||
catch (IOException | ParseException e) {
|
||||
Debugger.log("Failed to fetch from the usercache.");
|
||||
}
|
||||
}
|
||||
|
||||
public static Location findAbove(Location loc, int amount) {
|
||||
boolean check = false;
|
||||
|
||||
for (int i = 0; i <= amount; i++) {
|
||||
if (loc.clone().add(0, i, 0).getBlock().getType().isSolid()) {
|
||||
check = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (check) {
|
||||
return loc;
|
||||
} else {
|
||||
return loc.clone().add(0, amount, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public static Location findBottom(Location loc) {
|
||||
loc.setY(loc.getBlockY());
|
||||
|
||||
for (int i = 0; i < 255; i++) {
|
||||
Location check = loc.clone().add(0, -i, 0);
|
||||
|
||||
if (check.getY() <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (check.getBlock().getType().isSolid()) {
|
||||
return check.add(0, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return loc;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package net.nuggetmc.tplus.utils;
|
||||
|
||||
public class Singularity {
|
||||
|
||||
private Object value;
|
||||
|
||||
public Singularity(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Singularity() {
|
||||
this.value = null;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean hasValue() {
|
||||
return value != null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user