📝 Change Player to OfflinePlayer

This commit is contained in:
Maxlego08 2024-02-29 18:14:32 +01:00
parent bcb9d609ac
commit 8790dc4216
8 changed files with 62 additions and 49 deletions

View File

@ -1,5 +1,6 @@
package fr.maxlego08.koth.api; package fr.maxlego08.koth.api;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Listener; 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. * @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. * @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. * 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. * @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. * @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<Player> getOnlinePlayer(Player player); List<Player> getOnlinePlayer(OfflinePlayer player);
/** /**
* Retrieves the name of the leader of the team to which a given player belongs. * 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. * @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. * @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. * 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. * @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. * @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);
} }

View File

@ -5,6 +5,7 @@ import com.booksaw.betterTeams.Team;
import com.booksaw.betterTeams.customEvents.DisbandTeamEvent; import com.booksaw.betterTeams.customEvents.DisbandTeamEvent;
import fr.maxlego08.koth.KothPlugin; import fr.maxlego08.koth.KothPlugin;
import fr.maxlego08.koth.api.KothTeam; import fr.maxlego08.koth.api.KothTeam;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -20,25 +21,25 @@ public class BetterTeamHook implements KothTeam {
} }
@Override @Override
public String getTeamName(Player player) { public String getTeamName(OfflinePlayer player) {
Team team = Team.getTeam(player); Team team = Team.getTeam(player);
return team == null ? player.getName() : team.getName(); return team == null ? player.getName() : team.getName();
} }
@Override @Override
public List<Player> getOnlinePlayer(Player player) { public List<Player> getOnlinePlayer(OfflinePlayer player) {
Team team = Team.getTeam(player); Team team = Team.getTeam(player);
return team == null ? Collections.singletonList(player) : team.getOnlineMembers(); return team == null ? Collections.singletonList(player.getPlayer()) : team.getOnlineMembers();
} }
@Override @Override
public String getLeaderName(Player player) { public String getLeaderName(OfflinePlayer player) {
Team team = Team.getTeam(player); Team team = Team.getTeam(player);
return team == null ? player.getName() : team.getMembers().getRank(PlayerRank.OWNER).get(0).getPlayer().getName(); return team == null ? player.getName() : team.getMembers().getRank(PlayerRank.OWNER).get(0).getPlayer().getName();
} }
@Override @Override
public String getTeamId(Player player) { public String getTeamId(OfflinePlayer player) {
Team team = Team.getTeam(player); Team team = Team.getTeam(player);
return team == null ? player.getUniqueId().toString() : team.getID().toString(); return team == null ? player.getUniqueId().toString() : team.getID().toString();
} }

View File

@ -12,50 +12,57 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class HuskTownHook implements KothTeam { public class HuskTownHook implements KothTeam {
private final KothPlugin plugin; private final KothPlugin plugin;
private final Map<UUID, Town> towns = new HashMap<>();
public HuskTownHook(KothPlugin plugin) { public HuskTownHook(KothPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
private Optional<Town> getTown(Player player) { private Optional<Town> getTown(OfflinePlayer player) {
Optional<Member> optional = HuskTownsAPI.getInstance().getUserTown(player); if (this.towns.containsKey(player.getUniqueId())) return Optional.of(this.towns.get(player.getUniqueId()));
Optional<Member> optional = HuskTownsAPI.getInstance().getUserTown(player.getPlayer());
if (optional.isPresent()) { if (optional.isPresent()) {
Member member = optional.get(); Member member = optional.get();
this.towns.put(player.getUniqueId(), member.town());
return Optional.of(member.town()); return Optional.of(member.town());
} }
return Optional.empty(); return Optional.empty();
} }
@Override @Override
public String getTeamName(Player player) { public String getTeamName(OfflinePlayer player) {
Optional<Town> optional = getTown(player); Optional<Town> optional = getTown(player);
if (optional.isPresent()) return optional.get().getName(); if (optional.isPresent()) return optional.get().getName();
return player.getName(); return player.getName();
} }
@Override @Override
public List<Player> getOnlinePlayer(Player player) { public List<Player> getOnlinePlayer(OfflinePlayer player) {
Optional<Town> optional = getTown(player); Optional<Town> optional = getTown(player);
return optional.map(town -> town.getMembers().keySet().stream().map(Bukkit::getOfflinePlayer) 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 @Override
public String getLeaderName(Player player) { public String getLeaderName(OfflinePlayer player) {
Optional<Town> optional = getTown(player); Optional<Town> optional = getTown(player);
if (optional.isPresent()) return Bukkit.getOfflinePlayer(optional.get().getMayor()).getName(); if (optional.isPresent()) return Bukkit.getOfflinePlayer(optional.get().getMayor()).getName();
return player.getName(); return player.getName();
} }
@Override @Override
public String getTeamId(Player player) { public String getTeamId(OfflinePlayer player) {
Optional<Town> optional = getTown(player); Optional<Town> optional = getTown(player);
return optional.map(town -> String.valueOf(town.getId())).orElseGet(player::getName); return optional.map(town -> String.valueOf(town.getId())).orElseGet(player::getName);
} }

View File

@ -6,6 +6,7 @@ import me.angeschossen.lands.api.LandsIntegration;
import me.angeschossen.lands.api.events.LandDeleteEvent; import me.angeschossen.lands.api.events.LandDeleteEvent;
import me.angeschossen.lands.api.land.Land; import me.angeschossen.lands.api.land.Land;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -24,36 +25,36 @@ public class LandHook implements KothTeam {
} }
@Override @Override
public String getTeamName(Player player) { public String getTeamName(OfflinePlayer player) {
Optional<? extends Land> optional = getLandByPlayer(player); Optional<? extends Land> optional = getLandByPlayer(player);
return optional.map(Land::getName).orElseGet(player::getName); return optional.map(Land::getName).orElseGet(player::getName);
} }
@Override @Override
public List<Player> getOnlinePlayer(Player player) { public List<Player> getOnlinePlayer(OfflinePlayer player) {
Optional<? extends Land> optional = getLandByPlayer(player); Optional<? extends Land> optional = getLandByPlayer(player);
if (optional.isPresent()) { if (optional.isPresent()) {
return new ArrayList<>(optional.get().getOnlinePlayers()); return new ArrayList<>(optional.get().getOnlinePlayers());
} }
return Collections.singletonList(player); return Collections.singletonList(player.getPlayer());
} }
private Optional<? extends Land> getLandByPlayer(Player player) { private Optional<? extends Land> getLandByPlayer(OfflinePlayer player) {
LandsIntegration api = LandsIntegration.of(this.plugin); LandsIntegration api = LandsIntegration.of(this.plugin);
return api.getLandPlayer(player.getUniqueId()).getLands().stream().findFirst(); return api.getLandPlayer(player.getUniqueId()).getLands().stream().findFirst();
} }
@Override @Override
public String getLeaderName(Player player) { public String getLeaderName(OfflinePlayer player) {
Optional<? extends Land> optional = getLandByPlayer(player); Optional<? extends Land> optional = getLandByPlayer(player);
if (optional.isPresent()) return Bukkit.getOfflinePlayer(optional.get().getOwnerUID()).getName(); if (optional.isPresent()) return Bukkit.getOfflinePlayer(optional.get().getOwnerUID()).getName();
return player.getName(); return player.getName();
} }
@Override @Override
public String getTeamId(Player player) { public String getTeamId(OfflinePlayer player) {
Optional<? extends Land> optional = getLandByPlayer(player); Optional<? extends Land> optional = getLandByPlayer(player);
return optional.map(land -> String.valueOf(land.getId())).orElseGet(() -> player.getUniqueId().toString()); return optional.map(land -> String.valueOf(land.getId())).orElseGet(() -> player.getUniqueId().toString());
} }

View File

@ -1,6 +1,7 @@
package fr.maxlego08.koth.hook.teams; package fr.maxlego08.koth.hook.teams;
import fr.maxlego08.koth.api.KothTeam; import fr.maxlego08.koth.api.KothTeam;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Collections; import java.util.Collections;
@ -10,22 +11,22 @@ public class NoneHook implements KothTeam {
@Override @Override
public String getTeamName(Player player) { public String getTeamName(OfflinePlayer player) {
return player.getName(); return player.getName();
} }
@Override @Override
public List<Player> getOnlinePlayer(Player player) { public List<Player> getOnlinePlayer(OfflinePlayer player) {
return Collections.singletonList(player); return Collections.singletonList(player.getPlayer());
} }
@Override @Override
public String getLeaderName(Player player) { public String getLeaderName(OfflinePlayer player) {
return player.getName(); return player.getName();
} }
@Override @Override
public String getTeamId(Player player) { public String getTeamId(OfflinePlayer player) {
return player.getUniqueId().toString(); return player.getUniqueId().toString();
} }
} }

View File

@ -1,9 +1,11 @@
package fr.maxlego08.koth.hook.teams; package fr.maxlego08.koth.hook.teams;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.event.FactionDisbandEvent; import com.massivecraft.factions.event.FactionDisbandEvent;
import fr.maxlego08.koth.KothPlugin; import fr.maxlego08.koth.KothPlugin;
import fr.maxlego08.koth.api.KothTeam; import fr.maxlego08.koth.api.KothTeam;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -18,23 +20,24 @@ public class SaberFactionHook implements KothTeam {
} }
@Override @Override
public String getTeamName(Player player) { public String getTeamName(OfflinePlayer player) {
return FPlayers.getInstance().getByPlayer(player).getFaction().getTag(); return FPlayers.getInstance().getByOfflinePlayer(player).getFaction().getTag();
} }
@Override @Override
public List<Player> getOnlinePlayer(Player player) { public List<Player> getOnlinePlayer(OfflinePlayer player) {
return FPlayers.getInstance().getByPlayer(player).getFaction().getOnlinePlayers(); return FPlayers.getInstance().getByOfflinePlayer(player).getFaction().getOnlinePlayers();
} }
@Override @Override
public String getLeaderName(Player player) { public String getLeaderName(OfflinePlayer player) {
return FPlayers.getInstance().getByPlayer(player).getFaction().getFPlayerAdmin().getName(); FPlayer fPlayer = FPlayers.getInstance().getByOfflinePlayer(player).getFaction().getFPlayerAdmin();
return fPlayer == null ? player.getName() : fPlayer.getName();
} }
@Override @Override
public String getTeamId(Player player) { public String getTeamId(OfflinePlayer player) {
return FPlayers.getInstance().getByPlayer(player).getFactionId(); return FPlayers.getInstance().getByOfflinePlayer(player).getFactionId();
} }
@EventHandler @EventHandler

View File

@ -26,27 +26,27 @@ public class SimpleClanHook implements KothTeam {
this.clan = (SimpleClans) Bukkit.getServer().getPluginManager().getPlugin("SimpleClans"); this.clan = (SimpleClans) Bukkit.getServer().getPluginManager().getPlugin("SimpleClans");
} }
private Optional<Clan> getClan(Player player) { private Optional<Clan> getClan(OfflinePlayer player) {
ClanPlayer clanPlayer = this.clan.getClanManager().getClanPlayer(player); ClanPlayer clanPlayer = this.clan.getClanManager().getClanPlayer(player);
if (clanPlayer == null) return Optional.empty(); if (clanPlayer == null) return Optional.empty();
return Optional.ofNullable(clanPlayer.getClan()); return Optional.ofNullable(clanPlayer.getClan());
} }
@Override @Override
public String getTeamName(Player player) { public String getTeamName(OfflinePlayer player) {
Optional<Clan> optional = getClan(player); Optional<Clan> optional = getClan(player);
return optional.isPresent() ? optional.get().getName() : player.getName(); return optional.isPresent() ? optional.get().getName() : player.getName();
} }
@Override @Override
public List<Player> getOnlinePlayer(Player player) { public List<Player> getOnlinePlayer(OfflinePlayer player) {
Optional<Clan> optional = getClan(player); Optional<Clan> optional = getClan(player);
return optional.map(value -> value.getOnlineMembers().stream().map(e -> Bukkit.getOfflinePlayer(e.getUniqueId())) 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 @Override
public String getLeaderName(Player player) { public String getLeaderName(OfflinePlayer player) {
Optional<Clan> optional = getClan(player); Optional<Clan> optional = getClan(player);
if (!optional.isPresent()) return player.getName(); if (!optional.isPresent()) return player.getName();
Clan clan = optional.get(); Clan clan = optional.get();
@ -54,7 +54,7 @@ public class SimpleClanHook implements KothTeam {
} }
@Override @Override
public String getTeamId(Player player) { public String getTeamId(OfflinePlayer player) {
Optional<Clan> optional = getClan(player); Optional<Clan> optional = getClan(player);
return optional.isPresent() ? optional.get().getName() : player.getUniqueId().toString(); return optional.isPresent() ? optional.get().getName() : player.getUniqueId().toString();
} }

View File

@ -1,6 +1,5 @@
package fr.maxlego08.koth.hook.teams; package fr.maxlego08.koth.hook.teams;
import com.bgsoftware.superiorskyblock.api.SuperiorSkyblock;
import com.bgsoftware.superiorskyblock.api.SuperiorSkyblockAPI; import com.bgsoftware.superiorskyblock.api.SuperiorSkyblockAPI;
import com.bgsoftware.superiorskyblock.api.events.IslandDisbandEvent; import com.bgsoftware.superiorskyblock.api.events.IslandDisbandEvent;
import com.bgsoftware.superiorskyblock.api.island.Island; import com.bgsoftware.superiorskyblock.api.island.Island;
@ -23,33 +22,33 @@ public class SuperiorSkyblock2Hook implements KothTeam {
this.plugin = plugin; this.plugin = plugin;
} }
private Island getIsland(Player player) { private Island getIsland(OfflinePlayer player) {
return SuperiorSkyblockAPI.getPlayer(player).getIsland(); return SuperiorSkyblockAPI.getPlayer(player.getUniqueId()).getIsland();
} }
@Override @Override
public String getTeamName(Player player) { public String getTeamName(OfflinePlayer player) {
Island island = getIsland(player); Island island = getIsland(player);
return island == null ? player.getName() : getIsland(player).getName(); return island == null ? player.getName() : getIsland(player).getName();
} }
@Override @Override
public List<Player> getOnlinePlayer(Player player) { public List<Player> getOnlinePlayer(OfflinePlayer player) {
Island island = getIsland(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())) return island.getIslandMembers(true).stream().map(p -> Bukkit.getOfflinePlayer(p.getUniqueId()))
.filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).collect(Collectors.toList()); .filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).collect(Collectors.toList());
} }
@Override @Override
public String getLeaderName(Player player) { public String getLeaderName(OfflinePlayer player) {
Island island = getIsland(player); Island island = getIsland(player);
return island != null ? island.getOwner().getName() : player.getName(); return island != null ? island.getOwner().getName() : player.getName();
} }
@Override @Override
public String getTeamId(Player player) { public String getTeamId(OfflinePlayer player) {
Island island = getIsland(player); Island island = getIsland(player);
return island != null ? island.getUniqueId().toString() : player.getUniqueId().toString(); return island != null ? island.getUniqueId().toString() : player.getUniqueId().toString();
} }