Initial commit

This commit is contained in:
2022-01-03 22:25:23 +01:00
parent de11502f37
commit be656b4606
12 changed files with 85 additions and 303 deletions
@@ -1,14 +1,10 @@
package com.alttd.commands;
import com.alttd.VillagerUI;
import com.alttd.commands.subcommands.CommandCreateVillager;
import com.alttd.AltitudeParticles;
import com.alttd.commands.subcommands.CommandHelp;
import com.alttd.commands.subcommands.CommandReload;
import com.alttd.commands.subcommands.CommandRemoveVillager;
import com.alttd.config.Config;
import com.alttd.util.Logger;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.Template;
import org.bukkit.command.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -20,16 +16,14 @@ import java.util.stream.Collectors;
public class CommandManager implements CommandExecutor, TabExecutor {
private final List<SubCommand> subCommands;
private final MiniMessage miniMessage;
public CommandManager() {
VillagerUI villagerUI = VillagerUI.getInstance();
AltitudeParticles aPart = AltitudeParticles.getInstance();
PluginCommand command = villagerUI.getCommand("villagerui");
PluginCommand command = aPart.getCommand("apart");
if (command == null) {
subCommands = null;
miniMessage = null;
Logger.severe("Unable to find villager ui command.");
Logger.severe("Unable to find AltitudeParticles command.");
return;
}
command.setExecutor(this);
@@ -37,26 +31,23 @@ public class CommandManager implements CommandExecutor, TabExecutor {
subCommands = Arrays.asList(
new CommandHelp(this),
new CommandCreateVillager(),
new CommandReload(),
new CommandRemoveVillager());
miniMessage = MiniMessage.get();
new CommandReload());
}
@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String cmd, @NotNull String[] args) {
if (args.length == 0) {
commandSender.sendMessage(miniMessage.parse(Config.HELP_MESSAGE_WRAPPER, Template.of("commands", subCommands.stream()
commandSender.sendMiniMessage(Config.HELP_MESSAGE_WRAPPER.replaceAll("<config>", subCommands.stream()
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
.map(SubCommand::getHelpMessage)
.collect(Collectors.joining("\n")))));
.collect(Collectors.joining("\n"))), null);
return true;
}
SubCommand subCommand = getSubCommand(args[0]);
if (!commandSender.hasPermission(subCommand.getPermission())) {
commandSender.sendMessage(miniMessage.parse(Config.NO_PERMISSION));
commandSender.sendMiniMessage(Config.NO_PERMISSION, null);
return true;
}
@@ -10,7 +10,7 @@ public abstract class SubCommand {
private final MiniMessage miniMessage;
public SubCommand() {
miniMessage = MiniMessage.get();
miniMessage = MiniMessage.miniMessage();
}
public abstract boolean onCommand(CommandSender commandSender, String[] args);
@@ -3,7 +3,6 @@ package com.alttd.commands.subcommands;
import com.alttd.commands.CommandManager;
import com.alttd.commands.SubCommand;
import com.alttd.config.Config;
import net.kyori.adventure.text.minimessage.Template;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
@@ -21,10 +20,11 @@ public class CommandHelp extends SubCommand {
@Override
public boolean onCommand(CommandSender commandSender, String[] args) {
commandSender.sendMessage(getMiniMessage().parse(Config.HELP_MESSAGE_WRAPPER, Template.of("commands", commandManager.getSubCommands().stream()
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
.map(SubCommand::getHelpMessage)
.collect(Collectors.joining("\n")))));
commandSender.sendMiniMessage(Config.HELP_MESSAGE_WRAPPER.replaceAll("<commands>", commandManager
.getSubCommands().stream()
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
.map(SubCommand::getHelpMessage)
.collect(Collectors.joining("\n"))), null);
return true;
}
@@ -2,8 +2,7 @@ package com.alttd.commands.subcommands;
import com.alttd.commands.SubCommand;
import com.alttd.config.Config;
import com.alttd.config.VillagerConfig;
import com.alttd.config.WorthConfig;
import com.alttd.config.DatabaseConfig;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
@@ -14,9 +13,8 @@ public class CommandReload extends SubCommand {
@Override
public boolean onCommand(CommandSender commandSender, String[] args) {
Config.reload();
VillagerConfig.reload();
WorthConfig.reload();
commandSender.sendMessage(getMiniMessage().parse("<green>Reloaded VillagerShopUI config.</green>"));
DatabaseConfig.reload();
commandSender.sendMiniMessage("<green>Reloaded VillagerShopUI config.</green>", null);
return true;
}