From 74a187be395185d190917a7e2e5f6b30f04ede53 Mon Sep 17 00:00:00 2001 From: Alfie Cleveland Date: Thu, 5 Oct 2017 10:25:54 +0100 Subject: [PATCH] Work to reduce the number of packets sent diff --git a/src/main/java/net/minecraft/server/EntityTrackerEntry.java b/src/main/java/net/minecraft/server/EntityTrackerEntry.java index 8e05bc923..7c44c064e 100644 --- a/src/main/java/net/minecraft/server/EntityTrackerEntry.java +++ b/src/main/java/net/minecraft/server/EntityTrackerEntry.java @@ -251,7 +251,11 @@ public class EntityTrackerEntry { this.j = this.tracker.motX; this.k = this.tracker.motY; this.l = this.tracker.motZ; - this.broadcast(new PacketPlayOutEntityVelocity(this.tracker.getId(), this.j, this.k, this.l)); + /* + if (this.tracker instanceof EntityArrow || this.tracker instanceof EntityProjectile) { + this.broadcast(new PacketPlayOutEntityVelocity(this.tracker.getId(), this.j, this.k, this.l)); + } + */ } } @@ -321,7 +325,11 @@ public class EntityTrackerEntry { } if (!cancelled) { - this.broadcastIncludingSelf((Packet) (new PacketPlayOutEntityVelocity(this.tracker))); + if (this.tracker instanceof EntityPlayer) { + ((EntityPlayer) this.tracker).playerConnection.sendPacket(new PacketPlayOutEntityVelocity(this.tracker)); + } else if (this.tracker instanceof EntityArrow || this.tracker instanceof EntityProjectile) { + // this.broadcast(new PacketPlayOutEntityVelocity(this.tracker)); + } } // CraftBukkit end @@ -435,26 +443,34 @@ public class EntityTrackerEntry { return; } } - - // entityplayer.removeQueue.remove(Integer.valueOf(this.tracker.getId())); // MineHQ + + // entityplayer.removeQueue.remove(Integer.valueOf(this.tracker.getId())); // + // MineHQ // CraftBukkit end - + this.trackedPlayers.add(entityplayer); Packet packet = this.c(); - + // Spigot start - protocol patch - if ( tracker instanceof EntityPlayer ) - { - entityplayer.playerConnection.sendPacket( PacketPlayOutPlayerInfo.addPlayer( (EntityPlayer) tracker ) ); - - if ( !entityplayer.getName().equals( entityplayer.listName ) && entityplayer.playerConnection.networkManager.getVersion() > 28 ) { // Spigot Update - 20140927a // Spigot Update - 20141001a - entityplayer.playerConnection.sendPacket( PacketPlayOutPlayerInfo.updateDisplayName( (EntityPlayer) this.tracker ) ); + // MineHQ start - tablist stuff + boolean isTarget18 = entityplayer.playerConnection.networkManager.getVersion() > 28; // MineHQ + boolean trackerInstanceOf = this.tracker instanceof EntityPlayer; + if (isTarget18) { + if (trackerInstanceOf) { + entityplayer.playerConnection.sendPacket(PacketPlayOutPlayerInfo.addPlayer((EntityPlayer) tracker)); + entityplayer.playerConnection.sendPacket(PacketPlayOutPlayerInfo.updateDisplayName((EntityPlayer) this.tracker)); + } + entityplayer.playerConnection.sendPacket(packet); + if (trackerInstanceOf && SpigotConfig.onlyCustomTab) entityplayer.playerConnection.sendPacket(PacketPlayOutPlayerInfo.removePlayer((EntityPlayer) tracker)); + } else { + if (tracker instanceof EntityPlayer && !SpigotConfig.onlyCustomTab) { entityplayer.playerConnection.sendPacket(PacketPlayOutPlayerInfo.addPlayer((EntityPlayer) tracker)); } + + entityplayer.playerConnection.sendPacket(packet); } + // MineHQ end // Spigot end - entityplayer.playerConnection.sendPacket(packet); - if (!this.tracker.getDataWatcher().d()) { // MineHQ start PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(this.tracker.getId(), this.tracker.getDataWatcher(), true); @@ -468,24 +484,6 @@ public class EntityTrackerEntry { } // MineHQ end - // MineHQ start - /* - if (this.tracker instanceof EntityLiving) { - AttributeMapServer attributemapserver = (AttributeMapServer) ((EntityLiving) this.tracker).getAttributeMap(); - Collection collection = attributemapserver.c(); - - // CraftBukkit start - If sending own attributes send scaled health instead of current maximum health - if (this.tracker.getId() == entityplayer.getId()) { - ((EntityPlayer) this.tracker).getBukkitEntity().injectScaledMaxHealth(collection, false); - } - // CraftBukkit end - if (!collection.isEmpty()) { - entityplayer.playerConnection.sendPacket(new PacketPlayOutUpdateAttributes(this.tracker.getId(), collection)); - } - } - */ - // MineHQ end - this.j = this.tracker.motX; this.k = this.tracker.motY; this.l = this.tracker.motZ; diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index 9abe8a94b..74ee10cf4 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -729,6 +729,7 @@ public abstract class MinecraftServer implements ICommandListener, Runnable, IMo // if (i == 0 || this.getAllowNether()) { WorldServer worldserver = this.worlds.get(i); + if (!worldserver.checkTicking()) continue; // MineHQ this.methodProfiler.a(worldserver.getWorldData().getName()); this.methodProfiler.a("pools"); diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java index fee969618..fc0507d6e 100644 --- a/src/main/java/net/minecraft/server/PlayerList.java +++ b/src/main/java/net/minecraft/server/PlayerList.java @@ -344,6 +344,8 @@ public abstract class PlayerList { } // CraftBukkit end + if (!SpigotConfig.playerListPackets) return; // MineHQ + // CraftBukkit start - sendAll above replaced with this loop PacketPlayOutPlayerInfo packet = PacketPlayOutPlayerInfo.addPlayer( entityplayer ); // Spigot - protocol patch PacketPlayOutPlayerInfo displayPacket = PacketPlayOutPlayerInfo.updateDisplayName( entityplayer ); // Spigot Update - 20140927a @@ -423,6 +425,7 @@ public abstract class PlayerList { EntityPlayer entityplayer1 = (EntityPlayer) this.players.get(i); if (entityplayer1.getBukkitEntity().canSee(entityplayer.getBukkitEntity())) { + if (!SpigotConfig.playerListPackets) continue; // MineHQ entityplayer1.playerConnection.sendPacket(packet); } else { entityplayer1.getBukkitEntity().removeDisconnectingPlayer(entityplayer.getBukkitEntity()); @@ -489,7 +492,6 @@ public abstract class PlayerList { public EntityPlayer processLogin(GameProfile gameprofile, EntityPlayer player) { // CraftBukkit - added EntityPlayer UUID uuid = EntityHuman.a(gameprofile); - ArrayList arraylist = Lists.newArrayList(); EntityPlayer entityplayer; @@ -920,11 +922,13 @@ public abstract class PlayerList { // Spigot start try { - if ( !players.isEmpty() ) + if ( !players.isEmpty() && SpigotConfig.updatePingOnTablist) { currentPing = ( currentPing + 1 ) % this.players.size(); EntityPlayer player = (EntityPlayer) this.players.get( currentPing ); - if ( player.lastPing == -1 || Math.abs( player.ping - player.lastPing ) > 20 ) + int oldPingToBars = pingToBars(player.lastPing); + int newPingToBars = pingToBars(player.ping); + if ( player.lastPing == -1 || oldPingToBars != newPingToBars ) { Packet packet = PacketPlayOutPlayerInfo.updatePing( player ); // Spigot - protocol patch for ( EntityPlayer splayer : (List) this.players ) @@ -943,6 +947,18 @@ public abstract class PlayerList { // Spigot end } + // MineHQ start + private int pingToBars(int ping) { + if (ping < 0) return 5; + else if (ping < 150) return 0; + else if (ping < 300) return 1; + else if (ping < 600) return 2; + else if (ping < 1_000) return 3; + else if (ping < Short.MAX_VALUE) return 4; + else return 5; + } + // MineHQ end + public void sendAll(Packet packet) { for (int i = 0; i < this.players.size(); ++i) { ((EntityPlayer) this.players.get(i)).playerConnection.sendPacket(packet); diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java index ef249eebd..6b76b4e77 100644 --- a/src/main/java/net/minecraft/server/WorldServer.java +++ b/src/main/java/net/minecraft/server/WorldServer.java @@ -12,7 +12,7 @@ import java.util.TreeSet; import net.minecraft.util.com.google.common.collect.Lists; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; - +import org.bukkit.Bukkit; // CraftBukkit start import org.bukkit.WeatherType; import org.bukkit.block.BlockState; @@ -45,6 +45,8 @@ public class WorldServer extends World { public List V = new ArrayList(); private IntHashMap entitiesById; + private boolean ticking = false; + // CraftBukkit start public final int dimension; @@ -78,6 +80,20 @@ public class WorldServer extends World { ((ScoreboardServer) this.scoreboard).a(persistentscoreboard); } + public boolean checkTicking() { + if (this.ticking && this.players.isEmpty()) { + this.ticking = false; + Bukkit.getLogger().info("Not ticking world " + this.getWorld().getName() + ". Unloading spawn..."); + this.keepSpawnInMemory = false; + } else if (!this.players.isEmpty() && !this.ticking) { + this.ticking = true; + Bukkit.getLogger().info("Ticking world " + this.getWorld().getName() + ". Loading spawn..."); + this.keepSpawnInMemory = true; + } + + return this.ticking; + } + // CraftBukkit start @Override public TileEntity getTileEntity(int i, int j, int k) { diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 2de043843..539d86b49 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -713,7 +713,7 @@ public class CraftWorld implements World { public List getPlayers() { List list = new ArrayList(); - for (Object o : world.entityList) { + for (Object o : world.players) { if (o instanceof net.minecraft.server.Entity) { net.minecraft.server.Entity mcEnt = (net.minecraft.server.Entity) o; Entity bukkitEntity = mcEnt.getBukkitEntity(); diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 0d66e7e1b..47aedf899 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -34,6 +34,7 @@ import org.bukkit.plugin.Plugin; import org.bukkit.plugin.messaging.StandardMessenger; import org.bukkit.scoreboard.Scoreboard; import org.bukkit.util.Vector; +import org.spigotmc.SpigotConfig; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -219,8 +220,8 @@ public class CraftPlayer extends CraftHumanEntity implements Player { EntityPlayer player = (EntityPlayer) playerObj; if (player.playerConnection != null) { - player.playerConnection.sendPacket(removeTabPacket); - player.playerConnection.sendPacket(addThisTabPacket); + if (SpigotConfig.playerListPackets) player.playerConnection.sendPacket(removeTabPacket); + if (SpigotConfig.playerListPackets || player.playerConnection.networkManager.getVersion() > 27) player.playerConnection.sendPacket(addThisTabPacket); } } @@ -233,6 +234,15 @@ public class CraftPlayer extends CraftHumanEntity implements Player { trackerEntry.broadcast(destroyPacket); trackerEntry.broadcast(spawnPacket); } + + PacketPlayOutPlayerInfo removeThisTabPacket = PacketPlayOutPlayerInfo.removePlayer(getHandle()); + for (Object playerObj : MinecraftServer.getServer().getPlayerList().players) { + EntityPlayer player = (EntityPlayer) playerObj; + + if (player.playerConnection != null) { + if (!SpigotConfig.playerListPackets && player.playerConnection.networkManager.getVersion() > 27) player.playerConnection.sendPacket(removeThisTabPacket); + } + } } @Override @@ -274,6 +284,14 @@ public class CraftPlayer extends CraftHumanEntity implements Player { trackerEntry.broadcast(destroyPacket); trackerEntry.broadcast(spawnPacket); } + + PacketPlayOutPlayerInfo removeThisTabPacket = PacketPlayOutPlayerInfo.removePlayer(getHandle()); + for (Object playerObj : MinecraftServer.getServer().getPlayerList().players) { + EntityPlayer player = (EntityPlayer) playerObj; + if (!SpigotConfig.playerListPackets) { + player.playerConnection.sendPacket(removeThisTabPacket); + } + } } // MineHQ end @@ -307,6 +325,8 @@ public class CraftPlayer extends CraftHumanEntity implements Player { getHandle().listName = name; + if (!SpigotConfig.playerListPackets) return; // MineHQ + // Change the name on the client side // Spigot start - protocol patch String temp = getHandle().listName; @@ -1067,7 +1087,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { entry.updatePlayer(getHandle()); } - getHandle().playerConnection.sendPacket(PacketPlayOutPlayerInfo.addPlayer( ( (CraftPlayer) player ).getHandle ())); // Spigot - protocol patch + // getHandle().playerConnection.sendPacket(PacketPlayOutPlayerInfo.addPlayer( ( (CraftPlayer) player ).getHandle ())); // Spigot - protocol patch // MineHQ - unneeded } public void removeDisconnectingPlayer(Player player) { diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java index 15f7bbb2c..bccf0c4b3 100644 --- a/src/main/java/org/spigotmc/SpigotConfig.java +++ b/src/main/java/org/spigotmc/SpigotConfig.java @@ -525,15 +525,24 @@ public class SpigotConfig private static void cacheChunkMaps() { cacheChunkMaps = getBoolean("settings.cache-chunk-maps", false); } + + public static boolean disableSaving; + private static void disableSaving() { + disableSaving = getBoolean("settings.disableSaving", false); + } + + public static boolean playerListPackets; + public static boolean updatePingOnTablist; + public static boolean onlyCustomTab; + private static void packets() { + onlyCustomTab = getBoolean("settings.only-custom-tab", false); + playerListPackets = !onlyCustomTab && !getBoolean("settings.disable.player-list-packets", false); + updatePingOnTablist = !onlyCustomTab && !getBoolean("settings.disable.ping-update-packets", false); + } // MineHQ end public static boolean reduceArmorDamage; private static void reduceArmorDamage() { reduceArmorDamage = getBoolean("settings.reduce-armor-damage", false); } - - public static boolean disableSaving; - private static void disableSaving() { - disableSaving = getBoolean("settings.disableSaving", false); - } } -- 2.13.5 (Apple Git-94)