From 3e54d74e8558f8cd58d92bc8564393bfb60a1106 Mon Sep 17 00:00:00 2001 From: Hempfest <64885225+Hempfest@users.noreply.github.com> Date: Tue, 6 Feb 2024 00:23:37 -0800 Subject: [PATCH] * Added reservoir gui * Fixed rank registry reloading & loading. (If you change the name of a rank put a new key called "old-name: NameHere") --- .../clans.upstream-conventions.gradle.kts | 2 +- .../clans/commands/CommandReservoir.java | 40 +++++++++++ .../sanctum/clans/construct/api/Clan.java | 9 ++- .../clans/construct/api/RankRegistry.java | 1 + .../clans/construct/impl/DefaultClan.java | 67 ++++++++++++++++++- src/main/resources/config/Messages.yml | 6 +- src/main/resources/config/Messages_es.yml | 6 +- src/main/resources/config/Messages_pt_br.yml | 37 ++++++++++ src/main/resources/config/Ranks.yml | 2 + 9 files changed, 159 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/github/sanctum/clans/commands/CommandReservoir.java diff --git a/buildSrc/src/main/kotlin/clans.upstream-conventions.gradle.kts b/buildSrc/src/main/kotlin/clans.upstream-conventions.gradle.kts index 71d4294..c0bf6db 100644 --- a/buildSrc/src/main/kotlin/clans.upstream-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/clans.upstream-conventions.gradle.kts @@ -15,5 +15,5 @@ repositories { // Define versions as extra properties val enterpriseVersion by extra("1.5") -val labyrinthVersion by extra("1.9.3") +val labyrinthVersion by extra("1.9.4-R1") val pantherVersion by extra("1.0.4-SNAPSHOT") diff --git a/src/main/java/com/github/sanctum/clans/commands/CommandReservoir.java b/src/main/java/com/github/sanctum/clans/commands/CommandReservoir.java new file mode 100644 index 0000000..82144fd --- /dev/null +++ b/src/main/java/com/github/sanctum/clans/commands/CommandReservoir.java @@ -0,0 +1,40 @@ +package com.github.sanctum.clans.commands; + +import com.github.sanctum.clans.construct.api.Clan; +import com.github.sanctum.clans.construct.api.ClanSubCommand; +import com.github.sanctum.clans.construct.api.ClansAPI; +import com.github.sanctum.clans.construct.api.GUI; +import com.github.sanctum.clans.construct.util.StringLibrary; +import com.github.sanctum.labyrinth.formatting.completion.SimpleTabCompletion; +import com.github.sanctum.labyrinth.formatting.completion.TabCompletionIndex; +import java.util.List; +import org.bukkit.entity.Player; + +public class CommandReservoir extends ClanSubCommand { + public CommandReservoir() { + super("reservoir"); + } + + @Override + public boolean player(Player p, String label, String[] args) { + StringLibrary lib = Clan.ACTION; + Clan.Associate associate = ClansAPI.getInstance().getAssociate(p).orElse(null); + + if (args.length == 0) { + if (associate != null) { + GUI.RESERVOIR.get(associate.getClan()).open(p); + } else { + sendMessage(p, lib.notInClan()); + } + return true; + } + return true; + } + + @Override + public List tab(Player p, String label, String[] args) { + return SimpleTabCompletion.of(args) + .then(TabCompletionIndex.ONE, getBaseCompletion(args)) + .get(); + } +} diff --git a/src/main/java/com/github/sanctum/clans/construct/api/Clan.java b/src/main/java/com/github/sanctum/clans/construct/api/Clan.java index e710c10..43dff9a 100644 --- a/src/main/java/com/github/sanctum/clans/construct/api/Clan.java +++ b/src/main/java/com/github/sanctum/clans/construct/api/Clan.java @@ -16,6 +16,7 @@ import com.github.sanctum.labyrinth.formatting.string.RandomHex; import com.github.sanctum.labyrinth.interfacing.Nameable; import com.github.sanctum.labyrinth.library.Mailer; +import com.github.sanctum.panther.annotation.Note; import com.github.sanctum.panther.file.JsonAdapter; import com.github.sanctum.panther.file.Node; import com.github.sanctum.panther.util.HUID; @@ -464,6 +465,12 @@ default boolean isConsole() { return getMembers().stream().filter(predicate).findFirst().orElse(null); } + @Note("This will be removed in the future. Its used temporarily in configuration.") + default double getBalanceDouble() { + ClanBank bank = BanksAPI.getInstance().getBank(this); + return bank != null ? bank.getBalanceDouble() : 0; + } + /** * @return The implementation this object provides. */ @@ -481,7 +488,7 @@ static BiFunction memoryDocketReplacer() { .replace(":reservoir_status:", (Reservoir.get(clan) != null ? "&aUP" : "&4DOWN")) .replace(":reservoir_progress:", Optional.ofNullable(Reservoir.get(clan)).map(r -> new ProgressBar().setProgress((int) r.getPower()).setGoal((int) r.getMaxPower()).setFullColor("&5&l").setPrefix(null).setSuffix(null).toString()).orElse(new ProgressBar().setProgress(0).setGoal(100).setBars(10).toString())) .replace(":reservoir_power:", Optional.ofNullable(Reservoir.get(clan)).map(r -> r.getPower() + "").orElse(0 + "")) - .replace(":reservoir_max_power:", Optional.ofNullable(Reservoir.get(clan)).map(r -> r.getMaxPower() + "").orElse(10000 + "")) + .replace(":reservoir_power_max:", Optional.ofNullable(Reservoir.get(clan)).map(r -> r.getMaxPower() + "").orElse(10000 + "")) .replace(":clan_logo:", clan.getLogo() == null ? "" : String.join("\n", clan.getLogo())) .replace(":clan_color:", clan.getPalette().toString()) .replace(":clan_name_colored:", clan.getPalette().toString(clan.getName())) diff --git a/src/main/java/com/github/sanctum/clans/construct/api/RankRegistry.java b/src/main/java/com/github/sanctum/clans/construct/api/RankRegistry.java index df00ae4..5f415ed 100644 --- a/src/main/java/com/github/sanctum/clans/construct/api/RankRegistry.java +++ b/src/main/java/com/github/sanctum/clans/construct/api/RankRegistry.java @@ -50,6 +50,7 @@ public void load() { if (ranksStream == null) throw new IllegalStateException("Unable to load Ranks.yml from the jar!"); FileList.copy(ranksStream, ranksFile.getRoot().getParent()); } + ranksFile.getRoot().reload(); ranksFile.read(c -> { int ordinal = 0; for (String section : c.getKeys(false)) { diff --git a/src/main/java/com/github/sanctum/clans/construct/impl/DefaultClan.java b/src/main/java/com/github/sanctum/clans/construct/impl/DefaultClan.java index eb1e181..9f05569 100644 --- a/src/main/java/com/github/sanctum/clans/construct/impl/DefaultClan.java +++ b/src/main/java/com/github/sanctum/clans/construct/impl/DefaultClan.java @@ -44,7 +44,11 @@ import com.github.sanctum.labyrinth.task.TaskScheduler; import com.github.sanctum.panther.annotation.Ordinal; import com.github.sanctum.panther.annotation.Removal; +import com.github.sanctum.panther.container.PantherCollectors; +import com.github.sanctum.panther.container.PantherEntry; +import com.github.sanctum.panther.container.PantherEntryMap; import com.github.sanctum.panther.container.PantherList; +import com.github.sanctum.panther.container.PantherMap; import com.github.sanctum.panther.file.Configurable; import com.github.sanctum.panther.file.MemorySpace; import com.github.sanctum.panther.file.Node; @@ -62,6 +66,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -69,6 +74,7 @@ import java.util.Optional; import java.util.Set; import java.util.Spliterator; +import java.util.TreeMap; import java.util.UUID; import java.util.function.Consumer; import java.util.function.Predicate; @@ -485,10 +491,14 @@ public boolean isNeutral(InvasiveEntity target) { } if (dataFile.isNode("members")) { fixOldRankNames(dataFile); - for (String rank : dataFile.getNode("members").getKeys(false)) { + PantherMap> ranksCorrected = new PantherEntryMap<>(); + Node memberNode = dataFile.getNode("members"); + for (String rank : memberNode.getKeys(false)) { Rank priority = positionRegistry.getRank(rank); + List members = new ArrayList<>(dataFile.getStringList("members." + rank)); if (priority != null) { - for (String mem : dataFile.getStringList("members." + rank)) { + ranksCorrected.put(rank, members); + for (String mem : members) { try { UUID id = UUID.fromString(mem); try { @@ -502,7 +512,58 @@ public boolean isNeutral(InvasiveEntity target) { } } } else { - ClansAPI.getInstance().getPlugin().getLogger().warning("Non-existing rank " + '"' + rank + '"' + " was found with (" + dataFile.getStringList("members." + rank).size() + ") members in clan file " + '"' + clanID + '"'); + ClansAPI.getInstance().getPlugin().getLogger().warning("Non-existing rank " + '"' + rank + '"' + " was found with (" + dataFile.getStringList("members." + rank).size() + ") members in clan file " + '"' + clanID + '"' + " Goal: Attempting to clean-up"); + // introduce config variable for replacement word, help people fix there data files! + // look for old-name variable to find rank. + String aName = "INTERNALCLANSPLACEHOLDER123"; + FileManager ranksFile = ClansAPI.getInstance().getFileList().get("Ranks", "Configuration"); + for (String tag : ranksFile.getRoot().getKeys(false)) { + String currentName = ranksFile.getRoot().getNode(tag + ".name").toPrimitive().getString(); + String oldName = ranksFile.getRoot().getNode(tag + ".old-name").toPrimitive().getString(); + if (rank.equals(oldName)) { + aName = currentName; + break; + } + } + Rank actual = positionRegistry.getRank(aName); + if (actual == null) { + ClansAPI.getInstance().getPlugin().getLogger().severe("Non-existing rank " + '"' + rank + '"' + " was found with (" + dataFile.getStringList("members." + rank).size() + ") members in clan file " + '"' + clanID + '"' + " Goal: Reset associates in tier."); + ClansAPI.getInstance().getPlugin().getLogger().severe("Setting associates to member to reduce risk of corruption."); + //remove associates from list and into members remove rank from list + actual = positionRegistry.getRank(0); + } + if (ranksCorrected.containsKey(actual.getName())) { + List list = ranksCorrected.get(actual.getName()); + for (String m : list) { + if (!list.contains(m)) { + TaskScheduler.of(() -> list.add(m)).schedule(); + } + } + } else { + ranksCorrected.put(actual.getName(), members); + } + } + } + if (!ranksCorrected.isEmpty()) { + memberNode.set(null); + ranksCorrected.forEach(e -> memberNode.getNode(e.getKey()).set(e.getValue())); + memberNode.save(); + for (String rank : memberNode.getKeys(false)) { + Rank priority = positionRegistry.getRank(rank); + List members = new ArrayList<>(dataFile.getStringList("members." + rank)); + for (String mem : members) { + try { + UUID id = UUID.fromString(mem); + try { + Associate associate = new DefaultAssociate(id, priority, this); + associates.add(associate); + } catch (InvalidAssociateTypeException e) { + ClansAPI.getInstance().getPlugin().getLogger().warning("A UUID with no playerdata in clan " + name + " was found " + '"' + mem + '"'); + } + } catch (IllegalArgumentException e) { + ClansAPI.getInstance().getPlugin().getLogger().warning('"' + mem + '"' + " is not a valid UUID. Please remove it from the " + '"' + name + '"' + " data file"); + } + } } } } diff --git a/src/main/resources/config/Messages.yml b/src/main/resources/config/Messages.yml index 3ed8f71..5454566 100644 --- a/src/main/resources/config/Messages.yml +++ b/src/main/resources/config/Messages.yml @@ -1368,9 +1368,9 @@ menu: locked: true type: left_button open: '/clan' - ':reservoir_progress:': + ' ': slot: 21 - lore: [ "&f&m&l--------------------", " ", "&eOur reservoir progress", " ", "&f&m&l--------------------", " ", "&aPower: &7:reservoir_power:/:reservoir_power_max:" ] + lore: [ "&f&m&l--------------------", " ", "&eOur reservoir progress", " ", ":reservoir_progress:", " ", "&f&m&l--------------------", " ", "&aPower: &7:reservoir_power:/:reservoir_power_max:" ] locked: true type: compass '&aGuards': @@ -1383,7 +1383,7 @@ menu: slot: 16 lore: [ "&fIf you need to purchase a reservoir you can do so by clicking this item." ] locked: true - type: endercrystal + type: endcrystal open: '/clan reservoir buy' title: 'Hello %player_name%' rows: SIX diff --git a/src/main/resources/config/Messages_es.yml b/src/main/resources/config/Messages_es.yml index 630eec8..0a1d225 100644 --- a/src/main/resources/config/Messages_es.yml +++ b/src/main/resources/config/Messages_es.yml @@ -1311,9 +1311,9 @@ menu: locked: true type: left_button open: '/clan' - ':reservoir_progress:': + ' ': slot: 21 - lore: [ "&f&m&l--------------------", " ", "&eOur reservoir progress", " ", "&f&m&l--------------------", " ", "&aPower: &7:reservoir_power:/:reservoir_power_max:" ] + lore: [ "&f&m&l--------------------", " ", "&eOur reservoir progress", " ", ":reservoir_progress:", " ", "&f&m&l--------------------", " ", "&aPower: &7:reservoir_power:/:reservoir_power_max:" ] locked: true type: compass '&aGuards': @@ -1326,7 +1326,7 @@ menu: slot: 16 lore: [ "&fIf you need to purchase a reservoir you can do so by clicking this item." ] locked: true - type: endercrystal + type: endcrystal open: '/clan reservoir buy' title: '&d&oRelaciones' rows: THREE diff --git a/src/main/resources/config/Messages_pt_br.yml b/src/main/resources/config/Messages_pt_br.yml index b20b0af..246f9c5 100644 --- a/src/main/resources/config/Messages_pt_br.yml +++ b/src/main/resources/config/Messages_pt_br.yml @@ -1327,6 +1327,43 @@ menu: enchantments: ARROW_DAMAGE: 2 flags: [ "HIDE_ENCHANTS" ] + reservoir: + title: '&6:clan_name: &0&lReservoir' + rows: FOUR + id: ':clan_name:;reservoir' + type: SINGULAR + filler: + name: ' ' + locked: true + type: glasspane + border: + name: ' ' + locked: true + type: stone + items: + '&cGo back': + slot: 10 + lore: [ "&cBack to main menu." ] + locked: true + type: left_button + open: '/clan' + ' ': + slot: 21 + lore: [ "&f&m&l--------------------", " ", "&eOur reservoir progress", " ", ":reservoir_progress:", " ", "&f&m&l--------------------", " ", "&aPower: &7:reservoir_power:/:reservoir_power_max:" ] + locked: true + type: compass + '&aGuards': + slot: 23 + lore: [ "&fCurrently active on duty: &e:%clans_guards_reservoir%:", "&7&o(Requires Guards addon)" ] + locked: true + close: true + type: ironaxe + '&eStatus&7: :reservoir_status:': + slot: 16 + lore: [ "&fIf you need to purchase a reservoir you can do so by clicking this item." ] + locked: true + type: endcrystal + open: '/clan reservoir buy' title: 'Hello %player_name%' rows: SIX type: SINGULAR diff --git a/src/main/resources/config/Ranks.yml b/src/main/resources/config/Ranks.yml index 11056f5..3dc14fb 100644 --- a/src/main/resources/config/Ranks.yml +++ b/src/main/resources/config/Ranks.yml @@ -17,6 +17,7 @@ # - MANAGE_PASSWORD # # - MANAGE_MODE # # - MANAGE_NICKNAMES # +# - MANAGE_NICK_NAME # # - LOGO_APPLY # # - LOGO_UPLOAD # # - LOGO_DISPLAY # @@ -78,5 +79,6 @@ HIGHEST: permissions: - MANAGE_FRIENDLY_FIRE - MANAGE_NAME + - MANAGE_NICK_NAME - MANAGE_DESCRIPTION - MANAGE_PERMS \ No newline at end of file