mirror of
https://github.com/songoda/UltimateStacker.git
synced 2025-02-17 03:41:20 +01:00
Lots more.
Added ability to shear mooshroom cows. Added ability to configure why entities are split. Redesigned split entity system. Fixed bug causing an entity to be lost when breeding a stack.
This commit is contained in:
parent
479c138893
commit
917a01d356
@ -169,6 +169,7 @@ public class UltimateStacker extends JavaPlugin {
|
||||
Bukkit.getPluginManager().registerEvents(new EntityListeners(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ItemListeners(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(new TameListeners(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(new SheepDyeListeners(this), this);
|
||||
|
||||
// Register Hologram Plugin
|
||||
if (getConfig().getBoolean("Spawners.Holograms Enabled")) {
|
||||
|
@ -15,8 +15,7 @@ public class EntityStack {
|
||||
private int amount;
|
||||
|
||||
public EntityStack(Entity entity, int amount) {
|
||||
this.entity = entity.getUniqueId();
|
||||
this.setAmount(amount);
|
||||
this(entity.getUniqueId(), amount);
|
||||
}
|
||||
|
||||
public EntityStack(UUID uuid, int amount) {
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.songoda.ultimatestacker.entity;
|
||||
|
||||
public enum Split {
|
||||
|
||||
NAME_TAG, MUSHROOM_SHEAR, SHEEP_SHEAR, SHEEP_DYE, ENTITY_BREED
|
||||
|
||||
}
|
@ -2,8 +2,10 @@ package com.songoda.ultimatestacker.listeners;
|
||||
|
||||
import com.songoda.ultimatestacker.UltimateStacker;
|
||||
import com.songoda.ultimatestacker.entity.EntityStack;
|
||||
import com.songoda.ultimatestacker.entity.Split;
|
||||
import com.songoda.ultimatestacker.utils.Methods;
|
||||
import com.songoda.ultimatestacker.utils.ServerVersion;
|
||||
import com.songoda.ultimatestacker.utils.settings.Setting;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.*;
|
||||
@ -25,26 +27,6 @@ public class InteractListeners implements Listener {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onSheepDye(SheepDyeWoolEvent event) {
|
||||
Sheep entity = event.getEntity();
|
||||
|
||||
if (!instance.getEntityStackManager().isStacked(entity) || event.getColor() == entity.getColor()) return;
|
||||
EntityStack stack = instance.getEntityStackManager().getStack(entity);
|
||||
if (stack.getAmount() <= 1) return;
|
||||
|
||||
Entity newEntity = entity.getWorld().spawnEntity(entity.getLocation(), entity.getType());
|
||||
entity.setVelocity(getRandomVector());
|
||||
|
||||
Sheep sheep = ((Sheep) newEntity);
|
||||
sheep.setSheared(entity.isSheared());
|
||||
sheep.setColor(entity.getColor());
|
||||
|
||||
instance.getEntityStackManager().addStack(new EntityStack(newEntity, stack.getAmount() - 1));
|
||||
stack.setAmount(1);
|
||||
instance.getEntityStackManager().removeStack(entity);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractAtEntityEvent event) {
|
||||
if (!(event.getRightClicked() instanceof LivingEntity)) return;
|
||||
@ -59,18 +41,19 @@ public class InteractListeners implements Listener {
|
||||
|
||||
EntityStack stack = instance.getEntityStackManager().getStack(entity);
|
||||
|
||||
if (stack.getAmount() <= 1) return;
|
||||
if (stack.getAmount() <= 1
|
||||
|| item.getType() == Material.NAME_TAG
|
||||
&& Setting.SPLIT_CHECKS.getStringList().stream().noneMatch(line -> Split.valueOf(line) == Split.NAME_TAG)
|
||||
|| item.getType() != Material.NAME_TAG
|
||||
&& Setting.SPLIT_CHECKS.getStringList().stream().noneMatch(line -> Split.valueOf(line) == Split.ENTITY_BREED))
|
||||
return;
|
||||
|
||||
if (item.getType() == Material.NAME_TAG)
|
||||
event.setCancelled(true);
|
||||
else if (entity instanceof Ageable && !((Ageable) entity).isAdult())
|
||||
return;
|
||||
|
||||
Entity newEntity = Methods.newEntity(entity);
|
||||
|
||||
instance.getEntityStackManager().addStack(new EntityStack(newEntity, stack.getAmount() - 1));
|
||||
stack.setAmount(1);
|
||||
instance.getEntityStackManager().removeStack(entity);
|
||||
Methods.splitFromStack(entity);
|
||||
|
||||
if (item.getType() == Material.NAME_TAG) {
|
||||
entity.setCustomName(item.getItemMeta().getDisplayName());
|
||||
@ -88,10 +71,6 @@ public class InteractListeners implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private Vector getRandomVector() {
|
||||
return new Vector(ThreadLocalRandom.current().nextDouble(-1, 1.01), 0, ThreadLocalRandom.current().nextDouble(-1, 1.01)).normalize().multiply(0.5);
|
||||
}
|
||||
|
||||
private boolean correctFood(ItemStack is, Entity entity) {
|
||||
boolean is13 = instance.isServerVersionAtLeast(ServerVersion.V1_13);
|
||||
Material type = is.getType();
|
||||
|
@ -3,14 +3,16 @@ package com.songoda.ultimatestacker.listeners;
|
||||
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.utils.Methods;
|
||||
import com.songoda.ultimatestacker.utils.settings.Setting;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Sheep;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerShearEntityEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.Wool;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
@ -24,42 +26,19 @@ public class ShearListeners implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onShearSheap(PlayerShearEntityEvent event) {
|
||||
public void onShear(PlayerShearEntityEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
|
||||
if (!(entity instanceof Sheep)) return;
|
||||
if (entity.getType() != EntityType.SHEEP && entity.getType() != EntityType.MUSHROOM_COW) return;
|
||||
EntityStackManager stackManager = instance.getEntityStackManager();
|
||||
if (!stackManager.isStacked(entity)) return;
|
||||
|
||||
LivingEntity sheep = (LivingEntity) entity;
|
||||
if (event.getEntity().getType() == EntityType.SHEEP
|
||||
&& Setting.SPLIT_CHECKS.getStringList().stream().noneMatch(line -> Split.valueOf(line) == Split.SHEEP_SHEAR)
|
||||
|| event.getEntity().getType() == EntityType.MUSHROOM_COW
|
||||
&& Setting.SPLIT_CHECKS.getStringList().stream().noneMatch(line -> Split.valueOf(line) == Split.MUSHROOM_SHEAR))
|
||||
return;
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
Entity newEntity = sheep.getWorld().spawnEntity(sheep.getLocation(), sheep.getType());
|
||||
((Sheep) newEntity).setSheared(true);
|
||||
newEntity.setVelocity(getRandomVector());
|
||||
((Sheep) newEntity).setAge(((Sheep) sheep).getAge());
|
||||
((Sheep) newEntity).setColor(((Sheep) sheep).getColor());
|
||||
|
||||
int num = (int) Math.round(1 + (Math.random() * 3));
|
||||
|
||||
|
||||
Wool woolColor = new Wool(((Sheep) sheep).getColor());
|
||||
|
||||
ItemStack wool = woolColor.toItemStack(num);
|
||||
sheep.getLocation().getWorld().dropItemNaturally(sheep.getEyeLocation(), wool);
|
||||
|
||||
EntityStack stack = stackManager.getStack(sheep);
|
||||
stack.addAmount(-1);
|
||||
if (stack.getAmount() <= 1) {
|
||||
stackManager.removeStack(entity);
|
||||
sheep.setCustomNameVisible(false);
|
||||
sheep.setCustomName(null);
|
||||
((Sheep) sheep).setSheared(false);
|
||||
}
|
||||
}
|
||||
|
||||
private Vector getRandomVector() {
|
||||
return new Vector(ThreadLocalRandom.current().nextDouble(-1, 1.01), 0, ThreadLocalRandom.current().nextDouble(-1, 1.01)).normalize().multiply(0.5);
|
||||
Methods.splitFromStack((LivingEntity)entity);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
package com.songoda.ultimatestacker.listeners;
|
||||
|
||||
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.utils.Methods;
|
||||
import com.songoda.ultimatestacker.utils.settings.Setting;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.SheepDyeWoolEvent;
|
||||
import org.bukkit.event.player.PlayerShearEntityEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.Wool;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class SheepDyeListeners implements Listener {
|
||||
|
||||
private UltimateStacker instance;
|
||||
|
||||
public SheepDyeListeners(UltimateStacker instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDye(SheepDyeWoolEvent event) {
|
||||
LivingEntity entity = event.getEntity();
|
||||
|
||||
EntityStackManager stackManager = instance.getEntityStackManager();
|
||||
if (!stackManager.isStacked(entity)) return;
|
||||
|
||||
if (Setting.SPLIT_CHECKS.getStringList().stream().noneMatch(line -> Split.valueOf(line) == Split.SHEEP_DYE))
|
||||
return;
|
||||
|
||||
Methods.splitFromStack(entity);
|
||||
}
|
||||
}
|
@ -13,11 +13,13 @@ import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Methods {
|
||||
@ -159,8 +161,8 @@ public class Methods {
|
||||
break;
|
||||
}
|
||||
case HORSE_JUMP: {
|
||||
if (!(toClone instanceof Horse)) break;
|
||||
((Horse) newEntity).setJumpStrength(((Horse) toClone).getJumpStrength());
|
||||
if (!(toClone instanceof AbstractHorse)) break;
|
||||
((AbstractHorse) newEntity).setJumpStrength(((AbstractHorse) toClone).getJumpStrength());
|
||||
break;
|
||||
}
|
||||
case HORSE_COLOR: {
|
||||
@ -356,9 +358,9 @@ public class Methods {
|
||||
break;
|
||||
}
|
||||
case HORSE_JUMP: {
|
||||
if (!(initalEntity instanceof Horse)) break;
|
||||
Horse horse = ((Horse) initalEntity);
|
||||
entityList.removeIf(entity -> ((Horse) entity).getJumpStrength() != horse.getJumpStrength());
|
||||
if (!(initalEntity instanceof AbstractHorse)) break;
|
||||
AbstractHorse horse = ((AbstractHorse) initalEntity);
|
||||
entityList.removeIf(entity -> ((AbstractHorse) entity).getJumpStrength() != horse.getJumpStrength());
|
||||
break;
|
||||
}
|
||||
case HORSE_COLOR: {
|
||||
@ -381,7 +383,10 @@ public class Methods {
|
||||
}
|
||||
case ENDERMAN_CARRY_BLOCK: {
|
||||
if (!(initalEntity instanceof Enderman)) break;
|
||||
entityList.removeIf(entity -> ((Enderman) entity).getCarriedBlock() != null);
|
||||
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13))
|
||||
entityList.removeIf(entity -> ((Enderman) entity).getCarriedBlock() == null);
|
||||
else
|
||||
entityList.removeIf(entity -> ((Enderman) entity).getCarriedMaterial().getItemType() == null);
|
||||
break;
|
||||
}
|
||||
case WOLF_COLLAR_COLOR: {
|
||||
@ -459,6 +464,27 @@ public class Methods {
|
||||
return entityList;
|
||||
}
|
||||
|
||||
public static void splitFromStack(LivingEntity entity) {
|
||||
UltimateStacker instance = UltimateStacker.getInstance();
|
||||
EntityStack stack = instance.getEntityStackManager().getStack(entity);
|
||||
|
||||
if (stack.getAmount() <= 1) return;
|
||||
|
||||
Entity newEntity = Methods.newEntity(entity);
|
||||
|
||||
int newAmount = stack.getAmount() - 1;
|
||||
if (newAmount != 1)
|
||||
instance.getEntityStackManager().addStack(new EntityStack(newEntity, newAmount));
|
||||
stack.setAmount(1);
|
||||
instance.getEntityStackManager().removeStack(entity);
|
||||
entity.setVelocity(getRandomVector());
|
||||
}
|
||||
|
||||
|
||||
private static Vector getRandomVector() {
|
||||
return new Vector(ThreadLocalRandom.current().nextDouble(-1, 1.01), 0, ThreadLocalRandom.current().nextDouble(-1, 1.01)).normalize().multiply(0.5);
|
||||
}
|
||||
|
||||
public static String compileSpawnerName(EntityType entityType, int amount) {
|
||||
String nameFormat = UltimateStacker.getInstance().getConfig().getString("Spawners.Name Format");
|
||||
String displayName = Methods.formatText(UltimateStacker.getInstance().getSpawnerFile().getConfig().getString("Spawners." + entityType.name() + ".Display Name"));
|
||||
|
@ -2,6 +2,7 @@ package com.songoda.ultimatestacker.utils.settings;
|
||||
|
||||
import com.songoda.ultimatestacker.UltimateStacker;
|
||||
import com.songoda.ultimatestacker.entity.Check;
|
||||
import com.songoda.ultimatestacker.entity.Split;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -64,6 +65,11 @@ public enum Setting {
|
||||
"LLAMA_COLOR, LLAMA_STRENGTH, PARROT_TYPE, PUFFERFISH_STATE",
|
||||
"TROPICALFISH_PATTERN, TROPICALFISH_BODY_COLOR, TROPICALFISH_PATTERN_COLOR"),
|
||||
|
||||
SPLIT_CHECKS("Entity.Split Checks", Arrays.asList(Split.values()).stream()
|
||||
.map(Split::name).collect(Collectors.toList()),
|
||||
"These are checks that when achieved will break separate a single entity",
|
||||
"from a stack."),
|
||||
|
||||
NAME_FORMAT_ENTITY("Entity.Name Format", "&f{TYPE} &6{AMT}x",
|
||||
"The text displayed above an entities head where {TYPE} refers to",
|
||||
"The entities type and {AMT} is the amount currently stacked."),
|
||||
|
Loading…
Reference in New Issue
Block a user