forked from unimatrix/web
Add operator admin GUI and automatic blaze rod scepter
This commit is contained in:
parent
6670d60b5c
commit
a1d09f96b4
6 changed files with 165 additions and 4 deletions
|
|
@ -1,6 +1,6 @@
|
|||
plugins { java }
|
||||
group = "com.example"
|
||||
version = "1.0.5"
|
||||
version = "1.0.6"
|
||||
repositories { mavenCentral(); maven("https://repo.papermc.io/repository/maven-public/"); maven("https://jitpack.io") }
|
||||
dependencies {
|
||||
compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,111 @@
|
|||
package com.example.dunerealms;
|
||||
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.*;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.inventory.*;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.*;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/** Operator-only controls. The persistent tag, rather than the display name, identifies the rod. */
|
||||
final class AdminGui implements Listener {
|
||||
private final DuneCore plugin;
|
||||
private final NamespacedKey rodKey;
|
||||
private static final Map<Integer, String> COMMANDS = Map.of(
|
||||
10, "summon sandworm", 12, "guildnpc", 14, "givespice",
|
||||
16, "guireload", 20, "kit", 24, "politics status");
|
||||
|
||||
private static final class Menu implements InventoryHolder {
|
||||
private Inventory inventory;
|
||||
@Override public Inventory getInventory() { return inventory; }
|
||||
}
|
||||
|
||||
AdminGui(DuneCore plugin) {
|
||||
this.plugin = plugin;
|
||||
rodKey = new NamespacedKey(plugin, "admin_rod");
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
// Also handles newly opped online players and retries when an inventory was full.
|
||||
Bukkit.getScheduler().runTaskTimer(plugin, () -> {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (player.isOp()) giveRod(player);
|
||||
else if (player.getOpenInventory().getTopInventory().getHolder() instanceof Menu)
|
||||
player.closeInventory();
|
||||
}
|
||||
}, 1L, 100L);
|
||||
}
|
||||
|
||||
boolean isRod(ItemStack item) {
|
||||
return item != null && item.getType() == Material.BLAZE_ROD && item.hasItemMeta()
|
||||
&& item.getItemMeta().getPersistentDataContainer().has(rodKey, PersistentDataType.BYTE);
|
||||
}
|
||||
|
||||
void giveRod(Player player) {
|
||||
if (!player.isOp()) return;
|
||||
for (ItemStack item : player.getInventory().getContents()) if (isRod(item)) return;
|
||||
if (player.getInventory().firstEmpty() < 0) return;
|
||||
ItemStack rod = icon(Material.BLAZE_ROD, "Imperial Admin Scepter",
|
||||
"Right-click to open the admin controls.", "Operators only.");
|
||||
ItemMeta meta = rod.getItemMeta();
|
||||
meta.getPersistentDataContainer().set(rodKey, PersistentDataType.BYTE, (byte) 1);
|
||||
meta.setEnchantmentGlintOverride(true);
|
||||
meta.setCustomModelData(1006);
|
||||
rod.setItemMeta(meta);
|
||||
player.getInventory().addItem(rod);
|
||||
}
|
||||
|
||||
void open(Player player) {
|
||||
if (!player.isOp()) { player.sendMessage(ChatColor.RED + "Operators only."); return; }
|
||||
Menu holder = new Menu();
|
||||
holder.inventory = Bukkit.createInventory(holder, 36, ChatColor.GOLD + "Dune | Imperial Administration");
|
||||
for (int slot = 0; slot < 36; slot++) holder.inventory.setItem(slot, icon(Material.BLACK_STAINED_GLASS_PANE, " "));
|
||||
holder.inventory.setItem(10, icon(Material.SNIFFER_SPAWN_EGG, "Summon Shai-Hulud", "Spawn a sandworm at your position on Arrakis."));
|
||||
holder.inventory.setItem(12, icon(Material.VILLAGER_SPAWN_EGG, "Place Guild Navigator", "Spawn a Guild NPC at your position."));
|
||||
holder.inventory.setItem(14, icon(Material.ORANGE_DYE, "Give Test Spice", "Receive one tagged spice item."));
|
||||
holder.inventory.setItem(16, icon(Material.COMPARATOR, "Reload Menus", "Reload gui.yml from disk."));
|
||||
holder.inventory.setItem(20, icon(Material.NETHERITE_CHESTPLATE, "Receive Faction Kit", "Receive your selected faction's kit."));
|
||||
holder.inventory.setItem(24, icon(Material.WRITABLE_BOOK, "Imperial Status", "View politics, appointments and Trust status."));
|
||||
holder.inventory.setItem(31, icon(Material.BARRIER, "Close"));
|
||||
player.openInventory(holder.inventory);
|
||||
}
|
||||
|
||||
private ItemStack icon(Material material, String name, String... lore) {
|
||||
ItemStack item = new ItemStack(material);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.GOLD + name);
|
||||
meta.setLore(List.of(lore).stream().map(line -> ChatColor.GRAY + line).toList());
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@EventHandler public void interact(PlayerInteractEvent event) {
|
||||
if (!isRod(event.getItem())) return;
|
||||
event.setCancelled(true);
|
||||
if (event.getHand() != EquipmentSlot.HAND) return;
|
||||
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)
|
||||
open(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler public void click(InventoryClickEvent event) {
|
||||
if (!(event.getView().getTopInventory().getHolder() instanceof Menu)) return;
|
||||
event.setCancelled(true);
|
||||
if (!(event.getWhoClicked() instanceof Player player)) return;
|
||||
if (!player.isOp()) { player.closeInventory(); return; }
|
||||
if (event.getClickedInventory() != event.getView().getTopInventory()) return;
|
||||
String command = COMMANDS.get(event.getRawSlot());
|
||||
if (command == null && event.getRawSlot() != 31) return;
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (!player.isOnline()) return;
|
||||
player.closeInventory();
|
||||
if (player.isOp() && command != null) plugin.runGuiCommand(player, command);
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler public void drag(InventoryDragEvent event) {
|
||||
if (event.getView().getTopInventory().getHolder() instanceof Menu) event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -58,6 +58,7 @@ public final class DuneCore extends JavaPlugin implements Listener, CommandExecu
|
|||
private ServerJobs serverJobs;
|
||||
private final Map<UUID, Integer> sunExposureSeconds = new HashMap<>();
|
||||
private ConfigurableGui gui;
|
||||
private AdminGui adminGui;
|
||||
private Politics politics;
|
||||
private SharedDatabase sharedDatabase;
|
||||
public SharedDatabase sharedDatabase(){return sharedDatabase;}
|
||||
|
|
@ -105,6 +106,7 @@ public final class DuneCore extends JavaPlugin implements Listener, CommandExecu
|
|||
duneCommand.setExecutor(this);
|
||||
duneCommand.setTabCompleter(this);
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
adminGui = new AdminGui(this);
|
||||
announcements = new ArrakisAnnouncements(this);
|
||||
sandwormMobs = new SandwormMobs(this, wormKey);
|
||||
World loadedArrakis = Bukkit.getWorld("arrakis");
|
||||
|
|
@ -445,6 +447,15 @@ public final class DuneCore extends JavaPlugin implements Listener, CommandExecu
|
|||
try{ess.getClass().getMethod("factionArrival",Player.class,String.class).invoke(ess,p,planet);}catch(ReflectiveOperationException ex){getLogger().warning("Faction arrival failed: "+ex.getMessage());}
|
||||
}
|
||||
@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (args.length > 0 && (args[0].equalsIgnoreCase("admin") || args[0].equalsIgnoreCase("adminitem"))) {
|
||||
if (sender instanceof Player player) {
|
||||
if (args[0].equalsIgnoreCase("adminitem")) {
|
||||
if (!player.isOp()) player.sendMessage(ChatColor.RED + "Operators only.");
|
||||
else { adminGui.giveRod(player); player.sendMessage("The admin rod is supplied when an inventory slot is free."); }
|
||||
} else adminGui.open(player);
|
||||
} else sender.sendMessage("Run this command in-game.");
|
||||
return true;
|
||||
}
|
||||
if (args.length > 0 && args[0].equalsIgnoreCase("summon")) {
|
||||
summonSandworm(sender, args);
|
||||
return true;
|
||||
|
|
@ -453,7 +464,7 @@ public final class DuneCore extends JavaPlugin implements Listener, CommandExecu
|
|||
if (sender instanceof Player player) Bukkit.dispatchCommand(player, "duneess help"); else sendHelp(sender);
|
||||
return true;
|
||||
}
|
||||
if (args.length > 0 && List.of("admin","balance","sell","travel").contains(args[0].toLowerCase(Locale.ROOT))) {
|
||||
if (args.length > 0 && List.of("balance","sell","travel").contains(args[0].toLowerCase(Locale.ROOT))) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Solaris, Guild travel, and admin teleports are now in DuneEss. Use /duneess help."); return true;
|
||||
}
|
||||
if (!(sender instanceof Player p)) { sender.sendMessage("Run this command in-game."); return true; }
|
||||
|
|
@ -538,6 +549,7 @@ public final class DuneCore extends JavaPlugin implements Listener, CommandExecu
|
|||
helpLine(sender, "/dune guireload", "Reload the configurable Navigator menu.");
|
||||
helpLine(sender, "/dune guildnpc", "Spawn a Spacing Guild Navigator at your location.");
|
||||
helpLine(sender, "/dune givespice", "Give yourself one spice item.");
|
||||
helpLine(sender, "/dune admin | /dune adminitem", "Operators: open admin controls or recover the custom blaze rod.");
|
||||
helpLine(sender, "/dune summon sandworm [x y z]", "Summon Shai-Hulud on Arrakis at your position or explicit coordinates.");
|
||||
helpLine(sender, "/duneess admin teleport arrakis [player]", "Teleport a player to the loaded Arrakis spawn.");
|
||||
helpLine(sender, "/duneess admin teleport sietch [player]", "Teleport a player to a generated Arrakis sietch.");
|
||||
|
|
@ -562,7 +574,7 @@ public final class DuneCore extends JavaPlugin implements Listener, CommandExecu
|
|||
if (args.length == 1) {
|
||||
List<String> commands = new ArrayList<>(List.of("help", "choose", "elytra", "kit", "politics", "trust", "water",
|
||||
"menu", "gui", "menuitem", "exchange", "serverjobs", "job"));
|
||||
if (sender.hasPermission("dune.admin")) commands.addAll(List.of("guireload", "guildnpc", "givespice", "summon"));
|
||||
if (sender.hasPermission("dune.admin")) commands.addAll(List.of("guireload", "guildnpc", "givespice", "summon", "admin", "adminitem"));
|
||||
return matching(commands, args[0]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
name: DuneCore
|
||||
version: 1.0.5
|
||||
version: 1.0.6
|
||||
main: com.example.dunerealms.DuneCore
|
||||
api-version: '1.21'
|
||||
depend: [Vault, DuneEss]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
package com.example.dunerealms;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
|
||||
class AdminGuiTest {
|
||||
@Test void nonOperatorsCannotOpenMenuEvenWithAdminPermission() {
|
||||
AdminGui gui = mock(AdminGui.class);
|
||||
Player player = mock(Player.class);
|
||||
when(player.hasPermission("dune.admin")).thenReturn(true);
|
||||
doCallRealMethod().when(gui).open(player);
|
||||
gui.open(player);
|
||||
verify(player).sendMessage(contains("Operators only"));
|
||||
verify(player, never()).openInventory(any(org.bukkit.inventory.Inventory.class));
|
||||
}
|
||||
|
||||
@Test void nonOperatorsNeverReceiveAutomaticRod() {
|
||||
AdminGui gui = mock(AdminGui.class);
|
||||
Player player = mock(Player.class);
|
||||
doCallRealMethod().when(gui).giveRod(player);
|
||||
gui.giveRod(player);
|
||||
verify(player, never()).getInventory();
|
||||
}
|
||||
}
|
||||
12
README.md
12
README.md
|
|
@ -90,3 +90,15 @@ The existing workflow builds all three modules and produces the downloadable ser
|
|||
- [Manual artwork and icon prompt notes](docs/artwork/README.md)
|
||||
|
||||
The manual's cover, sietch art, and item icons are thematic illustrations, not screenshots or new game models. Actual faction armor uses vanilla leather armor with custom attributes and tags, and the winged suits use Elytra geometry. Shai-Hulud uses the vanilla Sniffer model with the updated desert skin.
|
||||
|
||||
### Operator admin controls (DuneCore 1.0.6)
|
||||
Operators automatically receive a glowing **Imperial Admin Scepter**, a tagged blaze rod.
|
||||
Right-click it in your main hand to open the admin menu, or use `/dune admin`.
|
||||
`/dune adminitem` recovers the rod; delivery retries every five seconds if your inventory is full.
|
||||
The same check supplies newly opped online players and replacements after respawning. Existing rods are not duplicated.
|
||||
|
||||
The menu can summon a sandworm at your current Arrakis location, place a Guild Navigator NPC,
|
||||
give one test spice item, reload `gui.yml`, issue your selected faction kit, and show politics status.
|
||||
Actions use the existing command checks. Both opening the menu and clicking a control require operator status;
|
||||
granting only `dune.admin` does not enable this menu. A deopped player cannot use a retained rod.
|
||||
The blaze rod has custom model data 1006, a gold name and enchantment glint; its current appearance uses the vanilla blaze rod texture.
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff