mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-09 04:09:54 +01:00
4ed5ab7c79
--- work/CraftBukkit Submodule work/CraftBukkit 297ff400..83af86db: > SPIGOT-5457: Downgrade 'Mismatch in destroy block pos' message to debug > SPIGOT-5481: PlayerBedLeaveEvent returns wrong bed location > SPIGOT-5482: Structure Block setUsageMode encounters NullpointerException > SPIGOT-5426: isSimilar for player heads fails > SPIGOT-5478: XP not dropping when a player dies --- work/Spigot Submodule work/Spigot 05bb8bcf..492a7792: > Rebuild patches
198 lines
10 KiB
Diff
198 lines
10 KiB
Diff
From eb8e56f6ab1d36c34da3b2c08bef1c5c911a5729 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/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
|
|
index ba3e6b882..2265b01e6 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityHuman.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
|
|
@@ -164,7 +164,7 @@ public abstract class EntityHuman extends EntityLiving {
|
|
this.dW();
|
|
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;
|
|
}
|
|
|
|
@@ -363,6 +363,13 @@ public abstract class EntityHuman extends EntityLiving {
|
|
return 20;
|
|
}
|
|
|
|
+ // 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 39d10f870..ee2810685 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
@@ -362,7 +362,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;
|
|
}
|
|
|
|
@@ -536,7 +536,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|
|
|
// SPIGOT-943 - only call if they have an inventory open
|
|
if (this.activeContainer != this.defaultContainer) {
|
|
- this.closeInventory();
|
|
+ this.closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.DEATH); // Paper
|
|
}
|
|
|
|
String deathMessage = event.getDeathMessage();
|
|
@@ -1028,7 +1028,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|
return OptionalInt.empty();
|
|
} else {
|
|
if (this.activeContainer != this.defaultContainer) {
|
|
- this.closeInventory();
|
|
+ this.closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.OPEN_NEW); // Paper
|
|
}
|
|
|
|
this.nextContainerCounter();
|
|
@@ -1088,7 +1088,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(); // CraftBukkit - moved up
|
|
@@ -1152,7 +1152,12 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|
|
|
@Override
|
|
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 8757b6751..4f04410f9 100644
|
|
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
@@ -2039,7 +2039,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
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 002f7e844..fd0f5c6f2 100644
|
|
--- a/src/main/java/net/minecraft/server/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/PlayerList.java
|
|
@@ -403,7 +403,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/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
|
|
index abf91bd8c..fa7b38a5c 100644
|
|
--- a/src/main/java/net/minecraft/server/WorldServer.java
|
|
+++ b/src/main/java/net/minecraft/server/WorldServer.java
|
|
@@ -1036,7 +1036,7 @@ public class WorldServer extends World {
|
|
{
|
|
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
|
|
}
|
|
}
|
|
}
|
|
@@ -1059,7 +1059,7 @@ public class WorldServer extends World {
|
|
{
|
|
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/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
|
index cd8ad2704..e169679c8 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
|
@@ -619,8 +619,13 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
|
|
|
@Override
|
|
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
|
|
|
|
@Override
|
|
public boolean isBlocking() {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index ebf025c8a..ba4eb3726 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -780,7 +780,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 13598e3bb..bb48d44ff 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
@@ -1292,8 +1292,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.24.1
|
|
|