From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Martijn Muijsers Date: Sat, 24 Dec 2022 13:09:34 +0100 Subject: [PATCH] CraftBukkit UUID to world map License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html) Gale - https://galemc.org This patch is based on the following patch: "Optimize CraftServer.getWorld(UUID)" By: PureGero As part of: MultiPaper (https://github.com/MultiPaper/MultiPaper) Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html) diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index e9412757b1b8cdee878b5a210ad7d9b008e9d710..be250f95e1ebf61e74b3c025f2c90d48c75aad76 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -42,6 +42,9 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; import javax.imageio.ImageIO; + +import it.unimi.dsi.fastutil.objects.Object2ObjectMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.minecraft.advancements.Advancement; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; @@ -277,6 +280,7 @@ public final class CraftServer implements Server { protected final DedicatedServer console; protected final DedicatedPlayerList playerList; private final Map worlds = new LinkedHashMap(); + private final Object2ObjectMap worldsByUUID = new Object2ObjectOpenHashMap<>(); // Gale - MultiPaper - CraftBukkit UUID to world map private final Map, Registry> registries = new HashMap<>(); private YamlConfiguration configuration; private YamlConfiguration commandsConfiguration; @@ -1339,6 +1343,7 @@ public final class CraftServer implements Server { this.getLogger().log(Level.SEVERE, null, ex); } + this.worldsByUUID.remove(world.getUID()); // Gale - MultiPaper - CraftBukkit UUID to world map this.worlds.remove(world.getName().toLowerCase(java.util.Locale.ENGLISH)); this.console.removeLevel(handle); return true; @@ -1357,12 +1362,7 @@ public final class CraftServer implements Server { @Override public World getWorld(UUID uid) { - for (World world : this.worlds.values()) { - if (world.getUID().equals(uid)) { - return world; - } - } - return null; + return this.worldsByUUID.get(uid); // Gale - MultiPaper - CraftBukkit UUID to world map } // Paper start @@ -1380,6 +1380,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); // Gale - MultiPaper - CraftBukkit UUID to world map this.worlds.put(world.getName().toLowerCase(java.util.Locale.ENGLISH), world); }