diff --git a/Changelog.txt b/Changelog.txt index e9ceb3027..3e43afc57 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -8,8 +8,9 @@ Version 1.3.00-dev - Added configuration option to control mcMMO reporting damage events - Added hunger regain bonuses to Herbalism skill - Changed chat logging for /p & /a - - Fixed Tree Feller not playing nice with NoCheat + - Fixed Tree Feller not playing nice with NoCheat (?) - Added framework for new Blast Mining skill + - Changed Tree Feller to use per-use ArrayList Version 1.2.12 - Fixed issue that caused terrible MySQL performance and negative XP on levelup (Issue #134) diff --git a/src/main/java/com/gmail/nossr50/config/Misc.java b/src/main/java/com/gmail/nossr50/config/Misc.java index 2d184327a..d4aaa4f4b 100644 --- a/src/main/java/com/gmail/nossr50/config/Misc.java +++ b/src/main/java/com/gmail/nossr50/config/Misc.java @@ -33,7 +33,6 @@ public class Misc public ArrayList mobSpawnerList = new ArrayList(); public HashSet blockWatchList = new HashSet(); - public ArrayList treeFeller = new ArrayList(); public HashMap arrowTracker = new HashMap(); public ArrayList bleedTracker = new ArrayList(); public HashMap tntTracker = new HashMap(); diff --git a/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java b/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java index 1eefee7b4..e5fa4cd49 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java @@ -16,6 +16,8 @@ */ package com.gmail.nossr50.listeners; +import java.util.ArrayList; + import com.gmail.nossr50.Users; import com.gmail.nossr50.m; import com.gmail.nossr50.mcMMO; @@ -223,8 +225,8 @@ public class mcBlockListener implements Listener PlayerAnimationEvent armswing = new PlayerAnimationEvent(player); Bukkit.getPluginManager().callEvent(armswing); - WoodCutting.treeFeller(block, player, plugin); - for(Block blockx : plugin.misc.treeFeller) + ArrayList fell = WoodCutting.treeFeller(block, player); + for(Block blockx : fell) { if(blockx != null) { @@ -262,7 +264,6 @@ public class mcBlockListener implements Listener if(!player.getItemInHand().containsEnchantment(Enchantment.DURABILITY)) m.damageTool(player, (short) LoadProperties.abilityDurabilityLoss); } - plugin.misc.treeFeller.clear(); } } /* diff --git a/src/main/java/com/gmail/nossr50/skills/WoodCutting.java b/src/main/java/com/gmail/nossr50/skills/WoodCutting.java index 0813302d6..f572afbb8 100644 --- a/src/main/java/com/gmail/nossr50/skills/WoodCutting.java +++ b/src/main/java/com/gmail/nossr50/skills/WoodCutting.java @@ -40,8 +40,6 @@ import org.getspout.spoutapi.sound.SoundEffect; public class WoodCutting { - static int w = 0; - private static boolean isdone = false; public static void woodCuttingProcCheck(Player player, Block block) { @@ -99,34 +97,29 @@ public class WoodCutting } } } - public static void treeFeller(Block block, Player player, mcMMO plugin){ + public static ArrayList treeFeller(Block block, Player player) { PlayerProfile PP = Users.getProfile(player); + int radius = 1; if(PP.getSkillLevel(SkillType.WOODCUTTING) >= 500) radius++; if(PP.getSkillLevel(SkillType.WOODCUTTING) >= 950) radius++; - ArrayList blocklist = new ArrayList(); - ArrayList toAdd = new ArrayList(); + + ArrayList blockList = new ArrayList(); + ArrayList returnList = new ArrayList(); + if(block != null) - blocklist.add(block); - while(isdone == false){ - addBlocksToTreeFelling(blocklist, toAdd, radius); + blockList.add(block); + + boolean isDone = false; + while(isDone == false){ + isDone = addBlocksToTreeFelling(blockList, returnList, radius); } - //This needs to be a hashmap too! - isdone = false; - /* - * Add blocks from the temporary 'toAdd' array list into the 'treeFeller' array list - * We use this temporary list to prevent concurrent modification exceptions - */ - for(Block x : toAdd) - { - if(!plugin.misc.treeFeller.contains(x)) - plugin.misc.treeFeller.add(x); - } - toAdd.clear(); + + return returnList; } - public static void addBlocksToTreeFelling(ArrayList blocklist, ArrayList toAdd, Integer radius) + public static boolean addBlocksToTreeFelling(ArrayList blocklist, ArrayList toAdd, Integer radius) { int u = 0; for (Block x : blocklist) @@ -134,7 +127,6 @@ public class WoodCutting u++; if(toAdd.contains(x)) continue; - w = 0; Location loc = x.getLocation(); int vx = x.getX(); int vy = x.getY(); @@ -149,7 +141,6 @@ public class WoodCutting Block blocktarget = loc.getWorld().getBlockAt(vx + cx, vy + cy, vz + cz); if (!blocklist.contains(blocktarget) && !toAdd.contains(blocktarget) && (blocktarget.getTypeId() == 17 || blocktarget.getTypeId() == 18)) { toAdd.add(blocktarget); - w++; } } } @@ -165,9 +156,9 @@ public class WoodCutting } if(u >= blocklist.size()) { - isdone = true; + return true; } else { - isdone = false; + return false; } }