📝 Add SimpleClan

This commit is contained in:
Maxlego08 2024-02-24 15:31:30 +01:00
parent 2317209ca3
commit a4e1111209
5 changed files with 83 additions and 1 deletions

10
pom.xml
View File

@ -112,6 +112,10 @@
<id>bg-repo</id>
<url>https://repo.bg-software.com/repository/api/</url>
</repository>
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.org/repository/maven-public</url>
</repository>
</repositories>
<dependencies>
<dependency>
@ -225,5 +229,11 @@
<systemPath>${basedir}/libs/SaberFactions.jar</systemPath>
<scope>system</scope>
</dependency>
<dependency>
<groupId>net.sacredlabyrinth.phaed.simpleclans</groupId>
<artifactId>SimpleClans</artifactId>
<version>2.15.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -20,6 +20,7 @@ import fr.maxlego08.koth.zcore.utils.storage.Persist;
import fr.maxlego08.koth.zcore.utils.storage.Savable;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
@ -55,10 +56,12 @@ public class KothManager extends ZUtils implements Savable {
for (TeamPlugin value : TeamPlugin.values()) {
if (value.isEnable()) {
kothTeam = value.init(plugin);
this.kothTeam = value.init(plugin);
Logger.info("Register " + value.getPluginName() + " team implementation.", Logger.LogType.INFO);
}
}
Bukkit.getPluginManager().registerEvents(this.kothTeam, plugin);
}
@Override

View File

@ -6,6 +6,7 @@ import fr.maxlego08.koth.hook.teams.BetterTeamHook;
import fr.maxlego08.koth.hook.teams.HuskTownHook;
import fr.maxlego08.koth.hook.teams.LandHook;
import fr.maxlego08.koth.hook.teams.SaberFactionHook;
import fr.maxlego08.koth.hook.teams.SimpleClanHook;
import fr.maxlego08.koth.hook.teams.SuperiorSkyblock2Hook;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
@ -19,6 +20,7 @@ public enum TeamPlugin {
SUPERIORSKYBLOCK("SuperiorSkyblock2", SuperiorSkyblock2Hook.class),
BETTERTEAMS("BetterTeams", BetterTeamHook.class),
FACTIONS("Factions", SaberFactionHook.class),
SIMPLECLANS("SimpleClans", SimpleClanHook.class),
;

View File

@ -0,0 +1,66 @@
package fr.maxlego08.koth.hook.teams;
import fr.maxlego08.koth.KothPlugin;
import fr.maxlego08.koth.api.KothTeam;
import net.sacredlabyrinth.phaed.simpleclans.Clan;
import net.sacredlabyrinth.phaed.simpleclans.ClanPlayer;
import net.sacredlabyrinth.phaed.simpleclans.SimpleClans;
import net.sacredlabyrinth.phaed.simpleclans.events.DisbandClanEvent;
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.Optional;
import java.util.stream.Collectors;
public class SimpleClanHook implements KothTeam {
private final KothPlugin plugin;
private final SimpleClans clan;
public SimpleClanHook(KothPlugin plugin) {
this.plugin = plugin;
this.clan = (SimpleClans) Bukkit.getServer().getPluginManager().getPlugin("SimpleClans");
}
private Optional<Clan> getClan(Player 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) {
Optional<Clan> optional = getClan(player);
return optional.isPresent() ? optional.get().getName() : player.getName();
}
@Override
public List<Player> getOnlinePlayer(Player player) {
Optional<Clan> 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));
}
@Override
public String getLeaderName(Player player) {
Optional<Clan> optional = getClan(player);
if (!optional.isPresent()) return player.getName();
Clan clan = optional.get();
return clan.getMembers().stream().filter(e -> clan.isLeader(e.getUniqueId())).findFirst().map(ClanPlayer::getName).orElseGet(player::getName);
}
@Override
public String getTeamId(Player player) {
Optional<Clan> optional = getClan(player);
return optional.isPresent() ? optional.get().getName() : player.getUniqueId().toString();
}
@EventHandler
public void onClan(DisbandClanEvent event) {
this.plugin.getStorageManager().onTeamDisband(event.getClan().getName());
}
}

View File

@ -59,6 +59,7 @@
# - BetterTeams
# - SaberFaction
# - FactionUUID
# - SimpleClan
#
# Need scheduler ? Use zScheduler: https://www.spigotmc.org/resources/zschedulers.112705/
#