Better handle cancelled inventory open event
This commit is contained in:
@@ -38,6 +38,7 @@ import org.bukkit.event.block.BlockBreakEvent;
|
|||||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.inventory.CraftingInventory;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
public class SignListener implements Listener {
|
public class SignListener implements Listener {
|
||||||
@@ -123,6 +124,12 @@ public class SignListener implements Listener {
|
|||||||
Inventory inv = VaultManager.getInstance().loadOwnVault(player, num, VaultOperations.getMaxVaultSize(player));
|
Inventory inv = VaultManager.getInstance().loadOwnVault(player, num, VaultOperations.getMaxVaultSize(player));
|
||||||
if (inv != null) {
|
if (inv != null) {
|
||||||
player.openInventory(inv);
|
player.openInventory(inv);
|
||||||
|
|
||||||
|
// Check if the inventory was actually opened
|
||||||
|
if (player.getOpenInventory().getTopInventory() instanceof CraftingInventory || player.getOpenInventory().getTopInventory() == null) {
|
||||||
|
PlayerVaults.debug(String.format("Cancelled opening sign vault.", player.getName()));
|
||||||
|
return; // inventory open event was cancelled.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(Lang.TITLE.toString() + Lang.NO_PERMS.toString());
|
player.sendMessage(Lang.TITLE.toString() + Lang.NO_PERMS.toString());
|
||||||
@@ -134,6 +141,12 @@ public class SignListener implements Listener {
|
|||||||
player.sendMessage(Lang.TITLE.toString() + Lang.VAULT_DOES_NOT_EXIST.toString());
|
player.sendMessage(Lang.TITLE.toString() + Lang.VAULT_DOES_NOT_EXIST.toString());
|
||||||
} else {
|
} else {
|
||||||
player.openInventory(inv);
|
player.openInventory(inv);
|
||||||
|
|
||||||
|
// Check if the inventory was actually opened
|
||||||
|
if (player.getOpenInventory().getTopInventory() instanceof CraftingInventory || player.getOpenInventory().getTopInventory() == null) {
|
||||||
|
PlayerVaults.debug(String.format("Cancelled opening non-self sign vault.", player.getName()));
|
||||||
|
return; // inventory open event was cancelled.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerVaults.getInstance().getInVault().put(player.getUniqueId().toString(), new VaultViewInfo(self ? player.getUniqueId().toString() : offlinePlayer.getUniqueId().toString(), num));
|
PlayerVaults.getInstance().getInVault().put(player.getUniqueId().toString(), new VaultViewInfo(self ? player.getUniqueId().toString() : offlinePlayer.getUniqueId().toString(), num));
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import org.bukkit.ChatColor;
|
|||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.CraftingInventory;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryView;
|
import org.bukkit.inventory.InventoryView;
|
||||||
|
|
||||||
@@ -156,7 +157,7 @@ public class VaultOperations {
|
|||||||
player.openInventory(inv);
|
player.openInventory(inv);
|
||||||
|
|
||||||
// Check if the inventory was actually opened
|
// Check if the inventory was actually opened
|
||||||
if (player.getOpenInventory().getTopInventory() == null) {
|
if (player.getOpenInventory().getTopInventory() instanceof CraftingInventory || player.getOpenInventory().getTopInventory() == null) {
|
||||||
PlayerVaults.debug(String.format("Cancelled opening vault %s for %s from an outside source.", arg, player.getName()));
|
PlayerVaults.debug(String.format("Cancelled opening vault %s for %s from an outside source.", arg, player.getName()));
|
||||||
return false; // inventory open event was cancelled.
|
return false; // inventory open event was cancelled.
|
||||||
}
|
}
|
||||||
@@ -235,6 +236,12 @@ public class VaultOperations {
|
|||||||
player.sendMessage(Lang.TITLE.toString() + Lang.VAULT_DOES_NOT_EXIST.toString());
|
player.sendMessage(Lang.TITLE.toString() + Lang.VAULT_DOES_NOT_EXIST.toString());
|
||||||
} else {
|
} else {
|
||||||
player.openInventory(inv);
|
player.openInventory(inv);
|
||||||
|
|
||||||
|
// Check if the inventory was actually opened
|
||||||
|
if (player.getOpenInventory().getTopInventory() instanceof CraftingInventory || player.getOpenInventory().getTopInventory() == null) {
|
||||||
|
PlayerVaults.debug(String.format("Cancelled opening vault %s for %s from an outside source.", arg, player.getName()));
|
||||||
|
return false; // inventory open event was cancelled.
|
||||||
|
}
|
||||||
player.sendMessage(Lang.TITLE.toString() + Lang.OPEN_OTHER_VAULT.toString().replace("%v", arg).replace("%p", name));
|
player.sendMessage(Lang.TITLE.toString() + Lang.OPEN_OTHER_VAULT.toString().replace("%v", arg).replace("%p", name));
|
||||||
PlayerVaults.debug("opening other vault", time);
|
PlayerVaults.debug("opening other vault", time);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user