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/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
2021-10-17 18:57:00 +02:00
index ad73dbb8e7112e2843c4104d367c98bf8b2b3370..f54096daee8c51a887b943ddd257ac2eae63952e 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
2021-11-09 08:59:15 +01:00
@@ -244,4 +244,9 @@ public class PaperConfig {
2021-06-11 14:02:28 +02:00
private static void regionFileCacheSize() {
regionFileCacheSize = Math.max(getInt("settings.region-file-cache-size", 256), 4);
}
+
+ public static boolean enablePlayerCollisions = true;
+ private static void enablePlayerCollisions() {
+ enablePlayerCollisions = getBoolean("settings.enable-player-collisions", true);
+ }
}
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetPlayerTeamPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetPlayerTeamPacket.java
2021-06-12 06:38:04 +02:00
index 8885220e4813b34627b42523834bbec995d8950d..4c9660176e783999301565790b8cf6f47b0d02a2 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
2021-06-12 06:38:04 +02:00
@@ -193,7 +193,7 @@ public class ClientboundSetPlayerTeamPacket implements Packet<ClientGamePacketLi
2021-06-11 14:02:28 +02:00
buf.writeComponent(this.displayName);
buf.writeByte(this.options);
buf.writeUtf(this.nametagVisibility);
- buf.writeUtf(this.collisionRule);
+ buf.writeUtf(!com.destroystokyo.paper.PaperConfig.enablePlayerCollisions ? "never" : this.collisionRule); // Paper
2021-06-12 06:38:04 +02:00
buf.writeEnum(this.color);
2021-06-11 14:02:28 +02:00
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
2021-11-09 08:59:15 +01:00
index d6195f7b0bac1bd1ababe8c4eec07654c323c014..4e7016c20a72271ff62fb676280d3880864919f1 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
2021-08-25 09:59:26 +02:00
@@ -161,6 +161,7 @@ import net.minecraft.world.level.storage.loot.LootTables;
2021-06-11 14:02:28 +02:00
import net.minecraft.world.level.storage.loot.PredicateManager;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
2021-06-12 06:38:04 +02:00
+import net.minecraft.world.scores.PlayerTeam; // Paper
2021-06-11 14:02:28 +02:00
import org.apache.commons.lang3.Validate;
2021-06-12 06:38:04 +02:00
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2021-11-09 08:59:15 +01:00
@@ -616,6 +617,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()));
}
+ // Paper start - Handle collideRule team for player collision toggle
2021-06-12 06:38:04 +02:00
+ final ServerScoreboard scoreboard = this.getScoreboard();
+ final java.util.Collection<String> toRemove = scoreboard.getPlayerTeams().stream().filter(team -> team.getName().startsWith("collideRule_")).map(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
+ }
+
+ if (!com.destroystokyo.paper.PaperConfig.enablePlayerCollisions) {
+ this.getPlayerList().collideRuleTeamName = org.apache.commons.lang3.StringUtils.left("collideRule_" + java.util.concurrent.ThreadLocalRandom.current().nextInt(), 16);
2021-06-12 06:38:04 +02:00
+ 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
+ }
+ // 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
2021-10-17 18:57:00 +02:00
index e2e20a33c8e434af6b3637f49181c530b32633c7..4b21d3d73d76b81377a1d2222f37074c75ac3753 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
2021-07-07 08:52:40 +02:00
@@ -87,6 +87,7 @@ import net.minecraft.world.level.storage.PlayerDataStorage;
2021-06-11 14:02:28 +02:00
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.scores.Objective;
import net.minecraft.world.scores.PlayerTeam;
2021-06-12 06:38:04 +02:00
+import net.minecraft.world.scores.Scoreboard; // Paper
2021-06-11 14:02:28 +02:00
import net.minecraft.world.scores.Team;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2021-07-07 08:52:40 +02:00
@@ -149,6 +150,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<>();
+ public @Nullable String collideRuleTeamName; // Paper - Team name used for collideRule
public PlayerList(MinecraftServer server, RegistryAccess.RegistryHolder registryManager, PlayerDataStorage saveHandler, int maxPlayers) {
this.cserver = server.server = new CraftServer((DedicatedServer) server, this);
2021-07-07 08:52:40 +02:00
@@ -385,6 +387,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
2021-06-11 14:02:28 +02:00
+ // Paper start - Add to collideRule team if needed
+ final 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);
+ }
+ // Paper end
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
2021-07-07 08:52:40 +02:00
@@ -504,6 +513,16 @@ public abstract class PlayerList {
2021-06-11 14:02:28 +02:00
entityplayer.doTick(); // SPIGOT-924
// CraftBukkit end
+ // Paper start - Remove from collideRule team if needed
+ if (this.collideRuleTeamName != null) {
+ final 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);
+ }
+ }
+ // Paper end
+
this.save(entityplayer);
if (entityplayer.isPassenger()) {
Entity entity = entityplayer.getRootVehicle();
2021-10-17 18:57:00 +02:00
@@ -1127,6 +1146,13 @@ public abstract class PlayerList {
2021-06-11 14:02:28 +02:00
}
// CraftBukkit end
+ // Paper start - Remove collideRule team if it exists
+ if (this.collideRuleTeamName != null) {
+ final 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
+ }
+ // Paper end
}
// CraftBukkit start