mirror of
https://github.com/Maxlego08/zKoth.git
synced 2025-02-21 02:33:13 +01:00
Ajout du manager, des gestions des différents plugins faction, des messages, des events
This commit is contained in:
parent
4014c6c265
commit
bd8391d119
43
src/fr/maxlego08/koth/FactionListener.java
Normal file
43
src/fr/maxlego08/koth/FactionListener.java
Normal file
@ -0,0 +1,43 @@
|
||||
package fr.maxlego08.koth;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public interface FactionListener extends Listener{
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
String getFactionTag(Player player);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
String getFactionTag(String player);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
List<Player> getOnlinePlayer(String player);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
List<Player> getOnlinePlayer(Player player);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
//void factionTagChange(TotemFaction totemFaction, String newName);
|
||||
|
||||
}
|
103
src/fr/maxlego08/koth/Koth.java
Normal file
103
src/fr/maxlego08/koth/Koth.java
Normal file
@ -0,0 +1,103 @@
|
||||
package fr.maxlego08.koth;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import fr.maxlego08.koth.zcore.utils.Cuboid;
|
||||
|
||||
public class Koth {
|
||||
|
||||
private final String name;
|
||||
private Location pos1;
|
||||
private Location pos2;
|
||||
private transient boolean isEnable;
|
||||
private transient boolean isCooldown;
|
||||
private transient String currentPlayer;
|
||||
private transient Cuboid cuboid;
|
||||
|
||||
public Koth(String name) {
|
||||
super();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pos1
|
||||
* the pos1 to set
|
||||
*/
|
||||
public void setPos1(Location pos1) {
|
||||
this.pos1 = pos1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pos2
|
||||
* the pos2 to set
|
||||
*/
|
||||
public void setPos2(Location pos2) {
|
||||
this.pos2 = pos2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the pos1
|
||||
*/
|
||||
public Location getPos1() {
|
||||
return pos1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the pos2
|
||||
*/
|
||||
public Location getPos2() {
|
||||
return pos2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the isEnable
|
||||
*/
|
||||
public boolean isEnable() {
|
||||
return isEnable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the isCooldown
|
||||
*/
|
||||
public boolean isCooldown() {
|
||||
return isCooldown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the currentPlayer
|
||||
*/
|
||||
public String getCurrentPlayer() {
|
||||
return currentPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the cuboid
|
||||
*/
|
||||
public Cuboid getCuboid() {
|
||||
return cuboid;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String toFirstLocation() {
|
||||
return pos1.getBlockX() + ", " + pos1.getBlockY() + ", " + pos1.getBlockZ();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String toSecondLocation() {
|
||||
return pos2.getBlockX() + ", " + pos2.getBlockY() + ", " + pos2.getBlockZ();
|
||||
}
|
||||
|
||||
}
|
249
src/fr/maxlego08/koth/KothManager.java
Normal file
249
src/fr/maxlego08/koth/KothManager.java
Normal file
@ -0,0 +1,249 @@
|
||||
package fr.maxlego08.koth;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import fr.maxlego08.koth.event.KothRegisterEvent;
|
||||
import fr.maxlego08.koth.factions.LegacyFaction;
|
||||
import fr.maxlego08.koth.factions.NoFaction;
|
||||
import fr.maxlego08.koth.factions.SuperiorSkyblock2;
|
||||
import fr.maxlego08.koth.factions.UUIDFaction;
|
||||
import fr.maxlego08.koth.listener.ListenerAdapter;
|
||||
import fr.maxlego08.koth.zcore.ZPlugin;
|
||||
import fr.maxlego08.koth.zcore.enums.Message;
|
||||
import fr.maxlego08.koth.zcore.logger.Logger;
|
||||
import fr.maxlego08.koth.zcore.logger.Logger.LogType;
|
||||
import fr.maxlego08.koth.zcore.utils.storage.Persist;
|
||||
import fr.maxlego08.koth.zcore.utils.storage.Saveable;
|
||||
import net.md_5.bungee.api.chat.ClickEvent.Action;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
public class KothManager extends ListenerAdapter implements Saveable {
|
||||
|
||||
private static List<Koth> koths = new ArrayList<Koth>();
|
||||
private transient FactionListener factionListener;
|
||||
|
||||
@Override
|
||||
public void save(Persist persist) {
|
||||
persist.save(this, "kohts");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(Persist persist) {
|
||||
persist.loadOrSaveDefault(this, KothManager.class, "kohts");
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet de savoir si un koth existe en fonction du nom
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public boolean exist(String name) {
|
||||
return koths.stream().filter(koth -> koth.getName().equalsIgnoreCase(name)).findAny().isPresent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet de récupérer un koth en fonction du nom
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public Koth get(String name) {
|
||||
return koths.stream().filter(koth -> koth.getName().equalsIgnoreCase(name)).findAny().orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet de vérifier si un koth est activer
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean hasKothEnable() {
|
||||
if (koths.size() == 0)
|
||||
return false;
|
||||
return koths.stream().filter(Koth::isEnable).findAny().isPresent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet de récupérer tout les koths actifs
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Collection<Koth> getKoths() {
|
||||
return koths.stream().filter(Koth::isEnable).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet de créer un koth
|
||||
*
|
||||
* @param sender
|
||||
* @param name
|
||||
*/
|
||||
public void create(CommandSender sender, String name) {
|
||||
|
||||
if (exist(name)) {
|
||||
message(sender, Message.KOTH_ALREADY_EXIST, name);
|
||||
return;
|
||||
}
|
||||
|
||||
Koth koth = new Koth(name);
|
||||
koths.add(koth);
|
||||
|
||||
message(sender, Message.KOTH_CREATE, name);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet de mettre la position d'un koth
|
||||
*
|
||||
* @param sender
|
||||
* @param name
|
||||
* @param location
|
||||
*/
|
||||
public void setPosition(CommandSender sender, String name, Location location, boolean isFirst) {
|
||||
|
||||
if (!exist(name)) {
|
||||
message(sender, Message.KOTH_DOESNT_EXIST, name);
|
||||
return;
|
||||
}
|
||||
|
||||
Koth koth = get(name);
|
||||
|
||||
if (koth == null)
|
||||
return;
|
||||
|
||||
if (isFirst) {
|
||||
koth.setPos1(location);
|
||||
message(sender, Message.KOTH_SET_FIRST_POSITION, name);
|
||||
} else {
|
||||
message(sender, Message.KOTH_SET_SECOND_POSITION, name);
|
||||
koth.setPos2(location);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprimer un koth
|
||||
*
|
||||
* @param sender
|
||||
* @param name
|
||||
*/
|
||||
public void delete(CommandSender sender, String name) {
|
||||
|
||||
if (!exist(name)) {
|
||||
message(sender, Message.KOTH_DOESNT_EXIST, name);
|
||||
return;
|
||||
}
|
||||
|
||||
Koth koth = get(name);
|
||||
koths.remove(koth);
|
||||
|
||||
message(sender, Message.KOTH_DELETE, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet d'envoyer tout les koths a la console
|
||||
*
|
||||
* @param sender
|
||||
*/
|
||||
public void sendKoths(CommandSender sender) {
|
||||
message(sender, Message.KOTH_LIST);
|
||||
|
||||
if (koths.size() == 0)
|
||||
message(sender, Message.KOTH_EMPTY);
|
||||
|
||||
if (sender instanceof Player)
|
||||
sendKoths((Player) sender);
|
||||
else
|
||||
koths.forEach(totem -> message(sender, "§eTotem§8: §6" + totem.getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet d'enviyer tout les koths a un joueur
|
||||
*
|
||||
* @param player
|
||||
*/
|
||||
public void sendKoths(Player player) {
|
||||
|
||||
koths.forEach(koth -> {
|
||||
|
||||
TextComponent component = buildTextComponent("§eKoth§8: §6" + koth.getName());
|
||||
String firstLocation = "§f» §7" + Message.KOTH_FIRST.getMessage() + "§8: §a"
|
||||
+ (koth.getPos1() == null ? Message.KOTH_LOCATION_NULL.getMessage() : koth.toFirstLocation());
|
||||
String secondLocation = "§f» §7" + Message.KOTH_SECOND.getMessage() + "§8: §a"
|
||||
+ (koth.getPos1() == null ? Message.KOTH_LOCATION_NULL.getMessage() : koth.toFirstLocation());
|
||||
setHoverMessage(component, firstLocation, secondLocation);
|
||||
|
||||
TextComponent spawn = buildTextComponent(" §8(§2spawn§8)");
|
||||
setClickAction(spawn, Action.SUGGEST_COMMAND, "/koth spawn " + koth.getName());
|
||||
setHoverMessage(spawn, "§f» §7Click for spawn koth");
|
||||
|
||||
TextComponent now = buildTextComponent(" §8(§2now§8)");
|
||||
setClickAction(now, Action.SUGGEST_COMMAND, "/koth now " + koth.getName());
|
||||
setHoverMessage(now, "§f» §7Click for spawn koth now");
|
||||
|
||||
TextComponent delete = buildTextComponent(" §8(§cdelete§8)");
|
||||
setClickAction(delete, Action.SUGGEST_COMMAND, "/koth delete " + koth.getName());
|
||||
setHoverMessage(delete, "§f» §7Click for delete koth");
|
||||
|
||||
component.addExtra(spawn);
|
||||
component.addExtra(now);
|
||||
component.addExtra(delete);
|
||||
|
||||
player.spigot().sendMessage(component);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet de charger la class {@link FactionListener} en fonction du plugin
|
||||
* Faction
|
||||
*/
|
||||
public void eneableFaction() {
|
||||
|
||||
// On parcours la liste des plugins
|
||||
for (Plugin pl : Bukkit.getPluginManager().getPlugins()) {
|
||||
if (pl.getName().equalsIgnoreCase("LegacyFactions")) {
|
||||
factionListener = new LegacyFaction();
|
||||
Logger.info("LegacyFaction plugin detected successfully.", LogType.SUCCESS);
|
||||
return;
|
||||
} else if (pl.getName().equalsIgnoreCase("SuperiorSkyblock2")) {
|
||||
factionListener = new SuperiorSkyblock2();
|
||||
Logger.info("SuperiorSkyblock2 plugin detected successfully.", LogType.SUCCESS);
|
||||
return;
|
||||
} else if (pl.getName().equalsIgnoreCase("Factions")) {
|
||||
String author = pl.getDescription().getAuthors().toString();
|
||||
if (author.contains("drtshock")) {
|
||||
factionListener = new UUIDFaction();
|
||||
Logger.info("FactionUUID plugin detected successfully.", LogType.SUCCESS);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
factionListener = new NoFaction();
|
||||
Logger.info("no faction plugin was detected.", LogType.SUCCESS);
|
||||
|
||||
KothRegisterEvent event = new KothRegisterEvent(factionListener);
|
||||
event.callEvent();
|
||||
|
||||
factionListener = event.getFactionListener();
|
||||
|
||||
ZPlugin.z().addListener(factionListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMove(PlayerMoveEvent event, Player player) {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -4,6 +4,7 @@ import fr.maxlego08.koth.command.CommandManager;
|
||||
import fr.maxlego08.koth.inventory.InventoryManager;
|
||||
import fr.maxlego08.koth.listener.AdapterListener;
|
||||
import fr.maxlego08.koth.save.Config;
|
||||
import fr.maxlego08.koth.save.Lang;
|
||||
import fr.maxlego08.koth.zcore.ZPlugin;
|
||||
import fr.maxlego08.koth.zcore.utils.builder.CooldownBuilder;
|
||||
|
||||
@ -11,6 +12,7 @@ public class ZKoth extends ZPlugin {
|
||||
|
||||
private CommandManager commandManager;
|
||||
private InventoryManager inventoryManager;
|
||||
private KothManager manager;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@ -30,10 +32,13 @@ public class ZKoth extends ZPlugin {
|
||||
|
||||
addListener(new AdapterListener(this));
|
||||
addListener(inventoryManager);
|
||||
addListener(manager = new KothManager());
|
||||
manager.eneableFaction();
|
||||
|
||||
/* Add Saver */
|
||||
|
||||
addSave(Config.getInstance());
|
||||
addSave(Lang.getInstance());
|
||||
addSave(new CooldownBuilder());
|
||||
|
||||
getSavers().forEach(saver -> saver.load(getPersist()));
|
||||
@ -74,4 +79,8 @@ public class ZKoth extends ZPlugin {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public KothManager getManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
}
|
||||
|
66
src/fr/maxlego08/koth/event/KothEvent.java
Normal file
66
src/fr/maxlego08/koth/event/KothEvent.java
Normal file
@ -0,0 +1,66 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package fr.maxlego08.koth.event;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* @author Maxlego08
|
||||
*
|
||||
*/
|
||||
public class KothEvent extends Event implements Cancellable {
|
||||
|
||||
private final static HandlerList handlers = new HandlerList();
|
||||
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public KothEvent() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isAsync
|
||||
*/
|
||||
public KothEvent(boolean isAsync) {
|
||||
super(isAsync);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.bukkit.event.Event#getHandlers()
|
||||
*/
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean c) {
|
||||
this.cancelled = c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet d'appeler l'event
|
||||
*/
|
||||
public void callEvent(){
|
||||
Bukkit.getPluginManager().callEvent(this);
|
||||
}
|
||||
|
||||
}
|
36
src/fr/maxlego08/koth/event/KothRegisterEvent.java
Normal file
36
src/fr/maxlego08/koth/event/KothRegisterEvent.java
Normal file
@ -0,0 +1,36 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package fr.maxlego08.koth.event;
|
||||
|
||||
import fr.maxlego08.koth.FactionListener;
|
||||
|
||||
/**
|
||||
* @author Maxlego08
|
||||
* Permet de register le faction listener
|
||||
*/
|
||||
public class KothRegisterEvent extends KothEvent {
|
||||
|
||||
private FactionListener factionListener;
|
||||
|
||||
public KothRegisterEvent(FactionListener factionListener) {
|
||||
super();
|
||||
this.factionListener = factionListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the factionListener
|
||||
*/
|
||||
public FactionListener getFactionListener() {
|
||||
return factionListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param factionListener
|
||||
* the factionListener to set
|
||||
*/
|
||||
public void setFactionListener(FactionListener factionListener) {
|
||||
this.factionListener = factionListener;
|
||||
}
|
||||
|
||||
}
|
37
src/fr/maxlego08/koth/factions/LegacyFaction.java
Normal file
37
src/fr/maxlego08/koth/factions/LegacyFaction.java
Normal file
@ -0,0 +1,37 @@
|
||||
package fr.maxlego08.koth.factions;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.maxlego08.koth.FactionListener;
|
||||
import fr.maxlego08.koth.zcore.ZPlugin;
|
||||
import net.redstoneore.legacyfactions.entity.FPlayerColl;
|
||||
|
||||
public class LegacyFaction implements FactionListener {
|
||||
|
||||
public LegacyFaction() {
|
||||
ZPlugin.z().addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFactionTag(Player player) {
|
||||
return FPlayerColl.get(player).getFaction().getTag();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFactionTag(String player) {
|
||||
return FPlayerColl.get(player).getFaction().getTag();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Player> getOnlinePlayer(String player) {
|
||||
return FPlayerColl.get(player).getFaction().getOnlinePlayers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Player> getOnlinePlayer(Player player) {
|
||||
return getOnlinePlayer(player.getName());
|
||||
}
|
||||
|
||||
}
|
37
src/fr/maxlego08/koth/factions/NoFaction.java
Normal file
37
src/fr/maxlego08/koth/factions/NoFaction.java
Normal file
@ -0,0 +1,37 @@
|
||||
package fr.maxlego08.koth.factions;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.maxlego08.koth.FactionListener;
|
||||
|
||||
public class NoFaction implements FactionListener {
|
||||
|
||||
public NoFaction() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFactionTag(Player player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFactionTag(String player) {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Player> getOnlinePlayer(String player) {
|
||||
return Arrays.asList(Bukkit.getPlayer(player));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Player> getOnlinePlayer(Player player) {
|
||||
return Arrays.asList(player);
|
||||
}
|
||||
|
||||
}
|
46
src/fr/maxlego08/koth/factions/SuperiorSkyblock2.java
Normal file
46
src/fr/maxlego08/koth/factions/SuperiorSkyblock2.java
Normal file
@ -0,0 +1,46 @@
|
||||
package fr.maxlego08.koth.factions;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.bgsoftware.superiorskyblock.api.SuperiorSkyblock;
|
||||
import com.bgsoftware.superiorskyblock.api.SuperiorSkyblockAPI;
|
||||
import com.bgsoftware.superiorskyblock.api.island.Island;
|
||||
|
||||
import fr.maxlego08.koth.FactionListener;
|
||||
|
||||
public class SuperiorSkyblock2 implements FactionListener {
|
||||
|
||||
private final SuperiorSkyblock plugin = SuperiorSkyblockAPI.getSuperiorSkyblock();
|
||||
|
||||
private Island getIsland(Player player) {
|
||||
return plugin.getGrid().getIsland(SuperiorSkyblockAPI.getPlayer(player));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFactionTag(Player player) {
|
||||
return getIsland(player).getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFactionTag(String player) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Player> getOnlinePlayer(String player) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Player> getOnlinePlayer(Player player) {
|
||||
Island island = getIsland(player);
|
||||
List<Player> players = island.getIslandMembers(true).stream().map(p -> Bukkit.getOfflinePlayer(p.getUniqueId()))
|
||||
.filter(p -> p.isOnline()).map(p -> p.getPlayer()).collect(Collectors.toList());
|
||||
return players;
|
||||
}
|
||||
|
||||
}
|
33
src/fr/maxlego08/koth/factions/UUIDFaction.java
Normal file
33
src/fr/maxlego08/koth/factions/UUIDFaction.java
Normal file
@ -0,0 +1,33 @@
|
||||
package fr.maxlego08.koth.factions;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
|
||||
import fr.maxlego08.koth.FactionListener;
|
||||
|
||||
public class UUIDFaction implements FactionListener {
|
||||
|
||||
@Override
|
||||
public String getFactionTag(Player player) {
|
||||
return FPlayers.getInstance().getByPlayer(player).getFaction().getTag();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFactionTag(String player) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Player> getOnlinePlayer(String player) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Player> getOnlinePlayer(Player player) {
|
||||
return FPlayers.getInstance().getByPlayer(player).getFaction().getOnlinePlayers();
|
||||
}
|
||||
|
||||
}
|
@ -1,8 +1,5 @@
|
||||
package fr.maxlego08.koth.listener;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
@ -19,7 +16,6 @@ import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
@ -28,7 +24,6 @@ import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import fr.maxlego08.koth.ZKoth;
|
||||
import fr.maxlego08.koth.save.Config;
|
||||
import fr.maxlego08.koth.zcore.utils.ZUtils;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@ -118,27 +113,6 @@ public class AdapterListener extends ZUtils implements Listener {
|
||||
template.getListenerAdapters().forEach(adapter -> adapter.onGamemodeChange(event, event.getPlayer()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDrop(PlayerDropItemEvent event) {
|
||||
template.getListenerAdapters().forEach(adapter -> adapter.onDrop(event, event.getPlayer()));
|
||||
if (!Config.useItemFallEvent)
|
||||
return;
|
||||
Item item = event.getItemDrop();
|
||||
AtomicBoolean hasSendEvent = new AtomicBoolean(false);
|
||||
scheduleFix(100, (task, isActive) -> {
|
||||
if (!isActive)
|
||||
return;
|
||||
template.getListenerAdapters().forEach(adapter -> adapter.onItemMove(event, event.getPlayer(), item,
|
||||
item.getLocation(), item.getLocation().getBlock()));
|
||||
if (item.isOnGround() && !hasSendEvent.get()) {
|
||||
task.cancel();
|
||||
hasSendEvent.set(true);
|
||||
template.getListenerAdapters().forEach(
|
||||
adapter -> adapter.onItemisOnGround(event, event.getPlayer(), item, item.getLocation()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPick(PlayerPickupItemEvent event) {
|
||||
template.getListenerAdapters().forEach(adapter -> adapter.onPickUp(event, event.getPlayer()));
|
||||
|
@ -5,8 +5,6 @@ import fr.maxlego08.koth.zcore.utils.storage.Saveable;
|
||||
|
||||
public class Config implements Saveable {
|
||||
|
||||
public static String version = "0.0.0.1";
|
||||
public static boolean useItemFallEvent = false;
|
||||
|
||||
/**
|
||||
* static Singleton instance.
|
||||
|
59
src/fr/maxlego08/koth/save/Lang.java
Normal file
59
src/fr/maxlego08/koth/save/Lang.java
Normal file
@ -0,0 +1,59 @@
|
||||
package fr.maxlego08.koth.save;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import fr.maxlego08.koth.zcore.enums.Message;
|
||||
import fr.maxlego08.koth.zcore.utils.storage.Persist;
|
||||
import fr.maxlego08.koth.zcore.utils.storage.Saveable;
|
||||
|
||||
public class Lang implements Saveable {
|
||||
|
||||
public static Map<Message, String> messages = new HashMap<Message, String>();
|
||||
|
||||
static {
|
||||
|
||||
for (Message message : Message.values())
|
||||
messages.put(message, message.getMessage());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* static Singleton instance.
|
||||
*/
|
||||
private static volatile Lang instance;
|
||||
|
||||
/**
|
||||
* Private constructor for singleton.
|
||||
*/
|
||||
private Lang() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a singleton instance of Config.
|
||||
*/
|
||||
public static Lang getInstance() {
|
||||
// Double lock for thread safety.
|
||||
if (instance == null) {
|
||||
synchronized (Lang.class) {
|
||||
if (instance == null) {
|
||||
instance = new Lang();
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void save(Persist persist) {
|
||||
for (Message message : Message.values())
|
||||
if (message.isUse())
|
||||
messages.putIfAbsent(message, message.getMessage());
|
||||
persist.save(getInstance());
|
||||
}
|
||||
|
||||
public void load(Persist persist) {
|
||||
persist.loadOrSaveDefault(getInstance(), Lang.class);
|
||||
messages.forEach((key, value) -> key.setMessage(value));
|
||||
}
|
||||
|
||||
}
|
@ -2,38 +2,72 @@ package fr.maxlego08.koth.zcore.enums;
|
||||
|
||||
public enum Message {
|
||||
|
||||
PREFIX("§7(§bTemplate§7)"),
|
||||
PREFIX("§8(§6zKoth§8)", true),
|
||||
|
||||
TELEPORT_MOVE("§cVous ne devez pas bouger !"),
|
||||
TELEPORT_MESSAGE("§7Téléportatio dans §3%s §7secondes !"),
|
||||
TELEPORT_ERROR("§cVous avez déjà une téléportation en cours !"),
|
||||
TELEPORT_SUCCESS("§7Téléportation effectué !"),
|
||||
TELEPORT_MOVE("§cVous ne devez pas bouger !", false),
|
||||
TELEPORT_MESSAGE("§7Téléportatio dans §3%s §7secondes !", false),
|
||||
TELEPORT_ERROR("§cVous avez déjà une téléportation en cours !", false),
|
||||
TELEPORT_SUCCESS("§7Téléportation effectué !", false),
|
||||
|
||||
INVENTORY_NULL("§cImpossible de trouver l'inventaire avec l'id §6%s§c."),
|
||||
INVENTORY_CLONE_NULL("§cLe clone de l'inventaire est null !"),
|
||||
INVENTORY_OPEN_ERROR("§cUne erreur est survenu avec l'ouverture de l'inventaire §6%s§c."),
|
||||
INVENTORY_BUTTON_PREVIOUS("§f» §7Page précédente"),
|
||||
INVENTORY_BUTTON_NEXT("§f» §7Page suivante"),
|
||||
INVENTORY_NULL("§cImpossible de trouver l'inventaire avec l'id §6%s§c.", false),
|
||||
INVENTORY_CLONE_NULL("§cLe clone de l'inventaire est null !", false),
|
||||
INVENTORY_OPEN_ERROR("§cUne erreur est survenu avec l'ouverture de l'inventaire §6%s§c.", false),
|
||||
INVENTORY_BUTTON_PREVIOUS("§f» §7Page précédente", false),
|
||||
INVENTORY_BUTTON_NEXT("§f» §7Page suivante", false),
|
||||
|
||||
TIME_DAY("%02d jour(s) %02d heure(s) %02d minute(s) %02d seconde(s)"),
|
||||
TIME_HOUR("%02d heure(s) %02d minute(s) %02d seconde(s)"),
|
||||
TIME_HOUR_SIMPLE("%02d:%02d:%02d"),
|
||||
TIME_MINUTE("%02d minute(s) %02d seconde(s)"),
|
||||
TIME_SECOND("%02d seconde(s)"),
|
||||
TIME_DAY("%02d jour(s) %02d heure(s) %02d minute(s) %02d seconde(s)", true),
|
||||
TIME_HOUR("%02d heure(s) %02d minute(s) %02d seconde(s)", true),
|
||||
TIME_HOUR_SIMPLE("%02d:%02d:%02d", true),
|
||||
TIME_MINUTE("%02d minute(s) %02d seconde(s)", true),
|
||||
TIME_SECOND("%02d seconde(s)", true),
|
||||
|
||||
COMMAND_SYNTAXE_ERROR("§cVous devez exécuter la commande comme ceci§7: §a%s"),
|
||||
COMMAND_NO_PERMISSION("§cVous n'avez pas la permission d'exécuter cette commande."),
|
||||
COMMAND_NO_CONSOLE("§cSeul un joueur peut exécuter cette commande."),
|
||||
COMMAND_NO_ARG("§cImpossible de trouver la commande avec ses arguments."),
|
||||
COMMAND_SYNTAXE_HELP("§a%s §b» §7%s"),
|
||||
COMMAND_SYNTAXE_ERROR("§cVous devez exécuter la commande comme ceci§7: §a%s", true),
|
||||
COMMAND_NO_PERMISSION("§cVous n'avez pas la permission d'exécuter cette commande.", true),
|
||||
COMMAND_NO_CONSOLE("§cSeul un joueur peut exécuter cette commande.", true),
|
||||
COMMAND_NO_ARG("§cImpossible de trouver la commande avec ses arguments.", true),
|
||||
COMMAND_SYNTAXE_HELP("§a%s §b» §7%s", true),
|
||||
|
||||
KOTH_LIST("§eAvailable koths§8:"),
|
||||
KOTH_EMPTY("§cNo koth available."),
|
||||
KOTH_CREATE("§eYou have just created the koth §6%s§e. Now you must do §f/koth set pos1/pos2 <koth name>§e."),
|
||||
KOTH_DELETE("§eYou have just deleted the koth §6%s§e."),
|
||||
KOTH_ALREADY_EXIST("§cThe koth §6%s §calready exist."),
|
||||
KOTH_DOESNT_EXIST("§cThe koth §6%s §cdoesn't exist."),
|
||||
KOTH_SET_FIRST_POSITION("§eYou just put the first position for the koth §6%s§e."),
|
||||
KOTH_SET_SECOND_POSITION("§eYou just put the second position for the koth §6%s§e."),
|
||||
|
||||
KOTH_LOCATION_NULL("You did not put this location"),
|
||||
KOTH_FIRST("First location"),
|
||||
KOTH_SECOND("Second location"),
|
||||
|
||||
DESCRIPTION_SPAWN("Spawn a koth"),
|
||||
DESCRIPTION_CREATE("Create a koth"),
|
||||
DESCRIPTION_DELETE("Delete a koth"),
|
||||
DESCRIPTION_NOW("Spawn koth without cooldown"),
|
||||
DESCRIPTION_STOP("Stop a koth"),
|
||||
DESCRIPTION_RELOAD("Reload plugin"),
|
||||
DESCRIPTION_VERSION("Show plugin version"),
|
||||
DESCRIPTION_HELP("Show commands"),
|
||||
DESCRIPTION_SHOW("Show koth"),
|
||||
DESCRIPTION_SET("Set koth locations"),
|
||||
DESCRIPTION_SCHEDULER("Show scheduler commands"),
|
||||
DESCRIPTION_SCHEDULER_LIST("Show scheduler list"),
|
||||
DESCRIPTION_SCHEDULER_ADD("Add a scheduler"),
|
||||
DESCRIPTION_SCHEDULER_REMOVE("Remove a scheduler"),
|
||||
|
||||
;
|
||||
|
||||
private String message;
|
||||
private boolean use = true;
|
||||
|
||||
private Message(String message) {
|
||||
this.message = message;
|
||||
this.use = true;
|
||||
}
|
||||
|
||||
private Message(String message, boolean use) {
|
||||
this.message = message;
|
||||
this.use = use;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
@ -47,6 +81,13 @@ public enum Message {
|
||||
public String msg() {
|
||||
return message;
|
||||
}
|
||||
public boolean isUse() {
|
||||
return use;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,10 @@ import fr.maxlego08.koth.ZKoth;
|
||||
import fr.maxlego08.koth.zcore.ZPlugin;
|
||||
import fr.maxlego08.koth.zcore.enums.Message;
|
||||
import fr.maxlego08.koth.zcore.enums.Permission;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@ -863,4 +867,48 @@ public abstract class ZUtils {
|
||||
tmpList.add(list.get(index));
|
||||
return tmpList;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param message
|
||||
* @return
|
||||
*/
|
||||
protected TextComponent buildTextComponent(String message) {
|
||||
return new TextComponent(message);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param message
|
||||
* @return
|
||||
*/
|
||||
protected TextComponent buildTextComponentWithPrefix(String message) {
|
||||
return new TextComponent(Message.PREFIX.getMessage() + " " + message);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param message
|
||||
* @return
|
||||
*/
|
||||
protected TextComponent setHoverMessage(TextComponent component, String... messages) {
|
||||
BaseComponent[] list = new BaseComponent[messages.length];
|
||||
for (int a = 0; a != messages.length; a++)
|
||||
list[a] = new TextComponent(messages[a] + (messages.length - 1 == a ? "" : "\n"));
|
||||
component.setHoverEvent(new HoverEvent(net.md_5.bungee.api.chat.HoverEvent.Action.SHOW_TEXT, list));
|
||||
return component;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param component
|
||||
* @param action
|
||||
* @param command
|
||||
* @return
|
||||
*/
|
||||
protected TextComponent setClickAction(TextComponent component, net.md_5.bungee.api.chat.ClickEvent.Action action,
|
||||
String command) {
|
||||
component.setClickEvent(new ClickEvent(action, command));
|
||||
return component;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user