9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-29 11:59:17 +00:00

fix: fakeplayer load by world(#411)

This commit is contained in:
MC_XiaoHei
2025-07-07 15:12:12 +08:00
parent 3043e16dbb
commit 30e665c576
14 changed files with 107 additions and 44 deletions

View File

@@ -30,7 +30,7 @@ index 8bab2c26e10e8495fd39be470bcb02917fe56f40..c9840dfa4067973aafed7e7c7305182d
private DisconnectionDetails disconnectionDetails;
private boolean encrypted;
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 95f5d078019ebd4fde9bf65748d866b51cfeabc6..05966b2600bead23ab2ec19c95a3797eda7f3ef8 100644
index 95f5d078019ebd4fde9bf65748d866b51cfeabc6..feb5fc93498a5ed89e3bcb61cd72ba6e75881358 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -304,6 +304,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -42,16 +42,7 @@ index 95f5d078019ebd4fde9bf65748d866b51cfeabc6..05966b2600bead23ab2ec19c95a3797e
public static <S extends MinecraftServer> S spin(Function<Thread, S> threadFunction) {
ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry.init(); // Paper - rewrite data converter system
AtomicReference<S> atomicReference = new AtomicReference<>();
@@ -740,6 +742,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
// Paper end - Configurable player collision
+ this.getBotList().loadResume(); // Leaves - load resident bot
+
this.server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.POSTWORLD);
this.server.spark.registerCommandBeforePlugins(this.server); // Paper - spark
this.server.spark.enableAfterPlugins(this.server); // Paper - spark
@@ -996,6 +1000,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -996,6 +998,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
LOGGER.info("Stopping server");
Commands.COMMAND_SENDING_POOL.shutdownNow(); // Paper - Perf: Async command map building; Shutdown and don't bother finishing
@@ -59,7 +50,7 @@ index 95f5d078019ebd4fde9bf65748d866b51cfeabc6..05966b2600bead23ab2ec19c95a3797e
// CraftBukkit start
if (this.server != null) {
this.server.spark.disable(); // Paper - spark
@@ -1761,6 +1766,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1761,6 +1764,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
public void tickConnection() {
this.getConnection().tick();
@@ -67,7 +58,7 @@ index 95f5d078019ebd4fde9bf65748d866b51cfeabc6..05966b2600bead23ab2ec19c95a3797e
}
private void synchronizeTime(ServerLevel level) {
@@ -2810,6 +2816,16 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -2810,6 +2814,16 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
return 0;
}
@@ -101,7 +92,7 @@ index fdeca41d40705f28864ce4443d01cd872c9d51b0..5c0e338dc1b0eb5724d10a73d6fc7975
AdvancementProgress orStartProgress = this.getOrStartProgress(advancement);
boolean isDone = orStartProgress.isDone();
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
index 414a8357a7498c69341fa634ada2e664e18ca03a..d0971352de582c3d3bda544f08578d0c4c3618eb 100644
index 414a8357a7498c69341fa634ada2e664e18ca03a..f85993fc507d699728e058b12bb49dcb7aaea44b 100644
--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -162,6 +162,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@@ -112,6 +103,14 @@ index 414a8357a7498c69341fa634ada2e664e18ca03a..d0971352de582c3d3bda544f08578d0c
this.setPlayerList(new DedicatedPlayerList(this, this.registries(), this.playerDataStorage));
org.spigotmc.SpigotConfig.init((java.io.File) this.options.valueOf("spigot-settings"));
org.spigotmc.SpigotConfig.registerCommands();
@@ -185,6 +186,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // Paper - load version history now
org.leavesmc.leaves.LeavesConfig.init((java.io.File) options.valueOf("leaves-settings")); // Leaves - Server Config
+ this.getBotList().loadBotInfo(); // Leaves - load resident bot info
com.destroystokyo.paper.Metrics.PaperMetrics.startMetrics(); // Paper - start metrics // Leaves - down
diff --git a/net/minecraft/server/level/ChunkMap.java b/net/minecraft/server/level/ChunkMap.java
index eb352aa4296abc3ed4cf31c590bc0be66daf4de3..019886669966c69936ae6591598c97a8afbfd3db 100644
--- a/net/minecraft/server/level/ChunkMap.java
@@ -213,7 +212,7 @@ index dfa00516e9a6c941087bd7ecfd5aca8a9f7915be..6ce8772bbec5f20b38ba991e8f7b1da4
org.bukkit.event.player.PlayerChangedWorldEvent changeEvent = new org.bukkit.event.player.PlayerChangedWorldEvent(this.getBukkitEntity(), serverLevel.getWorld());
this.level().getCraftServer().getPluginManager().callEvent(changeEvent);
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
index 91f505c9d84aba773d237664c2aaaf9750cadadf..580ab889bce7d0dff64e5e1ae92a646ac96e3168 100644
index 184d116320f0cd3e9fba47a86e94e0a8424c913f..baeeb4a0863cb37eee487b0e463fea37eaf2e791 100644
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -337,6 +337,19 @@ public abstract class PlayerList {
@@ -299,7 +298,7 @@ index 91f505c9d84aba773d237664c2aaaf9750cadadf..580ab889bce7d0dff64e5e1ae92a646a
public boolean canBypassPlayerLimit(GameProfile profile) {
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 910bec7cbb2ef140ab16d99f93859326b5475a25..089b50dbae2ae351d81deb041663f8885e3bfae1 100644
index b257428466f25b90caadc54ce01d948287d46c26..7082b94662c23ccb688a203866df2d2feaf23917 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -1487,7 +1487,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess

View File

@@ -91,10 +91,10 @@ index 1df628ac0b414511aaed6e09d78f884c4170f730..b92081d70ffeec47c304e553ce1aea0a
}
}
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
index d0971352de582c3d3bda544f08578d0c4c3618eb..9112c203c7cf31b2ce1789ea97ab17ceaaba24b4 100644
index f85993fc507d699728e058b12bb49dcb7aaea44b..91babab6152bb12768399ef6f2ea6afcb5e644b7 100644
--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -572,7 +572,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@@ -573,7 +573,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
// Paper start - Add setting for proxy online mode status
return properties.enforceSecureProfile
&& io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode()
@@ -133,7 +133,7 @@ index dd377f2f85da6c3b86dad7c577887c128b63004b..8786c9436c5acc59221fa713a00314a4
if (packet == null || this.processedDisconnect) { // Spigot
return;
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
index 580ab889bce7d0dff64e5e1ae92a646ac96e3168..11aa0c3379ec13d91770ba1e7dfb63e83eacadcd 100644
index baeeb4a0863cb37eee487b0e463fea37eaf2e791..a1e7d92c922013cbd0e3a613aa0c2c49ac3e3ef2 100644
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -1315,7 +1315,7 @@ public abstract class PlayerList {

View File

@@ -6,10 +6,10 @@ Subject: [PATCH] Config to disable method profiler
This patch is Powered by Pufferfish(https://github.com/pufferfish-gg/Pufferfish)
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 05966b2600bead23ab2ec19c95a3797eda7f3ef8..11728fa48bb144bbe933eb8fa2df22b52ac1b5a5 100644
index feb5fc93498a5ed89e3bcb61cd72ba6e75881358..6539574b72dcb362d8d106a68d6e2d968340fc5e 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1250,7 +1250,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1248,7 +1248,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
lastTick = currentTime;
this.nextTickTimeNanos += l;

View File

@@ -20,10 +20,10 @@ index 4535858701b2bb232b9d2feb2af6551526232ddc..2a51acd97afc525170e8001b76f57ad1
if (var4 instanceof ReportedException reportedException && reportedException.getCause() instanceof OutOfMemoryError) {
throw makeReportedException(var4, packet, processor);
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 7e339cb26a132487ac0ab91d3db7e4885bacd545..44079b08d2abd53c12cea3441a38b0b66b3669b0 100644
index edab8f8be8bc513afe435f3f2d1419de8fae1135..881eec1193e9b74d4ac78873654bf2f79f9750e3 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1726,6 +1726,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1724,6 +1724,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
try {
serverLevel.tick(hasTimeLeft);

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Bedrock break list
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 44079b08d2abd53c12cea3441a38b0b66b3669b0..f288b85909550e6eec931ee2da9e0d4c7808fdc9 100644
index 881eec1193e9b74d4ac78873654bf2f79f9750e3..a9322925daca18b3f3120bd540c47b4758b1ecf7 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1753,6 +1753,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1751,6 +1751,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
profilerFiller.popPush("server gui refresh");
org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handleTick(tickCount); // Leaves - protocol

View File

@@ -81,10 +81,10 @@ index 514f8fbdeb776087608665c35de95294aadf5cf0..2f78ca86f46ea08fdcf4b8047d3d0b04
if (players.size() >= resultLimit) {
return players;
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index f288b85909550e6eec931ee2da9e0d4c7808fdc9..f880cfc9394454bc090f41bc51fbc29b382fab31 100644
index a9322925daca18b3f3120bd540c47b4758b1ecf7..57b0ec8336722197dae868d92d8733330f0b0722 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1640,7 +1640,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1638,7 +1638,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
private ServerStatus.Players buildPlayerStatus() {

View File

@@ -39,13 +39,13 @@ index e673df664b06c654a7be0622874b9b27ad7ef20f..898bf4d1e3269135f9514cdfd923040b
String awtException = io.papermc.paper.util.ServerEnvironment.awtDependencyCheck();
if (awtException != null) {
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
index 9112c203c7cf31b2ce1789ea97ab17ceaaba24b4..d587517dde1f5c3f57d8312ab1643c837fbd3056 100644
index 91babab6152bb12768399ef6f2ea6afcb5e644b7..bb6863ed3fdb7bcf73ddecc1a93f89d5f84b728e 100644
--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -186,6 +186,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // Paper - load version history now
@@ -187,6 +187,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
org.leavesmc.leaves.LeavesConfig.init((java.io.File) options.valueOf("leaves-settings")); // Leaves - Server Config
this.getBotList().loadBotInfo(); // Leaves - load resident bot info
+ org.leavesmc.leaves.util.ServerI18nUtil.init(); // Leaves I18n
com.destroystokyo.paper.Metrics.PaperMetrics.startMetrics(); // Paper - start metrics // Leaves - down

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Disable offline warn if use proxy
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
index d587517dde1f5c3f57d8312ab1643c837fbd3056..9da70088b377f0b093aa12837861025a0522773d 100644
index bb6863ed3fdb7bcf73ddecc1a93f89d5f84b728e..6a6209750854f5bad7f069cd6694d339bd9ce834 100644
--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -246,7 +246,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@@ -247,7 +247,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
String proxyFlavor = (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled) ? "Velocity" : "BungeeCord";
String proxyLink = (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled) ? "https://docs.papermc.io/velocity/security" : "http://www.spigotmc.org/wiki/firewall-guide/";
// Paper end - Add Velocity IP Forwarding Support

View File

@@ -54,10 +54,10 @@ index 51c126735ace8fdde89ad97b5cab62f244212db0..a6573e327ace16b7ea320eb1440ffcbc
+ public void moonrise$write(final org.leavesmc.leaves.region.IRegionFile regionFile) throws IOException; // Leaves - more region format
}
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index f880cfc9394454bc090f41bc51fbc29b382fab31..1c26b6767b53c7e90764f7ec42503dfbe9c49bc6 100644
index 57b0ec8336722197dae868d92d8733330f0b0722..d2f98398492b74de6a03dbd2cc8f431ddb90867b 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -946,10 +946,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -944,10 +944,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// CraftBukkit end
if (flush) {
for (ServerLevel serverLevel2 : this.getAllLevels()) {

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Leaves Fakeplayer
diff --git a/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java b/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java
index a589689e3a9de1fffef62e0e3dcd79bb2e848c5b..a0a6cde96322df8e455b26b32b1c593f332d4db6 100644
index a589689e3a9de1fffef62e0e3dcd79bb2e848c5b..af9408c990d5ba2cf34d6c64db86a04c90165e91 100644
--- a/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java
+++ b/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java
@@ -41,6 +41,12 @@ class PaperEventManager {
@@ -41,6 +41,22 @@ class PaperEventManager {
throw new IllegalStateException(event.getEventName() + " may only be triggered synchronously.");
}
@@ -17,6 +17,16 @@ index a589689e3a9de1fffef62e0e3dcd79bb2e848c5b..a0a6cde96322df8e455b26b32b1c593f
+ return;
+ }
+ // Leaves end - skip bot
+
+ // Leaves start - process bot load/save
+ if (org.leavesmc.leaves.LeavesConfig.modify.fakeplayer.enable && org.leavesmc.leaves.LeavesConfig.modify.fakeplayer.canResident) {
+ if (event instanceof org.bukkit.event.world.WorldLoadEvent worldLoadEvent) {
+ org.leavesmc.leaves.bot.BotList.INSTANCE.loadResume(worldLoadEvent.getWorld().getUID().toString());
+ } else if (event instanceof org.bukkit.event.world.WorldUnloadEvent worldUnloadEvent) {
+ org.leavesmc.leaves.bot.BotList.INSTANCE.removeAllIn(worldUnloadEvent.getWorld().getUID().toString());
+ }
+ }
+ // Leaves end - process bot load/save
+
HandlerList handlers = event.getHandlers();
RegisteredListener[] listeners = handlers.getRegisteredListeners();

View File

@@ -105,6 +105,18 @@ public class BotDataStorage implements IPlayerDataStorage {
return Optional.empty();
}
public Optional<CompoundTag> read(String uuid) {
File file = new File(this.botDir, uuid + ".dat");
if (file.exists() && file.isFile()) {
try {
return Optional.of(NbtIo.readCompressed(file.toPath(), NbtAccounter.unlimitedHeap()));
} catch (Exception exception) {
BotDataStorage.LOGGER.warn("Failed to read fakeplayer data for {}", uuid);
}
}
return Optional.empty();
}
private void saveBotList() {
try {
if (this.botListFile.exists() && this.botListFile.isFile()) {

View File

@@ -36,10 +36,12 @@ import org.leavesmc.leaves.event.bot.BotRemoveEvent;
import org.leavesmc.leaves.event.bot.BotSpawnLocationEvent;
import org.slf4j.Logger;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -56,6 +58,7 @@ public class BotList {
private final Map<UUID, ServerBot> botsByUUID = Maps.newHashMap();
private final Map<String, ServerBot> botsByName = Maps.newHashMap();
private final Map<String, Set<String>> botsNameByWorldUuid = Maps.newHashMap();
public BotList(MinecraftServer server) {
this.server = server;
@@ -171,6 +174,9 @@ public class BotList {
bot.level().getChunkSource().chunkMap.addEntity(bot);
bot.initInventoryMenu();
botsNameByWorldUuid
.computeIfAbsent(bot.level().uuid.toString(), (k) -> new HashSet<>())
.add(bot.getBukkitEntity().getRealName());
BotList.LOGGER.info("{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", bot.getName().getString(), "Local", bot.getId(), bot.level().serverLevelData.getLevelName(), bot.getX(), bot.getY(), bot.getZ());
return bot;
}
@@ -198,6 +204,7 @@ public class BotList {
playerIO.save(bot);
} else {
bot.dropAll(true);
botsNameByWorldUuid.get(bot.level().uuid.toString()).remove(bot.getBukkitEntity().getRealName());
}
if (bot.isPassenger() && event.shouldSave()) {
@@ -250,6 +257,15 @@ public class BotList {
return true;
}
public void removeAllIn(String worldUuid) {
for (String realName : this.botsNameByWorldUuid.getOrDefault(worldUuid, new HashSet<>())) {
ServerBot bot = this.getBotByName(realName);
if (bot != null) {
this.removeBot(bot, BotRemoveEvent.RemoveReason.INTERNAL, null, LeavesConfig.modify.fakeplayer.canResident);
}
}
}
public void removeAll() {
for (ServerBot bot : this.bots) {
bot.resume = LeavesConfig.modify.fakeplayer.canResident;
@@ -257,18 +273,31 @@ public class BotList {
}
}
public void loadResume() {
if (LeavesConfig.modify.fakeplayer.enable && LeavesConfig.modify.fakeplayer.canResident) {
CompoundTag savedBotList = this.getSavedBotList().copy();
for (String realName : savedBotList.keySet()) {
CompoundTag nbt = savedBotList.getCompound(realName).orElseThrow();
if (nbt.getBoolean("resume").orElse(false)) {
this.loadNewBot(realName);
}
public void loadBotInfo() {
System.out.println(LeavesConfig.modify.fakeplayer.canResident);
if (!LeavesConfig.modify.fakeplayer.enable || !LeavesConfig.modify.fakeplayer.canResident) return;
CompoundTag savedBotList = this.getSavedBotList().copy();
for (String realName : savedBotList.keySet()) {
CompoundTag nbt = savedBotList.getCompound(realName).orElseThrow();
if (!nbt.getBoolean("resume").orElse(false)) continue;
UUID levelUuid = BotUtil.getBotLevel(realName, this.dataStorage);
if (levelUuid == null) {
LOGGER.warn("Bot {} has no world UUID, skipping loading.", realName);
continue;
}
this.botsNameByWorldUuid
.computeIfAbsent(levelUuid.toString(), (k) -> new HashSet<>())
.add(realName);
}
}
public void loadResume(String worldUuid) {
if (!LeavesConfig.modify.fakeplayer.enable || !LeavesConfig.modify.fakeplayer.canResident) return;
Set<String> bots = this.botsNameByWorldUuid.get(worldUuid);
if (bots == null) return;
bots.forEach(this::loadNewBot);
}
public void networkTick() {
this.bots.forEach(ServerBot::networkTick);
}

View File

@@ -2,12 +2,14 @@ package org.leavesmc.leaves.bot;
import com.google.common.base.Charsets;
import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ItemStack;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.LeavesConfig;
import java.util.Optional;
import java.util.UUID;
public class BotUtil {
@@ -73,6 +75,17 @@ public class BotUtil {
return UUID.nameUUIDFromBytes(("Fakeplayer:" + realName).getBytes(Charsets.UTF_8));
}
public static UUID getBotLevel(@NotNull String realName, BotDataStorage botDataStorage) {
UUID uuid = BotUtil.getBotUUID(realName);
Optional<CompoundTag> tagOptional = botDataStorage.read(uuid.toString());
if (tagOptional.isEmpty()) return null;
CompoundTag tag = tagOptional.get();
Optional<Long> worldUUIDMost = tag.getLong("WorldUUIDMost");
Optional<Long> worldUUIDLeast = tag.getLong("WorldUUIDLeast");
if (worldUUIDMost.isEmpty() || worldUUIDLeast.isEmpty()) return null;
return new UUID(worldUUIDMost.get(), worldUUIDLeast.get());
}
public static String getFullName(String inputName) {
return LeavesConfig.modify.fakeplayer.prefix + inputName + LeavesConfig.modify.fakeplayer.suffix;
}