From 92cdeae93889e8a428177d159db5f2299412f8c2 Mon Sep 17 00:00:00 2001 From: Brianna Date: Sun, 2 Feb 2020 09:46:00 -0500 Subject: [PATCH 1/3] Remove invulnerable from 1.8 --- .../java/com/songoda/ultimatestacker/utils/EntityUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/songoda/ultimatestacker/utils/EntityUtils.java b/src/main/java/com/songoda/ultimatestacker/utils/EntityUtils.java index 9026fd7..598fdbe 100644 --- a/src/main/java/com/songoda/ultimatestacker/utils/EntityUtils.java +++ b/src/main/java/com/songoda/ultimatestacker/utils/EntityUtils.java @@ -97,7 +97,8 @@ public class EntityUtils { newEntity.setVelocity(toClone.getVelocity()); } - newEntity.setInvulnerable(false); + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_12)) + newEntity.setInvulnerable(false); for (String checkStr : checks) { Check check = Check.valueOf(checkStr); From 4c70a6e79ed9c5d237367088320697931fcfae87 Mon Sep 17 00:00:00 2001 From: Brianna Date: Sun, 2 Feb 2020 11:11:50 -0500 Subject: [PATCH 2/3] Add the ability to shear all entities in a stack at once. --- .../listeners/ShearListeners.java | 67 +++++++++++++++++-- .../ultimatestacker/settings/Settings.java | 3 + 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/songoda/ultimatestacker/listeners/ShearListeners.java b/src/main/java/com/songoda/ultimatestacker/listeners/ShearListeners.java index ff12e60..8be82f2 100644 --- a/src/main/java/com/songoda/ultimatestacker/listeners/ShearListeners.java +++ b/src/main/java/com/songoda/ultimatestacker/listeners/ShearListeners.java @@ -1,16 +1,22 @@ package com.songoda.ultimatestacker.listeners; +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.core.compatibility.ServerVersion; import com.songoda.ultimatestacker.UltimateStacker; +import com.songoda.ultimatestacker.entity.EntityStack; import com.songoda.ultimatestacker.entity.EntityStackManager; import com.songoda.ultimatestacker.entity.Split; import com.songoda.ultimatestacker.settings.Settings; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.LivingEntity; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.*; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerShearEntityEvent; +import org.bukkit.inventory.ItemStack; + +import java.util.Random; public class ShearListeners implements Listener { @@ -38,6 +44,59 @@ public class ShearListeners implements Listener { && Settings.SPLIT_CHECKS.getStringList().stream().noneMatch(line -> Split.valueOf(line) == Split.SNOWMAN_DERP)) return; - plugin.getEntityUtils().splitFromStack((LivingEntity)entity); + + if (Settings.SHEAR_IN_ONE_CLICK.getBoolean()) { + World world = entity.getLocation().getWorld(); + EntityStack stack = stackManager.getStack(entity); + int amount = stack.getAmount() - 1; + ItemStack item = getDrop(entity); + if (item == null) + return; + + int amountToDrop = 0; + + if (entity.getType() == EntityType.SHEEP) { + for (int i = 0; i < amount; i++) { + amountToDrop += new Random().nextInt(2) + 1; + } + } else + amountToDrop = item.getAmount() * amount; + + int fullStacks = (int) Math.floor(amountToDrop / 64); + int nonStack = amountToDrop - (fullStacks * 64); + + for (int i = 0; i < fullStacks; i++) { + ItemStack clone = item.clone(); + clone.setAmount(64); + world.dropItemNaturally(entity.getLocation(), clone); + } + if (nonStack != 0) { + ItemStack clone = item.clone(); + clone.setAmount(nonStack); + world.dropItemNaturally(entity.getLocation(), clone); + } + } else + plugin.getEntityUtils().splitFromStack((LivingEntity) entity); + } + + private ItemStack getDrop(Entity entity) { + ItemStack itemStack = null; + + switch (entity.getType()) { + case SHEEP: + itemStack = new ItemStack(CompatibleMaterial.WHITE_WOOL.getMaterial()); + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) + itemStack.setType(Material.valueOf(((Sheep) entity).getColor() + "_WOOL")); + else + itemStack.setDurability((short) ((Sheep) entity).getColor().getWoolData()); + break; + case MUSHROOM_COW: + itemStack = new ItemStack(CompatibleMaterial.RED_MUSHROOM.getMaterial(), 5); + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_14) + && ((MushroomCow) entity).getVariant() == MushroomCow.Variant.BROWN) + itemStack.setType(CompatibleMaterial.BROWN_MUSHROOM.getMaterial()); + break; + } + return itemStack; } } diff --git a/src/main/java/com/songoda/ultimatestacker/settings/Settings.java b/src/main/java/com/songoda/ultimatestacker/settings/Settings.java index 4d8fc8a..428daae 100644 --- a/src/main/java/com/songoda/ultimatestacker/settings/Settings.java +++ b/src/main/java/com/songoda/ultimatestacker/settings/Settings.java @@ -171,6 +171,9 @@ public class Settings { public static final ConfigSetting DISABLE_KNOCKBACK = new ConfigSetting(config, "Entities.Disable Knockback", false, "Should knockback be disabled on unstacked mobs?"); + public static final ConfigSetting SHEAR_IN_ONE_CLICK = new ConfigSetting(config, "Entities.Shear In One Click", false, + "Should entities be sheared in a single click?"); + public static final ConfigSetting STACK_ITEMS = new ConfigSetting(config, "Items.Enabled", true, "Should items be stacked?"); From 613a1a4b2500679357c9b4a348c9e3c109c2459a Mon Sep 17 00:00:00 2001 From: Brianna Date: Sun, 2 Feb 2020 11:12:16 -0500 Subject: [PATCH 3/3] version 1.11.6 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e54ed3b..f296e08 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ com.songoda UltimateStacker 4.0.0 - 1.11.5 + 1.11.6 clean install UltimateStacker-${project.version}