HookFabledSkyblock.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package xyz.spaceio.hooks;
  2. import java.util.Optional;
  3. import java.util.UUID;
  4. import com.craftaro.skyblock.SkyBlock;
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.Location;
  7. import org.bukkit.OfflinePlayer;
  8. import org.bukkit.block.Block;
  9. import com.craftaro.skyblock.island.Island;
  10. public class HookFabledSkyblock implements SkyblockAPIHook{
  11. private SkyBlock api;
  12. public HookFabledSkyblock() {
  13. api = (SkyBlock) Bukkit.getPluginManager().getPlugin("FabledSkyBlock");
  14. }
  15. @Override
  16. public int getIslandLevel(UUID uuid, String onWorld) {
  17. // create an offline player object because this plugin (unlike the others) does not have a method to obtain an island by UUID.
  18. OfflinePlayer skyblockPlayer = Bukkit.getOfflinePlayer(uuid);
  19. // api does not provide any optional, so doing a few checks here
  20. if(api.getIslandManager() != null) {
  21. if(api.getIslandManager().getIsland(skyblockPlayer) != null) {
  22. Island is = api.getIslandManager().getIsland(skyblockPlayer);
  23. if(is.getLevel() != null) {
  24. return (int) is.getLevel().getLevel();
  25. }
  26. }
  27. }
  28. return 0;
  29. }
  30. @Override
  31. public Optional<UUID> getIslandOwner(Location loc) {
  32. Optional<UUID> optional = Optional.empty();
  33. // some more classic null checks...
  34. if(api.getIslandManager() != null) {
  35. if(api.getIslandManager().getIslandAtLocation(loc) != null) {
  36. if(api.getIslandManager().getIslandAtLocation(loc).getOwnerUUID() != null) {
  37. optional = Optional.of(api.getIslandManager().getIslandAtLocation(loc).getOwnerUUID());
  38. }
  39. }
  40. }
  41. return optional;
  42. }
  43. @Override
  44. public String[] getSkyBlockWorldNames() {
  45. if(api.getWorldManager() != null) {
  46. // a method for getting the islands is missing, so using what we have
  47. return Bukkit.getWorlds().stream().filter(w -> api.getWorldManager().isIslandWorld(w)).map(w -> w.getName()).toArray(String[]::new);
  48. }
  49. return null;
  50. }
  51. @Override
  52. public void sendBlockAcknowledge(Block block) {
  53. if(block != null && api.getIslandManager().getIslandAtLocation(block.getLocation()) != null) {
  54. System.out.println(block.getType());
  55. api.getLevellingManager().updateLevel(api.getIslandManager().getIslandAtLocation(block.getLocation()), block.getLocation());
  56. }
  57. }
  58. }