From bf99953fa0cc34e8022079704eca427b7d01b7c9 Mon Sep 17 00:00:00 2001 From: Jake Potrebic <jake.m.potrebic@gmail.com> Date: Mon, 4 Jan 2021 19:49:15 -0800 Subject: [PATCH] fix converting txt to json file --- .../dedicated/DedicatedPlayerList.java.patch | 14 +++++ .../dedicated/DedicatedServer.java.patch | 40 +++++++------ .../server/players/PlayerList.java.patch | 57 ++++++++++--------- 3 files changed, 65 insertions(+), 46 deletions(-) create mode 100644 paper-server/patches/sources/net/minecraft/server/dedicated/DedicatedPlayerList.java.patch diff --git a/paper-server/patches/sources/net/minecraft/server/dedicated/DedicatedPlayerList.java.patch b/paper-server/patches/sources/net/minecraft/server/dedicated/DedicatedPlayerList.java.patch new file mode 100644 index 0000000000..17d45a61ee --- /dev/null +++ b/paper-server/patches/sources/net/minecraft/server/dedicated/DedicatedPlayerList.java.patch @@ -0,0 +1,14 @@ +--- a/net/minecraft/server/dedicated/DedicatedPlayerList.java ++++ b/net/minecraft/server/dedicated/DedicatedPlayerList.java +@@ -18,6 +18,11 @@ + this.setViewDistance(dedicatedServerProperties.viewDistance); + this.setSimulationDistance(dedicatedServerProperties.simulationDistance); + super.setUsingWhiteList(dedicatedServerProperties.whiteList.get()); ++ // Paper start - fix converting txt to json file; moved from constructor ++ } ++ @Override ++ public void loadAndSaveFiles() { ++ // Paper end - fix converting txt to json file + this.loadUserBanList(); + this.saveUserBanList(); + this.loadIpBanList(); diff --git a/paper-server/patches/sources/net/minecraft/server/dedicated/DedicatedServer.java.patch b/paper-server/patches/sources/net/minecraft/server/dedicated/DedicatedServer.java.patch index 27912d744c..c6f8e00d2f 100644 --- a/paper-server/patches/sources/net/minecraft/server/dedicated/DedicatedServer.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/dedicated/DedicatedServer.java.patch @@ -144,7 +144,7 @@ thread.setDaemon(true); thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(DedicatedServer.LOGGER)); thread.start(); -@@ -126,13 +203,27 @@ +@@ -126,13 +203,33 @@ this.setPreventProxyConnections(dedicatedserverproperties.preventProxyConnections); this.setLocalIp(dedicatedserverproperties.serverIp); } @@ -158,6 +158,12 @@ + this.paperConfigurations.initializeGlobalConfiguration(this.registryAccess()); + this.paperConfigurations.initializeWorldDefaultsConfiguration(this.registryAccess()); + // Paper end - initialize global and world-defaults configuration ++ // Paper start - fix converting txt to json file; convert old users earlier after PlayerList creation but before file load/save ++ if (this.convertOldUsers()) { ++ this.getProfileCache().save(false); // Paper ++ } ++ this.getPlayerList().loadAndSaveFiles(); // Must be after convertNames ++ // Paper end - fix converting txt to json file + org.spigotmc.WatchdogThread.doStart(org.spigotmc.SpigotConfig.timeoutTime, org.spigotmc.SpigotConfig.restartOnCrash); // Paper - start watchdog thread + io.papermc.paper.command.PaperCommands.registerCommands(this); // Paper - setup /paper command + com.destroystokyo.paper.Metrics.PaperMetrics.startMetrics(); // Paper - start metrics @@ -173,17 +179,16 @@ DedicatedServer.LOGGER.info("Default game type: {}", dedicatedserverproperties.gamemode); InetAddress inetaddress = null; -@@ -155,22 +246,35 @@ - DedicatedServer.LOGGER.warn("Perhaps a server is already running on that port?"); +@@ -156,21 +253,31 @@ return false; } -+ + + // CraftBukkit start + // this.setPlayerList(new DedicatedPlayerList(this, this.registries(), this.playerDataStorage)); // Spigot - moved up + this.server.loadPlugins(); + this.server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.STARTUP); + // CraftBukkit end - ++ if (!this.usesAuthentication()) { DedicatedServer.LOGGER.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!"); DedicatedServer.LOGGER.warn("The server will make no attempt to authenticate usernames. Beware."); @@ -199,10 +204,9 @@ DedicatedServer.LOGGER.warn("To change this, set \"online-mode\" to \"true\" in the server.properties file."); } - if (this.convertOldUsers()) { +- if (this.convertOldUsers()) { - this.getProfileCache().save(); -+ this.getProfileCache().save(false); // Paper - Perf: Async GameProfileCache saving - } +- } if (!OldUsersConverter.serverReadyAfterUserconversion(this)) { return false; @@ -212,7 +216,7 @@ this.debugSampleSubscriptionTracker = new DebugSampleSubscriptionTracker(this.getPlayerList()); this.tickTimeLogger = new RemoteSampleLogger(TpsDebugDimensions.values().length, this.debugSampleSubscriptionTracker, RemoteDebugSampleType.TICK_TIME); long i = Util.getNanos(); -@@ -178,13 +282,13 @@ +@@ -178,13 +285,13 @@ SkullBlockEntity.setup(this.services, this); GameProfileCache.setUsesAuthentication(this.usesAuthentication()); DedicatedServer.LOGGER.info("Preparing level \"{}\"", this.getLevelIdName()); @@ -228,7 +232,7 @@ } if (dedicatedserverproperties.enableQuery) { -@@ -197,7 +301,7 @@ +@@ -197,7 +304,7 @@ this.rconThread = RconThread.create(this); } @@ -237,7 +241,7 @@ Thread thread1 = new Thread(new ServerWatchdog(this)); thread1.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandlerWithName(DedicatedServer.LOGGER)); -@@ -215,6 +319,12 @@ +@@ -215,6 +322,12 @@ } } @@ -250,7 +254,7 @@ @Override public boolean isSpawningMonsters() { return this.settings.getProperties().spawnMonsters && super.isSpawningMonsters(); -@@ -227,7 +337,7 @@ +@@ -227,7 +340,7 @@ @Override public void forceDifficulty() { @@ -259,7 +263,7 @@ } @Override -@@ -286,13 +396,14 @@ +@@ -286,13 +399,14 @@ } if (this.rconThread != null) { @@ -276,7 +280,7 @@ } @Override -@@ -302,19 +413,29 @@ +@@ -302,19 +416,29 @@ } @Override @@ -312,7 +316,7 @@ } } -@@ -383,7 +504,7 @@ +@@ -383,7 +507,7 @@ @Override public boolean isUnderSpawnProtection(ServerLevel world, BlockPos pos, Player player) { @@ -321,7 +325,7 @@ return false; } else if (this.getPlayerList().getOps().isEmpty()) { return false; -@@ -453,7 +574,11 @@ +@@ -453,7 +577,11 @@ public boolean enforceSecureProfile() { DedicatedServerProperties dedicatedserverproperties = this.getProperties(); @@ -334,7 +338,7 @@ } @Override -@@ -541,16 +666,52 @@ +@@ -541,16 +669,52 @@ @Override public String getPluginNames() { @@ -391,7 +395,7 @@ } public void storeUsingWhiteList(boolean useWhitelist) { -@@ -660,4 +821,15 @@ +@@ -660,4 +824,15 @@ } } } diff --git a/paper-server/patches/sources/net/minecraft/server/players/PlayerList.java.patch b/paper-server/patches/sources/net/minecraft/server/players/PlayerList.java.patch index c934c70e87..f8c4e2f476 100644 --- a/paper-server/patches/sources/net/minecraft/server/players/PlayerList.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/players/PlayerList.java.patch @@ -63,7 +63,7 @@ public final PlayerDataStorage playerIo; private boolean doWhiteList; private final LayeredRegistryAccess<RegistryLayer> registries; -@@ -134,13 +156,24 @@ +@@ -134,58 +156,137 @@ private static final boolean ALLOW_LOGOUTIVATOR = false; private int sendAllPlayerInfoIn; @@ -90,8 +90,9 @@ this.server = server; this.registries = registryManager; this.maxPlayers = maxPlayers; -@@ -148,44 +181,111 @@ + this.playerIo = saveHandler; } ++ abstract public void loadAndSaveFiles(); // Paper - fix converting txt to json file; moved from DedicatedPlayerList constructor public void placeNewPlayer(Connection connection, ServerPlayer player, CommonListenerCookie clientData) { + player.isRealPlayer = true; // Paper @@ -211,7 +212,7 @@ ServerGamePacketListenerImpl playerconnection = new ServerGamePacketListenerImpl(this.server, connection, player, clientData); connection.setupInboundProtocol(GameProtocols.SERVERBOUND_TEMPLATE.bind(RegistryFriendlyByteBuf.decorator(this.server.registryAccess())), playerconnection); -@@ -194,7 +294,9 @@ +@@ -194,7 +295,9 @@ boolean flag1 = gamerules.getBoolean(GameRules.RULE_REDUCEDDEBUGINFO); boolean flag2 = gamerules.getBoolean(GameRules.RULE_LIMITED_CRAFTING); @@ -222,7 +223,7 @@ playerconnection.send(new ClientboundChangeDifficultyPacket(worlddata.getDifficulty(), worlddata.isDifficultyLocked())); playerconnection.send(new ClientboundPlayerAbilitiesPacket(player.getAbilities())); playerconnection.send(new ClientboundSetHeldSlotPacket(player.getInventory().selected)); -@@ -213,8 +315,10 @@ +@@ -213,8 +316,10 @@ } else { ichatmutablecomponent = Component.translatable("multiplayer.player.joined.renamed", player.getDisplayName(), s); } @@ -234,7 +235,7 @@ playerconnection.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot()); ServerStatus serverping = this.server.getStatus(); -@@ -222,17 +326,85 @@ +@@ -222,17 +327,85 @@ player.sendServerStatus(serverping); } @@ -325,7 +326,7 @@ } public void updateEntireScoreboard(ServerScoreboard scoreboard, ServerPlayer player) { -@@ -269,30 +441,31 @@ +@@ -269,30 +442,31 @@ } public void addWorldborderListener(ServerLevel world) { @@ -362,7 +363,7 @@ } @Override -@@ -319,14 +492,15 @@ +@@ -319,14 +493,15 @@ } protected void save(ServerPlayer player) { @@ -380,7 +381,7 @@ if (advancementdataplayer != null) { advancementdataplayer.save(); -@@ -334,95 +508,194 @@ +@@ -334,95 +509,194 @@ } @@ -571,13 +572,13 @@ + if (this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(gameprofile)) { + event.disallow(PlayerLoginEvent.Result.KICK_FULL, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(org.spigotmc.SpigotConfig.serverFullMessage)); // Spigot // Paper - Adventure + } - } ++ } + + this.cserver.getPluginManager().callEvent(event); + if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) { + loginlistener.disconnect(io.papermc.paper.adventure.PaperAdventure.asVanilla(event.kickMessage())); // Paper - Adventure + return null; -+ } + } + return entity; } @@ -613,7 +614,7 @@ if (entityplayer1 != null) { set.add(entityplayer1); -@@ -431,72 +704,160 @@ +@@ -431,72 +705,160 @@ Iterator iterator1 = set.iterator(); while (iterator1.hasNext()) { @@ -795,7 +796,7 @@ return entityplayer1; } -@@ -516,15 +877,32 @@ +@@ -516,15 +878,32 @@ } public void sendPlayerPermissionLevel(ServerPlayer player) { @@ -830,7 +831,7 @@ this.sendAllPlayerInfoIn = 0; } -@@ -541,6 +919,25 @@ +@@ -541,6 +920,25 @@ } @@ -856,7 +857,7 @@ public void broadcastAll(Packet<?> packet, ResourceKey<Level> dimension) { Iterator iterator = this.players.iterator(); -@@ -554,7 +951,7 @@ +@@ -554,7 +952,7 @@ } @@ -865,7 +866,7 @@ PlayerTeam scoreboardteam = source.getTeam(); if (scoreboardteam != null) { -@@ -573,7 +970,7 @@ +@@ -573,7 +971,7 @@ } } @@ -874,7 +875,7 @@ PlayerTeam scoreboardteam = source.getTeam(); if (scoreboardteam == null) { -@@ -619,7 +1016,7 @@ +@@ -619,7 +1017,7 @@ } public void deop(GameProfile profile) { @@ -883,7 +884,7 @@ ServerPlayer entityplayer = this.getPlayer(profile.getId()); if (entityplayer != null) { -@@ -629,6 +1026,11 @@ +@@ -629,6 +1027,11 @@ } private void sendPlayerPermissionLevel(ServerPlayer player, int permissionLevel) { @@ -895,7 +896,7 @@ if (player.connection != null) { byte b0; -@@ -643,36 +1045,53 @@ +@@ -643,36 +1046,53 @@ player.connection.send(new ClientboundEntityEventPacket(player, b0)); } @@ -962,7 +963,7 @@ if (entityplayer != player && entityplayer.level().dimension() == worldKey) { double d4 = x - entityplayer.getX(); double d5 = y - entityplayer.getY(); -@@ -687,10 +1106,12 @@ +@@ -687,10 +1107,12 @@ } public void saveAll() { @@ -975,7 +976,7 @@ } public UserWhiteList getWhiteList() { -@@ -712,15 +1133,19 @@ +@@ -712,15 +1134,19 @@ public void reloadWhiteList() {} public void sendLevelInfo(ServerPlayer player, ServerLevel world) { @@ -999,7 +1000,7 @@ } player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.LEVEL_CHUNKS_LOAD_START, 0.0F)); -@@ -729,8 +1154,16 @@ +@@ -729,8 +1155,16 @@ public void sendAllPlayerInfo(ServerPlayer player) { player.inventoryMenu.sendAllDataToRemote(); @@ -1017,7 +1018,7 @@ } public int getPlayerCount() { -@@ -746,6 +1179,7 @@ +@@ -746,6 +1180,7 @@ } public void setUsingWhiteList(boolean whitelistEnabled) { @@ -1025,7 +1026,7 @@ this.doWhiteList = whitelistEnabled; } -@@ -786,12 +1220,36 @@ +@@ -786,12 +1221,36 @@ } public void removeAll() { @@ -1064,7 +1065,7 @@ public void broadcastSystemMessage(Component message, boolean overlay) { this.broadcastSystemMessage(message, (entityplayer) -> { return message; -@@ -819,24 +1277,43 @@ +@@ -819,24 +1278,43 @@ } public void broadcastChatMessage(PlayerChatMessage message, ServerPlayer sender, ChatType.Bound params) { @@ -1111,7 +1112,7 @@ } if (flag1 && sender != null) { -@@ -845,20 +1322,27 @@ +@@ -845,20 +1323,27 @@ } @@ -1144,7 +1145,7 @@ Path path = file2.toPath(); if (FileUtil.isPathNormalized(path) && FileUtil.isPathPortable(path) && path.startsWith(file.getPath()) && file2.isFile()) { -@@ -867,7 +1351,7 @@ +@@ -867,7 +1352,7 @@ } serverstatisticmanager = new ServerStatsCounter(this.server, file1); @@ -1153,7 +1154,7 @@ } return serverstatisticmanager; -@@ -875,13 +1359,13 @@ +@@ -875,13 +1360,13 @@ public PlayerAdvancements getPlayerAdvancements(ServerPlayer player) { UUID uuid = player.getUUID(); @@ -1169,7 +1170,7 @@ } advancementdataplayer.setPlayer(player); -@@ -932,15 +1416,28 @@ +@@ -932,15 +1417,28 @@ } public void reloadResources() {