From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Aikar Date: Wed, 13 Apr 2016 02:10:49 -0400 Subject: [PATCH] Configurable Player Collision diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java index 439dcc6effdc91830d2b7ede9063982998b37120..504efea7b6f50a0d17f4f353781953dfb18bdeca 100644 --- a/src/main/java/com/destroystokyo/paper/PaperConfig.java +++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java @@ -232,4 +232,9 @@ public class PaperConfig { private static void regionFileCacheSize() { regionFileCacheSize = Math.max(getInt("settings.region-file-cache-size", 256), 4); } + + public static boolean enablePlayerCollisions = true; + private static void enablePlayerCollisions() { + enablePlayerCollisions = getBoolean("settings.enable-player-collisions", true); + } } diff --git a/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutScoreboardTeam.java b/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutScoreboardTeam.java index bc40f2cbe1645fd60c4cee106b90f17cd043d32d..c1bb5c325286119891e8d68ce8f7328c99edb486 100644 --- a/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutScoreboardTeam.java +++ b/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutScoreboardTeam.java @@ -112,7 +112,7 @@ public class PacketPlayOutScoreboardTeam implements Packet toRemove = scoreboard.getTeams().stream().filter(team -> team.getName().startsWith("collideRule_")).map(ScoreboardTeam::getName).collect(java.util.stream.Collectors.toList()); + for (String teamName : toRemove) { + scoreboard.removeTeam(scoreboard.getTeam(teamName)); // Clean up after ourselves + } + + if (!com.destroystokyo.paper.PaperConfig.enablePlayerCollisions) { + this.getPlayerList().collideRuleTeamName = org.apache.commons.lang3.StringUtils.left("collideRule_" + java.util.concurrent.ThreadLocalRandom.current().nextInt(), 16); + ScoreboardTeam collideTeam = scoreboard.createTeam(this.getPlayerList().collideRuleTeamName); + collideTeam.setCanSeeFriendlyInvisibles(false); // Because we want to mimic them not being on a team at all + } + // Paper end + this.server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.POSTWORLD); this.server.getPluginManager().callEvent(new ServerLoadEvent(ServerLoadEvent.LoadType.STARTUP)); this.serverConnection.acceptConnections(); diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java index 152aa38788a21638aab7cfe2dc187671f1143bde..95ff827b1d5704d279d258bdfb43fd33ec7a9187 100644 --- a/src/main/java/net/minecraft/server/players/PlayerList.java +++ b/src/main/java/net/minecraft/server/players/PlayerList.java @@ -86,6 +86,7 @@ import net.minecraft.world.level.storage.SavedFile; import net.minecraft.world.level.storage.WorldData; import net.minecraft.world.level.storage.WorldNBTStorage; import net.minecraft.world.phys.Vec3D; +import net.minecraft.world.scores.Scoreboard; import net.minecraft.world.scores.ScoreboardObjective; import net.minecraft.world.scores.ScoreboardTeam; import net.minecraft.world.scores.ScoreboardTeamBase; @@ -145,6 +146,7 @@ public abstract class PlayerList { // CraftBukkit start private CraftServer cserver; private final Map playersByName = new java.util.HashMap<>(); + @Nullable String collideRuleTeamName; // Paper - Team name used for collideRule public PlayerList(MinecraftServer minecraftserver, IRegistryCustom.Dimension iregistrycustom_dimension, WorldNBTStorage worldnbtstorage, int i) { this.cserver = minecraftserver.server = new CraftServer((DedicatedServer) minecraftserver, this); @@ -376,6 +378,13 @@ public abstract class PlayerList { } entityplayer.syncInventory(); + // Paper start - Add to collideRule team if needed + final Scoreboard scoreboard = this.getServer().getWorldServer(World.OVERWORLD).getScoreboard(); + final ScoreboardTeam collideRuleTeam = scoreboard.getTeam(collideRuleTeamName); + if (this.collideRuleTeamName != null && collideRuleTeam != null && entityplayer.getScoreboardTeam() == null) { + scoreboard.addPlayerToTeam(entityplayer.getName(), collideRuleTeam); + } + // Paper end // CraftBukkit - Moved from above, added world PlayerList.LOGGER.info("{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", entityplayer.getDisplayName().getString(), s1, entityplayer.getId(), worldserver1.worldDataServer.getName(), entityplayer.locX(), entityplayer.locY(), entityplayer.locZ()); } @@ -496,6 +505,16 @@ public abstract class PlayerList { entityplayer.playerTick(); // SPIGOT-924 // CraftBukkit end + // Paper start - Remove from collideRule team if needed + if (this.collideRuleTeamName != null) { + final Scoreboard scoreBoard = this.server.getWorldServer(World.OVERWORLD).getScoreboard(); + final ScoreboardTeam team = scoreBoard.getTeam(this.collideRuleTeamName); + if (entityplayer.getScoreboardTeam() == team && team != null) { + scoreBoard.removePlayerFromTeam(entityplayer.getName(), team); + } + } + // Paper end + this.savePlayerFile(entityplayer); if (entityplayer.isPassenger()) { Entity entity = entityplayer.getRootVehicle(); @@ -1144,6 +1163,13 @@ public abstract class PlayerList { } // CraftBukkit end + // Paper start - Remove collideRule team if it exists + if (this.collideRuleTeamName != null) { + final Scoreboard scoreboard = this.getServer().getWorldServer(World.OVERWORLD).getScoreboard(); + final ScoreboardTeam team = scoreboard.getTeam(this.collideRuleTeamName); + if (team != null) scoreboard.removeTeam(team); + } + // Paper end } // CraftBukkit start