Drop loot items if they are not taken out of the UI

This commit is contained in:
Daniel Saukel 2020-10-23 18:41:09 +02:00
parent 5fa360539d
commit 32a6651ecf

View File

@ -25,10 +25,13 @@ import de.erethon.dungeonsxl.player.DPlayerListener;
import de.erethon.dungeonsxl.util.ContainerAdapter; import de.erethon.dungeonsxl.util.ContainerAdapter;
import de.erethon.dungeonsxl.world.DGameWorld; import de.erethon.dungeonsxl.world.DGameWorld;
import de.erethon.dungeonsxl.world.block.RewardChest; import de.erethon.dungeonsxl.world.block.RewardChest;
import de.erethon.vignette.api.InventoryGUI;
import de.erethon.vignette.api.PaginatedInventoryGUI; import de.erethon.vignette.api.PaginatedInventoryGUI;
import de.erethon.vignette.api.component.Component;
import de.erethon.vignette.api.component.InventoryButton; import de.erethon.vignette.api.component.InventoryButton;
import de.erethon.vignette.api.layout.PaginatedFlowInventoryLayout; import de.erethon.vignette.api.layout.PaginatedFlowInventoryLayout;
import de.erethon.vignette.api.layout.PaginatedInventoryLayout.PaginationButtonPosition; import de.erethon.vignette.api.layout.PaginatedInventoryLayout.PaginationButtonPosition;
import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -37,6 +40,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -119,16 +123,28 @@ public class RewardListener implements Listener {
return; return;
} }
GlobalPlayer dPlayer = plugin.getPlayerCache().get(player); GlobalPlayer dPlayer = plugin.getPlayerCache().get(player);
if (plugin.getInstanceWorld(player.getWorld()) != null) { World world = player.getWorld();
Location location = player.getLocation();
if (plugin.getInstanceWorld(world) != null) {
return; return;
} }
Block block = player.getLocation().getBlock(); Block block = location.getBlock();
if (dPlayer.hasRewardItemsLeft() && !VanillaItem.NETHER_PORTAL.is(block.getRelative(0, 1, 0)) && !VanillaItem.NETHER_PORTAL.is(block.getRelative(0, -1, 0)) if (dPlayer.hasRewardItemsLeft() && !VanillaItem.NETHER_PORTAL.is(block.getRelative(0, 1, 0)) && !VanillaItem.NETHER_PORTAL.is(block.getRelative(0, -1, 0))
&& !VanillaItem.NETHER_PORTAL.is(block.getRelative(1, 0, 0)) && !VanillaItem.NETHER_PORTAL.is(block.getRelative(-1, 0, 0)) && !VanillaItem.NETHER_PORTAL.is(block.getRelative(1, 0, 0)) && !VanillaItem.NETHER_PORTAL.is(block.getRelative(-1, 0, 0))
&& !VanillaItem.NETHER_PORTAL.is(block.getRelative(0, 0, 1)) && !VanillaItem.NETHER_PORTAL.is(block.getRelative(0, 0, -1))) { && !VanillaItem.NETHER_PORTAL.is(block.getRelative(0, 0, 1)) && !VanillaItem.NETHER_PORTAL.is(block.getRelative(0, 0, -1))) {
PaginatedInventoryGUI lootInventory = new PaginatedInventoryGUI(DMessage.PLAYER_TREASURES.getMessage()); PaginatedInventoryGUI lootInventory = new PaginatedInventoryGUI(DMessage.PLAYER_TREASURES.getMessage());
PaginatedFlowInventoryLayout layout = new PaginatedFlowInventoryLayout(lootInventory, 54, PaginationButtonPosition.BOTTOM); PaginatedFlowInventoryLayout layout = new PaginatedFlowInventoryLayout(lootInventory, 54, PaginationButtonPosition.BOTTOM);
layout.setSwitchButtonLinePlaceholdersEnabled(true); layout.setSwitchButtonLinePlaceholdersEnabled(true);
lootInventory.setCloseListener(e -> {
for (Inventory inventory : lootInventory.getOpenedInventories()) {
for (int i = 0; i < 45; i++) {
ItemStack item = inventory.getItem(i);
if (item != null) {
world.dropItem(location, item);
}
}
}
});
lootInventory.setLayout(layout); lootInventory.setLayout(layout);
lootInventory.register(); lootInventory.register();
for (ItemStack item : dPlayer.getRewardItems()) { for (ItemStack item : dPlayer.getRewardItems()) {