mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-09 20:31:28 +01:00
Added a new loot inventory at the end of a dungeon
This commit is contained in:
parent
928b0e35af
commit
15e9db2216
@ -1,5 +1,5 @@
|
||||
name: DungeonsXL
|
||||
version: 2.8.5
|
||||
version: 2.9
|
||||
main: com.dre.dungeonsxl.DungeonsXL
|
||||
authors: [Frank Baumann]
|
||||
softdepend: [Vault]
|
||||
|
44
DungeonsXL/src/com/dre/dungeonsxl/DLootInventory.java
Normal file
44
DungeonsXL/src/com/dre/dungeonsxl/DLootInventory.java
Normal file
@ -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<DLootInventory> LootInventorys=new CopyOnWriteArrayList<DLootInventory>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -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){
|
||||
|
@ -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. ---------------------------------
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user