mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-06-27 23:25:06 +02:00
Made it so entities spawn directly into stacks from spawners.
This commit is contained in:
parent
67431362ff
commit
1184ce24f3
|
@ -4,7 +4,7 @@ stages:
|
||||||
variables:
|
variables:
|
||||||
name: "UltimateStacker"
|
name: "UltimateStacker"
|
||||||
path: "/builds/$CI_PROJECT_PATH"
|
path: "/builds/$CI_PROJECT_PATH"
|
||||||
version: "1.6.7"
|
version: "1.6.8"
|
||||||
|
|
||||||
build:
|
build:
|
||||||
stage: build
|
stage: build
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -91,7 +91,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.bgsoftware</groupId>
|
<groupId>com.bgsoftware</groupId>
|
||||||
<artifactId>WildStacker</artifactId>
|
<artifactId>WildStacker</artifactId>
|
||||||
<version>2.8.1</version>
|
<version>2-9-0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>uk.antiperson</groupId>
|
<groupId>uk.antiperson</groupId>
|
||||||
|
|
|
@ -174,6 +174,7 @@ public class UltimateStacker extends JavaPlugin {
|
||||||
pluginManager.registerEvents(new EntityListeners(this), this);
|
pluginManager.registerEvents(new EntityListeners(this), this);
|
||||||
pluginManager.registerEvents(new ItemListeners(this), this);
|
pluginManager.registerEvents(new ItemListeners(this), this);
|
||||||
pluginManager.registerEvents(new TameListeners(this), this);
|
pluginManager.registerEvents(new TameListeners(this), this);
|
||||||
|
pluginManager.registerEvents(new SpawnerListeners(this), this);
|
||||||
pluginManager.registerEvents(new SheepDyeListeners(this), this);
|
pluginManager.registerEvents(new SheepDyeListeners(this), this);
|
||||||
|
|
||||||
if (Setting.CLEAR_LAG.getBoolean() && pluginManager.isPluginEnabled("ClearLag"))
|
if (Setting.CLEAR_LAG.getBoolean() && pluginManager.isPluginEnabled("ClearLag"))
|
||||||
|
|
|
@ -8,7 +8,6 @@ import com.songoda.ultimatestacker.utils.Methods;
|
||||||
import com.songoda.ultimatestacker.utils.ServerVersion;
|
import com.songoda.ultimatestacker.utils.ServerVersion;
|
||||||
import com.songoda.ultimatestacker.utils.settings.Setting;
|
import com.songoda.ultimatestacker.utils.settings.Setting;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.songoda.ultimatestacker.listeners;
|
||||||
|
|
||||||
|
import com.songoda.ultimatestacker.UltimateStacker;
|
||||||
|
import com.songoda.ultimatestacker.entity.EntityStack;
|
||||||
|
import com.songoda.ultimatestacker.spawner.SpawnerStack;
|
||||||
|
import com.songoda.ultimatestacker.spawner.SpawnerStackManager;
|
||||||
|
import com.songoda.ultimatestacker.utils.settings.Setting;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.SpawnerSpawnEvent;
|
||||||
|
|
||||||
|
public class SpawnerListeners implements Listener {
|
||||||
|
|
||||||
|
private final UltimateStacker instance;
|
||||||
|
|
||||||
|
public SpawnerListeners(UltimateStacker instance) {
|
||||||
|
this.instance = instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onSpawn(SpawnerSpawnEvent event) {
|
||||||
|
if (!Setting.STACK_ENTITIES.getBoolean()) return;
|
||||||
|
SpawnerStackManager spawnerStackManager = instance.getSpawnerStackManager();
|
||||||
|
if (!spawnerStackManager.isSpawner(event.getSpawner().getLocation())) return;
|
||||||
|
|
||||||
|
SpawnerStack spawnerStack = spawnerStackManager.getSpawner(event.getSpawner().getLocation());
|
||||||
|
|
||||||
|
EntityStack stack = instance.getEntityStackManager().addStack(event.getEntity().getUniqueId(), spawnerStack.calculateSpawnCount());
|
||||||
|
|
||||||
|
instance.getStackingTask().attemptSplit(stack, (LivingEntity)event.getEntity());
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,10 +3,13 @@ package com.songoda.ultimatestacker.spawner;
|
||||||
import com.songoda.ultimatestacker.UltimateStacker;
|
import com.songoda.ultimatestacker.UltimateStacker;
|
||||||
import com.songoda.ultimatestacker.utils.Reflection;
|
import com.songoda.ultimatestacker.utils.Reflection;
|
||||||
import com.songoda.ultimatestacker.utils.ServerVersion;
|
import com.songoda.ultimatestacker.utils.ServerVersion;
|
||||||
|
import com.songoda.ultimatestacker.utils.settings.Setting;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.CreatureSpawner;
|
import org.bukkit.block.CreatureSpawner;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class SpawnerStack {
|
public class SpawnerStack {
|
||||||
|
|
||||||
private final Location location;
|
private final Location location;
|
||||||
|
@ -30,7 +33,7 @@ public class SpawnerStack {
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(UltimateStacker.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(UltimateStacker.getInstance(), () -> {
|
||||||
if (!(location.getBlock().getState() instanceof CreatureSpawner)) return;
|
if (!(location.getBlock().getState() instanceof CreatureSpawner)) return;
|
||||||
int count = 4 * amount;
|
int count = Setting.STACK_ENTITIES.getBoolean() ? 1 : calculateSpawnCount();
|
||||||
int maxNearby = amount > 6 ? amount + 3 : 6;
|
int maxNearby = amount > 6 ? amount + 3 : 6;
|
||||||
CreatureSpawner creatureSpawner = (CreatureSpawner) location.getBlock().getState();
|
CreatureSpawner creatureSpawner = (CreatureSpawner) location.getBlock().getState();
|
||||||
if (UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_12)) {
|
if (UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_12)) {
|
||||||
|
@ -55,4 +58,13 @@ public class SpawnerStack {
|
||||||
+ "}"
|
+ "}"
|
||||||
+ "}";
|
+ "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int calculateSpawnCount() {
|
||||||
|
Random random = new Random();
|
||||||
|
int count = 0;
|
||||||
|
for (int i = 0; i < getAmount(); i ++) {
|
||||||
|
count += random.nextInt(3 - 1 + 1) + 1;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,6 +182,19 @@ public class StackingTask extends BukkitRunnable {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void attemptSplit(EntityStack stack, LivingEntity entity) {
|
||||||
|
int stackSize = stack.getAmount();
|
||||||
|
int maxEntityStackAmount = Setting.MAX_STACK_ENTITIES.getInt();
|
||||||
|
|
||||||
|
if (stackSize <= maxEntityStackAmount) return;
|
||||||
|
|
||||||
|
for (int i = stackSize; i > 0; i -= maxEntityStackAmount) {
|
||||||
|
instance.getEntityStackManager().addStack(Methods.newEntity(entity), i > 25 ? 25 : i);
|
||||||
|
}
|
||||||
|
entity.remove();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void fixHealth(LivingEntity entity, LivingEntity initialEntity) {
|
private void fixHealth(LivingEntity entity, LivingEntity initialEntity) {
|
||||||
if (!Setting.STACK_ENTITY_HEALTH.getBoolean() && Setting.CARRY_OVER_LOWEST_HEALTH.getBoolean() && initialEntity.getHealth() < entity.getHealth())
|
if (!Setting.STACK_ENTITY_HEALTH.getBoolean() && Setting.CARRY_OVER_LOWEST_HEALTH.getBoolean() && initialEntity.getHealth() < entity.getHealth())
|
||||||
entity.setHealth(initialEntity.getHealth());
|
entity.setHealth(initialEntity.getHealth());
|
||||||
|
@ -191,5 +204,4 @@ public class StackingTask extends BukkitRunnable {
|
||||||
if (Setting.STACK_ENTITY_HEALTH.getBoolean())
|
if (Setting.STACK_ENTITY_HEALTH.getBoolean())
|
||||||
stack.updateHealth(stack.getEntity());
|
stack.updateHealth(stack.getEntity());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user