mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-03 13:36:44 +01:00
48b6bfe2a6
Upstream has released updates that appears to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: c987938a SPIGOT-5180: Add Villager#sleep() and #wakeup() methods CraftBukkit Changes:7f33c6a2
SPIGOT-5196: Restore previous version behaviour regarding cancelled BlockBreakEvent6a5fc902
Improve diff in EntityHangingc98d61bf
SPIGOT-4712: Allow spawning of upwards or downwards facing item framesdb971477
SPIGOT-5199: Fix NPE if setting the book of the ItemMeta of a lecternb0ef3996
SPIGOT-4679 Fix black lines after book paragraphs1215188f
SPIGOT-5180: Add Villager#sleep() and #wakeup() methodsc03b2bef
SPIGOT-4975: NPE on WorldGenStronghold When Using Multiple Worlds65ea162c
Ensure Bukkit data pack is always up to date0b107b8d
MC-157395, SPIGOT-5193: Small armor stands do not drop loot6da0abca
SPIGOT-5195: Player loot table does not drop when keepInventory is on8b09d983
SPIGOT-5190: Superfluous EntityCombustEvent called when using fire aspect sword Spigot Changes: 1981d553 SPIGOT-5198: Catch more bad async operations 6a14ca46 Rebuild patches
251 lines
9.1 KiB
Diff
251 lines
9.1 KiB
Diff
From 20f83dd15b487d2c37dd45bc8bb3906242f3073d Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Mon, 17 Sep 2018 23:37:31 -0400
|
|
Subject: [PATCH] Optimize Server World Map
|
|
|
|
Minecraft moved worlds to a hashmap in 1.13.1.
|
|
This creates inconsistent order for iteration of the map.
|
|
|
|
This patch restores World management to be back as an Array.
|
|
|
|
.values() will allow us to iterate as it was pre 1.13.1 by
|
|
ArrayList, giving consistent ordering and effecient iteration performance.
|
|
|
|
KeySet and EntrySet iteration is proxied to the List iterator,
|
|
and should retain manipulation behavior but nothing should be doing that.
|
|
|
|
Getting a World by dimension ID is now back a constant time operation.
|
|
|
|
Hopefully no other plugins try to mess with this map, as we are only handling
|
|
known NMS used methods, but we can add more if naughty plugins are found later.
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldMap.java b/src/main/java/com/destroystokyo/paper/PaperWorldMap.java
|
|
new file mode 100644
|
|
index 000000000..6bb2f98b4
|
|
--- /dev/null
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldMap.java
|
|
@@ -0,0 +1,191 @@
|
|
+package com.destroystokyo.paper;
|
|
+
|
|
+import net.minecraft.server.DimensionManager;
|
|
+import net.minecraft.server.WorldServer;
|
|
+
|
|
+import javax.annotation.Nonnull;
|
|
+import java.util.AbstractSet;
|
|
+import java.util.ArrayList;
|
|
+import java.util.Collection;
|
|
+import java.util.HashMap;
|
|
+import java.util.Iterator;
|
|
+import java.util.List;
|
|
+import java.util.Map;
|
|
+import java.util.Set;
|
|
+
|
|
+public class PaperWorldMap extends HashMap<DimensionManager, WorldServer> {
|
|
+ private final List<WorldServer> worlds = new ArrayList<>();
|
|
+ private final List<WorldServer> worldsIterable = new ArrayList<WorldServer>() {
|
|
+ @Override
|
|
+ public Iterator<WorldServer> iterator() {
|
|
+ Iterator<WorldServer> iterator = super.iterator();
|
|
+ return new Iterator<WorldServer>() {
|
|
+ private WorldServer last;
|
|
+
|
|
+ @Override
|
|
+ public boolean hasNext() {
|
|
+ return iterator.hasNext();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public WorldServer next() {
|
|
+ this.last = iterator.next();
|
|
+ return last;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void remove() {
|
|
+ worlds.set(last.worldProvider.getDimensionManager().getDimensionID() + 1, null);
|
|
+ }
|
|
+ };
|
|
+ }
|
|
+ };
|
|
+ @Override
|
|
+ public int size() {
|
|
+ return worldsIterable.size();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean isEmpty() {
|
|
+ return worldsIterable.isEmpty();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public WorldServer get(Object key) {
|
|
+ // Will hit the below method
|
|
+ return key instanceof DimensionManager ? get((DimensionManager) key) : null;
|
|
+ }
|
|
+
|
|
+ public WorldServer get(DimensionManager key) {
|
|
+ int id = key.getDimensionID()+1;
|
|
+ return worlds.size() > id ? worlds.get(id) : null;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean containsKey(Object key) {
|
|
+ // will hit below method
|
|
+ return key instanceof DimensionManager && containsKey((DimensionManager) key);
|
|
+ }
|
|
+ public boolean containsKey(DimensionManager key) {
|
|
+ return get(key) != null;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public WorldServer put(DimensionManager key, WorldServer value) {
|
|
+ while (worlds.size() <= key.getDimensionID()+1) {
|
|
+ worlds.add(null);
|
|
+ }
|
|
+ WorldServer old = worlds.set(key.getDimensionID()+1, value);
|
|
+ if (old != null) {
|
|
+ worldsIterable.remove(old);
|
|
+ }
|
|
+ worldsIterable.add(value);
|
|
+ return old;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void putAll(Map<? extends DimensionManager, ? extends WorldServer> m) {
|
|
+ for (Entry<? extends DimensionManager, ? extends WorldServer> e : m.entrySet()) {
|
|
+ put(e.getKey(), e.getValue());
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public WorldServer remove(Object key) {
|
|
+ return key instanceof DimensionManager ? remove((DimensionManager) key) : null;
|
|
+ }
|
|
+
|
|
+ public WorldServer remove(DimensionManager key) {
|
|
+ WorldServer old;
|
|
+ if (key.getDimensionID()+1 == worlds.size() - 1) {
|
|
+ old = worlds.remove(key.getDimensionID()+1);
|
|
+ } else {
|
|
+ old = worlds.set(key.getDimensionID() + 1, null);
|
|
+ }
|
|
+ if (old != null) {
|
|
+ worldsIterable.remove(old);
|
|
+ }
|
|
+ return old;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void clear() {
|
|
+ throw new RuntimeException("What the hell are you doing?");
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean containsValue(Object value) {
|
|
+ return value instanceof WorldServer && get(((WorldServer) value).worldProvider.getDimensionManager()) != null;
|
|
+ }
|
|
+
|
|
+ @Nonnull
|
|
+ @Override
|
|
+ public Set<DimensionManager> keySet() {
|
|
+ return new AbstractSet<DimensionManager>() {
|
|
+ @Override
|
|
+ public Iterator<DimensionManager> iterator() {
|
|
+ Iterator<WorldServer> iterator = worldsIterable.iterator();
|
|
+ return new Iterator<DimensionManager>() {
|
|
+
|
|
+ @Override
|
|
+ public boolean hasNext() {
|
|
+ return iterator.hasNext();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public DimensionManager next() {
|
|
+ return iterator.next().worldProvider.getDimensionManager();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void remove() {
|
|
+ iterator.remove();
|
|
+ }
|
|
+ };
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int size() {
|
|
+ return worlds.size();
|
|
+ }
|
|
+ };
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Collection<WorldServer> values() {
|
|
+ return worldsIterable;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Set<Entry<DimensionManager, WorldServer>> entrySet() {
|
|
+ return new AbstractSet<Entry<DimensionManager, WorldServer>>() {
|
|
+ @Override
|
|
+ public Iterator<Entry<DimensionManager, WorldServer>> iterator() {
|
|
+ Iterator<WorldServer> iterator = worldsIterable.iterator();
|
|
+ return new Iterator<Entry<DimensionManager, WorldServer>>() {
|
|
+
|
|
+ @Override
|
|
+ public boolean hasNext() {
|
|
+ return iterator.hasNext();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Entry<DimensionManager, WorldServer> next() {
|
|
+ WorldServer entry = iterator.next();
|
|
+ return new SimpleEntry<>(entry.worldProvider.getDimensionManager(), entry);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void remove() {
|
|
+ iterator.remove();
|
|
+ }
|
|
+ };
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int size() {
|
|
+ return worldsIterable.size();
|
|
+ }
|
|
+ };
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index 150f19024..f6a979a5b 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -88,7 +88,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
|
public final DataFixer dataConverterManager;
|
|
private String serverIp;
|
|
private int serverPort = -1;
|
|
- public final Map<DimensionManager, WorldServer> worldServer = Maps.newLinkedHashMap(); // CraftBukkit - keep order, k+v already use identity methods
|
|
+ public final Map<DimensionManager, WorldServer> worldServer = new com.destroystokyo.paper.PaperWorldMap(); // Paper;
|
|
private PlayerList playerList;
|
|
private volatile boolean isRunning = true;
|
|
private volatile boolean isRestarting = false; // Paper - flag to signify we're attempting to restart
|
|
@@ -451,7 +451,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
|
}
|
|
}
|
|
this.a(this.getDifficulty(), true);
|
|
- for (WorldServer worldserver : this.getWorlds()) {
|
|
+ for (WorldServer worldserver : com.google.common.collect.Lists.newArrayList(this.getWorlds())) { // Paper - avoid como if 1 world triggers another world
|
|
this.loadSpawn(worldserver.getChunkProvider().playerChunkMap.worldLoadListener, worldserver);
|
|
this.server.getPluginManager().callEvent(new org.bukkit.event.world.WorldLoadEvent(worldserver.getWorld()));
|
|
}
|
|
@@ -597,7 +597,6 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
|
// this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
|
|
this.executeModerately();
|
|
// Iterator iterator = DimensionManager.a().iterator();
|
|
-
|
|
if (true) {
|
|
DimensionManager dimensionmanager = worldserver.worldProvider.getDimensionManager();
|
|
ForcedChunk forcedchunk = (ForcedChunk) worldserver.getWorldPersistentData().b(ForcedChunk::new, "chunks");
|
|
--
|
|
2.22.0
|
|
|