diff --git a/RPGRegions.iml b/RPGRegions.iml index 0981ea4..5420fd9 100644 --- a/RPGRegions.iml +++ b/RPGRegions.iml @@ -1,6 +1,6 @@ - + diff --git a/gradle.properties b/gradle.properties index b444566..563826b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ pluginGroup=net.islandearth -pluginVersion=1.2.3 +pluginVersion=1.2.4 diff --git a/rpgregions/src/main/java/net/islandearth/rpgregions/RPGRegions.java b/rpgregions/src/main/java/net/islandearth/rpgregions/RPGRegions.java index e2603cf..d5245d5 100644 --- a/rpgregions/src/main/java/net/islandearth/rpgregions/RPGRegions.java +++ b/rpgregions/src/main/java/net/islandearth/rpgregions/RPGRegions.java @@ -1,7 +1,9 @@ package net.islandearth.rpgregions; +import co.aikar.commands.InvalidCommandArgument; import co.aikar.commands.PaperCommandManager; import co.aikar.idb.DB; +import com.google.common.collect.ImmutableList; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import net.islandearth.languagy.language.Language; @@ -18,6 +20,8 @@ import net.islandearth.rpgregions.listener.ConnectionListener; import net.islandearth.rpgregions.listener.MoveListener; import net.islandearth.rpgregions.listener.RegionListener; import net.islandearth.rpgregions.managers.RPGRegionsManagers; +import net.islandearth.rpgregions.managers.data.account.RPGRegionsAccount; +import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion; import net.islandearth.rpgregions.requirements.RegionRequirement; import net.islandearth.rpgregions.rewards.DiscoveryReward; import net.islandearth.rpgregions.translation.Translations; @@ -25,6 +29,7 @@ import net.islandearth.rpgregions.utils.XMaterial; import net.islandearth.rpgregions.utils.XSound; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.PluginManager; @@ -49,13 +54,13 @@ public final class RPGRegions extends JavaPlugin implements RPGRegionsAPI, Langu @Override public void onEnable() { - new Metrics(this, 2066); plugin = this; this.createConfig(); this.generateLang(); this.managers = new RPGRegionsManagers(this); this.registerListeners(); this.registerCommands(); + this.registerMetrics(); } @Override @@ -173,6 +178,16 @@ public final class RPGRegions extends JavaPlugin implements RPGRegionsAPI, Langu private void registerCommands() { PaperCommandManager manager = new PaperCommandManager(this); + manager.getCommandCompletions().registerAsyncCompletion("regions", context -> ImmutableList.copyOf(getManagers().getRegionsCache().getConfiguredRegions().keySet())); + manager.getCommandContexts().registerContext(ConfiguredRegion.class, context -> { + String id = context.popFirstArg(); + for (ConfiguredRegion region : plugin.getManagers().getRegionsCache().getConfiguredRegions().values()) { + if (region.getId().equals(id)) { + return region; + } + } + throw new InvalidCommandArgument("Could not find a region with that id."); + }); manager.registerCommand(new RPGRegionsCommand(this)); } @@ -219,4 +234,19 @@ public final class RPGRegions extends JavaPlugin implements RPGRegionsAPI, Langu } return "WorldGuard"; } + + private void registerMetrics() { + Metrics metrics = new Metrics(this, 2066); + metrics.addCustomChart(new Metrics.SingleLineChart("regions_discovered", () -> { + int discoveries = 0; + for (OfflinePlayer offlinePlayer : Bukkit.getOfflinePlayers()) { + RPGRegionsAccount account = getManagers().getStorageManager().getAccount(offlinePlayer.getUniqueId()).get(); + discoveries = discoveries + account.getDiscoveredRegions().size(); + getManagers().getStorageManager().removeCachedAccount(offlinePlayer.getUniqueId()); // Cleanup so we don't use memory + } + return discoveries; + })); + + metrics.addCustomChart(new Metrics.SimplePie("storage_mode", () -> getConfig().getString("settings.integration.name", getIntegration()))); + } } diff --git a/rpgregions/src/main/java/net/islandearth/rpgregions/commands/RPGRegionsCommand.java b/rpgregions/src/main/java/net/islandearth/rpgregions/commands/RPGRegionsCommand.java index 36e9d18..4718e55 100644 --- a/rpgregions/src/main/java/net/islandearth/rpgregions/commands/RPGRegionsCommand.java +++ b/rpgregions/src/main/java/net/islandearth/rpgregions/commands/RPGRegionsCommand.java @@ -2,6 +2,7 @@ package net.islandearth.rpgregions.commands; import co.aikar.commands.BaseCommand; import co.aikar.commands.annotation.CommandAlias; +import co.aikar.commands.annotation.CommandCompletion; import co.aikar.commands.annotation.CommandPermission; import co.aikar.commands.annotation.Default; import co.aikar.commands.annotation.Subcommand; @@ -32,7 +33,7 @@ public class RPGRegionsCommand extends BaseCommand { } @Default - public void onDefault(CommandSender sender, String[] args) { + public void onDefault(CommandSender sender) { sender.sendMessage(ChatColor.YELLOW + "Wiki > " + plugin.getDescription().getWebsite()); sender.sendMessage(ChatColor.YELLOW + "Bugs > https://gitlab.com/SamB440/rpgregions-2"); sender.sendMessage(ChatColor.YELLOW + "Discord > https://discord.gg/fh62mxU"); @@ -55,68 +56,56 @@ public class RPGRegionsCommand extends BaseCommand { @Subcommand("add") @CommandPermission("rpgregions.add") - public void onAdd(Player player, String[] args) { - if (args.length == 1) { - String region = args[0]; - if (!plugin.getManagers().getIntegrationManager().exists(player.getLocation().getWorld(), region)) { - player.sendMessage(StringUtils.colour("&cThat region does not exist in your protection plugin.")); - return; - } - - int x = player.getLocation().getBlockX(); - int y = player.getLocation().getBlockY(); - int z = player.getLocation().getBlockZ(); - ConfiguredRegion configuredRegion = new ConfiguredRegion(player.getWorld(), region, region, new ArrayList<>(), - new ArrayList<>(), x, y, z); - plugin.getManagers().getRegionsCache().addConfiguredRegion(configuredRegion); - player.sendMessage(StringUtils.colour("&aAdded configured region " + region + "!")); - //TODO add an editor - /*player.sendMessage(StringUtils.colour("&e&oNow use /rpgregions edit " - + region - + " to edit it!"));*/ - player.sendMessage(StringUtils.colour("&e&oUse /rpgregions save to save this to file for editing.")); - } else { - player.sendMessage(StringUtils.colour("&cUsage: /rpgregions add ")); + @CommandCompletion("@regions") + public void onAdd(Player player, String region) { + if (!plugin.getManagers().getIntegrationManager().exists(player.getLocation().getWorld(), region)) { + player.sendMessage(StringUtils.colour("&cThat region does not exist in your protection plugin.")); + return; } + + int x = player.getLocation().getBlockX(); + int y = player.getLocation().getBlockY(); + int z = player.getLocation().getBlockZ(); + ConfiguredRegion configuredRegion = new ConfiguredRegion(player.getWorld(), region, region, new ArrayList<>(), + new ArrayList<>(), x, y, z); + plugin.getManagers().getRegionsCache().addConfiguredRegion(configuredRegion); + player.sendMessage(StringUtils.colour("&aAdded configured region " + region + "!")); + //TODO add an editor + /*player.sendMessage(StringUtils.colour("&e&oNow use /rpgregions edit " + + region + + " to edit it!"));*/ + player.sendMessage(StringUtils.colour("&e&oUse /rpgregions save to save this to file for editing.")); } @Subcommand("remove") @CommandPermission("rpgregions.remove") - public void onRemove(CommandSender sender, String[] args) { - if (args.length == 1) { - String region = args[0]; - ConfiguredRegion configuredRegion = plugin.getManagers().getRegionsCache().getConfiguredRegion(region); - if (configuredRegion != null) { - configuredRegion.delete(plugin); - plugin.getManagers().getRegionsCache().removeConfiguredRegion(region); - sender.sendMessage(StringUtils.colour("&cRemoved configured region " + region + "!")); - } else { - sender.sendMessage(StringUtils.colour("&cA region by that name is not yet configured.")); - } + @CommandCompletion("@regions") + public void onRemove(CommandSender sender, ConfiguredRegion configuredRegion) { + if (configuredRegion != null) { + configuredRegion.delete(plugin); + plugin.getManagers().getRegionsCache().removeConfiguredRegion(configuredRegion.getId()); + sender.sendMessage(StringUtils.colour("&cRemoved configured region " + configuredRegion.getId() + "!")); } else { - sender.sendMessage(StringUtils.colour("&cUsage: /rpgregions remove ")); + sender.sendMessage(StringUtils.colour("&cA region by that name is not yet configured.")); } } @Subcommand("edit") @CommandPermission("rpgregions.edit") - public void onEdit(Player player, String[] args) { - if (args.length == 1) {//TODO gui - String region = args[0]; - /*Gui gui = new Gui(plugin, 1, "Editing: " + region); - OutlinePane pane = new OutlinePane(0, 0, 9, 1); - GuiItem item = new GuiItem(new ItemStackBuilder(Material.BARRIER) - .withName(ChatColor.RED + "Close") - .withLore(StringUtils.colour("&f&oThe edit feature is currently not available.")) - .build(), - e -> player.closeInventory()); - pane.insertItem(item, 8); - gui.addPane(pane); - player.openInventory(gui.getInventory());*/ - player.sendMessage(ChatColor.RED + "Not ready yet! Coming in a future update."); - } else { - player.sendMessage(ChatColor.RED + "Usage: /rpgregions edit "); - } + @CommandCompletion("@regions") + public void onEdit(Player player, ConfiguredRegion configuredRegion) { + //TODO gui + /*Gui gui = new Gui(plugin, 1, "Editing: " + region); + OutlinePane pane = new OutlinePane(0, 0, 9, 1); + GuiItem item = new GuiItem(new ItemStackBuilder(Material.BARRIER) + .withName(ChatColor.RED + "Close") + .withLore(StringUtils.colour("&f&oThe edit feature is currently not available.")) + .build(), + e -> player.closeInventory()); + pane.insertItem(item, 8); + gui.addPane(pane); + player.openInventory(gui.getInventory());*/ + player.sendMessage(ChatColor.RED + "Not ready yet! Coming in a future update."); } @Subcommand("list|discoveries") @@ -127,22 +116,19 @@ public class RPGRegionsCommand extends BaseCommand { @Subcommand("additem") @CommandPermission("rpgregions.additem") - public void onAddItem(Player player, String[] args) { - if (args.length > 0) { - String region = args[0]; - ConfiguredRegion configuredRegion = plugin.getManagers().getRegionsCache().getConfiguredRegion(region); - if (configuredRegion != null) { - configuredRegion.getRewards().add(new ItemReward(player.getInventory().getItemInMainHand())); - player.sendMessage(ChatColor.GREEN + "Item added to configuration!"); - } else { - player.sendMessage(ChatColor.RED + "No region exists by that name."); - } + @CommandCompletion("@regions") + public void onAddItem(Player player, ConfiguredRegion configuredRegion) { + if (configuredRegion != null) { + configuredRegion.getRewards().add(new ItemReward(player.getInventory().getItemInMainHand())); + player.sendMessage(ChatColor.GREEN + "Item added to configuration!"); + } else { + player.sendMessage(ChatColor.RED + "No region exists by that name."); } } @Subcommand("reload") @CommandPermission("rpgregions.reload") - public void onReload(CommandSender sender, String[] args) { + public void onReload(CommandSender sender) { sender.sendMessage(ChatColor.GREEN + "Reloading region files..."); long startTime = System.currentTimeMillis(); File folder = new File(plugin.getDataFolder() + "/regions/"); @@ -171,7 +157,7 @@ public class RPGRegionsCommand extends BaseCommand { @Subcommand("save") @CommandPermission("rpgregions.save") - public void onSave(CommandSender sender, String[] args) { + public void onSave(CommandSender sender) { sender.sendMessage(ChatColor.GREEN + "Saving data..."); long startTime = System.currentTimeMillis(); @@ -197,6 +183,7 @@ public class RPGRegionsCommand extends BaseCommand { @Subcommand("reset") @CommandPermission("rpgregions.reset") + @CommandCompletion("@players @regions") public void onReset(CommandSender sender, String[] args) { switch (args.length) { case 1: { @@ -234,33 +221,27 @@ public class RPGRegionsCommand extends BaseCommand { @Subcommand("delete") @CommandPermission("rpgregions.delete") - public void onDelete(CommandSender sender, String[] args) { - if (args.length > 0) { - Player player = Bukkit.getPlayer(args[0]); - if (player != null) { - plugin.getManagers().getStorageManager().deleteAccount(player.getUniqueId()); - } else { - sender.sendMessage(ChatColor.RED + "That player cannot be found."); - } + @CommandCompletion("@players") + public void onDelete(CommandSender sender, Player player) { + if (player != null) { + plugin.getManagers().getStorageManager().deleteAccount(player.getUniqueId()); } else { - sender.sendMessage(ChatColor.RED + "Usage: /rpgregions delete "); + sender.sendMessage(ChatColor.RED + "That player cannot be found."); } } @Subcommand("setlocation") @CommandPermission("rpgregions.setlocation") - public void onSetLocation(Player player, String[] args) { - if (args.length > 0) { - ConfiguredRegion configuredRegion = plugin.getManagers().getRegionsCache().getConfiguredRegion(args[0]); - if (configuredRegion != null) { - Location location = player.getLocation(); - configuredRegion.setX(location.getBlockX()); - configuredRegion.setY(location.getBlockY()); - configuredRegion.setZ(location.getBlockZ()); - player.sendMessage(ChatColor.GREEN + "Location has been updated."); - } else { - player.sendMessage(StringUtils.colour("&cA region by that name is not yet configured.")); - } + @CommandCompletion("@regions") + public void onSetLocation(Player player, ConfiguredRegion configuredRegion) { + if (configuredRegion != null) { + Location location = player.getLocation(); + configuredRegion.setX(location.getBlockX()); + configuredRegion.setY(location.getBlockY()); + configuredRegion.setZ(location.getBlockZ()); + player.sendMessage(ChatColor.GREEN + "Location has been updated."); + } else { + player.sendMessage(StringUtils.colour("&cA region by that name is not yet configured.")); } } }