2018-09-08 05:49:37 +02:00
From 195aa61857efd8a86fbf6826cdba5eefc31f3d6f Mon Sep 17 00:00:00 2001
2018-07-15 03:53:17 +02: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
2018-08-06 01:46:43 +02:00
index a6042ca607..9fe1311143 100644
2018-07-15 03:53:17 +02:00
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
2018-07-24 02:24:44 +02:00
@@ -224,4 +224,9 @@ public class PaperConfig {
2018-07-15 03:53:17 +02:00
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
2018-09-08 05:49:37 +02:00
index 280e684db4..9675d5a100 100644
2018-07-15 03:53:17 +02:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2018-09-08 05:49:37 +02:00
@@ -425,6 +425,19 @@ public abstract class MinecraftServer implements IAsyncTaskHandler, IMojangStati
2018-08-26 20:11:49 +02:00
this.a(this.getWorldServer(DimensionManager.OVERWORLD).worldMaps);
// CraftBukkit end
2018-07-15 03:53:17 +02: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 20:11:49 +02:00
+ this.getPlayerList().collideRuleTeamName = org.apache.commons.lang3.StringUtils.left("collideRule_" + java.util.concurrent.ThreadLocalRandom.current().nextInt(), 16);
2018-07-15 03:53:17 +02: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
}
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
2018-09-01 00:56:57 +02:00
index f7a9b9d885..7befd80cf5 100644
2018-07-15 03:53:17 +02:00
--- a/src/main/java/net/minecraft/server/PacketPlayOutScoreboardTeam.java
+++ b/src/main/java/net/minecraft/server/PacketPlayOutScoreboardTeam.java
2018-09-01 00:56:57 +02:00
@@ -92,7 +92,7 @@ public class PacketPlayOutScoreboardTeam implements Packet<PacketListenerPlayOut
2018-07-15 03:53:17 +02: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
2018-09-01 00:56:57 +02:00
packetdataserializer.a((Enum)this.g);
2018-07-15 03:53:17 +02: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
2018-08-26 20:11:49 +02:00
index 8121f8e40a..02dbb8c6c3 100644
2018-07-15 03:53:17 +02:00
--- a/src/main/java/net/minecraft/server/PlayerList.java
+++ b/src/main/java/net/minecraft/server/PlayerList.java
@@ -74,6 +74,7 @@ public abstract class PlayerList {
// CraftBukkit start
private CraftServer cserver;
private final Map<String,EntityPlayer> playersByName = new org.spigotmc.CaseInsensitiveMap<EntityPlayer>();
+ @Nullable String collideRuleTeamName; // Paper - Team name used for collideRule
public PlayerList(MinecraftServer minecraftserver) {
this.cserver = minecraftserver.server = new CraftServer(minecraftserver, this);
2018-07-19 06:42:43 +02:00
@@ -231,6 +232,13 @@ public abstract class PlayerList {
2018-07-15 03:53:17 +02:00
}
entityplayer.syncInventory();
+ // Paper start - Add to collideRule team if needed
2018-08-26 20:11:49 +02:00
+ final Scoreboard scoreboard = this.getServer().getWorldServer(DimensionManager.OVERWORLD).getScoreboard();
2018-07-19 06:42:43 +02:00
+ final ScoreboardTeam collideRuleTeam = scoreboard.getTeam(collideRuleTeamName);
+ if (this.collideRuleTeamName != null && collideRuleTeam != null && entityplayer.getTeam() == null) {
+ scoreboard.addPlayerToTeam(entityplayer.getName(), collideRuleTeam);
2018-07-15 03:53:17 +02:00
+ }
+ // 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));
}
2018-07-19 06:42:43 +02:00
@@ -423,6 +431,16 @@ public abstract class PlayerList {
2018-07-15 03:53:17 +02:00
entityplayer.playerTick();// SPIGOT-924
// CraftBukkit end
+ // Paper start - Remove from collideRule team if needed
+ if (this.collideRuleTeamName != null) {
2018-08-26 20:11:49 +02:00
+ final Scoreboard scoreBoard = this.server.getWorldServer(DimensionManager.OVERWORLD).getScoreboard();
2018-07-15 03:53:17 +02:00
+ 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();
2018-08-26 20:11:49 +02:00
@@ -1305,7 +1323,13 @@ public abstract class PlayerList {
2018-07-15 03:53:17 +02:00
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) {
2018-08-26 20:11:49 +02:00
+ final Scoreboard scoreboard = this.getServer().getWorldServer(DimensionManager.OVERWORLD).getScoreboard();
2018-07-15 03:53:17 +02:00
+ final ScoreboardTeam team = scoreboard.getTeam(this.collideRuleTeamName);
+ if (team != null) scoreboard.removeTeam(team);
+ }
+ // Paper end
}
// CraftBukkit start
--
2.18.0