Add condition validation to find the root cause of SSM errors
This commit is contained in:
parent
eb9a9d5303
commit
ee898f8185
@ -1,13 +1,15 @@
|
||||
package mineplex.minecraft.game.core.condition;
|
||||
|
||||
import mineplex.core.events.AddConditionEvent;
|
||||
import net.minecraft.server.v1_8_R3.MobEffect;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import mineplex.core.events.AddConditionEvent;
|
||||
|
||||
public class Condition
|
||||
{
|
||||
public enum ConditionType
|
||||
@ -104,7 +106,7 @@ public class Condition
|
||||
//Live if NOT Additive
|
||||
_live = !add;
|
||||
}
|
||||
|
||||
|
||||
public Condition(ConditionManager manager, String reason, LivingEntity ent, LivingEntity source,
|
||||
ConditionType type, int mult, int ticks, boolean add, Material visualType, byte visualData, boolean showIndicator, boolean ambient, boolean cancelPotion)
|
||||
{
|
||||
@ -339,4 +341,10 @@ public class Condition
|
||||
{
|
||||
_mult = Math.max(0, _mult + i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return getClass().getSimpleName() + "[ent=" + _ent + "]";
|
||||
}
|
||||
}
|
||||
|
@ -38,16 +38,27 @@ import mineplex.minecraft.game.core.damage.DamageManager;
|
||||
|
||||
public class ConditionManager extends MiniPlugin
|
||||
{
|
||||
static class ConditionMap<T> extends WeakHashMap<LivingEntity, LinkedList<T>>
|
||||
{
|
||||
@Override
|
||||
public LinkedList<T> put(LivingEntity key, LinkedList<T> value)
|
||||
{
|
||||
if (key == null)
|
||||
throw new NullPointerException("Key cannot be null!");
|
||||
return super.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
private ConditionFactory _factory;
|
||||
private ConditionApplicator _applicator;
|
||||
protected ConditionEffect Effect;
|
||||
|
||||
private DamageManager _damageManager;
|
||||
|
||||
private WeakHashMap<LivingEntity, LinkedList<Condition>> _conditions = new WeakHashMap<LivingEntity, LinkedList<Condition>>();
|
||||
private WeakHashMap<LivingEntity, LinkedList<ConditionActive>> _activeConditions = new WeakHashMap<LivingEntity, LinkedList<ConditionActive>>();
|
||||
private WeakHashMap<LivingEntity, LinkedList<Condition>> _conditions = new ConditionMap<>();
|
||||
private WeakHashMap<LivingEntity, LinkedList<ConditionActive>> _activeConditions = new ConditionMap<>();
|
||||
|
||||
private HashSet<Entity> _items = new HashSet<Entity>();
|
||||
private HashSet<Entity> _items = new HashSet<>();
|
||||
|
||||
public ConditionManager(JavaPlugin plugin)
|
||||
{
|
||||
@ -92,8 +103,18 @@ public class ConditionManager extends MiniPlugin
|
||||
return Effect;
|
||||
}
|
||||
|
||||
private void validate(Condition condition)
|
||||
{
|
||||
if (condition == null)
|
||||
throw new NullPointerException("Provided condition was null");
|
||||
if (condition.GetEnt() == null)
|
||||
throw new NullPointerException("Entity in condition " + condition);
|
||||
}
|
||||
|
||||
public Condition AddCondition(Condition newCon)
|
||||
{
|
||||
validate(newCon);
|
||||
|
||||
//Event
|
||||
ConditionApplyEvent condEvent = new ConditionApplyEvent(newCon);
|
||||
getPlugin().getServer().getPluginManager().callEvent(condEvent);
|
||||
@ -134,6 +155,7 @@ public class ConditionManager extends MiniPlugin
|
||||
|
||||
public ConditionActive GetIndicatorType(Condition newCon)
|
||||
{
|
||||
validate(newCon);
|
||||
if (!_activeConditions.containsKey(newCon.GetEnt()))
|
||||
_activeConditions.put(newCon.GetEnt(), new LinkedList<>());
|
||||
|
||||
@ -146,6 +168,8 @@ public class ConditionManager extends MiniPlugin
|
||||
|
||||
public void AddIndicator(Condition newCon)
|
||||
{
|
||||
validate(newCon);
|
||||
|
||||
//Create
|
||||
ConditionActive newInd = new ConditionActive(newCon);
|
||||
|
||||
@ -165,6 +189,8 @@ public class ConditionManager extends MiniPlugin
|
||||
|
||||
public void UpdateActive(ConditionActive active, Condition newCon)
|
||||
{
|
||||
validate(newCon);
|
||||
|
||||
//Not Additive
|
||||
|
||||
if (!active.GetCondition().IsExpired())
|
||||
@ -191,6 +217,12 @@ public class ConditionManager extends MiniPlugin
|
||||
/** Conditions **/
|
||||
for (LivingEntity ent : _conditions.keySet())
|
||||
{
|
||||
if (ent == null)
|
||||
{
|
||||
_conditions.remove(null);
|
||||
continue;
|
||||
}
|
||||
|
||||
Iterator<Condition> conditionIterator = _conditions.get(ent).iterator();
|
||||
|
||||
while (conditionIterator.hasNext())
|
||||
@ -213,6 +245,12 @@ public class ConditionManager extends MiniPlugin
|
||||
/** Indicators **/
|
||||
for (LivingEntity ent : _activeConditions.keySet())
|
||||
{
|
||||
if (ent == null)
|
||||
{
|
||||
_activeConditions.remove(null);
|
||||
continue;
|
||||
}
|
||||
|
||||
Iterator<ConditionActive> conditionIndicatorIterator = _activeConditions.get(ent).iterator();
|
||||
|
||||
while (conditionIndicatorIterator.hasNext())
|
||||
|
Loading…
Reference in New Issue
Block a user