mirror of
https://github.com/songoda/UltimateStacker.git
synced 2025-03-12 22:49:02 +01:00
Named entity will no longer stack.
When using a nametag on an entity the entity a new entity will break apart from the stack with the custom name rather than just naming the whole stack. Two stacks will now stack together. When epicspawners is installed spawner stacking will automatically disable.
This commit is contained in:
parent
dea3a461af
commit
9276bf397a
8
.gitignore
vendored
8
.gitignore
vendored
@ -144,3 +144,11 @@ target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles\.ls
|
|||||||
\.idea/vcs\.xml
|
\.idea/vcs\.xml
|
||||||
|
|
||||||
UltimateStacker\.iml
|
UltimateStacker\.iml
|
||||||
|
|
||||||
|
\.idea/libraries/Maven__org_spigotmc_spigot_1_12_2\.xml
|
||||||
|
|
||||||
|
target/classes/com/songoda/ultimatestacker/events/InteractListeners\.class
|
||||||
|
|
||||||
|
target/classes/com/songoda/ultimatestacker/utils/Reflection\.class
|
||||||
|
|
||||||
|
target/classes/com/songoda/ultimatestacker/utils/ServerVersion\.class
|
||||||
|
@ -170,7 +170,6 @@ public class UltimateStacker extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (SpawnerStack stack : spawnerStackManager.getStacks()) {
|
for (SpawnerStack stack : spawnerStackManager.getStacks()) {
|
||||||
storage.prepareSaveItem("spawners", new StorageItem("location", Serialize.getInstance().serializeLocation(stack.getLocation())),
|
storage.prepareSaveItem("spawners", new StorageItem("location", Serialize.getInstance().serializeLocation(stack.getLocation())),
|
||||||
new StorageItem("amount", stack.getAmount()));
|
new StorageItem("amount", stack.getAmount()));
|
||||||
@ -185,7 +184,7 @@ public class UltimateStacker extends JavaPlugin {
|
|||||||
Bukkit.getPluginManager().registerEvents(new BlockListeners(this), this);
|
Bukkit.getPluginManager().registerEvents(new BlockListeners(this), this);
|
||||||
Bukkit.getPluginManager().registerEvents(new DeathListeners(this), this);
|
Bukkit.getPluginManager().registerEvents(new DeathListeners(this), this);
|
||||||
Bukkit.getPluginManager().registerEvents(new ShearListeners(this), this);
|
Bukkit.getPluginManager().registerEvents(new ShearListeners(this), this);
|
||||||
Bukkit.getPluginManager().registerEvents(new DropListeners(this), this);
|
Bukkit.getPluginManager().registerEvents(new InteractListeners(this), this);
|
||||||
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::saveToFile, 6000, 6000);
|
Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::saveToFile, 6000, 6000);
|
||||||
@ -272,6 +271,11 @@ public class UltimateStacker extends JavaPlugin {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean spawnersEnabled() {
|
||||||
|
if (this.getServer().getPluginManager().isPluginEnabled("EpicSpawners")) return false;
|
||||||
|
return this.getConfig().getBoolean("Main.Stack Spawners");
|
||||||
|
}
|
||||||
|
|
||||||
public ServerVersion getServerVersion() {
|
public ServerVersion getServerVersion() {
|
||||||
return serverVersion;
|
return serverVersion;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.songoda.ultimatestacker.entity;
|
package com.songoda.ultimatestacker.entity;
|
||||||
|
|
||||||
|
import com.songoda.ultimatestacker.UltimateStacker;
|
||||||
import com.songoda.ultimatestacker.utils.Methods;
|
import com.songoda.ultimatestacker.utils.Methods;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
|
||||||
@ -36,6 +37,12 @@ public class EntityStack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setAmount(int amount) {
|
public void setAmount(int amount) {
|
||||||
|
if (amount == 1) {
|
||||||
|
UltimateStacker.getInstance().getEntityStackManager().removeStack(entity);
|
||||||
|
entity.setCustomName(null);
|
||||||
|
entity.setCustomNameVisible(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
updateStack();
|
updateStack();
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ public class BlockListeners implements Listener {
|
|||||||
|
|
||||||
if (block == null || item == null || block.getType() != Material.MOB_SPAWNER || item.getType() != Material.MOB_SPAWNER || event.getAction() == Action.LEFT_CLICK_BLOCK) return;
|
if (block == null || item == null || block.getType() != Material.MOB_SPAWNER || item.getType() != Material.MOB_SPAWNER || event.getAction() == Action.LEFT_CLICK_BLOCK) return;
|
||||||
|
|
||||||
if (!instance.getConfig().getBoolean("Main.Stack Spawners")) return;
|
if (!instance.spawnersEnabled()) return;
|
||||||
|
|
||||||
BlockStateMeta bsm = (BlockStateMeta) item.getItemMeta();
|
BlockStateMeta bsm = (BlockStateMeta) item.getItemMeta();
|
||||||
CreatureSpawner cs = (CreatureSpawner) bsm.getBlockState();
|
CreatureSpawner cs = (CreatureSpawner) bsm.getBlockState();
|
||||||
@ -87,7 +87,7 @@ public class BlockListeners implements Listener {
|
|||||||
|
|
||||||
if (block == null || block.getType() != Material.MOB_SPAWNER) return;
|
if (block == null || block.getType() != Material.MOB_SPAWNER) return;
|
||||||
|
|
||||||
if (!instance.getConfig().getBoolean("Main.Stack Spawners")) return;
|
if (!instance.spawnersEnabled()) return;
|
||||||
|
|
||||||
SpawnerStack stack = instance.getSpawnerStackManager().addSpawner(new SpawnerStack(block.getLocation(), getSpawnerAmount(event.getItemInHand())));
|
SpawnerStack stack = instance.getSpawnerStackManager().addSpawner(new SpawnerStack(block.getLocation(), getSpawnerAmount(event.getItemInHand())));
|
||||||
instance.getHologramHandler().updateHologram(stack);
|
instance.getHologramHandler().updateHologram(stack);
|
||||||
@ -100,7 +100,7 @@ public class BlockListeners implements Listener {
|
|||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
if (block.getType() != Material.MOB_SPAWNER) return;
|
if (block.getType() != Material.MOB_SPAWNER) return;
|
||||||
|
|
||||||
if (!instance.getConfig().getBoolean("Main.Stack Spawners")) return;
|
if (!instance.spawnersEnabled()) return;
|
||||||
|
|
||||||
CreatureSpawner cs = (CreatureSpawner) block.getState();
|
CreatureSpawner cs = (CreatureSpawner) block.getState();
|
||||||
|
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
package com.songoda.ultimatestacker.events;
|
|
||||||
|
|
||||||
import com.songoda.ultimatestacker.UltimateStacker;
|
|
||||||
import org.bukkit.entity.Item;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
|
||||||
|
|
||||||
public class DropListeners implements Listener {
|
|
||||||
|
|
||||||
private final UltimateStacker instance;
|
|
||||||
|
|
||||||
public DropListeners(UltimateStacker instance) {
|
|
||||||
this.instance = instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onDrop(PlayerDropItemEvent event) {
|
|
||||||
Item dropped = event.getItemDrop();
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,67 @@
|
|||||||
|
package com.songoda.ultimatestacker.events;
|
||||||
|
|
||||||
|
import com.songoda.ultimatestacker.UltimateStacker;
|
||||||
|
import com.songoda.ultimatestacker.entity.EntityStack;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.*;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
|
public class InteractListeners implements Listener {
|
||||||
|
|
||||||
|
private final UltimateStacker instance;
|
||||||
|
|
||||||
|
public InteractListeners(UltimateStacker instance) {
|
||||||
|
this.instance = instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInteract(PlayerInteractAtEntityEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
Entity entity = event.getRightClicked();
|
||||||
|
|
||||||
|
ItemStack item = player.getInventory().getItemInMainHand();
|
||||||
|
|
||||||
|
if (item.getType() != Material.NAME_TAG
|
||||||
|
|| !instance.getEntityStackManager().isStacked(entity)) return;
|
||||||
|
|
||||||
|
EntityStack stack = instance.getEntityStackManager().getStack(entity);
|
||||||
|
|
||||||
|
if (stack.getAmount() == 1) return;
|
||||||
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> stack.setAmount(stack.getAmount() - 1), 1L);
|
||||||
|
|
||||||
|
Entity newEntity = entity.getWorld().spawnEntity(entity.getLocation(), entity.getType());
|
||||||
|
newEntity.setVelocity(getRandomVector());
|
||||||
|
|
||||||
|
if (entity instanceof Ageable) {
|
||||||
|
if (((Ageable) entity).isAdult()) {
|
||||||
|
((Ageable) newEntity).setAdult();
|
||||||
|
} else {
|
||||||
|
((Ageable) entity).setBaby();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity instanceof Sheep) {
|
||||||
|
Sheep sheep = ((Sheep) newEntity);
|
||||||
|
sheep.setSheared(sheep.isSheared());
|
||||||
|
sheep.setColor(sheep.getColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity instanceof Villager) {
|
||||||
|
Villager villager = ((Villager) newEntity);
|
||||||
|
villager.setProfession(villager.getProfession());
|
||||||
|
}
|
||||||
|
newEntity.setCustomName(item.getItemMeta().getDisplayName());
|
||||||
|
}
|
||||||
|
private Vector getRandomVector() {
|
||||||
|
return new Vector(ThreadLocalRandom.current().nextDouble(-1, 1.01), 0, ThreadLocalRandom.current().nextDouble(-1, 1.01)).normalize().multiply(0.5);
|
||||||
|
}
|
||||||
|
}
|
@ -8,15 +8,13 @@ import com.songoda.ultimatestacker.utils.Methods;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.ArmorStand;
|
import org.bukkit.entity.*;
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.Item;
|
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class StackingTask extends BukkitRunnable {
|
public class StackingTask extends BukkitRunnable {
|
||||||
@ -57,6 +55,8 @@ public class StackingTask extends BukkitRunnable {
|
|||||||
|
|
||||||
nextEntity:
|
nextEntity:
|
||||||
for (Entity entityO : world.getEntities()) {
|
for (Entity entityO : world.getEntities()) {
|
||||||
|
if (entityO instanceof Player) continue;
|
||||||
|
|
||||||
if (entityO instanceof Item && instance.getConfig().getBoolean("Main.Stack Items")) {
|
if (entityO instanceof Item && instance.getConfig().getBoolean("Main.Stack Items")) {
|
||||||
ItemStack item = ((Item) entityO).getItemStack();
|
ItemStack item = ((Item) entityO).getItemStack();
|
||||||
|
|
||||||
@ -85,8 +85,11 @@ public class StackingTask extends BukkitRunnable {
|
|||||||
|
|
||||||
if (initalEntity.isDead()
|
if (initalEntity.isDead()
|
||||||
|| !initalEntity.isValid()
|
|| !initalEntity.isValid()
|
||||||
|| initalEntity instanceof ArmorStand
|
|| initalEntity instanceof ArmorStand) continue;
|
||||||
|| stackManager.isStacked(initalEntity)) continue;
|
|
||||||
|
EntityStack initialStack = stackManager.getStack(initalEntity);
|
||||||
|
if (initialStack == null && initalEntity.getCustomName() != null) continue;
|
||||||
|
int amtToStack = initialStack != null ? initialStack.getAmount() : 1;
|
||||||
|
|
||||||
ConfigurationSection configurationSection = UltimateStacker.getInstance().getMobFile().getConfig();
|
ConfigurationSection configurationSection = UltimateStacker.getInstance().getMobFile().getConfig();
|
||||||
|
|
||||||
@ -98,19 +101,24 @@ public class StackingTask extends BukkitRunnable {
|
|||||||
|
|
||||||
List<Entity> entityList = Methods.getSimilarEntitesAroundEntity(initalEntity);
|
List<Entity> entityList = Methods.getSimilarEntitesAroundEntity(initalEntity);
|
||||||
|
|
||||||
for (Entity entity : entityList) {
|
for (Entity entity : new ArrayList<>(entityList)) {
|
||||||
|
|
||||||
EntityStack stack = stackManager.getStack(entity);
|
EntityStack stack = stackManager.getStack(entity);
|
||||||
|
if (stack == null && entity.getCustomName() != null) {
|
||||||
|
entityList.remove(entity);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
//If a stack was found add 1 to this stack.
|
//If a stack was found add 1 to this stack.
|
||||||
if (stack != null && stack.getAmount() < maxEntityStackSize) {
|
if (stack != null && (stack.getAmount() + amtToStack) <= maxEntityStackSize) {
|
||||||
stack.addAmount(1);
|
stack.addAmount(amtToStack);
|
||||||
stack.updateStack();
|
stack.updateStack();
|
||||||
initalEntity.remove();
|
initalEntity.remove();
|
||||||
continue nextEntity;
|
continue nextEntity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (initialStack != null) continue;
|
||||||
|
|
||||||
entityList.removeIf(stackManager::isStacked);
|
entityList.removeIf(stackManager::isStacked);
|
||||||
|
|
||||||
if (entityList.size() < instance.getConfig().getInt("Entity.Min Stack Amount") - 1) continue;
|
if (entityList.size() < instance.getConfig().getInt("Entity.Min Stack Amount") - 1) continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user