Skip to content

Commit

Permalink
Verificar se InventoryHolder é nulo
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBedrock committed Mar 8, 2024
1 parent 6b658d8 commit dddb123
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 29 deletions.
2 changes: 1 addition & 1 deletion paper/run/server.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Minecraft server properties
#Tue Mar 05 21:13:54 EST 2024
#Fri Mar 08 12:37:41 GMT-03:00 2024
enable-jmx-monitoring=false
rcon.port=25575
level-seed=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public static class CrateAdminListener implements Listener {
public void onInventoryClick(InventoryClickEvent event) {
Inventory inventory = event.getInventory();

if (inventory.getHolder() == null) return;
if (!(inventory.getHolder(false) instanceof CrateAdminMenu holder)) return;

event.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,26 @@ public InventoryBuilder build() {

if (slot > getSize()) continue;

slot--;

String name = file.getString(path + "Name", path + "Name is missing in " + crate.getName() + ".yml");

inventory.setItem(slot, new ItemBuilder()
.setTarget(getPlayer())
.setMaterial(file.getString(path + "Item", "CHEST"))
.setName(name)
.setLore(file.getStringList(path + "Lore"))
.setCrateName(crate.getName())
.setPlayerName(file.getString(path + "Player"))
.setGlow(file.getBoolean(path + "Glowing"))
.addLorePlaceholder("%Keys%", NumberFormat.getNumberInstance().format(this.crazyHandler.getUserManager().getVirtualKeys(getPlayer().getUniqueId(), crate.getName())))
.addLorePlaceholder("%Keys_Physical%", NumberFormat.getNumberInstance().format(this.crazyHandler.getUserManager().getPhysicalKeys(getPlayer().getUniqueId(), crate.getName())))
.addLorePlaceholder("%Keys_Total%", NumberFormat.getNumberInstance().format(this.crazyHandler.getUserManager().getTotalKeys(getPlayer().getUniqueId(), crate.getName())))
.addLorePlaceholder("%crate_opened%", NumberFormat.getNumberInstance().format(this.crazyHandler.getUserManager().getCrateOpened(getPlayer().getUniqueId(), crate.getName())))
.addLorePlaceholder("%Player%", getPlayer().getName())
.build());
}
slot--;

String name = file.getString(path + "Name", path + "Name is missing in " + crate.getName() + ".yml");

inventory.setItem(slot, new ItemBuilder()
.setTarget(getPlayer())
.setMaterial(file.getString(path + "Item", "CHEST"))
.setName(name)
.setLore(file.getStringList(path + "Lore"))
.setCrateName(crate.getName())
.setPlayerName(file.getString(path + "Player"))
.setGlow(file.getBoolean(path + "Glowing"))
.addLorePlaceholder("%Keys%", NumberFormat.getNumberInstance().format(this.crazyHandler.getUserManager().getVirtualKeys(getPlayer().getUniqueId(), crate.getName())))
.addLorePlaceholder("%Keys_Physical%", NumberFormat.getNumberInstance().format(this.crazyHandler.getUserManager().getPhysicalKeys(getPlayer().getUniqueId(), crate.getName())))
.addLorePlaceholder("%Keys_Total%", NumberFormat.getNumberInstance().format(this.crazyHandler.getUserManager().getTotalKeys(getPlayer().getUniqueId(), crate.getName())))
.addLorePlaceholder("%crate_opened%", NumberFormat.getNumberInstance().format(this.crazyHandler.getUserManager().getCrateOpened(getPlayer().getUniqueId(), crate.getName())))
.addLorePlaceholder("%Player%", getPlayer().getName())
.build());
}
}

