From 159ec3f04d53802904b206f825c8b08d957d7919 Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Tue, 8 Jan 2013 09:35:41 -0500 Subject: [PATCH 01/15] Pass location & type as params, rather than calling inside the function. --- .../gmail/nossr50/skills/mining/BlastMining.java | 11 ++++++++--- .../com/gmail/nossr50/skills/mining/Mining.java | 14 +++++++------- ...Handler.java => MiningBlockEventHandler.java} | 16 ++++++++++++---- .../nossr50/skills/mining/MiningManager.java | 6 +++--- 4 files changed, 30 insertions(+), 17 deletions(-) rename src/main/java/com/gmail/nossr50/skills/mining/{MiningDropsBlockHandler.java => MiningBlockEventHandler.java} (62%) diff --git a/src/main/java/com/gmail/nossr50/skills/mining/BlastMining.java b/src/main/java/com/gmail/nossr50/skills/mining/BlastMining.java index f4f73ea09..008020a56 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/BlastMining.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/BlastMining.java @@ -7,6 +7,7 @@ import java.util.List; import java.util.Random; import org.bukkit.ChatColor; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -57,15 +58,17 @@ public class BlastMining { while (oresIterator.hasNext()) { Block temp = oresIterator.next(); + Location tempLocation = temp.getLocation(); + Material tempType = temp.getType(); if (random.nextFloat() < (yield + oreBonus)) { blocksDropped.add(temp); - Mining.miningDrops(temp); + Mining.miningDrops(temp, tempLocation, tempType); if (!mcMMO.placeStore.isTrue(temp)) { for (int i = 1 ; i < extraDrops ; i++) { blocksDropped.add(temp); - Mining.miningDrops(temp); + Mining.miningDrops(temp, tempLocation, tempType); } } } @@ -76,9 +79,11 @@ public class BlastMining { while (debrisIterator.hasNext()) { Block temp = debrisIterator.next(); + Location tempLocation = temp.getLocation(); + Material tempType = temp.getType(); if (random.nextFloat() < (yield - debrisReduction)) - Mining.miningDrops(temp); + Mining.miningDrops(temp, tempLocation, tempType); } } diff --git a/src/main/java/com/gmail/nossr50/skills/mining/Mining.java b/src/main/java/com/gmail/nossr50/skills/mining/Mining.java index a6ea8c8cb..e8f431a57 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/Mining.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/Mining.java @@ -201,10 +201,10 @@ public class Mining { * Handle double drops when using Silk Touch. * * @param block The block to process drops for + * @param location The location of the block + * @param type The material type of the block */ - protected static void silkTouchDrops(Block block) { - Location location = block.getLocation(); - Material type = block.getType(); + protected static void silkTouchDrops(Block block, Location location, Material type) { ItemStack item = new ItemStack(type); switch (type) { @@ -215,7 +215,7 @@ public class Mining { case NETHERRACK: case OBSIDIAN: case SANDSTONE: - miningDrops(block); + miningDrops(block, location, type); break; case COAL_ORE: @@ -276,10 +276,10 @@ public class Mining { * Drop items from Mining & Blast Mining skills. * * @param block The block to process drops for + * @param location The location of the block + * @param type The material type of the block */ - protected static void miningDrops(Block block) { - Location location = block.getLocation(); - Material type = block.getType(); + protected static void miningDrops(Block block, Location location, Material type) { ItemStack item = new ItemStack(type); switch (type) { diff --git a/src/main/java/com/gmail/nossr50/skills/mining/MiningDropsBlockHandler.java b/src/main/java/com/gmail/nossr50/skills/mining/MiningBlockEventHandler.java similarity index 62% rename from src/main/java/com/gmail/nossr50/skills/mining/MiningDropsBlockHandler.java rename to src/main/java/com/gmail/nossr50/skills/mining/MiningBlockEventHandler.java index 7c0ce5500..13152bde0 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningDropsBlockHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningBlockEventHandler.java @@ -1,19 +1,27 @@ package com.gmail.nossr50.skills.mining; +import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.enchantments.Enchantment; import com.gmail.nossr50.util.Misc; -public class MiningDropsBlockHandler { +public class MiningBlockEventHandler { private MiningManager manager; + private Block block; + private Location blockLocation; + private Material blockType; protected int skillModifier; - protected MiningDropsBlockHandler(MiningManager manager, Block block) { + protected MiningBlockEventHandler(MiningManager manager, Block block) { this.manager = manager; + this.block = block; + this.blockLocation = block.getLocation(); + this.blockType = block.getType(); calculateSkillModifier(); } @@ -30,10 +38,10 @@ public class MiningDropsBlockHandler { */ protected void processDrops() { if (manager.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) { - Mining.silkTouchDrops(block); + Mining.silkTouchDrops(block, blockLocation, blockType); } else { - Mining.miningDrops(block); + Mining.miningDrops(block, blockLocation, blockType); } } } diff --git a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java index db21ff5dc..daae9d75c 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java @@ -38,17 +38,17 @@ public class MiningManager { return; } - MiningDropsBlockHandler blockHandler = new MiningDropsBlockHandler(this, block); + MiningBlockEventHandler eventHandler = new MiningBlockEventHandler(this, block); int randomChance = 100; if (Permissions.luckyMining(player)) { randomChance = (int) (randomChance * 0.75); } - float chance = (float) (((double) Mining.DOUBLE_DROPS_MAX_CHANCE / Mining.DOUBLE_DROPS_MAX_BONUS_LEVEL) * blockHandler.skillModifier); + float chance = (float) (((double) Mining.DOUBLE_DROPS_MAX_CHANCE / Mining.DOUBLE_DROPS_MAX_BONUS_LEVEL) * eventHandler.skillModifier); if (chance > Mining.getRandom().nextInt(randomChance)) { - blockHandler.processDrops(); + eventHandler.processDrops(); } } From aee4bcd65efbb16e10026acd892080659dfb87fb Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Tue, 8 Jan 2013 09:42:37 -0500 Subject: [PATCH 02/15] More mining restructuring. --- .../com/gmail/nossr50/skills/mining/BlastMining.java | 2 +- .../java/com/gmail/nossr50/skills/mining/Mining.java | 5 +---- .../nossr50/skills/mining/MiningBlockEventHandler.java | 4 ++++ .../com/gmail/nossr50/skills/mining/MiningManager.java | 10 +++++++--- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/mining/BlastMining.java b/src/main/java/com/gmail/nossr50/skills/mining/BlastMining.java index 008020a56..232dd4cf6 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/BlastMining.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/BlastMining.java @@ -178,7 +178,7 @@ public class BlastMining { for (Block block : xp) { if (!mcMMO.placeStore.isTrue(block)) { - Mining.miningXP(player, block); + Mining.miningXP(player, Users.getProfile(player), block, block.getType()); } } } diff --git a/src/main/java/com/gmail/nossr50/skills/mining/Mining.java b/src/main/java/com/gmail/nossr50/skills/mining/Mining.java index e8f431a57..16743c9ff 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/Mining.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/Mining.java @@ -38,10 +38,7 @@ public class Mining { * @param player The player to award XP to * @param block The block to award XP for */ - public static void miningXP(Player player, Block block) { - PlayerProfile profile = Users.getProfile(player); - Material type = block.getType(); - + protected static void miningXP(Player player, PlayerProfile profile, Block block, Material type) { int xp = 0; switch (type) { diff --git a/src/main/java/com/gmail/nossr50/skills/mining/MiningBlockEventHandler.java b/src/main/java/com/gmail/nossr50/skills/mining/MiningBlockEventHandler.java index 13152bde0..dedd33da6 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningBlockEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningBlockEventHandler.java @@ -44,4 +44,8 @@ public class MiningBlockEventHandler { Mining.miningDrops(block, blockLocation, blockType); } } + + protected void processXP() { + Mining.miningXP(manager.getPlayer(), manager.getProfile(), block, blockType); + } } diff --git a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java index daae9d75c..ae4166552 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java @@ -32,14 +32,14 @@ public class MiningManager { return; } - Mining.miningXP(player, block); + MiningBlockEventHandler eventHandler = new MiningBlockEventHandler(this, block); + + eventHandler.processXP(); if (!Permissions.miningDoubleDrops(player)) { return; } - MiningBlockEventHandler eventHandler = new MiningBlockEventHandler(this, block); - int randomChance = 100; if (Permissions.luckyMining(player)) { randomChance = (int) (randomChance * 0.75); @@ -63,4 +63,8 @@ public class MiningManager { protected Player getPlayer() { return player; } + + protected PlayerProfile getProfile() { + return profile; + } } From b99d26108472fd4b59fdd35eeaf2cce746303bf9 Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Tue, 8 Jan 2013 10:45:49 -0500 Subject: [PATCH 03/15] Remove our workaround for NBT tag issues since Bukkit fixed it. --- .../gmail/nossr50/skills/repair/Repair.java | 29 ------------------- 1 file changed, 29 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/repair/Repair.java b/src/main/java/com/gmail/nossr50/skills/repair/Repair.java index ec352ccf9..65f57c348 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/Repair.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/Repair.java @@ -108,7 +108,6 @@ public class Repair { is.removeEnchantment(x); } player.sendMessage(LocaleLoader.getString("Repair.Arcane.Lost")); - clearEnchantTag(is); return; } @@ -142,7 +141,6 @@ public class Repair { if (newEnchants.isEmpty()) { player.sendMessage(LocaleLoader.getString("Repair.Arcane.Fail")); - clearEnchantTag(is); } else if (downgraded || newEnchants.size() < enchants.size()) { player.sendMessage(LocaleLoader.getString("Repair.Arcane.Downgrade")); @@ -152,33 +150,6 @@ public class Repair { } } - private static void clearEnchantTag(ItemStack is) { - Object o; - Class c; - Field f; - - o = is; - c = o.getClass(); - - try { - f = c.getDeclaredField("handle"); - f.setAccessible(true); - o = f.get(o); - - c = o.getClass(); - f = c.getDeclaredField("tag"); - o = f.get(o); - - c = o.getClass(); - f = c.getDeclaredField("map"); - f.setAccessible(true); - Map tagMap = (Map) f.get(o); - - tagMap.remove("ench"); - } - catch(Exception e) {} - } - /** * Gets chance of keeping enchantment during repair. * From 753652dcf92dce459d2affcbe8558226cc2d6c2e Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Tue, 8 Jan 2013 10:46:19 -0500 Subject: [PATCH 04/15] More mining updates. --- src/main/java/com/gmail/nossr50/skills/mining/Mining.java | 1 - .../java/com/gmail/nossr50/skills/mining/MiningManager.java | 5 ----- 2 files changed, 6 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/mining/Mining.java b/src/main/java/com/gmail/nossr50/skills/mining/Mining.java index 16743c9ff..b8f6bde1a 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/Mining.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/Mining.java @@ -22,7 +22,6 @@ import com.gmail.nossr50.spout.SpoutSounds; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.ModChecks; import com.gmail.nossr50.util.Skills; -import com.gmail.nossr50.util.Users; public class Mining { private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); diff --git a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java index ae4166552..7cf0740ed 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java @@ -13,7 +13,6 @@ public class MiningManager { private Player player; private PlayerProfile profile; private int skillLevel; - private Permissions permissionsInstance; public MiningManager (Player player) { this.player = player; @@ -56,10 +55,6 @@ public class MiningManager { return skillLevel; } - protected Permissions getPermissionsInstance() { - return permissionsInstance; - } - protected Player getPlayer() { return player; } From 1a2dfb9b19f0aa1213ebf2df865ed79f18648791 Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Tue, 8 Jan 2013 10:48:30 -0500 Subject: [PATCH 05/15] Fixed parameterization issue. --- .../nossr50/util/blockmeta/chunkmeta/HashChunkManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/util/blockmeta/chunkmeta/HashChunkManager.java b/src/main/java/com/gmail/nossr50/util/blockmeta/chunkmeta/HashChunkManager.java index c7a7d18cf..5e55934b8 100755 --- a/src/main/java/com/gmail/nossr50/util/blockmeta/chunkmeta/HashChunkManager.java +++ b/src/main/java/com/gmail/nossr50/util/blockmeta/chunkmeta/HashChunkManager.java @@ -167,8 +167,8 @@ public class HashChunkManager implements ChunkManager { if(in != null) { store.put(world.getName() + "," + cx + "," + cz, in); - List mobs = in.getSpawnedMobs(); - List pets = in.getSpawnedPets(); + List mobs = in.getSpawnedMobs(); + List pets = in.getSpawnedPets(); if(mobs.isEmpty() && pets.isEmpty()) return; From 84994c2b2f309a4ee1decb69f2c547f8e0525912 Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Tue, 8 Jan 2013 10:50:37 -0500 Subject: [PATCH 06/15] Remove a few unused imports & variables. --- src/main/java/com/gmail/nossr50/skills/repair/Repair.java | 1 - src/main/java/com/gmail/nossr50/util/Database.java | 3 --- src/main/java/com/gmail/nossr50/util/Permissions.java | 2 -- 3 files changed, 6 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/repair/Repair.java b/src/main/java/com/gmail/nossr50/skills/repair/Repair.java index 65f57c348..7e2a2f330 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/Repair.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/Repair.java @@ -1,6 +1,5 @@ package com.gmail.nossr50.skills.repair; -import java.lang.reflect.Field; import java.util.Map; import java.util.Map.Entry; import java.util.Random; diff --git a/src/main/java/com/gmail/nossr50/util/Database.java b/src/main/java/com/gmail/nossr50/util/Database.java index 16a60f5fe..8f94d5d1d 100644 --- a/src/main/java/com/gmail/nossr50/util/Database.java +++ b/src/main/java/com/gmail/nossr50/util/Database.java @@ -287,9 +287,6 @@ public class Database { boolean isValid = false; boolean exists = (connection != null); - // Initialized as needed later - long timestamp=0; - // If we're waiting for server to recover then leave early if (nextReconnectTimestamp > 0 && nextReconnectTimestamp > System.nanoTime()) { return false; diff --git a/src/main/java/com/gmail/nossr50/util/Permissions.java b/src/main/java/com/gmail/nossr50/util/Permissions.java index 6cce4b1f2..c976b7b5b 100644 --- a/src/main/java/com/gmail/nossr50/util/Permissions.java +++ b/src/main/java/com/gmail/nossr50/util/Permissions.java @@ -4,8 +4,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class Permissions { - private static volatile Permissions instance; - public static boolean hasPermission(CommandSender sender, String perm) { if(sender.hasPermission(perm)) From 85fb12a4ec6bad0f369f4c36a5d91f2f366eee13 Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Tue, 8 Jan 2013 11:31:07 -0500 Subject: [PATCH 07/15] Use new Bukkit DyeColor data. --- .../java/com/gmail/nossr50/skills/gathering/Fishing.java | 3 ++- .../com/gmail/nossr50/skills/gathering/Herbalism.java | 9 +++++---- .../java/com/gmail/nossr50/skills/mining/Mining.java | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/gathering/Fishing.java b/src/main/java/com/gmail/nossr50/skills/gathering/Fishing.java index 6d57d360b..f32705a5a 100755 --- a/src/main/java/com/gmail/nossr50/skills/gathering/Fishing.java +++ b/src/main/java/com/gmail/nossr50/skills/gathering/Fishing.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Map; import java.util.Random; +import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; @@ -404,7 +405,7 @@ public class Fishing { case SQUID: ItemStack item = new ItemStack(Material.INK_SACK, 1, (short) 0); - item.setData(new MaterialData(Material.INK_SACK, (byte) 0x0)); + item.setData(new MaterialData(Material.INK_SACK, DyeColor.BLACK.getDyeData())); Misc.dropItem(location, item); break; diff --git a/src/main/java/com/gmail/nossr50/skills/gathering/Herbalism.java b/src/main/java/com/gmail/nossr50/skills/gathering/Herbalism.java index 90f1664e3..ed04198c7 100644 --- a/src/main/java/com/gmail/nossr50/skills/gathering/Herbalism.java +++ b/src/main/java/com/gmail/nossr50/skills/gathering/Herbalism.java @@ -3,6 +3,7 @@ package com.gmail.nossr50.skills.gathering; import java.util.Random; import org.bukkit.CropState; +import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -268,7 +269,7 @@ public class Herbalism { } else { if (mat == Material.COCOA) { - is = new ItemStack(Material.INK_SACK, 1, (short) 3); + is = new ItemStack(Material.INK_SACK, 1, DyeColor.BROWN.getDyeData()); } else if (mat == Material.CARROT) { is = new ItemStack(Material.CARROT_ITEM, 1, (short) 0); @@ -421,7 +422,7 @@ public class Herbalism { break; case COCOA: // Broken: Requires an update to bukkit to enable seaching for variable-sized ItemStacks. - hasSeeds = inventory.contains(new ItemStack(Material.INK_SACK, 1, (short) 3), 1); + hasSeeds = inventory.contains(new ItemStack(Material.INK_SACK, 1, DyeColor.BROWN.getDyeData()), 1); break; case CARROT: hasSeeds = inventory.contains(Material.CARROT_ITEM); @@ -455,8 +456,8 @@ public class Herbalism { inventory.removeItem(new ItemStack(Material.SEEDS)); break; case COCOA: - Misc.dropItem(location, new ItemStack(Material.INK_SACK, 3, (short) 3)); - inventory.removeItem(new ItemStack(Material.INK_SACK, 1, (short) 3)); + Misc.dropItem(location, new ItemStack(Material.INK_SACK, 3, DyeColor.BROWN.getDyeData())); + inventory.removeItem(new ItemStack(Material.INK_SACK, 1, DyeColor.BROWN.getDyeData())); break; case CARROT: Misc.dropItem(location, new ItemStack(Material.CARROT_ITEM)); diff --git a/src/main/java/com/gmail/nossr50/skills/mining/Mining.java b/src/main/java/com/gmail/nossr50/skills/mining/Mining.java index b8f6bde1a..81fd48ed8 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/Mining.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/Mining.java @@ -3,6 +3,7 @@ package com.gmail.nossr50.skills.mining; import java.util.Random; import org.bukkit.CoalType; +import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -331,7 +332,7 @@ public class Mining { case LAPIS_ORE: if (config.getLapisDoubleDropsEnabled()) { - item = (new MaterialData(Material.INK_SACK, (byte) 0x4)).toItemStack(1); + item = (new MaterialData(Material.INK_SACK, DyeColor.BLUE.getDyeData())).toItemStack(1); Misc.dropItems(location, item, 4); Misc.randomDropItems(location, item, 50, 4); From ccfe1181be4baab0d8fc0e446a1bebbcf27af64a Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Tue, 8 Jan 2013 12:52:16 -0500 Subject: [PATCH 08/15] More mining restructuring. --- src/main/java/com/gmail/nossr50/mcMMO.java | 1 - .../gmail/nossr50/skills/mining/Mining.java | 96 +------------- .../mining/MiningBlockEventHandler.java | 7 +- .../nossr50/skills/mining/MiningManager.java | 27 +++- .../mining/SuperBreakerEventHandler.java | 123 ++++++++++++++++++ .../java/com/gmail/nossr50/util/Misc.java | 3 +- 6 files changed, 161 insertions(+), 96 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/skills/mining/SuperBreakerEventHandler.java diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index a0b973e54..90bdf68c5 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -83,7 +83,6 @@ import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManagerFactory; public class mcMMO extends JavaPlugin { - private final PlayerListener playerListener = new PlayerListener(this); private final BlockListener blockListener = new BlockListener(this); private final EntityListener entityListener = new EntityListener(this); diff --git a/src/main/java/com/gmail/nossr50/skills/mining/Mining.java b/src/main/java/com/gmail/nossr50/skills/mining/Mining.java index 81fd48ed8..4e2b2408c 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/Mining.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/Mining.java @@ -10,16 +10,12 @@ import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.material.MaterialData; -import org.getspout.spoutapi.sound.SoundEffect; -import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.mods.CustomBlock; -import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; -import com.gmail.nossr50.spout.SpoutSounds; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.ModChecks; import com.gmail.nossr50.util.Skills; @@ -32,13 +28,17 @@ public class Mining { public static final int DOUBLE_DROPS_MAX_BONUS_LEVEL = advancedConfig.getMiningDoubleDropMaxLevel(); public static final int DOUBLE_DROPS_MAX_CHANCE = advancedConfig.getMiningDoubleDropChance(); + public static final int DIAMOND_TOOL_TIER = 4; + public static final int IRON_TOOL_TIER = 3; + public static final int STONE_TOOL_TIER = 2; + /** * Award XP for Mining blocks. * * @param player The player to award XP to * @param block The block to award XP for */ - protected static void miningXP(Player player, PlayerProfile profile, Block block, Material type) { + protected static void miningXP(Player player, PlayerProfile profile, Block block, Material type) { int xp = 0; switch (type) { @@ -109,91 +109,6 @@ public class Mining { Skills.xpProcessing(player, profile, SkillType.MINING, xp); } - /** - * Handle the Super Breaker ability. - * - * @param player The player using the ability - * @param block The block being affected - */ - public static void superBreakerBlockCheck(Player player, Block block) { - Material type = block.getType(); - int tier = Misc.getTier(player.getItemInHand()); - int durabilityLoss = config.getAbilityToolDamage(); - FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player); - - if (ModChecks.isCustomMiningBlock(block)) { - if (ModChecks.getCustomBlock(block).getTier() < tier) { - return; - } - - if (mcMMO.placeStore.isTrue(block) || Misc.blockBreakSimulate(block, player, true)) { - return; - } - - mcMMO.p.getServer().getPluginManager().callEvent(armswing); - Skills.abilityDurabilityLoss(player.getItemInHand(), durabilityLoss); - - MiningManager manager = new MiningManager(player); - manager.miningBlockCheck(block); - - if (mcMMO.spoutEnabled) { - SpoutSounds.playSoundForPlayer(SoundEffect.POP, player, block.getLocation()); - } - } - else { - switch (type) { - case OBSIDIAN: - if (tier < 4) { - return; - } - durabilityLoss = durabilityLoss * 5; //Obsidian needs to do more damage than normal - /* FALL THROUGH */ - - case DIAMOND_ORE: - case GLOWING_REDSTONE_ORE: - case GOLD_ORE: - case LAPIS_ORE: - case REDSTONE_ORE: - case EMERALD_ORE: - if (tier < 3) { - return; - } - /* FALL THROUGH */ - - case IRON_ORE: - if (tier < 2) { - return; - } - /* FALL THROUGH */ - - case COAL_ORE: - case ENDER_STONE: - case GLOWSTONE: - case MOSSY_COBBLESTONE: - case NETHERRACK: - case SANDSTONE: - case STONE: - if (mcMMO.placeStore.isTrue(block) || Misc.blockBreakSimulate(block, player, true)) { - return; - } - - mcMMO.p.getServer().getPluginManager().callEvent(armswing); - Skills.abilityDurabilityLoss(player.getItemInHand(), durabilityLoss); - - MiningManager manager = new MiningManager(player); - manager.miningBlockCheck(block); - - if (mcMMO.spoutEnabled) { - SpoutSounds.playSoundForPlayer(SoundEffect.POP, player, block.getLocation()); - } - - default: - return; - } - } - } - - /** * Handle double drops when using Silk Touch. * @@ -266,7 +181,6 @@ public class Mining { } break; } - } /** diff --git a/src/main/java/com/gmail/nossr50/skills/mining/MiningBlockEventHandler.java b/src/main/java/com/gmail/nossr50/skills/mining/MiningBlockEventHandler.java index dedd33da6..6abbd0a75 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningBlockEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningBlockEventHandler.java @@ -4,11 +4,13 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; import com.gmail.nossr50.util.Misc; public class MiningBlockEventHandler { private MiningManager manager; + private Player player; private Block block; private Location blockLocation; @@ -18,6 +20,7 @@ public class MiningBlockEventHandler { protected MiningBlockEventHandler(MiningManager manager, Block block) { this.manager = manager; + this.player = manager.getPlayer(); this.block = block; this.blockLocation = block.getLocation(); @@ -37,7 +40,7 @@ public class MiningBlockEventHandler { * @param block The block being broken */ protected void processDrops() { - if (manager.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) { + if (player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) { Mining.silkTouchDrops(block, blockLocation, blockType); } else { @@ -46,6 +49,6 @@ public class MiningBlockEventHandler { } protected void processXP() { - Mining.miningXP(manager.getPlayer(), manager.getProfile(), block, blockType); + Mining.miningXP(player, manager.getProfile(), block, blockType); } } diff --git a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java index 7cf0740ed..87cfaab48 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java @@ -6,6 +6,7 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Users; @@ -44,13 +45,37 @@ public class MiningManager { randomChance = (int) (randomChance * 0.75); } - float chance = (float) (((double) Mining.DOUBLE_DROPS_MAX_CHANCE / Mining.DOUBLE_DROPS_MAX_BONUS_LEVEL) * eventHandler.skillModifier); + float chance = ((float) Mining.DOUBLE_DROPS_MAX_CHANCE / Mining.DOUBLE_DROPS_MAX_BONUS_LEVEL) * eventHandler.skillModifier; if (chance > Mining.getRandom().nextInt(randomChance)) { eventHandler.processDrops(); } } + /** + * Handle the Super Breaker ability. + * + * @param player The player using the ability + * @param block The block being affected + */ + public void superBreakerBlockCheck(Block block) { + if (mcMMO.placeStore.isTrue(block) || Misc.blockBreakSimulate(block, player, true)) { + return; + } + + MiningManager manager = new MiningManager(player); + SuperBreakerEventHandler eventHandler = new SuperBreakerEventHandler(manager, block); + + if (eventHandler.tierCheck()) { + return; + } + + eventHandler.callFakeArmswing(); + eventHandler.processDurabilityLoss(); + eventHandler.processDropsAndXP(); + eventHandler.playSpoutSound(); + } + protected int getSkillLevel() { return skillLevel; } diff --git a/src/main/java/com/gmail/nossr50/skills/mining/SuperBreakerEventHandler.java b/src/main/java/com/gmail/nossr50/skills/mining/SuperBreakerEventHandler.java new file mode 100644 index 000000000..1bc4f3297 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/skills/mining/SuperBreakerEventHandler.java @@ -0,0 +1,123 @@ +package com.gmail.nossr50.skills.mining; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.getspout.spoutapi.sound.SoundEffect; + +import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; +import com.gmail.nossr50.spout.SpoutSounds; +import com.gmail.nossr50.util.Misc; +import com.gmail.nossr50.util.ModChecks; +import com.gmail.nossr50.util.Skills; + +public class SuperBreakerEventHandler { + private MiningManager manager; + private Player player; + + private Block block; + private Material blockType; + private boolean customBlock; + + private ItemStack heldItem; + private int tier; + + private int durabilityLoss; + private FakePlayerAnimationEvent armswing; + + protected SuperBreakerEventHandler (MiningManager manager, Block block) { + this.manager = manager; + this.player = manager.getPlayer(); + + this.block = block; + this.blockType = block.getType(); + this.customBlock = ModChecks.isCustomMiningBlock(block); + + this.heldItem = player.getItemInHand(); + this.tier = Misc.getTier(heldItem); + + this.armswing = new FakePlayerAnimationEvent(player); + + calculateDurabilityLoss(); + } + + protected void callFakeArmswing() { + mcMMO.p.getServer().getPluginManager().callEvent(armswing); + } + + protected void processDurabilityLoss() { + Skills.abilityDurabilityLoss(heldItem, durabilityLoss); + } + + protected void processDropsAndXP() { + manager.miningBlockCheck(block); + } + + protected void playSpoutSound() { + SpoutSounds.playSoundForPlayer(SoundEffect.POP, player, block.getLocation()); + } + + /** + * Check for the proper tier of item for use with Super Breaker. + * + * @return True if the item is the required tier or higher, false otherwise + */ + protected boolean tierCheck() { + if (customBlock) { + if (ModChecks.getCustomBlock(block).getTier() < tier) { + return false; + } + else { + return true; + } + } + else { + switch (blockType) { + case OBSIDIAN: + if (tier < Mining.DIAMOND_TOOL_TIER) { + return false; + } + /* FALL THROUGH */ + + case DIAMOND_ORE: + case GLOWING_REDSTONE_ORE: + case GOLD_ORE: + case LAPIS_ORE: + case REDSTONE_ORE: + case EMERALD_ORE: + if (tier < Mining.IRON_TOOL_TIER) { + return false; + } + /* FALL THROUGH */ + + case IRON_ORE: + if (tier < Mining.STONE_TOOL_TIER) { + return false; + } + /* FALL THROUGH */ + + case COAL_ORE: + case ENDER_STONE: + case GLOWSTONE: + case MOSSY_COBBLESTONE: + case NETHERRACK: + case SANDSTONE: + case STONE: + return true; + + default: + return false; + } + } + } + + private void calculateDurabilityLoss() { + this.durabilityLoss = Misc.TOOL_DURABILITY_LOSS; + + if (blockType.equals(Material.OBSIDIAN)) { + durabilityLoss = durabilityLoss * 5; + } + } +} diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index dc160cba5..596286518 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -20,9 +20,10 @@ import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import com.gmail.nossr50.events.items.McMMOItemSpawnEvent; public class Misc { - private static Random random = new Random(); + public static final int TOOL_DURABILITY_LOSS = Config.getInstance().getAbilityToolDamage(); + /** * Gets a capitalized version of the target string. * From d2aa19e31f6abab053bcc543e79228f5a65f6f5b Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Tue, 8 Jan 2013 14:23:21 -0500 Subject: [PATCH 09/15] Whoops, forgot to change a reference. --- .../java/com/gmail/nossr50/listeners/BlockListener.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index ac126bc7e..22c6fd692 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -357,15 +357,17 @@ public class BlockListener implements Listener { } } else if (profile.getAbilityMode(AbilityType.SUPER_BREAKER) && Skills.triggerCheck(player, block, AbilityType.SUPER_BREAKER)) { + MiningManager manager = new MiningManager(player); + if (configInstance.getMiningRequiresTool()) { if (ItemChecks.isPickaxe(inHand)) { event.setInstaBreak(true); - Mining.superBreakerBlockCheck(player, block); + manager.superBreakerBlockCheck(block); } } else { event.setInstaBreak(true); - Mining.superBreakerBlockCheck(player, block); + manager.superBreakerBlockCheck(block); } } else if (profile.getSkillLevel(SkillType.WOODCUTTING) >= LEAF_BLOWER_LEVEL && (material.equals(Material.LEAVES) || (configInstance.getBlockModsEnabled() && ModChecks.isCustomLeafBlock(block)))) { From fadec1a8467c89f19b17b146e8a6e5acec8c36d0 Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Tue, 8 Jan 2013 14:27:09 -0500 Subject: [PATCH 10/15] Remove unused import. --- src/main/java/com/gmail/nossr50/listeners/BlockListener.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 22c6fd692..518a57a67 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -30,7 +30,6 @@ import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import com.gmail.nossr50.runnables.StickyPistonTracker; import com.gmail.nossr50.skills.gathering.Excavation; import com.gmail.nossr50.skills.gathering.Herbalism; -import com.gmail.nossr50.skills.mining.Mining; import com.gmail.nossr50.skills.mining.MiningManager; import com.gmail.nossr50.skills.gathering.WoodCutting; import com.gmail.nossr50.skills.repair.Repair; From 7c211fa50c1cb318ce735a6783244c40e823d0b4 Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Tue, 8 Jan 2013 14:56:31 -0500 Subject: [PATCH 11/15] Fix for Super Breaker & Giga Drill Breaker double/triple drops. --- .../java/com/gmail/nossr50/skills/gathering/Excavation.java | 2 +- .../java/com/gmail/nossr50/skills/mining/MiningManager.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/gathering/Excavation.java b/src/main/java/com/gmail/nossr50/skills/gathering/Excavation.java index 39e62042d..04704e635 100644 --- a/src/main/java/com/gmail/nossr50/skills/gathering/Excavation.java +++ b/src/main/java/com/gmail/nossr50/skills/gathering/Excavation.java @@ -133,7 +133,7 @@ public class Excavation { Skills.abilityDurabilityLoss(player.getItemInHand(), Config.getInstance().getAbilityToolDamage()); - if (!mcMMO.placeStore.isTrue(block) && !Misc.blockBreakSimulate(block, player, true)) { + if (!mcMMO.placeStore.isTrue(block) && Misc.blockBreakSimulate(block, player, true)) { FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player); mcMMO.p.getServer().getPluginManager().callEvent(armswing); diff --git a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java index 87cfaab48..34b853bdd 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java @@ -59,7 +59,7 @@ public class MiningManager { * @param block The block being affected */ public void superBreakerBlockCheck(Block block) { - if (mcMMO.placeStore.isTrue(block) || Misc.blockBreakSimulate(block, player, true)) { + if (mcMMO.placeStore.isTrue(block) || !Misc.blockBreakSimulate(block, player, true)) { return; } From d2f61916158899ee8164f03d7e6afbebae561154 Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Tue, 8 Jan 2013 16:07:29 -0500 Subject: [PATCH 12/15] Starting on cleaning up null checks & type casting --- .../nossr50/skills/acrobatics/Acrobatics.java | 8 ++--- .../acrobatics/AcrobaticsEventHandler.java | 12 +++---- .../skills/acrobatics/AcrobaticsManager.java | 31 +++++++++---------- .../skills/acrobatics/DodgeEventHandler.java | 8 +---- .../skills/acrobatics/RollEventHandler.java | 9 ------ .../nossr50/skills/mining/MiningManager.java | 3 +- .../java/com/gmail/nossr50/util/Misc.java | 5 +++ 7 files changed, 30 insertions(+), 46 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java index c9883433d..d36c49d56 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java @@ -5,7 +5,9 @@ import java.util.Random; import com.gmail.nossr50.config.AdvancedConfig; public class Acrobatics { - static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); + private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); + private static Random random = new Random(); + public static final int DODGE_MAX_CHANCE = advancedConfig.getDodgeChanceMax(); public static final int DODGE_MAX_BONUS_LEVEL = advancedConfig.getDodgeMaxBonusLevel(); public static final int DODGE_XP_MODIFIER = advancedConfig.getDodgeXPModifier(); @@ -18,9 +20,7 @@ public class Acrobatics { public static final int ROLL_XP_MODIFIER = advancedConfig.getRollXPModifier(); public static final int FALL_XP_MODIFIER = advancedConfig.getFallXPModifier(); - private static Random random = new Random(); - - public static Random getRandom() { + protected static Random getRandom() { return random; } } diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsEventHandler.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsEventHandler.java index 383cd70a4..f123724ed 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsEventHandler.java @@ -3,6 +3,8 @@ package com.gmail.nossr50.skills.acrobatics; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; +import com.gmail.nossr50.util.Misc; + public abstract class AcrobaticsEventHandler { protected AcrobaticsManager manager; protected Player player; @@ -51,14 +53,10 @@ public abstract class AcrobaticsEventHandler { * @return true if the damage is fatal, false otherwise */ protected boolean isFatal(int damage) { - if(player == null) + if (Misc.isCitizensNPC(player) || player.getHealth() - damage < 1) { return true; + } - if (player.getHealth() - damage < 1) { - return true; - } - else { - return false; - } + return false; } } diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java index aff0a0e93..473836f3c 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java @@ -6,10 +6,13 @@ import org.bukkit.event.entity.EntityDamageEvent; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Users; public class AcrobaticsManager { + private static Config config = Config.getInstance(); + private Player player; private PlayerProfile profile; private int skillLevel; @@ -26,29 +29,28 @@ public class AcrobaticsManager { * @param event The event to check */ public void rollCheck(EntityDamageEvent event) { - if(player == null) - return; - - if (!Permissions.roll(player)) { + if (Misc.isCitizensNPC(player) || !Permissions.roll(player)) { return; } - if(Config.getInstance().getAcrobaticsAFKDisabled() && player.isInsideVehicle()) + if (config.getAcrobaticsAFKDisabled() && player.isInsideVehicle()) { return; + } RollEventHandler eventHandler = new RollEventHandler(this, event); int randomChance = 100; - if (Permissions.luckyAcrobatics(player)) { randomChance = (int) (randomChance * 0.75); } - float chance = (float) (((double) Acrobatics.ROLL_MAX_CHANCE / (double) Acrobatics.ROLL_MAX_BONUS_LEVEL) * skillLevel); - if (chance > Acrobatics.ROLL_MAX_CHANCE) chance = Acrobatics.ROLL_MAX_CHANCE; + float chance; + if (eventHandler.isGraceful) { - chance = (float) (((double) Acrobatics.GRACEFUL_MAX_CHANCE / (double) Acrobatics.GRACEFUL_MAX_BONUS_LEVEL) * skillLevel); - if (chance > Acrobatics.GRACEFUL_MAX_CHANCE) chance = Acrobatics.GRACEFUL_MAX_CHANCE; + chance = ((float) Acrobatics.GRACEFUL_MAX_CHANCE / Acrobatics.GRACEFUL_MAX_BONUS_LEVEL) * eventHandler.skillModifier; + } + else { + chance = ((float) Acrobatics.ROLL_MAX_CHANCE / Acrobatics.ROLL_MAX_BONUS_LEVEL) * eventHandler.skillModifier; } if (chance > Acrobatics.getRandom().nextInt(randomChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) { @@ -67,23 +69,18 @@ public class AcrobaticsManager { * @param event The event to check */ public void dodgeCheck(EntityDamageEvent event) { - if(player == null) - return; - - if (!Permissions.dodge(player)) { + if (Misc.isCitizensNPC(player) || !Permissions.dodge(player)) { return; } DodgeEventHandler eventHandler = new DodgeEventHandler(this, event); int randomChance = 100; - if (Permissions.luckyAcrobatics(player)) { randomChance = (int) (randomChance * 0.75); } - float chance = (float) (((double) Acrobatics.DODGE_MAX_CHANCE / (double) Acrobatics.DODGE_MAX_BONUS_LEVEL) * skillLevel); - if (chance > Acrobatics.DODGE_MAX_CHANCE) chance = Acrobatics.DODGE_MAX_CHANCE; + float chance = ((float) Acrobatics.DODGE_MAX_CHANCE / Acrobatics.DODGE_MAX_BONUS_LEVEL) * eventHandler.skillModifier; if (chance > Acrobatics.getRandom().nextInt(randomChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) { eventHandler.modifyEventDamage(); diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/DodgeEventHandler.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/DodgeEventHandler.java index 6fe6064e9..64f28adb4 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/DodgeEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/DodgeEventHandler.java @@ -39,20 +39,14 @@ public class DodgeEventHandler extends AcrobaticsEventHandler { @Override protected void sendAbilityMessage() { - if(player == null) - return; - player.sendMessage(LocaleLoader.getString("Acrobatics.Combat.Proc")); } @Override protected void processXPGain(int xp) { - if(player == null) - return; - PlayerProfile profile = manager.getProfile(); - if (System.currentTimeMillis() >= profile.getRespawnATS() + 5) { + if (System.currentTimeMillis() >= profile.getRespawnATS() + Misc.PLAYER_RESPAWN_COOLDOWN_SECONDS) { Skills.xpProcessing(player, profile, SkillType.ACROBATICS, xp); } } diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java index 4e98848b5..43cbcebc3 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java @@ -56,9 +56,6 @@ public class RollEventHandler extends AcrobaticsEventHandler { @Override protected void sendAbilityMessage() { - if(player == null) - return; - if (isGraceful) { player.sendMessage(LocaleLoader.getString("Acrobatics.Ability.Proc")); } @@ -70,9 +67,6 @@ public class RollEventHandler extends AcrobaticsEventHandler { @Override protected void processXPGain(int xpGain) { - if(player == null) - return; - Skills.xpProcessing(player, manager.getProfile(), SkillType.ACROBATICS, xpGain); } @@ -80,9 +74,6 @@ public class RollEventHandler extends AcrobaticsEventHandler { * Check if this is a graceful roll. */ private void isGracefulRoll() { - if(player == null) - return; - if (Permissions.gracefulRoll(player)) { this.isGraceful = player.isSneaking(); } diff --git a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java index 34b853bdd..b8740c5c2 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java @@ -63,8 +63,7 @@ public class MiningManager { return; } - MiningManager manager = new MiningManager(player); - SuperBreakerEventHandler eventHandler = new SuperBreakerEventHandler(manager, block); + SuperBreakerEventHandler eventHandler = new SuperBreakerEventHandler(this, block); if (eventHandler.tierCheck()) { return; diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index 596286518..3056dbc6d 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -23,6 +23,11 @@ public class Misc { private static Random random = new Random(); public static final int TOOL_DURABILITY_LOSS = Config.getInstance().getAbilityToolDamage(); + public static final int PLAYER_RESPAWN_COOLDOWN_SECONDS = 5; + + public static boolean isCitizensNPC(Player player) { + return player.hasMetadata("NPC"); + } /** * Gets a capitalized version of the target string. From e0da506d1aed22c1fc610f2d4f068da07c7625e7 Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Tue, 8 Jan 2013 16:10:19 -0500 Subject: [PATCH 13/15] Protected, not public. --- .../com/gmail/nossr50/skills/acrobatics/RollEventHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java index 43cbcebc3..f55650c03 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java @@ -9,7 +9,7 @@ import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Skills; public class RollEventHandler extends AcrobaticsEventHandler { - public boolean isGraceful; + protected boolean isGraceful; private int damageThreshold; protected RollEventHandler(AcrobaticsManager manager, EntityDamageEvent event) { From b78299bbbd16c75aca52ecbc13137b68b403639d Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Tue, 8 Jan 2013 17:24:09 -0500 Subject: [PATCH 14/15] Metadata does nothing, apparently. --- .../java/com/gmail/nossr50/skills/archery/Archery.java | 7 +++---- .../skills/archery/ArcheryBonusDamageEventHandler.java | 8 +++----- src/main/java/com/gmail/nossr50/util/Misc.java | 6 +++++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/archery/Archery.java b/src/main/java/com/gmail/nossr50/skills/archery/Archery.java index 08093959c..4d21f8628 100644 --- a/src/main/java/com/gmail/nossr50/skills/archery/Archery.java +++ b/src/main/java/com/gmail/nossr50/skills/archery/Archery.java @@ -13,7 +13,7 @@ import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.util.Misc; public class Archery { - static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); + private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); private static Random random = new Random(); private static List trackedEntities = new ArrayList(); @@ -30,14 +30,13 @@ public class Archery { protected static void incrementTrackerValue(LivingEntity livingEntity) { for (TrackedEntity trackedEntity : trackedEntities) { - if (trackedEntity.getLivingEntity() == livingEntity) { + if (trackedEntity.getLivingEntity().getEntityId() == livingEntity.getEntityId()) { trackedEntity.incrementArrowCount(); return; } } - //If the entity isn't tracked yet - addToTracker(livingEntity); + addToTracker(livingEntity); //If the entity isn't tracked yet } protected static void addToTracker(LivingEntity livingEntity) { diff --git a/src/main/java/com/gmail/nossr50/skills/archery/ArcheryBonusDamageEventHandler.java b/src/main/java/com/gmail/nossr50/skills/archery/ArcheryBonusDamageEventHandler.java index 889d66f08..dba5c88e0 100644 --- a/src/main/java/com/gmail/nossr50/skills/archery/ArcheryBonusDamageEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/archery/ArcheryBonusDamageEventHandler.java @@ -14,13 +14,11 @@ public class ArcheryBonusDamageEventHandler { } protected void calculateDamageBonus() { - double damageBonus = ((manager.getSkillLevel() / Archery.BONUS_DAMAGE_INCREASE_LEVEL) * Archery.BONUS_DAMAGE_INCREASE_PERCENT); + this.damageBonusPercent = ((manager.getSkillLevel() / Archery.BONUS_DAMAGE_INCREASE_LEVEL) * Archery.BONUS_DAMAGE_INCREASE_PERCENT); - if (damageBonus > Archery.BONUS_DAMAGE_MAX_BONUS_PERCENTAGE) { - damageBonus = Archery.BONUS_DAMAGE_MAX_BONUS_PERCENTAGE; + if (damageBonusPercent > Archery.BONUS_DAMAGE_MAX_BONUS_PERCENTAGE) { + damageBonusPercent = Archery.BONUS_DAMAGE_MAX_BONUS_PERCENTAGE; } - - this.damageBonusPercent = damageBonus; } protected void modifyEventDamage() { diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index 3056dbc6d..5ec785749 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -26,7 +26,11 @@ public class Misc { public static final int PLAYER_RESPAWN_COOLDOWN_SECONDS = 5; public static boolean isCitizensNPC(Player player) { - return player.hasMetadata("NPC"); + if (player == null || Users.getProfile(player) == null) { + return true; + } + + return false; } /** From 08b46e1a7c0346cef98dd28a717a3e3a4ddf0156 Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Tue, 8 Jan 2013 17:26:11 -0500 Subject: [PATCH 15/15] Cover ALL the bases. --- src/main/java/com/gmail/nossr50/util/Misc.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index 5ec785749..3bd6bb497 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -26,7 +26,7 @@ public class Misc { public static final int PLAYER_RESPAWN_COOLDOWN_SECONDS = 5; public static boolean isCitizensNPC(Player player) { - if (player == null || Users.getProfile(player) == null) { + if (player == null || Users.getProfile(player) == null || player.hasMetadata("NPC")) { return true; }