Skip to content

Commit

Permalink
* Added reservoir gui
Browse files Browse the repository at this point in the history
* Fixed rank registry reloading & loading.
(If you change the name of a rank put a new key called "old-name: NameHere")
  • Loading branch information
Hempfest committed Feb 6, 2024
1 parent 1ffd099 commit 3e54d74
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Original file line number Diff line number Diff line change
@@ -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<String> tab(Player p, String label, String[] args) {
return SimpleTabCompletion.of(args)
.then(TabCompletionIndex.ONE, getBaseCompletion(args))
.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand All @@ -481,7 +488,7 @@ static <V extends Clan> BiFunction<String, V, String> 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()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -62,13 +66,15 @@
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;
import java.util.Objects;
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;
Expand Down Expand Up @@ -485,10 +491,14 @@ public boolean isNeutral(InvasiveEntity target) {
}
if (dataFile.isNode("members")) {
fixOldRankNames(dataFile);
for (String rank : dataFile.getNode("members").getKeys(false)) {
PantherMap<String, List<String>> ranksCorrected = new PantherEntryMap<>();
Node memberNode = dataFile.getNode("members");
for (String rank : memberNode.getKeys(false)) {
Rank priority = positionRegistry.getRank(rank);
List<String> 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 {
Expand All @@ -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<String> 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<String> 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");
}
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/config/Messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/config/Messages_es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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
Expand Down
37 changes: 37 additions & 0 deletions src/main/resources/config/Messages_pt_br.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config/Ranks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# - MANAGE_PASSWORD #
# - MANAGE_MODE #
# - MANAGE_NICKNAMES #
# - MANAGE_NICK_NAME #
# - LOGO_APPLY #
# - LOGO_UPLOAD #
# - LOGO_DISPLAY #
Expand Down Expand Up @@ -78,5 +79,6 @@ HIGHEST:
permissions:
- MANAGE_FRIENDLY_FIRE
- MANAGE_NAME
- MANAGE_NICK_NAME
- MANAGE_DESCRIPTION
- MANAGE_PERMS

0 comments on commit 3e54d74

Please sign in to comment.