mirror of
https://github.com/Maxlego08/zKoth.git
synced 2025-02-22 02:42:15 +01:00
🚧 Edit messages
This commit is contained in:
parent
2b5f8c7e31
commit
28da6557aa
@ -146,10 +146,11 @@ public class ZKoth extends ZUtils implements Koth {
|
||||
} else if (this.isEnable) {
|
||||
message(sender, Message.ZKOTH_SPAWN_ALREADY);
|
||||
} else {
|
||||
if (now)
|
||||
if (now) {
|
||||
spawnNow();
|
||||
else
|
||||
} else {
|
||||
spawn();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -164,14 +165,18 @@ public class ZKoth extends ZUtils implements Koth {
|
||||
} else if (this.isEnable) {
|
||||
return;
|
||||
} else {
|
||||
if (now)
|
||||
if (now) {
|
||||
spawnNow();
|
||||
else
|
||||
} else {
|
||||
spawn();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet de faire spawn le Koth avec un cooldown
|
||||
*/
|
||||
private void spawn() {
|
||||
|
||||
this.isCooldown = true;
|
||||
@ -201,8 +206,9 @@ public class ZKoth extends ZUtils implements Koth {
|
||||
int tmpCapture = this.currentCaptureSeconds.get();
|
||||
|
||||
// Si on doit avetir
|
||||
if (Config.displayMessageCooldown.contains(tmpCapture))
|
||||
if (Config.displayMessageCooldown.contains(tmpCapture)) {
|
||||
broadcast(Message.ZKOTH_EVENT_COOLDOWN);
|
||||
}
|
||||
|
||||
if (tmpCapture <= 0) {
|
||||
this.isCooldown = false;
|
||||
@ -215,13 +221,17 @@ public class ZKoth extends ZUtils implements Koth {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet de faire spawn le koth maintenant
|
||||
*/
|
||||
private void spawnNow() {
|
||||
|
||||
KothSpawnEvent event = new KothSpawnEvent(this);
|
||||
event.callEvent();
|
||||
|
||||
if (event.isCancelled())
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.isCooldown = false;
|
||||
this.isEnable = true;
|
||||
@ -247,9 +257,11 @@ public class ZKoth extends ZUtils implements Koth {
|
||||
if (message.getMessages().size() == 0) {
|
||||
String realMessage = replaceMessage(message.getMessage());
|
||||
broadcastCenterMessage(Arrays.asList(realMessage));
|
||||
} else
|
||||
broadcastCenterMessage(
|
||||
message.getMessages().stream().map(e -> replaceMessage(e)).collect(Collectors.toList()));
|
||||
} else {
|
||||
broadcastCenterMessage(message.getMessages().stream().map(e -> {
|
||||
return replaceMessage(e);
|
||||
}).collect(Collectors.toList()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TCHAT: {
|
||||
@ -270,8 +282,9 @@ public class ZKoth extends ZUtils implements Koth {
|
||||
int fadeInTime = message.getStart();
|
||||
int showTime = message.getTime();
|
||||
int fadeOutTime = message.getEnd();
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
this.title(player, title, subTitle, fadeInTime, showTime, fadeOutTime);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NONE:
|
||||
@ -281,6 +294,7 @@ public class ZKoth extends ZUtils implements Koth {
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet de remplacer les messages
|
||||
*
|
||||
* @param message
|
||||
* @return string
|
||||
@ -289,17 +303,22 @@ public class ZKoth extends ZUtils implements Koth {
|
||||
|
||||
Cuboid cuboid = getCuboid();
|
||||
Location center = cuboid.getCenter();
|
||||
|
||||
if (center != null) {
|
||||
message = message.replace("%x%", String.valueOf(center.getBlockX()));
|
||||
message = message.replace("%y%", String.valueOf(center.getBlockY()));
|
||||
message = message.replace("%z%", String.valueOf(center.getBlockZ()));
|
||||
}
|
||||
message = message.replace("%capture%", TimerBuilder
|
||||
.getStringTime(this.currentCaptureSeconds == null ? this.captureSeconds : currentCaptureSeconds.get()));
|
||||
|
||||
int seconds = this.currentCaptureSeconds == null ? this.captureSeconds : currentCaptureSeconds.get();
|
||||
message = message.replace("%capture%", TimerBuilder.getStringTime(seconds));
|
||||
message = message.replace("%world%", center.getWorld().getName());
|
||||
message = message.replace("%name%", this.name);
|
||||
message = message.replace("%player%",
|
||||
this.currentPlayer == null ? Message.ZKOHT_EVENT_PLAYER.getMessage() : this.currentPlayer.getName());
|
||||
|
||||
String player = this.currentPlayer == null ? Message.ZKOHT_EVENT_PLAYER.getMessage()
|
||||
: this.currentPlayer.getName();
|
||||
message = message.replace("%player%", player);
|
||||
|
||||
String faction = this.currentPlayer == null ? Message.ZKOHT_EVENT_FACION.getMessage()
|
||||
: this.factionListener.getFactionTag(this.currentPlayer);
|
||||
message = message.replace("%faction%", faction);
|
||||
@ -310,8 +329,9 @@ public class ZKoth extends ZUtils implements Koth {
|
||||
@Override
|
||||
public void playerMove(Player player, FactionListener factionListener) {
|
||||
|
||||
if (!this.isEnable)
|
||||
if (!this.isEnable) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.factionListener = factionListener;
|
||||
Cuboid cuboid = this.getCuboid();
|
||||
@ -326,13 +346,15 @@ public class ZKoth extends ZUtils implements Koth {
|
||||
KothLooseEvent event = new KothLooseEvent(this.currentPlayer, this);
|
||||
event.callEvent();
|
||||
|
||||
if (event.isCancelled())
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
broadcast(Message.ZKOHT_EVENT_LOOSE);
|
||||
|
||||
if (this.timerTask != null)
|
||||
if (this.timerTask != null) {
|
||||
this.timerTask.cancel();
|
||||
}
|
||||
|
||||
this.timerTask = null;
|
||||
this.currentPlayer = null;
|
||||
@ -357,8 +379,9 @@ public class ZKoth extends ZUtils implements Koth {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Config.enableStartCapMessage)
|
||||
if (Config.enableStartCapMessage) {
|
||||
broadcast(Message.ZKOHT_EVENT_CATCH);
|
||||
}
|
||||
|
||||
int captureSeconds = event.getCaptureSeconds();
|
||||
captureSeconds = captureSeconds < 0 ? 30 : captureSeconds;
|
||||
@ -392,8 +415,9 @@ public class ZKoth extends ZUtils implements Koth {
|
||||
KothLooseEvent kothLooseEvent = new KothLooseEvent(this.currentPlayer, this);
|
||||
kothLooseEvent.callEvent();
|
||||
|
||||
if (kothLooseEvent.isCancelled())
|
||||
if (kothLooseEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.timerTask != null)
|
||||
this.timerTask.cancel();
|
||||
@ -401,21 +425,25 @@ public class ZKoth extends ZUtils implements Koth {
|
||||
this.timerTask = null;
|
||||
this.currentPlayer = null;
|
||||
|
||||
if (Config.enableLooseCapMessage)
|
||||
if (Config.enableLooseCapMessage) {
|
||||
broadcast(Message.ZKOHT_EVENT_LOOSE);
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
if (Config.displayMessageKothCap.contains(tmpCapture))
|
||||
|
||||
if (Config.displayMessageKothCap.contains(tmpCapture)) {
|
||||
broadcast(Message.ZKOHT_EVENT_TIMER);
|
||||
}
|
||||
|
||||
if (tmpCapture <= 0) {
|
||||
|
||||
KothWinEvent kothWinEvent = new KothWinEvent(this, this.currentPlayer);
|
||||
kothWinEvent.callEvent();
|
||||
|
||||
if (kothWinEvent.isCancelled())
|
||||
if (kothWinEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
task.cancel();
|
||||
broadcast(Message.ZKOTH_EVENT_WIN);
|
||||
@ -429,8 +457,10 @@ public class ZKoth extends ZUtils implements Koth {
|
||||
|
||||
Location center = cuboid.getCenter();
|
||||
World world = center.getWorld();
|
||||
while (center.getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.AIR))
|
||||
while (center.getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.AIR)) {
|
||||
center = center.getBlock().getRelative(BlockFace.DOWN).getLocation();
|
||||
}
|
||||
|
||||
Location location = center;
|
||||
|
||||
if (this.itemStacks.size() != 0)
|
||||
@ -516,7 +546,7 @@ public class ZKoth extends ZUtils implements Koth {
|
||||
@Override
|
||||
public void stop(CommandSender sender) {
|
||||
|
||||
if (!isEnable) {
|
||||
if (!this.isEnable) {
|
||||
message(sender, Message.ZKOTH_EVENT_DISABLE);
|
||||
return;
|
||||
}
|
||||
@ -524,13 +554,16 @@ public class ZKoth extends ZUtils implements Koth {
|
||||
KothStopEvent event = new KothStopEvent(this);
|
||||
event.callEvent();
|
||||
|
||||
if (event.isCancelled())
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
broadcast(Message.ZKOHT_EVENT_STOP);
|
||||
|
||||
if (this.timerTask != null)
|
||||
if (this.timerTask != null) {
|
||||
this.timerTask.cancel();
|
||||
}
|
||||
|
||||
this.timerTask = null;
|
||||
this.isEnable = false;
|
||||
this.isCooldown = false;
|
||||
|
@ -20,7 +20,6 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
@ -65,10 +64,10 @@ public class ZKothManager extends ListenerAdapter implements KothManager {
|
||||
private static List<ZKoth> koths = new ArrayList<ZKoth>();
|
||||
|
||||
private final transient ScoreBoardManager manager;
|
||||
private final transient String itemName = "§6✤ §ezKoth axe §6✤";
|
||||
private final transient Map<UUID, Selection> selections = new HashMap<UUID, Selection>();
|
||||
private transient FactionListener factionListener;
|
||||
private transient long playerMoveEventCooldown = 0;
|
||||
private transient final Map<Inventory, String> lootInventories = new HashMap<>();
|
||||
|
||||
/**
|
||||
* @param plugin
|
||||
@ -95,37 +94,37 @@ public class ZKothManager extends ListenerAdapter implements KothManager {
|
||||
|
||||
if (pluginManager.isPluginEnabled("FactionsX")) {
|
||||
|
||||
factionListener = new FactionsXHook();
|
||||
this.factionListener = new FactionsXHook();
|
||||
Logger.info("FactionsX plugin detected successfully.", LogType.SUCCESS);
|
||||
|
||||
} else if (pluginManager.isPluginEnabled("SuperiorSkyblock2")) {
|
||||
|
||||
factionListener = new SuperiorSkyblock2Hook();
|
||||
this.factionListener = new SuperiorSkyblock2Hook();
|
||||
Logger.info("SuperiorSkyblock2 plugin detected successfully.", LogType.SUCCESS);
|
||||
|
||||
} else if (pluginManager.isPluginEnabled("Clans")) {
|
||||
|
||||
factionListener = new ClanHook();
|
||||
this.factionListener = new ClanHook();
|
||||
Logger.info("Clans plugin detected successfully.", LogType.SUCCESS);
|
||||
|
||||
} else if (pluginManager.isPluginEnabled("GangsPlus")) {
|
||||
|
||||
factionListener = new GangsHook();
|
||||
this.factionListener = new GangsHook();
|
||||
Logger.info("GangsPlus plugin detected successfully.", LogType.SUCCESS);
|
||||
|
||||
} else if (pluginManager.isPluginEnabled("UltimateFactions")) {
|
||||
|
||||
factionListener = new UltimateFaction();
|
||||
this.factionListener = new UltimateFaction();
|
||||
Logger.info("UltimateFactions plugin detected successfully.", LogType.SUCCESS);
|
||||
|
||||
} else if (pluginManager.isPluginEnabled("Guilds")) {
|
||||
|
||||
factionListener = new GuildsHook();
|
||||
this.factionListener = new GuildsHook();
|
||||
Logger.info("Guilds plugin detected successfully.", LogType.SUCCESS);
|
||||
|
||||
} else if (pluginManager.isPluginEnabled("LegacyFactions")) {
|
||||
|
||||
factionListener = new FactionLegacyHook();
|
||||
this.factionListener = new FactionLegacyHook();
|
||||
Logger.info("LegacyFactions plugin detected successfully.", LogType.SUCCESS);
|
||||
|
||||
} else if (pluginManager.isPluginEnabled("Factions")) {
|
||||
@ -135,41 +134,39 @@ public class ZKothManager extends ListenerAdapter implements KothManager {
|
||||
|
||||
if (authors.contains("Cayorion") && pluginManager.isPluginEnabled("MassiveCore")) {
|
||||
|
||||
factionListener = new FactionMassiveHook();
|
||||
this.factionListener = new FactionMassiveHook();
|
||||
Logger.info("MassiveCraft plugin detected successfully.", LogType.SUCCESS);
|
||||
|
||||
} else if (authors.contains("Savag3life")) {
|
||||
|
||||
factionListener = new FactionsHook();
|
||||
this.factionListener = new FactionsHook();
|
||||
Logger.info("SavageFaction plugin detected successfully.", LogType.SUCCESS);
|
||||
|
||||
} else if (authors.contains("Driftay")) {
|
||||
|
||||
factionListener = new FactionsHook();
|
||||
this.factionListener = new FactionsHook();
|
||||
Logger.info("SaberFaction plugin detected successfully.", LogType.SUCCESS);
|
||||
|
||||
} else if (authors.contains("drtshock")) {
|
||||
|
||||
factionListener = new FactionsHook();
|
||||
this.factionListener = new FactionsHook();
|
||||
Logger.info("FactionUUID plugin detected successfully.", LogType.SUCCESS);
|
||||
|
||||
}
|
||||
|
||||
} else
|
||||
|
||||
{
|
||||
factionListener = new DefaultHook();
|
||||
} else {
|
||||
this.factionListener = new DefaultHook();
|
||||
Logger.info("No plugin was detected.", LogType.SUCCESS);
|
||||
}
|
||||
} else {
|
||||
factionListener = new DefaultHook();
|
||||
this.factionListener = new DefaultHook();
|
||||
Logger.info("No plugin was detected.", LogType.SUCCESS);
|
||||
}
|
||||
|
||||
KothHookEvent event = new KothHookEvent(factionListener);
|
||||
event.callEvent();
|
||||
|
||||
factionListener = event.getFactionListener();
|
||||
this.factionListener = event.getFactionListener();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -184,7 +181,7 @@ public class ZKothManager extends ListenerAdapter implements KothManager {
|
||||
|
||||
Optional<Koth> optional = getKoth(name);
|
||||
if (optional.isPresent()) {
|
||||
message(sender, Message.ZKOTH_ALREADY_EXIST.replace("%name%", name));
|
||||
message(sender, Message.ZKOTH_ALREADY_EXIST, "%name%", name);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -193,25 +190,20 @@ public class ZKothManager extends ListenerAdapter implements KothManager {
|
||||
KothCreateEvent event = new KothCreateEvent(koth);
|
||||
event.callEvent();
|
||||
|
||||
if (event.isCancelled())
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
koths.add((ZKoth) koth);
|
||||
message(sender, Message.ZKOTH_CREATE_SUCCESS.replace("%name%", name));
|
||||
message(sender, Message.ZKOTH_CREATE_SUCCESS, "%name%", name);
|
||||
|
||||
this.save(this.plugin.getPersist());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getKothAxe() {
|
||||
ItemBuilder builder = new ItemBuilder(Material.STONE_AXE, itemName);
|
||||
builder.addLine("§8§m-+------------------------------+-");
|
||||
builder.addLine("");
|
||||
builder.addLine("§f§l» §7Allows you to select a zone to create a koth");
|
||||
builder.addLine(" §7§oYou must select an area with the right click");
|
||||
builder.addLine(" §7§oand left then do the command /koth create <name>");
|
||||
builder.addLine("");
|
||||
builder.addLine("§8§m-+------------------------------+-");
|
||||
ItemBuilder builder = new ItemBuilder(Material.STONE_AXE, Message.ZKOTH_AXE_NAME.getMessage());
|
||||
Message.ZKOTH_AXE_DESCRIPTION.getMessages().forEach(e -> builder.addLine(e));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@ -219,48 +211,51 @@ public class ZKothManager extends ListenerAdapter implements KothManager {
|
||||
protected void onInteract(PlayerInteractEvent event, Player player) {
|
||||
@SuppressWarnings("deprecation")
|
||||
ItemStack itemStack = player.getItemInHand();
|
||||
if (itemStack != null && event.getClickedBlock() != null && same(itemStack, itemName)) {
|
||||
if (itemStack != null && event.getClickedBlock() != null
|
||||
&& same(itemStack, Message.ZKOTH_AXE_NAME.getMessage())) {
|
||||
|
||||
event.setCancelled(true);
|
||||
Optional<Selection> optional = getSelection(player.getUniqueId());
|
||||
Selection selection = null;
|
||||
|
||||
if (!optional.isPresent()) {
|
||||
selection = new ZSelection();
|
||||
this.selections.put(player.getUniqueId(), selection);
|
||||
} else
|
||||
} else {
|
||||
selection = optional.get();
|
||||
}
|
||||
|
||||
Location location = event.getClickedBlock().getLocation();
|
||||
org.bukkit.event.block.Action action = event.getAction();
|
||||
selection.action(action, location);
|
||||
String message = (action.equals(org.bukkit.event.block.Action.LEFT_CLICK_BLOCK) ? Message.ZKOTH_AXE_POS1
|
||||
: Message.ZKOTH_AXE_POS2).getMessage();
|
||||
message = message.replace("%x%", String.valueOf(location.getBlockX()));
|
||||
message = message.replace("%y%", String.valueOf(location.getBlockY()));
|
||||
message = message.replace("%z%", String.valueOf(location.getBlockZ()));
|
||||
message = message.replace("%world%", location.getWorld().getName());
|
||||
message(player, message);
|
||||
Message message = action.equals(org.bukkit.event.block.Action.LEFT_CLICK_BLOCK) ? Message.ZKOTH_AXE_POS1
|
||||
: Message.ZKOTH_AXE_POS2;
|
||||
message(player, message, "%x%", String.valueOf(location.getBlockX()), "%y%",
|
||||
String.valueOf(location.getBlockY()), "%z%", String.valueOf(location.getBlockZ()), "%world%",
|
||||
location.getWorld().getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Selection> getSelection(UUID uuid) {
|
||||
return Optional.ofNullable(selections.getOrDefault(uuid, null));
|
||||
return Optional.ofNullable(this.selections.getOrDefault(uuid, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onConnect(PlayerJoinEvent event, Player player) {
|
||||
|
||||
if (this.hasActiveKoth())
|
||||
if (Config.enableScoreboard)
|
||||
manager.createBoard(player, Config.scoreboardTitle);
|
||||
if (this.hasActiveKoth()) {
|
||||
if (Config.enableScoreboard) {
|
||||
this.manager.createBoard(player, Config.scoreboardTitle);
|
||||
}
|
||||
}
|
||||
|
||||
schedule(500, () -> {
|
||||
if (event.getPlayer().getName().startsWith("Maxlego") || event.getPlayer().getName().startsWith("Sak")) {
|
||||
String version = ZPlugin.z().getDescription().getFullName();
|
||||
message(player, "§aLe serveur utilise §2%s§a!", version);
|
||||
message(player, "§aLe serveur utilise §2%version§a!", "%version%", version);
|
||||
String name = "%%__USER__%%";
|
||||
message(player, "§aUtilisateur spigot §2%s §a!", name);
|
||||
message(player, "§aUtilisateur spigot §2%name%§a.", "%name%", name);
|
||||
}
|
||||
|
||||
});
|
||||
@ -278,13 +273,13 @@ public class ZKothManager extends ListenerAdapter implements KothManager {
|
||||
|
||||
Optional<Koth> optional = getKoth(name);
|
||||
if (!optional.isPresent()) {
|
||||
message(sender, Message.ZKOTH_DOESNT_EXIST.replace("%name%", name));
|
||||
message(sender, Message.ZKOTH_DOESNT_EXIST, "%name%", name);
|
||||
return;
|
||||
}
|
||||
|
||||
ZKoth koth = (ZKoth) optional.get();
|
||||
koths.remove(koth);
|
||||
message(sender, Message.ZKOTH_DELETE_SUCCESS.replace("%name%", name));
|
||||
message(sender, Message.ZKOTH_DELETE_SUCCESS, "%name%", name);
|
||||
|
||||
this.save(this.plugin.getPersist());
|
||||
}
|
||||
@ -294,7 +289,7 @@ public class ZKothManager extends ListenerAdapter implements KothManager {
|
||||
|
||||
Optional<Koth> optional = getKoth(name);
|
||||
if (!optional.isPresent()) {
|
||||
message(sender, Message.ZKOTH_DOESNT_EXIST.replace("%name%", name));
|
||||
message(sender, Message.ZKOTH_DOESNT_EXIST, "%name%", name);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -302,11 +297,12 @@ public class ZKothManager extends ListenerAdapter implements KothManager {
|
||||
KothMoveEvent event = new KothMoveEvent(koth, maxLocation, minLocation);
|
||||
event.callEvent();
|
||||
|
||||
if (event.isCancelled())
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
koth.move(minLocation, maxLocation);
|
||||
message(sender, Message.ZKOTH_MOVE_SUCCESS.replace("%name%", name));
|
||||
message(sender, Message.ZKOTH_MOVE_SUCCESS, "%name%", name);
|
||||
|
||||
this.save(this.plugin.getPersist());
|
||||
}
|
||||
@ -316,7 +312,7 @@ public class ZKothManager extends ListenerAdapter implements KothManager {
|
||||
|
||||
Optional<Koth> optional = getKoth(name);
|
||||
if (!optional.isPresent()) {
|
||||
message(sender, Message.ZKOTH_DOESNT_EXIST.replace("%name%", name));
|
||||
message(sender, Message.ZKOTH_DOESNT_EXIST, "%name%", name);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -348,7 +344,7 @@ public class ZKothManager extends ListenerAdapter implements KothManager {
|
||||
|
||||
if (this.playerMoveEventCooldown != 0 && this.playerMoveEventCooldown > System.currentTimeMillis()) {
|
||||
|
||||
// Do nothin
|
||||
// On est dans le cooldown
|
||||
|
||||
} else {
|
||||
|
||||
@ -367,12 +363,12 @@ public class ZKothManager extends ListenerAdapter implements KothManager {
|
||||
|
||||
@Override
|
||||
public void onKothWin(KothWinEvent event, Koth koth) {
|
||||
manager.clearBoard();
|
||||
this.manager.clearBoard();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKothStop(KothStopEvent event, Koth koth) {
|
||||
manager.clearBoard();
|
||||
this.manager.clearBoard();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -380,8 +376,8 @@ public class ZKothManager extends ListenerAdapter implements KothManager {
|
||||
|
||||
if (sender instanceof ConsoleCommandSender) {
|
||||
|
||||
message(sender, "§fKoths§8: §f"
|
||||
+ toList(koths.stream().map(e -> e.getName()).collect(Collectors.toList()), "§8", "§7"));
|
||||
String string = toList(koths.stream().map(e -> e.getName()).collect(Collectors.toList()), "§8", "§7");
|
||||
message(sender, Message.ZKOTH_LIST_CONSOLE, "%koth%", string);
|
||||
|
||||
} else {
|
||||
|
||||
@ -394,6 +390,7 @@ public class ZKothManager extends ListenerAdapter implements KothManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet d'afficher les informations d'un koth
|
||||
*
|
||||
* @param player
|
||||
* @param koth
|
||||
@ -435,7 +432,7 @@ public class ZKothManager extends ListenerAdapter implements KothManager {
|
||||
|
||||
Optional<Koth> optional = getKoth(name);
|
||||
if (!optional.isPresent()) {
|
||||
message(sender, Message.ZKOTH_DOESNT_EXIST.replace("%name%", name));
|
||||
message(sender, Message.ZKOTH_DOESNT_EXIST, "%name%", name);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -480,14 +477,14 @@ public class ZKothManager extends ListenerAdapter implements KothManager {
|
||||
|
||||
Optional<Koth> optional = getKoth(name);
|
||||
if (!optional.isPresent()) {
|
||||
message(sender, Message.ZKOTH_DOESNT_EXIST.replace("%name%", name));
|
||||
message(sender, Message.ZKOTH_DOESNT_EXIST, "%name%", name);
|
||||
return;
|
||||
}
|
||||
|
||||
Koth koth = optional.get();
|
||||
koth.addCommand(command);
|
||||
message(sender, "§fYou have just added the command §8\"§7" + command + "§8\"");
|
||||
|
||||
message(sender, Message.ZKOTH_COMMAND_CREATE, "%command%", command);
|
||||
|
||||
this.save(this.plugin.getPersist());
|
||||
}
|
||||
|
||||
@ -496,14 +493,14 @@ public class ZKothManager extends ListenerAdapter implements KothManager {
|
||||
|
||||
Optional<Koth> optional = getKoth(name);
|
||||
if (!optional.isPresent()) {
|
||||
message(sender, Message.ZKOTH_DOESNT_EXIST.replace("%name%", name));
|
||||
message(sender, Message.ZKOTH_DOESNT_EXIST, "%name%", name);
|
||||
return;
|
||||
}
|
||||
|
||||
Koth koth = optional.get();
|
||||
koth.removeCommand(id);
|
||||
message(sender, "§7You have just deleted a command.");
|
||||
|
||||
message(sender, Message.ZKOTH_COMMAND_DELETE);
|
||||
|
||||
this.save(this.plugin.getPersist());
|
||||
}
|
||||
|
||||
@ -512,14 +509,14 @@ public class ZKothManager extends ListenerAdapter implements KothManager {
|
||||
|
||||
Optional<Koth> optional = getKoth(name);
|
||||
if (!optional.isPresent()) {
|
||||
message(sender, Message.ZKOTH_DOESNT_EXIST.replace("%name%", name));
|
||||
message(sender, Message.ZKOTH_DOESNT_EXIST, "%name%", name);
|
||||
return;
|
||||
}
|
||||
|
||||
Koth koth = optional.get();
|
||||
koth.setLootType(type);
|
||||
message(sender, "§7You have just set the type to §f%s§7.", type.name().toLowerCase());
|
||||
|
||||
message(sender, Message.ZKOTH_LOOT_EDIT, "%type%", name(type.name()));
|
||||
|
||||
this.save(this.plugin.getPersist());
|
||||
}
|
||||
|
||||
@ -528,43 +525,48 @@ public class ZKothManager extends ListenerAdapter implements KothManager {
|
||||
|
||||
Optional<Koth> optional = getKoth(name);
|
||||
if (!optional.isPresent()) {
|
||||
message(player, Message.ZKOTH_DOESNT_EXIST.replace("%name%", name));
|
||||
message(player, Message.ZKOTH_DOESNT_EXIST, "%name%", name);
|
||||
return;
|
||||
}
|
||||
|
||||
Koth koth = optional.get();
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, "§8Loots: " + name);
|
||||
String inventoryName = this.getMessage(Message.ZKOTH_LOOT_INVENTORY, "%name%", name);
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, inventoryName);
|
||||
|
||||
int slot = 0;
|
||||
for (ItemStack itemStack : koth.getItemStacks()) {
|
||||
inventory.setItem(slot++, itemStack);
|
||||
}
|
||||
|
||||
this.lootInventories.put(inventory, name);
|
||||
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onInventoryClose(InventoryCloseEvent event, Player player) {
|
||||
|
||||
InventoryView view = event.getView();
|
||||
String title = view.getTitle();
|
||||
Inventory inventory = event.getInventory();
|
||||
|
||||
if (title.startsWith("§8Loots: ")) {
|
||||
if (this.lootInventories.containsKey(inventory)) {
|
||||
|
||||
String name = title.replace("§8Loots: ", "");
|
||||
String name = this.lootInventories.get(inventory);
|
||||
Optional<Koth> optional = getKoth(name);
|
||||
if (!optional.isPresent()) {
|
||||
message(player, Message.ZKOTH_DOESNT_EXIST.replace("%name%", name));
|
||||
message(player, Message.ZKOTH_DOESNT_EXIST, "%name%", name);
|
||||
return;
|
||||
}
|
||||
|
||||
Koth koth = optional.get();
|
||||
List<ItemStack> itemStacks = new ArrayList<>();
|
||||
for (ItemStack itemStack : event.getInventory().getContents())
|
||||
if (itemStack != null)
|
||||
for (ItemStack itemStack : event.getInventory().getContents()) {
|
||||
if (itemStack != null) {
|
||||
itemStacks.add(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
koth.setItemStacks(itemStacks);
|
||||
message(player, "§aYou have just modified the loots of the koth §2%s.", koth.getName());
|
||||
message(player, Message.ZKOTH_LOOT_CHANGE, "%name%", koth.getName());
|
||||
}
|
||||
|
||||
}
|
||||
@ -574,7 +576,7 @@ public class ZKothManager extends ListenerAdapter implements KothManager {
|
||||
|
||||
Optional<Koth> optional = getKoth(name);
|
||||
if (!optional.isPresent()) {
|
||||
message(sender, Message.ZKOTH_DOESNT_EXIST.replace("%name%", name));
|
||||
message(sender, Message.ZKOTH_DOESNT_EXIST, "%name%", name);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -589,15 +591,15 @@ public class ZKothManager extends ListenerAdapter implements KothManager {
|
||||
|
||||
Optional<Koth> optional = getKoth(name);
|
||||
if (!optional.isPresent()) {
|
||||
message(sender, Message.ZKOTH_DOESNT_EXIST.replace("%name%", name));
|
||||
message(sender, Message.ZKOTH_DOESNT_EXIST, "%name%", name);
|
||||
return;
|
||||
}
|
||||
|
||||
Koth koth = optional.get();
|
||||
koth.setCapture(second);
|
||||
message(sender, "§aYou have just modified the capture time of the koth §n%s§a to §f%s§a.", koth.getName(),
|
||||
message(sender, Message.ZKOTH_CAPUTRE_EDIT, "%name%", koth.getName(), "%seconds%",
|
||||
TimerBuilder.getStringTime(second));
|
||||
|
||||
|
||||
this.save(this.plugin.getPersist());
|
||||
}
|
||||
|
||||
|
@ -167,15 +167,16 @@ public class CommandManager extends ZUtils implements CommandExecutor, TabComple
|
||||
if (command.runAsync) {
|
||||
super.runAsync(() -> {
|
||||
CommandType returnType = command.prePerform(main, sender, strings);
|
||||
if (returnType == CommandType.SYNTAX_ERROR)
|
||||
message(sender, Message.COMMAND_SYNTAXE_ERROR, command.getSyntaxe());
|
||||
if (returnType == CommandType.SYNTAX_ERROR) {
|
||||
message(sender, Message.COMMAND_SYNTAXE_ERROR, "%syntax%", command.getSyntaxe());
|
||||
}
|
||||
});
|
||||
return CommandType.DEFAULT;
|
||||
}
|
||||
|
||||
CommandType returnType = command.prePerform(main, sender, strings);
|
||||
if (returnType == CommandType.SYNTAX_ERROR) {
|
||||
message(sender, Message.COMMAND_SYNTAXE_ERROR, command.getSyntaxe());
|
||||
message(sender, Message.COMMAND_SYNTAXE_ERROR, "%syntax%", command.getSyntaxe());
|
||||
}
|
||||
return returnType;
|
||||
}
|
||||
@ -196,10 +197,10 @@ public class CommandManager extends ZUtils implements CommandExecutor, TabComple
|
||||
* @param sender
|
||||
*/
|
||||
public void sendHelp(String commandString, CommandSender sender) {
|
||||
commands.forEach(command -> {
|
||||
this.commands.forEach(command -> {
|
||||
if (isValid(command, commandString)
|
||||
&& (command.getPermission() == null || hasPermission(sender, command.getPermission()))) {
|
||||
message(sender, Message.COMMAND_SYNTAXE_HELP, command.getSyntaxe(), command.getDescription());
|
||||
message(sender, Message.COMMAND_SYNTAXE_HELP, "%syntax%", command.getSyntaxe(), "%description%", command.getDescription());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -218,7 +219,7 @@ public class CommandManager extends ZUtils implements CommandExecutor, TabComple
|
||||
* Check if your order is ready for use
|
||||
*/
|
||||
private void commandChecking() {
|
||||
commands.forEach(command -> {
|
||||
this.commands.forEach(command -> {
|
||||
if (command.sameSubCommands()) {
|
||||
Logger.info(command.toString() + " command to an argument similar to its parent command !",
|
||||
LogType.ERROR);
|
||||
@ -263,7 +264,7 @@ public class CommandManager extends ZUtils implements CommandExecutor, TabComple
|
||||
String startWith = args[args.length - 1];
|
||||
|
||||
List<String> tabCompleter = new ArrayList<>();
|
||||
for (VCommand vCommand : commands) {
|
||||
for (VCommand vCommand : this.commands) {
|
||||
if ((vCommand.getParent() != null && vCommand.getParent() == command)) {
|
||||
String cmd = vCommand.getSubCommands().get(0);
|
||||
if (vCommand.getPermission() == null || sender.hasPermission(vCommand.getPermission()))
|
||||
@ -274,7 +275,7 @@ public class CommandManager extends ZUtils implements CommandExecutor, TabComple
|
||||
return tabCompleter.size() == 0 ? null : tabCompleter;
|
||||
|
||||
} else if (type.equals(CommandType.SUCCESS))
|
||||
return command.toTab(plugin, sender, args);
|
||||
return command.toTab(this.plugin, sender, args);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -35,12 +35,8 @@ public class CommandKoth extends VCommand {
|
||||
protected CommandType perform(ZKothPlugin main) {
|
||||
|
||||
this.subVCommands.forEach(command -> {
|
||||
|
||||
String message = Message.COMMAND_SYNTAXE_HELP.getMessage();
|
||||
message = message.replace("%command%", command.getSyntaxe());
|
||||
message = message.replace("%description%", command.getDescription());
|
||||
messageWO(sender, message);
|
||||
|
||||
messageWO(this.sender, Message.COMMAND_SYNTAXE_HELP, "%command%", command.getSyntaxe(), "%description%",
|
||||
command.getDescription());
|
||||
});
|
||||
|
||||
return CommandType.SUCCESS;
|
||||
|
@ -43,7 +43,7 @@ public class CommandKothSchedulerAdd extends VCommand {
|
||||
String day = argAsString(2);
|
||||
|
||||
if (!isDay(day)) {
|
||||
message(sender, Message.KOTH_SCHEDULER_ERROR, day);
|
||||
message(sender, Message.ZKOTH_SCHEDULER_ERROR, day);
|
||||
return CommandType.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ public class MessageLoader extends YamlUtils implements Saveable {
|
||||
}
|
||||
|
||||
Logger.info(file.getAbsolutePath() + " successfully saved !", LogType.SUCCESS);
|
||||
|
||||
|
||||
// Pour avoir directs les news paramètres
|
||||
this.save(null);
|
||||
}
|
||||
@ -113,51 +113,53 @@ public class MessageLoader extends YamlUtils implements Saveable {
|
||||
private void loadMessage(YamlConfiguration configuration, String key) {
|
||||
|
||||
if (configuration.contains(key + ".type")) {
|
||||
|
||||
MessageType messageType = MessageType.valueOf(configuration.getString(key + ".type").toUpperCase());
|
||||
String keys = key.substring("messages.".length(), key.length());
|
||||
Message enumMessage = Message.valueOf(keys.toUpperCase().replace(".", "_"));
|
||||
enumMessage.setType(messageType);
|
||||
switch (messageType) {
|
||||
case ACTION: {
|
||||
String message = configuration.getString(key + ".message");
|
||||
enumMessage.setMessage(color(message));
|
||||
break;
|
||||
}
|
||||
case CENTER:
|
||||
case TCHAT: {
|
||||
if (configuration.contains(key + ".messages")) {
|
||||
List<String> messages = configuration.getStringList(key + ".messages");
|
||||
enumMessage.setMessages(color(messages));
|
||||
enumMessage.setMessage(null);
|
||||
} else {
|
||||
try {
|
||||
MessageType messageType = MessageType.valueOf(configuration.getString(key + ".type").toUpperCase());
|
||||
String keys = key.substring("messages.".length(), key.length());
|
||||
Message enumMessage = Message.valueOf(keys.toUpperCase().replace(".", "_"));
|
||||
enumMessage.setType(messageType);
|
||||
switch (messageType) {
|
||||
case ACTION: {
|
||||
String message = configuration.getString(key + ".message");
|
||||
enumMessage.setMessage(color(message));
|
||||
enumMessage.setMessages(new ArrayList<String>());
|
||||
break;
|
||||
}
|
||||
case CENTER:
|
||||
case TCHAT: {
|
||||
if (configuration.contains(key + ".messages")) {
|
||||
List<String> messages = configuration.getStringList(key + ".messages");
|
||||
enumMessage.setMessages(color(messages));
|
||||
enumMessage.setMessage(null);
|
||||
} else {
|
||||
String message = configuration.getString(key + ".message");
|
||||
enumMessage.setMessage(color(message));
|
||||
enumMessage.setMessages(new ArrayList<String>());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TITLE: {
|
||||
String title = configuration.getString(key + ".title");
|
||||
String subtitle = configuration.getString(key + ".subtitle");
|
||||
int fadeInTime = configuration.getInt(key + ".fadeInTime");
|
||||
int showTime = configuration.getInt(key + ".showTime");
|
||||
int fadeOutTime = configuration.getInt(key + ".fadeOutTime");
|
||||
Map<String, Object> titles = new HashMap<String, Object>();
|
||||
titles.put("title", color(title));
|
||||
titles.put("subtitle", color(subtitle));
|
||||
titles.put("start", fadeInTime);
|
||||
titles.put("time", showTime);
|
||||
titles.put("end", fadeOutTime);
|
||||
titles.put("isUse", true);
|
||||
enumMessage.setTitles(titles);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TITLE: {
|
||||
String title = configuration.getString(key + ".title");
|
||||
String subtitle = configuration.getString(key + ".subtitle");
|
||||
int fadeInTime = configuration.getInt(key + ".fadeInTime");
|
||||
int showTime = configuration.getInt(key + ".showTime");
|
||||
int fadeOutTime = configuration.getInt(key + ".fadeOutTime");
|
||||
Map<String, Object> titles = new HashMap<String, Object>();
|
||||
titles.put("title", color(title));
|
||||
titles.put("subtitle", color(subtitle));
|
||||
titles.put("start", fadeInTime);
|
||||
titles.put("time", showTime);
|
||||
titles.put("end", fadeOutTime);
|
||||
titles.put("isUse", true);
|
||||
enumMessage.setTitles(titles);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
for (String newKey : configuration.getConfigurationSection(key + ".").getKeys(false))
|
||||
|
@ -12,18 +12,13 @@ import fr.maxlego08.zkoth.zcore.utils.nms.NMSUtils;
|
||||
|
||||
public enum Message {
|
||||
|
||||
PREFIX("§8(§fzKoth§8) "),
|
||||
PREFIX("§8(§fzKoth§8) "),
|
||||
|
||||
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%id%§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%id%§c.", false),
|
||||
INVENTORY_BUTTON_PREVIOUS("§f» §7Page précédente", false),
|
||||
INVENTORY_BUTTON_NEXT("§f» §7Page suivante", false),
|
||||
INVENTORY_NULL("§cImpossible de trouver l'inventaire avec l'id §6%id%§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%id%§c.", false),
|
||||
INVENTORY_BUTTON_PREVIOUS("§f» §7Page précédente", false),
|
||||
INVENTORY_BUTTON_NEXT("§f» §7Page suivante", false),
|
||||
|
||||
TIME_DAY("%02dd %02dh %02dm %02ds"),
|
||||
TIME_HOUR("%02dh %02dm %02ds"),
|
||||
@ -31,79 +26,95 @@ public enum Message {
|
||||
TIME_MINUTE("%02dm %02ds"),
|
||||
TIME_SECOND("%02ds"),
|
||||
|
||||
COMMAND_SYNTAXE_ERROR("§cYou have to execute the command like this§7: §2%s"),
|
||||
COMMAND_NO_PERMISSION("§cYou do not have permission to execute this command.."),
|
||||
COMMAND_NO_CONSOLE("§cOnly a player can execute this command."),
|
||||
COMMAND_NO_ARG("§cImpossible to find the command with its arguments."),
|
||||
COMMAND_SYNTAXE_HELP("§f%command% §8» §7%description%"),
|
||||
COMMAND_SYNTAXE_ERROR("§cYou have to execute the command like this§7: §2%syntax%"),
|
||||
COMMAND_NO_PERMISSION("§cYou do not have permission to execute this command.."),
|
||||
COMMAND_NO_CONSOLE("§cOnly a player can execute this command."),
|
||||
COMMAND_NO_ARG("§cImpossible to find the command with its arguments."),
|
||||
COMMAND_SYNTAXE_HELP("§f%command% §8» §7%description%"),
|
||||
|
||||
|
||||
ZKOTH_AXE_RECEIVE("§7You have just received the axe for zone selection."),
|
||||
ZKOTH_AXE_POS1("§7You have just put the first position in §f%world%§7, §f%x%§7, §f%y%§7, §f%z%§7."),
|
||||
ZKOTH_AXE_POS2("§7You have just put the second position in §f%world%§7, §f%x%§7, §f%y%§7, §f%z%§7."),
|
||||
ZKOTH_ALREADY_EXIST("§cThe koth §f%name% §calready exists."),
|
||||
ZKOTH_DOESNT_EXIST("§cThe koth §f%name% §cdoesnt exists."),
|
||||
ZKOTH_AXE_RECEIVE("§7You have just received the axe for zone selection."),
|
||||
ZKOTH_AXE_POS1("§7You have just put the first position in §f%world%§7, §f%x%§7, §f%y%§7, §f%z%§7."),
|
||||
ZKOTH_AXE_POS2("§7You have just put the second position in §f%world%§7, §f%x%§7, §f%y%§7, §f%z%§7."),
|
||||
ZKOTH_ALREADY_EXIST("§cThe koth §f%name% §calready exists."),
|
||||
ZKOTH_DOESNT_EXIST("§cThe koth §f%name% §cdoesnt exists."),
|
||||
|
||||
ZKOTH_CREATE_SUCCESS("§7You just created the koth §f%name%§7."),
|
||||
ZKOTH_DELETE_SUCCESS("§7You just deleted the koth §f%name%§7."),
|
||||
ZKOTH_MOVE_SUCCESS("§7You have just moved the koth §f%name%§7."),
|
||||
ZKOTH_CREATE_ERROR_SELECTION("§cYou must select a zone with the command §f/zkoth axe§c."),
|
||||
ZKOTH_CREATE_SUCCESS("§7You just created the koth §f%name%§7."),
|
||||
ZKOTH_DELETE_SUCCESS("§7You just deleted the koth §f%name%§7."),
|
||||
ZKOTH_MOVE_SUCCESS("§7You have just moved the koth §f%name%§7."),
|
||||
ZKOTH_CREATE_ERROR_SELECTION("§cYou must select a zone with the command §f/zkoth axe§c."),
|
||||
|
||||
|
||||
ZKOTH_SPAWN_ERROR("§cImpossible to spawn the koth, positions do not work. You have to do §f/zkoth move <name>§c."),
|
||||
ZKOTH_SPAWN_COOLDOWN("§cthe countdown to the appearance of the koth is already underway"),
|
||||
ZKOTH_SPAWN_ALREADY("§cThe koth is running."),
|
||||
ZKOTH_SPAWN_ERROR("§cImpossible to spawn the koth, positions do not work. You have to do §f/zkoth move <name>§c."),
|
||||
ZKOTH_SPAWN_COOLDOWN("§cthe countdown to the appearance of the koth is already underway"),
|
||||
ZKOTH_SPAWN_ALREADY("§cThe koth is running."),
|
||||
|
||||
ZKOTH_EVENT_START(MessageType.CENTER,
|
||||
"§8§m-+------------------------------+-",
|
||||
"§8§m-+------------------------------+-",
|
||||
"",
|
||||
"§fThe koth §b%name% §has just appeared!",
|
||||
"§fCoordinate§8: §7%x%, %y%, %z%.",
|
||||
"§fThe koth §b%name% §has just appeared!",
|
||||
"§fCoordinate§8: §7%x%, %y%, %z%.",
|
||||
"",
|
||||
"§8§m-+------------------------------+-"
|
||||
"§8§m-+------------------------------+-"
|
||||
),
|
||||
|
||||
ZKOTH_EVENT_WIN(MessageType.CENTER,
|
||||
"§8§m-+------------------------------+-",
|
||||
"§8§m-+------------------------------+-",
|
||||
"",
|
||||
"§d%player% §fof faction §7%faction% §fhas just captured",
|
||||
"§fthe koth, and §nwins§f the event!",
|
||||
"§d%player% §fof faction §7%faction% §fhas just captured",
|
||||
"§fthe koth, and §nwins§f the event!",
|
||||
"",
|
||||
"§8§m-+------------------------------+-"
|
||||
"§8§m-+------------------------------+-"
|
||||
),
|
||||
|
||||
ZKOTH_EVENT_COOLDOWN(MessageType.CENTER,
|
||||
"§8§m-+------------------------------+-",
|
||||
"§8§m-+------------------------------+-",
|
||||
"",
|
||||
"§fThe koth §n%name%§f will appear in §d%capture%",
|
||||
"§fCoordinate§8: §7%x%, %y%, %z%.",
|
||||
"§fThe koth §n%name%§f will appear in §d%capture%",
|
||||
"§fCoordinate§8: §7%x%, %y%, %z%.",
|
||||
"",
|
||||
"§8§m-+------------------------------+-"
|
||||
"§8§m-+------------------------------+-"
|
||||
),
|
||||
|
||||
ZKOHT_EVENT_STOP(MessageType.CENTER, "§8§m-+------------------------------+-", "", "§fkoth §n%name%§f has just been stopped.", "", "§8§m-+------------------------------+-"),
|
||||
ZKOHT_EVENT_STOP(MessageType.CENTER, "§8§m-+------------------------------+-", "", "§fkoth §n%name%§f has just been stopped.", "", "§8§m-+------------------------------+-"),
|
||||
|
||||
ZKOHT_EVENT_CATCH(MessageType.ACTION, "§d%player% §fjust started capturing the koth §n%name%§f. §8(§7%x%, %y%, %z%§8)"),
|
||||
ZKOHT_EVENT_LOOSE(MessageType.ACTION, "§d%player% §fjust loose koth §n%name%§f. §8(§7%x%, %y%, %z%§8)"),
|
||||
ZKOHT_EVENT_TIMER(MessageType.ACTION, "§fAnother §b%capture% §fbefore §d%player% §fwins the koth §n%name%§e. §8(§7%x%, %y%, %z%§8)"),
|
||||
ZKOHT_EVENT_CATCH(MessageType.ACTION, "§d%player% §fjust started capturing the koth §n%name%§f. §8(§7%x%, %y%, %z%§8)"),
|
||||
ZKOHT_EVENT_LOOSE(MessageType.ACTION, "§d%player% §fjust loose koth §n%name%§f. §8(§7%x%, %y%, %z%§8)"),
|
||||
ZKOHT_EVENT_TIMER(MessageType.ACTION, "§fAnother §b%capture% §fbefore §d%player% §fwins the koth §n%name%§e. §8(§7%x%, %y%, %z%§8)"),
|
||||
|
||||
ZKOHT_EVENT_FACION("No faction"),
|
||||
ZKOHT_EVENT_PLAYER("Person"),
|
||||
ZKOTH_EVENT_DISABLE("§cThe event is not enable."),
|
||||
ZKOTH_EVENT_DISABLE("§cThe event is not enable."),
|
||||
|
||||
ZKOTH_SCHEDULER_CREATE("§eYou have just created a scheduler for the koth §6%s§e."),
|
||||
ZKOTH_SCHEDULER_EMPTY("§cNo scheduler available"),
|
||||
ZKOTH_SCHEDULER_REMOVE_HOVER("§7Click to delete the scheduler"),
|
||||
ZKOTH_SCHEDULER_LIST("§6%totemName%§7, §f%type%§7, §e%day%§7, §e%hour%§7, §e%minute%"),
|
||||
ZKOTH_SCHEDULER_LIST_REPEAT("§6%totemName%§7, §f%type%§7, §e%timer%"),
|
||||
ZKOTH_SCHEDULER_REMOVE_ERROR("§cYou must make /koth scheduler list and then click on one of the koths to be able to delete it"),
|
||||
ZKOTH_SCHEDULER_REMOVE_SUCCESS("§eYou have just deleted the scheduler"),
|
||||
ZKOTH_SCHEDULER_CREATE("§eYou have just created a scheduler for the koth §6%s§e."),
|
||||
ZKOTH_SCHEDULER_EMPTY("§cNo scheduler available"),
|
||||
ZKOTH_SCHEDULER_REMOVE_HOVER("§7Click to delete the scheduler"),
|
||||
ZKOTH_SCHEDULER_LIST("§6%totemName%§7, §f%type%§7, §e%day%§7, §e%hour%§7, §e%minute%"),
|
||||
ZKOTH_SCHEDULER_LIST_REPEAT("§6%totemName%§7, §f%type%§7, §e%timer%"),
|
||||
ZKOTH_SCHEDULER_REMOVE_ERROR("§cYou must make /koth scheduler list and then click on one of the koths to be able to delete it"),
|
||||
ZKOTH_SCHEDULER_REMOVE_SUCCESS("§eYou have just deleted the scheduler"),
|
||||
ZKOTH_SCHEDULER_ERROR("§cImpossible to find the day §f%day%§c."),
|
||||
|
||||
ZKOTH_COMMAND_CREATE("§7You have just added the command §8\"§f%command%§8\""),
|
||||
ZKOTH_COMMAND_DELETE("§aYou have just deleted a command."),
|
||||
ZKOTH_LOOT_EDIT("§aYou have just set the type to §f%type%§a."),
|
||||
ZKOTH_LOOT_INVENTORY("§7Loots §b%name%"),
|
||||
ZKOTH_LOOT_CHANGE("§aYou have just modified the loots of the koth §2%name%§a."),
|
||||
ZKOTH_CAPUTRE_EDIT("§aYou have just modified the capture time of the koth §n%name%§a to §f%seconds%§a."),
|
||||
ZKOTH_LIST_CONSOLE("§fKoths§8: §f%koth%"),
|
||||
ZKOTH_AXE_NAME("§6✤ §ezKoth axe §6✤"),
|
||||
ZKOTH_AXE_DESCRIPTION("§8§m-+------------------------------+-", "",
|
||||
"",
|
||||
"§f§l» §7Allows you to select a zone to create a koth",
|
||||
" §7§oYou must select an area with the right click",
|
||||
" §7§oand left then do the command /koth create <name>",
|
||||
"",
|
||||
"§8§m-+------------------------------+-"),
|
||||
|
||||
DESCRIPTION_SCHEDULER("Show scheduler commands"),
|
||||
DESCRIPTION_SCHEDULER_LIST("Show scheduler list"),
|
||||
DESCRIPTION_SCHEDULER_ADD("Add a scheduler"),
|
||||
DESCRIPTION_SCHEDULER_REMOVE("Remove a scheduler"),
|
||||
KOTH_SCHEDULER_ERROR("§cImpossible to find the day §f%s§c."),
|
||||
|
||||
;
|
||||
|
||||
@ -203,7 +214,7 @@ public enum Message {
|
||||
}
|
||||
|
||||
public List<String> getMessages() {
|
||||
return messages == null ? Arrays.asList(message) : messages;
|
||||
return this.messages == null ? Arrays.asList(this.message) : this.messages;
|
||||
}
|
||||
|
||||
public void setMessages(List<String> messages) {
|
||||
|
@ -1,77 +1,18 @@
|
||||
package fr.maxlego08.zkoth.zcore.utils;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.maxlego08.zkoth.zcore.enums.Message;
|
||||
import fr.maxlego08.zkoth.zcore.utils.nms.NMSUtils;
|
||||
import fr.maxlego08.zkoth.zcore.utils.players.ActionBar;
|
||||
|
||||
public abstract class MessageUtils extends LocationUtils {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
* @param message
|
||||
*/
|
||||
protected void message(CommandSender player, Message message) {
|
||||
player.sendMessage(Message.PREFIX.msg() + papi(message.msg(), player));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
* @param message
|
||||
*/
|
||||
protected void message(CommandSender player, String message) {
|
||||
player.sendMessage(Message.PREFIX.msg() + papi(message, player));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
* @param message
|
||||
*/
|
||||
protected void broadcast(String message) {
|
||||
Bukkit.broadcastMessage(Message.PREFIX.msg() + message);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
* @param message
|
||||
*/
|
||||
protected void message(CommandSender player, String message, Object... args) {
|
||||
player.sendMessage(Message.PREFIX.msg() + String.format(papi(message, player), args));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
* @param message
|
||||
*/
|
||||
protected void messageWO(CommandSender player, Message message) {
|
||||
player.sendMessage(papi(message.msg(), player));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
* @param message
|
||||
*/
|
||||
protected void messageWO(CommandSender player, String message) {
|
||||
player.sendMessage(papi(message, player));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
* @param message
|
||||
*/
|
||||
protected void messageWO(CommandSender player, String message, Object... args) {
|
||||
player.sendMessage(String.format(papi(message, player), args));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
@ -79,7 +20,7 @@ public abstract class MessageUtils extends LocationUtils {
|
||||
* @param args
|
||||
*/
|
||||
protected void messageWO(CommandSender player, Message message, Object... args) {
|
||||
player.sendMessage(String.format(papi(message.getMessage(), player), args));
|
||||
player.sendMessage(getMessage(message, args));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,8 +29,83 @@ public abstract class MessageUtils extends LocationUtils {
|
||||
* @param message
|
||||
* @param args
|
||||
*/
|
||||
protected void message(CommandSender player, Message message, Object... args) {
|
||||
player.sendMessage(Message.PREFIX.msg() + String.format(papi(message.msg(), player), args));
|
||||
protected void messageWO(CommandSender player, String message, Object... args) {
|
||||
player.sendMessage(getMessage(message, args));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param sender
|
||||
* @param message
|
||||
* @param args
|
||||
*/
|
||||
protected void message(CommandSender sender, String message, Object... args) {
|
||||
sender.sendMessage(Message.PREFIX.msg() + getMessage(message, args));
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows you to send a message to a command sender
|
||||
*
|
||||
* @param sender
|
||||
* User who sent the command
|
||||
* @param message
|
||||
* The message - Using the Message enum for simplified message
|
||||
* management
|
||||
* @param args
|
||||
* The arguments - The arguments work in pairs, you must put for
|
||||
* example %test% and then the value
|
||||
*/
|
||||
protected void message(CommandSender sender, Message message, Object... args) {
|
||||
|
||||
if (sender instanceof ConsoleCommandSender) {
|
||||
if (message.getMessages().size() > 0) {
|
||||
message.getMessages().forEach(msg -> sender.sendMessage(Message.PREFIX.msg() + getMessage(msg, args)));
|
||||
} else {
|
||||
sender.sendMessage(Message.PREFIX.msg() + getMessage(message, args));
|
||||
}
|
||||
} else {
|
||||
|
||||
Player player = (Player) sender;
|
||||
switch (message.getType()) {
|
||||
case ACTION:
|
||||
this.actionMessage(player, message, args);
|
||||
break;
|
||||
case TCHAT:
|
||||
if (message.getMessages().size() > 0) {
|
||||
message.getMessages()
|
||||
.forEach(msg -> sender.sendMessage(Message.PREFIX.msg() + getMessage(msg, args)));
|
||||
} else {
|
||||
sender.sendMessage(Message.PREFIX.msg() + getMessage(message, args));
|
||||
}
|
||||
break;
|
||||
case TITLE:
|
||||
// title message management
|
||||
String title = message.getTitle();
|
||||
String subTitle = message.getSubTitle();
|
||||
int fadeInTime = message.getStart();
|
||||
int showTime = message.getTime();
|
||||
int fadeOutTime = message.getEnd();
|
||||
this.title(player, title, subTitle, fadeInTime, showTime, fadeOutTime);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
* @param message
|
||||
* @param args
|
||||
*/
|
||||
protected void broadcast(Message message, Object... args) {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
message(player, message, args);
|
||||
}
|
||||
message(Bukkit.getConsoleSender(), message, args);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -99,18 +115,101 @@ public abstract class MessageUtils extends LocationUtils {
|
||||
* @param args
|
||||
*/
|
||||
protected void actionMessage(Player player, Message message, Object... args) {
|
||||
ActionBar.sendActionBar(player, String.format(papi(message.msg(), player), args));
|
||||
ActionBar.sendActionBar(player, getMessage(message, args));
|
||||
}
|
||||
|
||||
protected String getMessage(Message message, Object... args) {
|
||||
return getMessage(message.getMessage(), args);
|
||||
}
|
||||
|
||||
protected String getMessage(String message, Object... args) {
|
||||
if (args.length % 2 != 0)
|
||||
System.err.println("Impossible to apply the method for messages.");
|
||||
else
|
||||
for (int a = 0; a < args.length; a += 2) {
|
||||
String replace = args[a].toString();
|
||||
String to = args[a + 1].toString();
|
||||
message = message.replace(replace, to);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
protected final Class<?> getNMSClass(String name) {
|
||||
try {
|
||||
return Class.forName("net.minecraft.server."
|
||||
+ Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3] + "." + name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send title to player
|
||||
*
|
||||
* @param player
|
||||
* @param title
|
||||
* @param subtitle
|
||||
* @param fadeInTime
|
||||
* @param showTime
|
||||
* @param fadeOutTime
|
||||
*/
|
||||
protected void title(Player player, String title, String subtitle, int fadeInTime, int showTime, int fadeOutTime) {
|
||||
|
||||
if (NMSUtils.isNewVersion()) {
|
||||
player.sendTitle(title, subtitle, fadeInTime, showTime, fadeOutTime);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Object chatTitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", String.class)
|
||||
.invoke(null, "{\"text\": \"" + title + "\"}");
|
||||
Constructor<?> titleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(
|
||||
getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"),
|
||||
int.class, int.class, int.class);
|
||||
Object packet = titleConstructor.newInstance(
|
||||
getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TITLE").get(null), chatTitle,
|
||||
fadeInTime, showTime, fadeOutTime);
|
||||
|
||||
Object chatsTitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", String.class)
|
||||
.invoke(null, "{\"text\": \"" + subtitle + "\"}");
|
||||
Constructor<?> timingTitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(
|
||||
getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"),
|
||||
int.class, int.class, int.class);
|
||||
Object timingPacket = timingTitleConstructor.newInstance(
|
||||
getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("SUBTITLE").get(null),
|
||||
chatsTitle, fadeInTime, showTime, fadeOutTime);
|
||||
|
||||
sendPacket(player, packet);
|
||||
sendPacket(player, timingPacket);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
* @param message
|
||||
* @param args
|
||||
* @param packet
|
||||
*/
|
||||
protected final void sendPacket(Player player, Object packet) {
|
||||
try {
|
||||
Object handle = player.getClass().getMethod("getHandle").invoke(player);
|
||||
Object playerConnection = handle.getClass().getField("playerConnection").get(handle);
|
||||
playerConnection.getClass().getMethod("sendPacket", getNMSClass("Packet")).invoke(playerConnection, packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected void broadcastAction(String message) {
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
ActionBar.sendActionBar(player, papi(message, player));
|
||||
}
|
||||
}
|
||||
|
||||
protected void broadcast(String message) {
|
||||
Bukkit.broadcastMessage(Message.PREFIX.msg() + message);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.maxlego08.zkoth.zcore.utils;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
@ -18,13 +17,10 @@ import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ -55,7 +51,6 @@ import fr.maxlego08.zkoth.ZKothPlugin;
|
||||
import fr.maxlego08.zkoth.api.enums.DefaultFontInfo;
|
||||
import fr.maxlego08.zkoth.zcore.ZPlugin;
|
||||
import fr.maxlego08.zkoth.zcore.enums.EnumInventory;
|
||||
import fr.maxlego08.zkoth.zcore.enums.Message;
|
||||
import fr.maxlego08.zkoth.zcore.enums.Permission;
|
||||
import fr.maxlego08.zkoth.zcore.utils.builder.CooldownBuilder;
|
||||
import fr.maxlego08.zkoth.zcore.utils.builder.TimerBuilder;
|
||||
@ -71,7 +66,6 @@ import net.md_5.bungee.api.chat.TextComponent;
|
||||
@SuppressWarnings("deprecation")
|
||||
public abstract class ZUtils extends MessageUtils {
|
||||
|
||||
private static transient List<String> teleportPlayers = new ArrayList<String>();
|
||||
protected transient ZKothPlugin plugin = (ZKothPlugin) ZPlugin.z();
|
||||
|
||||
/**
|
||||
@ -223,70 +217,6 @@ public abstract class ZUtils extends MessageUtils {
|
||||
&& (l.getBlockZ() == l2.getBlockZ()) && l.getWorld().getName().equals(l2.getWorld().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleport a player to a given location with a given delay
|
||||
*
|
||||
* @param player
|
||||
* who will be teleported
|
||||
* @param delay
|
||||
* before the teleportation of the player
|
||||
* @param location
|
||||
* where the player will be teleported
|
||||
*/
|
||||
protected void teleport(Player player, int delay, Location location) {
|
||||
teleport(player, delay, location, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleport a player to a given location with a given delay
|
||||
*
|
||||
* @param player
|
||||
* who will be teleported
|
||||
* @param delay
|
||||
* before the teleportation of the player
|
||||
* @param location
|
||||
* where the player will be teleported
|
||||
* @param code
|
||||
* executed when the player is teleported or not
|
||||
*/
|
||||
protected void teleport(Player player, int delay, Location location, Consumer<Boolean> cmd) {
|
||||
if (teleportPlayers.contains(player.getName())) {
|
||||
message(player, Message.TELEPORT_ERROR);
|
||||
return;
|
||||
}
|
||||
ScheduledExecutorService ses = Executors.newScheduledThreadPool(1);
|
||||
Location playerLocation = player.getLocation();
|
||||
AtomicInteger verif = new AtomicInteger(delay);
|
||||
teleportPlayers.add(player.getName());
|
||||
if (!location.getChunk().isLoaded())
|
||||
location.getChunk().load();
|
||||
ses.scheduleWithFixedDelay(() -> {
|
||||
if (!same(playerLocation, player.getLocation())) {
|
||||
message(player, Message.TELEPORT_MOVE);
|
||||
ses.shutdown();
|
||||
teleportPlayers.remove(player.getName());
|
||||
if (cmd != null)
|
||||
cmd.accept(false);
|
||||
return;
|
||||
}
|
||||
int currentSecond = verif.getAndDecrement();
|
||||
if (!player.isOnline()) {
|
||||
ses.shutdown();
|
||||
teleportPlayers.remove(player.getName());
|
||||
return;
|
||||
}
|
||||
if (currentSecond == 0) {
|
||||
ses.shutdown();
|
||||
teleportPlayers.remove(player.getName());
|
||||
player.teleport(location);
|
||||
message(player, Message.TELEPORT_SUCCESS);
|
||||
if (cmd != null)
|
||||
cmd.accept(true);
|
||||
} else
|
||||
message(player, Message.TELEPORT_MESSAGE, currentSecond);
|
||||
}, 0, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a double in a String
|
||||
*
|
||||
@ -577,6 +507,21 @@ public abstract class ZUtils extends MessageUtils {
|
||||
* @return
|
||||
*/
|
||||
protected String color(String message) {
|
||||
|
||||
if (message == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (NMSUtils.isHexColor()) {
|
||||
Pattern pattern = Pattern.compile("#[a-fA-F0-9]{6}");
|
||||
Matcher matcher = pattern.matcher(message);
|
||||
while (matcher.find()) {
|
||||
String color = message.substring(matcher.start(), matcher.end());
|
||||
message = message.replace(color, net.md_5.bungee.api.ChatColor.of(color) + "");
|
||||
matcher = pattern.matcher(message);
|
||||
}
|
||||
}
|
||||
|
||||
return message.replace("&", "§");
|
||||
}
|
||||
|
||||
@ -1076,75 +1021,6 @@ public abstract class ZUtils extends MessageUtils {
|
||||
return (material.equals(getMaterial(397))) && (itemStack.getDurability() == 3);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* NMS
|
||||
*
|
||||
*/
|
||||
|
||||
protected final void sendPacket(Player player, Object packet) {
|
||||
try {
|
||||
Object handle = player.getClass().getMethod("getHandle").invoke(player);
|
||||
Object playerConnection = handle.getClass().getField("playerConnection").get(handle);
|
||||
playerConnection.getClass().getMethod("sendPacket", getNMSClass("Packet")).invoke(playerConnection, packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected final Class<?> getNMSClass(String name) {
|
||||
try {
|
||||
return Class.forName("net.minecraft.server."
|
||||
+ Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3] + "." + name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send title to player
|
||||
*
|
||||
* @param player
|
||||
* @param title
|
||||
* @param subtitle
|
||||
* @param fadeInTime
|
||||
* @param showTime
|
||||
* @param fadeOutTime
|
||||
*/
|
||||
protected void title(Player player, String title, String subtitle, int fadeInTime, int showTime, int fadeOutTime) {
|
||||
try {
|
||||
|
||||
if (NMSUtils.isNewVersion()){
|
||||
player.sendTitle(title, subtitle, fadeInTime, showTime, fadeOutTime);
|
||||
return;
|
||||
}
|
||||
|
||||
Object chatTitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", String.class)
|
||||
.invoke(null, "{\"text\": \"" + papi(title, player) + "\"}");
|
||||
Constructor<?> titleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(
|
||||
getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"),
|
||||
int.class, int.class, int.class);
|
||||
Object packet = titleConstructor.newInstance(
|
||||
getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TITLE").get(null), chatTitle,
|
||||
fadeInTime, showTime, fadeOutTime);
|
||||
|
||||
Object chatsTitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", String.class)
|
||||
.invoke(null, "{\"text\": \"" + papi(subtitle, player) + "\"}");
|
||||
Constructor<?> timingTitleConstructor = getNMSClass("PacketPlayOutTitle").getConstructor(
|
||||
getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"),
|
||||
int.class, int.class, int.class);
|
||||
Object timingPacket = timingTitleConstructor.newInstance(
|
||||
getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("SUBTITLE").get(null),
|
||||
chatsTitle, fadeInTime, showTime, fadeOutTime);
|
||||
|
||||
sendPacket(player, packet);
|
||||
sendPacket(player, timingPacket);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected Object getPrivateField(Object object, String field)
|
||||
throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
|
||||
Class<?> clazz = object.getClass();
|
||||
|
Loading…
Reference in New Issue
Block a user