2020-01-22 02:02:07 +00:00
From 51a8cb2552bb9d8bea3c784b46500428e0c9c86b Mon Sep 17 00:00:00 2001
2018-07-15 01:53:17 +00:00
From: Aikar <aikar@aikar.co>
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
2019-12-11 02:43:21 +00:00
index d500cd75a..e4f0db64c 100644
2018-07-15 01:53:17 +00:00
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
2019-05-06 07:20:16 +00:00
@@ -223,4 +223,9 @@ public class PaperConfig {
2018-07-15 01:53:17 +00:00
private static void regionFileCacheSize() {
2019-06-17 03:52:34 +00:00
regionFileCacheSize = Math.max(getInt("settings.region-file-cache-size", 256), 4);
2018-07-15 01:53:17 +00:00
}
+
+ 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
2020-01-22 02:02:07 +00:00
index 3094f763b..deffa2ddb 100644
2018-07-15 01:53:17 +00:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2020-01-22 02:02:07 +00:00
@@ -454,6 +454,20 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2019-05-06 02:58:04 +00:00
this.server.getPluginManager().callEvent(new org.bukkit.event.world.WorldLoadEvent(worldserver.getWorld()));
2019-04-27 03:05:36 +00:00
}
2018-07-15 01:53:17 +00:00
+ // Paper start - Handle collideRule team for player collision toggle
+ final Scoreboard scoreboard = this.getScoreboard();
+ final java.util.Collection<String> 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) {
2018-08-26 18:11:49 +00:00
+ this.getPlayerList().collideRuleTeamName = org.apache.commons.lang3.StringUtils.left("collideRule_" + java.util.concurrent.ThreadLocalRandom.current().nextInt(), 16);
2018-07-15 01:53:17 +00:00
+ 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
2019-04-27 03:05:36 +00:00
+
this.server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.POSTWORLD);
this.server.getPluginManager().callEvent(new ServerLoadEvent(ServerLoadEvent.LoadType.STARTUP));
2019-08-05 16:35:40 +00:00
this.serverConnection.acceptConnections();
2018-07-15 01:53:17 +00:00
diff --git a/src/main/java/net/minecraft/server/PacketPlayOutScoreboardTeam.java b/src/main/java/net/minecraft/server/PacketPlayOutScoreboardTeam.java
2019-12-11 02:43:21 +00:00
index b0740965a..6b1a914d2 100644
2018-07-15 01:53:17 +00:00
--- a/src/main/java/net/minecraft/server/PacketPlayOutScoreboardTeam.java
+++ b/src/main/java/net/minecraft/server/PacketPlayOutScoreboardTeam.java
2019-04-27 03:05:36 +00:00
@@ -96,7 +96,7 @@ public class PacketPlayOutScoreboardTeam implements Packet<PacketListenerPlayOut
2018-07-15 01:53:17 +00:00
packetdataserializer.a(this.b);
packetdataserializer.writeByte(this.j);
packetdataserializer.a(this.e);
- packetdataserializer.a(this.f);
+ packetdataserializer.a(!com.destroystokyo.paper.PaperConfig.enablePlayerCollisions ? "never" : this.f); // Paper
2019-01-01 03:15:55 +00:00
packetdataserializer.a((Enum) this.g);
2018-07-15 01:53:17 +00:00
packetdataserializer.a(this.c);
packetdataserializer.a(this.d);
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
2019-12-11 02:43:21 +00:00
index 94a24a49c..b7012b5b6 100644
2018-07-15 01:53:17 +00:00
--- a/src/main/java/net/minecraft/server/PlayerList.java
+++ b/src/main/java/net/minecraft/server/PlayerList.java
2019-04-27 03:05:36 +00:00
@@ -72,6 +72,7 @@ public abstract class PlayerList {
2018-07-15 01:53:17 +00:00
// CraftBukkit start
private CraftServer cserver;
2019-01-01 03:15:55 +00:00
private final Map<String,EntityPlayer> playersByName = new java.util.HashMap<>();
2018-07-15 01:53:17 +00:00
+ @Nullable String collideRuleTeamName; // Paper - Team name used for collideRule
2019-04-27 03:05:36 +00:00
public PlayerList(MinecraftServer minecraftserver, int i) {
this.cserver = minecraftserver.server = new CraftServer((DedicatedServer) minecraftserver, this);
2019-12-11 02:43:21 +00:00
@@ -287,6 +288,13 @@ public abstract class PlayerList {
2018-07-15 01:53:17 +00:00
}
entityplayer.syncInventory();
+ // Paper start - Add to collideRule team if needed
2018-08-26 18:11:49 +00:00
+ final Scoreboard scoreboard = this.getServer().getWorldServer(DimensionManager.OVERWORLD).getScoreboard();
2018-07-19 04:42:43 +00:00
+ final ScoreboardTeam collideRuleTeam = scoreboard.getTeam(collideRuleTeamName);
2018-12-17 05:18:06 +00:00
+ if (this.collideRuleTeamName != null && collideRuleTeam != null && entityplayer.getScoreboardTeam() == null) {
2018-07-19 04:42:43 +00:00
+ scoreboard.addPlayerToTeam(entityplayer.getName(), collideRuleTeam);
2018-07-15 01:53:17 +00:00
+ }
+ // Paper end
// CraftBukkit - Moved from above, added world
2019-12-11 02:43:21 +00:00
PlayerList.LOGGER.info("{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", entityplayer.getDisplayName().getString(), s1, entityplayer.getId(), entityplayer.world.worldData.getName(), entityplayer.locX(), entityplayer.locY(), entityplayer.locZ());
2018-07-15 01:53:17 +00:00
}
2019-12-11 02:43:21 +00:00
@@ -405,6 +413,16 @@ public abstract class PlayerList {
2018-07-15 01:53:17 +00:00
entityplayer.playerTick();// SPIGOT-924
// CraftBukkit end
+ // Paper start - Remove from collideRule team if needed
+ if (this.collideRuleTeamName != null) {
2018-08-26 18:11:49 +00:00
+ final Scoreboard scoreBoard = this.server.getWorldServer(DimensionManager.OVERWORLD).getScoreboard();
2018-07-15 01:53:17 +00:00
+ final ScoreboardTeam team = scoreBoard.getTeam(this.collideRuleTeamName);
2018-12-17 05:18:06 +00:00
+ if (entityplayer.getScoreboardTeam() == team && team != null) {
2018-07-15 01:53:17 +00:00
+ scoreBoard.removePlayerFromTeam(entityplayer.getName(), team);
+ }
+ }
+ // Paper end
+
this.savePlayerFile(entityplayer);
if (entityplayer.isPassenger()) {
Entity entity = entityplayer.getRootVehicle();
2019-12-11 02:43:21 +00:00
@@ -1029,6 +1047,13 @@ public abstract class PlayerList {
2018-07-15 01:53:17 +00:00
}
// CraftBukkit end
2019-12-11 02:43:21 +00:00
2018-07-15 01:53:17 +00:00
+ // Paper start - Remove collideRule team if it exists
+ if (this.collideRuleTeamName != null) {
2018-08-26 18:11:49 +00:00
+ final Scoreboard scoreboard = this.getServer().getWorldServer(DimensionManager.OVERWORLD).getScoreboard();
2018-07-15 01:53:17 +00:00
+ final ScoreboardTeam team = scoreboard.getTeam(this.collideRuleTeamName);
+ if (team != null) scoreboard.removeTeam(team);
+ }
+ // Paper end
}
// CraftBukkit start
--
2020-01-22 02:02:07 +00:00
2.25.0.windows.1
2018-07-15 01:53:17 +00:00