Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. package com.bgsoftware.superiorskyblock.hooks;
  2.  
  3. import com.bgsoftware.superiorskyblock.SuperiorSkyblockPlugin;
  4. import com.bgsoftware.superiorskyblock.api.island.Island;
  5. import com.bgsoftware.superiorskyblock.api.objects.Pair;
  6. import com.bgsoftware.superiorskyblock.api.key.Key;
  7. import com.bgsoftware.superiorskyblock.utils.legacy.Materials;
  8. import de.candc.events.SpawnerBreakEvent;
  9. import de.candc.events.SpawnerPlaceEvent;
  10. import org.bukkit.Bukkit;
  11. import org.bukkit.Location;
  12. import org.bukkit.entity.EntityType;
  13. import org.bukkit.event.EventHandler;
  14. import org.bukkit.event.EventPriority;
  15. import org.bukkit.event.Listener;
  16. import org.bukkit.inventory.ItemStack;
  17.  
  18. public final class BlocksProvider_SilkSpawners implements BlocksProvider {
  19.  
  20. public BlocksProvider_SilkSpawners(){
  21. Bukkit.getPluginManager().registerEvents(new BlocksProvider_SilkSpawners.StackerListener(), SuperiorSkyblockPlugin.getPlugin());
  22. }
  23.  
  24. @Override
  25. public Pair<Integer, EntityType> getSpawner(Location location) {
  26. return new Pair<>(1, null);
  27. }
  28.  
  29. @Override
  30. public EntityType getSpawnerType(ItemStack itemStack) {
  31. String name = itemStack.getItemMeta().getLore().get(0).replaceAll("ยงe", "");
  32. return EntityType.fromName(name);
  33. }
  34.  
  35. @SuppressWarnings("unused")
  36. private static class StackerListener implements Listener {
  37.  
  38. private final SuperiorSkyblockPlugin plugin = SuperiorSkyblockPlugin.getPlugin();
  39.  
  40. @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
  41. public void onSpawnerPlace(SpawnerPlaceEvent e){
  42. Island island = plugin.getGrid().getIslandAt(e.getSpawner().getLocation());
  43. if(island != null)
  44. island.handleBlockPlace(Key.of(Materials.SPAWNER.toBukkitType() + ":" + e.getSpawnedEntity()), 1);
  45. }
  46.  
  47. @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
  48. public void onSpawnerUnstack(SpawnerBreakEvent e){
  49. Island island = plugin.getGrid().getIslandAt(e.getSpawner().getLocation());
  50. if(island != null)
  51. island.handleBlockBreak(Key.of(Materials.SPAWNER.toBukkitType() + ":" + e.getSpawnedEntity()), 1);
  52. }
  53.  
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement