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;
|
package mineplex.minecraft.game.core.condition;
|
||||||
|
|
||||||
import mineplex.core.events.AddConditionEvent;
|
|
||||||
import net.minecraft.server.v1_8_R3.MobEffect;
|
import net.minecraft.server.v1_8_R3.MobEffect;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity;
|
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
|
import mineplex.core.events.AddConditionEvent;
|
||||||
|
|
||||||
public class Condition
|
public class Condition
|
||||||
{
|
{
|
||||||
public enum ConditionType
|
public enum ConditionType
|
||||||
@ -339,4 +341,10 @@ public class Condition
|
|||||||
{
|
{
|
||||||
_mult = Math.max(0, _mult + i);
|
_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
|
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 ConditionFactory _factory;
|
||||||
private ConditionApplicator _applicator;
|
private ConditionApplicator _applicator;
|
||||||
protected ConditionEffect Effect;
|
protected ConditionEffect Effect;
|
||||||
|
|
||||||
private DamageManager _damageManager;
|
private DamageManager _damageManager;
|
||||||
|
|
||||||
private WeakHashMap<LivingEntity, LinkedList<Condition>> _conditions = new WeakHashMap<LivingEntity, LinkedList<Condition>>();
|
private WeakHashMap<LivingEntity, LinkedList<Condition>> _conditions = new ConditionMap<>();
|
||||||
private WeakHashMap<LivingEntity, LinkedList<ConditionActive>> _activeConditions = new WeakHashMap<LivingEntity, LinkedList<ConditionActive>>();
|
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)
|
public ConditionManager(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
@ -92,8 +103,18 @@ public class ConditionManager extends MiniPlugin
|
|||||||
return Effect;
|
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)
|
public Condition AddCondition(Condition newCon)
|
||||||
{
|
{
|
||||||
|
validate(newCon);
|
||||||
|
|
||||||
//Event
|
//Event
|
||||||
ConditionApplyEvent condEvent = new ConditionApplyEvent(newCon);
|
ConditionApplyEvent condEvent = new ConditionApplyEvent(newCon);
|
||||||
getPlugin().getServer().getPluginManager().callEvent(condEvent);
|
getPlugin().getServer().getPluginManager().callEvent(condEvent);
|
||||||
@ -134,6 +155,7 @@ public class ConditionManager extends MiniPlugin
|
|||||||
|
|
||||||
public ConditionActive GetIndicatorType(Condition newCon)
|
public ConditionActive GetIndicatorType(Condition newCon)
|
||||||
{
|
{
|
||||||
|
validate(newCon);
|
||||||
if (!_activeConditions.containsKey(newCon.GetEnt()))
|
if (!_activeConditions.containsKey(newCon.GetEnt()))
|
||||||
_activeConditions.put(newCon.GetEnt(), new LinkedList<>());
|
_activeConditions.put(newCon.GetEnt(), new LinkedList<>());
|
||||||
|
|
||||||
@ -146,6 +168,8 @@ public class ConditionManager extends MiniPlugin
|
|||||||
|
|
||||||
public void AddIndicator(Condition newCon)
|
public void AddIndicator(Condition newCon)
|
||||||
{
|
{
|
||||||
|
validate(newCon);
|
||||||
|
|
||||||
//Create
|
//Create
|
||||||
ConditionActive newInd = new ConditionActive(newCon);
|
ConditionActive newInd = new ConditionActive(newCon);
|
||||||
|
|
||||||
@ -165,6 +189,8 @@ public class ConditionManager extends MiniPlugin
|
|||||||
|
|
||||||
public void UpdateActive(ConditionActive active, Condition newCon)
|
public void UpdateActive(ConditionActive active, Condition newCon)
|
||||||
{
|
{
|
||||||
|
validate(newCon);
|
||||||
|
|
||||||
//Not Additive
|
//Not Additive
|
||||||
|
|
||||||
if (!active.GetCondition().IsExpired())
|
if (!active.GetCondition().IsExpired())
|
||||||
@ -191,6 +217,12 @@ public class ConditionManager extends MiniPlugin
|
|||||||
/** Conditions **/
|
/** Conditions **/
|
||||||
for (LivingEntity ent : _conditions.keySet())
|
for (LivingEntity ent : _conditions.keySet())
|
||||||
{
|
{
|
||||||
|
if (ent == null)
|
||||||
|
{
|
||||||
|
_conditions.remove(null);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Iterator<Condition> conditionIterator = _conditions.get(ent).iterator();
|
Iterator<Condition> conditionIterator = _conditions.get(ent).iterator();
|
||||||
|
|
||||||
while (conditionIterator.hasNext())
|
while (conditionIterator.hasNext())
|
||||||
@ -213,6 +245,12 @@ public class ConditionManager extends MiniPlugin
|
|||||||
/** Indicators **/
|
/** Indicators **/
|
||||||
for (LivingEntity ent : _activeConditions.keySet())
|
for (LivingEntity ent : _activeConditions.keySet())
|
||||||
{
|
{
|
||||||
|
if (ent == null)
|
||||||
|
{
|
||||||
|
_activeConditions.remove(null);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Iterator<ConditionActive> conditionIndicatorIterator = _activeConditions.get(ent).iterator();
|
Iterator<ConditionActive> conditionIndicatorIterator = _activeConditions.get(ent).iterator();
|
||||||
|
|
||||||
while (conditionIndicatorIterator.hasNext())
|
while (conditionIndicatorIterator.hasNext())
|
||||||
|
Loading…
Reference in New Issue
Block a user