mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-04 01:39:54 +01:00
ccbeb5c4ed
Upstream has released updates that appears 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: 6ffe5a68 Add RecipeChoice.ExactChoice API for NBT matches on ingredients ffccf6b7 SPIGOT-4560: Add HumanEntity.sleep and related APIs CraftBukkit Changes:917411fd
Remove redundant BlockPosition creation from sleep API756c38d1
Add RecipeChoice.ExactChoice API for NBT matches on ingredients8e65d8df
SPIGOT-4560: Add HumanEntity.sleep and related APIsa8382862
SPIGOT-4562: reducedDebugInfo not updated on world change
198 lines
10 KiB
Diff
198 lines
10 KiB
Diff
From c12ce1eba38dd8d3e267c2ef474428a7bff54d41 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Tue, 3 Jul 2018 21:56:23 -0400
|
|
Subject: [PATCH] InventoryCloseEvent Reason API
|
|
|
|
Allows you to determine why an inventory was closed, enabling plugin developers
|
|
to "confirm" things based on if it was player triggered close or not.
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
|
|
index 6150b56e0e..3ca579e381 100644
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
|
@@ -943,7 +943,7 @@ public class Chunk implements IChunkAccess {
|
|
{
|
|
if ( h instanceof org.bukkit.craftbukkit.entity.CraftHumanEntity )
|
|
{
|
|
- ( (org.bukkit.craftbukkit.entity.CraftHumanEntity) h).getHandle().closeInventory();
|
|
+ ( (org.bukkit.craftbukkit.entity.CraftHumanEntity) h).getHandle().closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.UNLOADED); // Paper
|
|
}
|
|
}
|
|
}
|
|
@@ -968,7 +968,7 @@ public class Chunk implements IChunkAccess {
|
|
{
|
|
if ( h instanceof org.bukkit.craftbukkit.entity.CraftHumanEntity )
|
|
{
|
|
- ( (org.bukkit.craftbukkit.entity.CraftHumanEntity) h).getHandle().closeInventory();
|
|
+ ( (org.bukkit.craftbukkit.entity.CraftHumanEntity) h).getHandle().closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.UNLOADED); // Paper
|
|
}
|
|
}
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
|
|
index d9ee36faf3..cdf5eb62e7 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityHuman.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
|
|
@@ -158,7 +158,7 @@ public abstract class EntityHuman extends EntityLiving {
|
|
this.dg();
|
|
super.tick();
|
|
if (!this.world.isClientSide && this.activeContainer != null && !this.activeContainer.canUse(this)) {
|
|
- this.closeInventory();
|
|
+ this.closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.CANT_USE); // Paper
|
|
this.activeContainer = this.defaultContainer;
|
|
}
|
|
|
|
@@ -360,6 +360,13 @@ public abstract class EntityHuman extends EntityLiving {
|
|
return this.getHealth() <= 0.0F || this.isSleeping();
|
|
}
|
|
|
|
+ // Paper start - unused code, but to keep signatures aligned
|
|
+ public void closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
|
|
+ closeInventory();
|
|
+ this.activeContainer = this.defaultContainer;
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
public void closeInventory() {
|
|
this.activeContainer = this.defaultContainer;
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
index cd488d37f2..1054367d0e 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
@@ -344,7 +344,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|
}
|
|
// Paper end
|
|
if (!this.world.isClientSide && !this.activeContainer.canUse(this)) {
|
|
- this.closeInventory();
|
|
+ this.closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.CANT_USE); // Paper
|
|
this.activeContainer = this.defaultContainer;
|
|
}
|
|
|
|
@@ -555,7 +555,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|
if (!event.getKeepInventory()) {
|
|
this.inventory.clear();
|
|
}
|
|
-
|
|
+ this.closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.DEATH); // Paper
|
|
this.setSpectatorTarget(this); // Remove spectated target
|
|
// CraftBukkit end
|
|
|
|
@@ -867,7 +867,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|
this.a((new ChatMessage("container.spectatorCantOpen", new Object[0])).a(EnumChatFormat.RED), true);
|
|
} else {
|
|
if (this.activeContainer != this.defaultContainer) {
|
|
- this.closeInventory();
|
|
+ this.closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.OPEN_NEW); // Paper
|
|
}
|
|
|
|
if (iinventory instanceof ITileInventory) {
|
|
@@ -933,7 +933,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|
}
|
|
// CraftBukkit end
|
|
if (this.activeContainer != this.defaultContainer) {
|
|
- this.closeInventory();
|
|
+ this.closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.OPEN_NEW); // Paper
|
|
}
|
|
|
|
this.nextContainerCounter();
|
|
@@ -998,7 +998,12 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|
}
|
|
|
|
public void closeInventory() {
|
|
- CraftEventFactory.handleInventoryCloseEvent(this); // CraftBukkit
|
|
+ // Paper start
|
|
+ closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.UNKNOWN);
|
|
+ }
|
|
+ public void closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
|
|
+ CraftEventFactory.handleInventoryCloseEvent(this, reason); // CraftBukkit
|
|
+ // Paper end
|
|
this.playerConnection.sendPacket(new PacketPlayOutCloseWindow(this.activeContainer.windowId));
|
|
this.m();
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
index dfd64d1f58..3c9cfad9c5 100644
|
|
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
@@ -2019,7 +2019,7 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
|
|
PlayerConnectionUtils.ensureMainThread(packetplayinclosewindow, this, this.player.getWorldServer());
|
|
|
|
if (this.player.isFrozen()) return; // CraftBukkit
|
|
- CraftEventFactory.handleInventoryCloseEvent(this.player); // CraftBukkit
|
|
+ CraftEventFactory.handleInventoryCloseEvent(this.player, org.bukkit.event.inventory.InventoryCloseEvent.Reason.PLAYER); // CraftBukkit // Paper
|
|
|
|
this.player.m();
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
|
|
index 96eff10ffa..ddaa73e83d 100644
|
|
--- a/src/main/java/net/minecraft/server/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/PlayerList.java
|
|
@@ -422,7 +422,7 @@ public abstract class PlayerList {
|
|
entityplayer.a(StatisticList.LEAVE_GAME);
|
|
|
|
// CraftBukkit start - Quitting must be before we do final save of data, in case plugins need to modify it
|
|
- org.bukkit.craftbukkit.event.CraftEventFactory.handleInventoryCloseEvent(entityplayer);
|
|
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleInventoryCloseEvent(entityplayer, org.bukkit.event.inventory.InventoryCloseEvent.Reason.DISCONNECT); // Paper
|
|
|
|
PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(cserver.getPlayer(entityplayer), "\u00A7e" + entityplayer.getName() + " left the game");
|
|
cserver.getPluginManager().callEvent(playerQuitEvent);
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
|
index b82aa903ca..a2bf6b0460 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
|
@@ -513,8 +513,13 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
|
}
|
|
|
|
public void closeInventory() {
|
|
- getHandle().closeInventory();
|
|
+ // Paper start
|
|
+ getHandle().closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.PLUGIN);
|
|
}
|
|
+ public void closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
|
|
+ getHandle().closeInventory(reason);
|
|
+ }
|
|
+ // Paper end
|
|
|
|
public boolean isBlocking() {
|
|
return getHandle().isBlocking();
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index 412ac16dcb..261bc223e1 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -738,7 +738,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
|
|
// Close any foreign inventory
|
|
if (getHandle().activeContainer != getHandle().defaultContainer) {
|
|
- getHandle().closeInventory();
|
|
+ getHandle().closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.TELEPORT); // Paper
|
|
}
|
|
|
|
// Check if the fromWorld and toWorld are the same.
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
index 6c105ef742..83f7116f4a 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
@@ -1099,8 +1099,19 @@ public class CraftEventFactory {
|
|
return event;
|
|
}
|
|
|
|
+ // Paper start
|
|
+
|
|
+ /**
|
|
+ * Incase plugins hooked into this or Spigot adds a new inventory close event. Prefer to pass a reason
|
|
+ * @param human
|
|
+ */
|
|
+ @Deprecated
|
|
public static void handleInventoryCloseEvent(EntityHuman human) {
|
|
- InventoryCloseEvent event = new InventoryCloseEvent(human.activeContainer.getBukkitView());
|
|
+ handleInventoryCloseEvent(human, org.bukkit.event.inventory.InventoryCloseEvent.Reason.UNKNOWN);
|
|
+ }
|
|
+ public static void handleInventoryCloseEvent(EntityHuman human, org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
|
|
+ InventoryCloseEvent event = new InventoryCloseEvent(human.activeContainer.getBukkitView(), reason);
|
|
+ // Paper end
|
|
human.world.getServer().getPluginManager().callEvent(event);
|
|
human.activeContainer.transferTo(human.defaultContainer, human.getBukkitEntity());
|
|
}
|
|
--
|
|
2.20.1
|
|
|