mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-24 19:45:43 +01:00
Fix reward chest backwards compatibility
This commit is contained in:
parent
bd91373a03
commit
9a10bea264
@ -17,6 +17,7 @@
|
||||
package de.erethon.dungeonsxl.reward;
|
||||
|
||||
import de.erethon.caliburn.item.VanillaItem;
|
||||
import de.erethon.commons.compatibility.Version;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
@ -29,6 +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;
|
||||
@ -36,6 +38,8 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -89,14 +93,12 @@ public class RewardListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(inventory.getTopInventory().getHolder() instanceof Container)) {
|
||||
if (!(isValidContainer(inventory.getTopInventory()))) {
|
||||
return;
|
||||
}
|
||||
|
||||
Container container = (Container) inventory.getTopInventory().getHolder();
|
||||
|
||||
for (RewardChest rewardChest : gameWorld.getRewardChests()) {
|
||||
if (!rewardChest.getBlock().equals(container.getBlock())) {
|
||||
if (!rewardChest.getBlock().equals(getHolderBlock(inventory.getTopInventory().getHolder()))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -141,4 +143,20 @@ public class RewardListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isValidContainer(Inventory inventory) {
|
||||
if (Version.isAtLeast(Version.MC1_12_1)) {
|
||||
return inventory.getHolder() instanceof Container;
|
||||
} else {
|
||||
return inventory.getHolder() instanceof Chest;
|
||||
}
|
||||
}
|
||||
|
||||
private static Block getHolderBlock(InventoryHolder holder) {
|
||||
if (Version.isAtLeast(Version.MC1_12_1)) {
|
||||
return ((Container) holder).getBlock();
|
||||
} else {
|
||||
return ((Chest) holder).getBlock();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user