From 8790dc42167fa102b96ccee544b50566e3faf1c5 Mon Sep 17 00:00:00 2001 From: Maxlego08 Date: Thu, 29 Feb 2024 18:14:32 +0100 Subject: [PATCH] :memo: Change Player to OfflinePlayer --- src/fr/maxlego08/koth/api/KothTeam.java | 9 ++++---- .../koth/hook/teams/BetterTeamHook.java | 11 +++++----- .../koth/hook/teams/HuskTownHook.java | 21 ++++++++++++------- .../maxlego08/koth/hook/teams/LandHook.java | 13 ++++++------ .../maxlego08/koth/hook/teams/NoneHook.java | 11 +++++----- .../koth/hook/teams/SaberFactionHook.java | 19 ++++++++++------- .../koth/hook/teams/SimpleClanHook.java | 12 +++++------ .../hook/teams/SuperiorSkyblock2Hook.java | 15 +++++++------ 8 files changed, 62 insertions(+), 49 deletions(-) diff --git a/src/fr/maxlego08/koth/api/KothTeam.java b/src/fr/maxlego08/koth/api/KothTeam.java index 1f6b691..3c986d6 100644 --- a/src/fr/maxlego08/koth/api/KothTeam.java +++ b/src/fr/maxlego08/koth/api/KothTeam.java @@ -1,5 +1,6 @@ package fr.maxlego08.koth.api; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import org.bukkit.event.Listener; @@ -24,7 +25,7 @@ public interface KothTeam extends Listener { * @param player The player for whom the team name is to be retrieved. This parameter cannot be null. * @return A {@code String} representing the name of the team. Returns {@code null} if the player is not part of any team. */ - String getTeamName(Player player); + String getTeamName(OfflinePlayer player); /** * Retrieves a list of players who are currently online and belong to the same team as the given player. @@ -32,7 +33,7 @@ public interface KothTeam extends Listener { * @param player The player used as a reference for the team query. This parameter cannot be null. * @return A list of {@code Player} objects representing the online team members. Returns an empty list if no online players are found in the team. */ - List getOnlinePlayer(Player player); + List getOnlinePlayer(OfflinePlayer player); /** * Retrieves the name of the leader of the team to which a given player belongs. @@ -40,7 +41,7 @@ public interface KothTeam extends Listener { * @param player The player for whom the team leader's name is to be retrieved. This parameter cannot be null. * @return A {@code String} representing the name of the team leader. Returns {@code null} if the player is not part of any team or the team does not have a designated leader. */ - String getLeaderName(Player player); + String getLeaderName(OfflinePlayer player); /** * Retrieves the unique identifier (ID) of the team to which a given player belongs. @@ -48,5 +49,5 @@ public interface KothTeam extends Listener { * @param player The player for whom the team ID is to be retrieved. This parameter cannot be null. * @return A {@code String} representing the unique ID of the team. Returns {@code null} if the player is not part of any team. */ - String getTeamId(Player player); + String getTeamId(OfflinePlayer player); } diff --git a/src/fr/maxlego08/koth/hook/teams/BetterTeamHook.java b/src/fr/maxlego08/koth/hook/teams/BetterTeamHook.java index 60936ca..46e39f2 100644 --- a/src/fr/maxlego08/koth/hook/teams/BetterTeamHook.java +++ b/src/fr/maxlego08/koth/hook/teams/BetterTeamHook.java @@ -5,6 +5,7 @@ import com.booksaw.betterTeams.Team; import com.booksaw.betterTeams.customEvents.DisbandTeamEvent; import fr.maxlego08.koth.KothPlugin; import fr.maxlego08.koth.api.KothTeam; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -20,25 +21,25 @@ public class BetterTeamHook implements KothTeam { } @Override - public String getTeamName(Player player) { + public String getTeamName(OfflinePlayer player) { Team team = Team.getTeam(player); return team == null ? player.getName() : team.getName(); } @Override - public List getOnlinePlayer(Player player) { + public List getOnlinePlayer(OfflinePlayer player) { Team team = Team.getTeam(player); - return team == null ? Collections.singletonList(player) : team.getOnlineMembers(); + return team == null ? Collections.singletonList(player.getPlayer()) : team.getOnlineMembers(); } @Override - public String getLeaderName(Player player) { + public String getLeaderName(OfflinePlayer player) { Team team = Team.getTeam(player); return team == null ? player.getName() : team.getMembers().getRank(PlayerRank.OWNER).get(0).getPlayer().getName(); } @Override - public String getTeamId(Player player) { + public String getTeamId(OfflinePlayer player) { Team team = Team.getTeam(player); return team == null ? player.getUniqueId().toString() : team.getID().toString(); } diff --git a/src/fr/maxlego08/koth/hook/teams/HuskTownHook.java b/src/fr/maxlego08/koth/hook/teams/HuskTownHook.java index b2b41a4..47fcbf8 100644 --- a/src/fr/maxlego08/koth/hook/teams/HuskTownHook.java +++ b/src/fr/maxlego08/koth/hook/teams/HuskTownHook.java @@ -12,50 +12,57 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Optional; +import java.util.UUID; import java.util.stream.Collectors; public class HuskTownHook implements KothTeam { private final KothPlugin plugin; + private final Map towns = new HashMap<>(); public HuskTownHook(KothPlugin plugin) { this.plugin = plugin; } - private Optional getTown(Player player) { - Optional optional = HuskTownsAPI.getInstance().getUserTown(player); + private Optional getTown(OfflinePlayer player) { + if (this.towns.containsKey(player.getUniqueId())) return Optional.of(this.towns.get(player.getUniqueId())); + + Optional optional = HuskTownsAPI.getInstance().getUserTown(player.getPlayer()); if (optional.isPresent()) { Member member = optional.get(); + this.towns.put(player.getUniqueId(), member.town()); return Optional.of(member.town()); } return Optional.empty(); } @Override - public String getTeamName(Player player) { + public String getTeamName(OfflinePlayer player) { Optional optional = getTown(player); if (optional.isPresent()) return optional.get().getName(); return player.getName(); } @Override - public List getOnlinePlayer(Player player) { + public List getOnlinePlayer(OfflinePlayer player) { Optional optional = getTown(player); return optional.map(town -> town.getMembers().keySet().stream().map(Bukkit::getOfflinePlayer) - .filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).collect(Collectors.toList())).orElseGet(() -> Collections.singletonList(player)); + .filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).collect(Collectors.toList())).orElseGet(() -> Collections.singletonList(player.getPlayer())); } @Override - public String getLeaderName(Player player) { + public String getLeaderName(OfflinePlayer player) { Optional optional = getTown(player); if (optional.isPresent()) return Bukkit.getOfflinePlayer(optional.get().getMayor()).getName(); return player.getName(); } @Override - public String getTeamId(Player player) { + public String getTeamId(OfflinePlayer player) { Optional optional = getTown(player); return optional.map(town -> String.valueOf(town.getId())).orElseGet(player::getName); } diff --git a/src/fr/maxlego08/koth/hook/teams/LandHook.java b/src/fr/maxlego08/koth/hook/teams/LandHook.java index cdd68d6..fab2277 100644 --- a/src/fr/maxlego08/koth/hook/teams/LandHook.java +++ b/src/fr/maxlego08/koth/hook/teams/LandHook.java @@ -6,6 +6,7 @@ import me.angeschossen.lands.api.LandsIntegration; import me.angeschossen.lands.api.events.LandDeleteEvent; import me.angeschossen.lands.api.land.Land; import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -24,36 +25,36 @@ public class LandHook implements KothTeam { } @Override - public String getTeamName(Player player) { + public String getTeamName(OfflinePlayer player) { Optional optional = getLandByPlayer(player); return optional.map(Land::getName).orElseGet(player::getName); } @Override - public List getOnlinePlayer(Player player) { + public List getOnlinePlayer(OfflinePlayer player) { Optional optional = getLandByPlayer(player); if (optional.isPresent()) { return new ArrayList<>(optional.get().getOnlinePlayers()); } - return Collections.singletonList(player); + return Collections.singletonList(player.getPlayer()); } - private Optional getLandByPlayer(Player player) { + private Optional getLandByPlayer(OfflinePlayer player) { LandsIntegration api = LandsIntegration.of(this.plugin); return api.getLandPlayer(player.getUniqueId()).getLands().stream().findFirst(); } @Override - public String getLeaderName(Player player) { + public String getLeaderName(OfflinePlayer player) { Optional optional = getLandByPlayer(player); if (optional.isPresent()) return Bukkit.getOfflinePlayer(optional.get().getOwnerUID()).getName(); return player.getName(); } @Override - public String getTeamId(Player player) { + public String getTeamId(OfflinePlayer player) { Optional optional = getLandByPlayer(player); return optional.map(land -> String.valueOf(land.getId())).orElseGet(() -> player.getUniqueId().toString()); } diff --git a/src/fr/maxlego08/koth/hook/teams/NoneHook.java b/src/fr/maxlego08/koth/hook/teams/NoneHook.java index 98bf552..365855c 100644 --- a/src/fr/maxlego08/koth/hook/teams/NoneHook.java +++ b/src/fr/maxlego08/koth/hook/teams/NoneHook.java @@ -1,6 +1,7 @@ package fr.maxlego08.koth.hook.teams; import fr.maxlego08.koth.api.KothTeam; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import java.util.Collections; @@ -10,22 +11,22 @@ public class NoneHook implements KothTeam { @Override - public String getTeamName(Player player) { + public String getTeamName(OfflinePlayer player) { return player.getName(); } @Override - public List getOnlinePlayer(Player player) { - return Collections.singletonList(player); + public List getOnlinePlayer(OfflinePlayer player) { + return Collections.singletonList(player.getPlayer()); } @Override - public String getLeaderName(Player player) { + public String getLeaderName(OfflinePlayer player) { return player.getName(); } @Override - public String getTeamId(Player player) { + public String getTeamId(OfflinePlayer player) { return player.getUniqueId().toString(); } } diff --git a/src/fr/maxlego08/koth/hook/teams/SaberFactionHook.java b/src/fr/maxlego08/koth/hook/teams/SaberFactionHook.java index 7abaeae..e9fd0da 100644 --- a/src/fr/maxlego08/koth/hook/teams/SaberFactionHook.java +++ b/src/fr/maxlego08/koth/hook/teams/SaberFactionHook.java @@ -1,9 +1,11 @@ package fr.maxlego08.koth.hook.teams; +import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.event.FactionDisbandEvent; import fr.maxlego08.koth.KothPlugin; import fr.maxlego08.koth.api.KothTeam; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -18,23 +20,24 @@ public class SaberFactionHook implements KothTeam { } @Override - public String getTeamName(Player player) { - return FPlayers.getInstance().getByPlayer(player).getFaction().getTag(); + public String getTeamName(OfflinePlayer player) { + return FPlayers.getInstance().getByOfflinePlayer(player).getFaction().getTag(); } @Override - public List getOnlinePlayer(Player player) { - return FPlayers.getInstance().getByPlayer(player).getFaction().getOnlinePlayers(); + public List getOnlinePlayer(OfflinePlayer player) { + return FPlayers.getInstance().getByOfflinePlayer(player).getFaction().getOnlinePlayers(); } @Override - public String getLeaderName(Player player) { - return FPlayers.getInstance().getByPlayer(player).getFaction().getFPlayerAdmin().getName(); + public String getLeaderName(OfflinePlayer player) { + FPlayer fPlayer = FPlayers.getInstance().getByOfflinePlayer(player).getFaction().getFPlayerAdmin(); + return fPlayer == null ? player.getName() : fPlayer.getName(); } @Override - public String getTeamId(Player player) { - return FPlayers.getInstance().getByPlayer(player).getFactionId(); + public String getTeamId(OfflinePlayer player) { + return FPlayers.getInstance().getByOfflinePlayer(player).getFactionId(); } @EventHandler diff --git a/src/fr/maxlego08/koth/hook/teams/SimpleClanHook.java b/src/fr/maxlego08/koth/hook/teams/SimpleClanHook.java index 3a02c84..f466c27 100644 --- a/src/fr/maxlego08/koth/hook/teams/SimpleClanHook.java +++ b/src/fr/maxlego08/koth/hook/teams/SimpleClanHook.java @@ -26,27 +26,27 @@ public class SimpleClanHook implements KothTeam { this.clan = (SimpleClans) Bukkit.getServer().getPluginManager().getPlugin("SimpleClans"); } - private Optional getClan(Player player) { + private Optional getClan(OfflinePlayer player) { ClanPlayer clanPlayer = this.clan.getClanManager().getClanPlayer(player); if (clanPlayer == null) return Optional.empty(); return Optional.ofNullable(clanPlayer.getClan()); } @Override - public String getTeamName(Player player) { + public String getTeamName(OfflinePlayer player) { Optional optional = getClan(player); return optional.isPresent() ? optional.get().getName() : player.getName(); } @Override - public List getOnlinePlayer(Player player) { + public List getOnlinePlayer(OfflinePlayer player) { Optional optional = getClan(player); return optional.map(value -> value.getOnlineMembers().stream().map(e -> Bukkit.getOfflinePlayer(e.getUniqueId())) - .filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).collect(Collectors.toList())).orElseGet(() -> Collections.singletonList(player)); + .filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).collect(Collectors.toList())).orElseGet(() -> Collections.singletonList(player.getPlayer())); } @Override - public String getLeaderName(Player player) { + public String getLeaderName(OfflinePlayer player) { Optional optional = getClan(player); if (!optional.isPresent()) return player.getName(); Clan clan = optional.get(); @@ -54,7 +54,7 @@ public class SimpleClanHook implements KothTeam { } @Override - public String getTeamId(Player player) { + public String getTeamId(OfflinePlayer player) { Optional optional = getClan(player); return optional.isPresent() ? optional.get().getName() : player.getUniqueId().toString(); } diff --git a/src/fr/maxlego08/koth/hook/teams/SuperiorSkyblock2Hook.java b/src/fr/maxlego08/koth/hook/teams/SuperiorSkyblock2Hook.java index 20999c6..da23a22 100644 --- a/src/fr/maxlego08/koth/hook/teams/SuperiorSkyblock2Hook.java +++ b/src/fr/maxlego08/koth/hook/teams/SuperiorSkyblock2Hook.java @@ -1,6 +1,5 @@ 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; @@ -23,33 +22,33 @@ public class SuperiorSkyblock2Hook implements KothTeam { this.plugin = plugin; } - private Island getIsland(Player player) { - return SuperiorSkyblockAPI.getPlayer(player).getIsland(); + private Island getIsland(OfflinePlayer player) { + return SuperiorSkyblockAPI.getPlayer(player.getUniqueId()).getIsland(); } @Override - public String getTeamName(Player player) { + public String getTeamName(OfflinePlayer player) { Island island = getIsland(player); return island == null ? player.getName() : getIsland(player).getName(); } @Override - public List getOnlinePlayer(Player player) { + public List getOnlinePlayer(OfflinePlayer player) { Island island = getIsland(player); - if (island == null) return Collections.singletonList(player); + if (island == null) return Collections.singletonList(player.getPlayer()); 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) { + public String getLeaderName(OfflinePlayer player) { Island island = getIsland(player); return island != null ? island.getOwner().getName() : player.getName(); } @Override - public String getTeamId(Player player) { + public String getTeamId(OfflinePlayer player) { Island island = getIsland(player); return island != null ? island.getUniqueId().toString() : player.getUniqueId().toString(); }