aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0088-Configurable-Player-Collision.patch
diff options
context:
space:
mode:
authorNassim Jahnke <[email protected]>2023-12-05 20:54:55 +0100
committerNassim Jahnke <[email protected]>2023-12-05 20:54:55 +0100
commit2efd9bb99f2fcefd99f04b85048373905d496581 (patch)
treeb8e635ac3bee13a7a839b3ce6a88c54248924164 /patches/server/0088-Configurable-Player-Collision.patch
parentd7fc0c5ab221ea38b4ae14b862c06cfac2fc0277 (diff)
downloadPaper-2efd9bb99f2fcefd99f04b85048373905d496581.tar.gz
Paper-2efd9bb99f2fcefd99f04b85048373905d496581.zip
More more more work
Diffstat (limited to 'patches/server/0088-Configurable-Player-Collision.patch')
-rw-r--r--patches/server/0088-Configurable-Player-Collision.patch109
1 files changed, 109 insertions, 0 deletions
diff --git a/patches/server/0088-Configurable-Player-Collision.patch b/patches/server/0088-Configurable-Player-Collision.patch
new file mode 100644
index 0000000000..090748be48
--- /dev/null
+++ b/patches/server/0088-Configurable-Player-Collision.patch
@@ -0,0 +1,109 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Aikar <[email protected]>
+Date: Wed, 13 Apr 2016 02:10:49 -0400
+Subject: [PATCH] Configurable Player Collision
+
+
+diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetPlayerTeamPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetPlayerTeamPacket.java
+index 3d2a689d11bfa230bab61a2a65c6051328f6b78d..e52644010dc2cf41bbf508b16b8ec2f0003e9d0b 100644
+--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetPlayerTeamPacket.java
++++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetPlayerTeamPacket.java
+@@ -193,7 +193,7 @@ public class ClientboundSetPlayerTeamPacket implements Packet<ClientGamePacketLi
+ buf.writeComponent(this.displayName);
+ buf.writeByte(this.options);
+ buf.writeUtf(this.nametagVisibility);
+- buf.writeUtf(this.collisionRule);
++ buf.writeUtf(!io.papermc.paper.configuration.GlobalConfiguration.get().collisions.enablePlayerCollisions ? "never" : this.collisionRule); // Paper
+ buf.writeEnum(this.color);
+ buf.writeComponent(this.playerPrefix);
+ buf.writeComponent(this.playerSuffix);
+diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
+index 3b13d7b760ac2df6e21c0ac7064fae8240866399..450a9336a8a39a4ace147c73f82f9281fb5cc787 100644
+--- a/src/main/java/net/minecraft/server/MinecraftServer.java
++++ b/src/main/java/net/minecraft/server/MinecraftServer.java
+@@ -621,6 +621,20 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
+ this.server.getPluginManager().callEvent(new org.bukkit.event.world.WorldLoadEvent(worldserver.getWorld()));
+ }
+
++ // Paper start - Handle collideRule team for player collision toggle
++ final ServerScoreboard scoreboard = this.getScoreboard();
++ final java.util.Collection<String> toRemove = scoreboard.getPlayerTeams().stream().filter(team -> team.getName().startsWith("collideRule_")).map(net.minecraft.world.scores.PlayerTeam::getName).collect(java.util.stream.Collectors.toList());
++ for (String teamName : toRemove) {
++ scoreboard.removePlayerTeam(scoreboard.getPlayerTeam(teamName)); // Clean up after ourselves
++ }
++
++ if (!io.papermc.paper.configuration.GlobalConfiguration.get().collisions.enablePlayerCollisions) {
++ this.getPlayerList().collideRuleTeamName = org.apache.commons.lang3.StringUtils.left("collideRule_" + java.util.concurrent.ThreadLocalRandom.current().nextInt(), 16);
++ net.minecraft.world.scores.PlayerTeam collideTeam = scoreboard.addPlayerTeam(this.getPlayerList().collideRuleTeamName);
++ collideTeam.setSeeFriendlyInvisibles(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.connection.acceptConnections();
+diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
+index b74689297ca20efee391fe1da80377082d1758e5..64be8c7b88b958a31ada6e8c7ef6fc368af2125e 100644
+--- a/src/main/java/net/minecraft/server/players/PlayerList.java
++++ b/src/main/java/net/minecraft/server/players/PlayerList.java
+@@ -100,6 +100,7 @@ import net.minecraft.world.phys.Vec3;
+ import net.minecraft.world.scores.DisplaySlot;
+ import net.minecraft.world.scores.Objective;
+ import net.minecraft.world.scores.PlayerTeam;
++import net.minecraft.world.scores.Team;
+ import org.slf4j.Logger;
+
+ // CraftBukkit start
+@@ -156,6 +157,7 @@ public abstract class PlayerList {
+ // CraftBukkit start
+ private CraftServer cserver;
+ private final Map<String,ServerPlayer> playersByName = new java.util.HashMap<>();
++ public @Nullable String collideRuleTeamName; // Paper - Team name used for collideRule
+
+ public PlayerList(MinecraftServer server, LayeredRegistryAccess<RegistryLayer> registryManager, PlayerDataStorage saveHandler, int maxPlayers) {
+ this.cserver = server.server = new CraftServer((DedicatedServer) server, this);
+@@ -398,6 +400,13 @@ public abstract class PlayerList {
+
+ player.initInventoryMenu();
+ // CraftBukkit - Moved from above, added world
++ // Paper start - Add to collideRule team if needed
++ final net.minecraft.world.scores.Scoreboard scoreboard = this.getServer().getLevel(Level.OVERWORLD).getScoreboard();
++ final PlayerTeam collideRuleTeam = scoreboard.getPlayerTeam(this.collideRuleTeamName);
++ if (this.collideRuleTeamName != null && collideRuleTeam != null && player.getTeam() == null) {
++ scoreboard.addPlayerToTeam(player.getScoreboardName(), collideRuleTeam);
++ }
++ // Paper end
+ PlayerList.LOGGER.info("{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", player.getName().getString(), s1, player.getId(), worldserver1.serverLevelData.getLevelName(), player.getX(), player.getY(), player.getZ());
+ }
+
+@@ -521,6 +530,16 @@ public abstract class PlayerList {
+ entityplayer.doTick(); // SPIGOT-924
+ // CraftBukkit end
+
++ // Paper start - Remove from collideRule team if needed
++ if (this.collideRuleTeamName != null) {
++ final net.minecraft.world.scores.Scoreboard scoreBoard = this.server.getLevel(Level.OVERWORLD).getScoreboard();
++ final PlayerTeam team = scoreBoard.getPlayersTeam(this.collideRuleTeamName);
++ if (entityplayer.getTeam() == team && team != null) {
++ scoreBoard.removePlayerFromTeam(entityplayer.getScoreboardName(), team);
++ }
++ }
++ // Paper end
++
+ this.save(entityplayer);
+ if (entityplayer.isPassenger()) {
+ Entity entity = entityplayer.getRootVehicle();
+@@ -1161,6 +1180,13 @@ public abstract class PlayerList {
+ }
+ // CraftBukkit end
+
++ // Paper start - Remove collideRule team if it exists
++ if (this.collideRuleTeamName != null) {
++ final Scoreboard scoreboard = this.getServer().getLevel(Level.OVERWORLD).getScoreboard();
++ final PlayerTeam team = scoreboard.getPlayersTeam(this.collideRuleTeamName);
++ if (team != null) scoreboard.removePlayerTeam(team);
++ }
++ // Paper end
+ }
+
+ // CraftBukkit start