From 9520274e5ebaf3b72b6e5e36ed110e37723b933c Mon Sep 17 00:00:00 2001 From: batchprogrammer314 Date: Tue, 29 Jun 2021 16:43:19 -0500 Subject: [PATCH] Added CustomGameProfile.java --- src/main/java/net/nuggetmc/ai/bot/Bot.java | 28 ++++--------------- .../nuggetmc/ai/bot/CustomGameProfile.java | 22 +++++++++++++++ 2 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 src/main/java/net/nuggetmc/ai/bot/CustomGameProfile.java diff --git a/src/main/java/net/nuggetmc/ai/bot/Bot.java b/src/main/java/net/nuggetmc/ai/bot/Bot.java index 270ae4f..ce76df1 100644 --- a/src/main/java/net/nuggetmc/ai/bot/Bot.java +++ b/src/main/java/net/nuggetmc/ai/bot/Bot.java @@ -1,11 +1,9 @@ package net.nuggetmc.ai.bot; import com.mojang.authlib.GameProfile; -import com.mojang.authlib.properties.Property; import net.minecraft.server.v1_16_R3.*; import net.nuggetmc.ai.PlayerAI; import net.nuggetmc.ai.utils.MathUtils; -import net.nuggetmc.ai.utils.MojangAPI; import net.nuggetmc.ai.utils.SteveUUID; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -29,7 +27,6 @@ public class Bot extends EntityPlayer { private byte groundTicks; private final double regenAmount = 0.05; - private final double bbOffset = 0.05; private final double frictionMin = 0.01; private final double kbUp = 0.3; @@ -48,10 +45,10 @@ public class Bot extends EntityPlayer { UUID uuid = SteveUUID.generate(); - GameProfile profile = new GameProfile(uuid, name); + CustomGameProfile profile = new CustomGameProfile(uuid, name); PlayerInteractManager interactManager = new PlayerInteractManager(nmsWorld); - setSkin(profile, skin); + profile.setSkin(skin); Bot bot = new Bot(nmsServer, nmsWorld, profile, interactManager); @@ -60,28 +57,19 @@ public class Bot extends EntityPlayer { bot.getBukkitEntity().setNoDamageTicks(0); nmsWorld.addEntity(bot); - sendSpawnPackets(bot); + bot.sendSpawnPackets(); PlayerAI.getInstance().getManager().add(bot); return bot; } - private static void setSkin(GameProfile profile, String skin) { - String[] vals = MojangAPI.getSkin(skin); - - if (vals != null) { - profile.getProperties().put("textures", new Property("textures", vals[0], vals[1])); - } - } - - private static void sendSpawnPackets(Bot bot) { - DataWatcher watcher = bot.getDataWatcher(); - watcher.set(new DataWatcherObject<>(16, DataWatcherRegistry.a), (byte) 0xFF); + private void sendSpawnPackets() { + getDataWatcher().set(new DataWatcherObject<>(16, DataWatcherRegistry.a), (byte) 0xFF); for (Player player : Bukkit.getOnlinePlayers()) { PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - bot.render(connection, false); + render(connection, false); } } @@ -99,10 +87,6 @@ public class Bot extends EntityPlayer { } } - public void setOffset(Vector vector) { - this.offset = vector; - } - public Vector getOffset() { return offset; } diff --git a/src/main/java/net/nuggetmc/ai/bot/CustomGameProfile.java b/src/main/java/net/nuggetmc/ai/bot/CustomGameProfile.java new file mode 100644 index 0000000..de88b15 --- /dev/null +++ b/src/main/java/net/nuggetmc/ai/bot/CustomGameProfile.java @@ -0,0 +1,22 @@ +package net.nuggetmc.ai.bot; + +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import net.nuggetmc.ai.utils.MojangAPI; + +import java.util.UUID; + +public class CustomGameProfile extends GameProfile { + + public CustomGameProfile(UUID uuid, String name) { + super(uuid, name); + } + + public void setSkin(String skin) { + String[] vals = MojangAPI.getSkin(skin); + + if (vals != null) { + getProperties().put("textures", new Property("textures", vals[0], vals[1])); + } + } +}