Added "Entities.Only Stack Flying Down" option.

This commit is contained in:
Brianna 2019-06-22 21:10:11 -04:00
parent d5e98a98b7
commit a00b1abda2
3 changed files with 95 additions and 75 deletions

View File

@ -55,44 +55,44 @@ public class StackingTask extends BukkitRunnable {
|| !Setting.STACK_ENTITIES.getBoolean())
continue;
LivingEntity initalEntity = (LivingEntity) entityO;
LivingEntity initialEntity = (LivingEntity) entityO;
if (initalEntity.isDead()
|| !initalEntity.isValid()
|| initalEntity instanceof ArmorStand
|| initalEntity.hasMetadata("inLove")
if (initialEntity.isDead()
|| !initialEntity.isValid()
|| initialEntity instanceof ArmorStand
|| initialEntity.hasMetadata("inLove")
|| Setting.ONLY_STACK_FROM_SPAWNERS.getBoolean()
&& !(initalEntity.hasMetadata("US_REASON")
&& initalEntity.getMetadata("US_REASON").get(0).asString().equals("SPAWNER"))
&& !(initialEntity.hasMetadata("US_REASON")
&& initialEntity.getMetadata("US_REASON").get(0).asString().equals("SPAWNER"))
|| Setting.ONLY_STACK_ON_SURFACE.getBoolean()
&& !canFly(initalEntity)
&& (!initalEntity.isOnGround() && !initalEntity.getLocation().getBlock().isLiquid()))
&& !Methods.canFly(initialEntity)
&& (!initialEntity.isOnGround() && !initialEntity.getLocation().getBlock().isLiquid()))
continue;
EntityStack initialStack = stackManager.getStack(initalEntity);
if (initialStack == null && initalEntity.getCustomName() != null) continue;
EntityStack initialStack = stackManager.getStack(initialEntity);
if (initialStack == null && initialEntity.getCustomName() != null) continue;
int amtToStack = initialStack != null ? initialStack.getAmount() : 1;
ConfigurationSection configurationSection = UltimateStacker.getInstance().getMobFile().getConfig();
if (!configurationSection.getBoolean("Mobs." + initalEntity.getType().name() + ".Enabled"))
if (!configurationSection.getBoolean("Mobs." + initialEntity.getType().name() + ".Enabled"))
continue;
int maxEntityStackSize = maxEntityStackSizeGlobal;
if (configurationSection.getInt("Mobs." + initalEntity.getType().name() + ".Max Stack Size") != -1)
maxEntityStackSize = configurationSection.getInt("Mobs." + initalEntity.getType().name() + ".Max Stack Size");
if (configurationSection.getInt("Mobs." + initialEntity.getType().name() + ".Max Stack Size") != -1)
maxEntityStackSize = configurationSection.getInt("Mobs." + initialEntity.getType().name() + ".Max Stack Size");
List<LivingEntity> entityList = Methods.getSimilarEntitiesAroundEntity(initalEntity);
List<LivingEntity> entityList = Methods.getSimilarEntitiesAroundEntity(initialEntity);
entityList.removeIf(entity -> entity.hasMetadata("inLove")
|| entity.hasMetadata("breedCooldown")
|| Setting.ONLY_STACK_FROM_SPAWNERS.getBoolean()
&& !(initalEntity.hasMetadata("US_REASON")
&& initalEntity.getMetadata("US_REASON").get(0).asString().equals("SPAWNER")));
&& !(initialEntity.hasMetadata("US_REASON")
&& initialEntity.getMetadata("US_REASON").get(0).asString().equals("SPAWNER")));
for (Entity entity : new ArrayList<>(entityList)) {
for (LivingEntity entity : new ArrayList<>(entityList)) {
if (removed.contains(entity.getUniqueId())) continue;
EntityStack stack = stackManager.getStack(entity);
if (stack == null && entity.getCustomName() != null) {
@ -104,8 +104,19 @@ public class StackingTask extends BukkitRunnable {
if (stack != null && (stack.getAmount() + amtToStack) <= maxEntityStackSize) {
stack.addAmount(amtToStack);
stack.updateStack();
removed.add(initalEntity.getUniqueId());
initalEntity.remove();
removed.add(initialEntity.getUniqueId());
initialEntity.remove();
continue nextEntity;
} else if (stack == null
&& initialStack != null
&& (initialStack.getAmount() + 1) <= maxEntityStackSize
&& Methods.canFly(entity)
&& Setting.ONLY_STACK_FLYING_DOWN.getBoolean()
&& initialEntity.getLocation().getY() > entity.getLocation().getY()) {
stackManager.addStack(entity, initialStack.getAmount() + 1);
removed.add(initialEntity.getUniqueId());
initialEntity.remove();
continue nextEntity;
}
@ -120,7 +131,7 @@ public class StackingTask extends BukkitRunnable {
|| minEntityStackAmount == 1 && entityList.size() == 0) continue;
//If stack was never found make a new one.
EntityStack stack = stackManager.addStack(new EntityStack(initalEntity, (entityList.size() + 1) >
EntityStack stack = stackManager.addStack(new EntityStack(initialEntity, (entityList.size() + 1) >
maxEntityStackSize ? maxEntityStackSize : entityList.size() + 1));
entityList.stream().filter(entity -> !stackManager.isStacked(entity)
@ -136,14 +147,4 @@ public class StackingTask extends BukkitRunnable {
}
}
private boolean canFly(LivingEntity entity) {
switch (entity.getType()) {
case GHAST:
case BLAZE:
case PHANTOM:
return true;
default:
return false;
}
}
}

View File

@ -22,6 +22,17 @@ import java.util.stream.Collectors;
public class Methods {
public static boolean canFly(LivingEntity entity) {
switch (entity.getType()) {
case GHAST:
case BLAZE:
case PHANTOM:
return true;
default:
return false;
}
}
public static LivingEntity newEntity(LivingEntity toClone) {
LivingEntity newEntity = (LivingEntity) toClone.getWorld().spawnEntity(toClone.getLocation(), toClone.getType());
newEntity.setVelocity(toClone.getVelocity());
@ -185,6 +196,9 @@ public class Methods {
List<String> checks = Setting.STACK_CHECKS.getStringList();
if (Setting.ONLY_STACK_FLYING_DOWN.getBoolean() && Methods.canFly(initalEntity))
entityList.removeIf(entity -> entity.getLocation().getY() > initalEntity.getLocation().getY());
for (String checkStr : checks) {
Check check = Check.valueOf(checkStr);
switch (check) {

View File

@ -95,68 +95,73 @@ public enum Setting {
"Should entities only be stacked if they are touching the ground",
"or swimming? This does not effect flying entities."),
STACK_ITEMS("Items.Enabled",true,
"Should items be stacked?"),
ONLY_STACK_FLYING_DOWN("Entities.Only Stack Flying Down", true,
"Should entities that fly only stack with entities that are lower on the",
"Y axis. This is important for grinders so that flying entities don't continuously",
"to a higher up entity."),
ITEM_HOLOGRAMS("Items.Holograms Enabled",true,
"Should holograms be displayed above stacked items?"),
STACK_ITEMS("Items.Enabled", true,
"Should items be stacked?"),
MAX_STACK_ITEMS("Items.Max Stack Size",512,
"The max stack size for items.",
"Currently this can only be set to a max of 120."),
ITEM_HOLOGRAMS("Items.Holograms Enabled", true,
"Should holograms be displayed above stacked items?"),
NAME_FORMAT_ITEM("Items.Name Format","&f{TYPE} &6{AMT}x",
"The text displayed above a dropped item."),
MAX_STACK_ITEMS("Items.Max Stack Size", 512,
"The max stack size for items.",
"Currently this can only be set to a max of 120."),
SPAWNERS_ENABLED("Spawners.Enabled",true,
"Should spawners be stacked?"),
NAME_FORMAT_ITEM("Items.Name Format", "&f{TYPE} &6{AMT}x",
"The text displayed above a dropped item."),
SPAWNER_HOLOGRAMS("Spawners.Holograms Enabled",true,
"Should holograms be displayed above stacked spawners?"),
SPAWNERS_ENABLED("Spawners.Enabled", true,
"Should spawners be stacked?"),
MAX_STACK_SPAWNERS("Spawners.Max Stack Size",5,
"What should the max a spawner can stack to be?"),
SPAWNER_HOLOGRAMS("Spawners.Holograms Enabled", true,
"Should holograms be displayed above stacked spawners?"),
SNEAK_FOR_STACK("Spawners.Sneak To Receive A Stacked Spawner",true,
"Toggle ability to receive a stacked spawner when breaking a spawner while sneaking."),
MAX_STACK_SPAWNERS("Spawners.Max Stack Size", 5,
"What should the max a spawner can stack to be?"),
SPAWNERS_DONT_EXPLODE("Spawners.Prevent Spawners From Exploding",false,
"Should spawners not break when blown up?"),
SNEAK_FOR_STACK("Spawners.Sneak To Receive A Stacked Spawner", true,
"Toggle ability to receive a stacked spawner when breaking a spawner while sneaking."),
EXPLOSION_DROP_CHANCE_TNT("Spawners.Chance On TNT Explosion","100%",
"Chance of a TNT explosion dropping a spawner."),
SPAWNERS_DONT_EXPLODE("Spawners.Prevent Spawners From Exploding", false,
"Should spawners not break when blown up?"),
EXPLOSION_DROP_CHANCE_CREEPER("Spawners.Chance On Creeper Explosion","100%",
"Chance of a creeper explosion dropping a spawner."),
EXPLOSION_DROP_CHANCE_TNT("Spawners.Chance On TNT Explosion", "100%",
"Chance of a TNT explosion dropping a spawner."),
NAME_FORMAT_SPAWNER("Spawners.Name Format","&f{TYPE} Spawner &6{AMT}x",
"The text displayed above a stacked spawner where {TYPE} refers to",
"The entities type and {AMT} is the amount currently stacked."),
EXPLOSION_DROP_CHANCE_CREEPER("Spawners.Chance On Creeper Explosion", "100%",
"Chance of a creeper explosion dropping a spawner."),
DATABASE_SUPPORT("Database.Activate Mysql Support",false,
"Should MySQL be used for data storage?"),
NAME_FORMAT_SPAWNER("Spawners.Name Format", "&f{TYPE} Spawner &6{AMT}x",
"The text displayed above a stacked spawner where {TYPE} refers to",
"The entities type and {AMT} is the amount currently stacked."),
DATABASE_IP("Database.IP","127.0.0.1",
"MySQL IP"),
DATABASE_SUPPORT("Database.Activate Mysql Support", false,
"Should MySQL be used for data storage?"),
DATABASE_PORT("Database.Port",3306,
"MySQL Port"),
DATABASE_IP("Database.IP", "127.0.0.1",
"MySQL IP"),
DATABASE_NAME("Database.Database Name","UltimateStacker",
"The database you are inserting data into."),
DATABASE_PORT("Database.Port", 3306,
"MySQL Port"),
DATABASE_PREFIX("Database.Prefix","US-",
"The prefix for tables inserted into the database."),
DATABASE_NAME("Database.Database Name", "UltimateStacker",
"The database you are inserting data into."),
DATABASE_USERNAME("Database.Username","PUT_USERNAME_HERE",
"MySQL Username"),
DATABASE_PREFIX("Database.Prefix", "US-",
"The prefix for tables inserted into the database."),
DATABASE_PASSWORD("Database.Password","PUT_PASSWORD_HERE",
"MySQL Password"),
DATABASE_USERNAME("Database.Username", "PUT_USERNAME_HERE",
"MySQL Username"),
LANGUGE_MODE("System.Language Mode","en_US",
"The enabled language file.",
"More language files (if available) can be found in the plugins data folder.");
DATABASE_PASSWORD("Database.Password", "PUT_PASSWORD_HERE",
"MySQL Password"),
LANGUGE_MODE("System.Language Mode", "en_US",
"The enabled language file.",
"More language files (if available) can be found in the plugins data folder.");
private String setting;
private Object option;
@ -223,4 +228,4 @@ public enum Setting {
public double getDouble() {
return UltimateStacker.getInstance().getConfig().getDouble(setting);
}
}
}