Skip to content

Commit

Permalink
Added support for EpicSpawners 7 (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Jan 6, 2022
1 parent 927a017 commit 699d5eb
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
group 'Hook_EpicSpawners'
group 'Hook_EpicSpawners6'

dependencies {
compileOnly "com.songoda:EpicSpawners-6:latest"
Expand All @@ -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 }
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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<>();

Expand Down
13 changes: 13 additions & 0 deletions Hook_EpicSpawners7/build.gradle
Original file line number Diff line number Diff line change
@@ -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 }
}
Original file line number Diff line number Diff line change
@@ -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;
}

}

}
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -12,4 +13,5 @@ include 'v1_15_R1'
include 'v1_16_R3'
include 'v1_17_R1'
include 'v1_18_R1'
include 'Hook_EpicSpawners7'

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand Down Expand Up @@ -36,8 +37,7 @@ private void loadClaimsProviders() {
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);
}
Expand All @@ -55,8 +55,14 @@ private void loadClaimsProviders() {
private void loadTickableProviders() {
// Loading the tickable providers
if (Bukkit.getPluginManager().isPluginEnabled("EpicSpawners")) {
Optional<TickableProvider> tickableProvider = createInstance("TickableProvider_EpicSpawners");
tickableProvider.ifPresent(this::addTickableProvider);
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);
}
}
}

Expand Down

0 comments on commit 699d5eb

Please sign in to comment.