9
0
mirror of https://github.com/Auxilor/EcoMobs.git synced 2025-12-21 16:09:24 +00:00

Added auto spawn system

This commit is contained in:
Auxilor
2021-04-14 12:49:32 +01:00
parent 801d9214a4
commit f50579e541
7 changed files with 71 additions and 25 deletions

View File

@@ -6,10 +6,7 @@ import com.willfp.eco.core.command.AbstractCommand;
import com.willfp.eco.core.integrations.IntegrationLoader; import com.willfp.eco.core.integrations.IntegrationLoader;
import com.willfp.ecobosses.bosses.EcoBoss; import com.willfp.ecobosses.bosses.EcoBoss;
import com.willfp.ecobosses.bosses.EcoBosses; import com.willfp.ecobosses.bosses.EcoBosses;
import com.willfp.ecobosses.bosses.listeners.AttackListeners; import com.willfp.ecobosses.bosses.listeners.*;
import com.willfp.ecobosses.bosses.listeners.DeathListeners;
import com.willfp.ecobosses.bosses.listeners.PassiveListeners;
import com.willfp.ecobosses.bosses.listeners.SpawnListeners;
import com.willfp.ecobosses.commands.CommandEbdrop; import com.willfp.ecobosses.commands.CommandEbdrop;
import com.willfp.ecobosses.commands.CommandEbkillall; import com.willfp.ecobosses.commands.CommandEbkillall;
import com.willfp.ecobosses.commands.CommandEbreload; import com.willfp.ecobosses.commands.CommandEbreload;
@@ -46,7 +43,7 @@ public class EcoBossesPlugin extends EcoPlugin {
*/ */
@Override @Override
public void enable() { public void enable() {
this.getScheduler().runTimer(new AutoSpawnTimer(), 5, 1);
} }
/** /**

View File

@@ -10,18 +10,10 @@ import com.willfp.ecobosses.bosses.effects.Effect;
import com.willfp.ecobosses.bosses.effects.Effects; import com.willfp.ecobosses.bosses.effects.Effects;
import com.willfp.ecobosses.bosses.util.bosstype.BossEntityUtils; import com.willfp.ecobosses.bosses.util.bosstype.BossEntityUtils;
import com.willfp.ecobosses.bosses.util.bosstype.BossType; import com.willfp.ecobosses.bosses.util.bosstype.BossType;
import com.willfp.ecobosses.bosses.util.obj.BossbarProperties; import com.willfp.ecobosses.bosses.util.obj.*;
import com.willfp.ecobosses.bosses.util.obj.ExperienceOptions;
import com.willfp.ecobosses.bosses.util.obj.ImmunityOptions;
import com.willfp.ecobosses.bosses.util.obj.OptionedSound;
import com.willfp.ecobosses.bosses.util.obj.SpawnTotem;
import com.willfp.ecobosses.bosses.util.obj.TargetMode;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Bukkit; import org.bukkit.*;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.boss.BarColor; import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle; import org.bukkit.boss.BarStyle;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
@@ -31,16 +23,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Base64;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class EcoBoss extends PluginDependent { public class EcoBoss extends PluginDependent {
@@ -234,6 +217,18 @@ public class EcoBoss extends PluginDependent {
@Getter @Getter
private final boolean disableBoats; private final boolean disableBoats;
/**
* The time between auto spawns.
*/
@Getter
private final int autoSpawnInterval;
/**
* Locations that the boss can auto spawn at.
*/
@Getter
private final List<Location> autoSpawnLocations;
/** /**
* Create a new Boss. * Create a new Boss.
* *
@@ -425,6 +420,18 @@ public class EcoBoss extends PluginDependent {
// Boat + Minecarts // Boat + Minecarts
this.disableBoats = this.getConfig().getBool("defence.no-boats"); this.disableBoats = this.getConfig().getBool("defence.no-boats");
// Auto Spawn
this.autoSpawnInterval = this.getConfig().getInt("auto-spawn-interval");
this.autoSpawnLocations = new ArrayList<>();
for (String string : this.getConfig().getStrings("auto-spawn-locations")) {
String[] split = string.split(":");
World world = Bukkit.getWorld(split[0]);
double x = Double.parseDouble(split[1]);
double y = Double.parseDouble(split[2]);
double z = Double.parseDouble(split[3]);
autoSpawnLocations.add(new Location(world, x, y, z));
}
if (this.getConfig().getBool("enabled")) { if (this.getConfig().getBool("enabled")) {
EcoBosses.addBoss(this); EcoBosses.addBoss(this);
} }

View File

@@ -0,0 +1,30 @@
package com.willfp.ecobosses.bosses.listeners;
import com.willfp.eco.util.NumberUtils;
import com.willfp.ecobosses.bosses.EcoBoss;
import com.willfp.ecobosses.bosses.EcoBosses;
import org.bukkit.Location;
public class AutoSpawnTimer implements Runnable {
private int tick = 0;
@Override
public void run() {
tick++;
for (EcoBoss boss : EcoBosses.values()) {
if (boss.getAutoSpawnInterval() < 0) {
continue;
}
if (boss.getAutoSpawnLocations().isEmpty()) {
continue;
}
if (tick % boss.getAutoSpawnInterval() == 0) {
Location location = boss.getAutoSpawnLocations().get(NumberUtils.randInt(0, boss.getAutoSpawnLocations().size() - 1));
boss.spawn(location);
}
}
}
}

View File

@@ -13,6 +13,9 @@ attack-damage: 50
movement-speed: 2 movement-speed: 2
follow-range: 15 follow-range: 15
auto-spawn-interval: -1 # Time between auto spawns in ticks (20 ticks in a second) - Set to -1 to disable.
auto-spawn-locations: [ ] # Formatted as world:x:y:z - for example world_nether:100:10:100
spawn-totem: spawn-totem:
enabled: true enabled: true
top: beacon top: beacon

View File

@@ -13,6 +13,9 @@ attack-damage: 30
movement-speed: 1.2 movement-speed: 1.2
follow-range: 20 follow-range: 20
auto-spawn-interval: -1 # Time between auto spawns in ticks (20 ticks in a second) - Set to -1 to disable.
auto-spawn-locations: [ ] # Formatted as world:x:y:z - for example world_nether:100:10:100
spawn-totem: spawn-totem:
enabled: true enabled: true
top: carved_pumpkin top: carved_pumpkin

View File

@@ -13,6 +13,9 @@ attack-damage: 90
movement-speed: 1.5 movement-speed: 1.5
follow-range: 16 follow-range: 16
auto-spawn-interval: -1 # Time between auto spawns in ticks (20 ticks in a second) - Set to -1 to disable.
auto-spawn-locations: [] # Formatted as world:x:y:z - for example world_nether:100:10:100
spawn-totem: spawn-totem:
enabled: true enabled: true
top: netherite_block top: netherite_block

View File

@@ -13,6 +13,9 @@ attack-damage: 70
movement-speed: 1.3 movement-speed: 1.3
follow-range: 15 follow-range: 15
auto-spawn-interval: -1 # Time between auto spawns in ticks (20 ticks in a second) - Set to -1 to disable.
auto-spawn-locations: [ ] # Formatted as world:x:y:z - for example world_nether:100:10:100
spawn-totem: spawn-totem:
enabled: true enabled: true
top: netherite_block top: netherite_block