mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-12-31 21:07:47 +01:00
Merge branch 'development'
This commit is contained in:
commit
a33ac48df6
2
pom.xml
2
pom.xml
@ -2,7 +2,7 @@
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>UltimateStacker</artifactId>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>1.11.5</version>
|
||||
<version>1.11.6</version>
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<finalName>UltimateStacker-${project.version}</finalName>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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?");
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user