aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0102-Configurable-Player-Collision.patch
blob: 083cbcaeeaa4f0a71aae4fa17591e142f57a52e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
From 52851c88a5df872998f8f90dbe63f63e0fc9d504 Mon Sep 17 00:00:00 2001
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
index 0778f53e2..30fcf4a72 100644
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
@@ -233,4 +233,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 e53e25626..6841fc2bd 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -421,6 +421,19 @@ public abstract class MinecraftServer implements IAsyncTaskHandler, IMojangStati
         this.a(this.getWorldServer(DimensionManager.OVERWORLD).worldMaps);
         // CraftBukkit end
 
+        // 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) {
+            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
     }
 
     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 a6aed2531..575e3762b 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<PacketListenerPlayOut
             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
             packetdataserializer.a((Enum) this.g);
             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
index 523694899..79641a73a 100644
--- a/src/main/java/net/minecraft/server/PlayerList.java
+++ b/src/main/java/net/minecraft/server/PlayerList.java
@@ -73,6 +73,7 @@ public abstract class PlayerList {
     // CraftBukkit start
     private CraftServer cserver;
     private final Map<String,EntityPlayer> playersByName = new java.util.HashMap<>();
+    @Nullable String collideRuleTeamName; // Paper - Team name used for collideRule
 
     public PlayerList(MinecraftServer minecraftserver) {
         this.cserver = minecraftserver.server = new CraftServer(minecraftserver, this);
@@ -230,6 +231,13 @@ public abstract class PlayerList {
         }
 
         entityplayer.syncInventory();
+        // Paper start - Add to collideRule team if needed
+        final Scoreboard scoreboard = this.getServer().getWorldServer(DimensionManager.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.f.info("{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", entityplayer.getDisplayName().getString(), s1, entityplayer.getId(), entityplayer.world.worldData.getName(), entityplayer.locX, entityplayer.locY, entityplayer.locZ);
     }
@@ -423,6 +431,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(DimensionManager.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();
@@ -1309,7 +1327,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().getWorldServer(DimensionManager.OVERWORLD).getScoreboard();
+            final ScoreboardTeam team = scoreboard.getTeam(this.collideRuleTeamName);
+            if (team != null) scoreboard.removeTeam(team);
+        }
+        // Paper end
     }
 
     // CraftBukkit start
-- 
2.20.1