Add /warps
This commit is contained in:
parent
496525760d
commit
17a8a4e170
11 changed files with 227 additions and 15 deletions
|
@ -1,5 +1,6 @@
|
|||
package dev.zontreck.ase.commands;
|
||||
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
|
||||
import dev.zontreck.ase.commands.homes.DelHomeCommand;
|
||||
|
@ -17,6 +18,7 @@ import dev.zontreck.ase.commands.tpa.TPDenyCommand;
|
|||
import dev.zontreck.ase.commands.warps.DelWarpCommand;
|
||||
import dev.zontreck.ase.commands.warps.SetWarpCommand;
|
||||
import dev.zontreck.ase.commands.warps.WarpCommand;
|
||||
import dev.zontreck.ase.commands.warps.WarpsCommand;
|
||||
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;
|
||||
|
@ -140,5 +142,14 @@ public class CommandRegistry {
|
|||
.build()
|
||||
|
||||
);
|
||||
cmds.register(Commands.literal("warps")
|
||||
.requires(x -> x.getSender().isPermissionSet(WarpsCommand.PERMISSION))
|
||||
.executes(ctx -> WarpsCommand.execute(ctx.getSource(), 0))
|
||||
.then(Commands.argument("page", IntegerArgumentType.integer())
|
||||
.executes(ctx -> WarpsCommand.execute(ctx.getSource(),
|
||||
IntegerArgumentType.getInteger(ctx, "page"))))
|
||||
.build()
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public class DelWarpCommand {
|
|||
// 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(OTHERPERMISSION) || player.isPermissionSet(WarpConsts.WARP_BYPASS)) {
|
||||
// 3. Check if the current player isn't owner.
|
||||
boolean isDifferentPlayer = !warp.playerIsOwner(player);
|
||||
if (isDifferentPlayer) {
|
||||
|
|
|
@ -12,7 +12,6 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
|||
|
||||
public class WarpCommand {
|
||||
public static final String PERMISSION = "ase.commands.warp";
|
||||
public static final String OTHERPERMISSION = "ase.commands.warp.bypass";
|
||||
|
||||
public static int execute(CommandSourceStack source, String warpName) {
|
||||
Player player = (Player) source.getSender();
|
||||
|
@ -22,7 +21,7 @@ public class WarpCommand {
|
|||
if (AriasServerEssentials.getSelf().warps.containsKey(warpName)) {
|
||||
// Check access to the warp
|
||||
Warp warp = AriasServerEssentials.getSelf().warps.get(warpName);
|
||||
if (warp.hasAccess(player) || player.isPermissionSet(OTHERPERMISSION)) {
|
||||
if (warp.hasAccess(player) || player.isPermissionSet(WarpConsts.WARP_BYPASS)) {
|
||||
player.teleport(warp.location);
|
||||
player.sendMessage(warping);
|
||||
} else {
|
||||
|
|
|
@ -12,4 +12,6 @@ public class WarpConsts {
|
|||
public static final Component permissionDenied = AriasServerEssentials.getPrefix().append(Component.text(
|
||||
"You lack permission to access, edit, or remove this warp.",
|
||||
NamedTextColor.DARK_RED));
|
||||
|
||||
public static final String WARP_BYPASS = "ase.warp.bypass";
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package dev.zontreck.ase.commands.warps;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
|
||||
import dev.zontreck.ase.guis.WarpsGUI;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
|
||||
public class WarpsCommand {
|
||||
public static final String PERMISSION = "ase.commands.warps";
|
||||
|
||||
public static int execute(CommandSourceStack ctx, int page) {
|
||||
Player player = (Player) ctx.getSender();
|
||||
|
||||
WarpsGUI.openGUI(player, page);
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
|
@ -14,6 +15,10 @@ import dev.zontreck.ase.AriasServerEssentials;
|
|||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class ChestGUI {
|
||||
|
||||
public static final PrimitiveItem NullItem = new PrimitiveItem(Material.BLACK_STAINED_GLASS_PANE,
|
||||
Component.text(""), true,
|
||||
Component.text().build());
|
||||
// START STATIC REGISTRY
|
||||
private static final List<ChestGUI> GUI_LIST = new java.util.ArrayList<>();
|
||||
|
||||
|
@ -56,6 +61,8 @@ public class ChestGUI {
|
|||
public Player player;
|
||||
public boolean closed = false;
|
||||
|
||||
private int pointer = 0;
|
||||
|
||||
public ChestGUI(String title, int size) {
|
||||
this.guiTitle = title;
|
||||
this.totalSize = size;
|
||||
|
@ -67,12 +74,31 @@ public class ChestGUI {
|
|||
|
||||
public void fill(int amount, PrimitiveItem item) {
|
||||
for (int i = 0; i < amount; i++) {
|
||||
buttons.add(item.generate());
|
||||
add(item);
|
||||
}
|
||||
}
|
||||
|
||||
public void floodFill(PrimitiveItem item) {
|
||||
for (int i = 0; i < totalSize; i++) {
|
||||
add(item);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(PrimitiveItem item) {
|
||||
buttons.add(item.generate());
|
||||
if (buttons.size() > pointer)
|
||||
buttons.set(pointer, item.generate());
|
||||
else
|
||||
buttons.add(item.generate());
|
||||
|
||||
pointer++;
|
||||
}
|
||||
|
||||
public void resetPosition() {
|
||||
pointer = 0;
|
||||
}
|
||||
|
||||
public void seek(int position) {
|
||||
pointer = position;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,4 +144,8 @@ public class ChestGUI {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public int getPosition() {
|
||||
return pointer;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,6 @@ public class CreditsGui {
|
|||
public static void openGUI(Player player) {
|
||||
// First step, construct the layout
|
||||
ChestGUI gui = new ChestGUI("Credits", 9 * 3);
|
||||
PrimitiveItem StainedGlass = new PrimitiveItem(Material.BLACK_STAINED_GLASS_PANE, Component.text(""), true,
|
||||
Component.text().build());
|
||||
|
||||
PrimitiveItem zontreckHead = new PrimitiveItem(Material.PLAYER_HEAD,
|
||||
Component.text("Aria", NamedTextColor.DARK_RED), true,
|
||||
|
@ -19,12 +17,12 @@ public class CreditsGui {
|
|||
Component.text("Creator of ASE", NamedTextColor.DARK_PURPLE));
|
||||
zontreckHead.skull("zontreck");
|
||||
|
||||
gui.fill(9, StainedGlass);
|
||||
gui.add(StainedGlass);
|
||||
gui.fill(9, ChestGUI.NullItem);
|
||||
gui.add(ChestGUI.NullItem);
|
||||
gui.add(zontreckHead);
|
||||
|
||||
gui.fill(9 - 2, StainedGlass);
|
||||
gui.fill(9, StainedGlass);
|
||||
gui.fill(9 - 2, ChestGUI.NullItem);
|
||||
gui.fill(9, ChestGUI.NullItem);
|
||||
|
||||
// Second step, present to the player
|
||||
gui.setPlayer(player);
|
||||
|
|
|
@ -91,9 +91,9 @@ public class PrimitiveItem {
|
|||
PersistentDataType.BOOLEAN);
|
||||
}
|
||||
|
||||
public void skull(String string) {
|
||||
public void skull(String playerName) {
|
||||
isSkull = true;
|
||||
skullOwner = string;
|
||||
skullOwner = playerName;
|
||||
itemType = Material.PLAYER_HEAD;
|
||||
}
|
||||
|
||||
|
|
135
src/main/java/dev/zontreck/ase/guis/WarpsGUI.java
Normal file
135
src/main/java/dev/zontreck/ase/guis/WarpsGUI.java
Normal file
|
@ -0,0 +1,135 @@
|
|||
package dev.zontreck.ase.guis;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.zontreck.ase.AriasServerEssentials;
|
||||
import dev.zontreck.ase.commands.warps.WarpConsts;
|
||||
import dev.zontreck.ase.warps.Warp;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
|
||||
public class WarpsGUI {
|
||||
public static void openGUI(Player player, int page) {
|
||||
// Perform Layout
|
||||
ChestGUI gui = new ChestGUI("Warps", 9 * 6);
|
||||
gui.floodFill(ChestGUI.NullItem);
|
||||
gui.setPlayer(player);
|
||||
gui.seek(10);
|
||||
// We skip the entire first row, and the first element.
|
||||
/*
|
||||
* #########
|
||||
* #IIIIIII#
|
||||
* #IIIIIII#
|
||||
* #IIIIIII#
|
||||
* #IIIIIII#
|
||||
* ###BPN###
|
||||
*
|
||||
* # = nullItem
|
||||
* I = possible warp or null
|
||||
* P = current player's head - include page number.
|
||||
* B = Back button if applicable. null otherwise
|
||||
* N = next button if applicable. null otherwise.
|
||||
*
|
||||
*
|
||||
* Total real space for warps: 28
|
||||
*
|
||||
*/
|
||||
|
||||
int startPos = page * 28;
|
||||
if (startPos > 0)
|
||||
startPos++;
|
||||
|
||||
// We now perform some sanity checks
|
||||
int totalWarps = AriasServerEssentials.getSelf().warps.size();
|
||||
if (startPos >= totalWarps)
|
||||
startPos = 0; // Start at page 0.
|
||||
int pageNumber = startPos / 28;
|
||||
|
||||
// Generate the player head for showing the currnet page and total warps info.
|
||||
boolean isOp = player.isOp();
|
||||
|
||||
List<Component> lore = new ArrayList<>();
|
||||
|
||||
if (isOp)
|
||||
lore.add(Component.text("** OPERATOR **", NamedTextColor.DARK_RED));
|
||||
boolean hasBypass = player.isPermissionSet(WarpConsts.WARP_BYPASS);
|
||||
if (hasBypass || isOp)
|
||||
lore.add(Component.text("You have the ability to access other players' private warps",
|
||||
NamedTextColor.DARK_PURPLE));
|
||||
|
||||
PrimitiveItem playerHead = new PrimitiveItem(Material.PLAYER_HEAD,
|
||||
Component.text("Page " + (pageNumber + 1) + " / " + ((totalWarps / 28) + 1)), true,
|
||||
lore.toArray(new Component[0]));
|
||||
playerHead.skull(player.getName());
|
||||
|
||||
gui.seek((9 * 5) + 4);
|
||||
gui.add(playerHead);
|
||||
|
||||
gui.seek(10); // Move to the first possible position for a warp
|
||||
|
||||
Warp[] warps = AriasServerEssentials.getSelf().warps.values().toArray(new Warp[0]);
|
||||
int row = 0;
|
||||
for (int ix = startPos; ix < startPos + 28; ix++) {
|
||||
// Try to retrieve the indicated warp
|
||||
if (warps.length > ix) {
|
||||
Warp theWarp = warps[ix];
|
||||
// Check access privileges.
|
||||
|
||||
if (theWarp.hasAccess(player) || player.isPermissionSet(WarpConsts.WARP_BYPASS)) {
|
||||
lore = new ArrayList<>();
|
||||
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)));
|
||||
|
||||
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());
|
||||
warpItem.addAction(new PrimitiveAction(PrimitiveAction.CLOSE_GUI));
|
||||
warpItem.addAction(new PrimitiveAction(PrimitiveAction.SEND_COMMAND, "warp " + theWarp.warpName));
|
||||
|
||||
gui.add(warpItem);
|
||||
row++;
|
||||
|
||||
if (row >= 7) {
|
||||
row = 0;
|
||||
gui.seek(gui.getPosition() + 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (startPos + 28 < totalWarps) {
|
||||
// Add a next button!
|
||||
gui.seek((9 * 5) + 5);
|
||||
PrimitiveItem nextButton = new PrimitiveItem(Material.GREEN_STAINED_GLASS_PANE,
|
||||
Component.text("Next ->", NamedTextColor.YELLOW), true);
|
||||
nextButton.addAction(new PrimitiveAction(PrimitiveAction.CLOSE_GUI));
|
||||
nextButton.addAction(new PrimitiveAction(PrimitiveAction.SEND_COMMAND, "warps " + (pageNumber + 1)));
|
||||
|
||||
gui.add(nextButton);
|
||||
}
|
||||
|
||||
if (startPos > 0) {
|
||||
// Add a back button!
|
||||
gui.seek((9 * 5) + 3);
|
||||
PrimitiveItem nextButton = new PrimitiveItem(Material.RED_STAINED_GLASS_PANE,
|
||||
Component.text("<- Back", NamedTextColor.YELLOW), true);
|
||||
nextButton.addAction(new PrimitiveAction(PrimitiveAction.CLOSE_GUI));
|
||||
nextButton.addAction(new PrimitiveAction(PrimitiveAction.SEND_COMMAND, "warps " + (pageNumber - 1)));
|
||||
|
||||
gui.add(nextButton);
|
||||
}
|
||||
|
||||
gui.doPresentation();
|
||||
}
|
||||
}
|
|
@ -54,6 +54,9 @@ commands:
|
|||
warp:
|
||||
description: Go to warp
|
||||
usage: "- /warp [name] -"
|
||||
warps:
|
||||
description: Lists all warps!
|
||||
usage: "- /warps -"
|
||||
permissions:
|
||||
ase.commands.*:
|
||||
description: Allow all commands
|
||||
|
@ -73,6 +76,7 @@ permissions:
|
|||
ase.commands.setwarp: true
|
||||
ase.commands.delwarp: true
|
||||
ase.commands.warp: true
|
||||
ase.commands.warps: true
|
||||
ase.commands.home:
|
||||
description: Allows usage of the /home command
|
||||
default: true
|
||||
|
@ -121,6 +125,9 @@ 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
|
||||
|
|
|
@ -54,6 +54,9 @@ commands:
|
|||
warp:
|
||||
description: Go to warp
|
||||
usage: "- /warp [name] -"
|
||||
warps:
|
||||
description: Lists all warps!
|
||||
usage: "- /warps -"
|
||||
permissions:
|
||||
ase.commands.*:
|
||||
description: Allow all commands
|
||||
|
@ -73,6 +76,7 @@ permissions:
|
|||
ase.commands.setwarp: true
|
||||
ase.commands.delwarp: true
|
||||
ase.commands.warp: true
|
||||
ase.commands.warps: true
|
||||
ase.commands.home:
|
||||
description: Allows usage of the /home command
|
||||
default: true
|
||||
|
@ -121,3 +125,9 @@ 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.
|
||||
default: false
|
||||
ase.commands.warps:
|
||||
description: Allows listing all warps
|
||||
default: true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue