Skip to content

Commit

Permalink
Feature: Util migration (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
rainbowdashlabs authored Mar 12, 2024
1 parent 00512e5 commit c4756bb
Show file tree
Hide file tree
Showing 59 changed files with 1,645 additions and 1,883 deletions.
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

0 comments on commit c4756bb

Please sign in to comment.