54 lines
2.8 KiB
Diff
54 lines
2.8 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: PureGero <puregero@gmail.com>
|
|
Date: Sun, 26 Jun 2022 11:17:27 +1000
|
|
Subject: [PATCH] Optimize CraftServer.getWorld(UUID)
|
|
|
|
Original license: GPLv3
|
|
Original project: 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 d2478bda9e8395a8730a3416ce3133782ab9a8e9..cc9c5eecc4ef1d5dc4e814ad89a40a34f4d48a69 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -45,6 +45,8 @@ 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.Object2ObjectLinkedOpenHashMap;
|
|
import net.minecraft.advancements.Advancement;
|
|
import net.minecraft.commands.CommandSourceStack;
|
|
import net.minecraft.commands.Commands;
|
|
@@ -262,6 +264,7 @@ public final class CraftServer implements Server {
|
|
protected final DedicatedServer console;
|
|
protected final DedicatedPlayerList playerList;
|
|
private final Map<String, World> worlds = new LinkedHashMap<String, World>();
|
|
+ private final Map<UUID, World> worldsByUUID = new Object2ObjectLinkedOpenHashMap<>(); // MultiPaper - optimize getWorld(UUID)
|
|
private final Map<Class<?>, Registry<?>> registries = new HashMap<>();
|
|
private YamlConfiguration configuration;
|
|
private YamlConfiguration commandsConfiguration;
|
|
@@ -1312,6 +1315,7 @@ public final class CraftServer implements Server {
|
|
this.getLogger().log(Level.SEVERE, null, ex);
|
|
}
|
|
|
|
+ this.worldsByUUID.remove(world.getUID()); // MultiPaper - optimize getWorld(UUID)
|
|
this.worlds.remove(world.getName().toLowerCase(java.util.Locale.ENGLISH));
|
|
this.console.removeLevel(handle);
|
|
return true;
|
|
@@ -1330,6 +1334,7 @@ public final class CraftServer implements Server {
|
|
|
|
@Override
|
|
public World getWorld(UUID uid) {
|
|
+ if (true) return this.worldsByUUID.get(uid); // MultiPaper - optimize getWorld(UUID)
|
|
for (World world : this.worlds.values()) {
|
|
if (world.getUID().equals(uid)) {
|
|
return world;
|
|
@@ -1353,6 +1358,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); // MultiPaper - optimize getWorld(UUID)
|
|
this.worlds.put(world.getName().toLowerCase(java.util.Locale.ENGLISH), world);
|
|
}
|
|
|