2020-05-06 09:48:49 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2018-07-15 01:53:17 +00: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
2021-02-26 17:54:48 +00:00
index 439dcc6effdc91830d2b7ede9063982998b37120..504efea7b6f50a0d17f4f353781953dfb18bdeca 100644
2018-07-15 01:53:17 +00:00
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
2021-02-26 17:54:48 +00:00
@@ -232,4 +232,9 @@ public class PaperConfig {
2018-07-15 01:53:17 +00:00
private static void regionFileCacheSize() {
2019-06-17 03:52:34 +00:00
regionFileCacheSize = Math.max(getInt("settings.region-file-cache-size", 256), 4);
2018-07-15 01:53:17 +00:00
}
+
+ public static boolean enablePlayerCollisions = true;
+ private static void enablePlayerCollisions() {
+ enablePlayerCollisions = getBoolean("settings.enable-player-collisions", true);
+ }
}
2021-03-16 07:19:45 +00:00
diff --git a/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutScoreboardTeam.java b/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutScoreboardTeam.java
index bc40f2cbe1645fd60c4cee106b90f17cd043d32d..c1bb5c325286119891e8d68ce8f7328c99edb486 100644
--- a/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutScoreboardTeam.java
+++ b/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutScoreboardTeam.java
@@ -112,7 +112,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);
2018-07-15 01:53:17 +00:00
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2021-04-16 00:47:34 +00:00
index 33139f9dc6a9c6030f565b01c9b6fd411cafa710..026ddfba26439a00685f3962084aa6194086c9b7 100644
2018-07-15 01:53:17 +00:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2021-03-16 15:50:45 +00:00
@@ -151,6 +151,7 @@ import net.minecraft.world.phys.Vec2F;
import net.minecraft.world.phys.Vec3D;
import net.minecraft.world.scores.PersistentScoreboard;
import net.minecraft.world.scores.Scoreboard;
+import net.minecraft.world.scores.ScoreboardTeam;
import org.apache.commons.lang3.Validate;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2021-04-16 00:47:34 +00:00
@@ -552,6 +553,20 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2019-05-06 02:58:04 +00:00
this.server.getPluginManager().callEvent(new org.bukkit.event.world.WorldLoadEvent(worldserver.getWorld()));
2019-04-27 03:05:36 +00:00
}
2018-07-15 01:53:17 +00: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 18:11:49 +00:00
+ this.getPlayerList().collideRuleTeamName = org.apache.commons.lang3.StringUtils.left("collideRule_" + java.util.concurrent.ThreadLocalRandom.current().nextInt(), 16);
2018-07-15 01:53:17 +00: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
2019-04-27 03:05:36 +00:00
+
this.server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.POSTWORLD);
this.server.getPluginManager().callEvent(new ServerLoadEvent(ServerLoadEvent.LoadType.STARTUP));
2019-08-05 16:35:40 +00:00
this.serverConnection.acceptConnections();
2021-03-16 07:19:45 +00:00
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
2021-03-16 15:50:45 +00:00
index 152aa38788a21638aab7cfe2dc187671f1143bde..f9e9e51b0b0dcbf2a8424c7c14bd2cbb0d899e82 100644
2021-03-16 07:19:45 +00:00
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
2021-03-16 13:04:28 +00:00
@@ -86,6 +86,7 @@ import net.minecraft.world.level.storage.SavedFile;
import net.minecraft.world.level.storage.WorldData;
import net.minecraft.world.level.storage.WorldNBTStorage;
import net.minecraft.world.phys.Vec3D;
+import net.minecraft.world.scores.Scoreboard;
import net.minecraft.world.scores.ScoreboardObjective;
import net.minecraft.world.scores.ScoreboardTeam;
import net.minecraft.world.scores.ScoreboardTeamBase;
@@ -145,6 +146,7 @@ public abstract class PlayerList {
2018-07-15 01:53:17 +00:00
// CraftBukkit start
private CraftServer cserver;
2019-01-01 03:15:55 +00:00
private final Map<String,EntityPlayer> playersByName = new java.util.HashMap<>();
2021-03-16 15:50:45 +00:00
+ public @Nullable String collideRuleTeamName; // Paper - Team name used for collideRule
2018-07-15 01:53:17 +00:00
2020-06-25 11:00:35 +00:00
public PlayerList(MinecraftServer minecraftserver, IRegistryCustom.Dimension iregistrycustom_dimension, WorldNBTStorage worldnbtstorage, int i) {
2019-04-27 03:05:36 +00:00
this.cserver = minecraftserver.server = new CraftServer((DedicatedServer) minecraftserver, this);
2021-03-16 13:04:28 +00:00
@@ -376,6 +378,13 @@ public abstract class PlayerList {
2018-07-15 01:53:17 +00:00
}
entityplayer.syncInventory();
+ // Paper start - Add to collideRule team if needed
2020-06-26 12:04:38 +00:00
+ final Scoreboard scoreboard = this.getServer().getWorldServer(World.OVERWORLD).getScoreboard();
2018-07-19 04:42:43 +00:00
+ final ScoreboardTeam collideRuleTeam = scoreboard.getTeam(collideRuleTeamName);
2018-12-17 05:18:06 +00:00
+ if (this.collideRuleTeamName != null && collideRuleTeam != null && entityplayer.getScoreboardTeam() == null) {
2018-07-19 04:42:43 +00:00
+ scoreboard.addPlayerToTeam(entityplayer.getName(), collideRuleTeam);
2018-07-15 01:53:17 +00:00
+ }
+ // Paper end
// CraftBukkit - Moved from above, added world
2020-06-25 11:00:35 +00:00
PlayerList.LOGGER.info("{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", entityplayer.getDisplayName().getString(), s1, entityplayer.getId(), worldserver1.worldDataServer.getName(), entityplayer.locX(), entityplayer.locY(), entityplayer.locZ());
2018-07-15 01:53:17 +00:00
}
2021-03-16 13:04:28 +00:00
@@ -496,6 +505,16 @@ public abstract class PlayerList {
2020-06-24 00:25:28 +00:00
entityplayer.playerTick(); // SPIGOT-924
2018-07-15 01:53:17 +00:00
// CraftBukkit end
+ // Paper start - Remove from collideRule team if needed
+ if (this.collideRuleTeamName != null) {
2020-06-26 12:04:38 +00:00
+ final Scoreboard scoreBoard = this.server.getWorldServer(World.OVERWORLD).getScoreboard();
2018-07-15 01:53:17 +00:00
+ final ScoreboardTeam team = scoreBoard.getTeam(this.collideRuleTeamName);
2018-12-17 05:18:06 +00:00
+ if (entityplayer.getScoreboardTeam() == team && team != null) {
2018-07-15 01:53:17 +00:00
+ scoreBoard.removePlayerFromTeam(entityplayer.getName(), team);
+ }
+ }
+ // Paper end
+
this.savePlayerFile(entityplayer);
if (entityplayer.isPassenger()) {
Entity entity = entityplayer.getRootVehicle();
2021-03-16 13:04:28 +00:00
@@ -1144,6 +1163,13 @@ public abstract class PlayerList {
2018-07-15 01:53:17 +00:00
}
// CraftBukkit end
2019-12-11 02:43:21 +00:00
2018-07-15 01:53:17 +00:00
+ // Paper start - Remove collideRule team if it exists
+ if (this.collideRuleTeamName != null) {
2020-06-26 12:04:38 +00:00
+ final Scoreboard scoreboard = this.getServer().getWorldServer(World.OVERWORLD).getScoreboard();
2018-07-15 01:53:17 +00:00
+ final ScoreboardTeam team = scoreboard.getTeam(this.collideRuleTeamName);
+ if (team != null) scoreboard.removeTeam(team);
+ }
+ // Paper end
}
// CraftBukkit start