diff --git a/BankEconomyMod/src/me/kaZep/Base/Main.java b/BankEconomyMod/src/me/kaZep/Base/Main.java index 0dfa6df..623f02d 100644 --- a/BankEconomyMod/src/me/kaZep/Base/Main.java +++ b/BankEconomyMod/src/me/kaZep/Base/Main.java @@ -143,6 +143,7 @@ public class Main extends JavaPlugin public long check_lights_time=0; public long check_spleef_game=0; public static boolean ender_cube_active=true; + public static boolean book_shelf_active=true; public boolean harrowing_night=false; public double randomitemchance = 800; public static long SERVER_TICK_TIME = 0; @@ -3751,6 +3752,15 @@ public void payDay(int time) getLogger().log(Level.SEVERE, "Could not save chunk config to " + base, ex); } } + + public FileConfiguration reloadBookshelfConfig(int blockx,int blocky, int blockz) + { + File base; + FileConfiguration myFile; + base = new File(getDataFolder()+"/bookshelf", "bookshelf"+blockx+"_"+blocky+"_"+blockz+".yml"); + myFile = YamlConfiguration.loadConfiguration(base); + return myFile; + } public FileConfiguration reloadItemCubeConfig(int cubenumb) { @@ -3761,6 +3771,19 @@ public void payDay(int time) return myFile; } + public void saveBookshelfConfig(FileConfiguration filer, int blockx ,int blocky, int blockz) { + File base; + base = new File(getDataFolder()+"/bookshelf", "bookshelf"+blockx+"_"+blocky+"_"+blockz+".yml"); + if ((filer == null) || (base == null)) + return; + try + { + filer.save(base); + } catch (IOException ex) { + getLogger().log(Level.SEVERE, "Could not save Bookshelf config to " + base, ex); + } + } + public void saveItemCubeConfig(FileConfiguration filer, int cubenumb) { File base; base = new File(getDataFolder()+"/item-cube", "itemcube"+cubenumb+".yml"); diff --git a/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java b/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java index 35e03ca..265e321 100644 --- a/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java +++ b/BankEconomyMod/src/me/kaZep/Base/PlayerListener.java @@ -81,6 +81,7 @@ import org.bukkit.entity.Skeleton.SkeletonType; import org.bukkit.entity.Slime; import org.bukkit.entity.ThrownPotion; import org.bukkit.entity.Wither; +import org.bukkit.entity.WitherSkull; import org.bukkit.entity.Wolf; import org.bukkit.entity.Zombie; import org.bukkit.event.Event.Result; @@ -9273,6 +9274,17 @@ implements Listener } if (e.getCause()==DamageCause.WITHER) { // For each Witherless Rose, add a multiplicative 25% chance to negate this tick of wither damage. + if (p.hasPotionEffect(PotionEffectType.WITHER)) { + Collection pots = p.getActivePotionEffects(); + int witherlevel=0; + for (PotionEffect effect : pots) { + if (effect.getType().getName().equalsIgnoreCase("wither")) { + witherlevel = effect.getAmplifier(); + break; + } + } + e.setDamage(witherlevel*e.getDamage()); + } if (Math.random() > Math.pow(0.75, this.plugin.getWitherlessRoseCount(p))) { e.setCancelled(true); } @@ -9566,6 +9578,56 @@ implements Listener } //**********************************//Player buffs end boolean hitByPoweredMob=false; + if ((e.getDamager() instanceof WitherSkull) || (e.getDamager() instanceof Wither)) { + if (e.getEntity() instanceof Player) { + final Player p = (Player)e.getEntity(); + final Collection pots = p.getActivePotionEffects(); + Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, new Runnable() { + @Override + public void run() { + int witherlevel=0, witherduration=0; + for (PotionEffect effect : pots) { + if (effect.getType().getName().equalsIgnoreCase("wither")) { + witherlevel = effect.getAmplifier(); + witherduration = effect.getDuration(); + break; + } + } + //Bukkit.getLogger().info("Wither level adjusted from "+witherlevel+" to "+(++witherlevel)+"."); + p.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, witherduration, witherlevel++),true); + } + },1); + } + } + if (e.getDamager() instanceof Skeleton || ((e.getDamager() instanceof Projectile) && ((Projectile)e.getDamager()).getShooter() instanceof Skeleton)) { + Skeleton s = null; + if (e.getDamager() instanceof Projectile) { + s = (Skeleton)((Projectile)e.getDamager()).getShooter(); + } else { + s = (Skeleton)e.getDamager(); + } + if (s.getSkeletonType()==SkeletonType.WITHER) { + if (e.getEntity() instanceof Player) { + final Player p = (Player)e.getEntity(); + final Collection pots = p.getActivePotionEffects(); + Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, new Runnable() { + @Override + public void run() { + int witherlevel=0, witherduration=0; + for (PotionEffect effect : pots) { + if (effect.getType().getName().equalsIgnoreCase("wither")) { + witherlevel = effect.getAmplifier(); + witherduration = effect.getDuration(); + break; + } + } + //Bukkit.getLogger().info("Wither level adjusted from "+witherlevel+" to "+(++witherlevel)+"."); + p.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, witherduration, witherlevel++),true); + } + },1); + } + } + } if (e.getEntity() instanceof LivingEntity) { final LivingEntity l = (LivingEntity)e.getEntity(); if (e.getDamager() instanceof Monster) { @@ -11916,6 +11978,27 @@ implements Listener @EventHandler public void onInventoryDragEvent(InventoryDragEvent e) { Player p = (Player)e.getWhoClicked(); + if (isViewingBookshelf(p)) { + if (this.plugin.book_shelf_active) { + final Player p2 = p; + this.plugin.book_shelf_active=false; + int inven_amount=0; + int item_count=0; + for (int i=0;i<9;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+"."); + Bookshelf_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); + } + } if (isViewingEnderCube(p)) { if (this.plugin.ender_cube_active) { final Player p2 = p; @@ -11966,6 +12049,17 @@ implements Listener } } } else + if (e.getInventory().getName().contains("Bookshelf")) { + int identifier=-1; + //Get idenfitier. + String[] ident_string=e.getInventory().getTitle().substring(e.getInventory().getTitle().indexOf("#")).replace("#", "").split("_"); + //We are going to save the contents of this inventory appropriately. + FileConfiguration f = this.plugin.reloadBookshelfConfig(Integer.valueOf(ident_string[0]),Integer.valueOf(ident_string[1]),Integer.valueOf(ident_string[2])); + for (int i=0;i0) { + //Bukkit.getLogger().info("Check inventory title: "+Bukkit.getOnlinePlayers()[i].getOpenInventory().getTopInventory().getTitle().substring(Bukkit.getOnlinePlayers()[i].getOpenInventory().getTopInventory().getTitle().indexOf("#")).replace("#", "")); + if (Bukkit.getOnlinePlayers()[i].getOpenInventory().getTopInventory().getTitle().substring(Bukkit.getOnlinePlayers()[i].getOpenInventory().getTopInventory().getTitle().indexOf("#")).replace("#", "").equalsIgnoreCase(bookshelf_id.getBlockX()+"_"+bookshelf_id.getBlockY()+"_"+bookshelf_id.getBlockZ())) { + //It is! We need to close it out and re-open with the updated properties of the cube. + final int i2 = i; + final Location bookshelf_id2 = bookshelf_id; + Bookshelf_load(Bukkit.getOnlinePlayers()[i2], bookshelf_id2); + //Bukkit.getLogger().info("Re-loading Item Cube for "+Bukkit.getOnlinePlayers()[i].getName()); + } + } + } + } + } + } private void ItemCube_addSameEnderCube(ItemStack add_item, int cube_id, Player player) { //Helper function for ItemCube_add. @@ -16483,6 +16710,16 @@ implements Listener } } + private void Bookshelf_save(Player p, Location loc) { + FileConfiguration f = this.plugin.reloadBookshelfConfig(loc.getBlockX(),loc.getBlockY(),loc.getBlockZ()); + int slots = -1; + String heading = ""; + for (int i=0;i