From 21cff3cb5133d936be9fd59669164243d4e4a676 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Wed, 11 Dec 2013 06:14:48 -0700 Subject: [PATCH] Ender Item Cubes functioning 99.9%. All synchronization issues + duping issues fixed, without the closeInventory()/openInventory() silly lazy fix. Also made Item Cubes able to be opened inside of other Item Cubes. --- BankEconomyMod/plugin.yml | 2 + BankEconomyMod/src/me/kaZep/Base/Main.java | 3 + .../src/me/kaZep/Base/PlayerBuffData.java | 6 +- .../src/me/kaZep/Base/PlayerListener.java | 153 ++++++++++++++---- 4 files changed, 136 insertions(+), 28 deletions(-) diff --git a/BankEconomyMod/plugin.yml b/BankEconomyMod/plugin.yml index e295dcb..9107e8f 100644 --- a/BankEconomyMod/plugin.yml +++ b/BankEconomyMod/plugin.yml @@ -25,6 +25,8 @@ commands: description: Toggles or untoggles events. ticktime: description: Displays the server tick time. + rename: + description: Renames a name tag item. line: description: Gives the player a line builder tool. rectangle: diff --git a/BankEconomyMod/src/me/kaZep/Base/Main.java b/BankEconomyMod/src/me/kaZep/Base/Main.java index 53e48e8..1ab98b3 100644 --- a/BankEconomyMod/src/me/kaZep/Base/Main.java +++ b/BankEconomyMod/src/me/kaZep/Base/Main.java @@ -141,6 +141,7 @@ public class Main extends JavaPlugin public long check_nether_time=0; public long check_lights_time=0; public long check_spleef_game=0; + public static boolean ender_cube_active=true; public boolean harrowing_night=false; public double randomitemchance = 800; public static long SERVER_TICK_TIME = 0; @@ -5518,6 +5519,7 @@ public void payDay(int time) newLoreData.add(LoreData.get(i)); LoreData.remove(i); i--; + break; } } } @@ -5529,6 +5531,7 @@ public void payDay(int time) newLoreData.add(LoreData.get(i)); LoreData.remove(i); i--; + break; } } } diff --git a/BankEconomyMod/src/me/kaZep/Base/PlayerBuffData.java b/BankEconomyMod/src/me/kaZep/Base/PlayerBuffData.java index d8479c7..679ae64 100644 --- a/BankEconomyMod/src/me/kaZep/Base/PlayerBuffData.java +++ b/BankEconomyMod/src/me/kaZep/Base/PlayerBuffData.java @@ -196,7 +196,11 @@ public class PlayerBuffData { double temphp=0; temphp = p.getHealth(); p.setMaxHealth(base_hplv-extra_hp); - p.setHealth(temphp); + if (temphp>p.getMaxHealth()) { + p.setHealth(p.getMaxHealth()); + } else { + p.setHealth(temphp); + } } //Send new speed totals so the player's speed can be manually adjusted. diff --git a/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java b/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java index 3d8864d..ac1e84f 100644 --- a/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java +++ b/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java @@ -130,6 +130,7 @@ import org.bukkit.event.inventory.FurnaceExtractEvent; import org.bukkit.event.inventory.FurnaceSmeltEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.inventory.InventoryDragEvent; import org.bukkit.event.inventory.InventoryEvent; import org.bukkit.event.inventory.InventoryInteractEvent; import org.bukkit.event.inventory.InventoryMoveItemEvent; @@ -916,14 +917,14 @@ implements Listener if (Math.random()<1.0d/enchants.length) { if (enchants[j]==33) { if (e.getItem().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS)==0) { - e.getItem().addEnchantment(Enchantment.getById(enchants[j]), (int)(Math.random()*5)+1); - finalitem.addEnchantment(Enchantment.getById(enchants[j]), (int)(Math.random()*5)+1); + e.getItem().addUnsafeEnchantment(Enchantment.getById(enchants[j]), (int)(Math.random()*5)+1); + finalitem.addUnsafeEnchantment(Enchantment.getById(enchants[j]), (int)(Math.random()*5)+1); } } if (enchants[j]==35) { if (e.getItem().getEnchantmentLevel(Enchantment.SILK_TOUCH)==0) { - e.getItem().addEnchantment(Enchantment.getById(enchants[j]), (int)(Math.random()*5)+1); - finalitem.addEnchantment(Enchantment.getById(enchants[j]), (int)(Math.random()*5)+1); + e.getItem().addUnsafeEnchantment(Enchantment.getById(enchants[j]), (int)(Math.random()*5)+1); + finalitem.addUnsafeEnchantment(Enchantment.getById(enchants[j]), (int)(Math.random()*5)+1); } } } @@ -1646,10 +1647,6 @@ implements Listener this.plugin.gainMoneyExp(p,"Breeder",0.005,1); } } - if (e.getEntity().getType()==EntityType.MUSHROOM_COW) { - Bukkit.getWorld("world").spawnEntity(e.getEntity().getLocation(), EntityType.COW); - } - Bukkit.getWorld("world").spawnEntity((Location) e.getEntity(), EntityType.COW); } @EventHandler @@ -11634,6 +11631,32 @@ implements Listener } } }*/ + + @EventHandler + public void onInventoryDragEvent(InventoryDragEvent e) { + Player p = (Player)e.getWhoClicked(); + if (isViewingEnderCube(p)) { + if (this.plugin.ender_cube_active) { + final Player p2 = p; + this.plugin.ender_cube_active=false; + int inven_amount=0; + int item_count=0; + for (int i=0;i<27;i++) { + if (e.getInventory().getContents()[i]!=null) { + inven_amount+=e.getInventory().getContents()[i].getAmount(); + item_count++; + //Bukkit.getLogger().info("Check at "+e.getInventory().getContents()[i].toString()); + } + } + //Bukkit.getLogger().info("Marked at "+inven_amount+"."); + ItemCube_attemptUpdate(inven_amount,item_count,p2); + } else { + //Bukkit.getLogger().info("Cannot perform! We are waiting on an update."); + e.setCancelled(true); + e.setResult(Result.DENY); + } + } + } @EventHandler public void onInventoryCloseEvent(InventoryCloseEvent e) { @@ -11671,6 +11694,8 @@ implements Listener Bukkit.getLogger().severe("SEVERE error when saving Item Cube contents! Could not get ID!"); return; } + //Do an item cube load, just to be safe. + //ItemCube_load(p, identifier, Cube.LARGE); //We are going to save the contents of this inventory appropriately. FileConfiguration f = this.plugin.reloadItemCubeConfig(identifier); for (int i=0;i0) { if (Integer.valueOf(Bukkit.getOnlinePlayers()[i].getOpenInventory().getTopInventory().getTitle().substring(Bukkit.getOnlinePlayers()[i].getOpenInventory().getTopInventory().getTitle().indexOf("#")).replace("#", ""))==cube_id) { - //It is! We need to close it out and re-open with the updated properties of the cube. - ItemCube_load(Bukkit.getOnlinePlayers()[i], cube_id, Cube.ENDER); + //It is! We need to close it out and re-open with the updated properties of the cube. + final int i2 = i; + final int cube_id2 = cube_id; + ItemCube_load(Bukkit.getOnlinePlayers()[i2], cube_id2, Cube.ENDER); + //Bukkit.getLogger().info("Re-loading Item Cube for "+Bukkit.getOnlinePlayers()[i].getName()); } } } @@ -16151,8 +16248,10 @@ implements Listener //items.add(f.getItemStack("item-"+i)); if (f.contains("item-"+i)) { p.getOpenInventory().getTopInventory().addItem(f.getItemStack("item-"+i)); + //Bukkit.getLogger().info("Reloading item "+f.getItemStack("item-"+i).toString()); } } + p.updateInventory(); } private ItemStack ItemCube_add(Player p, int identifier, Cube size, ItemStack insert_item) {