From 65b406f8d5df426effb1a72cb75d6fd6f82a2e00 Mon Sep 17 00:00:00 2001 From: CJ Burkey Date: Thu, 30 May 2024 13:21:37 -0400 Subject: [PATCH] Add permission type selection and permission modification screens --- .../com/cjburkey/claimchunk/ClaimChunk.java | 2 +- .../cjburkey/claimchunk/ClaimChunkConfig.java | 6 ++ .../data/newdata/BackupCleaner.java | 2 + .../data/newdata/BulkMySQLDataHandler.java | 3 + .../data/newdata/IClaimChunkDataHandler.java | 10 +++ .../data/newdata/JsonDataHandler.java | 10 +++ .../data/newdata/MySQLDataHandler.java | 8 ++ .../data/sqlite/SqLiteDataHandler.java | 16 ++-- .../claimchunk/data/sqlite/SqLiteWrapper.java | 4 +- .../cjburkey/claimchunk/gui/CCGuiHandler.java | 4 +- .../claimchunk/gui/GuiMenuScreen.java | 21 +++++- .../claimchunk/gui/screens/MainMenu.java | 12 +-- .../claimchunk/gui/screens/MapMenu.java | 7 +- .../gui/screens/PermModifyMenu.java | 74 +++++++++++++++++++ .../gui/screens/PermSelectMenu.java | 52 +++++++++++++ .../claimchunk/i18n/V2JsonMessages.java | 49 ++++++++++-- .../claimchunk/player/PlayerHandler.java | 7 +- src/main/resources/config.yml | 5 +- 18 files changed, 252 insertions(+), 40 deletions(-) create mode 100644 src/main/java/com/cjburkey/claimchunk/gui/screens/PermModifyMenu.java create mode 100644 src/main/java/com/cjburkey/claimchunk/gui/screens/PermSelectMenu.java diff --git a/src/main/java/com/cjburkey/claimchunk/ClaimChunk.java b/src/main/java/com/cjburkey/claimchunk/ClaimChunk.java index b981db98..ff585212 100644 --- a/src/main/java/com/cjburkey/claimchunk/ClaimChunk.java +++ b/src/main/java/com/cjburkey/claimchunk/ClaimChunk.java @@ -340,7 +340,7 @@ private void initAnonymousData() { } } - @SuppressWarnings("ResultOfMethodCallIgnored") + @SuppressWarnings({"ResultOfMethodCallIgnored", "deprecation"}) private void initDataHandler() { // Initialize the data handler if another plugin hasn't substituted one already if (dataHandler == null) { diff --git a/src/main/java/com/cjburkey/claimchunk/ClaimChunkConfig.java b/src/main/java/com/cjburkey/claimchunk/ClaimChunkConfig.java index dd583b42..5cd88add 100644 --- a/src/main/java/com/cjburkey/claimchunk/ClaimChunkConfig.java +++ b/src/main/java/com/cjburkey/claimchunk/ClaimChunkConfig.java @@ -87,6 +87,9 @@ public class ClaimChunkConfig { @Getter private String guiMapMenuCenterUnclaimedItem; @Getter private String guiMapMenuCenterSelfClaimedItem; @Getter private String guiMapMenuCenterOtherClaimedItem; + @Getter private String guiPermSelectMenuItem; + @Getter private String guiPermModifyAllowItem; + @Getter private String guiPermModifyDenyItem; /* Titles */ @@ -186,6 +189,9 @@ public void reload() { guiMapMenuCenterUnclaimedItem = getString("gui", "mapMenuCenterUnclaimedItem"); guiMapMenuCenterSelfClaimedItem = getString("gui", "mapMenuCenterSelfClaimedItem"); guiMapMenuCenterOtherClaimedItem = getString("gui", "mapMenuCenterOtherClaimedItem"); + guiPermSelectMenuItem = getString("gui", "permSelectMenuItem"); + guiPermModifyAllowItem = getString("gui", "permModifyAllowItem"); + guiPermModifyDenyItem = getString("gui", "permModifyDenyItem"); useTitlesInsteadOfChat = getBool("titles", "useTitlesInsteadOfChat"); useActionBar = getBool("titles", "useActionBar"); diff --git a/src/main/java/com/cjburkey/claimchunk/data/newdata/BackupCleaner.java b/src/main/java/com/cjburkey/claimchunk/data/newdata/BackupCleaner.java index 92522358..8ba3a7a3 100644 --- a/src/main/java/com/cjburkey/claimchunk/data/newdata/BackupCleaner.java +++ b/src/main/java/com/cjburkey/claimchunk/data/newdata/BackupCleaner.java @@ -7,6 +7,7 @@ import java.io.File; import java.util.regex.Pattern; +// TODO: SWITCH THIS TO BACK UP THE .sqlite3 DATABASE FILE public final class BackupCleaner { public static boolean deleteBackups( @@ -68,6 +69,7 @@ public static boolean deleteBackups( } catch (Exception e) { // Print the error Utils.err("Failed to delete old backups in folder: %s", folder.toString()); + //noinspection CallToPrintStackTrace e.printStackTrace(); } diff --git a/src/main/java/com/cjburkey/claimchunk/data/newdata/BulkMySQLDataHandler.java b/src/main/java/com/cjburkey/claimchunk/data/newdata/BulkMySQLDataHandler.java index 40d62ce0..6f637569 100644 --- a/src/main/java/com/cjburkey/claimchunk/data/newdata/BulkMySQLDataHandler.java +++ b/src/main/java/com/cjburkey/claimchunk/data/newdata/BulkMySQLDataHandler.java @@ -29,7 +29,10 @@ * * @param The type of the backup data system. * @since 0.0.16 + * @deprecated We now use {@link com.cjburkey.claimchunk.data.sqlite.SqLiteDataHandler} */ +@SuppressWarnings("DeprecatedIsStillUsed") +@Deprecated public class BulkMySQLDataHandler extends MySQLDataHandler implements IClaimChunkDataHandler { diff --git a/src/main/java/com/cjburkey/claimchunk/data/newdata/IClaimChunkDataHandler.java b/src/main/java/com/cjburkey/claimchunk/data/newdata/IClaimChunkDataHandler.java index 015a0b0c..6400729a 100644 --- a/src/main/java/com/cjburkey/claimchunk/data/newdata/IClaimChunkDataHandler.java +++ b/src/main/java/com/cjburkey/claimchunk/data/newdata/IClaimChunkDataHandler.java @@ -204,6 +204,16 @@ default void addPlayer(UUID player, String lastIgn, boolean alerts, int defaultM */ void addPlayers(FullPlayerData[] players); + /** + * Get this player's default permission flags for non-overridden chunks. + * + * @param player The player's UUID to check. + * @return A map of this player's default permissions. + * @since 0.0.26 + */ + @Nullable + Map getDefaultPermissionsForPlayer(UUID player); + /** * Retrieves the username for the given player UUID. * diff --git a/src/main/java/com/cjburkey/claimchunk/data/newdata/JsonDataHandler.java b/src/main/java/com/cjburkey/claimchunk/data/newdata/JsonDataHandler.java index 6e8dceba..12595562 100644 --- a/src/main/java/com/cjburkey/claimchunk/data/newdata/JsonDataHandler.java +++ b/src/main/java/com/cjburkey/claimchunk/data/newdata/JsonDataHandler.java @@ -25,6 +25,11 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; +/** + * @deprecated We now use {@link com.cjburkey.claimchunk.data.sqlite.SqLiteDataHandler} + */ +@SuppressWarnings("DeprecatedIsStillUsed") +@Deprecated public class JsonDataHandler implements IClaimChunkDataHandler { // Matches: `FILENAME_yyyy-MM-dd-HH-mm-ss-SSS.json` @@ -168,6 +173,11 @@ public void addPlayers(FullPlayerData[] players) { for (FullPlayerData player : players) addPlayer(player); } + @Override + public @Nullable Map getDefaultPermissionsForPlayer(UUID player) { + return null; + } + @Override @Nullable public String getPlayerUsername(UUID player) { diff --git a/src/main/java/com/cjburkey/claimchunk/data/newdata/MySQLDataHandler.java b/src/main/java/com/cjburkey/claimchunk/data/newdata/MySQLDataHandler.java index df33d815..ae267171 100644 --- a/src/main/java/com/cjburkey/claimchunk/data/newdata/MySQLDataHandler.java +++ b/src/main/java/com/cjburkey/claimchunk/data/newdata/MySQLDataHandler.java @@ -28,7 +28,10 @@ * * @param The type of the backup data system. * @since 0.0.13 + * @deprecated We now use {@link com.cjburkey.claimchunk.data.sqlite.SqLiteDataHandler} */ +@SuppressWarnings("DeprecatedIsStillUsed") +@Deprecated public class MySQLDataHandler implements IClaimChunkDataHandler { static final String CLAIMED_CHUNKS_TABLE_NAME = "claimed_chunks"; @@ -424,6 +427,11 @@ public void addPlayers(FullPlayerData[] players) { } } + @Override + public @Nullable Map getDefaultPermissionsForPlayer(UUID player) { + return null; + } + @Override @Nullable public String getPlayerUsername(UUID player) { diff --git a/src/main/java/com/cjburkey/claimchunk/data/sqlite/SqLiteDataHandler.java b/src/main/java/com/cjburkey/claimchunk/data/sqlite/SqLiteDataHandler.java index a9a04093..c578af09 100644 --- a/src/main/java/com/cjburkey/claimchunk/data/sqlite/SqLiteDataHandler.java +++ b/src/main/java/com/cjburkey/claimchunk/data/sqlite/SqLiteDataHandler.java @@ -16,13 +16,6 @@ import java.util.*; import java.util.stream.Collectors; -/* - * I've actually just decided that we're gonna do it this way: - * - SQLite backing database *file* similar to current MySQL integration (which will - * be removed and automatically converted). - * - Have some intermediary layer that can Respond immediately and asynchronously update database. - */ - /** * The SHINY, NEW........data handler that tries to fix the data loss issues by which this project * has been plagued since its conception. @@ -144,6 +137,12 @@ public void addPlayers(FullPlayerData[] players) { Arrays.stream(players).forEach(this::addPlayer); } + @Override + public @Nullable Map getDefaultPermissionsForPlayer(UUID player) { + FullPlayerData ply = joinedPlayers.get(player); + return ply == null ? null : ply.defaultChunkPermissions.toPermissionsMap(); + } + @Override public @Nullable String getPlayerUsername(UUID player) { FullPlayerData ply = joinedPlayers.get(player); @@ -254,7 +253,6 @@ public void takePlayerAccess(ChunkPos chunk, UUID accessor) { @Override public Map getPlayersWithAccess(ChunkPos chunk) { DataChunk chunkData = claimedChunks.get(chunk); - if (chunkData != null) return chunkData.playerPermissions; - return null; + return chunkData == null ? null : chunkData.playerPermissions; } } diff --git a/src/main/java/com/cjburkey/claimchunk/data/sqlite/SqLiteWrapper.java b/src/main/java/com/cjburkey/claimchunk/data/sqlite/SqLiteWrapper.java index 40133363..96233f0a 100644 --- a/src/main/java/com/cjburkey/claimchunk/data/sqlite/SqLiteWrapper.java +++ b/src/main/java/com/cjburkey/claimchunk/data/sqlite/SqLiteWrapper.java @@ -282,15 +282,13 @@ public void setPlayerAccess(ChunkPos chunk, UUID accessor, int permissionFlags) connection.prepareStatement( chunkIdQuery( """ - INSERT INTO chunk_permissions ( + INSERT OR REPLACE INTO chunk_permissions ( chunk_id, other_player_uuid, permission_bits ) VALUES ( %%SELECT_CHUNK_ID_SQL%%, ?, ? ) - ON CONFLICT(chunk_id, other_player_uuid) DO - UPDATE SET permission_bits=excluded.permission_bits """))) { int next = setChunkPosParams(statement, 1, chunk); statement.setString(next, accessor.toString()); diff --git a/src/main/java/com/cjburkey/claimchunk/gui/CCGuiHandler.java b/src/main/java/com/cjburkey/claimchunk/gui/CCGuiHandler.java index 806f2206..2ed07db1 100644 --- a/src/main/java/com/cjburkey/claimchunk/gui/CCGuiHandler.java +++ b/src/main/java/com/cjburkey/claimchunk/gui/CCGuiHandler.java @@ -30,7 +30,9 @@ public void onGuiClick(InventoryClickEvent e) { UUID uuid = e.getWhoClicked().getUniqueId(); CCOpenGui openGui = openGuis.get(uuid); if (openGui != null) { - if (e.getInventory().equals(openGui.inventory())) { + if (e.getInventory().equals(openGui.inventory()) + && e.getSlot() >= 0 + && e.getSlot() < e.getInventory().getSize()) { openGui.gui() .onClick( openGui.inventory(), e.getSlot(), e.getClick(), e.getCurrentItem()); diff --git a/src/main/java/com/cjburkey/claimchunk/gui/GuiMenuScreen.java b/src/main/java/com/cjburkey/claimchunk/gui/GuiMenuScreen.java index 0ececbd8..0a146fc5 100644 --- a/src/main/java/com/cjburkey/claimchunk/gui/GuiMenuScreen.java +++ b/src/main/java/com/cjburkey/claimchunk/gui/GuiMenuScreen.java @@ -13,6 +13,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Arrays; import java.util.List; import java.util.UUID; import java.util.regex.Pattern; @@ -66,8 +67,6 @@ protected void addInteractiveButton( @NotNull String itemName, @NotNull List itemLore, @NotNull GuiItemAction action) { - Utils.debug("Made GUI stack in slot: " + slot); - Utils.debug("Max: " + this.actions.length); if (slot >= 0 && slot < this.actions.length && itemType != Material.AIR) { ItemStack stack = makeStack(itemType, itemName, itemLore); if (stack != null) { @@ -155,7 +154,7 @@ public Player getPlayer() { } /** - * Generate localized chunk owner name GUI text. + * Helper method to generate localized chunk owner name GUI text. * * @param chunkName The non-null name of the chunk owner. This replaces {@code %%NAME%%} * verbatim. @@ -169,7 +168,8 @@ public Player getPlayer() { } /** - * Get the name for this given chunk owner, or return the localized unknown player text. + * Helper method to get the name for this given chunk owner, or return the localized unknown + * player text. * * @param chunkOwner The non-null owner of the chunk. * @return The name for the chunk's owner that can be shown to a player in the GUI. @@ -178,4 +178,17 @@ public Player getPlayer() { String chunkName = claimChunk.getPlayerHandler().getChunkName(chunkOwner); return chunkName != null ? chunkName : claimChunk.getMessages().unknownChunkOwner; } + + protected static @NotNull List splitLineLore(@NotNull String loreLine) { + return Arrays.asList(loreLine.split("\n")); + } + + /** + * Helper method to open the given GUI for its respective player. + * + * @param gui The gui to open. + */ + protected void openGui(@NotNull ICCGui gui) { + claimChunk.getGuiHandler().openOrRefreshGui(gui); + } } 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 fa8b15e8..890483af 100644 --- a/src/main/java/com/cjburkey/claimchunk/gui/screens/MainMenu.java +++ b/src/main/java/com/cjburkey/claimchunk/gui/screens/MainMenu.java @@ -9,7 +9,6 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; -import java.util.Collections; import java.util.UUID; public class MainMenu extends GuiMenuScreen { @@ -82,11 +81,8 @@ private void addMapItem(@NotNull Inventory inventory) { 4, materialFromStr(claimChunk.getConfigHandler().getGuiMainMenuChunkMapItem()), claimChunk.getMessages().guiMainMenuMapItemName, - Collections.singletonList(claimChunk.getMessages().guiMapDescription), - (clickType, stack) -> - claimChunk - .getGuiHandler() - .openOrRefreshGui(new MapMenu(claimChunk, getPlayer()))); + splitLineLore(claimChunk.getMessages().guiMainMenuMapItemDesc), + (clickType, stack) -> openGui(new MapMenu(claimChunk, getPlayer()))); } private void addPermsItem(@NotNull Inventory inventory) { @@ -95,7 +91,7 @@ private void addPermsItem(@NotNull Inventory inventory) { 6, materialFromStr(claimChunk.getConfigHandler().getGuiMainMenuPermFlagsItem()), claimChunk.getMessages().guiMainMenuPermFlagsItemName, - Collections.singletonList(claimChunk.getMessages().guiMainMenuPermFlagsDescription), - (clickType, stack) -> {}); + splitLineLore(claimChunk.getMessages().guiMainMenuPermFlagsDescription), + (clickType, stack) -> openGui(new PermSelectMenu(claimChunk, getPlayer()))); } } 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 04c9f0dc..e7e55895 100644 --- a/src/main/java/com/cjburkey/claimchunk/gui/screens/MapMenu.java +++ b/src/main/java/com/cjburkey/claimchunk/gui/screens/MapMenu.java @@ -21,7 +21,7 @@ public class MapMenu extends GuiMenuScreen { public MapMenu(@NotNull ClaimChunk claimChunk, @NotNull Player player) { // Offset to make it 6 tall so that we can have the top row be a menu bar. - super(claimChunk, player, MAP_HEIGHT + 1, claimChunk.getMessages().guiMainMenuTitle); + super(claimChunk, player, MAP_HEIGHT + 1, claimChunk.getMessages().guiMapMenuTitle); } @Override @@ -41,10 +41,7 @@ public void onOpen(@NotNull Inventory inventory) { materialFromStr(config.getGuiMenuBackButtonItem()), messages.guiMenuBackButtonName, Collections.singletonList(messages.guiMenuBackButtonDesc), - (clickType, stack) -> - claimChunk - .getGuiHandler() - .openOrRefreshGui(new MainMenu(claimChunk, getPlayer()))); + (clickType, stack) -> openGui(new MainMenu(claimChunk, getPlayer()))); // Add the map items // Inventory width is 9, so go 4 eastward and westward diff --git a/src/main/java/com/cjburkey/claimchunk/gui/screens/PermModifyMenu.java b/src/main/java/com/cjburkey/claimchunk/gui/screens/PermModifyMenu.java new file mode 100644 index 00000000..a117d280 --- /dev/null +++ b/src/main/java/com/cjburkey/claimchunk/gui/screens/PermModifyMenu.java @@ -0,0 +1,74 @@ +package com.cjburkey.claimchunk.gui.screens; + +import com.cjburkey.claimchunk.ClaimChunk; +import com.cjburkey.claimchunk.ClaimChunkConfig; +import com.cjburkey.claimchunk.gui.GuiMenuScreen; +import com.cjburkey.claimchunk.i18n.V2JsonMessages; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +public class PermModifyMenu extends GuiMenuScreen { + + public final boolean isAllChunks; + + public PermModifyMenu( + @NotNull ClaimChunk claimChunk, @NotNull Player player, boolean isAllChunks) { + // Offset to make it 6 tall so that we can have the top row be a menu bar. + super(claimChunk, player, 4, claimChunk.getMessages().guiPermSelectMenuTitle); + + this.isAllChunks = isAllChunks; + } + + @Override + public void onOpen(@NotNull Inventory inventory) { + V2JsonMessages messages = claimChunk.getMessages(); + ClaimChunkConfig config = claimChunk.getConfigHandler(); + Material allowItem = materialFromStr(config.getGuiPermSelectMenuItem()); + Material denyItem = materialFromStr(config.getGuiPermSelectMenuItem()); + + // Back button + addInteractiveButton( + inventory, + 0, + materialFromStr(config.getGuiMenuBackButtonItem()), + messages.guiMenuBackButtonName, + splitLineLore(messages.guiMenuBackButtonDesc), + (clickType, stack) -> openGui(new PermSelectMenu(claimChunk, getPlayer()))); + + // Add permission buttons + // TODO: WE HAVE TO ADD DEFAULT PERMISSIONS TO CHUNK DATA! + Map permissions = + isAllChunks + ? claimChunk + .getPlayerHandler() + .getDefaultPermissions(getPlayer().getUniqueId()) + : null; + if (permissions == null) { + return; + } + int slot = 0; + for (Map.Entry permission : permissions.entrySet()) { + addInteractiveButton( + inventory, + 9 + slot, + permission.getValue() ? allowItem : denyItem, + "&r&f" + permission.getKey(), + splitLineLore(messages.guiPermModifyPermDesc), + (clickType, stack) -> {}); + slot++; + } + } + + @Override + public @NotNull String getName() { + V2JsonMessages messages = claimChunk.getMessages(); + return isAllChunks + ? messages.guiPermModifyAllMenuTitle + : messages.guiPermModifyThisMenuTitle; + } +} diff --git a/src/main/java/com/cjburkey/claimchunk/gui/screens/PermSelectMenu.java b/src/main/java/com/cjburkey/claimchunk/gui/screens/PermSelectMenu.java new file mode 100644 index 00000000..831cd2c6 --- /dev/null +++ b/src/main/java/com/cjburkey/claimchunk/gui/screens/PermSelectMenu.java @@ -0,0 +1,52 @@ +package com.cjburkey.claimchunk.gui.screens; + +import com.cjburkey.claimchunk.ClaimChunk; +import com.cjburkey.claimchunk.ClaimChunkConfig; +import com.cjburkey.claimchunk.gui.GuiMenuScreen; +import com.cjburkey.claimchunk.i18n.V2JsonMessages; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.jetbrains.annotations.NotNull; + +public class PermSelectMenu extends GuiMenuScreen { + + public PermSelectMenu(@NotNull ClaimChunk claimChunk, @NotNull Player player) { + // Offset to make it 6 tall so that we can have the top row be a menu bar. + super(claimChunk, player, 1, claimChunk.getMessages().guiPermSelectMenuTitle); + } + + @Override + public void onOpen(@NotNull Inventory inventory) { + V2JsonMessages messages = claimChunk.getMessages(); + ClaimChunkConfig config = claimChunk.getConfigHandler(); + + // Back button + addInteractiveButton( + inventory, + 0, + materialFromStr(config.getGuiMenuBackButtonItem()), + messages.guiMenuBackButtonName, + splitLineLore(messages.guiPermModifyBackButtonDesc), + (clickType, stack) -> openGui(new MainMenu(claimChunk, getPlayer()))); + + Material item = materialFromStr(config.getGuiPermSelectMenuItem()); + + // Permission type selection button + addInteractiveButton( + inventory, + 4, + item, + messages.guiPermSelectMenuThisChunkName, + splitLineLore(messages.guiPermSelectMenuThisChunkDesc), + (clickType, stack) -> openGui(new PermModifyMenu(claimChunk, getPlayer(), false))); + addInteractiveButton( + inventory, + 5, + item, + messages.guiPermSelectMenuAllChunksName, + splitLineLore(messages.guiPermSelectMenuAllChunksDesc), + (clickType, stack) -> openGui(new PermModifyMenu(claimChunk, getPlayer(), true))); + } +} diff --git a/src/main/java/com/cjburkey/claimchunk/i18n/V2JsonMessages.java b/src/main/java/com/cjburkey/claimchunk/i18n/V2JsonMessages.java index d7a3c6f4..ea33c46b 100644 --- a/src/main/java/com/cjburkey/claimchunk/i18n/V2JsonMessages.java +++ b/src/main/java/com/cjburkey/claimchunk/i18n/V2JsonMessages.java @@ -181,22 +181,56 @@ public final class V2JsonMessages { public String chunkCancelPearlLaunch = "&cYou can't use ender pearls in &e%%OWNER%%&c's chunk"; // 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"; + // General 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 guiClickToClaim = "&2Left click to claim!"; public String guiClickToUnclaim = "&4Right click to unclaim"; + public String guiMenuBackButtonName = "&r&3&lBack"; + public String guiMenuBackButtonDesc = "&r&fReturn to the main menu"; + // Main menu + public String guiMainMenuTitle = "ClaimChunk Main GUI"; + public String guiMainMenuCurrentChunkItemName = "&r&3&lCurrent Chunk"; public String guiMainMenuMapItemName = "&r&3&lChunk Map"; - public String guiMapDescription = "&fClick to view the in-game map"; + public String guiMainMenuMapItemDesc = "&r&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)"; + """ + &r&fClick to manage other players' + &r&fpermissions in your chunk(s) + """; + // Map menu public String guiMapMenuTitle = "ClaimChunk Map"; - public String guiMapMenuInsideThisChunk = "&fYou are standing inside this chunk"; + public String guiMapMenuInsideThisChunk = "&r&fYou are standing inside this chunk"; + // Permission type selection menu + public String guiPermSelectMenuTitle = "Chunk Permissions Selection"; + public String guiPermSelectMenuThisChunkName = "&r&3&lThis Chunk"; + public String guiPermSelectMenuThisChunkDesc = + """ + &r&fModify permissions that other + &r&fplayers have in this chunk + """; + public String guiPermSelectMenuAllChunksName = "&r&3&lAll Chunks"; + public String guiPermSelectMenuAllChunksDesc = + """ + &r&fModify permissions that other + &r&fplayers have in all chunks + &r&facross all dimensions + """; + // Modify permissions screen + public String guiPermModifyAllMenuTitle = "Modify All Chunks"; + public String guiPermModifyThisMenuTitle = "Modify This Chunk"; + public String guiPermModifyBackButtonDesc = + """ + &r&fReturn to the permission type + &r&fselection screen + """; + public String guiPermModifyPermDesc = + """ + &r&eLeft click&f to &aAllow + &r&eRight click&f to &cDeny + """; // AdminOverride localization public String adminOverrideEnable = "&eYou now have protection bypass"; @@ -434,6 +468,7 @@ public static V2JsonMessages load(File file) throws IOException { Utils.err("Failed to load messages.json file!"); Utils.err("This is probably a problem!!"); Utils.err("Here's the error report:"); + //noinspection CallToPrintStackTrace e.printStackTrace(); // Don't overwrite users' files if they don't parse correctly, that's mean. diff --git a/src/main/java/com/cjburkey/claimchunk/player/PlayerHandler.java b/src/main/java/com/cjburkey/claimchunk/player/PlayerHandler.java index 0536313b..ce94da88 100644 --- a/src/main/java/com/cjburkey/claimchunk/player/PlayerHandler.java +++ b/src/main/java/com/cjburkey/claimchunk/player/PlayerHandler.java @@ -61,6 +61,10 @@ public Map getPermissions(ChunkPos chunk, UUID player) { return null; } + public Map getDefaultPermissions(UUID player) { + return dataHandler.getDefaultPermissionsForPlayer(player); + } + public Map> getAllPlayerPermissions(ChunkPos chunk) { // Get all players with permissions on the given chunk, and what permissions they have Map permissionsOnChunk = @@ -122,7 +126,8 @@ public void setMaxClaims(UUID player, int maxClaims) { // Use negative to take public void addOrTakeMaxClaims(UUID player, int claimsToAdd) { - dataHandler.addPlayerExtraMaxClaims(player, Math.abs(claimsToAdd)); + if (claimsToAdd > 0) dataHandler.addPlayerExtraMaxClaims(player, claimsToAdd); + else if (claimsToAdd < 0) dataHandler.takePlayerExtraMaxClaims(player, -claimsToAdd); } public int getMaxClaims(UUID player) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 421c98d6..799a700d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -22,6 +22,9 @@ gui: mapMenuCenterSelfClaimedItem: 'minecraft:green_glazed_terracotta' mapMenuCenterOtherClaimedItem: 'minecraft:blue_glazed_terracotta' mapMenuAllowClaimOtherChunks: true + permSelectMenuItem: 'minecraft:bow' + permModifyAllowItem: 'minecraft:green_wool' + permModifyDenyItem: 'minecraft:red_wool' titles: useTitlesInsteadOfChat: true @@ -90,6 +93,6 @@ database: allowPublicKeyRetrieval: false floodclaim: - enabled: true + enabled: false maximumIterations: 6 maximumArea: 41