mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-25 12:05:53 +01:00
d1a72eac31
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: 1fc1020a PR-1049: Add MenuType API 8ae2e3be PR-1055: Expand riptiding API cac68bfb SPIGOT-7890: AttributeModifier#getUniqueId() doesn't match the UUID passed to its constructor 7004fcf2 SPIGOT-7886: Fix mistake in AttributeModifier UUID shim 1ac7f950 PR-1054: Add FireworkMeta#hasPower 4cfb565f SPIGOT-7873: Add powered state for skulls CraftBukkit Changes: bbb30e7a8 SPIGOT-7894: NPE when sending tile entity update ba21e9472 SPIGOT-7895: PlayerItemBreakEvent not firing 0fb24bbe0 SPIGOT-7875: Fix PlayerItemConsumeEvent cancellation causing client-side desync 815066449 SPIGOT-7891: Can't remove second ingredient of MerchantRecipe 45c206f2c PR-1458: Add MenuType API 19c8ef9ae SPIGOT-7867: Merchant instanceof AbstractVillager always returns false 4e006d28f PR-1468: Expand riptiding API bd8aded7d Ignore checks in CraftPlayerProfile for ResolvableProfile used in profile components 8679620b5 SPIGOT-7889: Fix tool component deserialisation without speed and/or correct-for-drops 8d5222691 SPIGOT-7882, PR-1467: Fix conversion of name in Profile Component to empty if it is missing 63f91669a SPIGOT-7887: Remove duplicate ProjectileHitEvent for fireballs 7070de8c8 SPIGOT-7878: Server#getLootTable does not return null on invalid loot table 060ee6cae SPIGOT-7876: Can't kick player or disconnect player in PlayerLoginEvent when checking for cookies 7ccb86cc0 PR-1465: Add FireworkMeta#hasPower 804ad6491 SPIGOT-7873: Add powered state for skulls f9610cdcb Improve minecart movement Spigot Changes: a759b629 Rebuild patches Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
162 lines
10 KiB
Diff
162 lines
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 52a5274fb811870481a48bf0505769d7ac5df31f..42df8d45ceb963043cf6467b8fc47272ce0873da 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -2084,10 +2084,18 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
|
|
}
|
|
|
|
public boolean setGameMode(GameType gameMode) {
|
|
+ // 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) {
|
|
boolean flag = this.isSpectator();
|
|
|
|
- if (!this.gameMode.changeGameModeForPlayer(gameMode)) {
|
|
- return false;
|
|
+ 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) {
|
|
@@ -2103,7 +2111,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
|
|
|
|
this.onUpdateAbilities();
|
|
this.updateEffectVisibility();
|
|
- return true;
|
|
+ return event; // Paper - Expand PlayerGameModeChangeEvent
|
|
}
|
|
}
|
|
|
|
@@ -2509,6 +2517,16 @@ public class ServerPlayer extends net.minecraft.world.entity.player.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 5de472df78940d1b8320f73d18b2edf3a796227e..073cf184a0e7af41048ae67a9b17b4cdfcc43c35 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
@@ -74,14 +74,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);
|
|
@@ -92,7 +99,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 276c0b017452a1d7b60a2a8e779f2f3fcf4960cc..9781047aa5e0a6e6bc9f9c43a1eb347b6ecdff66 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -2730,7 +2730,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
|
|
|
this.player = this.server.getPlayerList().respawn(this.player, false, Entity.RemovalReason.KILLED, RespawnReason.DEATH); // CraftBukkit
|
|
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 7de53f6750d478a052bc8ade6edac056565fe068..a85983b947147a1557908846b8773aab29c17fae 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -1654,7 +1654,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
|