Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 04:20:04 +01:00
2641c02193
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 69fa4695 Add some missing deprecation annotations f850da2e Update Maven plugins/versions 8d8400db Use regular compiler seeing as ECJ doesn't support Java 21 JRE c29e1688 Revert "BUILDTOOLS-676: Downgrade Maven compiler version" 07bce714 SPIGOT-7355: More field renames and fixes 6a8ea764 Fix bad merge in penultimate commit 50a7920c Fix imports in previous commit 83640dd1 PR-995: Add required feature to MinecraftExperimental for easy lookups fc1f96cf BUILDTOOLS-676: Downgrade Maven compiler version CraftBukkit Changes: 90f1059ba Fix item placement 661afb43c SPIGOT-7633: Clearer error message for missing particle data 807b465b3 SPIGOT-7634: Armadillo updates infrequently 590cf09a8 Fix unit tests always seeing Mojang server as unavailable 7c7ac5eb2 SPIGOT-7636: Fix clearing ItemMeta 4a72905cf SPIGOT-7635: Fix Player#transfer and cookie methods ebb50e136 Fix incorrect Vault implementation b33fed8b7 Update Maven plugins/versions 6f00f0608 SPIGOT-7632: Control middle clicking chest does not copy contents db821f405 Use regular compiler seeing as ECJ doesn't support Java 21 JRE 8a2976737 Revert "BUILDTOOLS-676: Downgrade Maven compiler version" 0297f87bb SPIGOT-7355: More field renames and fixes 2d03bdf6a SPIGOT-7629: Fix loading banner patterns e77951fac Fix equality of deserialized display names c66f3e4fd SPIGOT-7631: Fix deserialisation of BlockStateMeta 9c2c7be8d SPIGOT-7630: Fix crash saving unticked leashed entities 8c1e7c841 PR-1384: Disable certain PlayerProfile tests, if Mojang's services or internet are not available ced93d572 SPIGOT-7626: sendSignChange() has no effect c77362cae SPIGOT-7625: ItemStack with lore cannot be serialized in 1.20.5 ff2004387 SPIGOT-7620: Fix server crash when hoppers transfer items to double chests 8b4abeb03 BUILDTOOLS-676: Downgrade Maven compiler version
160 Zeilen
10 KiB
Diff
160 Zeilen
10 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
Date: Sat, 15 May 2021 10:04:43 -0700
|
|
Subject: [PATCH] Expand PlayerGameModeChangeEvent
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/commands/DefaultGameModeCommands.java b/src/main/java/net/minecraft/server/commands/DefaultGameModeCommands.java
|
|
index b95a979f8f58f43e0becedcd843ff8bb992eb455..a046a0b1519806ff3d987e6402f152b60a3a6f4c 100644
|
|
--- a/src/main/java/net/minecraft/server/commands/DefaultGameModeCommands.java
|
|
+++ b/src/main/java/net/minecraft/server/commands/DefaultGameModeCommands.java
|
|
@@ -28,9 +28,13 @@ public class DefaultGameModeCommands {
|
|
GameType gameType = minecraftServer.getForcedGameType();
|
|
if (gameType != null) {
|
|
for (ServerPlayer serverPlayer : minecraftServer.getPlayerList().getPlayers()) {
|
|
- if (serverPlayer.setGameMode(gameType)) {
|
|
- i++;
|
|
+ // Paper start - Expand PlayerGameModeChangeEvent
|
|
+ org.bukkit.event.player.PlayerGameModeChangeEvent event = serverPlayer.setGameMode(gameType, org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.DEFAULT_GAMEMODE, net.kyori.adventure.text.Component.empty());
|
|
+ if (event != null && event.isCancelled()) {
|
|
+ source.sendSuccess(() -> io.papermc.paper.adventure.PaperAdventure.asVanilla(event.cancelMessage()), false);
|
|
}
|
|
+ // Paper end - Expand PlayerGameModeChangeEvent
|
|
+ i++;
|
|
}
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/commands/GameModeCommand.java b/src/main/java/net/minecraft/server/commands/GameModeCommand.java
|
|
index 7f09119bc7d661e08a960dd2bd46006efe752d3e..d1da3600dc07107309b20ebe6e7c0c4da0e8de76 100644
|
|
--- a/src/main/java/net/minecraft/server/commands/GameModeCommand.java
|
|
+++ b/src/main/java/net/minecraft/server/commands/GameModeCommand.java
|
|
@@ -60,9 +60,14 @@ public class GameModeCommand {
|
|
int i = 0;
|
|
|
|
for (ServerPlayer serverPlayer : targets) {
|
|
- if (serverPlayer.setGameMode(gameMode)) {
|
|
+ // Paper start - Expand PlayerGameModeChangeEvent
|
|
+ org.bukkit.event.player.PlayerGameModeChangeEvent event = serverPlayer.setGameMode(gameMode, org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.COMMAND, net.kyori.adventure.text.Component.empty());
|
|
+ if (event != null && !event.isCancelled()) {
|
|
logGamemodeChange(context.getSource(), serverPlayer, gameMode);
|
|
i++;
|
|
+ } else if (event != null && event.cancelMessage() != null) {
|
|
+ context.getSource().sendSuccess(() -> io.papermc.paper.adventure.PaperAdventure.asVanilla(event.cancelMessage()), true);
|
|
+ // Paper end - Expand PlayerGameModeChangeEvent
|
|
}
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
index 2db78d991ef0595a0d8806414a959479e289c0fc..50c6b668a8e915081007dfd9c9fc1aae179e16c9 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -2024,8 +2024,16 @@ public class ServerPlayer extends Player {
|
|
}
|
|
|
|
public boolean setGameMode(GameType gameMode) {
|
|
- if (!this.gameMode.changeGameModeForPlayer(gameMode)) {
|
|
- return false;
|
|
+ // Paper start - Expand PlayerGameModeChangeEvent
|
|
+ org.bukkit.event.player.PlayerGameModeChangeEvent event = this.setGameMode(gameMode, org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.UNKNOWN, null);
|
|
+ return event == null ? false : event.isCancelled();
|
|
+ }
|
|
+ @Nullable
|
|
+ public org.bukkit.event.player.PlayerGameModeChangeEvent setGameMode(GameType gameMode, org.bukkit.event.player.PlayerGameModeChangeEvent.Cause cause, @Nullable net.kyori.adventure.text.Component message) {
|
|
+ org.bukkit.event.player.PlayerGameModeChangeEvent event = this.gameMode.changeGameModeForPlayer(gameMode, cause, message);
|
|
+ if (event == null || event.isCancelled()) {
|
|
+ return null;
|
|
+ // Paper end - Expand PlayerGameModeChangeEvent
|
|
} else {
|
|
this.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.CHANGE_GAME_MODE, (float) gameMode.getId()));
|
|
if (gameMode == GameType.SPECTATOR) {
|
|
@@ -2037,7 +2045,7 @@ public class ServerPlayer extends Player {
|
|
|
|
this.onUpdateAbilities();
|
|
this.updateEffectVisibility();
|
|
- return true;
|
|
+ return event; // Paper - Expand PlayerGameModeChangeEvent
|
|
}
|
|
}
|
|
|
|
@@ -2447,6 +2455,16 @@ public class ServerPlayer extends Player {
|
|
}
|
|
|
|
public void loadGameTypes(@Nullable CompoundTag nbt) {
|
|
+ // Paper start - Expand PlayerGameModeChangeEvent
|
|
+ if (this.server.getForcedGameType() != null && this.server.getForcedGameType() != ServerPlayer.readPlayerMode(nbt, "playerGameType")) {
|
|
+ if (new org.bukkit.event.player.PlayerGameModeChangeEvent(this.getBukkitEntity(), org.bukkit.GameMode.getByValue(this.server.getDefaultGameType().getId()), org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.DEFAULT_GAMEMODE, null).callEvent()) {
|
|
+ this.gameMode.setGameModeForPlayer(this.server.getForcedGameType(), GameType.DEFAULT_MODE);
|
|
+ } else {
|
|
+ this.gameMode.setGameModeForPlayer(ServerPlayer.readPlayerMode(nbt,"playerGameType"), ServerPlayer.readPlayerMode(nbt, "previousPlayerGameType"));
|
|
+ }
|
|
+ return;
|
|
+ }
|
|
+ // Paper end - Expand PlayerGameModeChangeEvent
|
|
this.gameMode.setGameModeForPlayer(this.calculateGameModeForNewPlayer(ServerPlayer.readPlayerMode(nbt, "playerGameType")), ServerPlayer.readPlayerMode(nbt, "previousPlayerGameType"));
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
index 486d9c4dbe3ee23198eba7f34ea8b5f4e9048c0b..f080322bc766361b9d2d8b1214c3dff1c3df9ae8 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
@@ -72,14 +72,21 @@ public class ServerPlayerGameMode {
|
|
}
|
|
|
|
public boolean changeGameModeForPlayer(GameType gameMode) {
|
|
+ // Paper start - Expand PlayerGameModeChangeEvent
|
|
+ PlayerGameModeChangeEvent event = this.changeGameModeForPlayer(gameMode, org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.UNKNOWN, null);
|
|
+ return event != null && event.isCancelled();
|
|
+ }
|
|
+ @Nullable
|
|
+ public PlayerGameModeChangeEvent changeGameModeForPlayer(GameType gameMode, org.bukkit.event.player.PlayerGameModeChangeEvent.Cause cause, @Nullable net.kyori.adventure.text.Component cancelMessage) {
|
|
+ // Paper end - Expand PlayerGameModeChangeEvent
|
|
if (gameMode == this.gameModeForPlayer) {
|
|
- return false;
|
|
+ return null; // Paper - Expand PlayerGameModeChangeEvent
|
|
} else {
|
|
// CraftBukkit start
|
|
- PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this.player.getBukkitEntity(), GameMode.getByValue(gameMode.getId()));
|
|
+ PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this.player.getBukkitEntity(), GameMode.getByValue(gameMode.getId()), cause, cancelMessage); // Paper
|
|
this.level.getCraftServer().getPluginManager().callEvent(event);
|
|
if (event.isCancelled()) {
|
|
- return false;
|
|
+ return event; // Paper - Expand PlayerGameModeChangeEvent
|
|
}
|
|
// CraftBukkit end
|
|
this.setGameModeForPlayer(gameMode, this.previousGameModeForPlayer);
|
|
@@ -90,7 +97,7 @@ public class ServerPlayerGameMode {
|
|
this.player.resetCurrentImpulseContext();
|
|
}
|
|
|
|
- return true;
|
|
+ return event; // Paper - Expand PlayerGameModeChangeEvent
|
|
}
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
index f84a6f1ec9d1081b05ab44dd99659918aa0f1874..806f16a183ff1abae4cc21409bf8d26e0803483d 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -2719,7 +2719,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
|
|
|
this.player = this.server.getPlayerList().respawn(this.player, false, RespawnReason.DEATH);
|
|
if (this.server.isHardcore()) {
|
|
- this.player.setGameMode(GameType.SPECTATOR);
|
|
+ this.player.setGameMode(GameType.SPECTATOR, org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.HARDCORE_DEATH, null); // Paper - Expand PlayerGameModeChangeEvent
|
|
((GameRules.BooleanValue) this.player.level().getGameRules().getRule(GameRules.RULE_SPECTATORSGENERATECHUNKS)).set(false, this.player.serverLevel()); // CraftBukkit - per-world
|
|
}
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index d2443a4de68d9fea215c114ada8426f55d9dc8d5..45174db532a56534184c201767910beb511cbea4 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -1640,7 +1640,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
Preconditions.checkArgument(mode != null, "GameMode cannot be null");
|
|
if (this.getHandle().connection == null) return;
|
|
|
|
- this.getHandle().setGameMode(GameType.byId(mode.getValue()));
|
|
+ this.getHandle().setGameMode(GameType.byId(mode.getValue()), org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.PLUGIN, null); // Paper - Expand PlayerGameModeChangeEvent
|
|
}
|
|
|
|
@Override
|