-
-
Notifications
You must be signed in to change notification settings - Fork 131
/
SpawnersProvider_SilkSpawners.java
64 lines (52 loc) · 2.42 KB
/
SpawnersProvider_SilkSpawners.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.bgsoftware.superiorskyblock.external.spawners;
import com.bgsoftware.superiorskyblock.SuperiorSkyblockPlugin;
import com.bgsoftware.superiorskyblock.api.island.Island;
import com.bgsoftware.superiorskyblock.api.objects.Pair;
import com.bgsoftware.superiorskyblock.core.key.Keys;
import com.bgsoftware.superiorskyblock.core.logging.Log;
import com.google.common.base.Preconditions;
import de.candc.events.SpawnerBreakEvent;
import de.candc.events.SpawnerPlaceEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
public class SpawnersProvider_SilkSpawners implements SpawnersProvider_AutoDetect {
private static boolean registered = false;
private final SuperiorSkyblockPlugin plugin;
public SpawnersProvider_SilkSpawners(SuperiorSkyblockPlugin plugin) {
this.plugin = plugin;
if (!registered) {
Bukkit.getPluginManager().registerEvents(new SpawnersProvider_SilkSpawners.StackerListener(), plugin);
registered = true;
Log.info("Using SilkSpawners as a spawners provider.");
}
}
@Override
public Pair<Integer, String> getSpawner(Location location) {
Preconditions.checkNotNull(location, "location parameter cannot be null.");
return new Pair<>(1, null);
}
@Override
public String getSpawnerType(ItemStack itemStack) {
Preconditions.checkNotNull(itemStack, "itemStack parameter cannot be null.");
return itemStack.getItemMeta().getLore().get(0).replaceAll("§e", "");
}
@SuppressWarnings("unused")
private class StackerListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onSpawnerPlace(SpawnerPlaceEvent e) {
Island island = plugin.getGrid().getIslandAt(e.getSpawner().getLocation());
if (island != null)
island.handleBlockPlace(Keys.ofSpawner(e.getSpawnedEntity()), 1);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onSpawnerUnstack(SpawnerBreakEvent e) {
Island island = plugin.getGrid().getIslandAt(e.getSpawner().getLocation());
if (island != null)
island.handleBlockBreak(Keys.ofSpawner(e.getSpawnedEntity()), 1);
}
}
}