return this;
}
Expand Down Expand Up @@ -182,6 +182,7 @@ public static class CrateMenuListener implements Listener {
public void onInventoryClick(InventoryClickEvent event) {
Inventory inventory = event.getInventory();

if (inventory.getHolder() == null) return;
if (!(inventory.getHolder(false) instanceof CrateMainMenu holder)) return;

event.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public static class CratePreviewListener implements Listener {
public void onInventoryClick(InventoryClickEvent event) {
Inventory inventory = event.getInventory();

if (inventory.getHolder() == null) return;
if (!(inventory.getHolder(false) instanceof CratePreviewMenu holder)) return;

event.setCancelled(true);
Expand All @@ -169,7 +170,7 @@ public void onInventoryClick(InventoryClickEvent event) {
if (this.inventoryManager.inCratePreview(player)) {
if (holder.overrideMenu()) return;

crate.playSound(player, player.getLocation(), "click-sound","UI_BUTTON_CLICK", SoundCategory.PLAYERS);
crate.playSound(player, player.getLocation(), "click-sound", "UI_BUTTON_CLICK", SoundCategory.PLAYERS);

if (crate.getCrateType() == CrateType.casino || crate.getCrateType() == CrateType.cosmic) {
player.openInventory(crate.getTierPreview(player));
Expand All @@ -190,7 +191,7 @@ public void onInventoryClick(InventoryClickEvent event) {

if (container.has(PersistentKeys.next_button.getNamespacedKey())) { // Clicked the next button.
if (this.inventoryManager.getPage(player) < crate.getMaxPage()) {
crate.playSound(player, player.getLocation(), "click-sound","UI_BUTTON_CLICK", SoundCategory.PLAYERS);
crate.playSound(player, player.getLocation(), "click-sound", "UI_BUTTON_CLICK", SoundCategory.PLAYERS);

this.inventoryManager.nextPage(player);

Expand All @@ -202,7 +203,7 @@ public void onInventoryClick(InventoryClickEvent event) {

if (container.has(PersistentKeys.back_button.getNamespacedKey())) { // Clicked the back button.
if (this.inventoryManager.getPage(player) > 1 && this.inventoryManager.getPage(player) <= crate.getMaxPage()) {
crate.playSound(player, player.getLocation(), "click-sound","UI_BUTTON_CLICK", SoundCategory.PLAYERS);
crate.playSound(player, player.getLocation(), "click-sound", "UI_BUTTON_CLICK", SoundCategory.PLAYERS);

this.inventoryManager.backPage(player);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public static class CrateTierListener implements Listener {
public void onInventoryClick(InventoryClickEvent event) {
Inventory inventory = event.getInventory();

if (inventory.getHolder() == null) return;
if (!(inventory.getHolder(false) instanceof CrateTierMenu holder)) return;

event.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void onWorldLoad(WorldLoadEvent event) {
this.plugin.debug(() -> "Fixed " + finalFixedAmount + " broken crate locations.", Level.WARNING);

if (this.crateManager.getBrokeLocations().isEmpty()) {
this.plugin.getLogger().warning("All broken crate locations have been fixed.");
this.plugin.debug(() -> "All broken crate locations have been fixed.", Level.WARNING);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public void onInventoryClose(InventoryCloseEvent event) {
}

// Play sound.
if (playSound) holder.getCrate().playSound(player, player.getLocation(), "click-sound", "UI_BUTTON_CLICK", SoundCategory.PLAYERS);
if (playSound)
holder.getCrate().playSound(player, player.getLocation(), "click-sound", "UI_BUTTON_CLICK", SoundCategory.PLAYERS);

// Remove opening stuff.
this.crateManager.removePlayerFromOpeningList(player);
Expand All @@ -109,6 +110,7 @@ public void onInventoryClickPrize(InventoryClickEvent event) {
// Get the inventory.
Inventory inventory = event.getInventory();

if (inventory.getHolder() == null) return;
if (!(inventory.getHolder(false) instanceof CratePrizeMenu holder)) return;

Player player = holder.getPlayer();
Expand Down Expand Up @@ -161,7 +163,7 @@ public void onInventoryClickPrize(InventoryClickEvent event) {

event.setCurrentItem(prize.getDisplayItem(player));

holder.getCrate().playSound(player, player.getLocation(), "click-sound","UI_BUTTON_CLICK", SoundCategory.PLAYERS);
holder.getCrate().playSound(player, player.getLocation(), "click-sound", "UI_BUTTON_CLICK", SoundCategory.PLAYERS);

if (prize.useFireworks()) MiscUtils.spawnFirework(player.getLocation().add(0, 1, 0), null);
}
Expand All @@ -171,6 +173,7 @@ public void onInventoryClick(InventoryClickEvent event) {
// Get the inventory.
Inventory inventory = event.getInventory();

if (inventory.getHolder() == null) return;
if (!(inventory.getHolder(false) instanceof CratePrizeMenu holder)) return;

Player player = holder.getPlayer();
Expand Down Expand Up @@ -212,7 +215,7 @@ public void onInventoryClick(InventoryClickEvent event) {
int totalPrizes = cosmicCrateManager.getTotalPrizes();

// Get picked slot.
int pickedSlot = slot+1;
int pickedSlot = slot + 1;

// Get clicked item's item meta.
ItemMeta itemMeta = itemStack.getItemMeta();
Expand Down Expand Up @@ -247,7 +250,7 @@ public void onInventoryClick(InventoryClickEvent event) {
cosmicCrateManager.addPickedPrize(player, slot, crate.getTier(tierName));

// Play a sound to indicate they clicked a chest.
holder.getCrate().playSound(player, player.getLocation(), "click-sound","UI_BUTTON_CLICK", SoundCategory.PLAYERS);
holder.getCrate().playSound(player, player.getLocation(), "click-sound", "UI_BUTTON_CLICK", SoundCategory.PLAYERS);
}
} else if (container.has(PersistentKeys.cosmic_picked_crate.getNamespacedKey())) {
// Gets the tier name from the pdc.
Expand All @@ -271,7 +274,7 @@ public void onInventoryClick(InventoryClickEvent event) {
cosmicCrateManager.removePickedPrize(player, slot);

// Play a sound to indicate they clicked a chest.
holder.getCrate().playSound(player, player.getLocation(), "click-sound","UI_BUTTON_CLICK", SoundCategory.PLAYERS);
holder.getCrate().playSound(player, player.getLocation(), "click-sound", "UI_BUTTON_CLICK", SoundCategory.PLAYERS);
}

// Get the crate name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class WarCrateListener implements Listener {
public void onInventoryClick(InventoryClickEvent event) {
Inventory inventory = event.getInventory();

if (inventory.getHolder() == null) return;
if (!(inventory.getHolder(false) instanceof CratePrizeMenu holder)) return;

Player player = holder.getPlayer();
Expand Down

0 comments on commit dddb123

Please sign in to comment.