mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-23 05:36:46 +01:00
Cleaned up the way we handle bleed tracking.
This commit is contained in:
parent
6b99d3e5f1
commit
bc725f46e8
@ -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);
|
||||
|
@ -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<Entity, Integer> arrowTracker = new HashMap<Entity, Integer>();
|
||||
public ArrayList<LivingEntity> bleedTracker = new ArrayList<LivingEntity>();
|
||||
public HashMap<Integer, Player> tntTracker = new HashMap<Integer, Player>();
|
||||
mcMMO plugin = null;
|
||||
mcMMO plugin;
|
||||
|
||||
//BLEED QUE STUFF
|
||||
public LivingEntity[] bleedQue = new LivingEntity[20];
|
||||
public int bleedQuePos = 0;
|
||||
public LivingEntity[] bleedRemovalQue = new LivingEntity[20];
|
||||
public int bleedRemovalQuePos = 0;
|
||||
/* BLEED QUE STUFF */
|
||||
public HashSet<LivingEntity> bleedQue = new HashSet<LivingEntity>();
|
||||
public HashSet<LivingEntity> bleedRemovalQue = new HashSet<LivingEntity>();
|
||||
|
||||
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;
|
||||
}
|
||||
public Misc(mcMMO mcMMO) {
|
||||
this.plugin = mcMMO;
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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++;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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"));
|
||||
|
Loading…
Reference in New Issue
Block a user