From f5f4102b6341f818aef3ccb79a0edc839174a2b8 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 ec4643384..430b5d0cd 100644 --- a/src/main/java/com/destroystokyo/paper/PaperConfig.java +++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java @@ -220,4 +220,9 @@ public class PaperConfig { private static void regionFileCacheSize() { regionFileCacheSize = getInt("settings.region-file-cache-size", 256); } + + public static boolean enablePlayerCollisions = true; + private static void enablePlayerCollisions() { + enablePlayerCollisions = getBoolean("settings.enable-player-collisions", true); + } } diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index b7aa9e869..c5670fe8d 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -379,6 +379,20 @@ public abstract class MinecraftServer implements IAsyncTaskHandler, IMojangStati this.a(this.getDifficulty()); this.g_(); + + // Paper start - Handle collideRule team for player collision toggle + final Scoreboard scoreboard = this.getScoreboard(); + final java.util.Collection 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_" + worlds.get(0).random.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 } protected void a(File file, WorldData worlddata) { diff --git a/src/main/java/net/minecraft/server/PacketPlayOutScoreboardTeam.java b/src/main/java/net/minecraft/server/PacketPlayOutScoreboardTeam.java index 5f54e7b9c..759288b97 100644 --- a/src/main/java/net/minecraft/server/PacketPlayOutScoreboardTeam.java +++ b/src/main/java/net/minecraft/server/PacketPlayOutScoreboardTeam.java @@ -94,7 +94,7 @@ public class PacketPlayOutScoreboardTeam implements Packet playersByName = new org.spigotmc.CaseInsensitiveMap(); + @Nullable String collideRuleTeamName; // Paper - Team name used for collideRule public PlayerList(MinecraftServer minecraftserver) { this.cserver = minecraftserver.server = new CraftServer(minecraftserver, this); @@ -231,6 +232,12 @@ public abstract class PlayerList { } entityplayer.syncInventory(); + // Paper start - Add to collideRule team if needed + final Scoreboard scoreboard = this.getServer().getWorld().getScoreboard(); + if (this.collideRuleTeamName != null && scoreboard.getTeam(collideRuleTeamName) != null && entityplayer.getTeam() == null) { + scoreboard.addPlayerToTeam(entityplayer.getName(), collideRuleTeamName); + } + // Paper end // CraftBukkit - Moved from above, added world PlayerList.f.info("{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", entityplayer.getDisplayName().getString(), s1, Integer.valueOf(entityplayer.getId()), entityplayer.world.worldData.getName(), Double.valueOf(entityplayer.locX), Double.valueOf(entityplayer.locY), Double.valueOf(entityplayer.locZ)); } @@ -423,6 +430,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.getWorld().getScoreboard(); + final ScoreboardTeam team = scoreBoard.getTeam(this.collideRuleTeamName); + if (entityplayer.getTeam() == team && team != null) { + scoreBoard.removePlayerFromTeam(entityplayer.getName(), team); + } + } + // Paper end + this.savePlayerFile(entityplayer); if (entityplayer.isPassenger()) { Entity entity = entityplayer.getRootVehicle(); @@ -1318,7 +1335,13 @@ public abstract class PlayerList { player.playerConnection.disconnect(this.server.server.getShutdownMessage()); // CraftBukkit - add custom shutdown message } // CraftBukkit end - + // Paper start - Remove collideRule team if it exists + if (this.collideRuleTeamName != null) { + final Scoreboard scoreboard = this.getServer().getWorld().getScoreboard(); + final ScoreboardTeam team = scoreboard.getTeam(this.collideRuleTeamName); + if (team != null) scoreboard.removeTeam(team); + } + // Paper end } // CraftBukkit start -- 2.18.0