2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 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/net/minecraft/network/protocol/game/ClientboundSetPlayerTeamPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetPlayerTeamPacket.java
2024-04-24 03:25:14 +02:00
index 9a1a961eabd4362c171da78c6be82c867f3696a4..1d0c473442b5c72245c356054440323e3c5d4711 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetPlayerTeamPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetPlayerTeamPacket.java
2024-04-24 03:25:14 +02:00
@@ -200,7 +200,7 @@ public class ClientboundSetPlayerTeamPacket implements Packet<ClientGamePacketLi
ComponentSerialization.TRUSTED_STREAM_CODEC.encode(buf, this.displayName);
2021-06-11 14:02:28 +02:00
buf.writeByte(this.options);
buf.writeUtf(this.nametagVisibility);
- buf.writeUtf(this.collisionRule);
2024-01-23 14:34:17 +01:00
+ buf.writeUtf(!io.papermc.paper.configuration.GlobalConfiguration.get().collisions.enablePlayerCollisions ? "never" : this.collisionRule); // Paper - Configurable player collision
2021-06-12 06:38:04 +02:00
buf.writeEnum(this.color);
2024-04-24 03:25:14 +02:00
ComponentSerialization.TRUSTED_STREAM_CODEC.encode(buf, this.playerPrefix);
ComponentSerialization.TRUSTED_STREAM_CODEC.encode(buf, this.playerSuffix);
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2024-04-24 03:25:14 +02:00
index d5b5eb914278fbd85921c039a8da3492dcbd6168..f46c8dd1ab752a88a3292f82720b27b250625982 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2024-04-24 03:25:14 +02:00
@@ -636,6 +636,20 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2021-06-11 14:02:28 +02:00
this.server.getPluginManager().callEvent(new org.bukkit.event.world.WorldLoadEvent(worldserver.getWorld()));
}
2024-01-23 14:34:17 +01:00
+ // Paper start - Configurable player collision; Handle collideRule team for player collision toggle
2021-06-12 06:38:04 +02:00
+ final ServerScoreboard scoreboard = this.getScoreboard();
2022-06-09 10:51:45 +02:00
+ 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());
2021-06-11 14:02:28 +02:00
+ for (String teamName : toRemove) {
2021-06-22 15:58:20 +02:00
+ scoreboard.removePlayerTeam(scoreboard.getPlayerTeam(teamName)); // Clean up after ourselves
2021-06-11 14:02:28 +02:00
+ }
+
2022-06-09 10:51:45 +02:00
+ if (!io.papermc.paper.configuration.GlobalConfiguration.get().collisions.enablePlayerCollisions) {
2021-06-11 14:02:28 +02:00
+ this.getPlayerList().collideRuleTeamName = org.apache.commons.lang3.StringUtils.left("collideRule_" + java.util.concurrent.ThreadLocalRandom.current().nextInt(), 16);
2022-06-09 10:51:45 +02:00
+ net.minecraft.world.scores.PlayerTeam collideTeam = scoreboard.addPlayerTeam(this.getPlayerList().collideRuleTeamName);
2021-06-11 14:02:28 +02:00
+ collideTeam.setSeeFriendlyInvisibles(false); // Because we want to mimic them not being on a team at all
+ }
2024-01-23 14:34:17 +01:00
+ // Paper end - Configurable player collision
2021-06-11 14:02:28 +02:00
+
this.server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.POSTWORLD);
this.server.getPluginManager().callEvent(new ServerLoadEvent(ServerLoadEvent.LoadType.STARTUP));
2024-04-24 03:25:14 +02:00
if (io.papermc.paper.plugin.PluginInitializerManager.instance().pluginRemapper != null) io.papermc.paper.plugin.PluginInitializerManager.instance().pluginRemapper.pluginsEnabled(); // Paper - Remap plugins
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
2024-04-24 03:25:14 +02:00
index 8f3bcb7183ed09e9c2a16e26b5b3ac125aa57d90..fa85bf581ff2ff8de50355c3b5bf74d38ef9ffc1 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
2024-04-24 03:25:14 +02:00
@@ -159,6 +159,7 @@ public abstract class PlayerList {
2021-06-11 14:02:28 +02:00
// CraftBukkit start
private CraftServer cserver;
private final Map<String,ServerPlayer> playersByName = new java.util.HashMap<>();
2024-01-23 14:34:17 +01:00
+ public @Nullable String collideRuleTeamName; // Paper - Configurable player collision
2021-06-11 14:02:28 +02:00
2022-12-07 19:52:24 +01:00
public PlayerList(MinecraftServer server, LayeredRegistryAccess<RegistryLayer> registryManager, PlayerDataStorage saveHandler, int maxPlayers) {
2021-06-11 14:02:28 +02:00
this.cserver = server.server = new CraftServer((DedicatedServer) server, this);
2024-04-24 03:25:14 +02:00
@@ -397,6 +398,13 @@ public abstract class PlayerList {
2021-06-11 14:02:28 +02:00
2021-06-12 06:38:04 +02:00
player.initInventoryMenu();
// CraftBukkit - Moved from above, added world
2024-01-23 14:34:17 +01:00
+ // Paper start - Configurable player collision; Add to collideRule team if needed
2023-12-05 20:54:55 +01:00
+ final net.minecraft.world.scores.Scoreboard scoreboard = this.getServer().getLevel(Level.OVERWORLD).getScoreboard();
2021-06-28 23:16:46 +02:00
+ final PlayerTeam collideRuleTeam = scoreboard.getPlayerTeam(this.collideRuleTeamName);
2021-06-11 14:02:28 +02:00
+ if (this.collideRuleTeamName != null && collideRuleTeam != null && player.getTeam() == null) {
+ scoreboard.addPlayerToTeam(player.getScoreboardName(), collideRuleTeam);
+ }
2024-01-23 14:34:17 +01:00
+ // Paper end - Configurable player collision
2021-06-12 06:38:04 +02:00
PlayerList.LOGGER.info("{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", player.getName().getString(), s1, player.getId(), worldserver1.serverLevelData.getLevelName(), player.getX(), player.getY(), player.getZ());
2021-06-11 14:02:28 +02:00
}
2021-06-12 06:38:04 +02:00
2024-04-24 03:25:14 +02:00
@@ -519,6 +527,16 @@ public abstract class PlayerList {
2021-06-11 14:02:28 +02:00
entityplayer.doTick(); // SPIGOT-924
// CraftBukkit end
2024-01-23 14:34:17 +01:00
+ // Paper start - Configurable player collision; Remove from collideRule team if needed
2021-06-11 14:02:28 +02:00
+ if (this.collideRuleTeamName != null) {
2023-12-05 20:54:55 +01:00
+ final net.minecraft.world.scores.Scoreboard scoreBoard = this.server.getLevel(Level.OVERWORLD).getScoreboard();
2021-06-12 06:38:04 +02:00
+ final PlayerTeam team = scoreBoard.getPlayersTeam(this.collideRuleTeamName);
2021-06-11 14:02:28 +02:00
+ if (entityplayer.getTeam() == team && team != null) {
+ scoreBoard.removePlayerFromTeam(entityplayer.getScoreboardName(), team);
+ }
+ }
2024-01-23 14:34:17 +01:00
+ // Paper end - Configurable player collision
2021-06-11 14:02:28 +02:00
+
this.save(entityplayer);
if (entityplayer.isPassenger()) {
Entity entity = entityplayer.getRootVehicle();
2024-04-24 03:25:14 +02:00
@@ -1160,6 +1178,13 @@ public abstract class PlayerList {
2021-06-11 14:02:28 +02:00
}
// CraftBukkit end
2024-01-23 14:34:17 +01:00
+ // Paper start - Configurable player collision; Remove collideRule team if it exists
2021-06-11 14:02:28 +02:00
+ if (this.collideRuleTeamName != null) {
2023-12-06 20:40:37 +01:00
+ final net.minecraft.world.scores.Scoreboard scoreboard = this.getServer().getLevel(Level.OVERWORLD).getScoreboard();
2021-06-12 06:38:04 +02:00
+ final PlayerTeam team = scoreboard.getPlayersTeam(this.collideRuleTeamName);
+ if (team != null) scoreboard.removePlayerTeam(team);
2021-06-11 14:02:28 +02:00
+ }
2024-01-23 14:34:17 +01:00
+ // Paper end - Configurable player collision
2021-06-11 14:02:28 +02:00
}
// CraftBukkit start