From 01bfc43c6e0c069bde09cd9af123018535d2338d Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Tue, 4 Feb 2020 23:01:53 +0100 Subject: [PATCH] Allow all containers as reward / dungeon chests; resolves #666 --- .../dungeonsxl/reward/RewardListener.java | 9 +++---- .../de/erethon/dungeonsxl/sign/ChestSign.java | 15 ++++++------ .../dungeonsxl/sign/DungeonChestSign.java | 4 ++-- .../dungeonsxl/world/block/RewardChest.java | 24 +++++++++---------- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/core/src/main/java/de/erethon/dungeonsxl/reward/RewardListener.java b/core/src/main/java/de/erethon/dungeonsxl/reward/RewardListener.java index 0ab64a21..f4f78171 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/reward/RewardListener.java +++ b/core/src/main/java/de/erethon/dungeonsxl/reward/RewardListener.java @@ -30,7 +30,7 @@ import de.erethon.vignette.api.layout.PaginatedFlowInventoryLayout; import de.erethon.vignette.api.layout.PaginatedInventoryLayout.PaginationButtonPosition; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.block.Chest; +import org.bukkit.block.Container; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -90,19 +90,20 @@ public class RewardListener implements Listener { return; } - if (!(inventory.getTopInventory().getHolder() instanceof Chest)) { + if (!(inventory.getTopInventory().getHolder() instanceof Container)) { return; } - Chest chest = (Chest) inventory.getTopInventory().getHolder(); + Container container = (Container) inventory.getTopInventory().getHolder(); for (RewardChest rewardChest : gameWorld.getRewardChests()) { - if (!rewardChest.getChest().equals(chest)) { + if (!rewardChest.getBlock().equals(container.getBlock())) { continue; } rewardChest.onOpen((Player) event.getPlayer()); event.setCancelled(true); + break; } if (!plugin.getMainConfig().getOpenInventories() && !DPermission.hasPermission(event.getPlayer(), DPermission.INSECURE)) { diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/ChestSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/ChestSign.java index 47e80756..337e68ff 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/ChestSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/ChestSign.java @@ -16,12 +16,11 @@ */ package de.erethon.dungeonsxl.sign; -import de.erethon.caliburn.category.Category; import de.erethon.caliburn.loottable.LootTable; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.world.DGameWorld; import org.bukkit.block.Block; -import org.bukkit.block.Chest; +import org.bukkit.block.Container; import org.bukkit.block.Sign; import org.bukkit.inventory.ItemStack; @@ -82,21 +81,21 @@ public abstract class ChestSign extends DSign { Block yRelative = sign.getRelative(0, i, 0); Block zRelative = sign.getRelative(0, 0, i); - if (Category.CHESTS.containsBlock(xRelative)) { + if (xRelative.getState() instanceof Container) { if (chestContent == null) { - chestContent = ((Chest) xRelative.getState()).getBlockInventory().getContents(); + chestContent = ((Container) xRelative.getState()).getInventory().getContents(); } chest = xRelative; - } else if (Category.CHESTS.containsBlock(yRelative)) { + } else if (yRelative.getState() instanceof Container) { if (chestContent == null) { - chestContent = ((Chest) yRelative.getState()).getBlockInventory().getContents(); + chestContent = ((Container) yRelative.getState()).getInventory().getContents(); } chest = yRelative; - } else if (Category.CHESTS.containsBlock(zRelative)) { + } else if (zRelative.getState() instanceof Container) { if (chestContent == null) { - chestContent = ((Chest) zRelative.getState()).getBlockInventory().getContents(); + chestContent = ((Container) zRelative.getState()).getInventory().getContents(); } chest = zRelative; } diff --git a/core/src/main/java/de/erethon/dungeonsxl/sign/DungeonChestSign.java b/core/src/main/java/de/erethon/dungeonsxl/sign/DungeonChestSign.java index 3cab6820..757f8bf9 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/sign/DungeonChestSign.java +++ b/core/src/main/java/de/erethon/dungeonsxl/sign/DungeonChestSign.java @@ -21,7 +21,7 @@ import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.world.DGameWorld; import java.util.Arrays; import java.util.List; -import org.bukkit.block.Chest; +import org.bukkit.block.Container; import org.bukkit.block.Sign; import org.bukkit.inventory.ItemStack; @@ -80,7 +80,7 @@ public class DungeonChestSign extends ChestSign { } chestContent = Arrays.copyOfRange(list.toArray(new ItemStack[list.size()]), 0, 26); - ((Chest) chest.getState()).getBlockInventory().setContents(chestContent); + ((Container) chest.getState()).getInventory().setContents(chestContent); } } diff --git a/core/src/main/java/de/erethon/dungeonsxl/world/block/RewardChest.java b/core/src/main/java/de/erethon/dungeonsxl/world/block/RewardChest.java index ea4a2e03..7f9f85a8 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/world/block/RewardChest.java +++ b/core/src/main/java/de/erethon/dungeonsxl/world/block/RewardChest.java @@ -33,7 +33,7 @@ import de.erethon.dungeonsxl.reward.RewardTypeDefault; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.block.Block; -import org.bukkit.block.Chest; +import org.bukkit.block.Container; import org.bukkit.entity.Player; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; @@ -45,19 +45,19 @@ public class RewardChest extends GameBlock { // Variables private boolean used = false; - private Chest chest; + private Container container; private double moneyReward; private int levelReward; private ItemStack[] itemReward; - public RewardChest(DungeonsXL plugin, Block chest, double moneyReward, int levelReward, ItemStack[] itemReward) { - super(plugin, chest); + public RewardChest(DungeonsXL plugin, Block container, double moneyReward, int levelReward, ItemStack[] itemReward) { + super(plugin, container); - if (!(chest.getState() instanceof Chest)) { + if (!(container.getState() instanceof Container)) { return; } - this.chest = (Chest) chest.getState(); + this.container = (Container) container.getState(); this.moneyReward = moneyReward; this.levelReward = levelReward; this.itemReward = itemReward; @@ -80,15 +80,15 @@ public class RewardChest extends GameBlock { /** * @return the chest */ - public Chest getChest() { - return chest; + public Container getContainer() { + return container; } /** - * @param chest the chest to set + * @param container the container to set */ - public void setChest(Chest chest) { - this.chest = chest; + public void setContainer(Container container) { + this.container = container; } /** @@ -134,7 +134,7 @@ public class RewardChest extends GameBlock { return; } - if (chest.getLocation().distance(chest.getLocation()) < 1) { + if (container.getLocation().distance(container.getLocation()) < 1) { addTreasure(DGroup.getByPlayer(opener)); used = true; }