diff --git a/TwosideKeeper.jar b/TwosideKeeper.jar index cbfc695..f5a45a6 100644 Binary files a/TwosideKeeper.jar and b/TwosideKeeper.jar differ diff --git a/src/sig/plugin/TwosideKeeper/DeathManager.java b/src/sig/plugin/TwosideKeeper/DeathManager.java index 7784512..c368ef4 100644 --- a/src/sig/plugin/TwosideKeeper/DeathManager.java +++ b/src/sig/plugin/TwosideKeeper/DeathManager.java @@ -43,7 +43,9 @@ public class DeathManager { }},1); PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); //pd.deathloot.clear(); - pd.hasDied=false; + if (pd!=null) { + pd.hasDied=false; + } p.setCollidable(true); } public static boolean deathStructureExists(Player p) { diff --git a/src/sig/plugin/TwosideKeeper/DropDeathItems.java b/src/sig/plugin/TwosideKeeper/DropDeathItems.java index f1ee76a..d12a25d 100644 --- a/src/sig/plugin/TwosideKeeper/DropDeathItems.java +++ b/src/sig/plugin/TwosideKeeper/DropDeathItems.java @@ -3,6 +3,7 @@ package sig.plugin.TwosideKeeper; import java.util.List; import org.bukkit.Bukkit; +import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.entity.Item; import org.bukkit.entity.Player; @@ -33,7 +34,11 @@ public class DropDeathItems implements Runnable{ TwosideKeeper.log("Respawn and Dropping...", 2); while (contents.size()>0) { if (deathloc.getChunk().isLoaded()) { - Item it = deathloc.getWorld().dropItemNaturally(deathloc, contents.get(0)); + Item it = null; + do { + deathloc.getWorld().loadChunk(deathloc.getChunk()); + it=deathloc.getWorld().dropItemNaturally(deathloc, contents.get(0)); + TwosideKeeper.temporary_chunks.add(deathloc.getChunk());} while (it==null || !it.isValid()); it.setInvulnerable(true); TwosideKeeper.log("Dropping "+contents.get(0).toString()+" at Death location "+deathloc,2); contents.remove(0); @@ -41,6 +46,10 @@ public class DropDeathItems implements Runnable{ deathloc.getWorld().loadChunk(deathloc.getChunk()); } } + for (Chunk c : TwosideKeeper.temporary_chunks) { + c.unload(true); + } + TwosideKeeper.temporary_chunks.clear(); DeathManager.removeDeathStructure(p); return true; } diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java b/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java index d4c799c..f296367 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java @@ -3838,7 +3838,9 @@ public class GenericFunctions { public static boolean giveItem(Player p, ItemStack... items) { HashMap remaining = p.getInventory().addItem(items); if (remaining.isEmpty()) { - SoundUtils.playGlobalSound(p.getLocation(), Sound.ENTITY_ITEM_PICKUP, 1.0f, 1.0f); + if (items[0]!=null) { + SoundUtils.playGlobalSound(p.getLocation(), Sound.ENTITY_ITEM_PICKUP, 0.6f, SoundUtils.DetermineItemPitch(items[0])); + } return true; } else { for (Integer i : remaining.keySet()) { diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/InventoryUtils.java b/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/InventoryUtils.java index ca49e88..b132312 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/InventoryUtils.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/InventoryUtils.java @@ -6,6 +6,7 @@ import java.util.List; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; @@ -92,4 +93,13 @@ public class InventoryUtils { } return false; } + public static boolean hasFullInventory(Player p) { + ItemStack[] inv = p.getInventory().getStorageContents(); + for (ItemStack i : inv) { + if (i==null || i.getType()==Material.AIR) { + return false; + } + } + return true; + } } diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/SoundUtils.java b/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/SoundUtils.java index d62aea2..2e65d49 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/SoundUtils.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/SoundUtils.java @@ -1,9 +1,14 @@ package sig.plugin.TwosideKeeper.HelperStructures.Utils; +import java.util.Random; + import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import sig.plugin.TwosideKeeper.TwosideKeeper; public class SoundUtils { @@ -41,5 +46,15 @@ public class SoundUtils { SoundUtils.playLocalSound(p, sound, vol, pitch); } } - + + public static float DetermineItemPitch(ItemStack item) { + double pitch = 1.0f; + double variance = 0.1f; + Random r = new Random(); + r.setSeed(item.getType().name().hashCode()); + double newnumb = r.nextFloat(); + double newpitch = pitch+variance-(newnumb*(variance*2d)); + TwosideKeeper.log("Next float:"+newnumb+" | Pitch: "+newpitch, 5); + return (float)newpitch; + } } diff --git a/src/sig/plugin/TwosideKeeper/PlayerStructure.java b/src/sig/plugin/TwosideKeeper/PlayerStructure.java index 636e1a6..ce48904 100644 --- a/src/sig/plugin/TwosideKeeper/PlayerStructure.java +++ b/src/sig/plugin/TwosideKeeper/PlayerStructure.java @@ -367,15 +367,15 @@ public class PlayerStructure { this.lastattacked = TwosideKeeper.getServerTickTime(); this.lastcombat = TwosideKeeper.getServerTickTime(); - /*if (this.hasDied) { + if (this.hasDied) { List deathlootlist = new ArrayList(); - ConfigurationSection deathlootsection = workable.getConfigurationSection("deathloot"); - for (int i=0;i log_messages=new ArrayList(); public static List temporary_lava_list = new ArrayList(); + public static List temporary_chunks = new ArrayList(); long LastClearStructureTime = 0; @@ -872,6 +873,21 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } log(ChatColor.YELLOW+" "+(System.currentTimeMillis()-betweentime)+"ms",CLEANUP_DEBUG); betweentime = System.currentTimeMillis(); + log("Cleaning up Open Player Death Inventories ["+Bukkit.getOnlinePlayers().size()+"]",CLEANUP_DEBUG); + for (Player p : Bukkit.getOnlinePlayers()) { + if (p.getOpenInventory()!=null && p.getOpenInventory().getTopInventory()!=null && + p.getOpenInventory().getTopInventory().getTitle()!=null && + DeathManager.deathStructureExists(p) && p.getOpenInventory().getTopInventory().getTitle().contains("Death Loot")) { + Location deathloc = DeathManager.getDeathStructure(p).deathloc; + DropDeathInventoryContents(p, deathloc); + } + } + log(ChatColor.YELLOW+" "+(System.currentTimeMillis()-betweentime)+"ms",CLEANUP_DEBUG); + betweentime = System.currentTimeMillis(); + log("Cleaning up Temporary Chunks ["+temporary_chunks.size()+"]",CLEANUP_DEBUG); + temporary_chunks.clear(); + log(ChatColor.YELLOW+" "+(System.currentTimeMillis()-betweentime)+"ms",CLEANUP_DEBUG); + betweentime = System.currentTimeMillis(); long endtime = System.currentTimeMillis(); log("Cleanup Maintenance completed. Total Time: "+(endtime-starttime)+"ms.",CLEANUP_DEBUG); } @@ -1539,6 +1555,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { @EventHandler(priority=EventPriority.LOW,ignoreCancelled = true) public void onPlayerLeave(PlayerQuitEvent ev) { + Player p = ev.getPlayer(); TwosideSpleefGames.PassEvent(ev); for (EliteMonster em : elitemonsters) { em.runPlayerLeaveEvent(ev.getPlayer()); @@ -1549,11 +1566,12 @@ public class TwosideKeeper extends JavaPlugin implements Listener { les.setGlow(ev.getPlayer(), null); } - for (Player p :Bukkit.getOnlinePlayers()) { - if (p!=null) { - SoundUtils.playLocalSound(p, Sound.BLOCK_NOTE_PLING, 8, 0.7f); + for (Player pl :Bukkit.getOnlinePlayers()) { + if (pl!=null) { + SoundUtils.playLocalSound(pl, Sound.BLOCK_NOTE_PLING, 8, 0.7f); } } + Bukkit.getScheduler().scheduleSyncDelayedTask(this, new ShutdownServerForUpdate(),5); //Find the player that is getting removed. @@ -3576,27 +3594,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { amounttotake = diff; givePlayerBankMoney(p,-amounttotake); } - Inventory contents = Bukkit.createInventory(p, 45); - log("Contents list includes ",2); - for (int i=0;i list=new ArrayList(); - for (int i=0;i list = PrepareDropItems(p); + deathloc.getWorld().loadChunk(deathloc.getChunk()); + while (list.size()>0) { + if (deathloc.getChunk().isLoaded()) { + Item it = null; + do { + deathloc.getWorld().loadChunk(deathloc.getChunk()); + it=deathloc.getWorld().dropItemNaturally(deathloc, list.get(0)); + TwosideKeeper.temporary_chunks.add(deathloc.getChunk()); + } while (it==null || !it.isValid()); + it.setInvulnerable(true); + TwosideKeeper.log("Dropping "+list.get(0).toString()+" at Death location "+deathloc,2); + list.remove(0); + } else { + deathloc.getWorld().loadChunk(deathloc.getChunk()); + } + } + for (Chunk c : TwosideKeeper.temporary_chunks) { + c.unload(true); + } + TwosideKeeper.temporary_chunks.clear(); + } + public void DropDeathInventoryContents(Player p, Location deathloc, int tickdelay) { + List list = PrepareDropItems(p); + Bukkit.getScheduler().scheduleSyncDelayedTask(this,new DropDeathItems(p,list,deathloc),tickdelay); + } + public List PrepareDropItems(Player p) { + Inventory contents = Bukkit.createInventory(p, 45); + log("Contents list includes ",2); + for (int i=0;i list=new ArrayList(); + for (int i=0;i ents = p.getNearbyEntities(0.25, 0.25, 0.25); for (Entity ent : ents) { if (ent instanceof Item && GenericFunctions.itemCanBeSuckedUp((Item)ent)) { Item it = (Item)ent; - ItemStack[] remaining = InventoryUtils.insertItemsInFilterCube(p, it.getItemStack()); - if (remaining.length==0) { - it.remove(); - SoundUtils.playGlobalSound(p.getLocation(), Sound.ENTITY_ITEM_PICKUP, 1.0f, 1.0f); - return; - } + if (it.getPickupDelay()