mirror of
https://github.com/BG-Software-LLC/WildLoaders.git
synced 2025-01-05 18:59:02 +01:00
Added support for EpicSpawners
This commit is contained in:
parent
0765174e5a
commit
075672121f
@ -0,0 +1,13 @@
|
||||
package com.bgsoftware.wildloaders.api.hooks;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
|
||||
public interface TickableProvider {
|
||||
|
||||
/**
|
||||
* Simulate a tick on a list of provided chunks.
|
||||
* @param chunks The chunks to tick.
|
||||
*/
|
||||
void tick(Chunk[] chunks);
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.bgsoftware.wildloaders.api.managers;
|
||||
|
||||
import com.bgsoftware.wildloaders.api.hooks.ClaimsProvider;
|
||||
import com.bgsoftware.wildloaders.api.hooks.TickableProvider;
|
||||
|
||||
public interface ProvidersManager {
|
||||
|
||||
@ -10,4 +11,10 @@ public interface ProvidersManager {
|
||||
*/
|
||||
void addClaimsProvider(ClaimsProvider claimsProvider);
|
||||
|
||||
/**
|
||||
* Add a tickable provider to the plugin.
|
||||
* @param tickableProvider The tickable provider to add.
|
||||
*/
|
||||
void addTickableProvider(TickableProvider tickableProvider);
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
package com.bgsoftware.wildloaders.handlers;
|
||||
|
||||
import com.bgsoftware.wildloaders.api.hooks.ClaimsProvider;
|
||||
import com.bgsoftware.wildloaders.api.hooks.TickableProvider;
|
||||
import com.bgsoftware.wildloaders.api.managers.ProvidersManager;
|
||||
import com.bgsoftware.wildloaders.hooks.ClaimsProvider_FactionsUUID;
|
||||
import com.bgsoftware.wildloaders.hooks.ClaimsProvider_FactionsX;
|
||||
import com.bgsoftware.wildloaders.hooks.ClaimsProvider_MassiveFactions;
|
||||
import com.bgsoftware.wildloaders.hooks.ClaimsProvider_SuperiorSkyblock;
|
||||
import com.bgsoftware.wildloaders.hooks.TickableProvider_EpicSpawners;
|
||||
import com.bgsoftware.wildloaders.utils.threads.Executor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
@ -17,20 +19,27 @@ import java.util.UUID;
|
||||
public final class ProvidersHandler implements ProvidersManager {
|
||||
|
||||
private final List<ClaimsProvider> claimsProviders = new ArrayList<>();
|
||||
private final List<TickableProvider> tickableProviders = new ArrayList<>();
|
||||
|
||||
public ProvidersHandler(){
|
||||
Executor.sync(() -> {
|
||||
// Loading the claim providers
|
||||
if(Bukkit.getPluginManager().isPluginEnabled("Factions")){
|
||||
if(Bukkit.getPluginManager().getPlugin("Factions").getDescription().getAuthors().contains("drtshock"))
|
||||
claimsProviders.add(new ClaimsProvider_FactionsUUID());
|
||||
addClaimsProvider(new ClaimsProvider_FactionsUUID());
|
||||
else
|
||||
claimsProviders.add(new ClaimsProvider_MassiveFactions());
|
||||
addClaimsProvider(new ClaimsProvider_MassiveFactions());
|
||||
}
|
||||
if(Bukkit.getPluginManager().isPluginEnabled("FactionsX")){
|
||||
claimsProviders.add(new ClaimsProvider_FactionsX());
|
||||
addClaimsProvider(new ClaimsProvider_FactionsX());
|
||||
}
|
||||
if(Bukkit.getPluginManager().isPluginEnabled("SuperiorSkyblock2")){
|
||||
claimsProviders.add(new ClaimsProvider_SuperiorSkyblock());
|
||||
addClaimsProvider(new ClaimsProvider_SuperiorSkyblock());
|
||||
}
|
||||
|
||||
// Loading the tickable providers
|
||||
if(Bukkit.getPluginManager().isPluginEnabled("EpicSpawners")){
|
||||
addTickableProvider(new TickableProvider_EpicSpawners());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -40,6 +49,11 @@ public final class ProvidersHandler implements ProvidersManager {
|
||||
claimsProviders.add(claimsProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTickableProvider(TickableProvider tickableProvider) {
|
||||
tickableProviders.add(tickableProvider);
|
||||
}
|
||||
|
||||
public boolean hasChunkAccess(UUID player, Chunk chunk){
|
||||
for(ClaimsProvider claimsProvider : claimsProviders) {
|
||||
if (claimsProvider.hasClaimAccess(player, chunk))
|
||||
@ -49,4 +63,8 @@ public final class ProvidersHandler implements ProvidersManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void tick(Chunk[] chunks){
|
||||
tickableProviders.forEach(tickableProvider -> tickableProvider.tick(chunks));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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_EpicSpawners 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 & 4294967295L) | (z & 4294967295L) << 32;
|
||||
}
|
||||
|
||||
private static final class TickDelay{
|
||||
|
||||
private int delay;
|
||||
|
||||
TickDelay(int delay){
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -64,6 +64,8 @@ public final class WChunkLoader implements ChunkLoader {
|
||||
}
|
||||
|
||||
public void tick(){
|
||||
plugin.getProviders().tick(loadedChunks);
|
||||
|
||||
if(!isInfinite()) {
|
||||
timeLeft--;
|
||||
if (timeLeft < 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user