mirror of
https://github.com/BG-Software-LLC/WildLoaders.git
synced 2024-11-21 11:46:46 +01:00
Adds support to SpawnerLegacy (#111)
This commit is contained in:
parent
ebe21c0329
commit
345a88ae74
19
Hooks/SpawnerLegacy/build.gradle
Normal file
19
Hooks/SpawnerLegacy/build.gradle
Normal file
@ -0,0 +1,19 @@
|
||||
group 'Hooks:SpawnerLegacy'
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(16))
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly "mc.rellox:SpawnerLegacy:1.2.4"
|
||||
compileOnly "org.spigotmc:v1_8_R3-Taco:latest"
|
||||
compileOnly project(":API")
|
||||
compileOnly rootProject
|
||||
}
|
||||
|
||||
if (project.hasProperty('hook.compile_spawnerlegacy') &&
|
||||
!Boolean.valueOf(project.findProperty("hook.compile_spawnerlegacy").toString())) {
|
||||
project.tasks.all { task -> task.enabled = false }
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
package com.bgsoftware.wildloaders.hooks;
|
||||
|
||||
import com.bgsoftware.common.reflection.ReflectField;
|
||||
import com.bgsoftware.wildloaders.WildLoadersPlugin;
|
||||
import com.bgsoftware.wildloaders.api.hooks.SpawnersProvider;
|
||||
import mc.rellox.spawnerlegacy.SpawnerLegacy;
|
||||
import mc.rellox.spawnerlegacy.api.APIInstance;
|
||||
import mc.rellox.spawnerlegacy.api.event.EventExecutor;
|
||||
import mc.rellox.spawnerlegacy.api.event.block.SpawnerPlaceEvent;
|
||||
import mc.rellox.spawnerlegacy.api.event.upgrade.SpawnerUpgradeEvent;
|
||||
import mc.rellox.spawnerlegacy.api.region.IBox;
|
||||
import mc.rellox.spawnerlegacy.api.spawner.IGenerator;
|
||||
import mc.rellox.spawnerlegacy.spawner.generator.ActiveGenerator;
|
||||
import mc.rellox.spawnerlegacy.utility.region.SphereBox;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class SpawnersProvider_SpawnerLegacy implements SpawnersProvider {
|
||||
|
||||
private static final ReflectField<IBox> GENERATOR_BOX = new ReflectField<>(
|
||||
ActiveGenerator.class, IBox.class, "box");
|
||||
|
||||
private final WildLoadersPlugin plugin;
|
||||
private final APIInstance api;
|
||||
|
||||
public SpawnersProvider_SpawnerLegacy(WildLoadersPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.api = SpawnerLegacy.instance().getAPI();
|
||||
this.api.register(SpawnerUpgradeEvent.class, new SpawnerUpgradeListener());
|
||||
this.api.register(SpawnerPlaceEvent.class, new SpawnerPlaceListener());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSpawnerRequiredRange(Location spawnerLocation, int requiredRange) {
|
||||
updateBoxForGenerator(spawnerLocation.getBlock(), requiredRange, true);
|
||||
}
|
||||
|
||||
private void updateBoxForGenerator(Block block, int requiredRange, boolean retryOnNull) {
|
||||
IGenerator generator = this.api.getGenerator(block);
|
||||
if (generator == null) {
|
||||
if (retryOnNull)
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> updateBoxForGenerator(block, requiredRange, false), 20L);
|
||||
return;
|
||||
}
|
||||
|
||||
IBox box;
|
||||
if (requiredRange == -1) {
|
||||
box = new LoaderBox(block.getX(), block.getY(), block.getZ(), generator.cache().range());
|
||||
} else {
|
||||
box = IBox.sphere(block, generator.cache().range());
|
||||
}
|
||||
|
||||
GENERATOR_BOX.set(generator, box);
|
||||
}
|
||||
|
||||
private class SpawnerUpgradeListener implements EventExecutor<SpawnerUpgradeEvent> {
|
||||
|
||||
@Override
|
||||
public void execute(SpawnerUpgradeEvent e) {
|
||||
if (!e.cancelled())
|
||||
setLoaderBox(e.getGenerator(), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class SpawnerPlaceListener implements EventExecutor<SpawnerPlaceEvent> {
|
||||
|
||||
@Override
|
||||
public void execute(SpawnerPlaceEvent e) {
|
||||
if (e.cancelled())
|
||||
return;
|
||||
|
||||
Block block = e.block();
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> {
|
||||
IGenerator generator = api.getGenerator(block);
|
||||
if (generator != null)
|
||||
setLoaderBox(generator, false);
|
||||
}, 5L);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setLoaderBox(IGenerator generator, boolean delay) {
|
||||
Chunk chunk = generator.center().getChunk();
|
||||
|
||||
if (plugin.getLoaders().getChunkLoader(chunk).isEmpty())
|
||||
return;
|
||||
|
||||
if (delay) {
|
||||
// Chunk is loaded, we want to update the box in the next tick.
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> {
|
||||
// Ensure chunk is still loaded.
|
||||
if (plugin.getLoaders().getChunkLoader(chunk).isEmpty())
|
||||
return;
|
||||
|
||||
Block block = generator.block();
|
||||
|
||||
GENERATOR_BOX.set(generator, new LoaderBox(block.getX(), block.getY(),
|
||||
block.getZ(), generator.cache().range()));
|
||||
}, 1L);
|
||||
} else {
|
||||
Block block = generator.block();
|
||||
|
||||
GENERATOR_BOX.set(generator, new LoaderBox(block.getX(), block.getY(),
|
||||
block.getZ(), generator.cache().range()));
|
||||
}
|
||||
}
|
||||
|
||||
private static class LoaderBox extends SphereBox {
|
||||
|
||||
public LoaderBox(int x, int z, int y, int r) {
|
||||
super(x, y, z, r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean in(Player player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean any(Iterable<? extends Player> players) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -20,4 +20,5 @@ hook.compile_folia=true
|
||||
hook.compile_lands=true
|
||||
hook.compile_massivefactions=true
|
||||
hook.compile_slimeworldmanager=true
|
||||
hook.compile_spawnerlegacy=true
|
||||
hook.compile_superiorskyblock=true
|
||||
|
@ -21,6 +21,7 @@ include 'Hooks:Folia'
|
||||
include 'Hooks:Lands'
|
||||
include 'Hooks:MassiveFactions'
|
||||
include 'Hooks:SlimeWorldManager'
|
||||
include 'Hooks:SpawnerLegacy'
|
||||
include 'Hooks:SuperiorSkyblock'
|
||||
include 'NMS'
|
||||
include 'NMS:v1_7_R4'
|
||||
|
@ -38,6 +38,7 @@ public final class ProvidersHandler implements ProvidersManager {
|
||||
Scheduler.runTask(() -> {
|
||||
loadClaimsProviders();
|
||||
loadTickableProviders();
|
||||
loadSpawnersProviders();
|
||||
});
|
||||
}
|
||||
|
||||
@ -88,6 +89,13 @@ public final class ProvidersHandler implements ProvidersManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void loadSpawnersProviders() {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("SpawnerLegacy")) {
|
||||
Optional<SpawnersProvider> spawnersProvider = createInstance("SpawnersProvider_SpawnerLegacy");
|
||||
spawnersProvider.ifPresent(this::addSpawnersProvider);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadWorldProviders() {
|
||||
Optional<WorldsProvider> worldsProvider;
|
||||
|
||||
|
@ -14,6 +14,7 @@ class-depends:
|
||||
- Factions
|
||||
- FactionsX
|
||||
- Lands
|
||||
- SpawnerLegacy
|
||||
- SuperiorSkyblock2
|
||||
|
||||
commands:
|
||||
|
Loading…
Reference in New Issue
Block a user