Attempt at carrying over lowest health feature.

This commit is contained in:
Brianna 2019-06-28 16:00:30 -04:00
parent 38787e0c1e
commit 0efcd158f8
4 changed files with 24 additions and 7 deletions

View File

@ -29,6 +29,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BlockStateMeta; import org.bukkit.inventory.meta.BlockStateMeta;
import java.util.List; import java.util.List;
import java.util.Random;
public class SpawnerListeners implements Listener { public class SpawnerListeners implements Listener {
@ -45,7 +46,6 @@ public class SpawnerListeners implements Listener {
if (instance.getStackingTask().attemptAddToStack((LivingEntity) event.getEntity(), null)) { if (instance.getStackingTask().attemptAddToStack((LivingEntity) event.getEntity(), null)) {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
if (entity.getType() == EntityType.FIREWORK) return;
if (entity.getVehicle() != null) { if (entity.getVehicle() != null) {
entity.getVehicle().remove(); entity.getVehicle().remove();
entity.remove(); entity.remove();
@ -60,6 +60,7 @@ public class SpawnerListeners implements Listener {
} }
} }
entity.remove(); entity.remove();
} }
} }
} }

View File

@ -117,6 +117,9 @@ public class StackingTask extends BukkitRunnable {
stack.addAmount(amtToStack); stack.addAmount(amtToStack);
stack.updateStack(); stack.updateStack();
removed.add(initialEntity.getUniqueId()); removed.add(initialEntity.getUniqueId());
fixHealth(entity, initialEntity);
initialEntity.remove(); initialEntity.remove();
return true; return true;
@ -128,6 +131,9 @@ public class StackingTask extends BukkitRunnable {
&& initialEntity.getLocation().getY() > entity.getLocation().getY()) { && initialEntity.getLocation().getY() > entity.getLocation().getY()) {
stackManager.addStack(entity, initialStack.getAmount() + 1); stackManager.addStack(entity, initialStack.getAmount() + 1);
removed.add(initialEntity.getUniqueId()); removed.add(initialEntity.getUniqueId());
fixHealth(initialEntity, entity);
initialEntity.remove(); initialEntity.remove();
return true; return true;
@ -148,6 +154,9 @@ public class StackingTask extends BukkitRunnable {
entityList.stream().filter(entity -> !stackManager.isStacked(entity) entityList.stream().filter(entity -> !stackManager.isStacked(entity)
&& !removed.contains(entity.getUniqueId())).limit(maxEntityStackSize).forEach(entity -> { && !removed.contains(entity.getUniqueId())).limit(maxEntityStackSize).forEach(entity -> {
fixHealth(initialEntity, entity);
removed.add(entity.getUniqueId()); removed.add(entity.getUniqueId());
entity.remove(); entity.remove();
}); });
@ -156,4 +165,9 @@ public class StackingTask extends BukkitRunnable {
return false; return false;
} }
private void fixHealth(LivingEntity entity, LivingEntity initialEntity) {
if (Setting.CARRY_OVER_LOWEST_HEALTH.getBoolean() && initialEntity.getHealth() < entity.getHealth())
entity.setHealth(initialEntity.getHealth());
}
} }

View File

@ -179,10 +179,10 @@ public class Methods {
if (Setting.KEEP_FIRE.getBoolean()) if (Setting.KEEP_FIRE.getBoolean())
newEntity.setFireTicks(toClone.getFireTicks()); newEntity.setFireTicks(toClone.getFireTicks());
if (Setting.KEEP_POTION.getBoolean()) if (Setting.KEEP_POTION.getBoolean())
newEntity.addPotionEffects(toClone.getActivePotionEffects()); newEntity.addPotionEffects(toClone.getActivePotionEffects());
return newEntity; return newEntity;
} }
public static List<LivingEntity> getSimilarEntitiesAroundEntity(LivingEntity initalEntity) { public static List<LivingEntity> getSimilarEntitiesAroundEntity(LivingEntity initalEntity) {
@ -368,7 +368,7 @@ public class Methods {
} }
case PARROT_TYPE: { case PARROT_TYPE: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_12) if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_12)
||!(initalEntity instanceof Parrot)) break; || !(initalEntity instanceof Parrot)) break;
Parrot parrot = (Parrot) initalEntity; Parrot parrot = (Parrot) initalEntity;
entityList.removeIf(entity -> ((Parrot) entity).getVariant() != parrot.getVariant()); entityList.removeIf(entity -> ((Parrot) entity).getVariant() != parrot.getVariant());
break; break;
@ -502,10 +502,10 @@ public class Methods {
ItemStack glass; ItemStack glass;
if (rainbow) { if (rainbow) {
glass = new ItemStack(UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? glass = new ItemStack(UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ?
Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) randomNum); Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) randomNum);
} else { } else {
glass = new ItemStack(UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? glass = new ItemStack(UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ?
Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) type); Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) type);
} }
ItemMeta glassmeta = glass.getItemMeta(); ItemMeta glassmeta = glass.getItemMeta();
glassmeta.setDisplayName("§l"); glassmeta.setDisplayName("§l");
@ -624,5 +624,4 @@ public class Methods {
} }
} }

View File

@ -85,6 +85,9 @@ public enum Setting {
KEEP_POTION("Entities.Keep Potion Effects", true, KEEP_POTION("Entities.Keep Potion Effects", true,
"Should potion effects persist to the next entity when an entity dies?"), "Should potion effects persist to the next entity when an entity dies?"),
CARRY_OVER_LOWEST_HEALTH("Entities.Carry Over Lowest Health", true,
"Should the lowest health be carried over when stacked?"),
ONLY_STACK_FROM_SPAWNERS("Entities.Only Stack From Spawners", false, ONLY_STACK_FROM_SPAWNERS("Entities.Only Stack From Spawners", false,
"Should entities only be stacked if they originate from a spawner?", "Should entities only be stacked if they originate from a spawner?",
"It should be noted that the identifier that tells the plugin", "It should be noted that the identifier that tells the plugin",