diff --git a/BloodNight-core/build.gradle.kts b/BloodNight-core/build.gradle.kts index be0be79e..d0eb4fd1 100644 --- a/BloodNight-core/build.gradle.kts +++ b/BloodNight-core/build.gradle.kts @@ -14,6 +14,9 @@ dependencies { implementation("de.eldoria.util", "inventory", "2.0.4-SNAPSHOT") implementation("de.eldoria.util", "conversation", "2.0.4-SNAPSHOT") implementation("de.eldoria.util", "threading", "2.0.4-SNAPSHOT") + implementation("de.eldoria.util", "crossversion", "2.0.4-SNAPSHOT") + implementation("de.eldoria.util", "entities", "2.0.4-SNAPSHOT") + implementation("de.eldoria.util", "legacy-serialization", "2.0.4-SNAPSHOT") implementation("net.kyori", "adventure-platform-bukkit", "4.3.1") testImplementation("org.junit.jupiter", "junit-jupiter-api", "5.10.1") testImplementation("junit", "junit", "4.13.2") diff --git a/BloodNight-core/src/main/java/de/eldoria/bloodnight/command/BloodNightCommand.java b/BloodNight-core/src/main/java/de/eldoria/bloodnight/command/BloodNightCommand.java index ba6dceb1..3f154b10 100644 --- a/BloodNight-core/src/main/java/de/eldoria/bloodnight/command/BloodNightCommand.java +++ b/BloodNight-core/src/main/java/de/eldoria/bloodnight/command/BloodNightCommand.java @@ -1,6 +1,5 @@ package de.eldoria.bloodnight.command; -import de.eldoria.bloodnight.command.bloodnight.About; import de.eldoria.bloodnight.command.bloodnight.CancelNight; import de.eldoria.bloodnight.command.bloodnight.ForceNight; import de.eldoria.bloodnight.command.bloodnight.Help; @@ -20,7 +19,6 @@ import de.eldoria.eldoutilities.commands.command.CommandMeta; import de.eldoria.eldoutilities.commands.defaultcommands.DefaultAbout; import de.eldoria.eldoutilities.commands.defaultcommands.DefaultDebug; -import de.eldoria.eldoutilities.simplecommands.commands.DefaultDebug; import org.bukkit.plugin.Plugin; public class BloodNightCommand extends AdvancedCommand { @@ -35,15 +33,16 @@ public BloodNightCommand(Configuration configuration, Plugin plugin, .withSubCommand(new DefaultAbout(plugin, "https://bn.discord.eldoria.de")) .withSubCommand(new SpawnMob(plugin, nightManager, mobManager)) .withSubCommand(new CancelNight(plugin, nightManager, configuration)) - .withSubCommand("forceNight", new ForceNight(plugin, nightManager, configuration)) - .withSubCommand("manageWorlds", new ManageWorlds(plugin, configuration)) - .withSubCommand("manageMob", new ManageMob(plugin, configuration, inventoryListener)) - .withSubCommand("manageNight", new ManageNight(plugin, configuration)) - .withSubCommand("manageMobs", new ManageMobs(plugin, configuration, inventoryListener)) - .withSubCommand("nightSelection", new ManageNightSelection(plugin, configuration, inventoryListener)) + .withSubCommand(new ForceNight(plugin, nightManager, configuration)) + .withSubCommand(new ManageWorlds(plugin, configuration)) + .withSubCommand(new ManageMob(plugin, configuration, inventoryListener)) + .withSubCommand(new ManageNight(plugin, configuration)) + .withSubCommand(new ManageMobs(plugin, configuration, inventoryListener)) + .withSubCommand(new ManageNightSelection(plugin, configuration, inventoryListener)) .withSubCommand(new ManageDeathActions(plugin, configuration)) .withSubCommand(new Reload(plugin)) .withSubCommand(new DefaultDebug(plugin, Permissions.Admin.RELOAD)) + .build() ); } } diff --git a/BloodNight-core/src/main/java/de/eldoria/bloodnight/command/bloodnight/ManageNight.java b/BloodNight-core/src/main/java/de/eldoria/bloodnight/command/bloodnight/ManageNight.java index 2a7263c6..8281f8da 100644 --- a/BloodNight-core/src/main/java/de/eldoria/bloodnight/command/bloodnight/ManageNight.java +++ b/BloodNight-core/src/main/java/de/eldoria/bloodnight/command/bloodnight/ManageNight.java @@ -6,13 +6,17 @@ import de.eldoria.bloodnight.config.worldsettings.WorldSettings; import de.eldoria.bloodnight.core.BloodNight; import de.eldoria.bloodnight.util.Permissions; -import de.eldoria.eldoutilities.localization.Replacement; -import de.eldoria.eldoutilities.simplecommands.EldoCommand; -import de.eldoria.eldoutilities.simplecommands.TabCompleteUtil; +import de.eldoria.eldoutilities.commands.Completion; +import de.eldoria.eldoutilities.commands.command.AdvancedCommand; +import de.eldoria.eldoutilities.commands.command.CommandMeta; +import de.eldoria.eldoutilities.commands.command.util.Arguments; +import de.eldoria.eldoutilities.commands.command.util.CommandAssertions; +import de.eldoria.eldoutilities.commands.command.util.Input; +import de.eldoria.eldoutilities.commands.exceptions.CommandException; +import de.eldoria.eldoutilities.commands.executor.IPlayerTabExecutor; +import de.eldoria.eldoutilities.messages.Replacement; import de.eldoria.eldoutilities.utils.ArgumentUtils; import de.eldoria.eldoutilities.utils.ArrayUtil; -import de.eldoria.eldoutilities.utils.EnumUtil; -import de.eldoria.eldoutilities.utils.Parser; import net.kyori.adventure.identity.Identity; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.text.Component; @@ -20,7 +24,6 @@ import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.World; -import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -29,228 +32,165 @@ import java.util.Collections; import java.util.List; -import java.util.Optional; -public class ManageNight extends EldoCommand { +import static de.eldoria.bloodnight.command.util.CommandUtil.changeableValue; +import static de.eldoria.bloodnight.command.util.CommandUtil.getBooleanField; +import static de.eldoria.bloodnight.command.util.CommandUtil.getHeader; +import static de.eldoria.bloodnight.command.util.CommandUtil.getToggleField; +import static de.eldoria.eldoutilities.localization.ILocalizer.escape; + +public class ManageNight extends AdvancedCommand implements IPlayerTabExecutor { private final Configuration configuration; private final BukkitAudiences bukkitAudiences; public ManageNight(Plugin plugin, Configuration configuration) { - super(plugin); + super(plugin, CommandMeta.builder("manageNight") + .withPermission(Permissions.Admin.MANAGE_NIGHT) + .addArgument("syntax.worldName", false) + .addArgument("syntax.field", false) + .addArgument("syntax.value", false) + .build()); this.configuration = configuration; bukkitAudiences = BukkitAudiences.create(BloodNight.getInstance()); } @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (denyConsole(sender)) { - return true; - } - - if (denyAccess(sender, Permissions.Admin.MANAGE_NIGHT)) { - return true; - } - - Player player = getPlayerFromSender(sender); - - World world = ArgumentUtils.getOrDefault(args, 0, ArgumentUtils::getWorld, player.getWorld()); - - if (world == null) { - messageSender().sendError(sender, localizer().getMessage("error.invalidWorld")); - return true; - } + public void onCommand(@NotNull Player player, @NotNull String alias, @NotNull Arguments args) throws CommandException { + World world = args.asWorld(0, player.getWorld()); WorldSettings worldSettings = configuration.getWorldSettings(world); - if (args.length < 2) { - sendNightSettings(sender, worldSettings); - return true; + if (args.size() < 2) { + sendNightSettings(player, worldSettings); + return; } - if (argumentsInvalid(sender, args, 3, - "[" + localizer().getMessage("syntax.worldName") + "] [<" - + localizer().getMessage("syntax.field") + "> <" - + localizer().getMessage("syntax.value") + ">]")) { - return true; - } - String cmd = args[1]; - String value = args[2]; - Optional optionalDouble = Parser.parseDouble(value); - Optional optionalInt = Parser.parseInt(value); - Optional optionalBoolean = Parser.parseBoolean(value); + String cmd = args.asString(1); + Input value = args.get(2); NightSettings nightSettings = worldSettings.getNightSettings(); if (ArrayUtil.arrayContains(new String[]{"enable", "skippable"}, cmd)) { - if (!optionalBoolean.isPresent()) { - messageSender().sendError(sender, localizer().getMessage("error.invalidBoolean")); - return true; - } - if ("enable".equalsIgnoreCase(cmd)) { - worldSettings.setEnabled(optionalBoolean.get()); + worldSettings.setEnabled(value.asBoolean()); } if ("skippable".equalsIgnoreCase(cmd)) { - nightSettings.setSkippable(optionalBoolean.get()); + nightSettings.setSkippable(value.asBoolean()); } configuration.save(); - sendNightSettings(sender, worldSettings); - return true; + sendNightSettings(player, worldSettings); + return; } if (ArrayUtil.arrayContains(new String[]{"nightBegin", "nightEnd", "nightDuration", "maxNightDuration"}, cmd)) { - if (!optionalInt.isPresent()) { - messageSender().sendError(sender, localizer().getMessage("error.invalidNumber")); - return true; - } if ("nightBegin".equalsIgnoreCase(cmd)) { - if (invalidRange(sender, optionalInt.get(), 0, 24000)) { - return true; - } - nightSettings.setNightBegin(optionalInt.get()); + CommandAssertions.range(value.asInt(), 0, 24000); + nightSettings.setNightBegin(value.asInt()); } if ("nightEnd".equalsIgnoreCase(cmd)) { - if (invalidRange(sender, optionalInt.get(), 0, 24000)) { - return true; - } - nightSettings.setNightEnd(optionalInt.get()); + CommandAssertions.range(value.asInt(), 0, 24000); + nightSettings.setNightEnd(value.asInt()); } if ("nightDuration".equalsIgnoreCase(cmd)) { - if (invalidRange(sender, optionalInt.get(), 0, 86400)) { - return true; - } - nightSettings.setNightDuration(optionalInt.get()); + CommandAssertions.range(value.asInt(), 0, 86400); + nightSettings.setNightDuration(value.asInt()); } if ("maxNightDuration".equalsIgnoreCase(cmd)) { - if (invalidRange(sender, optionalInt.get(), nightSettings.getNightDuration(), 86400)) { - return true; - } - nightSettings.setMaxNightDuration(optionalInt.get()); + CommandAssertions.range(value.asInt(), 0, 86400); + nightSettings.setMaxNightDuration(value.asInt()); } configuration.save(); - sendNightSettings(sender, worldSettings); - return true; + sendNightSettings(player, worldSettings); + return; } if ("durationMode".equalsIgnoreCase(cmd)) { - Optional parse = EnumUtil.parse(value, NightSettings.NightDuration.class); - if (parse.isEmpty()) { - messageSender().sendLocalizedError(sender, "error.invalidValue"); - return true; - } - nightSettings.setNightDurationMode(parse.get()); + nightSettings.setNightDurationMode(value.asEnum(NightSettings.NightDuration.class)); configuration.save(); - sendNightSettings(sender, worldSettings); - return true; + sendNightSettings(player, worldSettings); + return; } messageSender().sendError(player, localizer().getMessage("error.invalidField")); - return true; } private void sendNightSettings(CommandSender sender, WorldSettings worldSettings) { NightSettings nightSettings = worldSettings.getNightSettings(); String cmd = "/bloodnight manageNight " + ArgumentUtils.escapeWorldName(worldSettings.getWorldName()) + " "; NightSettings.NightDuration durationMode = nightSettings.getNightDurationMode(); - TextComponent.Builder builder = Component.text() - .append(Component.newline()) - .append(Component.newline()) - .append(Component.newline()) - .append(Component.newline()) - .append(CommandUtil.getHeader(localizer().getMessage("manageNight.title", - Replacement.create("WORLD", worldSettings.getWorldName()).addFormatting('6')))) - .append(Component.newline()) - // World state - .append(CommandUtil.getBooleanField( - worldSettings.isEnabled(), - cmd + "enable {bool}", - localizer().getMessage("field.active"), - localizer().getMessage("state.enabled"), - localizer().getMessage("state.disabled"))) - .append(Component.newline()) - // skippable - .append(CommandUtil.getBooleanField(nightSettings.isSkippable(), - cmd + "skippable {bool}", - localizer().getMessage("field.sleep"), - localizer().getMessage("state.allow"), - localizer().getMessage("state.deny"))) - .append(Component.newline()) - // night begin - .append(Component.text(localizer().getMessage("field.nightBegin") + ": ", NamedTextColor.AQUA)) - .append(Component.text(nightSettings.getNightBegin() + " ", NamedTextColor.GOLD)) - .append(Component.text("[" + localizer().getMessage("action.change") + "]", NamedTextColor.GREEN) - .clickEvent(ClickEvent.suggestCommand(cmd + "nightBegin "))) - .append(Component.newline()) - // night end - .append(Component.text(localizer().getMessage("field.nightEnd") + ": ", NamedTextColor.AQUA)) - .append(Component.text(nightSettings.getNightEnd() + " ", NamedTextColor.GOLD)) - .append(Component.text("[" + localizer().getMessage("action.change") + "]", NamedTextColor.GREEN) - .clickEvent(ClickEvent.suggestCommand(cmd + "nightEnd "))) - .append(Component.newline()) - // override night duration - .append(CommandUtil.getToggleField(durationMode == NightSettings.NightDuration.NORMAL, - cmd + "durationMode NORMAL", - localizer().getMessage("state.normal"))) - .append(Component.space()) - .append(CommandUtil.getToggleField(durationMode == NightSettings.NightDuration.EXTENDED, - cmd + "durationMode EXTENDED", - localizer().getMessage("state.extended"))) - .append(Component.space()) - .append(CommandUtil.getToggleField(durationMode == NightSettings.NightDuration.RANGE, - cmd + "durationMode RANGE", - localizer().getMessage("state.range"))) - .append(Component.newline()); - switch (durationMode) { - case NORMAL -> builder.append(Component.text(">", NamedTextColor.GOLD)) - .append(Component.newline()) - .append(Component.text(">", NamedTextColor.GOLD)); - case EXTENDED -> - //night duration - builder.append(Component.text(localizer().getMessage("field.nightDuration") + ": ", NamedTextColor.AQUA)) - .append(Component.text(nightSettings.getNightDuration() + " " + localizer().getMessage("value.seconds"), NamedTextColor.GOLD)) - .append(Component.text(" [" + localizer().getMessage("action.change") + "]", NamedTextColor.GREEN) - .clickEvent(ClickEvent.suggestCommand(cmd + "nightDuration "))) - .append(Component.newline()) - .append(Component.text(">", NamedTextColor.GOLD)); - case RANGE -> - builder.append(Component.text(localizer().getMessage("field.minDuration") + ": ", NamedTextColor.AQUA)) - .append(Component.text(nightSettings.getNightDuration() + " " + localizer().getMessage("value.seconds"), NamedTextColor.GOLD)) - .append(Component.text(" [" + localizer().getMessage("action.change") + "]", NamedTextColor.GREEN) - .clickEvent(ClickEvent.suggestCommand(cmd + "nightDuration "))) - .append(Component.newline()) - .append(Component.text(localizer().getMessage("field.maxDuration") + ": ", NamedTextColor.AQUA)) - .append(Component.text(nightSettings.getMaxNightDuration() + " " + localizer().getMessage("value.seconds"), NamedTextColor.GOLD)) - .append(Component.text(" [" + localizer().getMessage("action.change") + "]", NamedTextColor.GREEN) - .clickEvent(ClickEvent.suggestCommand(cmd + "maxNightDuration "))); - } - bukkitAudiences.sender(sender).sendMessage(Identity.nil(), builder.build()); + var duration = switch (durationMode) { + case NORMAL -> """ + > + >""".stripIndent(); + //night duration + case EXTENDED -> """ + %s + > + """.stripIndent() + .formatted( + changeableValue("field.nightDuration", nightSettings.getNightDuration() + " " + escape("value.seconds"), cmd + "nightDuration ") + ); + case RANGE -> """ + + """.stripIndent() + .formatted( + changeableValue("field.minDuration", nightSettings.getNightDuration() + " " + escape("value.seconds"), cmd + "nightDuration "), + changeableValue("field.maxDuration", nightSettings.getMaxNightDuration() + " " + escape("value.seconds"), cmd + "maxNightDuration ") + ); + }; + + var a = """ + %s + %s + %s + %s + %s + %s %s %s + """.stripIndent() + .formatted( + getHeader("manageNight.title"), + // World state + getBooleanField(worldSettings.isEnabled(), cmd + "enable {bool}", "field.active", "state.enabled", "state.disabled"), + // skippable + getBooleanField(nightSettings.isSkippable(), cmd + "skippable {bool}", "field.sleep", "state.allow", "state.deny"), + // night begin + changeableValue("field.nightBegin", nightSettings.getNightBegin(), cmd + "nightBegin "), + // night end + changeableValue("field.nightEnd", nightSettings.getNightEnd(), cmd + "nightEnd "), + // Night duration type + getToggleField(durationMode == NightSettings.NightDuration.NORMAL, cmd + "durationMode NORMAL", "state.normal"), + getToggleField(durationMode == NightSettings.NightDuration.EXTENDED, cmd + "durationMode EXTENDED", "state.extended"), + getToggleField(durationMode == NightSettings.NightDuration.RANGE, cmd + "durationMode RANGE", "state.range") + ); + + messageSender().sendMessage(sender, a, Replacement.create("WORLD", worldSettings.getWorldName())); } @Override - public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { - if (args.length == 1) { - return TabCompleteUtil.completeWorlds(args[0]); + public @Nullable List onTabComplete(@NotNull Player player, @NotNull String alias, @NotNull Arguments args) throws CommandException { + if (args.size() == 1) { + return Completion.completeWorlds(args.asString(0)); } - if (args.length == 2) { - return TabCompleteUtil.complete(args[1], "nightBegin", "nightEnd", "nightDuration", + if (args.size() == 2) { + return Completion.complete(args.asString(1), "nightBegin", "nightEnd", "nightDuration", "enable", "skippable", "overrideDuration"); } - String field = args[1]; - String value = args[2]; - if (TabCompleteUtil.isCommand(field, "nightBegin", "nightEnd", "nightDuration", "maxNightDuration")) { - return TabCompleteUtil.isCommand(field, "nightBegin", "nightEnd") - ? TabCompleteUtil.completeInt(value, 1, 24000, localizer()) - : TabCompleteUtil.completeInt(value, 1, 86400, localizer()); + String field = args.asString(1); + String value = args.asString(2); + if (Completion.isCommand(field, "nightBegin", "nightEnd", "nightDuration", "maxNightDuration")) { + return Completion.isCommand(field, "nightBegin", "nightEnd") + ? Completion.completeInt(value, 1, 24000) + : Completion.completeInt(value, 1, 86400); } - if (TabCompleteUtil.isCommand(field, "enable", "skippable")) { - return TabCompleteUtil.completeBoolean(value); + if (Completion.isCommand(field, "enable", "skippable")) { + return Completion.completeBoolean(value); } - if (TabCompleteUtil.isCommand(field, "durationMode")) { - return TabCompleteUtil.complete(value, NightSettings.NightDuration.class); + if (Completion.isCommand(field, "durationMode")) { + return Completion.complete(value, NightSettings.NightDuration.class); } return Collections.emptyList(); } diff --git a/BloodNight-core/src/main/java/de/eldoria/bloodnight/command/bloodnight/ManageNightSelection.java b/BloodNight-core/src/main/java/de/eldoria/bloodnight/command/bloodnight/ManageNightSelection.java index f27792d8..48ee0a28 100644 --- a/BloodNight-core/src/main/java/de/eldoria/bloodnight/command/bloodnight/ManageNightSelection.java +++ b/BloodNight-core/src/main/java/de/eldoria/bloodnight/command/bloodnight/ManageNightSelection.java @@ -7,26 +7,28 @@ import de.eldoria.bloodnight.config.worldsettings.WorldSettings; import de.eldoria.bloodnight.core.BloodNight; import de.eldoria.bloodnight.util.Permissions; +import de.eldoria.eldoutilities.commands.Completion; +import de.eldoria.eldoutilities.commands.command.AdvancedCommand; +import de.eldoria.eldoutilities.commands.command.CommandMeta; +import de.eldoria.eldoutilities.commands.command.util.Arguments; +import de.eldoria.eldoutilities.commands.command.util.Input; +import de.eldoria.eldoutilities.commands.exceptions.CommandException; +import de.eldoria.eldoutilities.commands.executor.IPlayerTabExecutor; import de.eldoria.eldoutilities.container.Pair; import de.eldoria.eldoutilities.localization.ILocalizer; -import de.eldoria.eldoutilities.simplecommands.EldoCommand; -import de.eldoria.eldoutilities.simplecommands.TabCompleteUtil; +import de.eldoria.eldoutilities.messages.Replacement; import de.eldoria.eldoutilities.utils.ArgumentUtils; import de.eldoria.eldoutilities.utils.EMath; -import de.eldoria.eldoutilities.utils.EnumUtil; -import de.eldoria.eldoutilities.utils.Parser; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.event.ClickEvent; -import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.World; -import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; @@ -41,16 +43,39 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; import java.util.stream.Collectors; -public class ManageNightSelection extends EldoCommand { +import static de.eldoria.bloodnight.command.util.CommandUtil.changeButton; +import static de.eldoria.bloodnight.command.util.CommandUtil.changeableValue; +import static de.eldoria.bloodnight.command.util.CommandUtil.getToggleField; +import static de.eldoria.bloodnight.config.worldsettings.NightSelection.NightSelectionType; +import static de.eldoria.bloodnight.config.worldsettings.NightSelection.NightSelectionType.CURVE; +import static de.eldoria.bloodnight.config.worldsettings.NightSelection.NightSelectionType.INTERVAL; +import static de.eldoria.bloodnight.config.worldsettings.NightSelection.NightSelectionType.MOON_PHASE; +import static de.eldoria.bloodnight.config.worldsettings.NightSelection.NightSelectionType.PHASE; +import static de.eldoria.bloodnight.config.worldsettings.NightSelection.NightSelectionType.RANDOM; +import static de.eldoria.bloodnight.config.worldsettings.NightSelection.NightSelectionType.REAL_MOON_PHASE; +import static de.eldoria.eldoutilities.localization.ILocalizer.escape; + +public class ManageNightSelection extends AdvancedCommand implements IPlayerTabExecutor { private final Configuration configuration; private final InventoryListener inventoryListener; private final BukkitAudiences bukkitAudiences; public ManageNightSelection(Plugin plugin, Configuration configuration, InventoryListener inventoryListener) { - super(plugin); + super(plugin, CommandMeta.builder("manageNightSelection") + .addArgument("syntax.worldName", false) + .addArgument("syntax.field", false) + .addArgument("syntax.value", false) + .withPermission(Permissions.Admin.MANAGE_WORLDS) + .build()); this.configuration = configuration; this.inventoryListener = inventoryListener; bukkitAudiences = BukkitAudiences.create(BloodNight.getInstance()); @@ -75,87 +100,60 @@ private static String getMoonPhaseSign(int phase) { } // world field value - @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (denyConsole(sender)) { - return true; - } - - if (denyAccess(sender, Permissions.Admin.MANAGE_WORLDS)) { - return true; - } - - Player player = getPlayerFromSender(sender); - - World world = ArgumentUtils.getOrDefault(args, 0, ArgumentUtils::getWorld, player.getWorld()); - if (world == null) { - messageSender().sendError(sender, localizer().getMessage("error.invalidWorld")); - return true; - } + @Override + public void onCommand(@NotNull Player player, @NotNull String alias, @NotNull Arguments args) throws CommandException { + World world = args.asWorld(0, player.getWorld()); WorldSettings worldSettings = configuration.getWorldSettings(world); - if (args.length < 2) { - sendWorldPage(world, sender, 0); - return true; + if (args.size() < 2) { + sendWorldPage(world, player, 0); + return; } - // world field value - if (argumentsInvalid(sender, args, 3, - "[" + localizer().getMessage("syntax.worldName") + "] [<" - + localizer().getMessage("syntax.field") + "> <" - + localizer().getMessage("syntax.value") + ">]")) { - return true; - } - String field = args[1]; - String value = ArgumentUtils.getOptionalParameter(args, 2, "none", s -> s); + String field = args.asString(1); + Input value = args.get(2, Input.of(plugin(), "none")); Optional optPage = CommandUtil.findPage(configuration.getWorldSettings().values(), 3, w -> w.getWorldName().equalsIgnoreCase(world.getName())); if ("page".equalsIgnoreCase(field)) { - Optional optionalInt = Parser.parseInt(value); - optionalInt.ifPresent(integer -> sendWorldPage(world, sender, integer)); - return true; + sendWorldPage(world, player, value.asInt()); + return; } final NightSelection sel = worldSettings.getNightSelection(); - if (TabCompleteUtil.isCommand(field, "interval", "intervalProbability", "probability", "phaseAmount", + if (Completion.isCommand(field, "interval", "intervalProbability", "probability", "phaseAmount", "period", "minCurveVal", "maxCurveVal")) { - Optional optionalInt = Parser.parseInt(value); - if (!optionalInt.isPresent()) { - messageSender().sendError(player, localizer().getMessage("error.invalidNumber")); - return true; - } if ("interval".equalsIgnoreCase(field)) { - sel.setInterval(EMath.clamp(1, 100, optionalInt.get())); + sel.setInterval(EMath.clamp(1, 100, value.asInt())); } if ("intervalProbability".equalsIgnoreCase(field)) { - sel.setIntervalProbability(EMath.clamp(0, 100, optionalInt.get())); + sel.setIntervalProbability(EMath.clamp(0, 100, value.asInt())); } if ("probability".equalsIgnoreCase(field)) { - sel.setProbability(EMath.clamp(0, 100, optionalInt.get())); + sel.setProbability(EMath.clamp(0, 100, value.asInt())); } if ("phaseAmount".equalsIgnoreCase(field)) { - sel.setPhaseCount(EMath.clamp(1, 54, optionalInt.get())); + sel.setPhaseCount(EMath.clamp(1, 54, value.asInt())); } if ("period".equalsIgnoreCase(field)) { - sel.setPeriod(EMath.clamp(3, 100, optionalInt.get())); + sel.setPeriod(EMath.clamp(3, 100, value.asInt())); } if ("minCurveVal".equalsIgnoreCase(field)) { - sel.setMinCurveVal(EMath.clamp(0, 100, optionalInt.get())); + sel.setMinCurveVal(EMath.clamp(0, 100, value.asInt())); } if ("maxCurveVal".equalsIgnoreCase(field)) { - sel.setMaxCurveVal(EMath.clamp(0, 100, optionalInt.get())); + sel.setMaxCurveVal(EMath.clamp(0, 100, value.asInt())); } - optPage.ifPresent(p -> sendWorldPage(world, sender, p)); + optPage.ifPresent(p -> sendWorldPage(world, player, p)); configuration.save(); - return true; + return; } - if (TabCompleteUtil.isCommand(field, "moonPhase", "phase")) { + if (Completion.isCommand(field, "moonPhase", "phase")) { boolean moonPhase = "moonPhase".equalsIgnoreCase(field); Inventory inv = Bukkit.createInventory(player, moonPhase ? 9 : 54, localizer().getMessage(moonPhase ? "nightSelection.title.moonPhase" : "nightSelection.title.phase")); @@ -176,7 +174,7 @@ public void onInventoryClose(InventoryCloseEvent event) { sel.setPhaseCustom(s.first, s.second); } }); - optPage.ifPresent(i -> sendWorldPage(world, sender, i)); + optPage.ifPresent(i -> sendWorldPage(world, player, i)); } @Override @@ -196,162 +194,137 @@ public void onInventoryClick(InventoryClickEvent event) { event.setCancelled(true); } }); - return true; + return; } - if (TabCompleteUtil.isCommand(field, "type")) { - Optional parse = EnumUtil.parse(value, NightSelection.NightSelectionType.class); - if (parse.isEmpty()) { - messageSender().sendLocalizedError(sender, "error.invalidValue"); - return true; - } - sel.setNightSelectionType(parse.get()); + if (Completion.isCommand(field, "type")) { + sel.setNightSelectionType(value.asEnum(NightSelectionType.class)); configuration.save(); - optPage.ifPresent(p -> sendWorldPage(world, sender, p)); - return true; + optPage.ifPresent(p -> sendWorldPage(world, player, p)); } - return true; } private void sendWorldPage(World world, CommandSender sender, int p) { - TextComponent page = CommandUtil.getPage(configuration.getWorldSettings().values(), p, 3, 4, s -> { + String page = CommandUtil.getPage(configuration.getWorldSettings().values(), p, 3, 4, s -> { NightSelection ns = s.getNightSelection(); String cmd = "/bloodnight nightSelection " + ArgumentUtils.escapeWorldName(s.getWorldName()) + " "; + String type = switch (ns.getNightSelectionType()) { + case RANDOM -> """ + %s + + + """.stripIndent() + .formatted(changeableValue("field.probability", ns.getProbability(), cmd + "probability ")); + case REAL_MOON_PHASE, MOON_PHASE -> { + var phases = ns.getMoonPhase().entrySet().stream().map(e -> { + var hover = """ + %s %s + %s + %s + %s: %s + """.stripIndent() + .formatted(escape("field.moonPhase"), e.getKey(), + escape(getMoonPhaseName(e.getKey())), + getMoonPhaseSign(e.getKey()), + escape("field.probability"), e.getValue()); + return "| %s:%s |".formatted(hover, e.getKey(), e.getValue()); + }).toList(); + yield """ + %s: %s + %s + """.stripIndent() + .formatted( + escape("field.moonPhase"), changeButton(cmd + "moonPhase none"), + String.join(" ", phases) + ); + } + case INTERVAL -> """ + %s + %s + """.stripIndent() + .formatted( + changeableValue("field.interval", ns.getInterval(), cmd + "interval "), + changeableValue("field.intervalProbability", ns.getIntervalProbability(), cmd + "intervalProbability ") + ); + case PHASE -> """ + %s + %s %s + """.stripIndent() + .formatted( + changeableValue("field.amount", ns.getPhaseCustom().size(), cmd + "phaseAmount "), + escape("field.amount"), changeButton(cmd + "phase none ") + ); + case CURVE -> """ + """.stripIndent() + .formatted( + changeableValue("field.length", ns.getPeriod(), cmd + "period "), + changeableValue("field.minProb", ns.getMinCurveVal(), cmd + "minCurveVal "), + changeableValue("field.maxProb", ns.getMaxCurveVal(), cmd + "maxCurveVal ") + ); + }; + + var a = """ + %s + %s: + %s %s %s %s %s %s + """.stripIndent() + .formatted( + s.getWorldName(), + // Night selection + escape("field.nightSelectionType"), + // Types + getToggleField(ns.getNightSelectionType() == RANDOM, cmd + "type random", "state.random"), + getToggleField(ns.getNightSelectionType() == MOON_PHASE, cmd + "type moon_phase", "state.moonPhase"), + getToggleField(ns.getNightSelectionType() == REAL_MOON_PHASE, cmd + "type real_moon_phase", "state.realMoonPhase"), + getToggleField(ns.getNightSelectionType() == INTERVAL, cmd + "type interval", "state.interval"), + getToggleField(ns.getNightSelectionType() == INTERVAL, cmd + "type interval", "state.interval"), + getToggleField(ns.getNightSelectionType() == PHASE, cmd + "type phase", "state.phase"), + getToggleField(ns.getNightSelectionType() == CURVE, cmd + "type curve", "state.curve") + ); TextComponent.Builder builder = Component.text() .append(Component.text(s.getWorldName(), NamedTextColor.GOLD, TextDecoration.BOLD)) .append(Component.newline()) .append(Component.text(localizer().getMessage("field.nightSelectionType") + ":", NamedTextColor.AQUA)) .append(Component.newline()) - .append(CommandUtil.getToggleField(ns.getNightSelectionType() == NightSelection.NightSelectionType.RANDOM, - cmd + "type random", - localizer().getMessage("state.random"))) - .append(Component.space()) - .append(CommandUtil.getToggleField(ns.getNightSelectionType() == NightSelection.NightSelectionType.MOON_PHASE, - cmd + "type moon_phase", - localizer().getMessage("state.moonPhase"))) - .append(Component.space()) - .append(CommandUtil.getToggleField(ns.getNightSelectionType() == NightSelection.NightSelectionType.REAL_MOON_PHASE, - cmd + "type real_moon_phase", - localizer().getMessage("state.realMoonPhase"))) - .append(Component.space()) - .append(CommandUtil.getToggleField(ns.getNightSelectionType() == NightSelection.NightSelectionType.INTERVAL, - cmd + "type interval", - localizer().getMessage("state.interval"))) - .append(Component.space()) - .append(CommandUtil.getToggleField(ns.getNightSelectionType() == NightSelection.NightSelectionType.PHASE, - cmd + "type phase", - localizer().getMessage("state.phase"))) - .append(Component.space()) - .append(CommandUtil.getToggleField(ns.getNightSelectionType() == NightSelection.NightSelectionType.CURVE, - cmd + "type curve", - localizer().getMessage("state.curve"))) .append(Component.space()) .append(Component.newline()); - switch (ns.getNightSelectionType()) { - case RANDOM -> - builder.append(Component.text(localizer().getMessage("field.probability") + ": ", NamedTextColor.AQUA)) - .append(Component.text(ns.getProbability(), NamedTextColor.GOLD)) - .append(Component.text(" [" + localizer().getMessage("action.change") + "]", NamedTextColor.GREEN) - .clickEvent(ClickEvent.suggestCommand(cmd + "probability "))) - .append(Component.newline()) - .append(Component.newline()); - case REAL_MOON_PHASE, MOON_PHASE -> { - builder.append(Component.text(localizer().getMessage("field.moonPhase") + ": ", NamedTextColor.AQUA)) - .append(Component.text(" [" + localizer().getMessage("action.change") + "]", NamedTextColor.GREEN) - .clickEvent(ClickEvent.runCommand(cmd + "moonPhase none"))) - .append(Component.newline()); - ns.getMoonPhase().forEach((key, value) -> - builder.append(Component.text("| " + key + ":" + value + " |", NamedTextColor.GOLD) - .hoverEvent( - HoverEvent.showText( - Component.text() - .append(Component.text(localizer().getMessage("field.moonPhase") + " " + key, NamedTextColor.GOLD)) - .append(Component.newline()) - .append(Component.text(localizer().getMessage(getMoonPhaseName(key)), NamedTextColor.AQUA)) - .append(Component.newline()) - .append(Component.text(getMoonPhaseSign(key))) - .append(Component.newline()) - .append(Component.text(localizer().getMessage("field.probability") + ": " + value, NamedTextColor.GREEN)) - .build() - ) - ) - )); - builder.append(Component.newline()); - } - case INTERVAL -> - builder.append(Component.text(localizer().getMessage("field.interval") + ": ", NamedTextColor.AQUA)) - .append(Component.text(ns.getInterval(), NamedTextColor.GOLD)) - .append(Component.text(" [" + localizer().getMessage("action.change") + "]", NamedTextColor.GREEN) - .clickEvent(ClickEvent.suggestCommand(cmd + "interval "))) - .append(Component.newline()) - .append(Component.text(localizer().getMessage("field.intervalProbability") + ": ", NamedTextColor.AQUA)) - .append(Component.text(ns.getIntervalProbability(), NamedTextColor.GOLD)) - .append(Component.text(" [" + localizer().getMessage("action.change") + "]", NamedTextColor.GREEN) - .clickEvent(ClickEvent.suggestCommand(cmd + "intervalProbability "))) - .append(Component.newline()); - case PHASE -> - builder.append(Component.text(localizer().getMessage("field.amount") + ": ", NamedTextColor.AQUA)) - .append(Component.text(ns.getPhaseCustom().size(), NamedTextColor.GOLD)) - .append(Component.text(" [" + localizer().getMessage("action.change") + "]", NamedTextColor.GREEN) - .clickEvent(ClickEvent.suggestCommand(cmd + "phaseAmount "))) - .append(Component.newline()) - .append(Component.text(localizer().getMessage("field.phase") + ": ", NamedTextColor.AQUA)) - .append(Component.text(" [" + localizer().getMessage("action.change") + "]", NamedTextColor.GREEN) - .clickEvent(ClickEvent.runCommand(cmd + "phase none"))) - .append(Component.newline()); - case CURVE -> - builder.append(Component.text(localizer().getMessage("field.length") + ": ", NamedTextColor.AQUA)) - .append(Component.text(ns.getPeriod(), NamedTextColor.GOLD)) - .append(Component.text(" [" + localizer().getMessage("action.change") + "]", NamedTextColor.GREEN) - .clickEvent(ClickEvent.suggestCommand(cmd + "period "))) - .append(Component.newline()) - .append(Component.text(localizer().getMessage("field.minProb") + ": ", NamedTextColor.AQUA)) - .append(Component.text(ns.getMinCurveVal(), NamedTextColor.GOLD)) - .append(Component.text(" [" + localizer().getMessage("action.change") + "]", NamedTextColor.GREEN) - .clickEvent(ClickEvent.suggestCommand(cmd + "minCurveVal "))) - .append(Component.newline()) - .append(Component.text(localizer().getMessage("field.maxProb") + ": ", NamedTextColor.AQUA)) - .append(Component.text(ns.getMaxCurveVal(), NamedTextColor.GOLD)) - .append(Component.text(" [" + localizer().getMessage("action.change") + "]", NamedTextColor.GREEN) - .clickEvent(ClickEvent.suggestCommand(cmd + "maxCurveVal "))); - } - return builder.build(); - }, localizer().getMessage("nightSelection.title.menu"), + return a; + }, "nightSelection.title.menu", "/bloodnight nightSelection " + ArgumentUtils.escapeWorldName(world) + " page {page}"); - bukkitAudiences.sender(sender).sendMessage(page); + messageSender().sendMessage(sender, page, Replacement.create("world", world)); } @Override - public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { - if (args.length == 1) { - return TabCompleteUtil.completeWorlds(args[0]); + public @Nullable List onTabComplete(@NotNull Player player, @NotNull String alias, @NotNull Arguments args) throws CommandException { + if (args.size() == 1) { + return Completion.completeWorlds(args.asString(0)); } - if (args.length == 2) { - return TabCompleteUtil.complete(args[1], "interval", "intervalProbability", "probability", "moonPhase", "type"); + if (args.size() == 2) { + return Completion.complete(args.asString(1), "interval", "intervalProbability", "probability", "moonPhase", "type"); } - String field = args[1]; - String value = args[2]; - if (TabCompleteUtil.isCommand(field, "interval")) { - return TabCompleteUtil.completeInt(value, 1, 100, localizer()); + String field = args.asString(1); + String value = args.asString(2); + if (Completion.isCommand(field, "interval")) { + return Completion.completeInt(value, 1, 100); } - if (TabCompleteUtil.isCommand(field, "intervalProbability", "probability", "minCurveVal", "maxCurveVal")) { - return TabCompleteUtil.completeInt(value, 0, 100, localizer()); + if (Completion.isCommand(field, "intervalProbability", "probability", "minCurveVal", "maxCurveVal")) { + return Completion.completeInt(value, 0, 100); } - if (TabCompleteUtil.isCommand(field, "phaseAmount")) { - return TabCompleteUtil.completeInt(value, 0, 54, localizer()); + if (Completion.isCommand(field, "phaseAmount")) { + return Completion.completeInt(value, 0, 54); } - if (TabCompleteUtil.isCommand(field, "period")) { - return TabCompleteUtil.completeInt(value, 3, 100, localizer()); + if (Completion.isCommand(field, "period")) { + return Completion.completeInt(value, 3, 100); } - if (TabCompleteUtil.isCommand(field, "moonPhase", "phase")) { + if (Completion.isCommand(field, "moonPhase", "phase")) { return Collections.emptyList(); } - if (TabCompleteUtil.isCommand(field, "type")) { - return TabCompleteUtil.complete(value, NightSelection.NightSelectionType.class); + if (Completion.isCommand(field, "type")) { + return Completion.complete(value, NightSelectionType.class); } return Collections.emptyList(); } @@ -371,7 +344,7 @@ private static ItemStack toPhaseItem(Map.Entry entry, boolean ItemStack stack = new ItemStack(Material.FIREWORK_STAR, phase); ItemMeta itemMeta = stack.getItemMeta(); itemMeta.setDisplayName("§2" + localizer.getMessage("phaseItem.phase") + ": " + phase - + (moon ? " (" + localizer.getMessage(getMoonPhaseName(entry.getKey())) + ")" : "")); + + (moon ? " (" + localizer.getMessage(getMoonPhaseName(entry.getKey())) + ")" : "")); itemMeta.setLore(getLore(entry.getKey(), entry.getValue(), moon)); PersistentDataContainer container = itemMeta.getPersistentDataContainer(); container.set(PROBABILITY, PersistentDataType.INTEGER, entry.getValue()); diff --git a/BloodNight-core/src/main/java/de/eldoria/bloodnight/config/Configuration.java b/BloodNight-core/src/main/java/de/eldoria/bloodnight/config/Configuration.java index 387503fa..9c7801b5 100644 --- a/BloodNight-core/src/main/java/de/eldoria/bloodnight/config/Configuration.java +++ b/BloodNight-core/src/main/java/de/eldoria/bloodnight/config/Configuration.java @@ -63,7 +63,7 @@ protected void reloadConfigs() { BloodNight.logger().info("§2Migration of config to v2 done."); } - generalSettings = getMainConfig().getConfig().getObject("generalSettings", GeneralSettings.class); + generalSettings = getMainConfig(plugin).getConfig().getObject("generalSettings", GeneralSettings.class); for (World world : Bukkit.getWorlds()) { loadWorldSettings(world.getName(), true); @@ -82,8 +82,8 @@ private void initV2() { private void migrateToV2() { setVersion(2, false); - getMainConfig().getConfig().set("updateReminder", null); - List worldList = ObjUtil.nonNull((List) getMainConfig().getConfig().get("worldSettings", new ArrayList<>()), new ArrayList<>()); + getMainConfig(plugin).getConfig().set("updateReminder", null); + List worldList = ObjUtil.nonNull((List) getMainConfig(plugin).getConfig().get("worldSettings", new ArrayList<>()), new ArrayList<>()); Path worldSettings = Paths.get(plugin.getDataFolder().toPath().toString(), "worldSettings"); @@ -94,7 +94,7 @@ private void migrateToV2() { }, true); BloodNight.logger().info("§2Migrated settings for " + settings.getWorldName()); } - getMainConfig().getConfig().set("worldSettings", null); + getMainConfig(plugin).getConfig().set("worldSettings", null); } private @NotNull @@ -119,7 +119,7 @@ WorldSettings loadWorldSettings(String world, boolean reload) { @Override protected void saveConfigs() { - getMainConfig().getConfig().set("generalSettings", generalSettings); + getMainConfig(plugin).getConfig().set("generalSettings", generalSettings); for (Map.Entry entry : worldSettings.entrySet()) { ObjUtil.nonNull(loadConfig(getWorldConfigPath(entry.getKey()), null, false), diff --git a/BloodNight-core/src/main/java/de/eldoria/bloodnight/core/manager/NotificationManager.java b/BloodNight-core/src/main/java/de/eldoria/bloodnight/core/manager/NotificationManager.java index d93c1f56..927797dd 100644 --- a/BloodNight-core/src/main/java/de/eldoria/bloodnight/core/manager/NotificationManager.java +++ b/BloodNight-core/src/main/java/de/eldoria/bloodnight/core/manager/NotificationManager.java @@ -7,8 +7,9 @@ import de.eldoria.bloodnight.events.BloodNightEndEvent; import de.eldoria.bloodnight.hooks.HookService; import de.eldoria.eldoutilities.localization.ILocalizer; -import de.eldoria.eldoutilities.localization.Replacement; import de.eldoria.eldoutilities.messages.MessageSender; +import de.eldoria.eldoutilities.messages.Replacement; +import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; @@ -20,6 +21,9 @@ import java.util.Collection; +import static java.time.Duration.ofSeconds; +import static net.kyori.adventure.title.Title.Times.times; + public class NotificationManager implements Listener { private final ILocalizer localizer; private final NightManager nightManager; @@ -38,20 +42,20 @@ public NotificationManager(Configuration configuration, NightManager nightManage @EventHandler(priority = EventPriority.MONITOR) public void onBloodNightEnd(BloodNightEndEvent event) { dispatchBroadcast(event.getWorld(), - localizer.getMessage("notify.nightEnd", - Replacement.create("WORLD", getAlias(event.getWorld())).addFormatting('6')) + "notify.nightEnd", + Replacement.create("WORLD", getAlias(event.getWorld())) ); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBloodNightStart(BloodNightBeginEvent event) { dispatchBroadcast(event.getWorld(), - localizer.getMessage("notify.nightStart", - Replacement.create("WORLD", getAlias(event.getWorld())).addFormatting('6')) + "notify.nightStart", + Replacement.create("WORLD", getAlias(event.getWorld())) ); } - private void dispatchBroadcast(World world, String message) { + private void dispatchBroadcast(World world, String message, TagResolver... tagResolver) { Collection players; switch (configuration.getGeneralSettings().getBroadcastLevel()) { case SERVER: @@ -68,16 +72,18 @@ private void dispatchBroadcast(World world, String message) { for (Player player : players) { - sendBroadcast(player, message); + sendBroadcast(player, message, tagResolver); } } - private void sendBroadcast(Player player, String message) { + private void sendBroadcast(Player player, String message, TagResolver... tagResolver) { String m = "§a" + message.replace("§r", "§r§a"); switch (configuration.getGeneralSettings().getBroadcastMethod()) { - case CHAT -> messageSender.sendMessage(player, message); - case TITLE -> player.sendTitle(m, "", 10, 70, 20); - case SUBTITLE -> player.sendTitle("", m, 10, 70, 20); + case CHAT -> messageSender.sendMessage(player, message, tagResolver); + case TITLE -> + messageSender.sendTitle(player, m, "", times(ofSeconds(1), ofSeconds(5), ofSeconds(1)), tagResolver); + case SUBTITLE -> + messageSender.sendTitle(player, "", m, times(ofSeconds(1), ofSeconds(5), ofSeconds(1)), tagResolver); } } diff --git a/BloodNight-core/src/main/java/de/eldoria/bloodnight/core/manager/mobmanager/MobManager.java b/BloodNight-core/src/main/java/de/eldoria/bloodnight/core/manager/mobmanager/MobManager.java index e33518b6..8623a0c3 100644 --- a/BloodNight-core/src/main/java/de/eldoria/bloodnight/core/manager/mobmanager/MobManager.java +++ b/BloodNight-core/src/main/java/de/eldoria/bloodnight/core/manager/mobmanager/MobManager.java @@ -14,11 +14,11 @@ import de.eldoria.bloodnight.hooks.mythicmobs.MythicMobUtil; import de.eldoria.bloodnight.specialmobs.SpecialMob; import de.eldoria.bloodnight.specialmobs.SpecialMobUtil; -import de.eldoria.eldoutilities.entityutils.ProjectileSender; -import de.eldoria.eldoutilities.entityutils.ProjectileUtil; +import de.eldoria.eldoutilities.entities.projectiles.ProjectileSender; +import de.eldoria.eldoutilities.entities.projectiles.ProjectileUtil; +import de.eldoria.eldoutilities.pdc.DataContainerUtil; import de.eldoria.eldoutilities.scheduling.DelayedActions; import de.eldoria.eldoutilities.threading.IteratingTask; -import de.eldoria.eldoutilities.utils.DataContainerUtil; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.World; diff --git a/BloodNight-core/src/main/java/de/eldoria/bloodnight/core/manager/mobmanager/SpecialMobManager.java b/BloodNight-core/src/main/java/de/eldoria/bloodnight/core/manager/mobmanager/SpecialMobManager.java index a1914fb9..7bade7d0 100644 --- a/BloodNight-core/src/main/java/de/eldoria/bloodnight/core/manager/mobmanager/SpecialMobManager.java +++ b/BloodNight-core/src/main/java/de/eldoria/bloodnight/core/manager/mobmanager/SpecialMobManager.java @@ -10,8 +10,8 @@ import de.eldoria.bloodnight.hooks.mythicmobs.MythicMobUtil; import de.eldoria.bloodnight.specialmobs.SpecialMob; import de.eldoria.bloodnight.specialmobs.SpecialMobUtil; -import de.eldoria.eldoutilities.entityutils.ProjectileSender; -import de.eldoria.eldoutilities.entityutils.ProjectileUtil; +import de.eldoria.eldoutilities.entities.projectiles.ProjectileSender; +import de.eldoria.eldoutilities.entities.projectiles.ProjectileUtil; import de.eldoria.eldoutilities.threading.IteratingTask; import lombok.NonNull; import org.bukkit.World; @@ -20,10 +20,23 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.entity.*; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.event.entity.EntityTeleportEvent; +import org.bukkit.event.entity.ExplosionPrimeEvent; +import org.bukkit.event.entity.ProjectileHitEvent; +import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.scheduler.BukkitRunnable; -import java.util.*; +import java.util.ArrayDeque; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.Queue; +import java.util.UUID; public class SpecialMobManager extends BukkitRunnable implements Listener { private final Map mobRegistry = new HashMap<>(); diff --git a/BloodNight-core/src/main/java/de/eldoria/bloodnight/core/manager/nightmanager/CommandBlocker.java b/BloodNight-core/src/main/java/de/eldoria/bloodnight/core/manager/nightmanager/CommandBlocker.java index 9b480662..7fce5ba6 100644 --- a/BloodNight-core/src/main/java/de/eldoria/bloodnight/core/manager/nightmanager/CommandBlocker.java +++ b/BloodNight-core/src/main/java/de/eldoria/bloodnight/core/manager/nightmanager/CommandBlocker.java @@ -25,7 +25,7 @@ public void onCommandPreprocessEvent(PlayerCommandPreprocessEvent event) { if (!nightManager.isBloodNightActive(event.getPlayer().getWorld())) return; if (isBlocked(event.getMessage()) && !event.getPlayer().hasPermission(Permissions.Bypass.COMMAND_BLOCK)) { - sender.sendLocalizedError(event.getPlayer(), "error.commandBlocked"); + sender.sendError(event.getPlayer(), "error.commandBlocked"); event.setCancelled(true); } } diff --git a/BloodNight-core/src/main/java/de/eldoria/bloodnight/core/manager/nightmanager/NightManager.java b/BloodNight-core/src/main/java/de/eldoria/bloodnight/core/manager/nightmanager/NightManager.java index 4f29ba0b..3e753813 100644 --- a/BloodNight-core/src/main/java/de/eldoria/bloodnight/core/manager/nightmanager/NightManager.java +++ b/BloodNight-core/src/main/java/de/eldoria/bloodnight/core/manager/nightmanager/NightManager.java @@ -14,9 +14,9 @@ import de.eldoria.bloodnight.events.BloodNightEndEvent; import de.eldoria.bloodnight.specialmobs.SpecialMobUtil; import de.eldoria.bloodnight.util.C; -import de.eldoria.eldoutilities.core.EldoUtilities; import de.eldoria.eldoutilities.localization.ILocalizer; import de.eldoria.eldoutilities.messages.MessageSender; +import de.eldoria.eldoutilities.scheduling.DelayedActions; import de.eldoria.eldoutilities.utils.ObjUtil; import org.bukkit.Bukkit; import org.bukkit.GameRule; @@ -30,14 +30,27 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.*; +import org.bukkit.event.player.PlayerBedEnterEvent; +import org.bukkit.event.player.PlayerChangedWorldEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitRunnable; -import java.util.*; +import java.util.ArrayDeque; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Queue; +import java.util.Set; import java.util.concurrent.ThreadLocalRandom; public class NightManager extends BukkitRunnable implements Listener { @@ -57,6 +70,7 @@ public class NightManager extends BukkitRunnable implements Listener { private final PluginManager pluginManager = Bukkit.getPluginManager(); private final ILocalizer localizer; private final MessageSender messageSender; + private final DelayedActions delayedActions; private TimeManager timeManager; private SoundManager soundManager; @@ -67,6 +81,7 @@ public NightManager(Plugin plugin, Configuration configuration) { this.configuration = configuration; this.localizer = ILocalizer.getPluginLocalizer(BloodNight.class); this.messageSender = MessageSender.getPluginMessageSender(BloodNight.class); + this.delayedActions = DelayedActions.start(plugin); reload(); } @@ -315,7 +330,7 @@ public void onPlayerDeath(PlayerDeathEvent event) { event.setDroppedExp(0); } - EldoUtilities.getDelayedActions().schedule(() -> { + delayedActions.schedule(() -> { for (String deathCommand : actions.getDeathCommands()) { Bukkit.dispatchCommand(Bukkit.getConsoleSender(), deathCommand.replace("{player}", event.getEntity().getName())); } @@ -333,7 +348,7 @@ public void onPlayerRespawn(PlayerRespawnEvent event) { .getDeathActionSettings() .getPlayerDeathActions(); - EldoUtilities.getDelayedActions().schedule(() -> { + delayedActions.schedule(() -> { for (PotionEffectSettings value : actions.getRespawnEffects().values()) { player.addPotionEffect(new PotionEffect(value.getEffectType(), value.getDuration() * 20, 1, false)); } diff --git a/BloodNight-core/src/main/java/de/eldoria/bloodnight/specialmobs/mobs/creeper/GhostCreeper.java b/BloodNight-core/src/main/java/de/eldoria/bloodnight/specialmobs/mobs/creeper/GhostCreeper.java index a8d2e6e3..ba1bf01b 100644 --- a/BloodNight-core/src/main/java/de/eldoria/bloodnight/specialmobs/mobs/creeper/GhostCreeper.java +++ b/BloodNight-core/src/main/java/de/eldoria/bloodnight/specialmobs/mobs/creeper/GhostCreeper.java @@ -3,8 +3,8 @@ import de.eldoria.bloodnight.core.BloodNight; import de.eldoria.bloodnight.specialmobs.SpecialMobUtil; import de.eldoria.bloodnight.specialmobs.mobs.ExtendedSpecialMob; -import de.eldoria.eldoutilities.container.Triple; import de.eldoria.eldoutilities.crossversion.ServerVersion; +import de.eldoria.eldoutilities.utils.Version; import org.bukkit.entity.Creeper; import org.bukkit.entity.EntityType; import org.bukkit.entity.Vex; @@ -13,26 +13,14 @@ import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitRunnable; -import java.util.Optional; - public class GhostCreeper extends ExtendedSpecialMob { private boolean legacy = false; public GhostCreeper(Creeper creeper) { super(EntityType.VEX, creeper); - Optional> optVersion = ServerVersion.extractVersion(); + Version optVersion = ServerVersion.getVersion(); // Entites can be invisible since 1.16.3. Hotfix for backwards compatibiliy to spigot 1.16.2 - if (optVersion.isPresent()) { - Triple version = optVersion.get(); - if (version.second >= 16 && version.third > 2) { - getBaseEntity().setInvisible(true); - } else { - legacy = true; - } - } else { - legacy = true; - } getBaseEntity().setInvulnerable(true); new BukkitRunnable() { @Override