From 34fcf06159e52fce918a568a18f3aa5c2be6fa6d Mon Sep 17 00:00:00 2001 From: CitralFlo Date: Thu, 3 Oct 2024 20:29:18 +0200 Subject: [PATCH 1/9] Multification setup --- buildSrc/src/main/kotlin/Versions.kt | 2 +- eternalcombat-plugin/build.gradle.kts | 7 +- .../com/eternalcode/combat/CombatPlugin.java | 10 +- .../combat/EternalCombatReloadCommand.java | 15 ++- .../combat/config/ConfigService.java | 15 ++- .../config/implementation/PluginConfig.java | 107 ++++++++++++----- .../combat/fight/FightTagCommand.java | 84 +++++++------ .../eternalcode/combat/fight/FightTask.java | 26 +--- .../combat/fight/bossbar/FightBossBar.java | 9 -- .../fight/bossbar/FightBossBarRegistry.java | 27 ----- .../fight/bossbar/FightBossBarService.java | 112 ------------------ .../FightActionBlockerController.java | 34 ++++-- .../controller/FightMessageController.java | 17 +-- .../combat/fight/logout/LogoutController.java | 11 +- .../fight/pearl/FightPearlController.java | 16 ++- .../fight/pearl/FightPearlSettings.java | 10 +- .../fight/tagout/FightTagOutCommand.java | 57 +++++---- .../handler/InvalidUsageHandlerImpl.java | 11 +- .../handler/MissingPermissionHandlerImpl.java | 23 +++- .../notification/NotificationAnnouncer.java | 78 ++++-------- .../combat/region/RegionController.java | 11 +- 21 files changed, 317 insertions(+), 365 deletions(-) delete mode 100644 eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/bossbar/FightBossBar.java delete mode 100644 eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/bossbar/FightBossBarRegistry.java delete mode 100644 eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/bossbar/FightBossBarService.java diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 22074a2e..76536c18 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -9,7 +9,7 @@ object Versions { const val JETBRAINS_ANNOTATIONS = "24.1.0" const val ETERNALCODE_COMMONS = "1.1.3" - // TODO: Multification. + const val MULTIFICATION = "1.1.3" const val ADVENTURE_PLATFORM_BUKKIT = "4.3.4" const val ADVENTURE_TEXT_MINIMESSAGE = "4.17.0" diff --git a/eternalcombat-plugin/build.gradle.kts b/eternalcombat-plugin/build.gradle.kts index 16039c64..f14ee4bd 100644 --- a/eternalcombat-plugin/build.gradle.kts +++ b/eternalcombat-plugin/build.gradle.kts @@ -45,6 +45,10 @@ dependencies { // PlaceholderAPI compileOnly("me.clip:placeholderapi:${Versions.PLACEHOLDER_API}") + + // Multification + implementation("com.eternalcode:multification-bukkit:${Versions.MULTIFICATION}") + implementation("com.eternalcode:multification-okaeri:${Versions.MULTIFICATION}") } bukkit { @@ -92,7 +96,8 @@ tasks.shadowJar { "org.apache.commons", "javassist", "com.github.benmanes.caffeine", - "com.eternalcode.commons" + "com.eternalcode.commons", + "com.eternalcode.multification" ).forEach { pack -> relocate(pack, "$prefix.$pack") } diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/CombatPlugin.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/CombatPlugin.java index c948ea00..a44f51d7 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/CombatPlugin.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/CombatPlugin.java @@ -25,7 +25,6 @@ import com.eternalcode.combat.event.EventCaller; import com.eternalcode.combat.fight.FightManagerImpl; import com.eternalcode.combat.fight.FightTask; -import com.eternalcode.combat.fight.bossbar.FightBossBarService; import com.eternalcode.combat.fight.effect.FightEffectServiceImpl; import com.eternalcode.combat.fight.logout.LogoutController; import com.eternalcode.combat.fight.logout.LogoutService; @@ -108,13 +107,12 @@ public void onEnable() { .preProcessor(new AdventureLegacyColorPreProcessor()) .build(); - FightBossBarService fightBossBarService = new FightBossBarService(this.pluginConfig, this.audienceProvider, miniMessage); - BridgeService bridgeService = new BridgeService(this.pluginConfig, server.getPluginManager(), this.getLogger(), this); bridgeService.init(this.fightManager, server); this.regionProvider = bridgeService.getRegionProvider(); - NotificationAnnouncer notificationAnnouncer = new NotificationAnnouncer(this.audienceProvider, miniMessage); + + NotificationAnnouncer notificationAnnouncer = new NotificationAnnouncer(this.audienceProvider, this.pluginConfig, miniMessage); this.liteCommands = LiteBukkitFactory.builder(FALLBACK_PREFIX, this, server) .message(LiteBukkitMessages.PLAYER_NOT_FOUND, this.pluginConfig.messages.playerNotFound) @@ -131,7 +129,7 @@ public void onEnable() { .build(); - FightTask fightTask = new FightTask(server, this.pluginConfig, this.fightManager, fightBossBarService, notificationAnnouncer); + FightTask fightTask = new FightTask(server, this.pluginConfig, this.fightManager, notificationAnnouncer); this.getServer().getScheduler().runTaskTimer(this, fightTask, 20L, 20L); new Metrics(this, BSTATS_METRICS_ID); @@ -153,7 +151,7 @@ public void onEnable() { new RegionController(notificationAnnouncer, this.regionProvider, this.fightManager, this.pluginConfig), new FightEffectController(this.pluginConfig.effect, this.fightEffectService, this.fightManager, this.getServer()), new FightTagOutController(this.fightTagOutService), - new FightMessageController(this.fightManager, notificationAnnouncer, fightBossBarService, this.pluginConfig, this.getServer()) + new FightMessageController(this.fightManager, notificationAnnouncer, this.pluginConfig, this.getServer()) ).forEach(listener -> this.getServer().getPluginManager().registerEvents(listener, this)); EternalCombatProvider.initialize(this); diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/EternalCombatReloadCommand.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/EternalCombatReloadCommand.java index 40209b03..7b23d10c 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/EternalCombatReloadCommand.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/EternalCombatReloadCommand.java @@ -2,6 +2,8 @@ import com.eternalcode.combat.config.ConfigService; import com.eternalcode.combat.notification.NotificationAnnouncer; +import com.eternalcode.multification.bukkit.notice.BukkitNotice; +import com.eternalcode.multification.notice.Notice; import com.google.common.base.Stopwatch; import dev.rollczi.litecommands.annotations.async.Async; import dev.rollczi.litecommands.annotations.command.Command; @@ -10,13 +12,14 @@ import dev.rollczi.litecommands.annotations.permission.Permission; import java.time.Duration; import org.bukkit.command.CommandSender; -import panda.utilities.text.Formatter; @Command(name = "combatlog", aliases = "combat") @Permission("eternalcombat.reload") public class EternalCombatReloadCommand { - private static final String RELOAD_MESSAGE = "EternalCombat: Reloaded EternalCombat in {TIME}ms!"; + private static final Notice RELOAD_MESSAGE = BukkitNotice.builder() + .chat("EternalCombat: Reloaded EternalCombat in {TIME}ms!") + .build(); private final ConfigService configService; private final NotificationAnnouncer announcer; @@ -33,7 +36,11 @@ void execute(@Context CommandSender sender) { this.configService.reload(); Duration elapsed = stopwatch.elapsed(); - Formatter format = new Formatter().register("{TIME}", elapsed.toMillis()); - this.announcer.sendMessage(sender, format.format(RELOAD_MESSAGE)); + this.announcer.create() + .viewer(sender) + .notice(RELOAD_MESSAGE) + .placeholder("{TIME}", String.valueOf(elapsed.toMillis())) + .send(); + } } diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/ConfigService.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/ConfigService.java index 53bfb06a..7a556464 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/ConfigService.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/ConfigService.java @@ -1,6 +1,10 @@ package com.eternalcode.combat.config; import com.eternalcode.combat.notification.serializer.NotificationSerializer; +import com.eternalcode.multification.bukkit.notice.resolver.sound.SoundBukkitResolver; +import com.eternalcode.multification.notice.resolver.NoticeResolverDefaults; +import com.eternalcode.multification.notice.resolver.NoticeResolverRegistry; +import com.eternalcode.multification.okaeri.MultificationSerdesPack; import eu.okaeri.configs.ConfigManager; import eu.okaeri.configs.OkaeriConfig; import eu.okaeri.configs.serdes.commons.SerdesCommons; @@ -18,10 +22,13 @@ public class ConfigService { public T create(Class config, File file) { T configFile = ConfigManager.create(config); - configFile.withConfigurer(new YamlBukkitConfigurer(), new SerdesCommons(), new SerdesBukkit()); - configFile.withSerdesPack(registry -> { - registry.register(new NotificationSerializer()); - }); + YamlBukkitConfigurer yamlBukkitConfigurer = new YamlBukkitConfigurer(); + NoticeResolverRegistry noticeRegistry = NoticeResolverDefaults.createRegistry() + .registerResolver(new SoundBukkitResolver()); + + configFile.withConfigurer(yamlBukkitConfigurer, new SerdesCommons(), new SerdesBukkit()); + configFile.withConfigurer(yamlBukkitConfigurer, new MultificationSerdesPack(noticeRegistry)); + configFile.withSerdesPack(registry -> registry.register(new NotificationSerializer())); configFile.withBindFile(file); configFile.withRemoveOrphans(true); diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/implementation/PluginConfig.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/implementation/PluginConfig.java index c4bc3716..dad426c4 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/implementation/PluginConfig.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/implementation/PluginConfig.java @@ -4,11 +4,13 @@ import com.eternalcode.combat.fight.drop.DropSettings; import com.eternalcode.combat.fight.effect.FightEffectSettings; import com.eternalcode.combat.fight.pearl.FightPearlSettings; -import com.eternalcode.combat.notification.Notification; -import com.eternalcode.combat.notification.implementation.ActionBarNotification; +import com.eternalcode.multification.bukkit.notice.BukkitNotice; +import com.eternalcode.multification.notice.Notice; import eu.okaeri.configs.OkaeriConfig; import eu.okaeri.configs.annotation.Comment; import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.SoundCategory; import org.bukkit.entity.EntityType; import org.bukkit.event.entity.EntityDamageEvent; @@ -168,85 +170,136 @@ public static class Messages extends OkaeriConfig { "# BossBar colors: https://javadoc.io/static/net.kyori/adventure-api/4.14.0/net/kyori/adventure/bossbar/BossBar.Color.html", "# BossBar overlays: https://javadoc.io/static/net.kyori/adventure-api/4.14.0/net/kyori/adventure/bossbar/BossBar.Overlay.html" }) - public Notification combatNotification = new ActionBarNotification("&dCombat ends in: &f{TIME}"); + public Notice combatNotification = BukkitNotice.builder() + .actionBar("&dCombat ends in: &f{TIME}") + .sound(Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, 2.0F, 1.0F) + .build(); @Comment("# Message sent when the player does not have permission to perform a command") - public String noPermission = "&cYou don't have permission to perform this command!"; + public Notice noPermission = BukkitNotice.builder() + .chat("&cYou don't have permission to perform this command!") + .build(); @Comment("# Message sent when the specified player could not be found") - public String playerNotFound = "&cThe specified player could not be found!"; + public Notice playerNotFound = BukkitNotice.builder() + .chat("&cThe specified player could not be found!") + .build(); @Comment("# Message sent when the player enters combat") - public String playerTagged = "&cYou are in combat, do not leave the server!"; + public Notice playerTagged = BukkitNotice.builder() + .chat("&cYou are in combat, do not leave the server!") + .build(); @Comment("# Message sent when the player leaves combat") - public String playerUntagged = "&aYou are no longer in combat! You can safely leave the server."; + public Notice playerUntagged = BukkitNotice.builder() + .chat("&aYou are no longer in combat! You can safely leave the server.") + .build(); @Comment("# This is broadcast when the player is in combat and logs out") - public String playerLoggedOutDuringCombat = "&c{PLAYER} logged off during the fight!"; + public Notice playerLoggedOutDuringCombat = BukkitNotice.builder() + .chat("&c{PLAYER} logged off during the fight!") + .build(); @Comment({ "# Message sent when the player is in combat and tries to use a disabled command", "# you can configure the list of disabled commands in the blockedCommands section of the config.yml file" }) - public String commandDisabledDuringCombat = "&cUsing this command during combat is prohibited!"; + public Notice commandDisabledDuringCombat = BukkitNotice.builder() + .chat("&cUsing this command during combat is prohibited!") + .build(); @Comment("# Message sent when player tries to use a command with invalid arguments") - public String invalidCommandUsage = "&7Correct usage: &e{USAGE}"; + public Notice invalidCommandUsage = BukkitNotice.builder() + .chat("&7Correct usage: &e{USAGE}") + .build(); @Comment("# Message sent when player tries to open inventory, but the inventory open is blocked") - public String inventoryBlockedDuringCombat = "&cYou cannot open this inventory during combat!"; + public Notice inventoryBlockedDuringCombat = BukkitNotice.builder() + .chat("&cYou cannot open this inventory during combat!") + .build(); @Comment({"# Message sent when player tries to place a block, but the block place is blocked", "# Placeholder {Y} is replaced with the Y coordinate set in the config", "# Placeholder {MODE} is replaced with the mode set in the config"}) - public String blockPlacingBlockedDuringCombat = "&cYou cannot place {MODE} {Y} coordinate during combat!"; + public Notice blockPlacingBlockedDuringCombat = BukkitNotice.builder() + .chat("&cYou cannot place {MODE} {Y} coordinate during combat!") + .build(); @Comment("# Message sent when player tries to enter a region") - public String cantEnterOnRegion = "&cYou can't enter this region during combat!"; + public Notice cantEnterOnRegion = BukkitNotice.builder() + .chat("&cYou can't enter this region during combat!") + .build(); public static class AdminMessages extends OkaeriConfig { @Comment("# Message sent when console tries to use a command that is only for players") - public String onlyForPlayers = "&cThis command is only available to players!"; + public Notice onlyForPlayers = BukkitNotice.builder() + .chat("&cThis command is only available to players!") + .build(); @Comment("# Message sent to admin when they tag a player") - public String adminTagPlayer = "&7You have tagged &e{PLAYER}"; + public Notice adminTagPlayer = BukkitNotice.builder() + .chat("&7You have tagged &e{PLAYER}") + .build(); @Comment("# Message sent when a player is tagged by an admin") - public String adminTagMultiplePlayers = "&7You have tagged &e{FIRST_PLAYER}&7 and &e{SECOND_PLAYER}&7."; + public Notice adminTagMultiplePlayers = BukkitNotice.builder() + .chat("&7You have tagged &e{FIRST_PLAYER}&7 and &e{SECOND_PLAYER}&7.") + .build(); @Comment("# Message sent to admin when they remove a player from combat") - public String adminUntagPlayer = "&7You have removed &e{PLAYER}&7 from the fight."; + public Notice adminUntagPlayer = BukkitNotice.builder() + .chat("&7You have removed &e{PLAYER}&7 from the fight.") + .build(); @Comment("# Message sent when the player is not in combat") - public String adminPlayerNotInCombat = "&cThis player is not in combat!"; + public Notice adminPlayerNotInCombat = BukkitNotice.builder() + .chat("&cThis player is not in combat!") + .build(); @Comment("# Message sent when the player is in combat") - public String playerInCombat = "&c{PLAYER} is currently in combat!"; + public Notice playerInCombat = BukkitNotice.builder() + .chat("&c{PLAYER} is currently in combat!") + .build(); @Comment("# Message sent when a player is not in combat") - public String playerNotInCombat = "&a{PLAYER} is not currently in combat."; + public Notice playerNotInCombat = BukkitNotice.builder() + .chat("&a{PLAYER} is not currently in combat.") + .build(); @Comment("# Message sent when an admin tries to tag themselves") - public String adminCannotTagSelf = "&cYou cannot tag yourself!"; + public Notice adminCannotTagSelf = BukkitNotice.builder() + .chat("&cYou cannot tag yourself!") + .build(); @Comment("# Message sent when an admin disables the ability to get tagged for some time") - public String adminTagOutSelf = "&7Successfully disabled tag for Yourself! You will be taggable after &e{TIME} "; + public Notice adminTagOutSelf = BukkitNotice.builder() + .chat("&7Successfully disabled tag for Yourself! You will be taggable after &e{TIME} ") + .build(); @Comment("# Message sent when an admin disables the ability to get tagged for some time for other player") - public String adminTagOut = "&7Successfully disabled tag for &e{PLAYER}! They will be taggable after &e{TIME} "; + public Notice adminTagOut = BukkitNotice.builder() + .chat("&7Successfully disabled tag for &e{PLAYER}! They will be taggable after &e{TIME} ") + .build(); @Comment("# Message sent to the player whom the ability to get tagged for some time has been disabled") - public String playerTagOut = "&7You will be taggable in &e{TIME} !"; + public Notice playerTagOut = BukkitNotice.builder() + .chat("&7You will be taggable in &e{TIME} !") + .build(); @Comment("# Message sent when an admin reenables the ability to get tagged for the player") - public String adminTagOutOff = "&7Successfully enabled tag for &e{PLAYER}!"; + public Notice adminTagOutOff = BukkitNotice.builder() + .chat("&7Successfully enabled tag for &e{PLAYER}!") + .build(); @Comment("# Message sent to the player whom the ability to get tagged has been reenabled") - public String playerTagOutOff = "&7You are now taggable!"; + public Notice playerTagOutOff = BukkitNotice.builder() + .chat("&7You are now taggable!") + .build(); @Comment("# Message sent when player cannot be tagged because they have enabled tag-out") - public String adminTagOutCanceled = "&cCannot tag this player due to tag-out!"; + public Notice adminTagOutCanceled = BukkitNotice.builder() + .chat("&cCannot tag this player due to tag-out!") + .build(); } } } diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTagCommand.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTagCommand.java index 6fe5b198..a2dfc55e 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTagCommand.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTagCommand.java @@ -16,7 +16,6 @@ import java.util.UUID; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import panda.utilities.text.Formatter; @Command(name = "combatlog", aliases = "combat") public class FightTagCommand { @@ -35,40 +34,44 @@ public FightTagCommand(FightManager fightManager, NotificationAnnouncer announce @Permission("eternalcombat.status") void status(@Context CommandSender sender, @Arg Player target) { UUID targetUniqueId = target.getUniqueId(); - PluginConfig.Messages messages = this.config.messages; - Formatter formatter = new Formatter() - .register("{PLAYER}", target.getName()); + this.announcer.create() + .notice(this.fightManager.isInCombat(targetUniqueId) + ? this.config.messages.admin.playerInCombat + : this.config.messages.admin.playerNotInCombat + ) + .placeholder("{PLAYER}", target.getName()) + .viewer(sender) + .send(); - this.announcer.sendMessage(sender, this.fightManager.isInCombat(targetUniqueId) - ? formatter.format(messages.admin.playerInCombat) - : formatter.format(messages.admin.playerNotInCombat)); } @Execute(name = "tag") @Permission("eternalcombat.tag") void tag(@Context CommandSender sender, @Arg Player target) { - UUID targetUniqueId = target.getUniqueId(); + UUID targetUniqueId = target.getUniqueId(); Duration time = this.config.settings.combatDuration; - Formatter formatter = new Formatter() - .register("{PLAYER}", target.getName()); - FightTagEvent event = this.fightManager.tag(targetUniqueId, time, CauseOfTag.COMMAND); if (event.isCancelled()) { CancelTagReason cancelReason = event.getCancelReason(); if (cancelReason == CancelTagReason.TAGOUT) { - this.announcer.sendMessage(sender, this.config.messages.admin.adminTagOutCanceled); - return; + this.announcer.create() + .notice(this.config.messages.admin.adminTagOutCanceled) + .viewer(sender) + .send(); } return; } - String format = formatter.format(this.config.messages.admin.adminTagPlayer); - this.announcer.sendMessage(sender, format); + this.announcer.create() + .notice(this.config.messages.admin.adminTagPlayer) + .viewer(sender) + .send(); + } @Execute(name = "tag") @@ -76,27 +79,28 @@ void tag(@Context CommandSender sender, @Arg Player target) { void tagMultiple(@Context CommandSender sender, @Arg Player firstTarget, @Arg Player secondTarget) { Duration combatTime = this.config.settings.combatDuration; PluginConfig.Messages messages = this.config.messages; - + if (sender.equals(firstTarget) || sender.equals(secondTarget)) { - this.announcer.sendMessage(sender, messages.admin.adminCannotTagSelf); + + this.announcer.create() + .notice(messages.admin.adminCannotTagSelf) + .viewer(sender) + .send(); + return; } FightTagEvent firstTagEvent = this.fightManager.tag(firstTarget.getUniqueId(), combatTime, CauseOfTag.COMMAND); FightTagEvent secondTagEvent = this.fightManager.tag(secondTarget.getUniqueId(), combatTime, CauseOfTag.COMMAND); - Formatter formatter = new Formatter() - .register("{FIRST_PLAYER}", firstTarget.getName()) - .register("{SECOND_PLAYER}", secondTarget.getName()); - - String format = formatter.format(messages.admin.adminTagMultiplePlayers); - if (firstTagEvent.isCancelled()) { CancelTagReason cancelReason = firstTagEvent.getCancelReason(); if (cancelReason == CancelTagReason.TAGOUT) { - this.announcer.sendMessage(sender, this.config.messages.admin.adminTagOutCanceled); - return; + this.announcer.create() + .notice(messages.admin.adminTagOutCanceled) + .send(); + } return; @@ -106,8 +110,11 @@ void tagMultiple(@Context CommandSender sender, @Arg Player firstTarget, @Arg Pl CancelTagReason cancelReason = secondTagEvent.getCancelReason(); if (cancelReason == CancelTagReason.TAGOUT) { - this.announcer.sendMessage(sender, this.config.messages.admin.adminTagOutCanceled); - return; + this.announcer.create() + .notice(messages.admin.adminTagOutCanceled) + .viewer(sender) + .send(); + } return; @@ -117,7 +124,13 @@ void tagMultiple(@Context CommandSender sender, @Arg Player firstTarget, @Arg Pl return; } - this.announcer.sendMessage(sender, format); + this.announcer.create() + .notice(messages.admin.adminTagMultiplePlayers) + .placeholder("{FIRST_PLAYER}", firstTarget.getName()) + .placeholder("{SECOND_PLAYER}", secondTarget.getName()) + .viewer(sender) + .send(); + } @Execute(name = "untag") @@ -126,7 +139,10 @@ void untag(@Context Player sender, @Arg Player target) { UUID targetUniqueId = target.getUniqueId(); if (!this.fightManager.isInCombat(targetUniqueId)) { - this.announcer.sendMessage(sender, this.config.messages.admin.adminPlayerNotInCombat); + this.announcer.create() + .viewer(sender) + .notice(this.config.messages.admin.adminPlayerNotInCombat) + .send(); return; } @@ -135,11 +151,11 @@ void untag(@Context Player sender, @Arg Player target) { return; } - Formatter formatter = new Formatter() - .register("{PLAYER}", target.getName()); - - String format = formatter.format(this.config.messages.admin.adminUntagPlayer); - this.announcer.sendMessage(sender, format); + this.announcer.create() + .notice(this.config.messages.admin.adminUntagPlayer) + .placeholder("{PLAYER}", target.getName()) + .viewer(sender) + .send(); } } diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTask.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTask.java index 0ffe7bd9..67f5db47 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTask.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTask.java @@ -1,15 +1,11 @@ package com.eternalcode.combat.fight; import com.eternalcode.combat.config.implementation.PluginConfig; -import com.eternalcode.combat.fight.bossbar.FightBossBarService; import com.eternalcode.combat.fight.event.CauseOfUnTag; -import com.eternalcode.combat.notification.Notification; import com.eternalcode.combat.notification.NotificationAnnouncer; -import com.eternalcode.combat.notification.implementation.BossBarNotification; import com.eternalcode.combat.util.DurationUtil; import org.bukkit.Server; import org.bukkit.entity.Player; -import panda.utilities.text.Formatter; import java.time.Duration; import java.util.UUID; @@ -19,14 +15,12 @@ public class FightTask implements Runnable { private final Server server; private final PluginConfig config; private final FightManager fightManager; - private final FightBossBarService bossBarService; private final NotificationAnnouncer announcer; - public FightTask(Server server, PluginConfig config, FightManager fightManager, FightBossBarService bossBarService, NotificationAnnouncer announcer) { + public FightTask(Server server, PluginConfig config, FightManager fightManager, NotificationAnnouncer announcer) { this.server = server; this.config = config; this.fightManager = fightManager; - this.bossBarService = bossBarService; this.announcer = announcer; } @@ -47,21 +41,13 @@ public void run() { } Duration remaining = fightTag.getRemainingDuration(); - Formatter formatter = new Formatter() - .register("{TIME}", DurationUtil.format(remaining)); - Notification combatNotification = this.config.messages.combatNotification; + this.announcer.create() + .player(player.getUniqueId()) + .notice(this.config.messages.combatNotification) + .placeholder("{TIME}", DurationUtil.format(remaining)) + .send(); - this.sendFightNotification(player, fightTag, combatNotification, formatter); } } - - private void sendFightNotification(Player player, FightTag fightTag, Notification notification, Formatter formatter) { - if (notification instanceof BossBarNotification bossBarNotification) { - this.bossBarService.send(player, fightTag, bossBarNotification, formatter); - return; - } - - this.announcer.send(player, notification, formatter); - } } diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/bossbar/FightBossBar.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/bossbar/FightBossBar.java deleted file mode 100644 index 430cca22..00000000 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/bossbar/FightBossBar.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.eternalcode.combat.fight.bossbar; - -import net.kyori.adventure.audience.Audience; -import net.kyori.adventure.bossbar.BossBar; - -import java.time.Duration; - -public record FightBossBar(Audience audience, BossBar bossBar, float progress, Duration combatDuration) { -} diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/bossbar/FightBossBarRegistry.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/bossbar/FightBossBarRegistry.java deleted file mode 100644 index b113a317..00000000 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/bossbar/FightBossBarRegistry.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.eternalcode.combat.fight.bossbar; - -import java.util.Map; -import java.util.Optional; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; - -class FightBossBarRegistry { - - private final Map fightBossBars = new ConcurrentHashMap<>(); - - void add(UUID uuid, FightBossBar fightBossBar) { - this.fightBossBars.put(uuid, fightBossBar); - } - - void remove(UUID uuid) { - this.fightBossBars.remove(uuid); - } - - boolean hasFightBossBar(UUID uuid) { - return this.fightBossBars.containsKey(uuid); - } - - Optional getFightBossBar(UUID uuid) { - return Optional.ofNullable(this.fightBossBars.get(uuid)); - } -} diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/bossbar/FightBossBarService.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/bossbar/FightBossBarService.java deleted file mode 100644 index e7fcb6de..00000000 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/bossbar/FightBossBarService.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.eternalcode.combat.fight.bossbar; - -import com.eternalcode.combat.config.implementation.PluginConfig; -import com.eternalcode.combat.fight.FightTag; -import com.eternalcode.combat.notification.implementation.BossBarNotification; -import net.kyori.adventure.audience.Audience; -import net.kyori.adventure.bossbar.BossBar; -import net.kyori.adventure.platform.AudienceProvider; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.minimessage.MiniMessage; -import org.bukkit.entity.Player; -import panda.utilities.text.Formatter; - -import java.time.Duration; -import java.util.Optional; -import java.util.UUID; - -public class FightBossBarService { - - private final PluginConfig pluginConfig; - private final FightBossBarRegistry bossBarRegistry = new FightBossBarRegistry(); - private final AudienceProvider audienceProvider; - private final MiniMessage miniMessage; - - public FightBossBarService(PluginConfig pluginConfig, AudienceProvider audienceProvider, MiniMessage miniMessage) { - this.pluginConfig = pluginConfig; - this.audienceProvider = audienceProvider; - this.miniMessage = miniMessage; - } - - public void hide(FightTag fightTag, FightBossBar fightBossBar) { - Audience audience = fightBossBar.audience(); - BossBar bossBar = fightBossBar.bossBar(); - UUID taggedPlayer = fightTag.getTaggedPlayer(); - - audience.hideBossBar(bossBar); - this.bossBarRegistry.remove(taggedPlayer); - } - - public void hide(UUID playerUuid) { - Optional bossBar = this.bossBarRegistry.getFightBossBar(playerUuid); - - if (bossBar.isPresent()) { - FightBossBar fightBossBar = bossBar.get(); - Audience audience = fightBossBar.audience(); - BossBar bar = fightBossBar.bossBar(); - - audience.hideBossBar(bar); - this.bossBarRegistry.remove(playerUuid); - } - } - - public void send(Player player, FightTag fightTag, BossBarNotification bossBarNotification, Formatter formatter) { - UUID playerUniqueId = player.getUniqueId(); - - FightBossBar fightBossBar = this.bossBarRegistry.getFightBossBar(playerUniqueId) - .orElseGet(() -> this.create(player, bossBarNotification, formatter)); - - if (!this.bossBarRegistry.hasFightBossBar(playerUniqueId)) { - this.show(player, fightBossBar); - return; - } - - String message = formatter.format(bossBarNotification.message()); - - this.update(fightTag, fightBossBar, message); - } - - private void update(FightTag fightTag, FightBossBar fightBossBar, String message) { - if (fightTag.isExpired()) { - this.hide(fightTag, fightBossBar); - return; - } - - BossBar bossBar = fightBossBar.bossBar(); - - long combatDurationMillis = this.pluginConfig.settings.combatDuration.toMillis(); - long remainingDurationMillis = fightTag.getRemainingDuration().toMillis(); - - float progress = (float) remainingDurationMillis / combatDurationMillis; - - if (progress > 1.0F) { - progress = 1.0F; - } - - Component name = this.miniMessage.deserialize(message); - bossBar.name(name); - bossBar.progress(progress); - } - - private void show(Player player, FightBossBar fightBossBar) { - UUID playerUniqueId = player.getUniqueId(); - - Audience audience = this.audienceProvider.player(playerUniqueId); - BossBar bossBar = fightBossBar.bossBar(); - - audience.showBossBar(bossBar); - this.bossBarRegistry.add(playerUniqueId, fightBossBar); - } - - private FightBossBar create(Player player, BossBarNotification bossBarNotification, Formatter formatter) { - Audience audience = this.audienceProvider.player(player.getUniqueId()); - - Component name = this.miniMessage.deserialize(formatter.format(bossBarNotification.message())); - BossBar bossBar = bossBarNotification.create(name); - - float progress = bossBarNotification.progress(); - Duration combatDuration = this.pluginConfig.settings.combatDuration; - - return new FightBossBar(audience, bossBar, progress, combatDuration); - } -} diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/controller/FightActionBlockerController.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/controller/FightActionBlockerController.java index ff3b7459..8d987754 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/controller/FightActionBlockerController.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/controller/FightActionBlockerController.java @@ -18,7 +18,6 @@ import java.util.List; import java.util.UUID; -import panda.utilities.text.Formatter; public class FightActionBlockerController implements Listener { @@ -52,20 +51,29 @@ void onPlace(BlockPlaceEvent event) { boolean isPlacementBlocked = this.isPlacementBlocked(level); - Formatter formatter = new Formatter() - .register("{Y}", this.config.settings.blockPlacingYCoordinate) - .register("{MODE}", this.config.settings.blockPlacingModeName); - if (isPlacementBlocked && specificBlocksToPreventPlacing.isEmpty()) { event.setCancelled(true); - this.announcer.sendMessage(player, formatter.format(this.config.messages.blockPlacingBlockedDuringCombat)); + this.announcer.create() + .player(uniqueId) + .notice(this.config.messages.blockPlacingBlockedDuringCombat) + .placeholder("{Y}", String.valueOf(this.config.settings.blockPlacingYCoordinate)) + .placeholder("{MODE}", this.config.settings.blockPlacingModeName) + .send(); + } Material blockMaterial = block.getType(); boolean isBlockInDisabledList = specificBlocksToPreventPlacing.contains(blockMaterial); if (isPlacementBlocked && isBlockInDisabledList) { event.setCancelled(true); - this.announcer.sendMessage(player, formatter.format(this.config.messages.blockPlacingBlockedDuringCombat)); + + this.announcer.create() + .player(uniqueId) + .notice(this.config.messages.blockPlacingBlockedDuringCombat) + .placeholder("{Y}", String.valueOf(this.config.settings.blockPlacingYCoordinate)) + .placeholder("{MODE}", this.config.settings.blockPlacingModeName) + .send(); + } } @@ -146,7 +154,11 @@ void onOpenInventory(InventoryOpenEvent event) { event.setCancelled(true); - this.announcer.sendMessage(player, this.config.messages.inventoryBlockedDuringCombat); + this.announcer.create() + .player(uniqueId) + .notice(this.config.messages.inventoryBlockedDuringCombat) + .send(); + } @EventHandler @@ -169,7 +181,11 @@ void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { if (shouldCancel) { event.setCancelled(true); - this.announcer.sendMessage(player, this.config.messages.commandDisabledDuringCombat); + this.announcer.create() + .player(playerUniqueId) + .notice(this.config.messages.commandDisabledDuringCombat) + .send(); + } } } diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/controller/FightMessageController.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/controller/FightMessageController.java index 99d5af57..c66566cd 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/controller/FightMessageController.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/controller/FightMessageController.java @@ -2,7 +2,6 @@ import com.eternalcode.combat.config.implementation.PluginConfig; import com.eternalcode.combat.fight.FightManager; -import com.eternalcode.combat.fight.bossbar.FightBossBarService; import com.eternalcode.combat.fight.event.FightTagEvent; import com.eternalcode.combat.fight.event.FightUntagEvent; import com.eternalcode.combat.notification.NotificationAnnouncer; @@ -16,14 +15,12 @@ public class FightMessageController implements Listener { private final FightManager fightManager; private final NotificationAnnouncer announcer; - private final FightBossBarService bossBarService; private final PluginConfig config; private final Server server; - public FightMessageController(FightManager fightManager, NotificationAnnouncer announcer, FightBossBarService bossBarService, PluginConfig config, Server server) { + public FightMessageController(FightManager fightManager, NotificationAnnouncer announcer, PluginConfig config, Server server) { this.fightManager = fightManager; this.announcer = announcer; - this.bossBarService = bossBarService; this.config = config; this.server = server; } @@ -40,7 +37,10 @@ void onTag(FightTagEvent event) { return; } - this.announcer.sendMessage(player, this.config.messages.playerTagged); + this.announcer.create() + .player(player.getUniqueId()) + .notice(this.config.messages.playerTagged) + .send(); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @@ -51,7 +51,10 @@ void onUnTag(FightUntagEvent event) { throw new IllegalStateException("Player cannot be null!"); } - this.announcer.sendMessage(player, this.config.messages.playerUntagged); - this.bossBarService.hide(event.getPlayer()); + this.announcer.create() + .player(player.getUniqueId()) + .notice(this.config.messages.playerUntagged) + .send(); + } } diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/logout/LogoutController.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/logout/LogoutController.java index c870fa38..2ae7aff6 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/logout/LogoutController.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/logout/LogoutController.java @@ -8,7 +8,6 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; -import panda.utilities.text.Formatter; public class LogoutController implements Listener { @@ -36,11 +35,11 @@ void onQuit(PlayerQuitEvent event) { this.logoutService.punishForLogout(player); player.setHealth(0.0); - Formatter formatter = new Formatter() - .register("{PLAYER}", player.getName()); - - String format = formatter.format(this.config.messages.playerLoggedOutDuringCombat); - this.announcer.broadcast(format); + this.announcer.create() + .notice(this.config.messages.playerLoggedOutDuringCombat) + .placeholder("{PLAYER}", player.getName()) + .onlinePlayers() + .send(); } diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/pearl/FightPearlController.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/pearl/FightPearlController.java index 8343bc24..52d98222 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/pearl/FightPearlController.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/pearl/FightPearlController.java @@ -14,7 +14,6 @@ import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; -import panda.utilities.text.Formatter; import java.time.Duration; import java.util.UUID; @@ -58,7 +57,11 @@ void onInteract(PlayerInteractEvent event) { if (this.settings.pearlThrowDelay.isZero()) { event.setCancelled(true); - this.announcer.sendMessage(player, this.settings.pearlThrowBlockedDuringCombat); + this.announcer.create() + .player(uniqueId) + .notice(this.settings.pearlThrowBlockedDuringCombat) + .send(); + return; } @@ -67,11 +70,12 @@ void onInteract(PlayerInteractEvent event) { Duration remainingPearlDelay = this.fightPearlService.getRemainingDelay(uniqueId); - Formatter formatter = new Formatter() - .register("{TIME}", DurationUtil.format(remainingPearlDelay)); + this.announcer.create() + .player(uniqueId) + .notice(this.settings.pearlThrowBlockedDelayDuringCombat) + .placeholder("{TIME}", DurationUtil.format(remainingPearlDelay)) + .send(); - String format = formatter.format(this.settings.pearlThrowBlockedDelayDuringCombat); - this.announcer.sendMessage(player, format); return; } diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/pearl/FightPearlSettings.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/pearl/FightPearlSettings.java index 62fa6e04..b607f775 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/pearl/FightPearlSettings.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/pearl/FightPearlSettings.java @@ -1,5 +1,7 @@ package com.eternalcode.combat.fight.pearl; +import com.eternalcode.multification.bukkit.notice.BukkitNotice; +import com.eternalcode.multification.notice.Notice; import eu.okaeri.configs.OkaeriConfig; import eu.okaeri.configs.annotation.Comment; @@ -21,9 +23,13 @@ public class FightPearlSettings extends OkaeriConfig { public Duration pearlThrowDelay = Duration.ofSeconds(3); @Comment("# Message sent when player tries to throw ender pearl, but are disabled") - public String pearlThrowBlockedDuringCombat = "&cThrowing ender pearls is prohibited during combat!"; + public Notice pearlThrowBlockedDuringCombat = BukkitNotice.builder() + .chat("&cThrowing ender pearls is prohibited during combat!") + .build(); @Comment("# Message sent when player tries to throw ender pearl, but has delay") - public String pearlThrowBlockedDelayDuringCombat = "&cYou must wait {TIME} before next throw!"; + public Notice pearlThrowBlockedDelayDuringCombat = BukkitNotice.builder() + .chat("&cYou must wait {TIME} before next throw!") + .build(); } diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/tagout/FightTagOutCommand.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/tagout/FightTagOutCommand.java index f9654786..ed7b4b87 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/tagout/FightTagOutCommand.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/tagout/FightTagOutCommand.java @@ -9,10 +9,8 @@ import dev.rollczi.litecommands.annotations.execute.Execute; import dev.rollczi.litecommands.annotations.permission.Permission; import java.time.Duration; -import java.time.Instant; import java.util.UUID; import org.bukkit.entity.Player; -import panda.utilities.text.Formatter; @Command(name = "tagout", aliases = "tagimmunity") public class FightTagOutCommand { @@ -36,14 +34,14 @@ public FightTagOutCommand( void tagout(@Context Player sender, @Arg Duration time) { UUID targetUniqueId = sender.getUniqueId(); - Formatter formatter = new Formatter() - .register("{PLAYER}", sender.getName()) - .register("{TIME}", DurationUtil.format(time)); - this.fightTagOutService.tagOut(targetUniqueId, time); - String format = formatter.format(this.config.messages.admin.adminTagOutSelf); - this.announcer.sendMessage(sender, format); + this.announcer.create() + .notice(this.config.messages.admin.adminTagOutSelf) + .placeholder("{TIME}", DurationUtil.format(time)) + .viewer(sender) + .send(); + } @Execute @@ -51,20 +49,21 @@ void tagout(@Context Player sender, @Arg Duration time) { void tagout(@Context Player sender, @Arg Player target, @Arg Duration time) { UUID targetUniqueId = target.getUniqueId(); - Instant now = Instant.now(); - Duration remaining = Duration.between(now, now.plus(time)); - - Formatter formatter = new Formatter() - .register("{PLAYER}", target.getName()) - .register("{TIME}", DurationUtil.format(remaining)); - this.fightTagOutService.tagOut(targetUniqueId, time); - String adminTagOutFormat = formatter.format(this.config.messages.admin.adminTagOut); - this.announcer.sendMessage(sender, adminTagOutFormat); + this.announcer.create() + .notice(this.config.messages.admin.adminTagOut) + .placeholder("{PLAYER}", target.getName()) + .placeholder("{TIME}", DurationUtil.format(time)) + .viewer(sender) + .send(); + + this.announcer.create() + .notice(this.config.messages.admin.playerTagOut) + .placeholder("{TIME}", DurationUtil.format(time)) + .player(target.getUniqueId()) + .send(); - String playerTagOutFormat = formatter.format(this.config.messages.admin.playerTagOut); - this.announcer.sendMessage(target, playerTagOutFormat); } @Execute(name = "remove") @@ -74,15 +73,19 @@ void untagout(@Context Player sender, @Arg Player target) { this.fightTagOutService.unTagOut(targetUniqueId); - Formatter formatter = new Formatter() - .register("{PLAYER}", target.getName()); if (!targetUniqueId.equals(sender.getUniqueId())) { - String adminUnTagOutFormat = formatter.format(this.config.messages.admin.adminTagOutOff); - this.announcer.sendMessage(sender, adminUnTagOutFormat); + this.announcer.create() + .notice(this.config.messages.admin.adminTagOutOff) + .placeholder("{PLAYER}", target.getName()) + .viewer(sender) + .send(); } - this.announcer.sendMessage(target, this.config.messages.admin.playerTagOutOff); + this.announcer.create() + .notice(this.config.messages.admin.playerTagOutOff) + .player(targetUniqueId) + .send(); } @Execute(name = "remove") @@ -92,7 +95,11 @@ void untagout(@Context Player sender) { this.fightTagOutService.unTagOut(senderUniqueId); - this.announcer.sendMessage(sender, this.config.messages.admin.playerTagOutOff); + this.announcer.create() + .notice(this.config.messages.admin.playerTagOutOff) + .viewer(sender) + .send(); + } } diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/handler/InvalidUsageHandlerImpl.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/handler/InvalidUsageHandlerImpl.java index a9546f74..5600748c 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/handler/InvalidUsageHandlerImpl.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/handler/InvalidUsageHandlerImpl.java @@ -8,7 +8,6 @@ import dev.rollczi.litecommands.invocation.Invocation; import dev.rollczi.litecommands.schematic.Schematic; import org.bukkit.command.CommandSender; -import panda.utilities.text.Formatter; public class InvalidUsageHandlerImpl implements InvalidUsageHandler { @@ -29,10 +28,12 @@ public void handle( Schematic schematic = commandSenderInvalidUsage.getSchematic(); for (String usage : schematic.all()) { - Formatter formatter = new Formatter() - .register("{USAGE}", usage); - - this.announcer.sendMessage(invocation.sender(), formatter.format(this.config.messages.invalidCommandUsage)); + this.announcer.create() + .viewer(invocation.sender()) + .notice(this.config.messages.invalidCommandUsage) + .placeholder("{USAGE}", usage) + .send(); } + } } diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/handler/MissingPermissionHandlerImpl.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/handler/MissingPermissionHandlerImpl.java index 0466f22b..90652efe 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/handler/MissingPermissionHandlerImpl.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/handler/MissingPermissionHandlerImpl.java @@ -7,7 +7,7 @@ import dev.rollczi.litecommands.permission.MissingPermissions; import dev.rollczi.litecommands.permission.MissingPermissionsHandler; import org.bukkit.command.CommandSender; -import panda.utilities.text.Formatter; +import org.bukkit.entity.Player; public class MissingPermissionHandlerImpl implements MissingPermissionsHandler { @@ -27,9 +27,24 @@ public void handle( ) { String joinedText = missingPermissions.asJoinedText(); - Formatter formatter = new Formatter() - .register("{PERMISSION}", joinedText); + if (invocation instanceof CommandSender sender) { + + if (sender instanceof Player player) { + this.announcer.create() + .player(player.getUniqueId()) + .notice(this.config.messages.noPermission) + .placeholder("{PERMISSION}", joinedText) + .send(); + return; + } + + this.announcer.create() + .console() + .notice(this.config.messages.noPermission) + .placeholder("{PERMISSION}", joinedText) + .send(); + + } - this.announcer.sendMessage(invocation.sender(), formatter.format(this.config.messages.noPermission)); } } diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/notification/NotificationAnnouncer.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/notification/NotificationAnnouncer.java index 47de9228..8644e02f 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/notification/NotificationAnnouncer.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/notification/NotificationAnnouncer.java @@ -1,78 +1,48 @@ package com.eternalcode.combat.notification; -import com.eternalcode.combat.notification.implementation.BossBarNotification; -import net.kyori.adventure.audience.Audience; -import net.kyori.adventure.bossbar.BossBar; +import com.eternalcode.combat.config.implementation.PluginConfig; +import com.eternalcode.multification.adventure.AudienceConverter; +import com.eternalcode.multification.bukkit.BukkitMultification; +import com.eternalcode.multification.translation.TranslationProvider; import net.kyori.adventure.platform.AudienceProvider; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; -import net.kyori.adventure.title.Title; +import net.kyori.adventure.text.serializer.ComponentSerializer; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import panda.utilities.text.Formatter; +import org.jetbrains.annotations.NotNull; -public final class NotificationAnnouncer { +public final class NotificationAnnouncer extends BukkitMultification { private final AudienceProvider audienceProvider; + private final PluginConfig pluginConfig; private final MiniMessage miniMessage; - public NotificationAnnouncer(AudienceProvider audienceProvider, MiniMessage miniMessage) { + public NotificationAnnouncer(AudienceProvider audienceProvider, PluginConfig pluginConfig, MiniMessage miniMessage) { this.audienceProvider = audienceProvider; + this.pluginConfig = pluginConfig; this.miniMessage = miniMessage; } - public void send(CommandSender sender, Notification notification, Formatter formatter) { - Audience audience = this.audience(sender); - Component message = this.miniMessage.deserialize(formatter.format(notification.message())); - - NotificationType type = notification.type(); - - switch (type) { - case CHAT -> audience.sendMessage(message); - case ACTION_BAR -> audience.sendActionBar(message); - - case TITLE -> { - Title title = Title.title(message, Component.empty()); - - audience.showTitle(title); - } - - case SUB_TITLE -> { - Title subTitle = Title.title(Component.empty(), message); - - audience.showTitle(subTitle); - } - - case BOSS_BAR -> { - BossBarNotification bossBarNotification = (BossBarNotification) notification; - BossBar bossBar = bossBarNotification.create(message); - - audience.showBossBar(bossBar); - } - - default -> throw new IllegalStateException("Unknown notification type: " + type); - } + @Override + protected @NotNull TranslationProvider translationProvider() { + return locale -> this.pluginConfig; } - public void sendMessage(CommandSender commandSender, String text) { - Audience audience = this.audience(commandSender); - Component message = this.miniMessage.deserialize(text); - - audience.sendMessage(message); + @Override + protected @NotNull ComponentSerializer serializer() { + return this.miniMessage; } - public void broadcast(String text) { - Audience audience = this.audienceProvider.all(); - Component message = this.miniMessage.deserialize(text); - - audience.sendMessage(message); - } + @Override + protected @NotNull AudienceConverter audienceConverter() { + return commandSender -> { + if (commandSender instanceof Player player) { + return this.audienceProvider.player(player.getUniqueId()); + } - private Audience audience(CommandSender sender) { - if (sender instanceof Player player) { - return this.audienceProvider.player(player.getUniqueId()); - } + return this.audienceProvider.console(); + }; - return this.audienceProvider.console(); } } diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/region/RegionController.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/region/RegionController.java index 1023c981..65711a66 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/region/RegionController.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/region/RegionController.java @@ -62,7 +62,11 @@ void onPlayerMove(PlayerMoveEvent event) { player.setVelocity(knockbackVector.multiply(configuredVector)); - this.announcer.sendMessage(player, this.pluginConfig.messages.cantEnterOnRegion); + this.announcer.create() + .player(player.getUniqueId()) + .notice(this.pluginConfig.messages.cantEnterOnRegion) + .send(); + } } @@ -78,7 +82,10 @@ public void onPlayerTeleport(PlayerTeleportEvent event) { if (this.regionProvider.isInRegion(targetLocation)) { event.setCancelled(true); - this.announcer.sendMessage(player, this.pluginConfig.messages.cantEnterOnRegion); + this.announcer.create() + .player(player.getUniqueId()) + .notice(this.pluginConfig.messages.cantEnterOnRegion) + .send(); } } } From c660a797dcb2d12fcb8c5f9aab969bd6afbb02bd Mon Sep 17 00:00:00 2001 From: CitralFlo Date: Thu, 17 Oct 2024 16:18:31 +0200 Subject: [PATCH 2/9] Bump version of multification --- buildSrc/src/main/kotlin/Versions.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 76536c18..06a3f860 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -9,7 +9,7 @@ object Versions { const val JETBRAINS_ANNOTATIONS = "24.1.0" const val ETERNALCODE_COMMONS = "1.1.3" - const val MULTIFICATION = "1.1.3" + const val MULTIFICATION = "1.1.4" const val ADVENTURE_PLATFORM_BUKKIT = "4.3.4" const val ADVENTURE_TEXT_MINIMESSAGE = "4.17.0" From 4c56f4daf5ce47366ad38c03ba4a9261fea53f3c Mon Sep 17 00:00:00 2001 From: Rollczi Date: Thu, 17 Oct 2024 21:28:31 +0200 Subject: [PATCH 3/9] Override adventure API. Bump LiteCommands --- buildSrc/src/main/kotlin/Versions.kt | 4 ++-- eternalcombat-plugin/build.gradle.kts | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 06a3f860..534a0311 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -12,9 +12,9 @@ object Versions { const val MULTIFICATION = "1.1.4" const val ADVENTURE_PLATFORM_BUKKIT = "4.3.4" - const val ADVENTURE_TEXT_MINIMESSAGE = "4.17.0" + const val ADVENTURE_API = "4.17.0" - const val LITE_COMMANDS = "3.5.0" + const val LITE_COMMANDS = "3.7.0" const val OKAERI_CONFIGS_YAML_BUKKIT = "5.0.3" const val OKAERI_CONFIGS_SERDES_COMMONS = "5.0.3" const val OKAERI_CONFIGS_SERDES_BUKKIT = "5.0.3" diff --git a/eternalcombat-plugin/build.gradle.kts b/eternalcombat-plugin/build.gradle.kts index f14ee4bd..49fa05d7 100644 --- a/eternalcombat-plugin/build.gradle.kts +++ b/eternalcombat-plugin/build.gradle.kts @@ -12,7 +12,12 @@ dependencies { // kyori implementation("net.kyori:adventure-platform-bukkit:${Versions.ADVENTURE_PLATFORM_BUKKIT}") - implementation("net.kyori:adventure-text-minimessage:${Versions.ADVENTURE_TEXT_MINIMESSAGE}") + implementation("net.kyori:adventure-text-minimessage:${Versions.ADVENTURE_API}") + implementation("net.kyori:adventure-api") { + version { + strictly(Versions.ADVENTURE_API) + } + } // litecommands implementation("dev.rollczi:litecommands-bukkit:${Versions.LITE_COMMANDS}") From 4ee3e3af7b88c249a74457015a9c32f68c107f82 Mon Sep 17 00:00:00 2001 From: Rollczi Date: Thu, 17 Oct 2024 22:42:23 +0200 Subject: [PATCH 4/9] Fix import --- .../java/com/eternalcode/combat/updater/UpdaterService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/updater/UpdaterService.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/updater/UpdaterService.java index bf5d665c..e5700829 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/updater/UpdaterService.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/updater/UpdaterService.java @@ -4,8 +4,8 @@ import com.eternalcode.gitcheck.GitCheckResult; import com.eternalcode.gitcheck.git.GitRepository; import com.eternalcode.gitcheck.git.GitTag; +import dev.rollczi.litecommands.shared.Lazy; import org.bukkit.plugin.PluginDescriptionFile; -import panda.std.Lazy; import java.util.concurrent.CompletableFuture; From 626e8ec08cb721c1282535d4282e0efabe91c13a Mon Sep 17 00:00:00 2001 From: CitralFlo Date: Tue, 22 Oct 2024 21:05:16 +0200 Subject: [PATCH 5/9] Fix minor issues with notices --- eternalcombat-plugin/build.gradle.kts | 2 +- .../com/eternalcode/combat/CombatPlugin.java | 6 +++++ .../config/implementation/PluginConfig.java | 2 +- .../combat/fight/FightTagCommand.java | 4 ++++ .../fight/tagout/FightTagOutCommand.java | 5 +--- .../handler/MissingPermissionHandlerImpl.java | 24 +++++-------------- 6 files changed, 19 insertions(+), 24 deletions(-) diff --git a/eternalcombat-plugin/build.gradle.kts b/eternalcombat-plugin/build.gradle.kts index 49fa05d7..6838a6a0 100644 --- a/eternalcombat-plugin/build.gradle.kts +++ b/eternalcombat-plugin/build.gradle.kts @@ -95,7 +95,7 @@ tasks.shadowJar { "eu.okaeri", "net.kyori", "org.bstats", - "dev.rollczi.litecommands", +// "dev.rollczi.litecommands", "com.eternalcode.gitcheck", "org.json.simple", "org.apache.commons", diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/CombatPlugin.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/CombatPlugin.java index a44f51d7..c1ece2b0 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/CombatPlugin.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/CombatPlugin.java @@ -40,6 +40,7 @@ import com.eternalcode.combat.updater.UpdaterService; import com.eternalcode.commons.adventure.AdventureLegacyColorPostProcessor; import com.eternalcode.commons.adventure.AdventureLegacyColorPreProcessor; +import com.eternalcode.multification.notice.Notice; import com.google.common.base.Stopwatch; import dev.rollczi.litecommands.LiteCommands; import dev.rollczi.litecommands.bukkit.LiteBukkitFactory; @@ -127,6 +128,11 @@ public void onEnable() { new EternalCombatReloadCommand(configService, notificationAnnouncer) ) + .result(Notice.class, (invocation, result, chain) -> notificationAnnouncer.create() + .viewer(invocation.sender()) + .notice(result) + .send()) + .build(); FightTask fightTask = new FightTask(server, this.pluginConfig, this.fightManager, notificationAnnouncer); diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/implementation/PluginConfig.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/implementation/PluginConfig.java index dad426c4..ea3dad2f 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/implementation/PluginConfig.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/implementation/PluginConfig.java @@ -177,7 +177,7 @@ public static class Messages extends OkaeriConfig { @Comment("# Message sent when the player does not have permission to perform a command") public Notice noPermission = BukkitNotice.builder() - .chat("&cYou don't have permission to perform this command!") + .chat("&cYou don't have permission \"{PERMISSION}\" to perform this command!") .build(); @Comment("# Message sent when the specified player could not be found") diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTagCommand.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTagCommand.java index a2dfc55e..20e451cd 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTagCommand.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTagCommand.java @@ -12,6 +12,8 @@ import dev.rollczi.litecommands.annotations.context.Context; import dev.rollczi.litecommands.annotations.execute.Execute; import dev.rollczi.litecommands.annotations.permission.Permission; +import dev.rollczi.litecommands.annotations.priority.Priority; +import dev.rollczi.litecommands.annotations.priority.PriorityValue; import java.time.Duration; import java.util.UUID; import org.bukkit.command.CommandSender; @@ -48,6 +50,7 @@ void status(@Context CommandSender sender, @Arg Player target) { @Execute(name = "tag") @Permission("eternalcombat.tag") + @Priority(PriorityValue.HIGH) void tag(@Context CommandSender sender, @Arg Player target) { UUID targetUniqueId = target.getUniqueId(); Duration time = this.config.settings.combatDuration; @@ -69,6 +72,7 @@ void tag(@Context CommandSender sender, @Arg Player target) { this.announcer.create() .notice(this.config.messages.admin.adminTagPlayer) + .placeholder("{PLAYER}", target.getName()) .viewer(sender) .send(); diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/tagout/FightTagOutCommand.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/tagout/FightTagOutCommand.java index ed7b4b87..1934dfd9 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/tagout/FightTagOutCommand.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/tagout/FightTagOutCommand.java @@ -12,6 +12,7 @@ import java.util.UUID; import org.bukkit.entity.Player; +@Permission("eternalcombat.tagout") @Command(name = "tagout", aliases = "tagimmunity") public class FightTagOutCommand { @@ -30,7 +31,6 @@ public FightTagOutCommand( } @Execute - @Permission("eternalcombat.tagout") void tagout(@Context Player sender, @Arg Duration time) { UUID targetUniqueId = sender.getUniqueId(); @@ -45,7 +45,6 @@ void tagout(@Context Player sender, @Arg Duration time) { } @Execute - @Permission("eternalcombat.tagout") void tagout(@Context Player sender, @Arg Player target, @Arg Duration time) { UUID targetUniqueId = target.getUniqueId(); @@ -67,7 +66,6 @@ void tagout(@Context Player sender, @Arg Player target, @Arg Duration time) { } @Execute(name = "remove") - @Permission("eternalcombat.tagout") void untagout(@Context Player sender, @Arg Player target) { UUID targetUniqueId = target.getUniqueId(); @@ -89,7 +87,6 @@ void untagout(@Context Player sender, @Arg Player target) { } @Execute(name = "remove") - @Permission("eternalcombat.tagout") void untagout(@Context Player sender) { UUID senderUniqueId = sender.getUniqueId(); diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/handler/MissingPermissionHandlerImpl.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/handler/MissingPermissionHandlerImpl.java index 90652efe..1b99b2b6 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/handler/MissingPermissionHandlerImpl.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/handler/MissingPermissionHandlerImpl.java @@ -7,7 +7,6 @@ import dev.rollczi.litecommands.permission.MissingPermissions; import dev.rollczi.litecommands.permission.MissingPermissionsHandler; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; public class MissingPermissionHandlerImpl implements MissingPermissionsHandler { @@ -27,24 +26,13 @@ public void handle( ) { String joinedText = missingPermissions.asJoinedText(); - if (invocation instanceof CommandSender sender) { - if (sender instanceof Player player) { - this.announcer.create() - .player(player.getUniqueId()) - .notice(this.config.messages.noPermission) - .placeholder("{PERMISSION}", joinedText) - .send(); - return; - } - - this.announcer.create() - .console() - .notice(this.config.messages.noPermission) - .placeholder("{PERMISSION}", joinedText) - .send(); - - } + this.announcer.create() + .viewer(invocation.sender()) + .notice(this.config.messages.noPermission) + .placeholder("{PERMISSION}", joinedText) + .send(); } } + From ce5895708779ec354418687a23592902eec20ed9 Mon Sep 17 00:00:00 2001 From: CitralFlo Date: Tue, 22 Oct 2024 21:22:46 +0200 Subject: [PATCH 6/9] Change BukktiNotice to Notice --- .../config/implementation/PluginConfig.java | 114 +++++------------- 1 file changed, 33 insertions(+), 81 deletions(-) diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/implementation/PluginConfig.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/implementation/PluginConfig.java index ea3dad2f..dbdcb0e5 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/implementation/PluginConfig.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/implementation/PluginConfig.java @@ -23,13 +23,13 @@ public class PluginConfig extends OkaeriConfig { @Comment("# Do you want to change the plugin settings?") public Settings settings = new Settings(); - @Comment({" ", "# Ender pearl settings"}) + @Comment({ " ", "# Ender pearl settings" }) public FightPearlSettings pearl = new FightPearlSettings(); - @Comment({" ", "# Custom effects settings"}) + @Comment({ " ", "# Custom effects settings" }) public FightEffectSettings effect = new FightEffectSettings(); - @Comment({" ", "# Set a custom way for a player's items to drop on death (if in combat)"}) + @Comment({ " ", "# Set a custom way for a player's items to drop on death (if in combat)" }) public DropSettings dropSettings = new DropSettings(); public static class Settings extends OkaeriConfig { @@ -55,7 +55,7 @@ public static class Settings extends OkaeriConfig { }) public double blockedRegionKnockMultiplier = 1; - @Comment({"# Should the player be prevented from entering regions with WorldGuard flag PVP set to DENY "}) + @Comment({ "# Should the player be prevented from entering regions with WorldGuard flag PVP set to DENY " }) public boolean shouldPreventPvpRegions = true; @Comment("# Set the radius of the blocked region if you aren't using WorldGuard basen on default spawn region!") @@ -64,7 +64,7 @@ public static class Settings extends OkaeriConfig { @Comment("# Release attacker after victim dies?") public boolean shouldReleaseAttacker = true; - @Comment({"# If you want to exclude admins from combat, ", + @Comment({ "# If you want to exclude admins from combat, ", "# Setting this to true - admins cannot be tagged and will not tag other players on hit", "# Setting this to false - admins can be tagged and can tag other players on hit" }) @@ -152,7 +152,7 @@ public enum BlockPlacingMode { } - @Comment({" ", "# Do you want to change the plugin messages?"}) + @Comment({ " ", "# Do you want to change the plugin messages?" }) public Messages messages = new Messages(); public static class Messages extends OkaeriConfig { @@ -176,130 +176,82 @@ public static class Messages extends OkaeriConfig { .build(); @Comment("# Message sent when the player does not have permission to perform a command") - public Notice noPermission = BukkitNotice.builder() - .chat("&cYou don't have permission \"{PERMISSION}\" to perform this command!") - .build(); + public Notice noPermission = Notice.chat("&cYou don't have permission \"{PERMISSION}\" to perform this command!"); @Comment("# Message sent when the specified player could not be found") - public Notice playerNotFound = BukkitNotice.builder() - .chat("&cThe specified player could not be found!") - .build(); + public Notice playerNotFound = Notice.chat("&cThe specified player could not be found!"); @Comment("# Message sent when the player enters combat") - public Notice playerTagged = BukkitNotice.builder() - .chat("&cYou are in combat, do not leave the server!") - .build(); + public Notice playerTagged = Notice.chat("&cYou are in combat, do not leave the server!"); @Comment("# Message sent when the player leaves combat") - public Notice playerUntagged = BukkitNotice.builder() - .chat("&aYou are no longer in combat! You can safely leave the server.") - .build(); + public Notice playerUntagged = Notice.chat("&aYou are no longer in combat! You can safely leave the server."); @Comment("# This is broadcast when the player is in combat and logs out") - public Notice playerLoggedOutDuringCombat = BukkitNotice.builder() - .chat("&c{PLAYER} logged off during the fight!") - .build(); + public Notice playerLoggedOutDuringCombat = Notice.chat("&c{PLAYER} logged off during the fight!"); @Comment({ "# Message sent when the player is in combat and tries to use a disabled command", "# you can configure the list of disabled commands in the blockedCommands section of the config.yml file" }) - public Notice commandDisabledDuringCombat = BukkitNotice.builder() - .chat("&cUsing this command during combat is prohibited!") - .build(); + public Notice commandDisabledDuringCombat = Notice.chat("&cUsing this command during combat is prohibited!"); @Comment("# Message sent when player tries to use a command with invalid arguments") - public Notice invalidCommandUsage = BukkitNotice.builder() - .chat("&7Correct usage: &e{USAGE}") - .build(); + public Notice invalidCommandUsage = Notice.chat("&7Correct usage: &e{USAGE}"); @Comment("# Message sent when player tries to open inventory, but the inventory open is blocked") - public Notice inventoryBlockedDuringCombat = BukkitNotice.builder() - .chat("&cYou cannot open this inventory during combat!") - .build(); + public Notice inventoryBlockedDuringCombat = Notice.chat("&cYou cannot open this inventory during combat!"); - @Comment({"# Message sent when player tries to place a block, but the block place is blocked", - "# Placeholder {Y} is replaced with the Y coordinate set in the config", - "# Placeholder {MODE} is replaced with the mode set in the config"}) - public Notice blockPlacingBlockedDuringCombat = BukkitNotice.builder() - .chat("&cYou cannot place {MODE} {Y} coordinate during combat!") - .build(); + @Comment({ "# Message sent when player tries to place a block, but the block place is blocked", + "# Placeholder {Y} is replaced with the Y coordinate set in the config", + "# Placeholder {MODE} is replaced with the mode set in the config" }) + public Notice blockPlacingBlockedDuringCombat = Notice.chat("&cYou cannot place {MODE} {Y} coordinate during combat!"); @Comment("# Message sent when player tries to enter a region") - public Notice cantEnterOnRegion = BukkitNotice.builder() - .chat("&cYou can't enter this region during combat!") - .build(); + public Notice cantEnterOnRegion = Notice.chat("&cYou can't enter this region during combat!"); public static class AdminMessages extends OkaeriConfig { @Comment("# Message sent when console tries to use a command that is only for players") - public Notice onlyForPlayers = BukkitNotice.builder() - .chat("&cThis command is only available to players!") - .build(); + public Notice onlyForPlayers = Notice.chat("&cThis command is only available to players!"); @Comment("# Message sent to admin when they tag a player") - public Notice adminTagPlayer = BukkitNotice.builder() - .chat("&7You have tagged &e{PLAYER}") - .build(); + public Notice adminTagPlayer = Notice.chat("&7You have tagged &e{PLAYER}"); @Comment("# Message sent when a player is tagged by an admin") - public Notice adminTagMultiplePlayers = BukkitNotice.builder() - .chat("&7You have tagged &e{FIRST_PLAYER}&7 and &e{SECOND_PLAYER}&7.") - .build(); + public Notice adminTagMultiplePlayers = Notice.chat("&7You have tagged &e{FIRST_PLAYER}&7 and &e{SECOND_PLAYER}&7."); @Comment("# Message sent to admin when they remove a player from combat") - public Notice adminUntagPlayer = BukkitNotice.builder() - .chat("&7You have removed &e{PLAYER}&7 from the fight.") - .build(); + public Notice adminUntagPlayer = Notice.chat("&7You have removed &e{PLAYER}&7 from the fight."); @Comment("# Message sent when the player is not in combat") - public Notice adminPlayerNotInCombat = BukkitNotice.builder() - .chat("&cThis player is not in combat!") - .build(); + public Notice adminPlayerNotInCombat = Notice.chat("&cThis player is not in combat!"); @Comment("# Message sent when the player is in combat") - public Notice playerInCombat = BukkitNotice.builder() - .chat("&c{PLAYER} is currently in combat!") - .build(); + public Notice playerInCombat = Notice.chat("&c{PLAYER} is currently in combat!"); @Comment("# Message sent when a player is not in combat") - public Notice playerNotInCombat = BukkitNotice.builder() - .chat("&a{PLAYER} is not currently in combat.") - .build(); + public Notice playerNotInCombat = Notice.chat("&a{PLAYER} is not currently in combat."); @Comment("# Message sent when an admin tries to tag themselves") - public Notice adminCannotTagSelf = BukkitNotice.builder() - .chat("&cYou cannot tag yourself!") - .build(); + public Notice adminCannotTagSelf = Notice.chat("&cYou cannot tag yourself!"); @Comment("# Message sent when an admin disables the ability to get tagged for some time") - public Notice adminTagOutSelf = BukkitNotice.builder() - .chat("&7Successfully disabled tag for Yourself! You will be taggable after &e{TIME} ") - .build(); + public Notice adminTagOutSelf = Notice.chat("&7Successfully disabled tag for Yourself! You will be taggable after &e{TIME} "); @Comment("# Message sent when an admin disables the ability to get tagged for some time for other player") - public Notice adminTagOut = BukkitNotice.builder() - .chat("&7Successfully disabled tag for &e{PLAYER}! They will be taggable after &e{TIME} ") - .build(); + public Notice adminTagOut = Notice.chat("&7Successfully disabled tag for &e{PLAYER}! They will be taggable after &e{TIME} "); @Comment("# Message sent to the player whom the ability to get tagged for some time has been disabled") - public Notice playerTagOut = BukkitNotice.builder() - .chat("&7You will be taggable in &e{TIME} !") - .build(); + public Notice playerTagOut = Notice.chat("&7You will be taggable in &e{TIME} !"); @Comment("# Message sent when an admin reenables the ability to get tagged for the player") - public Notice adminTagOutOff = BukkitNotice.builder() - .chat("&7Successfully enabled tag for &e{PLAYER}!") - .build(); + public Notice adminTagOutOff = Notice.chat("&7Successfully enabled tag for &e{PLAYER}!"); @Comment("# Message sent to the player whom the ability to get tagged has been reenabled") - public Notice playerTagOutOff = BukkitNotice.builder() - .chat("&7You are now taggable!") - .build(); + public Notice playerTagOutOff = Notice.chat("&7You are now taggable!"); @Comment("# Message sent when player cannot be tagged because they have enabled tag-out") - public Notice adminTagOutCanceled = BukkitNotice.builder() - .chat("&cCannot tag this player due to tag-out!") - .build(); + public Notice adminTagOutCanceled = Notice.chat("&cCannot tag this player due to tag-out!"); } } } From ef6ded78ed18438bfaedd418cc57f04358cc3c1b Mon Sep 17 00:00:00 2001 From: CitralFlo Date: Tue, 22 Oct 2024 21:27:05 +0200 Subject: [PATCH 7/9] Resolve Rollczi's suggestions --- .../combat/fight/FightTagCommand.java | 38 ++++++++----------- .../combat/fight/logout/LogoutController.java | 2 +- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTagCommand.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTagCommand.java index 20e451cd..eba66670 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTagCommand.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTagCommand.java @@ -60,12 +60,7 @@ void tag(@Context CommandSender sender, @Arg Player target) { if (event.isCancelled()) { CancelTagReason cancelReason = event.getCancelReason(); - if (cancelReason == CancelTagReason.TAGOUT) { - this.announcer.create() - .notice(this.config.messages.admin.adminTagOutCanceled) - .viewer(sender) - .send(); - } + tagoutReasonHandler(sender, cancelReason, this.config.messages); return; } @@ -100,12 +95,7 @@ void tagMultiple(@Context CommandSender sender, @Arg Player firstTarget, @Arg Pl if (firstTagEvent.isCancelled()) { CancelTagReason cancelReason = firstTagEvent.getCancelReason(); - if (cancelReason == CancelTagReason.TAGOUT) { - this.announcer.create() - .notice(messages.admin.adminTagOutCanceled) - .send(); - - } + tagoutReasonHandler(sender, cancelReason, messages); return; } @@ -113,13 +103,7 @@ void tagMultiple(@Context CommandSender sender, @Arg Player firstTarget, @Arg Pl if (secondTagEvent.isCancelled()) { CancelTagReason cancelReason = secondTagEvent.getCancelReason(); - if (cancelReason == CancelTagReason.TAGOUT) { - this.announcer.create() - .notice(messages.admin.adminTagOutCanceled) - .viewer(sender) - .send(); - - } + tagoutReasonHandler(sender, cancelReason, messages); return; } @@ -144,9 +128,9 @@ void untag(@Context Player sender, @Arg Player target) { if (!this.fightManager.isInCombat(targetUniqueId)) { this.announcer.create() - .viewer(sender) - .notice(this.config.messages.admin.adminPlayerNotInCombat) - .send(); + .viewer(sender) + .notice(this.config.messages.admin.adminPlayerNotInCombat) + .send(); return; } @@ -162,4 +146,14 @@ void untag(@Context Player sender, @Arg Player target) { .viewer(sender) .send(); } + + private void tagoutReasonHandler(CommandSender sender, CancelTagReason cancelReason, PluginConfig.Messages messages) { + if (cancelReason == CancelTagReason.TAGOUT) { + this.announcer.create() + .notice(messages.admin.adminTagOutCanceled) + .viewer(sender) + .send(); + + } + } } diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/logout/LogoutController.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/logout/LogoutController.java index 2ae7aff6..12ed80e3 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/logout/LogoutController.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/logout/LogoutController.java @@ -38,7 +38,7 @@ void onQuit(PlayerQuitEvent event) { this.announcer.create() .notice(this.config.messages.playerLoggedOutDuringCombat) .placeholder("{PLAYER}", player.getName()) - .onlinePlayers() + .all() .send(); } From db173a9e6f0e4847b672644800c9de0a7fd4baee Mon Sep 17 00:00:00 2001 From: CitralFlo Date: Tue, 22 Oct 2024 21:29:46 +0200 Subject: [PATCH 8/9] MAJOR FIX --- .../java/com/eternalcode/combat/fight/FightTagCommand.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTagCommand.java b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTagCommand.java index eba66670..c409d8a0 100644 --- a/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTagCommand.java +++ b/eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTagCommand.java @@ -60,7 +60,7 @@ void tag(@Context CommandSender sender, @Arg Player target) { if (event.isCancelled()) { CancelTagReason cancelReason = event.getCancelReason(); - tagoutReasonHandler(sender, cancelReason, this.config.messages); + this.tagoutReasonHandler(sender, cancelReason, this.config.messages); return; } @@ -95,7 +95,7 @@ void tagMultiple(@Context CommandSender sender, @Arg Player firstTarget, @Arg Pl if (firstTagEvent.isCancelled()) { CancelTagReason cancelReason = firstTagEvent.getCancelReason(); - tagoutReasonHandler(sender, cancelReason, messages); + this.tagoutReasonHandler(sender, cancelReason, messages); return; } @@ -103,7 +103,7 @@ void tagMultiple(@Context CommandSender sender, @Arg Player firstTarget, @Arg Pl if (secondTagEvent.isCancelled()) { CancelTagReason cancelReason = secondTagEvent.getCancelReason(); - tagoutReasonHandler(sender, cancelReason, messages); + this.tagoutReasonHandler(sender, cancelReason, messages); return; } From fe8e648de0e4be772a9c92e2145c321f1652b05a Mon Sep 17 00:00:00 2001 From: CitralFlo Date: Tue, 22 Oct 2024 21:35:57 +0200 Subject: [PATCH 9/9] uncomment dev.rollczi.litecommands needed for testing --- eternalcombat-plugin/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eternalcombat-plugin/build.gradle.kts b/eternalcombat-plugin/build.gradle.kts index 6838a6a0..49fa05d7 100644 --- a/eternalcombat-plugin/build.gradle.kts +++ b/eternalcombat-plugin/build.gradle.kts @@ -95,7 +95,7 @@ tasks.shadowJar { "eu.okaeri", "net.kyori", "org.bstats", -// "dev.rollczi.litecommands", + "dev.rollczi.litecommands", "com.eternalcode.gitcheck", "org.json.simple", "org.apache.commons",