Expand PlayerGameModeChangeEvent

This commit is contained in:
Jake Potrebic
2021-05-15 10:04:43 -07:00
parent 64365b4218
commit d6b69e74a9
6 changed files with 152 additions and 51 deletions

View File

@@ -39,15 +39,26 @@
public class ServerPlayerGameMode {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -56,9 +75,16 @@
@@ -53,18 +72,32 @@
}
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 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);
@@ -57,7 +68,14 @@
this.level.updateSleepingPlayerList();
if (gameMode == GameType.CREATIVE) {
this.player.resetCurrentImpulseContext();
@@ -92,12 +118,12 @@
}
- return true;
+ return event; // Paper - Expand PlayerGameModeChangeEvent
}
}
@@ -92,12 +125,12 @@
}
public void tick() {
@@ -73,7 +91,7 @@
this.hasDelayedDestroy = false;
} else {
float f = this.incrementDestroyProgress(iblockdata, this.delayedDestroyPos, this.delayedTickStart);
@@ -108,7 +134,13 @@
@@ -108,7 +141,13 @@
}
}
} else if (this.isDestroyingBlock) {
@@ -88,7 +106,7 @@
if (iblockdata.isAir()) {
this.level.destroyBlockProgress(this.player.getId(), this.destroyPos, -1);
this.lastSentState = -1;
@@ -137,6 +169,7 @@
@@ -137,6 +176,7 @@
public void handleBlockBreakAction(BlockPos pos, ServerboundPlayerActionPacket.Action action, Direction direction, int worldHeight, int sequence) {
if (!this.player.canInteractWithBlock(pos, 1.0D)) {
@@ -96,7 +114,7 @@
this.debugLogging(pos, false, sequence, "too far");
} else if (pos.getY() > worldHeight) {
this.player.connection.send(new ClientboundBlockUpdatePacket(pos, this.level.getBlockState(pos)));
@@ -146,16 +179,46 @@
@@ -146,16 +186,46 @@
if (action == ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK) {
if (!this.level.mayInteract(this.player, pos)) {
@@ -110,9 +128,9 @@
+ this.player.connection.send(tileentity.getUpdatePacket());
+ }
+ // CraftBukkit end
return;
}
+ return;
+ }
+
+ // CraftBukkit start
+ PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, pos, direction, this.player.getInventory().getSelected(), InteractionHand.MAIN_HAND);
+ if (event.isCancelled()) {
@@ -123,10 +141,10 @@
+ if (tileentity != null) {
+ this.player.connection.send(tileentity.getUpdatePacket());
+ }
+ return;
+ }
return;
}
+ // CraftBukkit end
+
if (this.isCreative()) {
this.destroyAndAck(pos, sequence, "creative destroy");
return;
@@ -143,7 +161,7 @@
if (this.player.blockActionRestricted(this.level, pos, this.gameModeForPlayer)) {
this.player.connection.send(new ClientboundBlockUpdatePacket(pos, this.level.getBlockState(pos)));
this.debugLogging(pos, false, sequence, "block action restricted");
@@ -166,7 +229,19 @@
@@ -166,7 +236,19 @@
float f = 1.0F;
iblockdata = this.level.getBlockState(pos);
@@ -164,7 +182,7 @@
EnchantmentHelper.onHitBlock(this.level, this.player.getMainHandItem(), this.player, this.player, EquipmentSlot.MAINHAND, Vec3.atCenterOf(pos), iblockdata, (item) -> {
this.player.onEquippedItemBroken(item, EquipmentSlot.MAINHAND);
});
@@ -174,6 +249,26 @@
@@ -174,6 +256,26 @@
f = iblockdata.getDestroyProgress(this.player, this.player.level(), pos);
}
@@ -191,7 +209,7 @@
if (!iblockdata.isAir() && f >= 1.0F) {
this.destroyAndAck(pos, sequence, "insta mine");
} else {
@@ -217,14 +312,18 @@
@@ -217,14 +319,18 @@
this.debugLogging(pos, true, sequence, "stopped destroying");
} else if (action == ServerboundPlayerActionPacket.Action.ABORT_DESTROY_BLOCK) {
this.isDestroyingBlock = false;
@@ -214,7 +232,7 @@
}
}
@@ -242,19 +341,78 @@
@@ -242,19 +348,78 @@
public boolean destroyBlock(BlockPos pos) {
BlockState iblockdata = this.level.getBlockState(pos);
@@ -295,7 +313,7 @@
BlockState iblockdata1 = block.playerWillDestroy(this.level, pos, iblockdata, this.player);
boolean flag = this.level.removeBlock(pos, false);
@@ -263,19 +421,34 @@
@@ -263,19 +428,34 @@
}
if (this.isCreative()) {
@@ -333,7 +351,7 @@
}
}
}
@@ -321,15 +494,58 @@
@@ -321,15 +501,58 @@
}
}
@@ -392,7 +410,7 @@
if (itileinventory != null) {
player.openMenu(itileinventory);
return InteractionResult.CONSUME;
@@ -359,7 +575,7 @@
@@ -359,7 +582,7 @@
}
}