9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-23 00:39:16 +00:00
Files
DivineMC/patches/server/0021-Optimize-CraftServer.getWorld-UUID.patch
2024-05-09 01:52:49 +03:00

52 lines
3.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sat, 13 Jan 2024 13:36:55 +0300
Subject: [PATCH] Optimize CraftServer.getWorld(UUID)
Original code by MultiPaper - https://github.com/MultiPaper/MultiPaper
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 8d75e43d1c0d8a65ebbf146dcccd23509c236540..71b40f824949dedfe35fe3012b9715a7c598dfb8 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -268,6 +268,7 @@ import javax.annotation.Nullable; // Paper
import javax.annotation.Nonnull; // Paper
import space.bxteam.divinemc.configuration.DivineConfig; // DivineMC
+import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; // DivineMC
public final class CraftServer implements Server {
private final String serverName = "DivineMC"; // Paper // Pufferfish // Purpur // DivineMC
@@ -286,6 +287,7 @@ public final class CraftServer implements Server {
protected final DedicatedPlayerList playerList;
private final Map<String, World> worlds = new LinkedHashMap<String, World>();
// private final Map<Class<?>, Registry<?>> registries = new HashMap<>(); // Paper - replace with RegistryAccess
+ private final Map<UUID, World> worldsByUUID = new Object2ObjectLinkedOpenHashMap<>(); // DivineMC - MultiPaper - optimize getWorld(UUID)
private YamlConfiguration configuration;
private YamlConfiguration commandsConfiguration;
private final Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions()));
@@ -1483,6 +1485,7 @@ public final class CraftServer implements Server {
this.getLogger().log(Level.SEVERE, null, ex);
}
+ this.worldsByUUID.remove(world.getUID()); // DivineMC - MultiPaper - optimize getWorld(UUID)
this.worlds.remove(world.getName().toLowerCase(java.util.Locale.ENGLISH));
this.console.removeLevel(handle);
return true;
@@ -1501,6 +1504,7 @@ public final class CraftServer implements Server {
@Override
public World getWorld(UUID uid) {
+ if (true) return this.worldsByUUID.get(uid); // DivineMC - MultiPaper - optimize getWorld(UUID)
for (World world : this.worlds.values()) {
if (world.getUID().equals(uid)) {
return world;
@@ -1524,6 +1528,7 @@ public final class CraftServer implements Server {
System.out.println("World " + world.getName() + " is a duplicate of another world and has been prevented from loading. Please delete the uid.dat file from " + world.getName() + "'s world directory if you want to be able to load the duplicate world.");
return;
}
+ this.worldsByUUID.put(world.getUID(), world); // DivineMC - MultiPaper - optimize getWorld(UUID)
this.worlds.put(world.getName().toLowerCase(java.util.Locale.ENGLISH), world);
}