Skip to content

Commit

Permalink
Added support to UltimateStacker3 (#1826)
Browse files Browse the repository at this point in the history
* Update hook for UltimateStacker

* Changed UltimateStacker3's dependency to BG-Software's mock jar

---------

Co-authored-by: OmerBenGera <omerthepro126@gmail.com>
  • Loading branch information
ceze88 and OmerBenGera committed Aug 4, 2023
1 parent 870c638 commit ef83d68
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Hooks/UltimateStacker3/build.gradle
@@ -0,0 +1,13 @@
group 'Hooks:UltimateStacker3'

dependencies {
compileOnly 'com.craftaro:UltimateStacker:3.0.0'
compileOnly "org.spigotmc:v1_8_R3-Taco:latest"
compileOnly project(":API")
compileOnly rootProject
}

if (project.hasProperty('hook.compile_ultimatestacker') &&
!Boolean.valueOf(project.findProperty("hook.compile_ultimatestacker").toString())) {
project.tasks.all { task -> task.enabled = false }
}
@@ -0,0 +1,78 @@
package com.bgsoftware.superiorskyblock.external.spawners;

import com.bgsoftware.superiorskyblock.SuperiorSkyblockPlugin;
import com.bgsoftware.superiorskyblock.api.island.Island;
import com.bgsoftware.superiorskyblock.api.key.Key;
import com.bgsoftware.superiorskyblock.api.objects.Pair;
import com.bgsoftware.superiorskyblock.core.Materials;
import com.bgsoftware.superiorskyblock.core.formatting.Formatters;
import com.bgsoftware.superiorskyblock.core.logging.Log;
import com.bgsoftware.superiorskyblock.core.messages.Message;
import com.craftaro.ultimatestacker.api.UltimateStackerApi;
import com.craftaro.ultimatestacker.api.events.spawner.SpawnerBreakEvent;
import com.craftaro.ultimatestacker.api.events.spawner.SpawnerPlaceEvent;
import com.google.common.base.Preconditions;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;

public class SpawnersProvider_UltimateStacker3 implements SpawnersProviderItemMetaSpawnerType {

private static boolean registered = false;

private final SuperiorSkyblockPlugin plugin;

public SpawnersProvider_UltimateStacker3(SuperiorSkyblockPlugin plugin) {
this.plugin = plugin;
if (!registered) {
Bukkit.getPluginManager().registerEvents(new StackerListener(), plugin);
registered = true;
Log.info("Using UltimateStacker as a spawners provider.");
}
}

@Override
public Pair<Integer, String> getSpawner(Location location) {
Preconditions.checkNotNull(location, "location parameter cannot be null.");

int blockCount = -1;
if (Bukkit.isPrimaryThread()) {
blockCount = UltimateStackerApi.getSpawnerStackManager().getSpawner(location).getAmount();
}

return new Pair<>(blockCount, null);
}

@SuppressWarnings("unused")
private class StackerListener implements Listener {

@EventHandler(priority = EventPriority.HIGHEST)
public void onSpawnerStack(SpawnerPlaceEvent e) {
Island island = plugin.getGrid().getIslandAt(e.getBlock().getLocation());

if (island == null)
return;

Key blockKey = Key.of(Materials.SPAWNER.toBukkitType() + "", e.getSpawnerType().name());
int increaseAmount = e.getAmount();

if (island.hasReachedBlockLimit(blockKey, increaseAmount)) {
e.setCancelled(true);
Message.REACHED_BLOCK_LIMIT.send(e.getPlayer(), Formatters.CAPITALIZED_FORMATTER.format(blockKey.toString()));
} else {
island.handleBlockPlace(blockKey, increaseAmount);
}
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onSpawnerUnstack(SpawnerBreakEvent e) {
Island island = plugin.getGrid().getIslandAt(e.getBlock().getLocation());
if (island != null)
island.handleBlockBreak(e.getBlock(), e.getAmount());
}

}

}
1 change: 1 addition & 0 deletions settings.gradle
Expand Up @@ -37,6 +37,7 @@ include 'Hooks:Slimefun:ProtectionModule_Dev999'
include 'Hooks:SlimeWorldManager'
include 'Hooks:SuperVanish'
include 'Hooks:UltimateStacker'
include 'Hooks:UltimateStacker3'
include 'Hooks:VanishNoPacket'
include 'Hooks:Vault'
include 'Hooks:WildStacker'
Expand Down
Expand Up @@ -452,7 +452,11 @@ private void registerSpawnersProvider() {
}
} else if (canRegisterHook("UltimateStacker") &&
(auto || configSpawnersProvider.equalsIgnoreCase("UltimateStacker"))) {
spawnersProvider = createInstance("spawners.SpawnersProvider_UltimateStacker");
if (Bukkit.getPluginManager().getPlugin("UltimateStacker").getDescription().getVersion().startsWith("3")) {
spawnersProvider = createInstance("spawners.SpawnersProvider_UltimateStacker");
} else {
spawnersProvider = createInstance("spawners.SpawnersProvider_UltimateStacker3");
}
listenToSpawnerChanges = false;
} else if (canRegisterHook("RoseStacker") &&
(auto || configSpawnersProvider.equalsIgnoreCase("RoseStacker"))) {
Expand Down

0 comments on commit ef83d68

Please sign in to comment.