Add initial edit warp and ACL editor

This commit is contained in:
zontreck 2025-04-06 22:51:43 -07:00
parent 17a8a4e170
commit a188657fb2
14 changed files with 540 additions and 52 deletions

View file

@ -42,6 +42,15 @@ public class EventsHandler implements Listener {
if (PrimitiveItem.isGUIButton(ice.getCurrentItem())) {
ice.setCancelled(true);
if (ice.isShiftClick()) {
List<PrimitiveAction> acts = PrimitiveAction.getSingleAction(ice.getCurrentItem(),
"shiftclickaction");
for (PrimitiveAction primitiveAction : acts) {
primitiveAction.handleAction(player);
}
}
// player.closeInventory();
List<PrimitiveAction> actions = PrimitiveAction.getActions(ice.getCurrentItem());
for (PrimitiveAction primitiveAction : actions) {
primitiveAction.handleAction(player);

View file

@ -8,6 +8,7 @@ import dev.zontreck.ase.commands.homes.HomeCommand;
import dev.zontreck.ase.commands.homes.HomesCommand;
import dev.zontreck.ase.commands.homes.SetHomeCommand;
import dev.zontreck.ase.commands.misc.BroadcastCommand;
import dev.zontreck.ase.commands.misc.CloseInvCommand;
import dev.zontreck.ase.commands.misc.CreditsCommand;
import dev.zontreck.ase.commands.misc.ShareItemCommand;
import dev.zontreck.ase.commands.tpa.TPACancelCommand;
@ -16,9 +17,11 @@ import dev.zontreck.ase.commands.tpa.TPAHereCommand;
import dev.zontreck.ase.commands.tpa.TPAcceptCommand;
import dev.zontreck.ase.commands.tpa.TPDenyCommand;
import dev.zontreck.ase.commands.warps.DelWarpCommand;
import dev.zontreck.ase.commands.warps.EditWarpCommand;
import dev.zontreck.ase.commands.warps.SetWarpCommand;
import dev.zontreck.ase.commands.warps.WarpCommand;
import dev.zontreck.ase.commands.warps.WarpsCommand;
import dev.zontreck.ase.commands.warps.EditWarpCommand.EditTypes;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
@ -151,5 +154,39 @@ public class CommandRegistry {
.build()
);
cmds.register(Commands.literal("editwarp")
.requires(x -> x.getSender().isPermissionSet(EditWarpCommand.PERMISSION))
.then(Commands.argument("name", StringArgumentType.string())
.executes(ctx -> EditWarpCommand.execute(ctx.getSource(),
StringArgumentType.getString(ctx, "name")))
.then(Commands.argument("action", StringArgumentType.string())
.executes(ctx -> EditWarpCommand.runAction(
ctx.getSource(),
StringArgumentType.getString(ctx,
"name"),
EditTypes.valueOf(StringArgumentType
.getString(ctx, "action")),
""))
.then(Commands.argument("args",
StringArgumentType.greedyString())
.executes(ctx -> EditWarpCommand
.runAction(ctx.getSource(),
StringArgumentType
.getString(ctx, "name"),
EditWarpCommand.EditTypes
.valueOf(StringArgumentType
.getString(ctx, "action")),
StringArgumentType
.getString(ctx, "args"))))
)
)
.build()
);
cmds.register(Commands.literal("closeinv").executes(ctx -> CloseInvCommand.execute(ctx.getSource()))
.build());
}
}

View file

@ -0,0 +1,18 @@
package dev.zontreck.ase.commands.misc;
import org.bukkit.entity.Player;
import io.papermc.paper.command.brigadier.CommandSourceStack;
/**
* This is a very simple helper command to be able to execute the
* Player#closeInventory method on the correct thread.
*/
public class CloseInvCommand {
public static int execute(CommandSourceStack ctx) {
Player player = (Player) ctx.getSender();
player.closeInventory();
return 1;
}
}

View file

@ -28,16 +28,18 @@ public class DelWarpCommand {
if (AriasServerEssentials.getSelf().warps.containsKey(warpName)) {
// 2. Check owner of warp, or if current player is operator
Warp warp = AriasServerEssentials.getSelf().warps.get(warpName);
if (warp.playerIsOwner(player) || player.isOp()
|| player.isPermissionSet(OTHERPERMISSION) || player.isPermissionSet(WarpConsts.WARP_BYPASS)) {
if (warp.playerIsOwner(player) || player.isPermissionSet(OTHERPERMISSION)
|| player.isPermissionSet(WarpConsts.WARP_BYPASS)) {
// 3. Check if the current player isn't owner.
boolean isDifferentPlayer = !warp.playerIsOwner(player);
if (isDifferentPlayer) {
player.sendMessage(AriasServerEssentials.getPrefix().append(Component.text(
"The warp owned by '" + ChatColor.YELLOW + warp.getOwner().getName() + ChatColor.DARK_GREEN
"The warp owned by '" + ChatColor.YELLOW
+ (warp.isServerWarp() ? "SERVER" : warp.getOwner().getName())
+ ChatColor.DARK_GREEN
+ "' has been deleted. They have been notified if they are online.",
NamedTextColor.DARK_GREEN)));
if (warp.tryGetOnlineOwner() != null) {
if (warp.tryGetOnlineOwner() != null && !warp.isServerWarp()) {
warp.tryGetOnlineOwner()
.sendMessage(AriasServerEssentials.getPrefix()
.append(Component.text(

View file

@ -0,0 +1,111 @@
package dev.zontreck.ase.commands.warps;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.mojang.brigadier.Command;
import dev.zontreck.ase.AriasServerEssentials;
import dev.zontreck.ase.guis.EditWarpGUI;
import dev.zontreck.ase.guis.WarpACLGUI;
import dev.zontreck.ase.warps.Warp;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
public class EditWarpCommand {
public static final String PERMISSION = "ase.commands.editwarp";
public static int execute(CommandSourceStack ctx, String warpName) {
Player player = (Player) ctx.getSender();
// Check for the warp
if (AriasServerEssentials.getSelf().warps.containsKey(warpName)) {
// Check access to the warp
if (!AriasServerEssentials.getSelf().warps.get(warpName).playerIsOwner(player)
&& !player.isPermissionSet(WarpConsts.WARP_BYPASS) && !player.isOp()) {
player.sendMessage(WarpConsts.permissionDenied);
return Command.SINGLE_SUCCESS;
}
} else {
player.sendMessage(WarpConsts.noWarp);
return Command.SINGLE_SUCCESS;
}
EditWarpGUI.openGUI(player, warpName);
return Command.SINGLE_SUCCESS;
}
public static int runAction(CommandSourceStack ctx, String warpName, EditTypes type, String rawArgs) {
Player player = (Player) ctx.getSender();
String[] args = rawArgs.split(" ");
if (AriasServerEssentials.getSelf().warps.containsKey(warpName)) {
Warp warp = AriasServerEssentials.getSelf().warps.get(warpName);
if (warp.playerIsOwner(player) || player.isPermissionSet(WarpConsts.WARP_BYPASS)) {
switch (type) {
case access:
if (warp.owningPlayer.toString().equals(new UUID(0, 0).toString())) {
player.sendMessage(
Component.text("A server warp cannot be made private", NamedTextColor.DARK_RED));
return Command.SINGLE_SUCCESS;
}
warp.isPublic = !warp.isPublic;
AriasServerEssentials.getSelf().warps.put(warpName, warp);
AriasServerEssentials.getSelf().SaveConfiguration();
break;
case mksrvwarp:
warp.owningPlayer = new UUID(0, 0);
warp.isPublic = true;
AriasServerEssentials.getSelf().warps.put(warpName, warp);
AriasServerEssentials.getSelf().SaveConfiguration();
break;
case acl:
// Open the ACL Editor GUI
WarpACLGUI.openGUI(player, warp, 0);
break;
case addacl:
if (args.length == 0 || args[0].isEmpty())
WarpACLGUI.openAdd(player, warp, 0);
else
WarpACLGUI.openAdd(player, warp, Integer.parseInt(args[0]));
break;
case trust:
if (args.length == 0 || args[0].isEmpty()) {
// silent failure. No player name was specified.
} else {
// Trust the specified player
Player toTrust = Bukkit.getPlayer(args[0]);
warp.allowedPlayers.add(toTrust.getUniqueId());
AriasServerEssentials.getSelf().warps.put(warpName, warp);
AriasServerEssentials.getSelf().SaveConfiguration();
}
break;
default:
break;
}
} else {
player.sendMessage(WarpConsts.permissionDenied);
}
} else {
player.sendMessage(WarpConsts.noWarp);
}
return Command.SINGLE_SUCCESS;
}
public enum EditTypes {
access,
mksrvwarp,
acl,
addacl,
trust
}
}

View file

@ -1,5 +1,7 @@
package dev.zontreck.ase.commands.warps;
import java.util.UUID;
import dev.zontreck.ase.AriasServerEssentials;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
@ -14,4 +16,10 @@ public class WarpConsts {
NamedTextColor.DARK_RED));
public static final String WARP_BYPASS = "ase.warp.bypass";
public static final String NULL_ID;
static {
NULL_ID = new UUID(0, 0).toString();
}
}

View file

@ -0,0 +1,96 @@
package dev.zontreck.ase.guis;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import dev.zontreck.ase.AriasServerEssentials;
import dev.zontreck.ase.warps.Warp;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
public class EditWarpGUI {
public static void openGUI(Player player, String warpName) {
ChestGUI gui = new ChestGUI("Edit Warp : " + warpName, (9 * 6));
gui.setPlayer(player);
gui.floodFill(ChestGUI.NullItem);
gui.seek(10); // A
/*
* #########
* #AL######
* #########
* #########
* #U##T##D#
* #########
*
*
* A = Access toggle
* U = Update button
* D = Delete button
* T = Transfer ownership to system. (OP only)
* L = Access Control List editing (Private only)
*
*/
Warp warp = AriasServerEssentials.getSelf().warps.get(warpName);
PrimitiveItem accessToggle = new PrimitiveItem(warp.isPublic ? Material.GREEN_WOOL : Material.RED_WOOL,
Component.text("Access", NamedTextColor.YELLOW), true,
Component.text("Public: ", NamedTextColor.AQUA).append(Component.text(warp.isPublic ? "Yes" : "No",
warp.isPublic ? NamedTextColor.DARK_GREEN : NamedTextColor.DARK_RED)));
accessToggle.addAction(new PrimitiveAction(PrimitiveAction.SEND_COMMAND, "editwarp " + warpName + " access"));
// accessToggle.addAction(new PrimitiveAction(PrimitiveAction.CLOSE_GUI));
accessToggle.addAction(new PrimitiveAction(PrimitiveAction.SEND_COMMAND, "editwarp " + warpName));
gui.add(accessToggle);
gui.seek((9 * 4) + 1); // U
// This button will be the update button
PrimitiveItem update = new PrimitiveItem(Material.GOLDEN_HOE, Component.text("Update", NamedTextColor.YELLOW),
true, Component.text("Update the position of the warp", NamedTextColor.AQUA));
update.addAction(new PrimitiveAction(PrimitiveAction.SEND_COMMAND, "setwarp " + warpName));
gui.add(update);
gui.seek((9 * 4) + 4); // T
if (player.isOp() && !warp.isServerWarp()) {
PrimitiveItem transfer = new PrimitiveItem(Material.BEDROCK,
Component.text("SERVER WARP", NamedTextColor.YELLOW), true,
Component.text(
"Transfer the warp to the ownership of the server. This cannot be undone without deleting the warp first.",
NamedTextColor.DARK_RED));
transfer.addAction(
new PrimitiveAction(PrimitiveAction.SEND_COMMAND, "editwarp " + warpName + " mksrvwarp"));
// transfer.addAction(new PrimitiveAction(PrimitiveAction.CLOSE_GUI));
transfer.addAction(new PrimitiveAction(PrimitiveAction.SEND_COMMAND, "editwarp " + warpName));
gui.add(transfer);
} else {
if (warp.isServerWarp()) {
PrimitiveItem srvwarp = new PrimitiveItem(Material.COMMAND_BLOCK,
Component.text("SERVER WARP", NamedTextColor.YELLOW), true,
Component.text("This warp is owned by the server.", NamedTextColor.DARK_RED));
gui.add(srvwarp);
}
}
gui.seek((9 * 4) + 4 + 3); // D
PrimitiveItem deleteItem = new PrimitiveItem(Material.DRIED_KELP,
Component.text("Delete Warp", NamedTextColor.YELLOW), true,
Component.text("- This button will delete the warp. This cannot be undone.", NamedTextColor.DARK_RED));
deleteItem.addAction(new PrimitiveAction(PrimitiveAction.SEND_COMMAND, "delwarp " + warpName));
deleteItem.addAction(new PrimitiveAction(PrimitiveAction.CLOSE_GUI));
gui.add(deleteItem);
gui.seek(11); // L
PrimitiveItem aclItem = new PrimitiveItem(Material.PAPER, Component.text("Access List", NamedTextColor.YELLOW),
true, Component.text("Management interface for the Access Control List", NamedTextColor.DARK_PURPLE));
aclItem.addAction(new PrimitiveAction(PrimitiveAction.SEND_COMMAND, "editwarp " + warpName + " acl"));
gui.add(aclItem);
gui.doPresentation();
}
}

View file

@ -13,6 +13,10 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import dev.zontreck.ase.AriasServerEssentials;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
@ -20,8 +24,8 @@ import net.kyori.adventure.title.Title;
import net.kyori.adventure.title.Title.Times;
public class PrimitiveAction {
public static final int NONE = 0;
public static final int OPEN_GUI = 1;
public static final int CLOSE_GUI = 2;
public static final int SEND_MESSAGE = 3;
public static final int SEND_COMMAND = 4;
@ -64,73 +68,65 @@ public class PrimitiveAction {
switch (actionType) {
case NONE:
return;
case OPEN_GUI:
// Handle opening a GUI (implement your logic here)
break;
case CLOSE_GUI:
player.closeInventory();
break;
case SEND_MESSAGE:
// Send a message to the player
player.sendMessage(deserializeComponent(actionData));
break;
case SEND_COMMAND:
// Execute a command (you can execute the command here)
player.performCommand(actionData);
break;
case SEND_SYSTEM_COMMAND:
// Executes a system command, ignores player's permissions.
player.getServer().dispatchCommand(null, actionData);
break;
case SEND_ACTIONBAR:
// Send an action bar message (You can use a plugin like Adventure API for this)
player.sendActionBar(deserializeComponent(actionData));
break;
case SEND_TITLE:
// Send a title message
player.showTitle(Title.title(deserializeComponent(actionData), Component.empty(),
Times.times(Duration.ofSeconds(1), Duration.ofSeconds(5), Duration.ofSeconds(1))));
break;
case SEND_SOUND:
// Play a sound to the player
// Example: player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP,
// 1, 1);
break;
case SEND_PARTICLE:
// Send a particle effect to the player
// Example: player.spawnParticle(Particle.EXPLOSION_LARGE, player.getLocation(),
// 1);
break;
case SEND_EFFECT:
// Apply a potion effect (can be customized)
// Example: player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 200,
// 1));
break;
}
}
// Attach a list of actions to an item with Base64 encoding
// Attach a list of actions to an item with Base64 encoding (using JSON format)
public static ItemStack attachActions(List<PrimitiveAction> actions, ItemStack item) {
return attach(item, ACTIONS, actions.toArray(new PrimitiveAction[0]));
}
public static ItemStack attachSingleAction(PrimitiveAction action, ItemStack item, String tag) {
return attach(item, tag, action);
}
private static ItemStack attach(ItemStack item, String encodeTag, PrimitiveAction... actions) {
ItemMeta meta = item.getItemMeta();
if (meta == null) {
return item; // No meta available
}
// Serialize the list of actions into a string
StringBuilder serializedActions = new StringBuilder();
// Create a JSON array to store the actions
JsonArray actionsJsonArray = new JsonArray();
for (PrimitiveAction action : actions) {
String actionString = action.actionType + ":"
+ Base64.getEncoder().encodeToString(action.actionData.getBytes(StandardCharsets.UTF_8));
serializedActions.append(actionString).append(";");
JsonObject actionJson = new JsonObject();
actionJson.addProperty(ACTION_TYPE, action.actionType);
actionJson.addProperty(ACTION_DATA, action.actionData);
actionsJsonArray.add(actionJson);
}
// Base64 encode the serialized actions string
// Base64 encode the JSON array
String base64EncodedActions = Base64.getEncoder()
.encodeToString(serializedActions.toString().getBytes(StandardCharsets.UTF_8));
.encodeToString(actionsJsonArray.toString().getBytes(StandardCharsets.UTF_8));
// Store the Base64 encoded actions in the persistent data container
PersistentDataContainer data = meta.getPersistentDataContainer();
data.set(NamespacedKey.fromString(ACTIONS, AriasServerEssentials.getSelf()), PersistentDataType.STRING,
data.set(NamespacedKey.fromString(encodeTag, AriasServerEssentials.getSelf()), PersistentDataType.STRING,
base64EncodedActions);
item.setItemMeta(meta);
@ -140,13 +136,17 @@ public class PrimitiveAction {
// Get the actions stored in the item's PersistentDataContainer with Base64
// decoding
public static List<PrimitiveAction> getActions(ItemStack item) {
return get(item, ACTIONS);
}
private static List<PrimitiveAction> get(ItemStack item, String tag) {
ItemMeta meta = item.getItemMeta();
if (meta == null) {
return new ArrayList<>(); // No meta available
}
PersistentDataContainer data = meta.getPersistentDataContainer();
String base64EncodedActions = data.get(NamespacedKey.fromString(ACTIONS, AriasServerEssentials.getSelf()),
String base64EncodedActions = data.get(NamespacedKey.fromString(tag, AriasServerEssentials.getSelf()),
PersistentDataType.STRING);
if (base64EncodedActions == null || base64EncodedActions.isEmpty()) {
@ -157,25 +157,29 @@ public class PrimitiveAction {
String decodedActions = new String(Base64.getDecoder().decode(base64EncodedActions), StandardCharsets.UTF_8);
List<PrimitiveAction> actions = new ArrayList<>();
String[] actionsArray = decodedActions.split(";");
try {
// Parse the decoded JSON string into a JsonArray
JsonArray actionsJsonArray = JsonParser.parseString(decodedActions).getAsJsonArray();
for (String actionString : actionsArray) {
if (!actionString.isEmpty()) {
String[] actionParts = actionString.split(":");
if (actionParts.length == 2) {
try {
int actionType = Integer.parseInt(actionParts[0]);
String actionData = new String(Base64.getDecoder().decode(actionParts[1]),
StandardCharsets.UTF_8);
actions.add(new PrimitiveAction(actionType, actionData));
} catch (NumberFormatException e) {
// Handle invalid action type (logging, skipping, etc.)
continue;
}
}
// Iterate over each action and create PrimitiveAction instances
for (int i = 0; i < actionsJsonArray.size(); i++) {
JsonObject actionJson = actionsJsonArray.get(i).getAsJsonObject();
int actionType = actionJson.get(ACTION_TYPE).getAsInt();
String actionData = actionJson.get(ACTION_DATA).getAsString();
actions.add(new PrimitiveAction(actionType, actionData));
// AriasServerEssentials.getSelf().getLogger()
// .info("Deserialized action: " + actionType + "; " + actionData);
}
} catch (Exception e) {
e.printStackTrace();
// Handle invalid or corrupt JSON
}
return actions;
}
public static List<PrimitiveAction> getSingleAction(ItemStack currentItem, String tag) {
return get(currentItem, tag);
}
}

View file

@ -27,6 +27,7 @@ public class PrimitiveItem {
public boolean isSkull = false;
public String skullOwner = "";
public List<PrimitiveAction> actions = new ArrayList<>();
public PrimitiveAction shiftClickAction = new PrimitiveAction(PrimitiveAction.NONE);
public PrimitiveItem(Material type, Component name, boolean isGUIButton, Component... lore) {
itemType = type;
@ -75,6 +76,7 @@ public class PrimitiveItem {
item.setItemMeta(meta);
item = PrimitiveAction.attachActions(actions, item);
item = PrimitiveAction.attachSingleAction(shiftClickAction, item, "shiftclickaction");
return item;
}

View file

@ -0,0 +1,162 @@
package dev.zontreck.ase.guis;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import dev.zontreck.ase.warps.Warp;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
public class WarpACLGUI {
public static void openGUI(Player player, Warp warp, int page) {
/*
* #########
* #PPPPPPP#
* #PPPPPPP#
* #PPPPPPP#
* #PPPPPPP#
* B##XWN##A
*
*
* B = Back button - Go to WarpEdit gui
* P = Authorized player
* A = add new entry
* W = warp details / acl page number
* N = next acl page
* X = previous acl page
*
* Total ACL Entries per page: 28
*/
String warpName = warp.warpName;
ChestGUI gui = new ChestGUI("Warp ACL Editor : " + warpName, (9 * 6));
gui.setPlayer(player);
gui.floodFill(ChestGUI.NullItem);
gui.seek((9 * 5)); // B
PrimitiveItem backButton = new PrimitiveItem(Material.RED_STAINED_GLASS_PANE,
Component.text("Back to Edit Warp", NamedTextColor.YELLOW), true,
Component.text("Takes you back to the /editwarp gui", NamedTextColor.DARK_PURPLE));
backButton.addAction(new PrimitiveAction(PrimitiveAction.SEND_COMMAND, "editwarp " + warpName));
gui.add(backButton);
gui.seek((9 * 6) - 1);
PrimitiveItem addButton = new PrimitiveItem(Material.WEATHERED_COPPER,
Component.text("Add New Entry", NamedTextColor.YELLOW), true,
Component.text("Add a new player to the allowed list!", NamedTextColor.DARK_GREEN));
addButton.addAction(new PrimitiveAction(PrimitiveAction.SEND_COMMAND, "editwarp " + warpName + " addacl"));
gui.add(addButton);
gui.doPresentation();
}
public static void openAdd(Player player, Warp warp, int page) {
/*
*
* #########
* #PPPPPPP#
* #PPPPPPP#
* #PPPPPPP#
* #PPPPPPP#
* C##BTN###
*
* C = cancel
* P = possible player or null item
* B = previous page button
* T = current page indication
* N = next page indication
*
* Maximum players per page: 28
*/
String warpName = warp.warpName;
ChestGUI gui = new ChestGUI("Add ACL : " + warpName, (9 * 6));
gui.setPlayer(player);
gui.floodFill(ChestGUI.NullItem);
gui.seek((9 * 5)); // C
PrimitiveItem backButton = new PrimitiveItem(Material.RED_STAINED_GLASS_PANE,
Component.text("Back to Warp ACL", NamedTextColor.YELLOW), true,
Component.text("Takes you back to the ACL Listing", NamedTextColor.DARK_PURPLE));
backButton.addAction(new PrimitiveAction(PrimitiveAction.SEND_COMMAND, "editwarp " + warpName + " acl"));
gui.add(backButton);
int startPos = page * 28;
if (startPos > 0)
startPos++;
int totalPlayers = Bukkit.getOnlinePlayers().size();
int pageNumber = startPos / 28;
int totalPages = totalPlayers / 28;
PrimitiveItem pageIndication = new PrimitiveItem(null,
Component.text("Page " + (pageNumber + 1) + " / " + (totalPages + 1), NamedTextColor.YELLOW), true,
Component.text("Total online players: ", NamedTextColor.AQUA)
.append(Component.text("" + totalPlayers, NamedTextColor.DARK_GREEN)));
pageIndication.skull(player.getName());
gui.seek((9 * 5) + 4);
gui.add(pageIndication);
gui.seek(10);
int row = 0;
Player[] onlinePlayers = Bukkit.getOnlinePlayers().toArray(new Player[0]);
for (int i = startPos; i < 28; i++) {
if (i >= onlinePlayers.length) {
// We've reached the end, break from loop
break;
}
Player plyr = onlinePlayers[i];
if (warp.playerIsOwner(plyr) || warp.hasAccess(plyr)) {
continue; // Don't add to the ACL menu
}
PrimitiveItem head = new PrimitiveItem(null, Component.text(plyr.getName(), NamedTextColor.YELLOW), true,
Component.text("Click to trust this player. They will gain access to the warp.",
NamedTextColor.DARK_PURPLE));
head.skull(plyr.getName());
head.addAction(new PrimitiveAction(PrimitiveAction.SEND_COMMAND,
"editwarp " + warpName + " trust " + plyr.getName()));
head.addAction(new PrimitiveAction(PrimitiveAction.SEND_COMMAND,
"editwarp " + warpName + " addacl " + pageNumber));
gui.add(head);
if (row > 7) {
row = 0;
gui.seek(gui.getPosition() + 2);
}
}
gui.seek((9 * 5) + 3);
// Prev Page button
if (startPos > 0) {
PrimitiveItem prevButton = new PrimitiveItem(Material.GREEN_STAINED_GLASS_PANE,
Component.text("<- Previous Page", NamedTextColor.YELLOW), true,
Component.text("Go to the previous page"));
prevButton.addAction(new PrimitiveAction(PrimitiveAction.SEND_COMMAND,
"editwarp " + warpName + " addacl " + (pageNumber - 1)));
gui.add(prevButton);
}
// Next page button
gui.seek((9 * 5) + 5);
if (pageNumber < totalPages) {
PrimitiveItem nextButton = new PrimitiveItem(Material.RED_STAINED_GLASS_PANE,
Component.text("Next Page ->", NamedTextColor.YELLOW), true,
Component.text("Go to the next page"));
nextButton.addAction(new PrimitiveAction(PrimitiveAction.SEND_COMMAND,
"editwarp " + warpName + " addacl " + (pageNumber + 1)));
gui.add(nextButton);
}
gui.doPresentation();
}
}

View file

@ -86,14 +86,24 @@ public class WarpsGUI {
lore.add(Component.text("Public: ", NamedTextColor.AQUA)
.append(Component.text(theWarp.isPublic ? "True" : "False",
theWarp.isPublic ? NamedTextColor.DARK_GREEN : NamedTextColor.DARK_RED)));
lore.add(Component.text("Owner: ", NamedTextColor.AQUA)
.append(Component.text(theWarp.getOwner().getName(), NamedTextColor.DARK_PURPLE)));
if (theWarp.isServerWarp())
lore.add(Component.text("*Server Warp*", NamedTextColor.DARK_PURPLE));
else
lore.add(Component.text("Owner: ", NamedTextColor.AQUA)
.append(Component.text(theWarp.getOwner().getName(), NamedTextColor.DARK_PURPLE)));
PrimitiveItem warpItem = new PrimitiveItem(null,
Component.text(theWarp.warpName,
Style.style(NamedTextColor.YELLOW, TextDecoration.BOLD, TextDecoration.ITALIC)),
true, lore.toArray(new Component[0]));
warpItem.skull(theWarp.getOwner().getName());
if (theWarp.isServerWarp()) {
warpItem.itemType = Material.COMMAND_BLOCK;
warpItem.isSkull = false;
warpItem.skullOwner = "";
} else
warpItem.skull(theWarp.getOwner().getName());
warpItem.addAction(new PrimitiveAction(PrimitiveAction.CLOSE_GUI));
warpItem.addAction(new PrimitiveAction(PrimitiveAction.SEND_COMMAND, "warp " + theWarp.warpName));

View file

@ -10,6 +10,8 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import dev.zontreck.ase.commands.warps.WarpConsts;
public class Warp {
public String warpName;
public UUID owningPlayer;
@ -80,4 +82,11 @@ public class Warp {
return false;
}
public boolean isServerWarp() {
if (owningPlayer.toString().equals(WarpConsts.NULL_ID))
return true;
else
return false;
}
}

View file

@ -57,6 +57,12 @@ commands:
warps:
description: Lists all warps!
usage: "- /warps -"
editwarp:
description: Edit a warp
usage: "- /editwarp [name] -"
closeinv:
description: Close inventory (Helper function)
usage: "- /closeinv -"
permissions:
ase.commands.*:
description: Allow all commands
@ -77,6 +83,7 @@ permissions:
ase.commands.delwarp: true
ase.commands.warp: true
ase.commands.warps: true
ase.commands.editwarp: true
ase.commands.home:
description: Allows usage of the /home command
default: true
@ -131,3 +138,6 @@ permissions:
ase.commands.warps:
description: Allows listing all warps
default: true
ase.commands.editwarp:
description: Allows editing warps
default: true

View file

@ -57,6 +57,12 @@ commands:
warps:
description: Lists all warps!
usage: "- /warps -"
editwarp:
description: Edit a warp
usage: "- /editwarp [name] -"
closeinv:
description: Close inventory (Helper function)
usage: "- /closeinv -"
permissions:
ase.commands.*:
description: Allow all commands
@ -77,6 +83,7 @@ permissions:
ase.commands.delwarp: true
ase.commands.warp: true
ase.commands.warps: true
ase.commands.editwarp: true
ase.commands.home:
description: Allows usage of the /home command
default: true
@ -125,9 +132,12 @@ permissions:
ase.commands.warp:
description: Allows going to warps
default: true
ase.commands.warp.bypass:
description: Administrative access to private warps. This permission also will show private warps inside the /warps listing.
ase.warp.bypass:
description: Administrative access to private warps. This permission also will show private warps inside the /warps listing. This privilege will also allow deleting other users' warps.
default: false
ase.commands.warps:
description: Allows listing all warps
default: true
ase.commands.editwarp:
description: Allows editing warps
default: true