mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-12-31 21:07:47 +01:00
sync lock health updates
This commit is contained in:
parent
7a406283a3
commit
0f3d21c1ec
@ -25,7 +25,8 @@ public class EntityStack {
|
||||
private UUID entity;
|
||||
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();
|
||||
|
||||
public EntityStack(LivingEntity entity, int amount) {
|
||||
@ -192,16 +193,22 @@ public class EntityStack {
|
||||
|
||||
public void updateHealth(LivingEntity entity) {
|
||||
if (entity == null) return;
|
||||
entity.setHealth(Settings.STACK_ENTITY_HEALTH.getBoolean()
|
||||
&& !this.health.isEmpty() ? this.health.removeFirst() : entity.getMaxHealth());
|
||||
synchronized (healthLock) {
|
||||
entity.setHealth(Settings.STACK_ENTITY_HEALTH.getBoolean()
|
||||
&& !this.health.isEmpty() ? this.health.removeFirst() : entity.getMaxHealth());
|
||||
}
|
||||
}
|
||||
|
||||
public void addHealth(double health) {
|
||||
this.health.addLast(health);
|
||||
synchronized(healthLock) {
|
||||
this.health.addLast(health);
|
||||
}
|
||||
}
|
||||
|
||||
public void mergeHealth(EntityStack stack) {
|
||||
this.health.addAll(stack.health);
|
||||
synchronized(healthLock) {
|
||||
this.health.addAll(stack.health);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,16 +19,17 @@ public class StackingTask extends BukkitRunnable {
|
||||
|
||||
private final UltimateStacker plugin;
|
||||
|
||||
private EntityStackManager stackManager;
|
||||
private final EntityStackManager stackManager;
|
||||
|
||||
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 int minEntityStackSize = Settings.MIN_STACK_ENTITIES.getInt();
|
||||
|
||||
private int maxPerTypeStacksPerChunk = Settings.MAX_PER_TYPE_STACKS_PER_CHUNK.getInt();
|
||||
private final HashMap<EntityType, Integer> entityStackSizes = new HashMap();
|
||||
private final int maxEntityStackSize = Settings.MAX_STACK_ENTITIES.getInt();
|
||||
private final int minEntityStackSize = Settings.MIN_STACK_ENTITIES.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) {
|
||||
this.plugin = plugin;
|
||||
@ -76,7 +77,6 @@ public class StackingTask extends BukkitRunnable {
|
||||
}
|
||||
|
||||
public boolean isWorldDisabled(World world) {
|
||||
List<String> disabledWorlds = Settings.DISABLED_WORLDS.getStringList();
|
||||
return disabledWorlds.stream().anyMatch(worldStr -> world.getName().equalsIgnoreCase(worldStr));
|
||||
}
|
||||
|
||||
@ -290,8 +290,14 @@ public class StackingTask extends BukkitRunnable {
|
||||
}
|
||||
|
||||
private int getEntityStackSize(LivingEntity initialEntity) {
|
||||
if (configurationSection.getInt("Mobs." + initialEntity.getType().name() + ".Max Stack Size") != -1)
|
||||
maxEntityStackSize = configurationSection.getInt("Mobs." + initialEntity.getType().name() + ".Max Stack Size");
|
||||
return maxEntityStackSize;
|
||||
Integer max = entityStackSizes.get(initialEntity.getType());
|
||||
if(max == null) {
|
||||
max = configurationSection.getInt("Mobs." + initialEntity.getType().name() + ".Max Stack Size");
|
||||
if(max == -1) {
|
||||
max = maxEntityStackSize;
|
||||
}
|
||||
entityStackSizes.put(initialEntity.getType(), max);
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user