mirror of
https://github.com/Maxlego08/zKoth.git
synced 2024-11-04 09:09:45 +01:00
🚧 Add team hook
This commit is contained in:
parent
b60d6bf52d
commit
1fd765fa0e
@ -1,10 +1,14 @@
|
||||
package fr.maxlego08.koth;
|
||||
|
||||
import fr.maxlego08.koth.api.Koth;
|
||||
import fr.maxlego08.koth.api.KothTeam;
|
||||
import fr.maxlego08.koth.api.KothType;
|
||||
import fr.maxlego08.koth.api.events.KothCreateEvent;
|
||||
import fr.maxlego08.koth.hook.TeamPlugin;
|
||||
import fr.maxlego08.koth.hook.teams.NoneHook;
|
||||
import fr.maxlego08.koth.loader.KothLoader;
|
||||
import fr.maxlego08.koth.zcore.enums.Message;
|
||||
import fr.maxlego08.koth.zcore.logger.Logger;
|
||||
import fr.maxlego08.koth.zcore.utils.ZUtils;
|
||||
import fr.maxlego08.koth.zcore.utils.builder.ItemBuilder;
|
||||
import fr.maxlego08.koth.zcore.utils.loader.Loader;
|
||||
@ -32,11 +36,19 @@ public class KothManager extends ZUtils implements Savable {
|
||||
private final Map<UUID, Selection> selections = new HashMap<>();
|
||||
private final KothPlugin plugin;
|
||||
private final File folder;
|
||||
private KothTeam kothTeam = new NoneHook();
|
||||
|
||||
public KothManager(KothPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.folder = new File(plugin.getDataFolder(), "koths");
|
||||
if (!this.folder.exists()) this.folder.mkdir();
|
||||
|
||||
for (TeamPlugin value : TeamPlugin.values()) {
|
||||
if (value.isEnable()) {
|
||||
kothTeam = value.init(plugin);
|
||||
Logger.info("Register " + value.getPluginName() + " team implementation.", Logger.LogType.INFO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -128,4 +140,8 @@ public class KothManager extends ZUtils implements Savable {
|
||||
private Optional<Koth> getKoth(String name) {
|
||||
return this.koths.stream().filter(koth -> name != null && koth.getName().equalsIgnoreCase(name)).findFirst();
|
||||
}
|
||||
|
||||
public KothTeam getKothTeam() {
|
||||
return kothTeam;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import fr.maxlego08.koth.hook.ScoreboardPlugin;
|
||||
import fr.maxlego08.koth.hook.scoreboard.DefaultHook;
|
||||
import fr.maxlego08.koth.placeholder.LocalPlaceholder;
|
||||
import fr.maxlego08.koth.save.MessageLoader;
|
||||
import fr.maxlego08.koth.storage.StorageManager;
|
||||
import fr.maxlego08.koth.zcore.ZPlugin;
|
||||
import fr.maxlego08.koth.zcore.logger.Logger;
|
||||
|
||||
@ -18,6 +19,7 @@ import fr.maxlego08.koth.zcore.logger.Logger;
|
||||
public class KothPlugin extends ZPlugin {
|
||||
|
||||
private KothManager kothManager;
|
||||
private StorageManager storageManager;
|
||||
private KothScoreboard kothScoreboard = new DefaultHook();
|
||||
|
||||
@Override
|
||||
@ -28,6 +30,7 @@ public class KothPlugin extends ZPlugin {
|
||||
|
||||
this.preEnable();
|
||||
|
||||
this.storageManager = new StorageManager(this);
|
||||
this.kothManager = new KothManager(this);
|
||||
|
||||
this.registerCommand("zkoth", new CommandKoth(this), "koth");
|
||||
@ -69,4 +72,8 @@ public class KothPlugin extends ZPlugin {
|
||||
public KothScoreboard getKothScoreboard() {
|
||||
return this.kothScoreboard;
|
||||
}
|
||||
|
||||
public StorageManager getStorageManager() {
|
||||
return this.storageManager;
|
||||
}
|
||||
}
|
||||
|
18
src/fr/maxlego08/koth/api/KothTeam.java
Normal file
18
src/fr/maxlego08/koth/api/KothTeam.java
Normal file
@ -0,0 +1,18 @@
|
||||
package fr.maxlego08.koth.api;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface KothTeam extends Listener {
|
||||
|
||||
String getFactionTag(Player player);
|
||||
|
||||
List<Player> getOnlinePlayer(Player player);
|
||||
|
||||
String getLeaderName(Player player);
|
||||
|
||||
String getTeamId(Player player);
|
||||
|
||||
}
|
@ -23,8 +23,6 @@ public enum ScoreboardPlugin {
|
||||
private final String pluginName;
|
||||
private final Class<? extends KothScoreboard> scoreboardClass;
|
||||
|
||||
private static KothScoreboard kothScoreboard;
|
||||
|
||||
ScoreboardPlugin(String pluginName, Class<? extends KothScoreboard> scoreboardClass) {
|
||||
this.pluginName = pluginName;
|
||||
this.scoreboardClass = scoreboardClass;
|
||||
|
45
src/fr/maxlego08/koth/hook/TeamPlugin.java
Normal file
45
src/fr/maxlego08/koth/hook/TeamPlugin.java
Normal file
@ -0,0 +1,45 @@
|
||||
package fr.maxlego08.koth.hook;
|
||||
|
||||
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 org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public enum TeamPlugin {
|
||||
|
||||
LANDS("Lands", LandHook.class),
|
||||
HUSKTOWN("HuskTowns", HuskTownHook.class),
|
||||
|
||||
;
|
||||
|
||||
private final String pluginName;
|
||||
private final Class<? extends KothTeam> teamHook;
|
||||
|
||||
TeamPlugin(String pluginName, Class<? extends KothTeam> teamHook) {
|
||||
this.pluginName = pluginName;
|
||||
this.teamHook = teamHook;
|
||||
}
|
||||
|
||||
public String getPluginName() {
|
||||
return pluginName;
|
||||
}
|
||||
|
||||
public boolean isEnable() {
|
||||
Plugin plugin = Bukkit.getPluginManager().getPlugin(this.pluginName);
|
||||
return plugin != null && plugin.isEnabled();
|
||||
}
|
||||
|
||||
public KothTeam init(KothPlugin plugin) {
|
||||
try {
|
||||
return teamHook.getConstructor(KothPlugin.class).newInstance(plugin);
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException |
|
||||
NoSuchMethodException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
68
src/fr/maxlego08/koth/hook/teams/HuskTownHook.java
Normal file
68
src/fr/maxlego08/koth/hook/teams/HuskTownHook.java
Normal file
@ -0,0 +1,68 @@
|
||||
package fr.maxlego08.koth.hook.teams;
|
||||
|
||||
import fr.maxlego08.koth.KothPlugin;
|
||||
import fr.maxlego08.koth.api.KothTeam;
|
||||
import me.angeschossen.lands.api.events.LandDeleteEvent;
|
||||
import net.william278.husktowns.api.HuskTownsAPI;
|
||||
import net.william278.husktowns.town.Member;
|
||||
import net.william278.husktowns.town.Town;
|
||||
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 HuskTownHook implements KothTeam {
|
||||
|
||||
private final KothPlugin plugin;
|
||||
|
||||
public HuskTownHook(KothPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
private Optional<Town> getTown(Player player) {
|
||||
Optional<Member> optional = HuskTownsAPI.getInstance().getUserTown(player);
|
||||
if (optional.isPresent()) {
|
||||
Member member = optional.get();
|
||||
return Optional.of(member.town());
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFactionTag(Player player) {
|
||||
Optional<Town> optional = getTown(player);
|
||||
if (optional.isPresent()) return optional.get().getName();
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Player> getOnlinePlayer(Player player) {
|
||||
Optional<Town> 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));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLeaderName(Player player) {
|
||||
Optional<Town> optional = getTown(player);
|
||||
if (optional.isPresent()) return Bukkit.getOfflinePlayer(optional.get().getMayor()).getName();
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTeamId(Player player) {
|
||||
Optional<Town> optional = getTown(player);
|
||||
return optional.map(town -> String.valueOf(town.getId())).orElseGet(player::getName);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDelete(LandDeleteEvent event) {
|
||||
this.plugin.getStorageManager().onTeamDisband(String.valueOf(event.getLand().getId()));
|
||||
}
|
||||
|
||||
}
|
66
src/fr/maxlego08/koth/hook/teams/LandHook.java
Normal file
66
src/fr/maxlego08/koth/hook/teams/LandHook.java
Normal file
@ -0,0 +1,66 @@
|
||||
package fr.maxlego08.koth.hook.teams;
|
||||
|
||||
import fr.maxlego08.koth.KothPlugin;
|
||||
import fr.maxlego08.koth.api.KothTeam;
|
||||
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.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class LandHook implements KothTeam {
|
||||
|
||||
private final KothPlugin plugin;
|
||||
|
||||
public LandHook(KothPlugin plugin) {
|
||||
super();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFactionTag(Player player) {
|
||||
Optional<? extends Land> optional = getLandByPlayer(player);
|
||||
return optional.map(Land::getName).orElseGet(player::getName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Player> getOnlinePlayer(Player player) {
|
||||
|
||||
Optional<? extends Land> optional = getLandByPlayer(player);
|
||||
if (optional.isPresent()) {
|
||||
return new ArrayList<>(optional.get().getOnlinePlayers());
|
||||
}
|
||||
|
||||
return Collections.singletonList(player);
|
||||
}
|
||||
|
||||
private Optional<? extends Land> getLandByPlayer(Player player) {
|
||||
LandsIntegration api = LandsIntegration.of(this.plugin);
|
||||
return api.getLandPlayer(player.getUniqueId()).getLands().stream().findFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLeaderName(Player player) {
|
||||
Optional<? extends Land> optional = getLandByPlayer(player);
|
||||
if (optional.isPresent()) return Bukkit.getOfflinePlayer(optional.get().getOwnerUID()).getName();
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTeamId(Player player) {
|
||||
Optional<? extends Land> optional = getLandByPlayer(player);
|
||||
return optional.map(land -> String.valueOf(land.getId())).orElseGet(() -> player.getUniqueId().toString());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDisband(LandDeleteEvent event) {
|
||||
this.plugin.getStorageManager().onTeamDisband(String.valueOf(event.getLand().getId()));
|
||||
}
|
||||
|
||||
}
|
31
src/fr/maxlego08/koth/hook/teams/NoneHook.java
Normal file
31
src/fr/maxlego08/koth/hook/teams/NoneHook.java
Normal file
@ -0,0 +1,31 @@
|
||||
package fr.maxlego08.koth.hook.teams;
|
||||
|
||||
import fr.maxlego08.koth.api.KothTeam;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class NoneHook implements KothTeam {
|
||||
|
||||
|
||||
@Override
|
||||
public String getFactionTag(Player player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Player> getOnlinePlayer(Player player) {
|
||||
return Collections.singletonList(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLeaderName(Player player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTeamId(Player player) {
|
||||
return player.getUniqueId().toString();
|
||||
}
|
||||
}
|
17
src/fr/maxlego08/koth/storage/StorageManager.java
Normal file
17
src/fr/maxlego08/koth/storage/StorageManager.java
Normal file
@ -0,0 +1,17 @@
|
||||
package fr.maxlego08.koth.storage;
|
||||
|
||||
import fr.maxlego08.koth.KothPlugin;
|
||||
|
||||
public class StorageManager {
|
||||
|
||||
private final KothPlugin plugin;
|
||||
|
||||
public StorageManager(KothPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void onTeamDisband(String teamId) {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -22,4 +22,5 @@ softdepend:
|
||||
- zSchedulers
|
||||
- DecentHolograms
|
||||
- HuskTowns
|
||||
- Lands
|
||||
commands:
|
Loading…
Reference in New Issue
Block a user