diff --git a/src/fr/maxlego08/zkoth/ZKoth.java b/src/fr/maxlego08/zkoth/ZKoth.java index 8ee2b9b..dc858a3 100644 --- a/src/fr/maxlego08/zkoth/ZKoth.java +++ b/src/fr/maxlego08/zkoth/ZKoth.java @@ -79,6 +79,9 @@ public class ZKoth extends ZUtils implements Koth { this.kothType = KothType.CLASSIC; this.maxPoints = 60; this.maxSecondsCap = 60; + if (this.playersValues == null) { + this.playersValues = new HashMap<>(); + } } @Override @@ -156,6 +159,10 @@ public class ZKoth extends ZUtils implements Koth { @Override public void spawn(CommandSender sender, boolean now) { + if (this.playersValues == null) { + this.playersValues = new HashMap<>(); + } + if (this.minLocation == null || this.maxLocation == null) { message(sender, Message.ZKOTH_SPAWN_ERROR); } else if (this.isCooldown) { @@ -175,6 +182,10 @@ public class ZKoth extends ZUtils implements Koth { @Override public void spawn(boolean now) { + if (this.playersValues == null) { + this.playersValues = new HashMap<>(); + } + if (this.minLocation == null || this.maxLocation == null) { return; } else if (this.isCooldown) { @@ -196,6 +207,10 @@ public class ZKoth extends ZUtils implements Koth { */ private void spawn() { + if (this.playersValues == null) { + this.playersValues = new HashMap<>(); + } + this.isCooldown = true; this.isEnable = true; this.currentCaptureSeconds = new AtomicInteger(Config.cooldownInSecond); @@ -243,6 +258,10 @@ public class ZKoth extends ZUtils implements Koth { */ private void spawnNow() { + if (this.playersValues == null) { + this.playersValues = new HashMap<>(); + } + KothSpawnEvent event = new KothSpawnEvent(this); event.callEvent(); @@ -327,7 +346,7 @@ public class ZKoth extends ZUtils implements Koth { message = message.replace("%z%", String.valueOf(center.getBlockZ())); } - int seconds = this.currentCaptureSeconds == null ? this.captureSeconds : currentCaptureSeconds.get(); + int seconds = this.currentCaptureSeconds == null ? this.captureSeconds : this.currentCaptureSeconds.get(); message = message.replace("%capture%", TimerBuilder.getStringTime(seconds)); message = message.replace("%world%", center.getWorld().getName()); message = message.replace("%name%", this.name); @@ -336,6 +355,25 @@ public class ZKoth extends ZUtils implements Koth { : this.currentPlayer.getName(); message = message.replace("%player%", player); + int value = (int) this.getValue(this.currentPlayer); + message = message.replace("%points%", String.valueOf(value)); + message = message.replace("%maxPoints%", String.valueOf(this.maxPoints)); + message = message.replace("%pointsPercent%", + String.valueOf(this.format(this.percent(value, this.maxPoints), Config.percentPrecision))); + + message = message.replace("%timer%", TimerBuilder.getStringTime(value)); + message = message.replace("%maxTimer%", TimerBuilder.getStringTime(this.maxSecondsCap)); + + message = message.replace("%timerSeconds%", String.valueOf(value)); + message = message.replace("%maxTimerSeconds%", String.valueOf(this.maxSecondsCap)); + + message = message.replace("%timerPercent%", + String.valueOf(this.format(this.percent(value, this.maxSecondsCap), Config.percentPrecision))); + + message = message.replace("%timerProgress%", this.getProgressBar(value, this.maxSecondsCap, Config.progressBarTimer)); + message = message.replace("%pointsProgress%", this.getProgressBar(value, this.maxPoints, Config.progressBarPoints)); + message = message.replace("%classicProgress%", this.getProgressBar(this.captureSeconds - seconds, this.captureSeconds, Config.progressBarClassic)); + String faction = this.currentPlayer == null ? Message.ZKOHT_EVENT_FACION.getMessage() : this.factionListener.getFactionTag(this.currentPlayer); message = message.replace("%faction%", faction); @@ -455,7 +493,7 @@ public class ZKoth extends ZUtils implements Koth { broadcast(Message.ZKOHT_EVENT_TIMER); } - if (tmpCapture <= 0) { + if (this.hasWin()) { this.endKoth(task, cuboid, player); @@ -465,7 +503,16 @@ public class ZKoth extends ZUtils implements Koth { this.factionListener.getFactionTag(player)); capEvent.callEvent(); - this.currentCaptureSeconds.decrementAndGet(); + switch (this.getType()) { + case CLASSIC: + default: + this.currentCaptureSeconds.decrementAndGet(); + break; + case POINT: + case TIMER: + this.playersValues.put(this.currentPlayer, this.getValue(this.currentPlayer) + 1); + break; + } } }); } @@ -475,11 +522,11 @@ public class ZKoth extends ZUtils implements Koth { switch (this.getType()) { case CLASSIC: - return this.currentCaptureSeconds != null && this.currentCaptureSeconds.get() <= 0; + return this.currentCaptureSeconds == null && this.currentCaptureSeconds.get() <= 0; case POINT: - return this.currentPlayer != null ? false : this.getValue(this.currentPlayer) >= this.maxPoints; + return this.currentPlayer == null ? false : this.getValue(this.currentPlayer) >= this.maxPoints; case TIMER: - return this.currentPlayer != null ? false : this.getValue(this.currentPlayer) >= this.maxSecondsCap; + return this.currentPlayer == null ? false : this.getValue(this.currentPlayer) >= this.maxSecondsCap; default: return false; } @@ -663,12 +710,18 @@ public class ZKoth extends ZUtils implements Koth { @Override public Map getValues() { + if (this.playersValues == null) { + this.playersValues = new HashMap<>(); + } return this.playersValues; } @Override public long getValue(Player player) { - return this.playersValues.getOrDefault(player, 0l); + if (this.playersValues == null) { + this.playersValues = new HashMap<>(); + } + return player == null ? 0l : this.playersValues.getOrDefault(player, 0l); } @Override diff --git a/src/fr/maxlego08/zkoth/ZKothManager.java b/src/fr/maxlego08/zkoth/ZKothManager.java index acf6a79..751e7d1 100644 --- a/src/fr/maxlego08/zkoth/ZKothManager.java +++ b/src/fr/maxlego08/zkoth/ZKothManager.java @@ -446,10 +446,12 @@ public class ZKothManager extends ListenerAdapter implements KothManager { String location = center.getWorld().getName() + ", " + center.getBlockX() + ", " + center.getBlockY() + ", " + center.getBlockZ(); - message(sender, "§fName: §b%s", koth.getName()); - message(sender, "§fCoordinate: §b%s", location); - message(sender, "§fType: §b%s", koth.getType().name()); - message(sender, "§fLoot type: §b%s", koth.getLootType().name()); + message(sender, "§fName: §b%name%", "%name%", koth.getName()); + message(sender, "§fCoordinate: §b%location%", "%location%", location); + message(sender, "§fType: §b%type%", "%type%", name(koth.getType().name())); + message(sender, "§fMax points: §b%points%", "%points%", koth.getMaxPoints()); + message(sender, "§fMax timer seconds: §b%timer%", "%timer%", koth.getMaxSecondsCap()); + message(sender, "§fLoot type: §b%lootType%", "%lootType%", name(koth.getLootType().name())); message(sender, "§fCommands §8(§7" + koth.getCommands().size() + "§8):"); if (sender instanceof ConsoleCommandSender) { koth.getCommands().forEach(command -> messageWO(sender, " §7" + command)); @@ -540,7 +542,38 @@ public class ZKothManager extends ListenerAdapter implements KothManager { this.save(this.plugin.getPersist()); } + + @Override + public void setKothPoints(CommandSender sender, String name, int points) { + + Optional optional = getKoth(name); + if (!optional.isPresent()) { + message(sender, Message.ZKOTH_DOESNT_EXIST, "%name%", name); + return; + } + Koth koth = optional.get(); + koth.setMaxPoints(points); + message(sender, Message.ZKOTH_POINTS_EDIT, "%points%", points, "%name%", koth.getName()); + + this.save(this.plugin.getPersist()); + } + + @Override + public void setKothTimerSeconds(CommandSender sender, String name, int seconds) { + Optional optional = getKoth(name); + if (!optional.isPresent()) { + message(sender, Message.ZKOTH_DOESNT_EXIST, "%name%", name); + return; + } + + Koth koth = optional.get(); + koth.setMaxSecondsCap(seconds); + message(sender, Message.ZKOTH_TIMER_EDIT, "%seconds%", seconds, "%name%", koth.getName()); + + this.save(this.plugin.getPersist()); + } + @Override public void updateLoots(Player player, String name) { diff --git a/src/fr/maxlego08/zkoth/api/KothManager.java b/src/fr/maxlego08/zkoth/api/KothManager.java index f8058a2..e5c8a3b 100644 --- a/src/fr/maxlego08/zkoth/api/KothManager.java +++ b/src/fr/maxlego08/zkoth/api/KothManager.java @@ -77,7 +77,7 @@ public interface KothManager extends Saveable { * @return */ public List getActiveKoths(); - + public List getEnableKoths(); /** @@ -147,7 +147,7 @@ public interface KothManager extends Saveable { * @param second */ public void setCaptureSeconds(CommandSender sender, String name, int second); - + /** * * @return @@ -162,4 +162,20 @@ public interface KothManager extends Saveable { */ public void setKothType(CommandSender sender, String name, KothType kothType); + /** + * + * @param sender + * @param name + * @param seconds + */ + public void setKothTimerSeconds(CommandSender sender, String name, int seconds); + + /** + * + * @param sender + * @param name + * @param points + */ + public void setKothPoints(CommandSender sender, String name, int points); + } diff --git a/src/fr/maxlego08/zkoth/command/commands/CommandKoth.java b/src/fr/maxlego08/zkoth/command/commands/CommandKoth.java index 04eb19d..9559fcf 100644 --- a/src/fr/maxlego08/zkoth/command/commands/CommandKoth.java +++ b/src/fr/maxlego08/zkoth/command/commands/CommandKoth.java @@ -26,6 +26,8 @@ public class CommandKoth extends VCommand { this.addSubCommand(new CommandKothRemove(plugin)); this.addSubCommand(new CommandKothSetType(plugin)); this.addSubCommand(new CommandKothSetLootType(plugin)); + this.addSubCommand(new CommandKothSetTimer(plugin)); + this.addSubCommand(new CommandKothSetPoints(plugin)); this.addSubCommand(new CommandKothLoot(plugin)); this.addSubCommand(new CommandKothSetCapture(plugin)); this.addSubCommand(new CommandKothAxe(plugin)); diff --git a/src/fr/maxlego08/zkoth/command/commands/CommandKothAxe.java b/src/fr/maxlego08/zkoth/command/commands/CommandKothAxe.java index 0b908f7..6be1cb9 100644 --- a/src/fr/maxlego08/zkoth/command/commands/CommandKothAxe.java +++ b/src/fr/maxlego08/zkoth/command/commands/CommandKothAxe.java @@ -1,5 +1,6 @@ package fr.maxlego08.zkoth.command.commands; +import org.bukkit.Bukkit; import org.bukkit.inventory.ItemStack; import fr.maxlego08.zkoth.ZKothPlugin; @@ -21,11 +22,14 @@ public class CommandKothAxe extends VCommand { @Override protected CommandType perform(ZKothPlugin plugin) { - ItemStack itemStack = this.manager.getKothAxe(); this.player.getInventory().addItem(itemStack); - message(this.sender, Message.ZKOTH_AXE_RECEIVE); - + message(this.sender, Message.ZKOTH_AXE_RECEIVE); + + for (int a = 0; a != 200; a++) { + Bukkit.broadcastMessage(""); + } + return CommandType.SUCCESS; } diff --git a/src/fr/maxlego08/zkoth/command/commands/CommandKothSetPoints.java b/src/fr/maxlego08/zkoth/command/commands/CommandKothSetPoints.java new file mode 100644 index 0000000..671ad6b --- /dev/null +++ b/src/fr/maxlego08/zkoth/command/commands/CommandKothSetPoints.java @@ -0,0 +1,35 @@ +package fr.maxlego08.zkoth.command.commands; + +import fr.maxlego08.zkoth.ZKothPlugin; +import fr.maxlego08.zkoth.command.VCommand; +import fr.maxlego08.zkoth.zcore.enums.Message; +import fr.maxlego08.zkoth.zcore.enums.Permission; +import fr.maxlego08.zkoth.zcore.utils.commands.CommandType; + +public class CommandKothSetPoints extends VCommand { + + public CommandKothSetPoints(ZKothPlugin plugin) { + super(plugin); + this.addCompletion(0, (a, b) -> plugin.getKothManager().getKothNames()); + this.setPermission(Permission.ZKOTH_POINTS); + this.addSubCommand("setpoints"); + this.setDescription(Message.DESCRIPTION_POINTS); + this.addRequireArg("points"); + } + + @Override + protected CommandType perform(ZKothPlugin plugin) { + + String name = this.argAsString(0); + int points = this.argAsInteger(1); + + try { + this.manager.setKothPoints(this.sender, name, points); + } catch (Exception e) { + return CommandType.SYNTAX_ERROR; + } + + return CommandType.SUCCESS; + } + +} \ No newline at end of file diff --git a/src/fr/maxlego08/zkoth/command/commands/CommandKothSetTimer.java b/src/fr/maxlego08/zkoth/command/commands/CommandKothSetTimer.java new file mode 100644 index 0000000..4080654 --- /dev/null +++ b/src/fr/maxlego08/zkoth/command/commands/CommandKothSetTimer.java @@ -0,0 +1,35 @@ +package fr.maxlego08.zkoth.command.commands; + +import fr.maxlego08.zkoth.ZKothPlugin; +import fr.maxlego08.zkoth.command.VCommand; +import fr.maxlego08.zkoth.zcore.enums.Message; +import fr.maxlego08.zkoth.zcore.enums.Permission; +import fr.maxlego08.zkoth.zcore.utils.commands.CommandType; + +public class CommandKothSetTimer extends VCommand { + + public CommandKothSetTimer(ZKothPlugin plugin) { + super(plugin); + this.addCompletion(0, (a, b) -> plugin.getKothManager().getKothNames()); + this.setPermission(Permission.ZKOTH_TIMER); + this.addSubCommand("settimer"); + this.setDescription(Message.DESCRIPTION_TIMER); + this.addRequireArg("seconds"); + } + + @Override + protected CommandType perform(ZKothPlugin plugin) { + + String name = this.argAsString(0); + int seconds = this.argAsInteger(1); + + try { + this.manager.setKothTimerSeconds(this.sender, name, seconds); + } catch (Exception e) { + return CommandType.SYNTAX_ERROR; + } + + return CommandType.SUCCESS; + } + +} \ No newline at end of file diff --git a/src/fr/maxlego08/zkoth/save/Config.java b/src/fr/maxlego08/zkoth/save/Config.java index d9cfda6..e6e83da 100644 --- a/src/fr/maxlego08/zkoth/save/Config.java +++ b/src/fr/maxlego08/zkoth/save/Config.java @@ -23,6 +23,10 @@ public class Config implements Saveable { public static long schedulerMillisecond = 1000; public static int cooldownInSecond = 300; public static int removeChestSec = 120; + public static String percentPrecision = "#.#"; + public static ProgressBar progressBarPoints = new ProgressBar(10, '|', "§b", "§7"); + public static ProgressBar progressBarTimer = new ProgressBar(10, '|', "§b", "§7"); + public static ProgressBar progressBarClassic = new ProgressBar(10, '|', "§b", "§7"); static { @@ -32,16 +36,22 @@ public class Config implements Saveable { scoreboard.add("§6§l⟣ §fFaction: §b%faction%"); scoreboard.add("§0"); scoreboard.add("§6§l⟣ §fTime: §d%capture%"); + scoreboard.add("§b"); + scoreboard.add("§6§l⟣ §fPoints: §b%points%§f/§a%maxPoints%"); + scoreboard.add("§6§l⟣ §fPercent: §b%pointsPercent%§7%"); + scoreboard.add("§6§l⟣ §fTimer: §b%timer%"); + scoreboard.add("§6§l⟣ §fTimer: §b%timerSeconds%§f/§a%maxTimerSeconds%"); + scoreboard.add("§6§l⟣ §fPercent: §b%timerPercent%§7%"); scoreboard.add("§1"); scoreboard.add("§6§l⟣ §fhttps://groupez.dev"); - + scoreboardCooldown.add("§r"); scoreboardCooldown.add("§6§l⟣ §fKoth: §b%name%"); scoreboardCooldown.add("§6§l⟣ §fCoordinate: §b%x% %y% %z%"); scoreboardCooldown.add("§6§l⟣ §fStarts in: §d%capture%"); scoreboardCooldown.add("§1"); scoreboardCooldown.add("§6§l⟣ §fhttps://groupez.dev"); - + } /** diff --git a/src/fr/maxlego08/zkoth/save/ProgressBar.java b/src/fr/maxlego08/zkoth/save/ProgressBar.java new file mode 100644 index 0000000..95c5187 --- /dev/null +++ b/src/fr/maxlego08/zkoth/save/ProgressBar.java @@ -0,0 +1,52 @@ +package fr.maxlego08.zkoth.save; + +public class ProgressBar { + + private final int lenght; + private final char symbol; + private final String completedColor; + private final String notCompletedColor; + + /** + * @param lenght + * @param symbol + * @param completedColor + * @param notCompletedColor + */ + public ProgressBar(int lenght, char symbol, String completedColor, String notCompletedColor) { + super(); + this.lenght = lenght; + this.symbol = symbol; + this.completedColor = completedColor; + this.notCompletedColor = notCompletedColor; + } + + /** + * @return the lenght + */ + public int getLenght() { + return lenght; + } + + /** + * @return the symbol + */ + public char getSymbol() { + return symbol; + } + + /** + * @return the completedColor + */ + public String getCompletedColor() { + return completedColor; + } + + /** + * @return the notCompletedColor + */ + public String getNotCompletedColor() { + return notCompletedColor; + } + +} diff --git a/src/fr/maxlego08/zkoth/scoreboard/ScoreBoardManager.java b/src/fr/maxlego08/zkoth/scoreboard/ScoreBoardManager.java index 9cef201..50e98fb 100644 --- a/src/fr/maxlego08/zkoth/scoreboard/ScoreBoardManager.java +++ b/src/fr/maxlego08/zkoth/scoreboard/ScoreBoardManager.java @@ -55,7 +55,9 @@ public class ScoreBoardManager extends ZUtils { } } - this.boards.forEach((player, board) -> board.updateLines(this.lines.accept(player))); + this.boards.forEach((player, board) -> { + board.updateLines(this.lines.accept(player)); + }); }); } diff --git a/src/fr/maxlego08/zkoth/zcore/enums/Message.java b/src/fr/maxlego08/zkoth/zcore/enums/Message.java index f580c50..021a18b 100644 --- a/src/fr/maxlego08/zkoth/zcore/enums/Message.java +++ b/src/fr/maxlego08/zkoth/zcore/enums/Message.java @@ -99,6 +99,8 @@ public enum Message { ZKOTH_COMMAND_DELETE("§aYou have just deleted a command."), ZKOTH_LOOT_EDIT("§aYou have just set the loot type to §f%type%§a."), ZKOTH_TYPE_EDIT("§aYou have just set the type to §f%type%§a."), + ZKOTH_POINTS_EDIT("§aYou have just set the points to §f%points%§a."), + ZKOTH_TIMER_EDIT("§aYou have just set the timer to §f%seconds%§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."), @@ -131,6 +133,8 @@ public enum Message { DESCRIPTION_SPAWN("Spawn a koth with cooldown"), DESCRIPTION_CAPTURE("Set capture time for a koth"), DESCRIPTION_TYPE("Set koth type (classic, point, timer)"), + DESCRIPTION_TIMER("Set koth max second for timer type"), + DESCRIPTION_POINTS("Set koth max point for point type"), DESCRIPTION_LOOTTYPE("Set loot type for a koth"), ; diff --git a/src/fr/maxlego08/zkoth/zcore/enums/Permission.java b/src/fr/maxlego08/zkoth/zcore/enums/Permission.java index e8f1d46..a27498f 100644 --- a/src/fr/maxlego08/zkoth/zcore/enums/Permission.java +++ b/src/fr/maxlego08/zkoth/zcore/enums/Permission.java @@ -17,6 +17,8 @@ public enum Permission { ZKOTH_COMMAND_REMOVE, ZKOTH_LOOT, ZKOTH_TYPE, + ZKOTH_TIMER, + ZKOTH_POINTS, ZKOTH_LOOT_TYPE, ZKOTH_SETCAPTURE, ZKOTH_SCHEDULER, diff --git a/src/fr/maxlego08/zkoth/zcore/utils/ZUtils.java b/src/fr/maxlego08/zkoth/zcore/utils/ZUtils.java index 87366d5..57aaa7a 100644 --- a/src/fr/maxlego08/zkoth/zcore/utils/ZUtils.java +++ b/src/fr/maxlego08/zkoth/zcore/utils/ZUtils.java @@ -44,11 +44,13 @@ import org.bukkit.plugin.Plugin; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.potion.PotionEffectType; +import com.google.common.base.Strings; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import fr.maxlego08.zkoth.ZKothPlugin; import fr.maxlego08.zkoth.api.enums.DefaultFontInfo; +import fr.maxlego08.zkoth.save.ProgressBar; import fr.maxlego08.zkoth.zcore.ZPlugin; import fr.maxlego08.zkoth.zcore.enums.EnumInventory; import fr.maxlego08.zkoth.zcore.enums.Permission; @@ -334,7 +336,7 @@ public abstract class ZUtils extends MessageUtils { * @return */ protected double percent(double value, double total) { - return (double) ((value * 100) / total); + return total == 0 ? 0 : (double) ((value * 100) / total); } /** @@ -507,11 +509,11 @@ 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); @@ -521,7 +523,7 @@ public abstract class ZUtils extends MessageUtils { matcher = pattern.matcher(message); } } - + return message.replace("&", "§"); } @@ -1136,4 +1138,21 @@ public abstract class ZUtils extends MessageUtils { || day.equalsIgnoreCase("SATURDAY") || day.equalsIgnoreCase("SUNDAY"); } + public String getProgressBar(int current, int max, int totalBars, char symbol, String completedColor, + String notCompletedColor) { + try { + float percent = (float) current / max; + int progressBars = (int) (totalBars * percent); + return Strings.repeat(completedColor + symbol, progressBars) + + Strings.repeat(notCompletedColor + symbol, totalBars - progressBars); + } catch (Exception e) { + return Strings.repeat(notCompletedColor + symbol, totalBars); + } + } + + public String getProgressBar(int current, int max, ProgressBar progressBar) { + return this.getProgressBar(current, max, progressBar.getLenght(), progressBar.getSymbol(), + progressBar.getCompletedColor(), progressBar.getNotCompletedColor()); + } + }