diff --git a/pom.xml b/pom.xml index 3600715..5d6696a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.modnmetl virtualrealty - 2.2.4 + 2.3.0 jar A plot creation and management plugin for Minecraft diff --git a/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java b/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java index 5a9cf3e..cd59ea7 100644 --- a/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java +++ b/src/main/java/com/modnmetl/virtualrealty/VirtualRealty.java @@ -1,6 +1,7 @@ package com.modnmetl.virtualrealty; import com.modnmetl.virtualrealty.commands.CommandManager; +import com.modnmetl.virtualrealty.commands.CommandRegistry; import com.modnmetl.virtualrealty.commands.SubCommand; import com.modnmetl.virtualrealty.commands.plot.PlotCommand; import com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand; @@ -61,6 +62,7 @@ public final class VirtualRealty extends JavaPlugin { public SizesConfiguration sizesConfiguration; public MessagesConfiguration messagesConfiguration; public PermissionsConfiguration permissionsConfiguration; + public CommandsConfiguration commandsConfiguration; private static ClassLoader classLoader; public static final String PREFIX = "§a§lVR §8§l» §7"; public static List tasks = new ArrayList<>(); @@ -83,6 +85,7 @@ public final class VirtualRealty extends JavaPlugin { private final File pluginConfigurationFile = new File(this.getDataFolder(), "config.yml"); private final File sizesConfigurationFile = new File(this.getDataFolder(), "sizes.yml"); private final File permissionsConfigurationFile = new File(this.getDataFolder(), "permissions.yml"); + private final File commandsConfigurationFile = new File(this.getDataFolder(), "commands.yml"); private final File languagesDirectory = new File(this.getDataFolder(), "messages"); private final File databaseFolder = new File(this.getDataFolder().getAbsolutePath(), File.separator + "data" + File.separator); private final File databaseFile = new File(databaseFolder, "data.db"); @@ -159,6 +162,7 @@ public void onEnable() { dynmapManager.registerDynmap(); } registerCommands(); + configureCommands(); registerListeners(); if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) { new VirtualPlaceholders(this).register(); @@ -173,8 +177,7 @@ public void onDisable() { Method method = Class.forName("com.modnmetl.virtualrealty.premiumloader.PremiumLoader", true, getLoader()).getMethod("onDisable"); method.setAccessible(true); method.invoke(premium); - } catch (Exception ignored) { - } + } catch (Exception ignored) {} DraftListener.DRAFT_MAP.forEach((player, gridStructureEntryEntry) -> { player.getInventory().remove(gridStructureEntryEntry.getValue().getValue().getItemStack()); player.getInventory().addItem(gridStructureEntryEntry.getValue().getKey().getItemStack()); @@ -208,6 +211,14 @@ public void configureMessages() { configFactory.loadMessagesConfiguration(messagesConfigurationFile); } + public void configureCommands() { + ConfigurationFactory configFactory = new ConfigurationFactory(); + commandsConfiguration = configFactory.loadCommandsConfiguration(commandsConfigurationFile); + commandsConfiguration.refreshHelpMessages(); + commandsConfiguration.assignAliases(); + CommandRegistry.setupPlaceholders(); + } + public void reloadConfigs() { try { ConfigurationFactory configFactory = new ConfigurationFactory(); @@ -236,7 +247,8 @@ private void registerCommands() { } public void registerSubCommands(Class mainCommandClass, String... names) { - SubCommand.registerSubCommands(names, mainCommandClass); + if (names.length > 0) + SubCommand.registerSubCommands(names, mainCommandClass); for (JarFile jarFile : jarFiles) { for (Enumeration entry = jarFile.entries(); entry.hasMoreElements();) { JarEntry jarEntry = entry.nextElement(); @@ -244,7 +256,9 @@ public void registerSubCommands(Class mainCommandClass, String... names) { if (name.endsWith(".class") && name.startsWith(mainCommandClass.getPackage().getName() + ".subcommand.")) { try { Class clazz = Class.forName(name.replaceAll("[.]class", ""), true, getClassLoader()); - SubCommand.registerSubCommands(new String[]{ clazz.getSimpleName().toLowerCase().replaceAll("subcommand", "") }, mainCommandClass); + String subcommand = clazz.getSimpleName().toLowerCase().replaceAll("subcommand", ""); + if (subcommand.isEmpty()) continue; + SubCommand.registerSubCommands(new String[]{subcommand}, mainCommandClass); } catch (ClassNotFoundException ignored) {} } } @@ -352,6 +366,10 @@ public static PermissionsConfiguration getPermissions() { return getInstance().permissionsConfiguration; } + public static CommandsConfiguration getCommands() { + return getInstance().commandsConfiguration; + } + public static DynmapManager getDynmapManager() { return getInstance().dynmapManager; } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java b/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java index a17f506..2a9fba8 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/CommandManager.java @@ -1,8 +1,10 @@ package com.modnmetl.virtualrealty.commands; +import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.plot.PlotCommand; import com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand; import com.modnmetl.virtualrealty.enums.PlotSize; +import com.modnmetl.virtualrealty.enums.commands.CommandType; import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.utils.EnumUtils; @@ -21,11 +23,23 @@ public class CommandManager implements TabCompleter { public static final HashMap, SortedSet> SUBCOMMANDS = new HashMap<>(); + public static void addSubCommand(String subCommand, Class mainCommandClass) { + if (subCommand == null || subCommand.isEmpty()) return; if (!SUBCOMMANDS.containsKey(mainCommandClass)) { SUBCOMMANDS.put(mainCommandClass, new TreeSet<>()); } SUBCOMMANDS.get(mainCommandClass).add(subCommand); + if (subCommand.equalsIgnoreCase("Panel") && VirtualRealty.getPremium() == null) return; + String className = mainCommandClass.getPackage().getName() + ".subcommand." + subCommand.replaceFirst(Character.toString(subCommand.toCharArray()[0]), Character.toString(Character.toUpperCase(subCommand.toCharArray()[0]))) + "SubCommand"; + Class subcommandClass; + try { + subcommandClass = VirtualRealty.getLoader().loadClass(className); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + String name = mainCommandClass.getPackage().getName().replaceAll("com.modnmetl.virtualrealty.commands.", "").toUpperCase(); + CommandRegistry.addSubCommandToRegistry(subcommandClass, CommandType.valueOf(name)); } @SneakyThrows diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/CommandRegistry.java b/src/main/java/com/modnmetl/virtualrealty/commands/CommandRegistry.java new file mode 100644 index 0000000..184fd10 --- /dev/null +++ b/src/main/java/com/modnmetl/virtualrealty/commands/CommandRegistry.java @@ -0,0 +1,97 @@ +package com.modnmetl.virtualrealty.commands; + +import com.modnmetl.virtualrealty.VirtualRealty; +import com.modnmetl.virtualrealty.enums.commands.CommandType; +import lombok.SneakyThrows; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Optional; + +public class CommandRegistry { + + public static final HashMap PLOT_PLACEHOLDERS = new HashMap<>(); + public static final HashMap VRPLOT_PLACEHOLDERS = new HashMap<>(); + public static final List PLOT_SUB_COMMAND_LIST = new ArrayList<>(); + public static final List VRPLOT_SUB_COMMAND_LIST = new ArrayList<>(); + + public static void setupPlaceholders() { + for (SubCommand subCommand : PLOT_SUB_COMMAND_LIST) { + PLOT_PLACEHOLDERS.put("%" + subCommand.getSubCommandClassName() + "_command%", subCommand.getSubCommandName()); + } + for (SubCommand subCommand : VRPLOT_SUB_COMMAND_LIST) { + VRPLOT_PLACEHOLDERS.put("%" + subCommand.getSubCommandClassName() + "_command%", subCommand.getSubCommandName()); + } + if (VirtualRealty.getPremium() == null) { + PLOT_PLACEHOLDERS.put("%panel_command%", "panel"); + } else { + getSubCommand("panel", CommandType.PLOT).ifPresent(subCommand -> { + PLOT_PLACEHOLDERS.put("%panel_command%", subCommand.getSubCommandName()); + }); + } + } + + @SneakyThrows + public static void addSubCommandToRegistry(Class clazz, CommandType commandType) { + if (clazz.getSimpleName().equalsIgnoreCase("SubCommand")) return; + Object newInstance = clazz.newInstance(); + switch (commandType) { + case PLOT: { + PLOT_SUB_COMMAND_LIST.add((SubCommand) newInstance); + break; + } + case VRPLOT: { + VRPLOT_SUB_COMMAND_LIST.add((SubCommand) newInstance); + break; + } + } + } + + public static Optional getSubCommand(String name, CommandType commandType) { + switch (commandType) { + case PLOT: { + return PLOT_SUB_COMMAND_LIST.stream().filter(subCommand -> + subCommand.getSubCommandClassName().equalsIgnoreCase(name) + || + (subCommand.getAlias() != null && subCommand.getAlias().equalsIgnoreCase(name)) + ).findAny(); + } + case VRPLOT: { + return VRPLOT_SUB_COMMAND_LIST.stream().filter(subCommand -> + subCommand.getSubCommandClassName().equalsIgnoreCase(name) + || + (subCommand.getAlias() != null && subCommand.getAlias().equalsIgnoreCase(name)) + ).findAny(); + } + } + return Optional.empty(); + } + + public static List getSubCommandList(CommandType commandType) { + switch (commandType) { + case VRPLOT: + return VRPLOT_SUB_COMMAND_LIST; + case PLOT: + return PLOT_SUB_COMMAND_LIST; + } + return new ArrayList<>(); + } + + @SneakyThrows + public static String getSubCommandName(String placeholder, CommandType commandType) { + Optional command = getSubCommand(placeholder.replaceAll("%", "").replaceAll("_command", ""), commandType); + return command.map(SubCommand::getSubCommandName).orElse(null); + } + + @SneakyThrows + public static List getSubCommandNames(SubCommand subCommand, CommandType commandType) { + List strings = new ArrayList<>(); + getSubCommand(subCommand.getSubCommandClassName(), commandType).ifPresent(subCommand1 -> { + strings.add(subCommand1.getSubCommandClassName()); + strings.add(subCommand1.getSubCommandName()); + }); + return strings; + } + +} diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java index 3a187c3..2e5aade 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/SubCommand.java @@ -1,8 +1,11 @@ package com.modnmetl.virtualrealty.commands; import com.modnmetl.virtualrealty.VirtualRealty; +import com.modnmetl.virtualrealty.enums.commands.CommandType; import com.modnmetl.virtualrealty.exceptions.FailedCommandException; import com.modnmetl.virtualrealty.exceptions.InsufficientPermissionsException; +import lombok.Getter; +import lombok.Setter; import lombok.SneakyThrows; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -10,6 +13,7 @@ import java.lang.reflect.Method; import java.util.LinkedList; +import java.util.Optional; import static com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand.COMMAND_PERMISSION; @@ -17,24 +21,39 @@ public abstract class SubCommand { private final String[] args; private final CommandSender commandSender; - private final LinkedList helpList; + @Getter + public LinkedList HELP_LIST; private final boolean bypass; + @Getter + @Setter + private String alias; + private String commandName; + + public SubCommand() { + this.args = null; + this.commandSender = null; + this.HELP_LIST = null; + this.bypass = false; + this.alias = null; + } @SneakyThrows - public SubCommand(CommandSender sender, Command command, String label, String[] args, boolean bypass, LinkedList helpList) throws FailedCommandException { + public SubCommand(CommandSender sender, Command command, String label, String[] args, boolean bypass, LinkedList HELP_LIST) throws FailedCommandException { this.args = args; - this.helpList = helpList; + this.HELP_LIST = HELP_LIST; this.commandSender = sender; this.bypass = bypass; + this.alias = null; exec(sender, command, label, args); } @SneakyThrows - public SubCommand(CommandSender sender, Command command, String label, String[] args, LinkedList helpList) throws FailedCommandException { + public SubCommand(CommandSender sender, Command command, String label, String[] args, LinkedList HELP_LIST) throws FailedCommandException { this.args = args; - this.helpList = helpList; + this.HELP_LIST = HELP_LIST; this.commandSender = sender; this.bypass = false; + this.alias = null; exec(sender, command, label, args); } @@ -47,6 +66,28 @@ public void assertPlayer() throws FailedCommandException { } } + public String getSubCommandClassName() { + return this.getClass().getSimpleName().replaceAll("SubCommand", "").toLowerCase(); + } + + public String getSubCommandName() { + if (this.commandName != null) return this.commandName; + Optional subCommand = CommandRegistry.getSubCommand(this.getSubCommandClassName(), getCommandType()); + if (subCommand.isPresent()) { + if (subCommand.get().getAlias() != null) { + this.commandName = subCommand.get().getAlias(); + return this.commandName; + } + } + this.commandName = this.getSubCommandClassName(); + return this.commandName; + } + + public CommandType getCommandType() { + String name = this.getClass().getPackage().getName().replaceAll("com.modnmetl.virtualrealty.commands.", "").replaceAll(".subcommand", "").toUpperCase(); + return CommandType.valueOf(name); + } + public String getDefaultPermission() { return COMMAND_PERMISSION.getName() + "." + args[0].toLowerCase(); } @@ -78,8 +119,8 @@ public boolean isBypass() { } public void printHelp() throws FailedCommandException { - for (String s : helpList) { - commandSender.sendMessage(s); + for (String s : HELP_LIST) { + commandSender.sendMessage(s.replaceAll("%command%", getSubCommandName())); } throw new FailedCommandException(); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java index 94cfecb..e20ae96 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/PlotCommand.java @@ -1,6 +1,9 @@ package com.modnmetl.virtualrealty.commands.plot; import com.modnmetl.virtualrealty.VirtualRealty; +import com.modnmetl.virtualrealty.commands.CommandRegistry; +import com.modnmetl.virtualrealty.commands.SubCommand; +import com.modnmetl.virtualrealty.enums.commands.CommandType; import com.modnmetl.virtualrealty.exceptions.FailedCommandException; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.TextComponent; @@ -13,6 +16,8 @@ import java.util.*; import java.util.logging.Level; +import static com.modnmetl.virtualrealty.commands.CommandRegistry.PLOT_SUB_COMMAND_LIST; + public class PlotCommand implements CommandExecutor { public static final LinkedList HELP_LIST = new LinkedList<>(); @@ -20,15 +25,15 @@ public class PlotCommand implements CommandExecutor { static { HELP_LIST.add(" "); HELP_LIST.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»"); - HELP_LIST.add(" §a/plot panel §8- §7Opens your plots panel"); - HELP_LIST.add(" §a/plot draft §8- §7Shows layout of potential new plot"); - HELP_LIST.add(" §a/plot stake §8- §7Creates the plot shown with draft"); - HELP_LIST.add(" §a/plot info §8- §7Shows plot info"); - HELP_LIST.add(" §a/plot gm §8- §7Changes gamemode"); - HELP_LIST.add(" §a/plot add §8- §7Adds a member"); - HELP_LIST.add(" §a/plot kick §8- §7Kicks a member"); - HELP_LIST.add(" §a/plot list §8- §7Shows your plots"); - HELP_LIST.add(" §a/plot tp §8- §7Teleports to the plot"); + HELP_LIST.add(" §a/plot %panel_command% §8- §7Opens your plots panel"); + HELP_LIST.add(" §a/plot %draft_command% §8- §7Shows layout of potential new plot"); + HELP_LIST.add(" §a/plot %stake_command% §8- §7Creates the plot shown with draft"); + HELP_LIST.add(" §a/plot %info_command% §8- §7Shows plot info"); + HELP_LIST.add(" §a/plot %gm_command% §8- §7Changes gamemode"); + HELP_LIST.add(" §a/plot %add_command% §8- §7Adds a member"); + HELP_LIST.add(" §a/plot %kick_command% §8- §7Kicks a member"); + HELP_LIST.add(" §a/plot %list_command% §8- §7Shows your plots"); + HELP_LIST.add(" §a/plot %tp_command% §8- §7Teleports to the plot"); } @Override @@ -57,14 +62,14 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } } try { - Class clazz = Class.forName("com.modnmetl.virtualrealty.commands.plot.subcommand." + String.valueOf(args[0].toCharArray()[0]).toUpperCase(Locale.ROOT) + args[0].substring(1) + "SubCommand", true, VirtualRealty.getLoader()); - clazz.getConstructors()[0].newInstance(sender, command, label, args); + String subcommandName = String.valueOf(args[0].toCharArray()[0]).toUpperCase() + args[0].substring(1); + Optional subCommand1 = CommandRegistry.getSubCommand(subcommandName.toLowerCase(), CommandType.PLOT); + subCommand1.get().getClass().getConstructors()[1].newInstance(sender, command, label, args); } catch (Exception e) { - if(!(e instanceof InvocationTargetException)) { + if (!(e instanceof InvocationTargetException)) { printHelp(sender); return false; } - if (displayError) { e.printStackTrace(); } else { @@ -80,7 +85,13 @@ public boolean onCommand(CommandSender sender, Command command, String label, St private static void printHelp(CommandSender sender) { for (String message : HELP_LIST) { - sender.sendMessage(message); + final String[] finalMessage = {message}; + CommandRegistry.PLOT_PLACEHOLDERS.forEach((s, s2) -> { + finalMessage[0] = finalMessage[0].replaceAll(s, s2); + }); + sender.sendMessage( + finalMessage[0] + ); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java index f394e17..b4cd4d1 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/AddSubCommand.java @@ -7,6 +7,7 @@ import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.objects.data.PlotMember; +import lombok.NoArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; @@ -14,18 +15,21 @@ import org.bukkit.entity.Player; import java.time.LocalDateTime; +import java.util.Arrays; import java.util.LinkedList; public class AddSubCommand extends SubCommand { - public static final LinkedList HELP = new LinkedList<>(); + public static LinkedList HELP = new LinkedList<>(); static { HELP.add(" "); HELP.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»"); - HELP.add(" §a/plot add §8<§7plot§8> §8<§7player§8>"); + HELP.add(" §a/plot %command% §8<§7plot§8> §8<§7player§8>"); } + public AddSubCommand() {} + public AddSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { super(sender, command, label, args, false, HELP); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/DraftSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/DraftSubCommand.java index 76a5d89..5bf6572 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/DraftSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/DraftSubCommand.java @@ -2,11 +2,13 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; +import com.modnmetl.virtualrealty.enums.ConfirmationType; import com.modnmetl.virtualrealty.enums.Direction; import com.modnmetl.virtualrealty.enums.PlotSize; import com.modnmetl.virtualrealty.enums.items.VItem; import com.modnmetl.virtualrealty.exceptions.FailedCommandException; import com.modnmetl.virtualrealty.listeners.stake.DraftListener; +import com.modnmetl.virtualrealty.managers.ConfirmationManager; import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.objects.data.PlotItem; @@ -26,6 +28,8 @@ public class DraftSubCommand extends SubCommand { + public DraftSubCommand() {} + public DraftSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { super(sender, command, label, args, new LinkedList<>()); } @@ -39,6 +43,7 @@ public void exec(CommandSender sender, Command command, String label, String[] a player.getInventory().addItem(DraftListener.DRAFT_MAP.get(player).getValue().getKey().getItemStack()); DraftListener.DRAFT_MAP.get(player).getKey().removeGrid(); DraftListener.DRAFT_MAP.remove(player); + ConfirmationManager.removeStakeConfirmations(ConfirmationType.STAKE, player.getUniqueId()); player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().draftModeDisabled); return; } @@ -60,8 +65,37 @@ public void exec(CommandSender sender, Command command, String label, String[] a } PlotItem plotItem = PlotItem.fromItemStack(claimItem); Plot plot = PlotManager.getPlot(player.getLocation()); - if (plot != null) { + String replacement = null; + if (plot == null) { + replacement = VirtualRealty.getMessages().createFeature; + } else { + if (plotItem.getPlotSize().equals(plot.getPlotSize())) { + if (((plot.isOwnershipExpired() && plot.getPlotOwner() != null && !plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) || plot.getPlotOwner() == null)) { + replacement = VirtualRealty.getMessages().claimFeature; + } else if (plot.getPlotOwner() != null && plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) { + replacement = VirtualRealty.getMessages().extendFeature; + } + } else { + replacement = VirtualRealty.getMessages().createFeature; + } + } + String finalReplacement = replacement; + if (plot != null && plotItem.getPlotSize().equals(plot.getPlotSize())) { player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().standingOnPlot); + GridStructure previewStructure = new GridStructure(((Player) sender), plot.getLength(), plot.getHeight(), plot.getWidth(), plot.getID(), ((Player) sender).getWorld(), 0, plot.getCreatedLocation()); + previewStructure.preview(player.getLocation(), true, false); + sender.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().visualBoundaryDisplayed); + PlotItem draftItem = PlotItem.fromItemStack(claimItem, VItem.DRAFT); + DraftListener.DRAFT_MAP.put(player, new AbstractMap.SimpleEntry<>(previewStructure, new AbstractMap.SimpleEntry<>(plotItem, draftItem))); + inv.remove(claimItem); + if (VirtualRealty.legacyVersion) { + player.setItemInHand(draftItem.getItemStack()); + } else { + inv.setItemInMainHand(draftItem.getItemStack()); + } + VirtualRealty.getMessages().draftEnabled.forEach((message) -> player.sendMessage(message.replaceAll("&", "§") + .replaceAll("%feature%", finalReplacement) + )); return; } PlotSize plotSize = PlotSize.valueOf(claimNbtItem.getString("vrplot_size")); @@ -70,7 +104,6 @@ public void exec(CommandSender sender, Command command, String label, String[] a player.sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().draftModeCancelledCollision); if (!GridStructure.isCuboidGridDisplaying(player, 0)) { new GridStructure(player, plotSize.getLength(), plotSize.getHeight(), plotSize.getWidth(), 0, ((Player) sender).getWorld(), 20 * 6, player.getLocation()).preview(player.getLocation(),true, true); - } return; } @@ -92,7 +125,9 @@ public void exec(CommandSender sender, Command command, String label, String[] a inv.setItemInMainHand(draftItem.getItemStack()); } draftStructure.preview(player.getLocation(), true, false); - VirtualRealty.getMessages().draftModeEnabled.forEach((message) -> player.sendMessage(message.replaceAll("&", "§"))); + VirtualRealty.getMessages().draftEnabled.forEach((message) -> player.sendMessage(message.replaceAll("&", "§") + .replaceAll("%feature%", finalReplacement) + )); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/GmSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/GmSubCommand.java index 8537c28..0ffa378 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/GmSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/GmSubCommand.java @@ -6,6 +6,7 @@ import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.objects.data.PlotMember; +import lombok.NoArgsConstructor; import org.bukkit.GameMode; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -15,13 +16,15 @@ public class GmSubCommand extends SubCommand { - public static final LinkedList HELP = new LinkedList<>(); + public static LinkedList HELP = new LinkedList<>(); static { HELP.add(" "); HELP.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»"); - HELP.add(" §a/plot gm §8<§7gamemode§8>"); + HELP.add(" §a/plot %command% §8<§7gamemode§8>"); } + + public GmSubCommand() {} public GmSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { super(sender, command, label, args, HELP); diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/InfoSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/InfoSubCommand.java index d72cae3..9762fb0 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/InfoSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/InfoSubCommand.java @@ -5,6 +5,7 @@ import com.modnmetl.virtualrealty.exceptions.FailedCommandException; import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; +import lombok.NoArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; @@ -17,6 +18,8 @@ public class InfoSubCommand extends SubCommand { + public InfoSubCommand() {} + public InfoSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { super(sender, command, label, args, new LinkedList<>()); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java index 3f1bdda..2a9fc7b 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/KickSubCommand.java @@ -7,6 +7,7 @@ import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.objects.data.PlotMember; +import lombok.NoArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; @@ -18,14 +19,16 @@ public class KickSubCommand extends SubCommand { - public static final LinkedList HELP = new LinkedList<>(); + public static LinkedList HELP = new LinkedList<>(); static { HELP.add(" "); HELP.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»"); - HELP.add(" §a/plot kick §8<§7plot§8> §8<§7player§8>"); + HELP.add(" §a/plot %command% §8<§7plot§8> §8<§7player§8>"); } + public KickSubCommand() {} + public KickSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { super(sender, command, label, args, HELP); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/ListSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/ListSubCommand.java index 83d21da..9850083 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/ListSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/ListSubCommand.java @@ -5,6 +5,7 @@ import com.modnmetl.virtualrealty.exceptions.FailedCommandException; import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; +import lombok.NoArgsConstructor; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -18,6 +19,8 @@ public class ListSubCommand extends SubCommand { + public ListSubCommand() {} + public ListSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { super(sender, command, label, args, new LinkedList<>()); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/StakeSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/StakeSubCommand.java index 7c06133..6aebde8 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/StakeSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/StakeSubCommand.java @@ -34,6 +34,8 @@ public class StakeSubCommand extends SubCommand { + public StakeSubCommand() {} + public StakeSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { super(sender, command, label, args, new LinkedList<>()); } @@ -49,6 +51,89 @@ public void exec(CommandSender sender, Command command, String label, String[] a GridStructure gridStructure = DraftListener.DRAFT_MAP.get(player).getKey(); PlotItem plotItem = DraftListener.DRAFT_MAP.get(player).getValue().getKey(); Cuboid cuboid = RegionUtil.getRegion(gridStructure.getPreviewLocation(), Direction.byYaw(gridStructure.getPreviewLocation().getYaw()), plotItem.getLength(), plotItem.getHeight(), plotItem.getWidth()); + Plot plot = PlotManager.getPlot(gridStructure.getPreviewLocation()); + if (plot != null) { + if (plotItem.getPlotSize().equals(plot.getPlotSize())) { + if (((plot.isOwnershipExpired() && plot.getPlotOwner() != null && !plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) || plot.getPlotOwner() == null)) { + for (String s : VirtualRealty.getMessages().claimConfirmation) { + player.sendMessage(VirtualRealty.PREFIX + s); + } + Confirmation confirmation = new Confirmation(ConfirmationType.CLAIM, (Player) sender, "YES") { + @Override + public void success() { + ItemStack plotItemStack = DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack(); + this.getSender().getInventory().remove(plotItemStack); + plot.setOwnedBy(this.getSender().getUniqueId()); + plot.setOwnedUntilDate(LocalDateTime.now().plusDays(plotItem.getAdditionalDays())); + gridStructure.removeGrid(); + DraftListener.DRAFT_MAP.remove(this.getSender()); + ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); + plot.update(); + this.getSender().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().plotClaimed); + } + + @Override + public void failed() { + this.getSender().getInventory().removeItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack()); + this.getSender().getInventory().remove(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack()); + this.getSender().getInventory().addItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getKey().getItemStack()); + DraftListener.DRAFT_MAP.get(this.getSender()).getKey().removeGrid(); + DraftListener.DRAFT_MAP.remove(this.getSender()); + this.getSender().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().stakeCancelled); + DraftListener.DRAFT_MAP.remove(this.getSender()); + ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); + } + + @Override + public void expiry() { + ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); + } + }; + ConfirmationManager.confirmations.add(confirmation); + return; + } else if (plot.getPlotOwner() != null && plot.getPlotOwner().getUniqueId().equals(player.getUniqueId())) { + for (String s : VirtualRealty.getMessages().extendConfirmation) { + player.sendMessage(VirtualRealty.PREFIX + s); + } + Confirmation confirmation = new Confirmation(ConfirmationType.EXTEND, (Player) sender, "YES") { + @Override + public void success() { + PlotItem plotItem = DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getKey(); + ItemStack plotItemStack = DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack(); + this.getSender().getInventory().remove(plotItemStack); + if (plot.isOwnershipExpired()) + plot.setOwnedUntilDate(LocalDateTime.now().plusDays(plotItem.getAdditionalDays())); + else + plot.setOwnedUntilDate(plot.getOwnedUntilDate().plusDays(plotItem.getAdditionalDays())); + gridStructure.removeGrid(); + DraftListener.DRAFT_MAP.remove(this.getSender()); + ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); + plot.update(); + this.getSender().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().leaseExtended.replaceAll("%plot_id%", String.valueOf(plot.getID())).replaceAll("%date%", Plot.SHORT_PLOT_DATE_FORMAT.format(plot.getOwnedUntilDate()))); + } + + @Override + public void failed() { + this.getSender().getInventory().removeItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack()); + this.getSender().getInventory().remove(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack()); + this.getSender().getInventory().addItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getKey().getItemStack()); + DraftListener.DRAFT_MAP.get(this.getSender()).getKey().removeGrid(); + DraftListener.DRAFT_MAP.remove(this.getSender()); + this.getSender().sendMessage(VirtualRealty.PREFIX + VirtualRealty.getMessages().stakeCancelled); + DraftListener.DRAFT_MAP.remove(this.getSender()); + ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); + } + + @Override + public void expiry() { + ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); + } + }; + ConfirmationManager.confirmations.add(confirmation); + return; + } + } + } if (RegionUtil.isCollidingWithAnotherPlot(cuboid)) { player.getInventory().remove(DraftListener.DRAFT_MAP.get(player).getValue().getValue().getItemStack()); player.getInventory().addItem(DraftListener.DRAFT_MAP.get(player).getValue().getKey().getItemStack()); @@ -114,7 +199,6 @@ public void run() { ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); plot.update(); } - @Override public void failed() { this.getSender().getInventory().removeItem(DraftListener.DRAFT_MAP.get(this.getSender()).getValue().getValue().getItemStack()); @@ -126,7 +210,6 @@ public void failed() { DraftListener.DRAFT_MAP.remove(this.getSender()); ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); } - @Override public void expiry() { ConfirmationManager.removeStakeConfirmations(this.getConfirmationType(), this.getSender().getUniqueId()); diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java index df89f06..cff3d50 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/plot/subcommand/TpSubCommand.java @@ -5,6 +5,7 @@ import com.modnmetl.virtualrealty.exceptions.FailedCommandException; import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; +import lombok.NoArgsConstructor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -13,14 +14,16 @@ public class TpSubCommand extends SubCommand { - public static final LinkedList HELP = new LinkedList<>(); + public static LinkedList HELP = new LinkedList<>(); static { HELP.add(" "); HELP.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»"); - HELP.add(" §a/plot tp §8<§7plot§8>"); + HELP.add(" §a/plot %command% §8<§7plot§8>"); } + public TpSubCommand() {} + public TpSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { super(sender, command, label, args, HELP); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java index 638aa7d..44e5f52 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/VirtualRealtyCommand.java @@ -1,5 +1,8 @@ package com.modnmetl.virtualrealty.commands.vrplot; +import com.modnmetl.virtualrealty.commands.CommandRegistry; +import com.modnmetl.virtualrealty.commands.SubCommand; +import com.modnmetl.virtualrealty.enums.commands.CommandType; import com.modnmetl.virtualrealty.exceptions.FailedCommandException; import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.exceptions.InsufficientPermissionsException; @@ -23,17 +26,17 @@ public class VirtualRealtyCommand implements CommandExecutor { static { HELP_LIST.add(" "); HELP_LIST.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»"); - HELP_LIST.add(" §a/vrplot create §8- §7Creates a plot"); - HELP_LIST.add(" §a/vrplot remove §8- §7Removes a plot"); - HELP_LIST.add(" §a/vrplot set §8- §7Sets a variable for the plot"); - HELP_LIST.add(" §a/vrplot assign §8- §7Assigns a plot to player"); - HELP_LIST.add(" §a/vrplot unassign §8- §7Sets assigned to and assigned by to null"); - HELP_LIST.add(" §a/vrplot info §8- §7Prints info about plot"); - HELP_LIST.add(" §a/vrplot list §8- §7Prints all plots"); - HELP_LIST.add(" §a/vrplot item §8- §7Creates plot item"); - HELP_LIST.add(" §a/vrplot visual §8- §7Displays visual grid of the plot"); - HELP_LIST.add(" §a/vrplot tp §8- §7Teleports to the plot"); - HELP_LIST.add(" §a/vrplot reload §8- §7Reloads plugin"); + HELP_LIST.add(" §a/vrplot %create_command% §8- §7Creates a plot"); + HELP_LIST.add(" §a/vrplot %remove_command% §8- §7Removes a plot"); + HELP_LIST.add(" §a/vrplot %set_command% §8- §7Sets a variable for the plot"); + HELP_LIST.add(" §a/vrplot %assign_command% §8- §7Assigns a plot to player"); + HELP_LIST.add(" §a/vrplot %unassign_command% §8- §7Sets assigned to and assigned by to null"); + HELP_LIST.add(" §a/vrplot %info_command% §8- §7Prints info about plot"); + HELP_LIST.add(" §a/vrplot %list_command% §8- §7Prints all plots"); + HELP_LIST.add(" §a/vrplot %item_command% §8- §7Creates plot item"); + HELP_LIST.add(" §a/vrplot %visual_command% §8- §7Displays visual grid of the plot"); + HELP_LIST.add(" §a/vrplot %tp_command% §8- §7Teleports to the plot"); + HELP_LIST.add(" §a/vrplot %reload_command% §8- §7Reloads plugin"); } @Override @@ -55,11 +58,12 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command return false; } try { - Class clazz = Class.forName("com.modnmetl.virtualrealty.commands.vrplot.subcommand." + String.valueOf(args[0].toCharArray()[0]).toUpperCase() + args[0].substring(1) + "SubCommand", true, VirtualRealty.getLoader()); + String subcommandName = String.valueOf(args[0].toCharArray()[0]).toUpperCase() + args[0].substring(1); + Class aClass = CommandRegistry.getSubCommand(subcommandName.toLowerCase(), CommandType.VRPLOT).get().getClass(); if (bypass) { - clazz.getConstructors()[1].newInstance(sender, command, label, args, true); + aClass.getConstructors()[2].newInstance(sender, command, label, args, true); } else { - clazz.getConstructors()[0].newInstance(sender, command, label, args); + aClass.getConstructors()[1].newInstance(sender, command, label, args); } } catch (Exception e) { if(!(e instanceof InvocationTargetException)) { @@ -82,7 +86,13 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command private static void printHelp(CommandSender sender) { for (String message : HELP_LIST) { - sender.sendMessage(message); + final String[] finalMessage = {message}; + CommandRegistry.VRPLOT_PLACEHOLDERS.forEach((s, s2) -> { + finalMessage[0] = finalMessage[0].replaceAll(s, s2); + }); + sender.sendMessage( + finalMessage[0] + ); } } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java index 44e6b84..a44b8c7 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/AssignSubCommand.java @@ -6,6 +6,7 @@ import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.utils.UUIDUtils; +import lombok.NoArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; @@ -18,14 +19,16 @@ public class AssignSubCommand extends SubCommand { - public static final LinkedList HELP = new LinkedList<>(); + public static LinkedList HELP = new LinkedList<>(); static { HELP.add(" "); HELP.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»"); - HELP.add(" §a/vrplot assign §8<§7plot§8> §8<§7username§8>"); + HELP.add(" §a/vrplot %command% §8<§7plot§8> §8<§7username§8>"); } + public AssignSubCommand() {} + public AssignSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { super(sender, command, label, args, HELP); } @@ -34,9 +37,7 @@ public AssignSubCommand(CommandSender sender, Command command, String label, Str public void exec(CommandSender sender, Command command, String label, String[] args) throws Exception { assertPermission(); if (args.length < 2) { - for (String helpMessage : HELP) { - sender.sendMessage(helpMessage); - } + printHelp(); return; } int plotID; diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java index 039ef8e..78e0386 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/CreateSubCommand.java @@ -12,6 +12,7 @@ import com.modnmetl.virtualrealty.utils.RegionUtil; import com.modnmetl.virtualrealty.utils.multiversion.Chat; import com.modnmetl.virtualrealty.utils.multiversion.VMaterial; +import lombok.NoArgsConstructor; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.HoverEvent; @@ -27,16 +28,18 @@ public class CreateSubCommand extends SubCommand { - public static final LinkedList HELP = new LinkedList<>(); + public static LinkedList HELP = new LinkedList<>(); static { HELP.add(" "); HELP.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»"); - HELP.add(" §a/vrplot create §8<§7small/medium/large§8> §8<§7floor (optional)§8> §8<§7border (optional)§8> §8<§7--natural(optional)§8>"); - HELP.add(" §a/vrplot create area §8<§7length§8> §8<§7height§8> §8<§7width§8>"); - HELP.add(" §a/vrplot create §8<§7length§8> §8<§7height§8> §8<§7width§8> §8<§7floor (optional)§8> §8<§7border (optional)§8> §8<§7--natural(optional)§8>"); + HELP.add(" §a/vrplot %command% §8<§7small/medium/large§8> §8<§7floor (optional)§8> §8<§7border (optional)§8> §8<§7--natural(optional)§8>"); + HELP.add(" §a/vrplot %command% area §8<§7length§8> §8<§7height§8> §8<§7width§8>"); + HELP.add(" §a/vrplot %command% §8<§7length§8> §8<§7height§8> §8<§7width§8> §8<§7floor (optional)§8> §8<§7border (optional)§8> §8<§7--natural(optional)§8>"); } + public CreateSubCommand() {} + public CreateSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { super(sender, command, label, args, HELP); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/DebugSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/DebugSubCommand.java index 2044b44..bd6c847 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/DebugSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/DebugSubCommand.java @@ -5,6 +5,7 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; import com.modnmetl.virtualrealty.exceptions.FailedCommandException; +import lombok.NoArgsConstructor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -22,6 +23,7 @@ public class DebugSubCommand extends SubCommand { private static long LAST_REQUEST = 0; + public DebugSubCommand() {} public DebugSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { super(sender, command, label, args, new LinkedList<>()); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java index a0bc24d..2ed6a86 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/InfoSubCommand.java @@ -5,6 +5,7 @@ import com.modnmetl.virtualrealty.exceptions.FailedCommandException; import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; +import lombok.NoArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; @@ -18,6 +19,8 @@ public class InfoSubCommand extends SubCommand { + public InfoSubCommand() {} + public InfoSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { super(sender, command, label, args, new LinkedList<>()); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ItemSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ItemSubCommand.java index cb2c1f5..1f1eeab 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ItemSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ItemSubCommand.java @@ -7,6 +7,7 @@ import com.modnmetl.virtualrealty.exceptions.FailedCommandException; import com.modnmetl.virtualrealty.objects.data.PlotItem; import com.modnmetl.virtualrealty.utils.EnumUtils; +import lombok.NoArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.command.Command; @@ -18,15 +19,17 @@ public class ItemSubCommand extends SubCommand { - public static final LinkedList HELP = new LinkedList<>(); + public static LinkedList HELP = new LinkedList<>(); static { HELP.add(" "); HELP.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»"); - HELP.add(" §a/vrplot item §8<§7small/medium/large§8> §8<§7floor§8> §8<§7border§8> §8<§7lease duration (in days)§8> §8<§7amount of items§8> §8<§7player§8> §8<§7--natural(optional)§8>"); - HELP.add(" §a/vrplot item §8<§7custom/area§8> §8<§7length§8> §8<§7height§8> §8<§7width§8> §8<§7floor§8> §8<§7border§8> §8<§7lease duration (in days)§8> §8<§7amount of items§8> §8<§7player§8> §8<§7--natural(optional)§8>"); + HELP.add(" §a/vrplot %command% §8<§7small/medium/large§8> §8<§7floor§8> §8<§7border§8> §8<§7lease duration (in days)§8> §8<§7amount of items§8> §8<§7player§8> §8<§7--natural(optional)§8>"); + HELP.add(" §a/vrplot %command% §8<§7custom/area§8> §8<§7length§8> §8<§7height§8> §8<§7width§8> §8<§7floor§8> §8<§7border§8> §8<§7lease duration (in days)§8> §8<§7amount of items§8> §8<§7player§8> §8<§7--natural(optional)§8>"); } + public ItemSubCommand() {} + public ItemSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { super(sender, command, label, args, HELP); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java index 53bb9ab..55cece8 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ListSubCommand.java @@ -6,6 +6,7 @@ import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.utils.multiversion.Chat; +import lombok.NoArgsConstructor; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.HoverEvent; @@ -20,6 +21,8 @@ public class ListSubCommand extends SubCommand { + public ListSubCommand() {} + public ListSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { super(sender, command, label, args, new LinkedList<>()); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java index 0ab4f51..85111a9 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/ReloadSubCommand.java @@ -6,6 +6,7 @@ import com.modnmetl.virtualrealty.managers.DynmapManager; import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; +import lombok.NoArgsConstructor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -13,6 +14,8 @@ public class ReloadSubCommand extends SubCommand { + public ReloadSubCommand() {} + public ReloadSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { super(sender, command, label, args, new LinkedList<>()); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java index e235d42..e4a5336 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/RemoveSubCommand.java @@ -8,6 +8,7 @@ import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.objects.data.Confirmation; +import lombok.NoArgsConstructor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -16,14 +17,16 @@ public class RemoveSubCommand extends SubCommand { - public static final LinkedList HELP = new LinkedList<>(); + public static LinkedList HELP = new LinkedList<>(); static { HELP.add(" "); HELP.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»"); - HELP.add(" §a/vrplot remove §8<§7plot§8>"); + HELP.add(" §a/vrplot %command% §8<§7plot§8>"); } + public RemoveSubCommand() {} + public RemoveSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { super(sender, command, label, args, HELP); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/SetSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/SetSubCommand.java index 14ab0b2..eae1663 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/SetSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/SetSubCommand.java @@ -7,6 +7,7 @@ import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.utils.UUIDUtils; import com.modnmetl.virtualrealty.utils.multiversion.VMaterial; +import lombok.NoArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.OfflinePlayer; @@ -21,17 +22,19 @@ public class SetSubCommand extends SubCommand { - public static final LinkedList HELP = new LinkedList<>(); + public static LinkedList HELP = new LinkedList<>(); static { HELP.add(" "); HELP.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»"); - HELP.add(" §a/vrplot set §8<§7plot§8> §aowner §8<§7username§8>"); - HELP.add(" §a/vrplot set §8<§7plot§8> §afloor §8<§7material§8>"); - HELP.add(" §a/vrplot set §8<§7plot§8> §aborder §8<§7material§8>"); - HELP.add(" §a/vrplot set §8<§7plot§8> §aexpiry §8<§7dd/mm/YYYY§8> §8<§7HH:mm (optional)§8>"); + HELP.add(" §a/vrplot %command% §8<§7plot§8> §aowner §8<§7username§8>"); + HELP.add(" §a/vrplot %command% §8<§7plot§8> §afloor §8<§7material§8>"); + HELP.add(" §a/vrplot %command% §8<§7plot§8> §aborder §8<§7material§8>"); + HELP.add(" §a/vrplot %command% §8<§7plot§8> §aexpiry §8<§7dd/mm/YYYY§8> §8<§7HH:mm (optional)§8>"); } + public SetSubCommand() {} + public SetSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { super(sender, command, label, args, HELP); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java index 970963b..9aa0b72 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/TpSubCommand.java @@ -5,6 +5,7 @@ import com.modnmetl.virtualrealty.exceptions.FailedCommandException; import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; +import lombok.NoArgsConstructor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -13,14 +14,16 @@ public class TpSubCommand extends SubCommand { - public static final LinkedList HELP = new LinkedList<>(); + public static LinkedList HELP = new LinkedList<>(); static { HELP.add(" "); HELP.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»"); - HELP.add(" §a/vrplot tp §8<§7plot§8>"); + HELP.add(" §a/vrplot %command% §8<§7plot§8>"); } + public TpSubCommand() {} + public TpSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { super(sender, command, label, args, HELP); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java index d588ac9..f484c45 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/UnassignSubCommand.java @@ -5,6 +5,7 @@ import com.modnmetl.virtualrealty.exceptions.FailedCommandException; import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; +import lombok.NoArgsConstructor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -12,14 +13,16 @@ public class UnassignSubCommand extends SubCommand { - public static final LinkedList HELP = new LinkedList<>(); + public static LinkedList HELP = new LinkedList<>(); static { HELP.add(" "); HELP.add(" §8§l«§8§m §8[§aVirtualRealty§8]§m §8§l»"); - HELP.add(" §a/vrplot unassign §8<§7plot§8>"); + HELP.add(" §a/vrplot %command% §8<§7plot§8>"); } + public UnassignSubCommand() {} + public UnassignSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { super(sender, command, label, args, HELP); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java index 92a4d52..693f7f5 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VersionSubCommand.java @@ -3,6 +3,7 @@ import com.modnmetl.virtualrealty.VirtualRealty; import com.modnmetl.virtualrealty.commands.SubCommand; import com.modnmetl.virtualrealty.exceptions.FailedCommandException; +import lombok.NoArgsConstructor; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; @@ -13,6 +14,8 @@ public class VersionSubCommand extends SubCommand { + public VersionSubCommand() {} + public VersionSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { super(sender, command, label, args, new LinkedList<>()); } diff --git a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java index 2e7eef3..e7ff5fd 100644 --- a/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java +++ b/src/main/java/com/modnmetl/virtualrealty/commands/vrplot/subcommand/VisualSubCommand.java @@ -6,6 +6,7 @@ import com.modnmetl.virtualrealty.managers.PlotManager; import com.modnmetl.virtualrealty.objects.Plot; import com.modnmetl.virtualrealty.objects.region.GridStructure; +import lombok.NoArgsConstructor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -14,6 +15,8 @@ public class VisualSubCommand extends SubCommand { + public VisualSubCommand() {} + public VisualSubCommand(CommandSender sender, Command command, String label, String[] args) throws FailedCommandException { super(sender, command, label, args, new LinkedList<>()); } diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/CommandsConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/CommandsConfiguration.java new file mode 100644 index 0000000..67e7fe8 --- /dev/null +++ b/src/main/java/com/modnmetl/virtualrealty/configs/CommandsConfiguration.java @@ -0,0 +1,135 @@ +package com.modnmetl.virtualrealty.configs; + +import com.modnmetl.virtualrealty.commands.CommandManager; +import com.modnmetl.virtualrealty.commands.CommandRegistry; +import com.modnmetl.virtualrealty.commands.SubCommand; +import com.modnmetl.virtualrealty.commands.plot.PlotCommand; +import com.modnmetl.virtualrealty.commands.vrplot.VirtualRealtyCommand; +import com.modnmetl.virtualrealty.enums.commands.CommandType; +import eu.okaeri.configs.OkaeriConfig; +import eu.okaeri.configs.annotation.*; + +import java.lang.reflect.Field; +import java.util.*; + +@Header("-------------------------------------------------------------- #") +@Header(" #") +@Header(" Commands #") +@Header(" #") +@Header("-------------------------------------------------------------- #") +@Names(strategy = NameStrategy.HYPHEN_CASE, modifier = NameModifier.TO_LOWER_CASE) +public class CommandsConfiguration extends OkaeriConfig { + + public LinkedHashMap plotAliases = getPlotAliasesHashMap(); + public LinkedHashMap vrplotAliases = getVRPlotAliasesHashMap(); + + public LinkedHashMap> plotCommandsHelp = getCommandsHelp(CommandType.PLOT); + public LinkedHashMap> vrplotCommandsHelp = getCommandsHelp(CommandType.VRPLOT); + + public static LinkedHashMap getVRPlotAliasesHashMap() { + LinkedHashMap aliasesHashMap = new LinkedHashMap<>(); + for (String s : CommandManager.SUBCOMMANDS.get(VirtualRealtyCommand.class)) { + if (s == null || s.isEmpty()) continue; + aliasesHashMap.put(s, s); + } + return aliasesHashMap; + } + + public static LinkedHashMap getPlotAliasesHashMap() { + LinkedHashMap aliasesHashMap = new LinkedHashMap<>(); + for (String s : CommandManager.SUBCOMMANDS.get(PlotCommand.class)) { + if (s == null || s.isEmpty()) continue; + aliasesHashMap.put(s, s); + } + return aliasesHashMap; + } + + public static LinkedHashMap> getCommandsHelp(CommandType commandType) { + LinkedHashMap> commandsHelpMap = new LinkedHashMap<>(); + switch (commandType) { + case VRPLOT: + commandsHelpMap.put("vrplot", VirtualRealtyCommand.HELP_LIST); + break; + case PLOT: + commandsHelpMap.put("plot", PlotCommand.HELP_LIST); + break; + } + for (SubCommand subCommand : CommandRegistry.getSubCommandList(commandType)) { + Class aClass = subCommand.getClass(); + String simpleName = aClass.getSimpleName(); + String subCommand1 = simpleName.replaceAll("SubCommand", "").toLowerCase(); + if (Arrays.stream(subCommand.getClass().getFields()).noneMatch(field -> field.getName().equalsIgnoreCase("HELP"))) continue; + Field helpList; + try { + helpList = subCommand.getClass().getField("HELP"); + } catch (NoSuchFieldException e) { + continue; + } + helpList.setAccessible(true); + Object o; + try { + o = helpList.get(null); + } catch (IllegalAccessException e) { + continue; + } + LinkedList o1 = (LinkedList) o; + if (o1 == null || o1.isEmpty()) continue; + commandsHelpMap.put(subCommand1, o1); + } + return commandsHelpMap; + } + + public void refreshHelpMessages() { + for (SubCommand subCommand : CommandRegistry.getSubCommandList(CommandType.PLOT)) { + if (plotCommandsHelp.containsKey(subCommand.getSubCommandClassName())) { + LinkedList strings = plotCommandsHelp.get(subCommand.getSubCommandClassName()); + Field helpList; + try { + helpList = subCommand.getClass().getField("HELP"); + } catch (NoSuchFieldException e) { + continue; + } + helpList.setAccessible(true); + try { + helpList.set(null, strings); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + PlotCommand.HELP_LIST.clear(); + PlotCommand.HELP_LIST.addAll(plotCommandsHelp.get("plot")); + + for (SubCommand subCommand : CommandRegistry.getSubCommandList(CommandType.VRPLOT)) { + if (vrplotCommandsHelp.containsKey(subCommand.getSubCommandClassName())) { + LinkedList strings = vrplotCommandsHelp.get(subCommand.getSubCommandClassName()); + Field helpList; + try { + helpList = subCommand.getClass().getField("HELP"); + } catch (NoSuchFieldException e) { + continue; + } + helpList.setAccessible(true); + try { + helpList.set(null, strings); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + VirtualRealtyCommand.HELP_LIST.clear(); + VirtualRealtyCommand.HELP_LIST.addAll(vrplotCommandsHelp.get("vrplot")); + } + + public void assignAliases() { + vrplotAliases.forEach((original, alias) -> { + Optional any = CommandRegistry.VRPLOT_SUB_COMMAND_LIST.stream().filter(subCommand -> subCommand.getSubCommandClassName().equalsIgnoreCase(original)).findAny(); + any.ifPresent(subCommand -> subCommand.setAlias(alias)); + }); + plotAliases.forEach((original, alias) -> { + Optional any = CommandRegistry.PLOT_SUB_COMMAND_LIST.stream().filter(subCommand -> subCommand.getSubCommandClassName().equalsIgnoreCase(original)).findAny(); + any.ifPresent(subCommand -> subCommand.setAlias(alias)); + }); + } + +} diff --git a/src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java b/src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java index 10baa02..ead7cf7 100644 --- a/src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java +++ b/src/main/java/com/modnmetl/virtualrealty/configs/MessagesConfiguration.java @@ -103,20 +103,33 @@ public class MessagesConfiguration extends OkaeriConfig { public String draftModeCancelledBedrock = "§cDraft cancelled. Colliding with bedrock."; public String draftModeCancelledCollision = "§cDraft cancelled. Colliding with another plot."; public String draftModeDisabledDueToDeath = "§cDraft mode has been disabled due to death."; - public List draftModeEnabled = Arrays.asList( + public List draftEnabled = Arrays.asList( " ", " §8§l«§8§m §8[§aDraft Mode§8]§m §8§l»", " ", - " §8§l» §7Type §a/plot stake §7to place plot.", + " §8§l» §7Type §a/plot stake §7to %feature%.", " §8§l» §7If you want to leave draft mode type §a/plot draft", " " ); public String stakeCancelled = "§cStake cancelled."; + public String createFeature = "place plot"; + public String claimFeature = "claim this existing plot for yourself"; + public String extendFeature = "extend the lease on this existing plot"; + public String plotClaimed = "§aYou have successfully claimed the plot!"; + public String leaseExtended = "§7Plot §8#§7%plot_id% lease extended to %date%."; public List stakeConfirmation = Arrays.asList( "§7You are about to stake your claim to the plot shown, once done you cannot undo.", "§7Type §aYES §7to proceed." ); + public List extendConfirmation = Arrays.asList( + "§7You are about extend the lease duration of the plot shown, once done you cannot undo.", + "§7Type §aYES §7to proceed." + ); + public List claimConfirmation = Arrays.asList( + "§7You are about to claim the plot shown, once done you cannot undo.", + "§7Type §aYES §7to proceed." + ); public String removalCancelled = "§cRemoval cancelled."; public List removeConfirmation = Arrays.asList( "§7You are about to remove §a%plot_id%§7, once done you cannot undo.", diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/ConfirmationType.java b/src/main/java/com/modnmetl/virtualrealty/enums/ConfirmationType.java index 4284744..bd1e14a 100644 --- a/src/main/java/com/modnmetl/virtualrealty/enums/ConfirmationType.java +++ b/src/main/java/com/modnmetl/virtualrealty/enums/ConfirmationType.java @@ -3,6 +3,8 @@ public enum ConfirmationType { STAKE, + CLAIM, + EXTEND, REMOVE } diff --git a/src/main/java/com/modnmetl/virtualrealty/enums/commands/CommandType.java b/src/main/java/com/modnmetl/virtualrealty/enums/commands/CommandType.java new file mode 100644 index 0000000..5a85ab2 --- /dev/null +++ b/src/main/java/com/modnmetl/virtualrealty/enums/commands/CommandType.java @@ -0,0 +1,8 @@ +package com.modnmetl.virtualrealty.enums.commands; + +public enum CommandType { + + VRPLOT, + PLOT + +} diff --git a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java index 85f97f8..0beb983 100644 --- a/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java +++ b/src/main/java/com/modnmetl/virtualrealty/listeners/protection/PlotProtectionListener.java @@ -616,6 +616,7 @@ public void onItemFrameRotate(PlayerInteractEntityEvent e) { if (e.isCancelled()) return; Player player = e.getPlayer(); Plot plot = PlotManager.getPlot(player.getLocation()); + if (!(e.getRightClicked() instanceof ItemFrame)) return; if (plot == null) return; if (hasPermission(player, PLOT_BUILD)) return; if (plot.hasMembershipAccess(player.getUniqueId())) { diff --git a/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java b/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java index 6bd30d8..7b4144d 100644 --- a/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java +++ b/src/main/java/com/modnmetl/virtualrealty/managers/DynmapManager.java @@ -117,6 +117,7 @@ public static void resetPlotMarker(Plot plot) { marker.setFillStyle(opacity, color); marker.setLineStyle(2, 0.8, 0x474747); marker.setMarkerSet(VirtualRealty.getDynmapManager().markerset); + VirtualRealty.debug("Updated dynmap marker #" + plot.getID()); } public static void removeDynMapMarker(Plot plot) { diff --git a/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java b/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java index eaf5317..50b18ae 100644 --- a/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java +++ b/src/main/java/com/modnmetl/virtualrealty/objects/Plot.java @@ -678,7 +678,6 @@ public Direction getCreatedDirection() { public void updateMarker() { DynmapManager.resetPlotMarker(this); - VirtualRealty.debug("Updated marker #" + this.ID); } @Override diff --git a/src/main/java/com/modnmetl/virtualrealty/utils/configuration/ConfigurationFactory.java b/src/main/java/com/modnmetl/virtualrealty/utils/configuration/ConfigurationFactory.java index b729d8c..8fa76f8 100644 --- a/src/main/java/com/modnmetl/virtualrealty/utils/configuration/ConfigurationFactory.java +++ b/src/main/java/com/modnmetl/virtualrealty/utils/configuration/ConfigurationFactory.java @@ -1,13 +1,10 @@ package com.modnmetl.virtualrealty.utils.configuration; -import com.modnmetl.virtualrealty.configs.PermissionsConfiguration; -import com.modnmetl.virtualrealty.configs.SizesConfiguration; +import com.modnmetl.virtualrealty.configs.*; import eu.okaeri.configs.ConfigManager; import eu.okaeri.configs.postprocessor.SectionSeparator; import eu.okaeri.configs.validator.okaeri.OkaeriValidator; import eu.okaeri.configs.yaml.bukkit.YamlBukkitConfigurer; -import com.modnmetl.virtualrealty.configs.MessagesConfiguration; -import com.modnmetl.virtualrealty.configs.PluginConfiguration; import eu.okaeri.configs.yaml.bukkit.serdes.SerdesBukkit; import lombok.NoArgsConstructor; @@ -52,6 +49,15 @@ public PermissionsConfiguration loadPermissionsConfiguration(File permissionsCon }); } + public CommandsConfiguration loadCommandsConfiguration(File commandsConfigurationFile) { + return ConfigManager.create(CommandsConfiguration.class, (it) -> { + it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesBukkit()); + it.withBindFile(commandsConfigurationFile); + it.saveDefaults(); + it.load(true); + }); + } + public PermissionsConfiguration updatePluginConfiguration(File pluginConfigurationFile) { return ConfigManager.create(PermissionsConfiguration.class, (it) -> { it.withConfigurer(new OkaeriValidator(new YamlBukkitConfigurer(), true), new SerdesBukkit());