diff --git a/src/main/java/com/gmail/nossr50/Combat.java b/src/main/java/com/gmail/nossr50/Combat.java index 2c17c8c3f..8666ef153 100644 --- a/src/main/java/com/gmail/nossr50/Combat.java +++ b/src/main/java/com/gmail/nossr50/Combat.java @@ -361,7 +361,7 @@ public class Combat { LivingEntity livingEntity = (LivingEntity) entity; if (type.equals(SkillType.SWORDS) && !plugin.misc.bleedTracker.contains(entity)) { - plugin.misc.addToBleedQue(livingEntity); + plugin.misc.bleedQue.add(livingEntity); } dealDamage(livingEntity, damageAmount, attacker); diff --git a/src/main/java/com/gmail/nossr50/config/Misc.java b/src/main/java/com/gmail/nossr50/config/Misc.java index 0557315c3..3dd329cff 100644 --- a/src/main/java/com/gmail/nossr50/config/Misc.java +++ b/src/main/java/com/gmail/nossr50/config/Misc.java @@ -2,6 +2,7 @@ package com.gmail.nossr50.config; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -9,63 +10,17 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.mcMMO; -public class Misc -{ - String location = "mcmmo.properties"; - +public class Misc { public HashMap arrowTracker = new HashMap(); public ArrayList bleedTracker = new ArrayList(); public HashMap tntTracker = new HashMap(); - mcMMO plugin = null; - - //BLEED QUE STUFF - public LivingEntity[] bleedQue = new LivingEntity[20]; - public int bleedQuePos = 0; - public LivingEntity[] bleedRemovalQue = new LivingEntity[20]; - public int bleedRemovalQuePos = 0; + mcMMO plugin; - public Misc(mcMMO mcMMO) - { - plugin = mcMMO; - } - - public void addToBleedQue(LivingEntity entity) - { - //Assign entity to empty position - bleedQue[bleedQuePos] = entity; - - //Move position up by 1 increment - bleedQuePos++; - - //Check if array is full - if(bleedQuePos >= bleedQue.length) - { - //Create new temporary array - LivingEntity[] temp = new LivingEntity[bleedQue.length*2]; - //Copy data from bleedQue to temporary array - System.arraycopy(bleedQue, 0, temp, 0, bleedQue.length); - //Point bleedQue to new array - bleedQue = temp; - } - } - - public void addToBleedRemovalQue(LivingEntity entity) - { - //Assign entity to empty position - bleedRemovalQue[bleedRemovalQuePos] = entity; - - //Move position up by 1 increment - bleedRemovalQuePos++; - - //Check if array is full - if(bleedRemovalQuePos >= bleedRemovalQue.length) - { - //Create new temporary array - LivingEntity[] temp = new LivingEntity[bleedRemovalQue.length*2]; - //Copy data from bleedRemovalQue to temporary array - System.arraycopy(bleedRemovalQue, 0, temp, 0, bleedRemovalQue.length); - //Point bleedRemovalQue to new array - bleedRemovalQue = temp; - } + /* BLEED QUE STUFF */ + public HashSet bleedQue = new HashSet(); + public HashSet bleedRemovalQue = new HashSet(); + + public Misc(mcMMO mcMMO) { + this.plugin = mcMMO; } } \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java b/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java index ef1aa1507..9775acd4b 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java @@ -147,7 +147,7 @@ public class mcEntityListener implements Listener { /* Remove bleed track */ if(plugin.misc.bleedTracker.contains(x)) { - plugin.misc.addToBleedRemovalQue(x); + plugin.misc.bleedRemovalQue.add(x); } Archery.arrowRetrievalCheck(x, plugin); diff --git a/src/main/java/com/gmail/nossr50/m.java b/src/main/java/com/gmail/nossr50/m.java index 1d692ac68..82e20b33a 100644 --- a/src/main/java/com/gmail/nossr50/m.java +++ b/src/main/java/com/gmail/nossr50/m.java @@ -276,6 +276,13 @@ public class m { Bukkit.getScheduler().scheduleAsyncDelayedTask(Bukkit.getPluginManager().getPlugin("mcMMO"), new SQLConversionTask(), 1); } + /** + * Check if a skill level is higher than the max bonus level of the ability. + * + * @param skillLevel Skill level to check + * @param maxLevel Max level of the ability + * @return whichever value is lower + */ public static int skillCheck(int skillLevel, int maxLevel) { if (skillLevel > maxLevel) { return maxLevel; @@ -284,4 +291,29 @@ public class m { return skillLevel; } } + + /** + * Simulate a bleed. + * + * @param plugin mcMMO plugin instance + */ + public static void bleedSimulate(mcMMO plugin) { + + /* Set up the tracker */ + plugin.misc.bleedTracker.addAll(plugin.misc.bleedQue); + plugin.misc.bleedQue.removeAll(plugin.misc.bleedQue); + plugin.misc.bleedTracker.removeAll(plugin.misc.bleedRemovalQue); + plugin.misc.bleedRemovalQue.removeAll(plugin.misc.bleedRemovalQue); + + /* Bleed monsters/animals */ + for (LivingEntity entity : plugin.misc.bleedTracker) { + if ((entity == null || entity.isDead())) { + plugin.misc.bleedRemovalQue.add(entity); + continue; + } + else { + Combat.dealDamage(entity, 2); + } + } + } } diff --git a/src/main/java/com/gmail/nossr50/runnables/mcTimer.java b/src/main/java/com/gmail/nossr50/runnables/mcTimer.java index 226b37a91..ba3e243d4 100644 --- a/src/main/java/com/gmail/nossr50/runnables/mcTimer.java +++ b/src/main/java/com/gmail/nossr50/runnables/mcTimer.java @@ -4,13 +4,13 @@ import org.bukkit.entity.*; import com.gmail.nossr50.Combat; import com.gmail.nossr50.Users; +import com.gmail.nossr50.m; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.datatypes.AbilityType; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.skills.Skills; -import com.gmail.nossr50.skills.Swords; public class mcTimer implements Runnable { @@ -81,7 +81,7 @@ public class mcTimer implements Runnable */ if(thecount % 2 == 0) - Swords.bleedSimulate(plugin); + m.bleedSimulate(plugin); //SETUP FOR HP REGEN/BLEED thecount++; diff --git a/src/main/java/com/gmail/nossr50/skills/Swords.java b/src/main/java/com/gmail/nossr50/skills/Swords.java index 5b6ed4837..df98e4059 100644 --- a/src/main/java/com/gmail/nossr50/skills/Swords.java +++ b/src/main/java/com/gmail/nossr50/skills/Swords.java @@ -66,7 +66,7 @@ public class Swords { Users.getProfile(target).addBleedTicks(bleedTicks); } else { - plugin.misc.addToBleedQue(entity); + plugin.misc.bleedQue.add(entity); } attacker.sendMessage(mcLocale.getString("Swords.EnemyBleeding")); } @@ -108,41 +108,4 @@ public class Swords { } } } - - /** - * Simulate a bleed. - * - * @param plugin mcMMO plugin instance - */ - public static void bleedSimulate(mcMMO plugin) { - - /* Add items from Que list to BleedTrack list */ - for (LivingEntity entity : plugin.misc.bleedQue) { - plugin.misc.bleedTracker.add(entity); - } - - /* Clear the BleedQue list */ - plugin.misc.bleedQue = new LivingEntity[plugin.misc.bleedQue.length]; - plugin.misc.bleedQuePos = 0; - - /* Cleanup any dead entities from the list */ - for(LivingEntity entity : plugin.misc.bleedRemovalQue) { - plugin.misc.bleedTracker.remove(entity); - } - - /* Clear bleed removal list */ - plugin.misc.bleedRemovalQue = new LivingEntity[plugin.misc.bleedRemovalQue.length]; - plugin.misc.bleedRemovalQuePos = 0; - - /* Bleed monsters/animals */ - for (LivingEntity entity : plugin.misc.bleedTracker) { - if (entity == null || entity.isDead()) { - plugin.misc.addToBleedRemovalQue(entity); - continue; - } - else { - Combat.dealDamage(entity, 2); - } - } - } } diff --git a/src/main/java/com/gmail/nossr50/skills/Taming.java b/src/main/java/com/gmail/nossr50/skills/Taming.java index b386108a7..434fe98eb 100644 --- a/src/main/java/com/gmail/nossr50/skills/Taming.java +++ b/src/main/java/com/gmail/nossr50/skills/Taming.java @@ -90,7 +90,7 @@ public class Taming { Users.getProfile(target).setBleedTicks(2); } else { - plugin.misc.addToBleedQue((LivingEntity)entity); + plugin.misc.bleedQue.add((LivingEntity) entity); } master.sendMessage(mcLocale.getString("Combat.Gore"));