diff --git a/DungeonsXL/plugin.yml b/DungeonsXL/plugin.yml index b59fbda1..ec8b65be 100644 --- a/DungeonsXL/plugin.yml +++ b/DungeonsXL/plugin.yml @@ -1,5 +1,5 @@ name: DungeonsXL -version: 2.8.5 +version: 2.9 main: com.dre.dungeonsxl.DungeonsXL authors: [Frank Baumann] softdepend: [Vault] diff --git a/DungeonsXL/src/com/dre/dungeonsxl/DLootInventory.java b/DungeonsXL/src/com/dre/dungeonsxl/DLootInventory.java new file mode 100644 index 00000000..ae24ecdc --- /dev/null +++ b/DungeonsXL/src/com/dre/dungeonsxl/DLootInventory.java @@ -0,0 +1,44 @@ +package com.dre.dungeonsxl; + +import java.util.concurrent.CopyOnWriteArrayList; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryView; +import org.bukkit.inventory.ItemStack; + +public class DLootInventory { + public static CopyOnWriteArrayList LootInventorys=new CopyOnWriteArrayList(); + + public Inventory inventory; + public InventoryView inventoryView; + public Player player; + + public long time; + + public DLootInventory(Player player, ItemStack[] istacks){ + LootInventorys.add(this); + + this.inventory = Bukkit.createInventory(player, InventoryType.CHEST); + for(ItemStack istack:istacks){ + if(istack!=null){ + this.inventory.addItem(istack); + } + } + this.player=player; + + + } + + + public static DLootInventory get(Player player) { + for(DLootInventory inventory:LootInventorys){ + if(inventory.player==player){ + return inventory; + } + } + return null; + } +} diff --git a/DungeonsXL/src/com/dre/dungeonsxl/DPlayer.java b/DungeonsXL/src/com/dre/dungeonsxl/DPlayer.java index 2e24d39f..b924ad5e 100644 --- a/DungeonsXL/src/com/dre/dungeonsxl/DPlayer.java +++ b/DungeonsXL/src/com/dre/dungeonsxl/DPlayer.java @@ -377,11 +377,7 @@ public class DPlayer { } public void addTreasure(){ - for(ItemStack istack:this.treasureInv.getContents()){ - if(istack!=null){ - this.player.getInventory().addItem(istack); - } - } + new DLootInventory(this.player,this.treasureInv.getContents()); } //Static public static void remove(DPlayer player){ diff --git a/DungeonsXL/src/com/dre/dungeonsxl/listener/PlayerListener.java b/DungeonsXL/src/com/dre/dungeonsxl/listener/PlayerListener.java index 376106f6..68a7b68e 100644 --- a/DungeonsXL/src/com/dre/dungeonsxl/listener/PlayerListener.java +++ b/DungeonsXL/src/com/dre/dungeonsxl/listener/PlayerListener.java @@ -11,6 +11,7 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerChatEvent; @@ -18,6 +19,7 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; @@ -25,6 +27,7 @@ import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.inventory.ItemStack; import com.dre.dungeonsxl.DGSign; import com.dre.dungeonsxl.DGroup; +import com.dre.dungeonsxl.DLootInventory; import com.dre.dungeonsxl.DPlayer; import com.dre.dungeonsxl.DPortal; import com.dre.dungeonsxl.DungeonsXL; @@ -330,7 +333,47 @@ public class PlayerListener implements Listener{ GameChest.onOpenInventory(event); } + @EventHandler + public void onInventoryClose(InventoryCloseEvent event){ + p.log("CLOSE!!!"); + Player player =(Player) event.getPlayer(); + for(DLootInventory inventory:DLootInventory.LootInventorys){ + if(event.getView()==inventory.inventoryView){ + if(System.currentTimeMillis()-inventory.time>1000){ + for(ItemStack istack:inventory.inventory.getContents()){ + if(istack!=null){ + player.getWorld().dropItem(player.getLocation(), istack); + } + } + + DLootInventory.LootInventorys.remove(inventory); + } + } + } + } + //Player move + @EventHandler + public void onPlayerMove(PlayerMoveEvent event){ + Player player=event.getPlayer(); + DLootInventory inventory=DLootInventory.get(player); + + if(inventory!=null){ + if(player.getLocation().getBlock().getType()!=Material.PORTAL){ + if( + player.getLocation().getBlock().getRelative(0, 1, 0).getType()!=Material.PORTAL && + player.getLocation().getBlock().getRelative(0, -1, 0).getType()!=Material.PORTAL && + player.getLocation().getBlock().getRelative(1, 0, 0).getType()!=Material.PORTAL && + player.getLocation().getBlock().getRelative(-1, 0, 0).getType()!=Material.PORTAL && + player.getLocation().getBlock().getRelative(0, 0, 1).getType()!=Material.PORTAL && + player.getLocation().getBlock().getRelative(0, 0, -1).getType()!=Material.PORTAL) + { + inventory.inventoryView=inventory.player.openInventory(inventory.inventory); + inventory.time=System.currentTimeMillis(); + } + } + } + } //Etc. ---------------------------------