Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/util migration #212

Merged
merged 23 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0dd4f89
Start migration to v2
rainbowdashlabs Feb 25, 2024
d9abfba
Refactor BloodNight commands and utils
rainbowdashlabs Feb 25, 2024
3fcfe6a
Refactor BloodNight commands and utils
rainbowdashlabs Feb 25, 2024
64b0884
Add new utility methods in CommandUtil
rainbowdashlabs Feb 25, 2024
321299f
Refactor ManageMobs command handling and command utilities
rainbowdashlabs Feb 25, 2024
c006c59
Refactor command handling in ManageMobs and simplify utility methods
rainbowdashlabs Feb 25, 2024
9f82383
Change some language codes
rainbowdashlabs Feb 26, 2024
b8ddea9
Use constants for text color
rainbowdashlabs Feb 26, 2024
471e756
Add default error color
rainbowdashlabs Feb 26, 2024
f262737
Merge remote-tracking branch 'origin/development' into feature/util-m…
rainbowdashlabs Feb 26, 2024
487d665
Add color tags to locale files
rainbowdashlabs Feb 26, 2024
72f981c
Fix startup errors
rainbowdashlabs Feb 26, 2024
49453af
Adjust help command
rainbowdashlabs Feb 26, 2024
8d28790
Fix wrong color formatting and messages
rainbowdashlabs Feb 26, 2024
1ae19b5
Remove unused imports
rainbowdashlabs Feb 26, 2024
d968cfb
Remove legacy boolean
rainbowdashlabs Feb 26, 2024
247f254
Switch to stable util version
rainbowdashlabs Feb 26, 2024
9a885e9
Remove unused import
rainbowdashlabs Feb 26, 2024
34777ee
Fix some formatting issues
rainbowdashlabs Mar 6, 2024
ed28953
Cancel pickup and remove item modification
rainbowdashlabs Mar 10, 2024
34a861f
Fix wrong formatted about command
rainbowdashlabs Mar 10, 2024
04f29c2
Switch to stable util version
rainbowdashlabs Mar 10, 2024
1bfa5bc
Merge branch 'development' into feature/util-migration
rainbowdashlabs Mar 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion BloodNight-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {

dependencies {
implementation(project(":BloodNight-api"))
implementation("de.eldoria", "eldo-util", "1.10.2-SNAPSHOT")
implementation(libs.bundles.eldoutil)
implementation("net.kyori", "adventure-platform-bukkit", "4.3.2")
testImplementation("org.junit.jupiter", "junit-jupiter-api", "5.10.2")
testImplementation("junit", "junit", "4.13.2")
Expand Down Expand Up @@ -62,6 +62,8 @@ publishing {
tasks {
shadowJar {
relocate("de.eldoria.eldoutilities", shadebase + "eldoutilities")
relocate("org.bstats", shadebase + "bstats")

relocate("net.kyori", shadebase + "kyori")
mergeServiceFiles()
archiveBaseName.set(project.parent?.name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
package de.eldoria.bloodnight.command;

import de.eldoria.bloodnight.command.bloodnight.*;
import de.eldoria.bloodnight.command.bloodnight.CancelNight;
import de.eldoria.bloodnight.command.bloodnight.ForceNight;
import de.eldoria.bloodnight.command.bloodnight.Help;
import de.eldoria.bloodnight.command.bloodnight.ManageDeathActions;
import de.eldoria.bloodnight.command.bloodnight.ManageMob;
import de.eldoria.bloodnight.command.bloodnight.ManageMobs;
import de.eldoria.bloodnight.command.bloodnight.ManageNight;
import de.eldoria.bloodnight.command.bloodnight.ManageNightSelection;
import de.eldoria.bloodnight.command.bloodnight.ManageWorlds;
import de.eldoria.bloodnight.command.bloodnight.Reload;
import de.eldoria.bloodnight.command.bloodnight.SpawnMob;
import de.eldoria.bloodnight.config.Configuration;
import de.eldoria.bloodnight.core.manager.mobmanager.MobManager;
import de.eldoria.bloodnight.core.manager.nightmanager.NightManager;
import de.eldoria.bloodnight.util.Permissions;
import de.eldoria.eldoutilities.simplecommands.EldoCommand;
import de.eldoria.eldoutilities.simplecommands.commands.DefaultDebug;
import de.eldoria.eldoutilities.commands.command.AdvancedCommand;
import de.eldoria.eldoutilities.commands.command.CommandMeta;
import de.eldoria.eldoutilities.commands.defaultcommands.DefaultAbout;
import de.eldoria.eldoutilities.commands.defaultcommands.DefaultDebug;
import org.bukkit.plugin.Plugin;

public class BloodNightCommand extends EldoCommand {
public class BloodNightCommand extends AdvancedCommand {

public BloodNightCommand(Configuration configuration, Plugin plugin,
NightManager nightManager, MobManager mobManager, InventoryListener inventoryListener) {
super(plugin);
Help help = new Help(plugin);
setDefaultCommand(help);
registerCommand("help", help);
registerCommand("about", new About(plugin));
registerCommand("spawnMob", new SpawnMob(plugin, nightManager, mobManager));
registerCommand("cancelNight", new CancelNight(plugin, nightManager, configuration));
registerCommand("forceNight", new ForceNight(plugin, nightManager, configuration));
registerCommand("manageWorlds", new ManageWorlds(plugin, configuration));
registerCommand("manageMob", new ManageMob(plugin, configuration, inventoryListener));
registerCommand("manageNight", new ManageNight(plugin, configuration));
registerCommand("manageMobs", new ManageMobs(plugin, configuration, inventoryListener));
registerCommand("nightSelection", new ManageNightSelection(plugin, configuration, inventoryListener));
registerCommand("deathActions", new ManageDeathActions(plugin, configuration));
registerCommand("reload", new Reload(plugin));
registerCommand("debug", new DefaultDebug(plugin, Permissions.Admin.RELOAD));
meta(CommandMeta.builder("bloodnight")
.withDefaultCommand(help)
.withSubCommand(help)
.withSubCommand(new DefaultAbout(plugin, "https://bn.discord.eldoria.de", "commands.about"))
.withSubCommand(new SpawnMob(plugin, nightManager, mobManager))
.withSubCommand(new CancelNight(plugin, nightManager, configuration))
.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()
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
import de.eldoria.bloodnight.config.Configuration;
import de.eldoria.bloodnight.core.manager.nightmanager.NightManager;
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.utils.ArgumentUtils;
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.Argument;
import de.eldoria.eldoutilities.commands.command.util.Arguments;
import de.eldoria.eldoutilities.commands.command.util.CommandAssertions;
import de.eldoria.eldoutilities.commands.exceptions.CommandException;
import de.eldoria.eldoutilities.commands.executor.ITabExecutor;
import de.eldoria.eldoutilities.messages.Replacement;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
Expand All @@ -18,60 +22,42 @@
import java.util.Collections;
import java.util.List;

public class CancelNight extends EldoCommand {
public class CancelNight extends AdvancedCommand implements ITabExecutor {
private final NightManager nightManager;
private final Configuration configuration;

public CancelNight(Plugin plugin, NightManager nightManager, Configuration configuration) {
super(plugin);
super(plugin, CommandMeta.builder("cancelNight")
.withPermission(Permissions.Admin.CANCEL_NIGHT)
.addArgument("syntax.worldName", false)
.build());
this.nightManager = nightManager;
this.configuration = configuration;
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (denyAccess(sender, Permissions.Admin.CANCEL_NIGHT)) {
return true;
}

public void onCommand(@NotNull CommandSender sender, @NotNull String alias, @NotNull Arguments args) throws CommandException {
World world = null;
if (sender instanceof Player player) {
world = player.getWorld();
} else {
if (argumentsInvalid(sender, args, 1, "[" + localizer().getMessage("syntax.worldName") + "]")) {
return true;
}
CommandAssertions.invalidArguments(args, Argument.input("syntax.worldName", true));
}

world = ArgumentUtils.getOrDefault(args, 0, ArgumentUtils::getWorld, world);

if (world == null) {
messageSender().sendError(sender, localizer().getMessage("error.invalidWorld"));
return true;
}
world = args.asWorld(0, world);

boolean enabled = configuration.getWorldSettings(world).isEnabled();
if (!enabled) {
messageSender().sendLocalizedError(sender, "error.worldNotEnabled",
Replacement.create("WORLD", world.getName(), '6'));
return true;
}
if (nightManager.isBloodNightActive(world)) {
nightManager.cancelNight(world);
messageSender().sendMessage(sender, localizer().getMessage("cancelNight.canceled",
Replacement.create("WORLD", world.getName()).addFormatting('6')));
} else {
messageSender().sendError(sender, localizer().getMessage("cancelNight.notActive",
Replacement.create("WORLD", world.getName()).addFormatting('6')));
}
return true;
CommandAssertions.isTrue(!enabled, "error.worldNotEnabled", Replacement.create("WORLD", world));
CommandAssertions.isTrue(nightManager.isBloodNightActive(world), "cancelNight.notActive", Replacement.create("WORLD", world));
nightManager.cancelNight(world);
messageSender().sendMessage(sender, "cancelNight.canceled",
Replacement.create("WORLD", world.getName()));
}

@Override
public @Nullable List<String> 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<String> onTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull Arguments args) throws CommandException {
if (args.sizeIs(1)) {
return Completion.completeWorlds(args.asString(0));
}
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
import de.eldoria.bloodnight.config.Configuration;
import de.eldoria.bloodnight.core.manager.nightmanager.NightManager;
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.utils.ArgumentUtils;
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.Argument;
import de.eldoria.eldoutilities.commands.command.util.Arguments;
import de.eldoria.eldoutilities.commands.command.util.CommandAssertions;
import de.eldoria.eldoutilities.commands.exceptions.CommandException;
import de.eldoria.eldoutilities.commands.executor.ITabExecutor;
import de.eldoria.eldoutilities.messages.Replacement;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
Expand All @@ -18,59 +22,43 @@
import java.util.Collections;
import java.util.List;

public class ForceNight extends EldoCommand {
public class ForceNight extends AdvancedCommand implements ITabExecutor {
private final NightManager nightManager;
private final Configuration configuration;

public ForceNight(Plugin plugin, NightManager nightManager, Configuration configuration) {
super(plugin);
super(plugin, CommandMeta.builder("forceNight")
.withPermission(Permissions.Admin.FORCE_NIGHT)
.addArgument("syntax.worldName", false)
.build());
this.nightManager = nightManager;
this.configuration = configuration;
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (denyAccess(sender, Permissions.Admin.FORCE_NIGHT)) {
return true;
}

public void onCommand(@NotNull CommandSender sender, @NotNull String alias, @NotNull Arguments args) throws CommandException {
World world = null;
if (sender instanceof Player player) {
world = player.getWorld();
} else {
if (argumentsInvalid(sender, args, 1, "[" + localizer().getMessage("syntax.worldName") + "]")) {
return true;
}
CommandAssertions.invalidArguments(args, Argument.input("syntax.worldName", true));
}

world = ArgumentUtils.getOrDefault(args, 0, ArgumentUtils::getWorld, world);

if (world == null) {
messageSender().sendError(sender, localizer().getMessage("error.invalidWorld"));
return true;
}
world = args.asWorld(0, world);

boolean enabled = configuration.getWorldSettings(world).isEnabled();
if (!enabled) {
messageSender().sendError(sender, localizer().getMessage("error.worldNotEnabled",
Replacement.create("WORLD", world.getName()).addFormatting('6')));
return true;
}
if (!nightManager.getBloodWorldsSet().contains(world)) {
nightManager.forceNight(world);
messageSender().sendMessage(sender, localizer().getMessage("forceNight.enabeld",
Replacement.create("WORLD", world.getName()).addFormatting('6')));
} else {
messageSender().sendError(sender, localizer().getMessage("forceNight.alreadyActive",
Replacement.create("WORLD", world.getName()).addFormatting('6')));
}
return true;
CommandAssertions.isTrue(!enabled, "error.worldNotEnabled", Replacement.create("WORLD", world));
CommandAssertions.isTrue(!nightManager.getBloodWorldsSet().contains(world), "forceNight.alreadyActive",
Replacement.create("WORLD", world.getName()));
nightManager.forceNight(world);
messageSender().sendMessage(sender, "forceNight.enabled",
Replacement.create("WORLD", world.getName()));
}

@Override
public @Nullable List<String> 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<String> onTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull Arguments args) throws CommandException {
if (args.sizeIs(1)) {
return Completion.completeWorlds(args.asString(0));
}
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,60 @@
package de.eldoria.bloodnight.command.bloodnight;

import de.eldoria.eldoutilities.simplecommands.EldoCommand;
import org.bukkit.command.Command;
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.exceptions.CommandException;
import de.eldoria.eldoutilities.commands.executor.ITabExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collections;
import java.util.List;
import static de.eldoria.eldoutilities.localization.ILocalizer.escape;

public class Help extends EldoCommand {
public class Help extends AdvancedCommand implements ITabExecutor {
public Help(Plugin plugin) {
super(plugin);
super(plugin, CommandMeta.builder("help").build());
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
messageSender().sendMessage(sender, localizer().getMessage("help.help") + "\n"
+ "§6/bn about§r\n" + localizer().getMessage("help.about") + "\n"
+ "§6/bn forceNight§r\n" + localizer().getMessage("help.forceNight") + "\n"
+ "§6/bn cancelNight§r\n" + localizer().getMessage("help.cancelNight") + "\n"
+ "§6/bn manageMob§r\n" + localizer().getMessage("help.manageMob") + "\n"
+ "§6/bn manageMobs§r\n" + localizer().getMessage("help.manageMobs") + "\n"
+ "§6/bn manageNight§r\n" + localizer().getMessage("help.manageNight") + "\n"
+ "§6/bn manageWorlds§r\n" + localizer().getMessage("help.manageWorlds") + "\n"
+ "§6/bn nightSelection§r\n" + localizer().getMessage("help.nightSelection") + "\n"
+ "§6/bn reload§r\n" + localizer().getMessage("help.reload") + "\n"
+ "§6/bn spawnMob§r\n" + localizer().getMessage("help.spawnMob")
public void onCommand(@NotNull CommandSender sender, @NotNull String alias, @NotNull Arguments args) throws CommandException {
messageSender().sendMessage(sender, """
%s
<field>/bn about<default>
%s
<field>/bn forceNight<default>
%s
<field>/bn cancelNight<default>
%s
<field>/bn manageMob<default>
%s
<field>/bn manageMobs<default>
%s
<field>/bn manageNight<default>
%s
<field>/bn manageWorlds<default>
%s
<field>/bn nightSelection<default>
%s
<field>/bn reload<default>
%s
<field>/bn spawnMob<default>
%s
""".stripIndent()
.formatted(
escape("help.help"),
escape("help.about"),
escape("help.forceNight"),
escape("help.cancelNight"),
escape("help.manageMob"),
escape("help.manageMobs"),
escape("help.manageNight"),
escape("help.manageWorlds"),
escape("help.nightSelection"),
escape("help.reload"),
escape("help.spawnMob")
)
);
return true;
}

@Override
public @Nullable
List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}
Loading