sync lock health updates

This commit is contained in:
jascotty2 2019-09-10 15:45:26 -05:00
parent 7a406283a3
commit 0f3d21c1ec
2 changed files with 28 additions and 15 deletions

View File

@ -25,7 +25,8 @@ public class EntityStack {
private UUID entity; private UUID entity;
private int amount; private int amount;
private Deque<Double> health = new ArrayDeque<>(); private final Deque<Double> health = new ArrayDeque<>();
final Object healthLock = new Object();
UltimateStacker plugin = UltimateStacker.getInstance(); UltimateStacker plugin = UltimateStacker.getInstance();
public EntityStack(LivingEntity entity, int amount) { public EntityStack(LivingEntity entity, int amount) {
@ -192,16 +193,22 @@ public class EntityStack {
public void updateHealth(LivingEntity entity) { public void updateHealth(LivingEntity entity) {
if (entity == null) return; if (entity == null) return;
entity.setHealth(Settings.STACK_ENTITY_HEALTH.getBoolean() synchronized (healthLock) {
&& !this.health.isEmpty() ? this.health.removeFirst() : entity.getMaxHealth()); entity.setHealth(Settings.STACK_ENTITY_HEALTH.getBoolean()
&& !this.health.isEmpty() ? this.health.removeFirst() : entity.getMaxHealth());
}
} }
public void addHealth(double health) { public void addHealth(double health) {
this.health.addLast(health); synchronized(healthLock) {
this.health.addLast(health);
}
} }
public void mergeHealth(EntityStack stack) { public void mergeHealth(EntityStack stack) {
this.health.addAll(stack.health); synchronized(healthLock) {
this.health.addAll(stack.health);
}
} }
@Override @Override

View File

@ -19,16 +19,17 @@ public class StackingTask extends BukkitRunnable {
private final UltimateStacker plugin; private final UltimateStacker plugin;
private EntityStackManager stackManager; private final EntityStackManager stackManager;
ConfigurationSection configurationSection = UltimateStacker.getInstance().getMobFile(); ConfigurationSection configurationSection = UltimateStacker.getInstance().getMobFile();
private List<UUID> processed = new ArrayList<>(); private final List<UUID> processed = new ArrayList<>();
private int maxEntityStackSize = Settings.MAX_STACK_ENTITIES.getInt(); private final HashMap<EntityType, Integer> entityStackSizes = new HashMap();
private int minEntityStackSize = Settings.MIN_STACK_ENTITIES.getInt(); private final int maxEntityStackSize = Settings.MAX_STACK_ENTITIES.getInt();
private final int minEntityStackSize = Settings.MIN_STACK_ENTITIES.getInt();
private int maxPerTypeStacksPerChunk = Settings.MAX_PER_TYPE_STACKS_PER_CHUNK.getInt(); private final int maxPerTypeStacksPerChunk = Settings.MAX_PER_TYPE_STACKS_PER_CHUNK.getInt();
private final List<String> disabledWorlds = Settings.DISABLED_WORLDS.getStringList();
public StackingTask(UltimateStacker plugin) { public StackingTask(UltimateStacker plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -76,7 +77,6 @@ public class StackingTask extends BukkitRunnable {
} }
public boolean isWorldDisabled(World world) { public boolean isWorldDisabled(World world) {
List<String> disabledWorlds = Settings.DISABLED_WORLDS.getStringList();
return disabledWorlds.stream().anyMatch(worldStr -> world.getName().equalsIgnoreCase(worldStr)); return disabledWorlds.stream().anyMatch(worldStr -> world.getName().equalsIgnoreCase(worldStr));
} }
@ -290,8 +290,14 @@ public class StackingTask extends BukkitRunnable {
} }
private int getEntityStackSize(LivingEntity initialEntity) { private int getEntityStackSize(LivingEntity initialEntity) {
if (configurationSection.getInt("Mobs." + initialEntity.getType().name() + ".Max Stack Size") != -1) Integer max = entityStackSizes.get(initialEntity.getType());
maxEntityStackSize = configurationSection.getInt("Mobs." + initialEntity.getType().name() + ".Max Stack Size"); if(max == null) {
return maxEntityStackSize; max = configurationSection.getInt("Mobs." + initialEntity.getType().name() + ".Max Stack Size");
if(max == -1) {
max = maxEntityStackSize;
}
entityStackSizes.put(initialEntity.getType(), max);
}
return max;
} }
} }