Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-18 20:40:08 +01:00
SPIGOT-287: Fire a cancelled inventory open event for locked chests
Dieser Commit ist enthalten in:
Ursprung
2d5a55b369
Commit
0a0d3aa5a7
@ -1,5 +1,5 @@
|
|||||||
--- ../work/decompile-8eb82bde/net/minecraft/server/EntityPlayer.java 2014-12-15 14:13:24.430966154 +0000
|
--- ../work/decompile-8eb82bde//net/minecraft/server/EntityPlayer.java 2014-12-28 15:14:13.016406534 +0000
|
||||||
+++ src/main/java/net/minecraft/server/EntityPlayer.java 2014-12-15 14:13:24.434966154 +0000
|
+++ src/main/java/net/minecraft/server/EntityPlayer.java 2014-12-28 15:14:13.016406534 +0000
|
||||||
@@ -13,6 +13,17 @@
|
@@ -13,6 +13,17 @@
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@ -50,7 +50,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void a(NBTTagCompound nbttagcompound) {
|
public void a(NBTTagCompound nbttagcompound) {
|
||||||
@@ -81,14 +108,40 @@
|
@@ -81,13 +108,39 @@
|
||||||
this.playerInteractManager.setGameMode(EnumGamemode.getById(nbttagcompound.getInt("playerGameType")));
|
this.playerInteractManager.setGameMode(EnumGamemode.getById(nbttagcompound.getInt("playerGameType")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,8 +62,8 @@
|
|||||||
super.b(nbttagcompound);
|
super.b(nbttagcompound);
|
||||||
nbttagcompound.setInt("playerGameType", this.playerInteractManager.getGameMode().getId());
|
nbttagcompound.setInt("playerGameType", this.playerInteractManager.getGameMode().getId());
|
||||||
+ this.getBukkitEntity().setExtraData(nbttagcompound); // CraftBukkit
|
+ this.getBukkitEntity().setExtraData(nbttagcompound); // CraftBukkit
|
||||||
}
|
+ }
|
||||||
|
+
|
||||||
+ // CraftBukkit start - World fallback code, either respawn location or global spawn
|
+ // CraftBukkit start - World fallback code, either respawn location or global spawn
|
||||||
+ public void spawnIn(World world) {
|
+ public void spawnIn(World world) {
|
||||||
+ super.spawnIn(world);
|
+ super.spawnIn(world);
|
||||||
@ -86,12 +86,11 @@
|
|||||||
+ }
|
+ }
|
||||||
+ this.dimension = ((WorldServer) this.world).dimension;
|
+ this.dimension = ((WorldServer) this.world).dimension;
|
||||||
+ this.playerInteractManager.a((WorldServer) world);
|
+ this.playerInteractManager.a((WorldServer) world);
|
||||||
+ }
|
}
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
+
|
|
||||||
public void levelDown(int i) {
|
public void levelDown(int i) {
|
||||||
super.levelDown(i);
|
super.levelDown(i);
|
||||||
this.lastSentExp = -1;
|
|
||||||
@@ -114,6 +167,11 @@
|
@@ -114,6 +167,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,11 +301,11 @@
|
|||||||
+ // mount(null) doesn't really fly for overloaded methods,
|
+ // mount(null) doesn't really fly for overloaded methods,
|
||||||
+ // so this method is needed
|
+ // so this method is needed
|
||||||
+ Entity currentVehicle = this.vehicle;
|
+ Entity currentVehicle = this.vehicle;
|
||||||
+
|
|
||||||
+ super.setPassengerOf(entity);
|
|
||||||
|
|
||||||
- super.mount(entity);
|
- super.mount(entity);
|
||||||
- if (entity != entity1) {
|
- if (entity != entity1) {
|
||||||
|
+ super.setPassengerOf(entity);
|
||||||
|
+
|
||||||
+ // Check if the vehicle actually changed.
|
+ // Check if the vehicle actually changed.
|
||||||
+ if (currentVehicle != this.vehicle) {
|
+ if (currentVehicle != this.vehicle) {
|
||||||
this.playerConnection.sendPacket(new PacketPlayOutAttachEntity(0, this, this.vehicle));
|
this.playerConnection.sendPacket(new PacketPlayOutAttachEntity(0, this, this.vehicle));
|
||||||
@ -317,7 +316,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) {}
|
protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) {}
|
||||||
@@ -490,19 +611,38 @@
|
@@ -490,19 +611,46 @@
|
||||||
this.playerConnection.sendPacket(new PacketPlayOutOpenSignEditor(tileentitysign.getPosition()));
|
this.playerConnection.sendPacket(new PacketPlayOutOpenSignEditor(tileentitysign.getPosition()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -344,21 +343,38 @@
|
|||||||
|
|
||||||
public void openContainer(IInventory iinventory) {
|
public void openContainer(IInventory iinventory) {
|
||||||
+ // CraftBukkit start - Inventory open hook
|
+ // CraftBukkit start - Inventory open hook
|
||||||
|
+ // Copied from below
|
||||||
|
+
|
||||||
|
+ boolean cancelled = false;
|
||||||
|
+ if (iinventory instanceof ITileInventory) {
|
||||||
|
+ ITileInventory itileinventory = (ITileInventory) iinventory;
|
||||||
|
+ cancelled = itileinventory.q_() && !this.a(itileinventory.i()) && !this.v();
|
||||||
|
+ }
|
||||||
|
+
|
||||||
+ Container container;
|
+ Container container;
|
||||||
+ if (iinventory instanceof ITileEntityContainer) {
|
+ if (iinventory instanceof ITileEntityContainer) {
|
||||||
+ container = ((ITileEntityContainer)iinventory).createContainer(this.inventory, this);
|
+ container = ((ITileEntityContainer)iinventory).createContainer(this.inventory, this);
|
||||||
+ } else {
|
+ } else {
|
||||||
+ container = new ContainerChest(this.inventory, iinventory, this);
|
+ container = new ContainerChest(this.inventory, iinventory, this);
|
||||||
+ }
|
+ }
|
||||||
+ container = CraftEventFactory.callInventoryOpenEvent(this, container);
|
+ container = CraftEventFactory.callInventoryOpenEvent(this, container, cancelled);
|
||||||
+ if (container == null) {
|
+ if (container == null && !cancelled) { // Let pre-cancelled events fall through
|
||||||
+ return;
|
+ return;
|
||||||
+ }
|
+ }
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
if (this.activeContainer != this.defaultContainer) {
|
if (this.activeContainer != this.defaultContainer) {
|
||||||
this.closeInventory();
|
this.closeInventory();
|
||||||
}
|
}
|
||||||
@@ -520,10 +660,10 @@
|
@@ -510,7 +658,7 @@
|
||||||
|
if (iinventory instanceof ITileInventory) {
|
||||||
|
ITileInventory itileinventory = (ITileInventory) iinventory;
|
||||||
|
|
||||||
|
- if (itileinventory.q_() && !this.a(itileinventory.i()) && !this.v()) {
|
||||||
|
+ if (itileinventory.q_() && !this.a(itileinventory.i()) && !this.v() && container == null) { // CraftBukkit - allow plugins to uncancel the lock
|
||||||
|
this.playerConnection.sendPacket(new PacketPlayOutChat(new ChatMessage("container.isLocked", new Object[] { iinventory.getScoreboardDisplayName()}), (byte) 2));
|
||||||
|
this.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect("random.door_close", this.locX, this.locY, this.locZ, 1.0F, 1.0F));
|
||||||
|
return;
|
||||||
|
@@ -520,10 +668,10 @@
|
||||||
this.nextContainerCounter();
|
this.nextContainerCounter();
|
||||||
if (iinventory instanceof ITileEntityContainer) {
|
if (iinventory instanceof ITileEntityContainer) {
|
||||||
this.playerConnection.sendPacket(new PacketPlayOutOpenWindow(this.containerCounter, ((ITileEntityContainer) iinventory).getContainerName(), iinventory.getScoreboardDisplayName(), iinventory.getSize()));
|
this.playerConnection.sendPacket(new PacketPlayOutOpenWindow(this.containerCounter, ((ITileEntityContainer) iinventory).getContainerName(), iinventory.getScoreboardDisplayName(), iinventory.getSize()));
|
||||||
@ -371,7 +387,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.activeContainer.windowId = this.containerCounter;
|
this.activeContainer.windowId = this.containerCounter;
|
||||||
@@ -531,8 +671,14 @@
|
@@ -531,8 +679,14 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openTrade(IMerchant imerchant) {
|
public void openTrade(IMerchant imerchant) {
|
||||||
@ -387,7 +403,7 @@
|
|||||||
this.activeContainer.windowId = this.containerCounter;
|
this.activeContainer.windowId = this.containerCounter;
|
||||||
this.activeContainer.addSlotListener(this);
|
this.activeContainer.addSlotListener(this);
|
||||||
InventoryMerchant inventorymerchant = ((ContainerMerchant) this.activeContainer).e();
|
InventoryMerchant inventorymerchant = ((ContainerMerchant) this.activeContainer).e();
|
||||||
@@ -552,13 +698,20 @@
|
@@ -552,13 +706,20 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openHorseInventory(EntityHorse entityhorse, IInventory iinventory) {
|
public void openHorseInventory(EntityHorse entityhorse, IInventory iinventory) {
|
||||||
@ -409,7 +425,7 @@
|
|||||||
this.activeContainer.windowId = this.containerCounter;
|
this.activeContainer.windowId = this.containerCounter;
|
||||||
this.activeContainer.addSlotListener(this);
|
this.activeContainer.addSlotListener(this);
|
||||||
}
|
}
|
||||||
@@ -587,6 +740,11 @@
|
@@ -587,6 +748,11 @@
|
||||||
public void a(Container container, List list) {
|
public void a(Container container, List list) {
|
||||||
this.playerConnection.sendPacket(new PacketPlayOutWindowItems(container.windowId, list));
|
this.playerConnection.sendPacket(new PacketPlayOutWindowItems(container.windowId, list));
|
||||||
this.playerConnection.sendPacket(new PacketPlayOutSetSlot(-1, -1, this.inventory.getCarried()));
|
this.playerConnection.sendPacket(new PacketPlayOutSetSlot(-1, -1, this.inventory.getCarried()));
|
||||||
@ -421,7 +437,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setContainerData(Container container, int i, int j) {
|
public void setContainerData(Container container, int i, int j) {
|
||||||
@@ -601,6 +759,7 @@
|
@@ -601,6 +767,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeInventory() {
|
public void closeInventory() {
|
||||||
@ -429,7 +445,7 @@
|
|||||||
this.playerConnection.sendPacket(new PacketPlayOutCloseWindow(this.activeContainer.windowId));
|
this.playerConnection.sendPacket(new PacketPlayOutCloseWindow(this.activeContainer.windowId));
|
||||||
this.p();
|
this.p();
|
||||||
}
|
}
|
||||||
@@ -681,7 +840,16 @@
|
@@ -681,7 +848,16 @@
|
||||||
|
|
||||||
public void triggerHealthUpdate() {
|
public void triggerHealthUpdate() {
|
||||||
this.bK = -1.0E8F;
|
this.bK = -1.0E8F;
|
||||||
@ -446,7 +462,7 @@
|
|||||||
|
|
||||||
public void b(IChatBaseComponent ichatbasecomponent) {
|
public void b(IChatBaseComponent ichatbasecomponent) {
|
||||||
this.playerConnection.sendPacket(new PacketPlayOutChat(ichatbasecomponent));
|
this.playerConnection.sendPacket(new PacketPlayOutChat(ichatbasecomponent));
|
||||||
@@ -747,6 +915,8 @@
|
@@ -747,6 +923,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public void a(EnumGamemode enumgamemode) {
|
public void a(EnumGamemode enumgamemode) {
|
||||||
@ -455,7 +471,7 @@
|
|||||||
this.playerInteractManager.setGameMode(enumgamemode);
|
this.playerInteractManager.setGameMode(enumgamemode);
|
||||||
this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(3, (float) enumgamemode.getId()));
|
this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(3, (float) enumgamemode.getId()));
|
||||||
if (enumgamemode == EnumGamemode.SPECTATOR) {
|
if (enumgamemode == EnumGamemode.SPECTATOR) {
|
||||||
@@ -757,6 +927,7 @@
|
@@ -757,6 +935,7 @@
|
||||||
|
|
||||||
this.updateAbilities();
|
this.updateAbilities();
|
||||||
this.bO();
|
this.bO();
|
||||||
@ -463,7 +479,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean v() {
|
public boolean v() {
|
||||||
@@ -768,6 +939,7 @@
|
@@ -768,6 +947,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean a(int i, String s) {
|
public boolean a(int i, String s) {
|
||||||
@ -471,7 +487,7 @@
|
|||||||
if ("seed".equals(s) && !this.server.ad()) {
|
if ("seed".equals(s) && !this.server.ad()) {
|
||||||
return true;
|
return true;
|
||||||
} else if (!"tell".equals(s) && !"help".equals(s) && !"me".equals(s) && !"trigger".equals(s)) {
|
} else if (!"tell".equals(s) && !"help".equals(s) && !"me".equals(s) && !"trigger".equals(s)) {
|
||||||
@@ -781,6 +953,9 @@
|
@@ -781,6 +961,9 @@
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -481,7 +497,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String w() {
|
public String w() {
|
||||||
@@ -867,6 +1042,129 @@
|
@@ -867,6 +1050,129 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public IChatBaseComponent getPlayerListName() {
|
public IChatBaseComponent getPlayerListName() {
|
||||||
|
@ -680,6 +680,10 @@ public class CraftEventFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Container callInventoryOpenEvent(EntityPlayer player, Container container) {
|
public static Container callInventoryOpenEvent(EntityPlayer player, Container container) {
|
||||||
|
return callInventoryOpenEvent(player, container, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Container callInventoryOpenEvent(EntityPlayer player, Container container, boolean cancelled) {
|
||||||
if (player.activeContainer != player.defaultContainer) { // fire INVENTORY_CLOSE if one already open
|
if (player.activeContainer != player.defaultContainer) { // fire INVENTORY_CLOSE if one already open
|
||||||
player.playerConnection.a(new PacketPlayInCloseWindow(player.activeContainer.windowId));
|
player.playerConnection.a(new PacketPlayInCloseWindow(player.activeContainer.windowId));
|
||||||
}
|
}
|
||||||
@ -689,6 +693,7 @@ public class CraftEventFactory {
|
|||||||
player.activeContainer.transferTo(container, craftPlayer);
|
player.activeContainer.transferTo(container, craftPlayer);
|
||||||
|
|
||||||
InventoryOpenEvent event = new InventoryOpenEvent(container.getBukkitView());
|
InventoryOpenEvent event = new InventoryOpenEvent(container.getBukkitView());
|
||||||
|
event.setCancelled(cancelled);
|
||||||
server.getPluginManager().callEvent(event);
|
server.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren