diff --git a/src/main/java/com/cjburkey/claimchunk/ClaimChunkConfig.java b/src/main/java/com/cjburkey/claimchunk/ClaimChunkConfig.java index e3e33e8..dd583b4 100644 --- a/src/main/java/com/cjburkey/claimchunk/ClaimChunkConfig.java +++ b/src/main/java/com/cjburkey/claimchunk/ClaimChunkConfig.java @@ -76,10 +76,17 @@ public class ClaimChunkConfig { @Getter private boolean debugSpam; /* GUI */ + @Getter private String guiMenuBackButtonItem; @Getter private String guiMainMenuCurrentChunkItem; @Getter private String guiMainMenuChunkMapItem; @Getter private String guiMainMenuPermFlagsItem; @Getter private boolean guiMapMenuAllowClaimOtherChunks; + @Getter private String guiMapMenuUnclaimedItem; + @Getter private String guiMapMenuSelfClaimedItem; + @Getter private String guiMapMenuOtherClaimedItem; + @Getter private String guiMapMenuCenterUnclaimedItem; + @Getter private String guiMapMenuCenterSelfClaimedItem; + @Getter private String guiMapMenuCenterOtherClaimedItem; /* Titles */ @@ -168,10 +175,17 @@ public void reload() { anonymousMetrics = getBool("log", "anonymousMetrics"); debugSpam = getBool("log", "debugSpam"); - guiMainMenuCurrentChunkItem = getString("gui", "mainMenuCurrentChunk"); + guiMenuBackButtonItem = getString("gui", "menuBackButtonItem"); + guiMainMenuCurrentChunkItem = getString("gui", "mainMenuCurrentChunkItem"); guiMainMenuChunkMapItem = getString("gui", "mainMenuChunkMapItem"); guiMainMenuPermFlagsItem = getString("gui", "mainMenuPermFlagsItem"); guiMapMenuAllowClaimOtherChunks = getBool("gui", "mapMenuAllowClaimOtherChunks"); + guiMapMenuUnclaimedItem = getString("gui", "mapMenuUnclaimedItem"); + guiMapMenuSelfClaimedItem = getString("gui", "mapMenuSelfClaimedItem"); + guiMapMenuOtherClaimedItem = getString("gui", "mapMenuOtherClaimedItem"); + guiMapMenuCenterUnclaimedItem = getString("gui", "mapMenuCenterUnclaimedItem"); + guiMapMenuCenterSelfClaimedItem = getString("gui", "mapMenuCenterSelfClaimedItem"); + guiMapMenuCenterOtherClaimedItem = getString("gui", "mapMenuCenterOtherClaimedItem"); useTitlesInsteadOfChat = getBool("titles", "useTitlesInsteadOfChat"); useActionBar = getBool("titles", "useActionBar"); diff --git a/src/main/java/com/cjburkey/claimchunk/gui/GuiMenuScreen.java b/src/main/java/com/cjburkey/claimchunk/gui/GuiMenuScreen.java index eafbaf7..a5d5dc5 100644 --- a/src/main/java/com/cjburkey/claimchunk/gui/GuiMenuScreen.java +++ b/src/main/java/com/cjburkey/claimchunk/gui/GuiMenuScreen.java @@ -2,6 +2,7 @@ import com.cjburkey.claimchunk.ClaimChunk; import com.cjburkey.claimchunk.Utils; +import com.cjburkey.claimchunk.chunk.ChunkPos; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -13,6 +14,8 @@ import org.jetbrains.annotations.Nullable; import java.util.List; +import java.util.UUID; +import java.util.regex.Pattern; /** * An abstract wrapper for {@link ICCGui} to make creating inventory menus easier. @@ -147,4 +150,31 @@ public int getRows() { } return item; } + + /** + * Generate chunk position text based on the message handler. + * + * @param chunkPos The position of the chunk + * @return A localized string representing a position in the given world. + */ + protected @NotNull String guiChunkPosText(@NotNull ChunkPos chunkPos) { + return claimChunk + .getMessages() + .guiChunkPos + .replaceAll(Pattern.quote("%%WORLD%%"), chunkPos.world()) + .replaceAll(Pattern.quote("%%X%%"), chunkPos.x() + "") + .replaceAll(Pattern.quote("%%Z%%"), chunkPos.z() + ""); + } + + protected @NotNull String guiChunkOwnerNameText(@NotNull String chunkName) { + return claimChunk + .getMessages() + .guiChunkOwner + .replaceAll(Pattern.quote("%%NAME%%"), chunkName); + } + + protected @NotNull String chunkNameOrUnknown(@NotNull UUID chunkOwner) { + String chunkName = claimChunk.getPlayerHandler().getChunkName(chunkOwner); + return chunkName != null ? chunkName : claimChunk.getMessages().unknownChunkOwner; + } } diff --git a/src/main/java/com/cjburkey/claimchunk/gui/screens/MainMenu.java b/src/main/java/com/cjburkey/claimchunk/gui/screens/MainMenu.java index 9306602..58a9e6f 100644 --- a/src/main/java/com/cjburkey/claimchunk/gui/screens/MainMenu.java +++ b/src/main/java/com/cjburkey/claimchunk/gui/screens/MainMenu.java @@ -1,10 +1,8 @@ package com.cjburkey.claimchunk.gui.screens; import com.cjburkey.claimchunk.ClaimChunk; -import com.cjburkey.claimchunk.chunk.ChunkHandler; import com.cjburkey.claimchunk.chunk.ChunkPos; import com.cjburkey.claimchunk.gui.GuiMenuScreen; -import com.cjburkey.claimchunk.player.PlayerHandler; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -13,7 +11,6 @@ import java.util.Collections; import java.util.Objects; import java.util.UUID; -import java.util.regex.Pattern; public class MainMenu extends GuiMenuScreen { @@ -38,38 +35,22 @@ protected void onBuildGui() { } private void addCurrentChunkItem(@NotNull Player player) { - ChunkHandler chunkHandler = claimChunk.getChunkHandler(); - PlayerHandler playerHandler = claimChunk.getPlayerHandler(); - ChunkPos chunkPos = new ChunkPos(player.getLocation().getChunk()); - UUID chunkOwner = chunkHandler.getOwner(chunkPos); - String chunkName = chunkOwner == null ? null : playerHandler.getChunkName(chunkOwner); - if (chunkName == null && chunkOwner != null) - chunkName = playerHandler.getUsername(chunkOwner); + UUID chunkOwner = claimChunk.getChunkHandler().getOwner(chunkPos); ArrayList lore = new ArrayList<>(); - lore.add( - claimChunk - .getMessages() - .guiChunkPos - .replaceAll(Pattern.quote("%%WORLD%%"), chunkPos.world()) - .replaceAll(Pattern.quote("%%X%%"), chunkPos.x() + "") - .replaceAll(Pattern.quote("%%Z%%"), chunkPos.z() + "")); + lore.add(guiChunkPosText(chunkPos)); if (chunkOwner != null) { - lore.add( - claimChunk - .getMessages() - .guiChunkOwner - .replaceAll(Pattern.quote("%%NAME%%"), chunkName)); + lore.add(guiChunkOwnerNameText(chunkNameOrUnknown(chunkOwner))); if (chunkOwner.equals(player.getUniqueId())) { lore.add(""); - lore.add(claimChunk.getMessages().guiMainMenuUnclaim); + lore.add(claimChunk.getMessages().guiClickToUnclaim); } } else { lore.add(claimChunk.getMessages().guiNotClaimed); lore.add(""); - lore.add(claimChunk.getMessages().guiMainMenuClaim); + lore.add(claimChunk.getMessages().guiClickToClaim); } addInteractiveButton( diff --git a/src/main/java/com/cjburkey/claimchunk/gui/screens/MapMenu.java b/src/main/java/com/cjburkey/claimchunk/gui/screens/MapMenu.java index d554fbb..7ab7d71 100644 --- a/src/main/java/com/cjburkey/claimchunk/gui/screens/MapMenu.java +++ b/src/main/java/com/cjburkey/claimchunk/gui/screens/MapMenu.java @@ -1,48 +1,119 @@ package com.cjburkey.claimchunk.gui.screens; import com.cjburkey.claimchunk.ClaimChunk; +import com.cjburkey.claimchunk.ClaimChunkConfig; +import com.cjburkey.claimchunk.chunk.ChunkHandler; import com.cjburkey.claimchunk.chunk.ChunkPos; import com.cjburkey.claimchunk.gui.GuiMenuScreen; - -import org.bukkit.Material; +import com.cjburkey.claimchunk.i18n.V2JsonMessages; import java.util.ArrayList; +import java.util.Collections; +import java.util.UUID; public class MapMenu extends GuiMenuScreen { private static final int MAP_HEIGHT = 5; public MapMenu(ClaimChunk claimChunk) { - super(claimChunk, MAP_HEIGHT, claimChunk.getMessages().guiMapMenuTitle); + // Offset to make it 6 tall so that we can have the top row be a menu bar. + super(claimChunk, MAP_HEIGHT + 1, claimChunk.getMessages().guiMapMenuTitle); } @Override protected void onBuildGui() { if (player == null) return; + int halfHeight = Math.floorDiv(MAP_HEIGHT, 2); + + ChunkHandler chunkHandler = claimChunk.getChunkHandler(); + V2JsonMessages messages = claimChunk.getMessages(); + ClaimChunkConfig config = claimChunk.getConfigHandler(); ChunkPos centerChunk = new ChunkPos(player.getLocation().getChunk()); + boolean enableClaimingFromMap = config.getGuiMapMenuAllowClaimOtherChunks(); - int halfHeight = Math.floorDiv(MAP_HEIGHT, 2); + // Add the back button + addInteractiveButton( + 0, + materialFromStr(config.getGuiMenuBackButtonItem()), + messages.guiMenuBackButtonName, + Collections.singletonList(messages.guiMenuBackButtonDesc), + (clickType, stack) -> + claimChunk.getGuiHandler().openGui(player, new MainMenu(claimChunk))); + // Add the map items // Inventory width is 9, so go 4 eastward and westward for (int offsetX = -4; offsetX <= 4; offsetX++) { // Inventory height is `MAP_HEIGHT`, so go `halfHeight` northward and southward for (int offsetZ = -halfHeight; offsetZ <= halfHeight; offsetZ++) { - int slot = (offsetX + 4) + 9 * (offsetZ + halfHeight); + // The `+1` pushes down by one row, for the top row menu bar idea I have. + int slot = (offsetX + 4) + 9 * (offsetZ + halfHeight + 1); ChunkPos offsetChunk = new ChunkPos( centerChunk.world(), centerChunk.x() + offsetX, centerChunk.z() + offsetZ); + boolean isCenter = offsetChunk.equals(centerChunk); + + ArrayList lore = new ArrayList<>(); + UUID chunkOwner = chunkHandler.getOwner(offsetChunk); + boolean isOwner = player.getUniqueId().equals(chunkOwner); + + if (isCenter) lore.add(messages.guiMapMenuInsideThisChunk); + + if (chunkOwner != null) { + lore.add(guiChunkOwnerNameText(chunkNameOrUnknown(chunkOwner))); + if (enableClaimingFromMap && isOwner) { + lore.add(""); + lore.add(messages.guiClickToUnclaim); + } + } else { + lore.add(messages.guiNotClaimed); + if (enableClaimingFromMap) { + lore.add(""); + lore.add(messages.guiClickToClaim); + } + } - // TODO: CHANGE MATERIAL + String mapItemMaterialStr; + if (isCenter) { + mapItemMaterialStr = + isOwner + ? config.getGuiMapMenuCenterSelfClaimedItem() + : chunkOwner == null + ? config.getGuiMapMenuCenterUnclaimedItem() + : config.getGuiMapMenuCenterOtherClaimedItem(); + } else { + mapItemMaterialStr = + isOwner + ? config.getGuiMapMenuSelfClaimedItem() + : chunkOwner == null + ? config.getGuiMapMenuUnclaimedItem() + : config.getGuiMapMenuOtherClaimedItem(); + } addInteractiveButton( slot, - Material.DIRT, - "&r&fChunk at " + offsetChunk, - new ArrayList<>(), - (clickType, stack) -> {}); + materialFromStr(mapItemMaterialStr), + guiChunkPosText(offsetChunk), + lore, + (clickType, stack) -> { + if (clickType.isLeftClick()) { + claimChunk.getMainHandler().claimChunk(player, offsetChunk); + refresh(); + } else if (clickType.isRightClick()) { + claimChunk + .getMainHandler() + .unclaimChunk( + false, + false, + player, + offsetChunk.world(), + offsetChunk.x(), + offsetChunk.z()); + refresh(); + } + }); } } } diff --git a/src/main/java/com/cjburkey/claimchunk/i18n/V2JsonMessages.java b/src/main/java/com/cjburkey/claimchunk/i18n/V2JsonMessages.java index 860b9fa..cecafe5 100644 --- a/src/main/java/com/cjburkey/claimchunk/i18n/V2JsonMessages.java +++ b/src/main/java/com/cjburkey/claimchunk/i18n/V2JsonMessages.java @@ -183,17 +183,20 @@ public final class V2JsonMessages { // GUI localization public String guiMainMenuTitle = "ClaimChunk Main GUI"; public String guiMainMenuCurrentChunkItemName = "&r&3&lCurrent Chunk"; + public String guiMenuBackButtonName = "&r&3&lBack"; + public String guiMenuBackButtonDesc = "&fReturn to the main menu"; public String guiChunkPos = "&fIn &e%%WORLD%%&f at (&e%%X%%&f, &e%%Z%%&f)"; public String guiChunkOwner = "&fOwner: %%NAME%%"; public String guiNotClaimed = "&fNot claimed"; - public String guiMainMenuClaim = "&2Click to claim!"; - public String guiMainMenuUnclaim = "&4Right click to unclaim"; + public String guiClickToClaim = "&2Left click to claim!"; + public String guiClickToUnclaim = "&4Right click to unclaim"; public String guiMainMenuMapItemName = "&r&3&lChunk Map"; public String guiMapDescription = "&fClick to view the in-game map"; public String guiMainMenuPermFlagsItemName = "&r&3&lPermission Flags"; public String guiMainMenuPermFlagsDescription = "&fClick to manage other players' permissions in your chunk(s)"; public String guiMapMenuTitle = "ClaimChunk Map"; + public String guiMapMenuInsideThisChunk = "&fYou are standing inside this chunk"; // AdminOverride localization public String adminOverrideEnable = "&eYou now have protection bypass"; diff --git a/src/main/java/com/cjburkey/claimchunk/player/PlayerHandler.java b/src/main/java/com/cjburkey/claimchunk/player/PlayerHandler.java index 5bd77b2..9c49704 100644 --- a/src/main/java/com/cjburkey/claimchunk/player/PlayerHandler.java +++ b/src/main/java/com/cjburkey/claimchunk/player/PlayerHandler.java @@ -6,6 +6,7 @@ import com.cjburkey.claimchunk.data.newdata.IClaimChunkDataHandler; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.stream.Collectors; @@ -91,6 +92,7 @@ public void clearChunkName(UUID owner) { setChunkName(owner, null); } + @Nullable public String getChunkName(UUID owner) { String chunkName = dataHandler.getPlayerChunkName(owner); if (chunkName != null) return chunkName; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f76136f..421c98d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -11,9 +11,16 @@ log: anonymousMetrics: true gui: - mainMenuCurrentChunk: 'minecraft:grass_block' + menuBackButtonItem: 'minecraft:barrier' + mainMenuCurrentChunkItem: 'minecraft:grass_block' mainMenuChunkMapItem: 'minecraft:map' mainMenuPermFlagsItem: 'minecraft:writable_book' + mapMenuUnclaimedItem: 'minecraft:white_wool' + mapMenuSelfClaimedItem: 'minecraft:green_wool' + mapMenuOtherClaimedItem: 'minecraft:blue_wool' + mapMenuCenterUnclaimedItem: 'minecraft:white_glazed_terracotta' + mapMenuCenterSelfClaimedItem: 'minecraft:green_glazed_terracotta' + mapMenuCenterOtherClaimedItem: 'minecraft:blue_glazed_terracotta' mapMenuAllowClaimOtherChunks: true titles: