Adds support to EpicSpawners 8

This commit is contained in:
OmerBenGera 2024-02-01 17:59:54 +02:00
parent acafffd6a8
commit 6d1adf07cc
4 changed files with 80 additions and 4 deletions

View File

@ -0,0 +1,13 @@
group 'Hooks:EpicSpawners8'
dependencies {
compileOnly "com.songoda:EpicSpawners:8.1.0"
compileOnly "org.spigotmc:v1_8_R3-Taco:latest"
compileOnly project(":API")
compileOnly rootProject
}
if (project.hasProperty('hook.compile_epicspawners8') &&
!Boolean.valueOf(project.findProperty("hook.compile_epicspawners8").toString())) {
project.tasks.all { task -> task.enabled = false }
}

View File

@ -0,0 +1,59 @@
package com.bgsoftware.wildloaders.hooks;
import com.bgsoftware.wildloaders.api.hooks.TickableProvider;
import com.craftaro.epicspawners.api.EpicSpawnersApi;
import org.bukkit.Chunk;
import org.bukkit.Location;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public final class TickableProvider_EpicSpawners8 implements TickableProvider {
private final Map<Location, TickDelay> spawnerDelays = new HashMap<>();
@Override
public void tick(Chunk[] chunks) {
if (EpicSpawnersApi.getSpawnerManager() == null)
return;
List<Long> chunkList = Stream.of(chunks).map(chunk -> pair(chunk.getX(), chunk.getZ())).collect(Collectors.toList());
EpicSpawnersApi.getSpawnerManager().getSpawners().stream()
.filter(spawner -> chunkList.contains(pair(spawner.getX() >> 4, spawner.getZ() >> 4)))
.forEach(spawner -> {
Location location = spawner.getLocation();
TickDelay tickDelay = spawnerDelays.get(location);
if (tickDelay == null) {
spawnerDelays.put(location, new TickDelay(spawner.updateDelay()));
return;
}
tickDelay.delay -= 1;
if (tickDelay.delay <= 0) {
spawner.spawn();
spawnerDelays.remove(location);
}
});
}
private long pair(int x, int z) {
return (x & 0xFFFFFFFFL) | (z & 0xFFFFFFFFL) << 32;
}
private static final class TickDelay {
private int delay;
TickDelay(int delay) {
this.delay = delay;
}
}
}

View File

@ -11,6 +11,7 @@ include 'API'
include 'Hooks'
include 'Hooks:EpicSpawners6'
include 'Hooks:EpicSpawners7'
include 'Hooks:EpicSpawners8'
include 'Hooks:FactionsUUID'
include 'Hooks:FactionsX'
include 'Hooks:Lands'
@ -27,4 +28,3 @@ include 'NMS:v1_19'
include 'NMS:v1_20_1'
include 'NMS:v1_20_2'
include 'NMS:v1_20_3'

View File

@ -60,12 +60,16 @@ public final class ProvidersHandler implements ProvidersManager {
// Loading the tickable providers
if (Bukkit.getPluginManager().isPluginEnabled("EpicSpawners")) {
Plugin epicSpawners = Bukkit.getPluginManager().getPlugin("EpicSpawners");
if (epicSpawners.getDescription().getVersion().startsWith("6")) {
String version = epicSpawners.getDescription().getVersion();
if (version.startsWith("6")) {
Optional<TickableProvider> tickableProvider = createInstance("TickableProvider_EpicSpawners6");
tickableProvider.ifPresent(this::addTickableProvider);
} else {
} else if(version.startsWith("7")) {
Optional<TickableProvider> tickableProvider = createInstance("TickableProvider_EpicSpawners7");
tickableProvider.ifPresent(this::addTickableProvider);
} else {
Optional<TickableProvider> tickableProvider = createInstance("TickableProvider_EpicSpawners8");
tickableProvider.ifPresent(this::addTickableProvider);
}
}
}