mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2026-01-06 15:41:35 +00:00
152 lines
4.9 KiB
Java
152 lines
4.9 KiB
Java
package net.islandearth.rpgregions.commands;
|
|
|
|
import co.aikar.commands.BaseCommand;
|
|
import co.aikar.commands.annotation.CommandAlias;
|
|
import co.aikar.commands.annotation.Default;
|
|
import co.aikar.commands.annotation.Subcommand;
|
|
import com.github.stefvanschie.inventoryframework.Gui;
|
|
import com.github.stefvanschie.inventoryframework.GuiItem;
|
|
import com.github.stefvanschie.inventoryframework.pane.PaginatedPane;
|
|
import com.github.stefvanschie.inventoryframework.pane.StaticPane;
|
|
import net.islandearth.rpgregions.RPGRegions;
|
|
import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
|
|
import net.islandearth.rpgregions.utils.ItemStackBuilder;
|
|
import net.islandearth.rpgregions.utils.StringUtils;
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
@CommandAlias("rpgregions")
|
|
public class RPGRegionsCommand extends BaseCommand {
|
|
|
|
private final RPGRegions plugin;
|
|
|
|
public RPGRegionsCommand(RPGRegions plugin) {
|
|
this.plugin = plugin;
|
|
}
|
|
|
|
@Default
|
|
public void onDefault(CommandSender sender, String[] args) {
|
|
|
|
}
|
|
|
|
@Subcommand("about")
|
|
public void onAbout(CommandSender sender) {
|
|
sender.sendMessage(StringUtils.colour("&eRPGRegions v" + plugin.getDescription().getVersion() + "."));
|
|
sender.sendMessage(StringUtils.colour("&eOwner: https://www.spigotmc.org/members/%%__USER__%%/"));
|
|
}
|
|
|
|
@Subcommand("add")
|
|
public void onAdd(CommandSender sender, String[] args) {
|
|
if (args.length == 1) {
|
|
String region = args[0];
|
|
ConfiguredRegion configuredRegion = new ConfiguredRegion(region, region, new ArrayList<>());
|
|
plugin.getManagers().getRegionsCache().addConfiguredRegion(configuredRegion);
|
|
sender.sendMessage(StringUtils.colour("&aAdded configured region " + region + "!"));
|
|
sender.sendMessage(StringUtils.colour("&e&oNow use /rpgregions edit "
|
|
+ region
|
|
+ " to edit it!"));
|
|
} else {
|
|
sender.sendMessage(StringUtils.colour("&cUsage: /rpgregions add <region>"));
|
|
}
|
|
}
|
|
|
|
@Subcommand("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."));
|
|
}
|
|
} else {
|
|
sender.sendMessage(StringUtils.colour("&cUsage: /rpgregions remove <region>"));
|
|
}
|
|
}
|
|
|
|
@Subcommand("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 <region>");
|
|
}
|
|
}
|
|
|
|
@Subcommand("list")
|
|
public void onList(Player player) {
|
|
Gui gui = new Gui(plugin, 6, "Regions");
|
|
PaginatedPane pane = new PaginatedPane(0, 0, 9, 5);
|
|
StaticPane back = new StaticPane(0, 5, 1, 1);
|
|
StaticPane forward = new StaticPane(8, 5, 1, 1);
|
|
|
|
back.addItem(new GuiItem(new ItemStackBuilder(Material.ARROW)
|
|
.withName(ChatColor.RED + "Previous Page")
|
|
.build(), event -> {
|
|
event.setCancelled(true);
|
|
if (pane.getPages() == 1) return;
|
|
|
|
pane.setPage(pane.getPage() - 1);
|
|
|
|
if (pane.getPage() == 0) {
|
|
back.setVisible(false);
|
|
}
|
|
|
|
forward.setVisible(true);
|
|
gui.update();
|
|
}), 0, 0);
|
|
|
|
back.setVisible(false);
|
|
|
|
forward.addItem(new GuiItem(new ItemStackBuilder(Material.ARROW)
|
|
.withName(ChatColor.GREEN + "Next Page")
|
|
.build(), event -> {
|
|
event.setCancelled(true);
|
|
if (pane.getPages() == 1) return;
|
|
|
|
pane.setPage(pane.getPage() + 1);
|
|
|
|
if (pane.getPage() == pane.getPages() - 1) {
|
|
forward.setVisible(false);
|
|
}
|
|
|
|
back.setVisible(true);
|
|
gui.update();
|
|
}), 0, 0);
|
|
|
|
gui.addPane(back);
|
|
gui.addPane(forward);
|
|
|
|
List<GuiItem> items = new ArrayList<>();
|
|
for (ConfiguredRegion configuredRegion : plugin.getManagers().getRegionsCache().getConfiguredRegions().values()) {
|
|
items.add(new GuiItem(new ItemStackBuilder(configuredRegion.getIcon())
|
|
.withName(ChatColor.WHITE + configuredRegion.getCustomName())
|
|
.build(),
|
|
event -> event.setCancelled(true)));
|
|
}
|
|
|
|
pane.populateWithGuiItems(items);
|
|
gui.addPane(pane);
|
|
gui.show(player);
|
|
}
|
|
}
|