Added support for EpicSpawners 7 (#32)

This commit is contained in:
OmerBenGera 2022-01-06 23:35:17 +02:00
parent 927a01722f
commit 699d5eb4f7
7 changed files with 91 additions and 10 deletions

View File

@ -1,4 +1,4 @@
group 'Hook_EpicSpawners'
group 'Hook_EpicSpawners6'
dependencies {
compileOnly "com.songoda:EpicSpawners-6:latest"
@ -7,7 +7,7 @@ dependencies {
compileOnly parent
}
if (project.hasProperty('hook.compile_epicspawners') &&
!Boolean.valueOf(project.findProperty("hook.compile_epicspawners").toString())) {
if (project.hasProperty('hook.compile_epicspawners6') &&
!Boolean.valueOf(project.findProperty("hook.compile_epicspawners6").toString())) {
project.tasks.all { task -> task.enabled = false }
}

View File

@ -11,7 +11,7 @@ import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public final class TickableProvider_EpicSpawners implements TickableProvider {
public final class TickableProvider_EpicSpawners6 implements TickableProvider {
private final Map<Location, TickDelay> spawnerDelays = new HashMap<>();

View File

@ -0,0 +1,13 @@
group 'Hook_EpicSpawners6'
dependencies {
compileOnly "com.songoda:EpicSpawners-7:latest"
compileOnly "org.spigotmc:v1_8_R3-Taco:latest"
compileOnly project(":API")
compileOnly parent
}
if (project.hasProperty('hook.compile_epicspawners7') &&
!Boolean.valueOf(project.findProperty("hook.compile_epicspawners7").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.songoda.epicspawners.EpicSpawners;
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_EpicSpawners7 implements TickableProvider {
private final Map<Location, TickDelay> spawnerDelays = new HashMap<>();
@Override
public void tick(Chunk[] chunks) {
if (EpicSpawners.getInstance().getSpawnerManager() == null)
return;
List<Long> chunkList = Stream.of(chunks).map(chunk -> pair(chunk.getX(), chunk.getZ())).collect(Collectors.toList());
EpicSpawners.getInstance().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,7 +11,8 @@ nms.compile_v1_15=true
nms.compile_v1_16=true
nms.compile_v1_17=true
nms.compile_v1_18=true
hook.compile_epicspawners=true
hook.compile_epicspawners6=true
hook.compile_epicspawners7=true
hook.compile_factionsuuid=true
hook.compile_factionsx=true
hook.compile_massivefactions=true

View File

@ -1,6 +1,7 @@
rootProject.name = 'WildLoaders'
include 'API'
include 'Hook_EpicSpawners'
include 'Hook_EpicSpawners6'
include 'Hook_EpicSpawners7'
include 'Hook_FactionsUUID'
include 'Hook_FactionsX'
include 'Hook_MassiveFactions'
@ -12,4 +13,5 @@ include 'v1_15_R1'
include 'v1_16_R3'
include 'v1_17_R1'
include 'v1_18_R1'
include 'Hook_EpicSpawners7'

View File

@ -7,6 +7,7 @@ import com.bgsoftware.wildloaders.api.managers.ProvidersManager;
import com.bgsoftware.wildloaders.utils.threads.Executor;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.plugin.Plugin;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
@ -36,8 +37,7 @@ public final class ProvidersHandler implements ProvidersManager {
if (Bukkit.getPluginManager().getPlugin("Factions").getDescription().getAuthors().contains("drtshock")) {
Optional<ClaimsProvider> claimsProvider = createInstance("ClaimsProvider_FactionsUUID");
claimsProvider.ifPresent(this::addClaimsProvider);
}
else {
} else {
Optional<ClaimsProvider> claimsProvider = createInstance("ClaimsProvider_MassiveFactions");
claimsProvider.ifPresent(this::addClaimsProvider);
}
@ -55,8 +55,14 @@ public final class ProvidersHandler implements ProvidersManager {
private void loadTickableProviders() {
// Loading the tickable providers
if (Bukkit.getPluginManager().isPluginEnabled("EpicSpawners")) {
Optional<TickableProvider> tickableProvider = createInstance("TickableProvider_EpicSpawners");
Plugin epicSpawners = Bukkit.getPluginManager().getPlugin("EpicSpawners");
if (epicSpawners.getDescription().getVersion().startsWith("6")) {
Optional<TickableProvider> tickableProvider = createInstance("TickableProvider_EpicSpawners6");
tickableProvider.ifPresent(this::addTickableProvider);
} else {
Optional<TickableProvider> tickableProvider = createInstance("TickableProvider_EpicSpawners7");
tickableProvider.ifPresent(this::addTickableProvider);
}
}
}