From c8aedf375cf2a28cdf2a317b77f413defa24bc9a Mon Sep 17 00:00:00 2001 From: SamB440 Date: Sun, 23 Apr 2023 21:07:42 +0100 Subject: [PATCH] Make several fields GUI editable, deprecate old annotations for removal --- .../editor/annotate/EditableField.java | 2 +- .../rpgregions/editor/annotate/NeedsGUI.java | 1 + .../data/region/ConfiguredRegion.java | 33 ++++--- .../rpgregions/gui/DiscoveryGUI.java | 4 +- .../rpgregions/gui/RegionCreateGUI.java | 89 +++++++++++++++++++ .../rpgregions/tasks/DynmapTask.java | 2 +- 6 files changed, 115 insertions(+), 16 deletions(-) diff --git a/api/src/main/java/net/islandearth/rpgregions/editor/annotate/EditableField.java b/api/src/main/java/net/islandearth/rpgregions/editor/annotate/EditableField.java index d2a54ef..5a4140a 100644 --- a/api/src/main/java/net/islandearth/rpgregions/editor/annotate/EditableField.java +++ b/api/src/main/java/net/islandearth/rpgregions/editor/annotate/EditableField.java @@ -12,7 +12,7 @@ import java.lang.annotation.Target; */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) -@Deprecated +@Deprecated(forRemoval = true) public @interface EditableField { Material material() default Material.OAK_SIGN; diff --git a/api/src/main/java/net/islandearth/rpgregions/editor/annotate/NeedsGUI.java b/api/src/main/java/net/islandearth/rpgregions/editor/annotate/NeedsGUI.java index a75e472..b7c80c9 100644 --- a/api/src/main/java/net/islandearth/rpgregions/editor/annotate/NeedsGUI.java +++ b/api/src/main/java/net/islandearth/rpgregions/editor/annotate/NeedsGUI.java @@ -10,4 +10,5 @@ import java.lang.annotation.Target; */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) +@Deprecated(forRemoval = true) public @interface NeedsGUI { } diff --git a/api/src/main/java/net/islandearth/rpgregions/managers/data/region/ConfiguredRegion.java b/api/src/main/java/net/islandearth/rpgregions/managers/data/region/ConfiguredRegion.java index f4e2312..002e7d5 100644 --- a/api/src/main/java/net/islandearth/rpgregions/managers/data/region/ConfiguredRegion.java +++ b/api/src/main/java/net/islandearth/rpgregions/managers/data/region/ConfiguredRegion.java @@ -48,18 +48,16 @@ public class ConfiguredRegion { private String customName; private final List rewards; @NeedsGUI private Sound sound; - @NeedsGUI private String icon; + private String icon; private int iconModel; private int undiscoveredIconModel; - @NeedsGUI private String undiscoveredIcon; + private String undiscoveredIcon; private final List iconCommand; - @EditableField(description = "Toggle whether the coordinates of the region are shown", name = "Toggle coordinates") - @NeedsGUI private final boolean showCoords; + private boolean showCoords; @EditableField(material = Material.ENDER_PEARL, name = "Set teleport location", description = "Set the teleport location to your current location") @NeedsGUI private Location location; @NeedsGUI private final List hints; - @EditableField(description = "Toggle whether the hint is shown", name = "Toggle hint") - @NeedsGUI private final boolean showHint; + private boolean showHint; private boolean teleportable; private boolean hidden; private boolean discoverable; @@ -73,15 +71,14 @@ public class ConfiguredRegion { private List discoveredTitle; private List discoveredSubtitle; private Regenerate regenerate; - @EditableField(material = Material.NETHER_STAR, name = "Set teleport cooldown", description = "Set the cooldown for teleportation") private int teleportCooldown; @EditableField(material = Material.NETHER_STAR, name = "Set teleport cost", description = "Set the cost for teleportation") private double teleportCost; - @NeedsGUI private boolean showActionbar; + private boolean showActionbar; @EditableField(material = Material.RED_DYE, name = "Hex display colour", description = "Set the colour of the region. It is a hex colour (e.g 0x42f4f1 for red) and is used in dynmap.") private final String colour; private final String lineColour; - @NeedsGUI private final boolean dynmap; + private boolean dynmap; private int secondsInsideToDiscover; // If this is the prioritised region and disablePassthrough is set to true, only the prioritised region shall run private boolean disablePassthrough; @@ -200,19 +197,27 @@ public class ConfiguredRegion { this.location = location; } - public boolean isShowCoords() { + public boolean showCoords() { return showCoords; } + public void setShowCoords(boolean showCoords) { + this.showCoords = showCoords; + } + @Nullable public List getHints() { return hints; } - public boolean isShowHint() { + public boolean showHint() { return showHint; } + public void setShowHint(boolean showHint) { + this.showHint = showHint; + } + public boolean isTeleportable() { return teleportable; } @@ -389,10 +394,14 @@ public class ConfiguredRegion { return lineColour; } - public boolean isDynmap() { + public boolean dynmap() { return dynmap; } + public void setDynmap(boolean dynmap) { + this.dynmap = dynmap; + } + public int getSecondsInsideToDiscover() { return secondsInsideToDiscover; } diff --git a/rpgregions/src/main/java/net/islandearth/rpgregions/gui/DiscoveryGUI.java b/rpgregions/src/main/java/net/islandearth/rpgregions/gui/DiscoveryGUI.java index 6da0f73..f47c922 100644 --- a/rpgregions/src/main/java/net/islandearth/rpgregions/gui/DiscoveryGUI.java +++ b/rpgregions/src/main/java/net/islandearth/rpgregions/gui/DiscoveryGUI.java @@ -196,7 +196,7 @@ public class DiscoveryGUI extends RPGRegionsGUI { ? Translations.DISCOVERED_ON.get(player, account.getDiscoveredRegions().get(configuredRegion.getId()).getDate()) : null; - String lore2 = configuredRegion.isShowCoords() + String lore2 = configuredRegion.showCoords() && player.hasPermission("rpgregions.showloc") ? ChatColor.GRAY + "" + configuredRegion.getLocation().getBlockX() + ", " + configuredRegion.getLocation().getBlockZ() : null; @@ -205,7 +205,7 @@ public class DiscoveryGUI extends RPGRegionsGUI { configuredRegion.getHints().forEach(hint -> translatedHint.add(plugin.miniMessage().deserialize(hint))); } - List hint = configuredRegion.isShowHint() + List hint = configuredRegion.showHint() && player.hasPermission("rpgregions.showhint." + configuredRegion.getId()) || player.hasPermission("rpgregions.showhint.*") && !hasDiscovered ? translatedHint diff --git a/rpgregions/src/main/java/net/islandearth/rpgregions/gui/RegionCreateGUI.java b/rpgregions/src/main/java/net/islandearth/rpgregions/gui/RegionCreateGUI.java index caf8cd6..5850479 100644 --- a/rpgregions/src/main/java/net/islandearth/rpgregions/gui/RegionCreateGUI.java +++ b/rpgregions/src/main/java/net/islandearth/rpgregions/gui/RegionCreateGUI.java @@ -198,6 +198,25 @@ public class RegionCreateGUI extends RPGRegionsGUI { }),0, 0); gui.addPane(time); + StaticPane teleport = new StaticPane(0, 5, 1, 1, Pane.Priority.HIGH); + ItemStack teleportItem = new ItemStackBuilder(Material.ENDER_PEARL) + .withName("&6Set teleport cooldown &7- &6" + region.getTeleportCooldown()) + .withLore("&7How long should the player have to", "&7wait until teleporting to the region again?", "", "&e&lClick &7to set teleport cooldown.") + .build(); + teleport.addItem(new GuiItem(teleportItem, event -> { + new ReturnValueConversationPreset(player, "How long should the player have to wait to teleport to the region again? (in ticks)", input -> { + try { + final int potentialTime = Integer.parseInt(input); + region.setTeleportCooldown(potentialTime); + } catch (NumberFormatException e) { + player.sendMessage(ChatColor.RED + "'" + input + "' is not a valid number."); + } + open(); + }); + player.closeInventory(); + }),0, 0); + gui.addPane(teleport); + int x = 4; for (RPGRegionsRegistry registry : plugin.getManagers().getRegistries()) { StaticPane registryPane = new StaticPane(x, 2, 1, 1, Pane.Priority.HIGH); @@ -256,6 +275,76 @@ public class RegionCreateGUI extends RPGRegionsGUI { } }),0, 0); gui.addPane(teleportable); + + StaticPane showHint = new StaticPane(7, 3, 1, 1, Pane.Priority.HIGH); + ItemStack showHintItem = new ItemStackBuilder(Material.BLUE_BANNER) + .withName("&6Toggle show hint &7- &6" + region.isTeleportable()) + .withLore("&7Whether the hint for this region is shown.", "&c&lShift-Click &7to toggle show hint.") + .build(); + showHint.addItem(new GuiItem(showHintItem, event -> { + if (event.getClick() == ClickType.SHIFT_LEFT) { + region.setShowHint(!region.showHint()); + player.playSound(player.getLocation(), Sound.BLOCK_TRIPWIRE_CLICK_ON, 1f, 1f); + open(); + } + }),0, 0); + gui.addPane(showHint); + + StaticPane dynmap = new StaticPane(7, 4, 1, 1, Pane.Priority.HIGH); + ItemStack dynmapItem = new ItemStackBuilder(Material.FILLED_MAP) + .withName("&6Toggle dynmap &7- &6" + region.dynmap()) + .withLore("&7Whether this region is shown on dynmap.", "&c&lShift-Click &7to toggle dynmap.") + .build(); + dynmap.addItem(new GuiItem(dynmapItem, event -> { + if (event.getClick() == ClickType.SHIFT_LEFT) { + region.setDynmap(!region.dynmap()); + player.playSound(player.getLocation(), Sound.BLOCK_TRIPWIRE_CLICK_ON, 1f, 1f); + open(); + } + }),0, 0); + gui.addPane(dynmap); + + StaticPane actionbar = new StaticPane(7, 5, 1, 1, Pane.Priority.HIGH); + ItemStack actionbarItem = new ItemStackBuilder(Material.BOOK) + .withName("&6Toggle actionbar &7- &6" + region.showActionbar()) + .withLore("&7Whether this region is shown in the actionbar on entry.", "&c&lShift-Click &7to toggle actionbar.") + .build(); + actionbar.addItem(new GuiItem(actionbarItem, event -> { + if (event.getClick() == ClickType.SHIFT_LEFT) { + region.setShowActionbar(!region.showActionbar()); + player.playSound(player.getLocation(), Sound.BLOCK_TRIPWIRE_CLICK_ON, 1f, 1f); + open(); + } + }),0, 0); + gui.addPane(actionbar); + + StaticPane coords = new StaticPane(8, 3, 1, 1, Pane.Priority.HIGH); + ItemStack coordsItem = new ItemStackBuilder(Material.MAP) + .withName("&6Toggle coords &7- &6" + region.showActionbar()) + .withLore("&7Whether the coordinates of this region are shown.", "&c&lShift-Click &7to toggle coords.") + .build(); + coords.addItem(new GuiItem(coordsItem, event -> { + if (event.getClick() == ClickType.SHIFT_LEFT) { + region.setShowCoords(!region.showCoords()); + player.playSound(player.getLocation(), Sound.BLOCK_TRIPWIRE_CLICK_ON, 1f, 1f); + open(); + } + }),0, 0); + gui.addPane(coords); + + StaticPane passthrough = new StaticPane(8, 4, 1, 1, Pane.Priority.HIGH); + ItemStack passthroughItem = new ItemStackBuilder(Material.BARRIER) + .withName("&6Toggle disable passthrough &7- &6" + region.disablesPassthrough()) + .withLore("&7If this is the prioritised region and disable passthrough is set to true,", "&7 only the prioritised region shall run.", "&c&lShift-Click &7to toggle passthrough.") + .build(); + passthrough.addItem(new GuiItem(passthroughItem, event -> { + if (event.getClick() == ClickType.SHIFT_LEFT) { + region.setDisablePassthrough(!region.disablesPassthrough()); + player.playSound(player.getLocation(), Sound.BLOCK_TRIPWIRE_CLICK_ON, 1f, 1f); + open(); + } + }),0, 0); + gui.addPane(passthrough); gui.update(); } diff --git a/rpgregions/src/main/java/net/islandearth/rpgregions/tasks/DynmapTask.java b/rpgregions/src/main/java/net/islandearth/rpgregions/tasks/DynmapTask.java index 12db5fa..6414f65 100644 --- a/rpgregions/src/main/java/net/islandearth/rpgregions/tasks/DynmapTask.java +++ b/rpgregions/src/main/java/net/islandearth/rpgregions/tasks/DynmapTask.java @@ -28,7 +28,7 @@ public class DynmapTask implements Runnable { @Override public void run() { plugin.getManagers().getRegionsCache().getConfiguredRegions().forEach((name, region) -> { - if (!region.isDynmap()) return; + if (!region.dynmap()) return; List boundingBox = region.getBoundingBox(); if (boundingBox == null) return; if (!markers.containsKey(name)) {