From f2494891b105d9604105f977a97ee4b98f1c07a4 Mon Sep 17 00:00:00 2001 From: Maxlego08 Date: Thu, 22 Feb 2024 20:59:04 +0100 Subject: [PATCH] :memo: Add superiorskyblock hook --- pom.xml | 10 +++ src/fr/maxlego08/koth/hook/TeamPlugin.java | 2 + .../hook/teams/SuperiorSkyblock2Hook.java | 62 +++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 src/fr/maxlego08/koth/hook/teams/SuperiorSkyblock2Hook.java diff --git a/pom.xml b/pom.xml index b061c4c..00f2750 100644 --- a/pom.xml +++ b/pom.xml @@ -99,6 +99,10 @@ william278.net https://repo.william278.net/releases + + bg-repo + https://repo.bg-software.com/repository/api/ + @@ -199,5 +203,11 @@ ${basedir}/libs/DecentHolograms-2.8.6.jar system + + com.bgsoftware + SuperiorSkyblockAPI + 2022.9 + provided + \ No newline at end of file diff --git a/src/fr/maxlego08/koth/hook/TeamPlugin.java b/src/fr/maxlego08/koth/hook/TeamPlugin.java index 86036f7..6e096f9 100644 --- a/src/fr/maxlego08/koth/hook/TeamPlugin.java +++ b/src/fr/maxlego08/koth/hook/TeamPlugin.java @@ -4,6 +4,7 @@ import fr.maxlego08.koth.KothPlugin; import fr.maxlego08.koth.api.KothTeam; import fr.maxlego08.koth.hook.teams.HuskTownHook; import fr.maxlego08.koth.hook.teams.LandHook; +import fr.maxlego08.koth.hook.teams.SuperiorSkyblock2Hook; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; @@ -13,6 +14,7 @@ public enum TeamPlugin { LANDS("Lands", LandHook.class), HUSKTOWN("HuskTowns", HuskTownHook.class), + SUPERIORSKYBLOCK("SuperiorSkyblock2", SuperiorSkyblock2Hook.class), ; diff --git a/src/fr/maxlego08/koth/hook/teams/SuperiorSkyblock2Hook.java b/src/fr/maxlego08/koth/hook/teams/SuperiorSkyblock2Hook.java new file mode 100644 index 0000000..3062707 --- /dev/null +++ b/src/fr/maxlego08/koth/hook/teams/SuperiorSkyblock2Hook.java @@ -0,0 +1,62 @@ +package fr.maxlego08.koth.hook.teams; + +import com.bgsoftware.superiorskyblock.api.SuperiorSkyblock; +import com.bgsoftware.superiorskyblock.api.SuperiorSkyblockAPI; +import com.bgsoftware.superiorskyblock.api.events.IslandDisbandEvent; +import com.bgsoftware.superiorskyblock.api.island.Island; +import fr.maxlego08.koth.KothPlugin; +import fr.maxlego08.koth.api.KothTeam; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +public class SuperiorSkyblock2Hook implements KothTeam { + + private final KothPlugin plugin; + + public SuperiorSkyblock2Hook(KothPlugin plugin) { + this.plugin = plugin; + } + + private Island getIsland(Player player) { + return SuperiorSkyblockAPI.getPlayer(player).getIsland(); + } + + @Override + public String getFactionTag(Player player) { + Island island = getIsland(player); + return island == null ? player.getName() : getIsland(player).getName(); + } + + @Override + public List getOnlinePlayer(Player player) { + Island island = getIsland(player); + if (island == null) return Collections.singletonList(player); + + return island.getIslandMembers(true).stream().map(p -> Bukkit.getOfflinePlayer(p.getUniqueId())) + .filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).collect(Collectors.toList()); + } + + @Override + public String getLeaderName(Player player) { + Island island = getIsland(player); + return island != null ? island.getOwner().getName() : player.getName(); + } + + @Override + public String getTeamId(Player player) { + Island island = getIsland(player); + return island != null ? island.getUniqueId().toString() : player.getUniqueId().toString(); + } + + @EventHandler + public void onIslandDisband(IslandDisbandEvent event) { + this.plugin.getStorageManager().onTeamDisband(event.getIsland().getUniqueId().toString()); + } + +}