Allow all containers as reward / dungeon chests; resolves #666

This commit is contained in:
Daniel Saukel 2020-02-04 23:01:53 +01:00
parent 054e7d9ae9
commit 01bfc43c6e
4 changed files with 26 additions and 26 deletions

View File

@ -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)) {

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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;
}