From 0f4c74885a0504ec79324ae1f35f8a314f8ce877 Mon Sep 17 00:00:00 2001 From: Maxlego08 Date: Fri, 8 Mar 2024 14:07:37 +0100 Subject: [PATCH] :memo: Fix errors --- changelog.md | 3 +++ src/fr/maxlego08/koth/KothManager.java | 4 ++++ src/fr/maxlego08/koth/KothPlaceholder.java | 8 ++++---- src/fr/maxlego08/koth/ZKoth.java | 17 +++++++++-------- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/changelog.md b/changelog.md index d8e6ca4..0011d0c 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # Unreleased +- Fix error with discord webhook on stop +- Fix problem with placeholder on koth spawn + # 3.0.3 - Fix NMS diff --git a/src/fr/maxlego08/koth/KothManager.java b/src/fr/maxlego08/koth/KothManager.java index 3e3c875..8226e54 100644 --- a/src/fr/maxlego08/koth/KothManager.java +++ b/src/fr/maxlego08/koth/KothManager.java @@ -170,6 +170,10 @@ public class KothManager extends ZUtils implements Savable { return koths.stream().filter(koth -> koth.getStatus() == KothStatus.COOLDOWN).collect(Collectors.toList()); } + public List getStartKoths() { + return koths.stream().filter(koth -> koth.getStatus() != KothStatus.STOP).collect(Collectors.toList()); + } + public List getNameKoths() { return this.koths.stream().map(Koth::getFileName).collect(Collectors.toList()); } diff --git a/src/fr/maxlego08/koth/KothPlaceholder.java b/src/fr/maxlego08/koth/KothPlaceholder.java index c504fd5..025821f 100644 --- a/src/fr/maxlego08/koth/KothPlaceholder.java +++ b/src/fr/maxlego08/koth/KothPlaceholder.java @@ -94,28 +94,28 @@ public class KothPlaceholder extends ZUtils { } public String onFirstKoth(ReturnConsumer consumer) { - Optional optional = this.kothManager.getActiveKoths().stream().findFirst(); + Optional optional = this.kothManager.getStartKoths().stream().findFirst(); if (optional.isPresent()) { return consumer.accept(optional.get()); } else return Config.noKoth; } public String onFirstKoth(Player player, ReturnBiConsumer consumer) { - Optional optional = this.kothManager.getActiveKoths().stream().findFirst(); + Optional optional = this.kothManager.getStartKoths().stream().findFirst(); if (optional.isPresent()) { return consumer.accept(player, optional.get()); } else return Config.noKoth; } public String onFirstKoth(String argument, ReturnBiConsumer consumer) { - Optional optional = this.kothManager.getActiveKoths().stream().findFirst(); + Optional optional = this.kothManager.getStartKoths().stream().findFirst(); if (optional.isPresent()) { return consumer.accept(argument, optional.get()); } else return Config.noKoth; } public String onFirstKothPosition(String argument, ReturnBiConsumer consumer) { - Optional optional = this.kothManager.getActiveKoths().stream().findFirst(); + Optional optional = this.kothManager.getStartKoths().stream().findFirst(); if (optional.isPresent()) { try { return consumer.accept(Integer.parseInt(argument), optional.get()); diff --git a/src/fr/maxlego08/koth/ZKoth.java b/src/fr/maxlego08/koth/ZKoth.java index bfa8941..230d1e3 100644 --- a/src/fr/maxlego08/koth/ZKoth.java +++ b/src/fr/maxlego08/koth/ZKoth.java @@ -85,7 +85,7 @@ public class ZKoth extends ZUtils implements Koth { private AtomicInteger remainingSeconds; private TimerTask timerTask; private TimerTask timerTaskStop; - private DiscordWebhookConfig discordWebhookConfig; + private final DiscordWebhookConfig discordWebhookConfig; private List playerResults = new ArrayList<>(); public ZKoth(KothPlugin plugin, String fileName, KothType kothType, String name, int captureSeconds, Location minLocation, Location maxLocation, List startCommands, List endCommands, ScoreboardConfiguration cooldownScoreboard, ScoreboardConfiguration startScoreboard, int cooldownStart, int stopAfterSeconds, boolean enableStartCapMessage, boolean enableLooseCapMessage, boolean enableEverySecondsCapMessage, HologramConfig hologramConfig, List itemStacks, KothLootType kothLootType, DiscordWebhookConfig discordWebhookConfig, int randomItemStacks, List blacklistTeamId, ProgressBar progressBar) { @@ -272,7 +272,7 @@ public class ZKoth extends ZUtils implements Koth { event.call(); if (event.isCancelled()) return; - this.discordWebhookConfig.send(this.plugin, this, KothEvent.STOP); + if (this.discordWebhookConfig != null) this.discordWebhookConfig.send(this.plugin, this, KothEvent.STOP); broadcast(Message.EVENT_STOP); @@ -314,7 +314,7 @@ public class ZKoth extends ZUtils implements Koth { if (event.isCancelled()) return; - this.discordWebhookConfig.send(this.plugin, this, KothEvent.START); + if (this.discordWebhookConfig != null) this.discordWebhookConfig.send(this.plugin, this, KothEvent.START); if (this.cooldownScoreboard.isEnable()) { ScoreBoardManager scoreBoardManager = this.plugin.getScoreBoardManager(); @@ -362,7 +362,7 @@ public class ZKoth extends ZUtils implements Koth { event.call(); if (event.isCancelled()) return; - this.discordWebhookConfig.send(this.plugin, this, KothEvent.SPAWN); + if (this.discordWebhookConfig != null) this.discordWebhookConfig.send(this.plugin, this, KothEvent.SPAWN); this.remainingSeconds = new AtomicInteger(this.captureSeconds); @@ -442,7 +442,7 @@ public class ZKoth extends ZUtils implements Koth { KothLooseEvent event = new KothLooseEvent(this.currentPlayer, this); event.call(); - this.discordWebhookConfig.send(this.plugin, this, KothEvent.LOOSE); + if (this.discordWebhookConfig != null) this.discordWebhookConfig.send(this.plugin, this, KothEvent.LOOSE); if (event.isCancelled()) return; @@ -478,7 +478,7 @@ public class ZKoth extends ZUtils implements Koth { return; } - this.discordWebhookConfig.send(this.plugin, this, KothEvent.START_CAP); + if (this.discordWebhookConfig != null) this.discordWebhookConfig.send(this.plugin, this, KothEvent.START_CAP); if (enableStartCapMessage) { broadcast(Message.EVENT_CATCH); @@ -522,7 +522,8 @@ public class ZKoth extends ZUtils implements Koth { if (kothLooseEvent.isCancelled()) return; - this.discordWebhookConfig.send(this.plugin, this, KothEvent.LOOSE); + if (this.discordWebhookConfig != null) + this.discordWebhookConfig.send(this.plugin, this, KothEvent.LOOSE); if (this.timerTask != null) { this.timerTask.cancel(); @@ -581,7 +582,7 @@ public class ZKoth extends ZUtils implements Koth { if (kothWinEvent.isCancelled()) return; - this.discordWebhookConfig.send(this.plugin, this, KothEvent.WIN); + if (this.discordWebhookConfig != null) this.discordWebhookConfig.send(this.plugin, this, KothEvent.WIN); task.cancel(); broadcast(Message.EVENT_WIN);