Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support to UltimateStacker3 (#1826)
* Update hook for UltimateStacker * Changed UltimateStacker3's dependency to BG-Software's mock jar --------- Co-authored-by: OmerBenGera <omerthepro126@gmail.com>
- Loading branch information
1 parent
870c638
commit ef83d68
Showing
4 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } | ||
} |
78 changes: 78 additions & 0 deletions
78
.../com/bgsoftware/superiorskyblock/external/spawners/SpawnersProvider_UltimateStacker3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters