mirror of
https://github.com/PaperMC/Paper.git
synced 2025-02-10 01:21:46 +01:00
SPIGOT-6535: PlayerGameModeChangeEvent event incorrectly reports old gamemode
By: Parker Hawke <hawkeboyz2@hotmail.com>
This commit is contained in:
parent
94c0260719
commit
f7478ccc32
@ -538,14 +538,14 @@
|
||||
+ // CraftBukkit start
|
||||
+ ResourceKey<World> maindimensionkey = CraftDimensionUtil.getMainDimensionKey(worldserver);
|
||||
+ ResourceKey<World> maindimensionkey1 = CraftDimensionUtil.getMainDimensionKey(this.level);
|
||||
+
|
||||
|
||||
- CriterionTriggers.CHANGED_DIMENSION.a(this, resourcekey, resourcekey1);
|
||||
- if (resourcekey == World.NETHER && resourcekey1 == World.OVERWORLD && this.enteredNetherPosition != null) {
|
||||
+ CriterionTriggers.CHANGED_DIMENSION.a(this, maindimensionkey, maindimensionkey1);
|
||||
+ if (maindimensionkey != resourcekey || maindimensionkey1 != resourcekey1) {
|
||||
+ CriterionTriggers.CHANGED_DIMENSION.a(this, resourcekey, resourcekey1);
|
||||
+ }
|
||||
|
||||
- CriterionTriggers.CHANGED_DIMENSION.a(this, resourcekey, resourcekey1);
|
||||
- if (resourcekey == World.NETHER && resourcekey1 == World.OVERWORLD && this.enteredNetherPosition != null) {
|
||||
+
|
||||
+ if (maindimensionkey == World.NETHER && maindimensionkey1 == World.OVERWORLD && this.enteredNetherPosition != null) {
|
||||
+ // CraftBukkit end
|
||||
CriterionTriggers.NETHER_TRAVEL.a(this, this.enteredNetherPosition);
|
||||
@ -786,21 +786,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1289,6 +1648,13 @@
|
||||
if (!this.gameMode.setGameMode(enumgamemode)) {
|
||||
return false;
|
||||
} else {
|
||||
+ // CraftBukkit start
|
||||
+ PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(getBukkitEntity(), GameMode.getByValue(enumgamemode.getId()));
|
||||
+ level.getCraftServer().getPluginManager().callEvent(event);
|
||||
+ if (event.isCancelled()) {
|
||||
+ return false;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
this.connection.sendPacket(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.CHANGE_GAME_MODE, (float) enumgamemode.getId()));
|
||||
if (enumgamemode == EnumGamemode.SPECTATOR) {
|
||||
this.releaseShoulderEntities();
|
||||
@@ -1341,7 +1707,20 @@
|
||||
@@ -1341,7 +1700,20 @@
|
||||
return s;
|
||||
}
|
||||
|
||||
@ -821,7 +807,7 @@
|
||||
this.chatVisibility = packetplayinsettings.d();
|
||||
this.canChatColor = packetplayinsettings.e();
|
||||
this.textFilteringEnabled = packetplayinsettings.h();
|
||||
@@ -1411,7 +1790,7 @@
|
||||
@@ -1411,7 +1783,7 @@
|
||||
this.camera = (Entity) (entity == null ? this : entity);
|
||||
if (entity1 != this.camera) {
|
||||
this.connection.sendPacket(new PacketPlayOutCamera(this.camera));
|
||||
@ -830,7 +816,7 @@
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1440,7 +1819,7 @@
|
||||
@@ -1440,7 +1812,7 @@
|
||||
|
||||
@Nullable
|
||||
public IChatBaseComponent getPlayerListName() {
|
||||
@ -839,7 +825,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1461,9 +1840,16 @@
|
||||
@@ -1461,9 +1833,16 @@
|
||||
return this.advancements;
|
||||
}
|
||||
|
||||
@ -856,7 +842,7 @@
|
||||
if (worldserver == this.level) {
|
||||
this.connection.b(d0, d1, d2, f, f1);
|
||||
} else {
|
||||
@@ -1483,6 +1869,9 @@
|
||||
@@ -1483,6 +1862,9 @@
|
||||
this.server.getPlayerList().a(this, worldserver);
|
||||
this.server.getPlayerList().updateClient(this);
|
||||
}
|
||||
@ -866,7 +852,7 @@
|
||||
|
||||
}
|
||||
|
||||
@@ -1628,4 +2017,144 @@
|
||||
@@ -1628,4 +2010,144 @@
|
||||
CriterionTriggers.USING_ITEM.a(this, itemstack);
|
||||
super.a(itemstack);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
--- a/net/minecraft/server/level/PlayerInteractManager.java
|
||||
+++ b/net/minecraft/server/level/PlayerInteractManager.java
|
||||
@@ -25,6 +25,25 @@
|
||||
@@ -25,6 +25,27 @@
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -15,18 +15,34 @@
|
||||
+import net.minecraft.world.level.block.BlockTrapdoor;
|
||||
+import net.minecraft.world.level.block.Blocks;
|
||||
+import net.minecraft.world.level.block.state.properties.BlockPropertyDoubleBlockHalf;
|
||||
+import org.bukkit.GameMode;
|
||||
+import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
+import org.bukkit.event.block.BlockBreakEvent;
|
||||
+import org.bukkit.craftbukkit.event.CraftEventFactory;
|
||||
+import org.bukkit.event.Event;
|
||||
+import org.bukkit.event.block.Action;
|
||||
+import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
||||
+import org.bukkit.event.player.PlayerInteractEvent;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class PlayerInteractManager {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
@@ -65,7 +84,7 @@
|
||||
@@ -55,6 +76,13 @@
|
||||
if (enumgamemode == this.gameModeForPlayer) {
|
||||
return false;
|
||||
} else {
|
||||
+ // CraftBukkit start
|
||||
+ PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(player.getBukkitEntity(), GameMode.getByValue(enumgamemode.getId()));
|
||||
+ level.getCraftServer().getPluginManager().callEvent(event);
|
||||
+ if (event.isCancelled()) {
|
||||
+ return false;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
this.a(enumgamemode, this.gameModeForPlayer);
|
||||
return true;
|
||||
}
|
||||
@@ -65,7 +93,7 @@
|
||||
this.gameModeForPlayer = enumgamemode;
|
||||
enumgamemode.a(this.player.getAbilities());
|
||||
this.player.updateAbilities();
|
||||
@ -35,7 +51,7 @@
|
||||
this.level.everyoneSleeping();
|
||||
}
|
||||
|
||||
@@ -87,7 +106,7 @@
|
||||
@@ -87,7 +115,7 @@
|
||||
}
|
||||
|
||||
public void a() {
|
||||
@ -44,7 +60,7 @@
|
||||
IBlockData iblockdata;
|
||||
|
||||
if (this.hasDelayedDestroy) {
|
||||
@@ -143,9 +162,31 @@
|
||||
@@ -143,9 +171,31 @@
|
||||
|
||||
if (packetplayinblockdig_enumplayerdigtype == PacketPlayInBlockDig.EnumPlayerDigType.START_DESTROY_BLOCK) {
|
||||
if (!this.level.a((EntityHuman) this.player, blockposition)) {
|
||||
@ -76,7 +92,7 @@
|
||||
|
||||
if (this.isCreative()) {
|
||||
this.a(blockposition, packetplayinblockdig_enumplayerdigtype, "creative destroy");
|
||||
@@ -161,11 +202,43 @@
|
||||
@@ -161,11 +211,43 @@
|
||||
float f = 1.0F;
|
||||
|
||||
iblockdata = this.level.getType(blockposition);
|
||||
@ -121,7 +137,7 @@
|
||||
if (!iblockdata.isAir() && f >= 1.0F) {
|
||||
this.a(blockposition, packetplayinblockdig_enumplayerdigtype, "insta mine");
|
||||
} else {
|
||||
@@ -209,7 +282,7 @@
|
||||
@@ -209,7 +291,7 @@
|
||||
} else if (packetplayinblockdig_enumplayerdigtype == PacketPlayInBlockDig.EnumPlayerDigType.ABORT_DESTROY_BLOCK) {
|
||||
this.isDestroyingBlock = false;
|
||||
if (!Objects.equals(this.destroyPos, blockposition)) {
|
||||
@ -130,7 +146,7 @@
|
||||
this.level.a(this.player.getId(), this.destroyPos, -1);
|
||||
this.player.connection.sendPacket(new PacketPlayOutBlockBreak(this.destroyPos, this.level.getType(this.destroyPos), packetplayinblockdig_enumplayerdigtype, true, "aborted mismatched destroying"));
|
||||
}
|
||||
@@ -225,17 +298,72 @@
|
||||
@@ -225,17 +307,72 @@
|
||||
if (this.breakBlock(blockposition)) {
|
||||
this.player.connection.sendPacket(new PacketPlayOutBlockBreak(blockposition, this.level.getType(blockposition), packetplayinblockdig_enumplayerdigtype, true, s));
|
||||
} else {
|
||||
@ -171,8 +187,7 @@
|
||||
+ if (nmsBlock != null && !event.isCancelled() && !this.isCreative() && this.player.hasBlock(nmsBlock.getBlockData())) {
|
||||
+ event.setExpToDrop(nmsBlock.getExpDrop(nmsData, this.level, blockposition, itemstack));
|
||||
+ }
|
||||
|
||||
- if (!this.player.getItemInMainHand().getItem().a(iblockdata, (World) this.level, blockposition, (EntityHuman) this.player)) {
|
||||
+
|
||||
+ this.level.getCraftServer().getPluginManager().callEvent(event);
|
||||
+
|
||||
+ if (event.isCancelled()) {
|
||||
@ -186,7 +201,8 @@
|
||||
+ for (EnumDirection dir : EnumDirection.values()) {
|
||||
+ this.player.connection.sendPacket(new PacketPlayOutBlockChange(level, blockposition.shift(dir)));
|
||||
+ }
|
||||
+
|
||||
|
||||
- if (!this.player.getItemInMainHand().getItem().a(iblockdata, (World) this.level, blockposition, (EntityHuman) this.player)) {
|
||||
+ // Update any tile entity data for this block
|
||||
+ TileEntity tileentity = this.level.getTileEntity(blockposition);
|
||||
+ if (tileentity != null) {
|
||||
@ -205,7 +221,7 @@
|
||||
TileEntity tileentity = this.level.getTileEntity(blockposition);
|
||||
Block block = iblockdata.getBlock();
|
||||
|
||||
@@ -245,6 +373,10 @@
|
||||
@@ -245,6 +382,10 @@
|
||||
} else if (this.player.a((World) this.level, blockposition, this.gameModeForPlayer)) {
|
||||
return false;
|
||||
} else {
|
||||
@ -216,7 +232,7 @@
|
||||
block.a((World) this.level, blockposition, iblockdata, (EntityHuman) this.player);
|
||||
boolean flag = this.level.a(blockposition, false);
|
||||
|
||||
@@ -253,19 +385,32 @@
|
||||
@@ -253,19 +394,32 @@
|
||||
}
|
||||
|
||||
if (this.isCreative()) {
|
||||
@ -239,20 +255,20 @@
|
||||
+ // CraftBukkit start
|
||||
+ if (event.isDropItems()) {
|
||||
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockDropItemEvent(bblock, state, this.player, level.captureDrops);
|
||||
}
|
||||
+ }
|
||||
+ level.captureDrops = null;
|
||||
+
|
||||
+ // Drop event experience
|
||||
+ if (flag && event != null) {
|
||||
+ iblockdata.getBlock().dropExperience(this.level, blockposition, event.getExpToDrop());
|
||||
+ }
|
||||
}
|
||||
+
|
||||
+ return true;
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -307,12 +452,52 @@
|
||||
@@ -307,12 +461,52 @@
|
||||
}
|
||||
}
|
||||
|
||||
@ -305,7 +321,7 @@
|
||||
|
||||
if (itileinventory != null) {
|
||||
entityplayer.openContainer(itileinventory);
|
||||
@@ -326,7 +511,7 @@
|
||||
@@ -326,7 +520,7 @@
|
||||
ItemStack itemstack1 = itemstack.cloneItemStack();
|
||||
|
||||
if (!flag1) {
|
||||
@ -314,7 +330,7 @@
|
||||
|
||||
if (enuminteractionresult.a()) {
|
||||
CriterionTriggers.ITEM_USED_ON_BLOCK.a(entityplayer, blockposition, itemstack1);
|
||||
@@ -334,17 +519,17 @@
|
||||
@@ -334,17 +528,17 @@
|
||||
}
|
||||
}
|
||||
|
||||
@ -335,7 +351,7 @@
|
||||
}
|
||||
|
||||
if (enuminteractionresult1.a()) {
|
||||
@@ -352,10 +537,10 @@
|
||||
@@ -352,10 +546,10 @@
|
||||
}
|
||||
|
||||
return enuminteractionresult1;
|
||||
|
Loading…
Reference in New Issue
Block a user