diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/Events.java b/Minigames/src/main/java/au/com/mineauz/minigames/Events.java index 6ec4b45de..9edea8185 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/Events.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/Events.java @@ -813,13 +813,13 @@ private void effectAreaAffectsPlayer(@NotNull AreaEffectCloudApplyEvent event) { private boolean isEffectApplicable(@NotNull Collection<@NotNull PotionEffectType> effectTypes, @NotNull MinigamePlayer mgPlayerEffecting, @NotNull MinigamePlayer mgPlayerReceiving) { if (!mgPlayerEffecting.getMinigame().isTeamGame()) { if (mgPlayerEffecting == mgPlayerReceiving) { - return !MinigameTag.NEGATIVE_POTION.allTagged(effectTypes); + return !MinigameTag.NEGATIVE_POTION_EFFECT.allTagged(effectTypes); } - return !MinigameTag.POSITIVE_POTION.allTagged(effectTypes); + return !MinigameTag.POSITIVE_POTION_EFFECT.allTagged(effectTypes); } if (mgPlayerEffecting.getTeam() == mgPlayerReceiving.getTeam()) { - return !MinigameTag.NEGATIVE_POTION.allTagged(effectTypes); + return !MinigameTag.NEGATIVE_POTION_EFFECT.allTagged(effectTypes); } - return !MinigameTag.POSITIVE_POTION.allTagged(effectTypes); + return !MinigameTag.POSITIVE_POTION_EFFECT.allTagged(effectTypes); } } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/MinigameTag.java b/Minigames/src/main/java/au/com/mineauz/minigames/MinigameTag.java index 37178e8a3..6f6549494 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/MinigameTag.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/MinigameTag.java @@ -11,7 +11,7 @@ public interface MinigameTag { * MinigameTag representing vanilla potions with negative effect(s). * Also represents all potions with exclusive negative effects, which aren't in the value list. */ - MinigameTag NEGATIVE_POTION = new MinigameTag<>() { + MinigameTag NEGATIVE_POTION_EFFECT = new MinigameTag<>() { @Override public boolean isTagged(PotionEffectType item) { return getValues().contains(item); @@ -47,7 +47,7 @@ public Set getValues() { * MinigameTag representing vanilla potions with positive effect(s) * Also represents all potions with exclusive positive effects, which aren't in the value list. */ - MinigameTag POSITIVE_POTION = new MinigameTag<>() { + MinigameTag POSITIVE_POTION_EFFECT = new MinigameTag<>() { @Override public boolean isTagged(PotionEffectType item) { return getValues().contains(item); @@ -87,7 +87,7 @@ public Set getValues() { /** * MinigameTag representing vanilla potions with both, positive and negative, effects */ - MinigameTag> MIXED_POTION = new MinigameTag<>() { + MinigameTag> MIXED_POTION_EFFECT = new MinigameTag<>() { @Override public boolean isTagged(Set item) { diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/PlayerLoadout.java b/Minigames/src/main/java/au/com/mineauz/minigames/PlayerLoadout.java index 6957c936d..33e9ed8ab 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/PlayerLoadout.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/PlayerLoadout.java @@ -22,7 +22,7 @@ public class PlayerLoadout { private final Map itemSlot = new HashMap<>(); private final List potions = new ArrayList<>(); private final Map, Object> addonValues = new HashMap<>(); - private String loadoutName = "default"; + private String loadoutName; private boolean usePermission = false; private boolean fallDamage = true; private boolean hunger = false; @@ -266,11 +266,11 @@ public void setValue(Integer value) { }; } - public boolean isDeleteable() { + public boolean isDeletable() { return deleteable; } - public void setDeleteable(boolean value) { + public void setDeletable(boolean value) { deleteable = value; } @@ -442,7 +442,7 @@ public void save(ConfigurationSection section) { section.set("hunger", hasHunger()); } - section.set("displayName", getDisplayName()); + section.set("displayName", MiniMessage.miniMessage().serialize(getDisplayName())); if (isArmourLocked()) { section.set("armourLocked", isArmourLocked()); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/commands/CommandDispatcher.java b/Minigames/src/main/java/au/com/mineauz/minigames/commands/CommandDispatcher.java index f05087c82..995da6a51 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/commands/CommandDispatcher.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/commands/CommandDispatcher.java @@ -143,7 +143,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) { if (args != null && args.length > 0) { - ACommand comd = commands.get(args[0].toLowerCase()); + ACommand comd = getCommand(args[0]); if (comd != null) { String[] shortArgs; diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/commands/HelpCommand.java b/Minigames/src/main/java/au/com/mineauz/minigames/commands/HelpCommand.java index 4574a8118..064678220 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/commands/HelpCommand.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/commands/HelpCommand.java @@ -9,7 +9,9 @@ import au.com.mineauz.minigames.managers.language.langkeys.MgCommandLangKey; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.JoinConfiguration; +import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.event.ClickEvent; +import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.command.CommandSender; import org.bukkit.permissions.Permissible; @@ -28,16 +30,23 @@ public class HelpCommand extends ACommand { private final int COMMANDS_PER_SITE = 6; // just a random number. Change it if you know a better one! private static boolean sendHelpInfo(@NotNull CommandSender sender, @NotNull ICommandInfo setCommand) { - if (setCommand.getPermission() != null || sender.hasPermission(setCommand.getPermission())) { - Component info = Component.empty(); - if (setCommand.getAliases() != null) { - info = info.append(Component.join(JoinConfiguration.arrayLike(), Arrays.stream(setCommand.getAliases()).map(Component::text).toList())); + if (setCommand.getPermission() == null || sender.hasPermission(setCommand.getPermission())) { + if (setCommand.getAliases() != null && setCommand.getAliases().length > 0) { + TextComponent.Builder info = Component.text(); + info.append(Component.join(JoinConfiguration.arrayLike(), Arrays.stream(setCommand.getAliases()).map(Component::text).toList())); + + MinigameMessageManager.sendMessage(sender, MinigameMessageType.NONE, + MinigameMessageManager.getMgMessage(MgCommandLangKey.COMMAND_HELP_INFO_HEADER, + Placeholder.unparsed(MinigamePlaceHolderKey.TEXT.getKey(), setCommand.getName())).appendNewline(). + append(info.appendNewline().append(setCommand.getUsage()).appendNewline().append(setCommand.getDescription()). + colorIfAbsent(NamedTextColor.WHITE)));//todo needs formatting (not hardcoded) + } else { + MinigameMessageManager.sendMessage(sender, MinigameMessageType.NONE, + MinigameMessageManager.getMgMessage(MgCommandLangKey.COMMAND_HELP_INFO_HEADER, + Placeholder.unparsed(MinigamePlaceHolderKey.TEXT.getKey(), setCommand.getName())).appendNewline(). + append(setCommand.getUsage().appendNewline().append(setCommand.getDescription()). + colorIfAbsent(NamedTextColor.WHITE)));//todo needs formatting (not hardcoded) } - - MinigameMessageManager.sendMessage(sender, MinigameMessageType.NONE, - MinigameMessageManager.getMgMessage(MgCommandLangKey.COMMAND_HELP_INFO_HEADER, - Placeholder.unparsed(MinigamePlaceHolderKey.TEXT.getKey(), setCommand.getName())).appendNewline(). - append(info.appendNewline().append(setCommand.getUsage()).appendNewline().append(setCommand.getDescription())));//todo needs formatting (not hardcoded) return true; } else { return false; @@ -82,7 +91,7 @@ private Component makePage(@NotNull Permissible permissible, int pageNumber) { // command name + description + click event for detailed info final Component pageCore = Component.join(JoinConfiguration.newlines(), commandsOfPage.stream(). map(cmd -> Component.text(cmd.getName()).append(Component.text(" - ")).append(cmd.getDescription()). - clickEvent(ClickEvent.suggestCommand("/minigame help " + cmd.getName()))).toList()); //todo needs formatting (not hardcoded) + clickEvent(ClickEvent.suggestCommand("/minigame help " + cmd.getName()))).toList()).colorIfAbsent(NamedTextColor.WHITE); //todo needs formatting (not hardcoded) final Component header = MinigameMessageManager.getMgMessage(MgCommandLangKey.COMMAND_HELP_LIST_HEADER, Placeholder.unparsed(MinigamePlaceHolderKey.NUMBER.getKey(), String.valueOf(pageNumber)), diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/commands/set/SetLoadoutCommand.java b/Minigames/src/main/java/au/com/mineauz/minigames/commands/set/SetLoadoutCommand.java index f39436a0b..aff47d623 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/commands/set/SetLoadoutCommand.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/commands/set/SetLoadoutCommand.java @@ -68,7 +68,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Minigame miniga MenuItemDisplayLoadout mil = new MenuItemDisplayLoadout(material, ld.getDisplayName(), MinigameMessageManager.getMgMessageList(MgMenuLangKey.MENU_DELETE_SHIFTRIGHTCLICK), ld, minigame); - mil.setAllowDelete(ld.isDeleteable()); + mil.setAllowDelete(ld.isDeletable()); mi.add(mil); } loadoutMenu.addItem(new MenuItemLoadoutAdd(Material.ITEM_FRAME, MgMenuLangKey.MENU_LOADOUT_ADD_NAME, diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/config/EnumFlag.java b/Minigames/src/main/java/au/com/mineauz/minigames/config/EnumFlag.java index c7d5d6292..0fbb80455 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/config/EnumFlag.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/config/EnumFlag.java @@ -1,7 +1,6 @@ package au.com.mineauz.minigames.config; import au.com.mineauz.minigames.menu.Callback; -import au.com.mineauz.minigames.menu.MenuItem; import au.com.mineauz.minigames.menu.MenuItemEnum; import net.kyori.adventure.text.Component; import org.bukkit.Material; @@ -44,7 +43,7 @@ public void loadValue(String path, FileConfiguration config) { * @param description will get ignored */ @Override - public MenuItem getMenuItem(@Nullable Material displayMat, @Nullable Component name, + public MenuItemEnum getMenuItem(@Nullable Material displayMat, @Nullable Component name, @Nullable List<@NotNull Component> description) { return new MenuItemEnum<>(displayMat, name, new Callback<>() { diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/config/LoadoutSetFlag.java b/Minigames/src/main/java/au/com/mineauz/minigames/config/LoadoutSetFlag.java index b9f1c3235..5c84f02c8 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/config/LoadoutSetFlag.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/config/LoadoutSetFlag.java @@ -35,7 +35,7 @@ public void loadValue(String path, FileConfiguration config) { for (String loadout : keys) { lf = new LoadoutFlag(new PlayerLoadout(loadout), loadout); if (loadout.equals("default")) - lf.getFlag().setDeleteable(false); + lf.getFlag().setDeletable(false); lf.loadValue(path + "." + getName(), config); getFlag().put(lf.getName(), lf.getFlag()); } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/config/MinigameSave.java b/Minigames/src/main/java/au/com/mineauz/minigames/config/MinigameSave.java index 04d8279bf..58bade805 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/config/MinigameSave.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/config/MinigameSave.java @@ -3,23 +3,26 @@ import au.com.mineauz.minigames.Minigames; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; public class MinigameSave { - private final String name; - String minigame = null; + private final @NotNull String name; + private final @Nullable String minigame; private FileConfiguration minigameSave = null; private File minigameSaveFile = null; - public MinigameSave(String name) { + public MinigameSave(@NotNull String name) { this.name = name; + this.minigame = null; reloadFile(); saveConfig(); } - public MinigameSave(String minigame, String name) { + public MinigameSave(@NotNull String minigame, @NotNull String name) { this.minigame = minigame; this.name = name; reloadFile(); @@ -48,13 +51,21 @@ public FileConfiguration getConfig() { public void saveConfig() { if (minigameSave == null || minigameSaveFile == null) { - Minigames.getCmpnntLogger().info("Could not save " + minigame + File.separator + name + " config file!"); + if (minigame != null) { + Minigames.getCmpnntLogger().info("Could not save " + minigame + File.separator + name + " config file!"); + } else { + Minigames.getCmpnntLogger().info("Could not save " + name + " config file!"); + } return; } try { minigameSave.save(minigameSaveFile); } catch (IOException ex) { - Minigames.getCmpnntLogger().error("Could not save " + minigame + File.separator + name + " config file!"); + if (minigame != null) { + Minigames.getCmpnntLogger().error("Could not save " + minigame + File.separator + name + " config file!"); + } else { + Minigames.getCmpnntLogger().error("Could not save " + name + " config file!"); + } } } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/managers/MinigameMessageManager.java b/Minigames/src/main/java/au/com/mineauz/minigames/managers/MinigameMessageManager.java index 2338493c7..4543ede68 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/managers/MinigameMessageManager.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/managers/MinigameMessageManager.java @@ -63,7 +63,7 @@ public static void registerCoreLanguage() { Minigames.getCmpnntLogger().info("MessageManager set locale for language:" + locale.toLanguageTag()); File file = new File(new File(Minigames.getPlugin().getDataFolder(), "lang"), "minigames.properties"); - registerCoreLanguage(file, Locale.getDefault()); + registerCoreLanguage(file, locale); } private static String saveConvert(String theString, boolean escapeSpace) { @@ -142,8 +142,9 @@ public static void initLangFiles(@NotNull CodeSource src, @NotNull String bundle FileUtils.copyToFile(zipStream, langFile); } else { // add defaults to file to expand in case there are key-value pairs missing Properties defaults = new Properties(); - try (InputStreamReader reader = new InputStreamReader(zipStream, StandardCharsets.UTF_8)) { - defaults.load(reader); + // no try with since we need to keep the ZipStream open + try { + defaults.load(new InputStreamReader(zipStream, StandardCharsets.UTF_8)); } catch (Exception e) { Minigames.getCmpnntLogger().warn("couldn't get default properties file for " + entryName + "!", e); continue; @@ -161,13 +162,16 @@ public static void initLangFiles(@NotNull CodeSource src, @NotNull String bundle // we are NOT using Properties#store since it gets rid of comments and doesn't guarantee ordering BufferedWriter bw = new BufferedWriter(fw)) { boolean updated = false; // only write comment once - for (Map.Entry translationPair : defaults.entrySet()) { + for (Map.Entry translationPair : defaults.entrySet()) { //todo guarantee ordering; default Properties are backed up by hashmap! if (current.get(translationPair.getKey()) == null) { if (!updated) { + // most likely this will generate an empty line, since the last line should be empty. + // however this is NOT guaranteed and therefore might write the command onto an existing line and ruin the translation there! + bw.newLine(); bw.write("# New Values where added. Is everything else up to date? Time of update: " + new Date()); bw.newLine(); - Minigames.getCmpnntLogger().trace("Updated langfile \"" + entryName + "\". Might want to check the new translation strings out!"); + Minigames.getCmpnntLogger().info("Updated langfile \"" + entryName + "\". Might want to check the new translation strings out!"); updated = true; } @@ -206,7 +210,7 @@ public static void registerCoreLanguage(@NotNull File file, @NotNull Locale loca } } if (langBundleMinigames != null) { - registerMessageFile("minigames", langBundleMinigames); + registerMessageFile(BUNDLE_KEY, langBundleMinigames); } else { Minigames.getCmpnntLogger().error("No Core Language Resource Could be loaded...messaging will be broken"); } @@ -313,6 +317,10 @@ public static void sendClickedCommandMessage(@NotNull Audience target, @NotNull Component init = getPluginPrefix(MinigameMessageType.INFO); Component message = getMessage(identifier, key, resolvers). clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND, command)); + + // don't use color of prefix + message = message.colorIfAbsent(NamedTextColor.WHITE); + target.sendMessage(init.append(message)); } @@ -325,6 +333,10 @@ public static void sendMessage(@NotNull Audience target, MinigameMessageType typ TagResolver... resolvers) { Component init = getPluginPrefix(type); Component message = getMessage(identifier, key, resolvers); + + // don't use color of prefix + message = message.colorIfAbsent(NamedTextColor.WHITE); + target.sendMessage(init.append(message)); } @@ -348,6 +360,9 @@ private static Component getPluginPrefix(MinigameMessageType type) { //todo get * @param permission - The permission required to see this broadcastServer message. */ public static void broadcastServer(@NotNull Component message, @NotNull Minigame minigame, @NotNull String permission) { + // don't use color of prefix + message = message.colorIfAbsent(NamedTextColor.WHITE); + MinigamesBroadcastEvent ev = new MinigamesBroadcastEvent(getPluginPrefix(MinigameMessageType.DEFAULT), message, minigame); Bukkit.getPluginManager().callEvent(ev); @@ -366,6 +381,9 @@ public static void broadcastServer(@NotNull Component message, @NotNull Minigame * @param type - The color to be used in the prefix. */ public static void broadcastServer(@NotNull Component message, @NotNull Minigame minigame, @NotNull MinigameMessageType type) { + // don't use color of prefix + message = message.colorIfAbsent(NamedTextColor.WHITE); + Component init = getPluginPrefix(type); MinigamesBroadcastEvent ev = new MinigamesBroadcastEvent(init, message, minigame); Bukkit.getPluginManager().callEvent(ev); @@ -449,7 +467,11 @@ public static void sendBroadcastMessageUnchecked(@NotNull Minigame minigame, fin public static void sendMessage(@NotNull Audience audience, @NotNull MinigameMessageType messageType, @Nullable String identifier, @NotNull LangKey key) { - audience.sendMessage(getPluginPrefix(messageType).append(getMessage(identifier, key))); + // don't use color of prefix + Component message = getMessage(identifier, key); + message = message.colorIfAbsent(NamedTextColor.WHITE); + + audience.sendMessage(getPluginPrefix(messageType).append(message)); } public static void sendMgMessage(@NotNull Audience audience, @NotNull MinigameMessageType messageType, @NotNull LangKey key) { @@ -473,6 +495,8 @@ public static void sendMgMessage(@NotNull MinigamePlayer mgPlayer, @NotNull Mini public static void sendMessage(@NotNull Audience audience, @NotNull MinigameMessageType messageType, @NotNull Component message) { + // don't use color of prefix + message = message.colorIfAbsent(NamedTextColor.WHITE); audience.sendMessage(getPluginPrefix(messageType).append(message)); } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/managers/language/langkeys/MgCommandLangKey.java b/Minigames/src/main/java/au/com/mineauz/minigames/managers/language/langkeys/MgCommandLangKey.java index be603ff0f..c1896473a 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/managers/language/langkeys/MgCommandLangKey.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/managers/language/langkeys/MgCommandLangKey.java @@ -55,7 +55,7 @@ public enum MgCommandLangKey implements LangKey { COMMAND_ERROR_NOTINMINIGAME_SELF("command.error.notInMinigame.self"), COMMAND_ERROR_NOTMATERIAL("command.error.notMaterial"), COMMAND_ERROR_NOTNUMBER("command.error.notNumber"), - COMMAND_ERROR_NOTPOTION("command.error.notPotion"), + COMMAND_ERROR_NOTSTATUSEFFECT("command.error.notStatusEffect"), COMMAND_ERROR_NOTTEAM("command.error.notTeam"), COMMAND_ERROR_NOTTIME("command.error.notTime"), COMMAND_ERROR_NOTTYPE("command.error.noType"), @@ -142,6 +142,11 @@ public enum MgCommandLangKey implements LangKey { COMMAND_SCORE_SET_PLAYER("command.score.set.player"), COMMAND_SCORE_SET_TEAM("command.score.set.team"), COMMAND_SCORE_USAGE("command.score.usage"), + COMMAND_SELECT_CLEAR("command.select.clear"), + COMMAND_SELECT_DESCRIPTION("command.select.description"), + COMMAND_SELECT_POINT1("command.select.point1"), + COMMAND_SELECT_POINT2("command.select.point2"), + COMMAND_SELECT_USAGE("command.select.usage"), COMMAND_SET_ALLOWENDERPERLS_DESCRIPTION("command.set.allowEnderPerls.description"), COMMAND_SET_ALLOWENDERPERLS_SUCCESS("command.set.allowEnderPerls.success"), COMMAND_SET_ALLOWENDERPERLS_USAGE("command.set.allowEnderPerls.usage"), @@ -398,12 +403,7 @@ public enum MgCommandLangKey implements LangKey { COMMAND_TOOL_ERROR_NOTOOL("command.tool.error.noTool"), COMMAND_TOOL_SETMODE("command.tool.setMode"), COMMAND_TOOL_SETTEAM("command.tool.setTeam"), - COMMAND_TOOL_USAGE("command.tool.usage"), - COMMAND_SELECT_DESCRIPTION("command.select.description"), - COMMAND_SELECT_USAGE("command.select.usage"), - COMMAND_SELECT_POINT1("command.select.point1"), - COMMAND_SELECT_POINT2("command.select.point2"), - COMMAND_SELECT_CLEAR("command.select.clear"); + COMMAND_TOOL_USAGE("command.tool.usage"); private final @NotNull String path; diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/managers/language/langkeys/MgMenuLangKey.java b/Minigames/src/main/java/au/com/mineauz/minigames/managers/language/langkeys/MgMenuLangKey.java index 562e3f570..1bf3bca80 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/managers/language/langkeys/MgMenuLangKey.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/managers/language/langkeys/MgMenuLangKey.java @@ -39,11 +39,9 @@ public enum MgMenuLangKey implements LangKey { MENU_DISPLAYLOADOUT_XPLEVEL_DESCRIPTION("menu.displayLoadout.xpLevel.description"), MENU_DISPLAYLOADOUT_XPLEVEL_NAME("menu.displayLoadout.xpLevel.name"), MENU_DISPLAYNAME_NAME("menu.displayName.name"), - MENU_EDIT_DOUBLECLICK("menu.edit.doubleClick"), MENU_EDIT_SHIFTLEFT("menu.edit.shiftLeft"), MENU_EFFECTS_SAVE_NAME("menu.effects.save.name"), MENU_ELEMENTNOTSET("menu.elementNotSet"), - MENU_ENUM_ERROR("menu.enum.error"), MENU_FLAGADD_ENTERCHAT("menu.flagAdd.enterChat"), MENU_FLAGADD_NAME("menu.flagAdd.name"), MENU_FLAG_REMOVED("menu.flag.removed"), @@ -61,6 +59,7 @@ public enum MgMenuLangKey implements LangKey { MENU_INFECTED_TEAM_INFECTED_NAME("menu.infected.team.infected.name"), MENU_INFECTED_TEAM_SURVIVOR_NAME("menu.infected.team.survivor.name"), MENU_INVERT_NAME("menu.invert.name"), + MENU_ITERABLE_ERROR_UNKNOWN("menu.iterable.error.unknown"), MENU_LIST_ENTERCHAT("menu.list.enterChat"), MENU_LIST_ERROR_INVALID("menu.list.error.invalid"), MENU_LIST_ERROR_TOOLONG("menu.list.error.long"), @@ -166,11 +165,6 @@ public enum MgMenuLangKey implements LangKey { MENU_PLAYSOUND_PRIVATEPLAYBACK_NAME("menu.playSound.privatePlayback.name"), MENU_PLAYSOUND_SOUND_NAME("menu.playSound.sound.name"), MENU_PLAYSOUND_VOLUME_NAME("menu.playSound.volume.name"), - MENU_POTIONADD_ENTERCHAT("menu.potionAdd.enterChat"), - MENU_POTIONADD_ERROR_SYNTAX("menu.potionAdd.error.syntax"), - MENU_POTIONADD_NAME("menu.potionAdd.name"), // todo unused - MENU_POTION_DURATION("menu.potion.duration"), - MENU_POTION_LEVEL("menu.potion.level"), MENU_RESOURCEPACK_OPTIONS_DISPLAYNAME_NAME("menu.resourcePack.options.displayname.name"), MENU_RESOURCEPACK_OPTIONS_ENABLE_NAME("menu.resourcePack.options.enable.name"), MENU_RESOURCEPACK_OPTIONS_FORCE_NAME("menu.resourcePack.options.force.name"), @@ -207,6 +201,11 @@ public enum MgMenuLangKey implements LangKey { MENU_SCOREBOARD_SETUP_NAME("menu.scoreboard.setup.name"), MENU_SCOREBOARD_STATISTIC_FIELD_NAME("menu.scoreboard.statistic.field.name"), MENU_SCOREBOARD_STATISTIC_NAME("menu.scoreboard.statistic.name"), + MENU_STATUSEFFECTADD_ENTERCHAT("menu.statusEffectAdd.enterChat"), + MENU_STATUSEFFECTADD_ERROR_SYNTAX("menu.statusEffectAdd.error.syntax"), + MENU_STATUSEFFECTADD_NAME("menu.statusEffectAdd.name"), + MENU_STATUSEFFECT_DURATION("menu.statusEffect.duration"), + MENU_STATUSEFFECT_LEVEL("menu.statusEffect.level"), MENU_STAT_EDIT_NAME("menu.stat.edit.name"), MENU_STAT_SELECT_FIELD_NAME("menu.stat.select.field.name"), MENU_STAT_SELECT_NAME("menu.stat.select.name"), diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/managers/language/langkeys/MinigameLangKey.java b/Minigames/src/main/java/au/com/mineauz/minigames/managers/language/langkeys/MinigameLangKey.java index 59949e667..e25785ca2 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/managers/language/langkeys/MinigameLangKey.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/managers/language/langkeys/MinigameLangKey.java @@ -4,9 +4,10 @@ public enum MinigameLangKey implements LangKey { //todo this gets rather big. Slit it into smaller digestible parts: tool, ?... AND("and"), + BOOL_FALSE("bool.false"), + BOOL_TRUE("bool.true"), CONFIG_BLACKLIST("config.blacklist"), CONFIG_WHITELIST("config.whitelist"), - BOOL_FALSE("bool.false"), MINIGAME_ERROR_FULL("minigame.error.full"), MINIGAME_ERROR_INCORRECTSTART("minigame.error.incorrectStart"), MINIGAME_ERROR_INVALIDMECHANIC("minigame.error.invalidMechanic"), @@ -191,10 +192,18 @@ public enum MinigameLangKey implements LangKey { //todo this gets rather big. Sl SIGN_SCORE_ERROR_ALREADYUSEDTEAM("sign.score.error.alreadyUsedTeam"), SIGN_TEAM_ERROR_UNBALANCE("sign.team.error.unbalance"), SIGN_TELEPORT_INVALID("sign.teleport.invalid"), + STATISTIC_ATTEMPTS_NAME("statistic.attempts.name"), + STATISTIC_DEATHS_NAME("statistic.deaths.name"), + STATISTIC_KILLS_NAME("statistic.kills.name"), + STATISTIC_LOSSES_NAME("statistic.losses.name"), + STATISTIC_REVERTS_NAME("statistic.reverts.name"), + STATISTIC_SCORE_NAME("statistic.score.name"), + STATISTIC_TIME_NAME("statistic.time.name"), STATISTIC_TITLE_LAST("statistic.title.last"), STATISTIC_TITLE_MAX("statistic.title.max"), STATISTIC_TITLE_MIN("statistic.title.min"), STATISTIC_TITLE_TOTAL("statistic.title.total"), + STATISTIC_WINS_NAME("statistic.wins.name"), TEAM_ADD("team.add"), TEAM_ERROR_COLOR_INVALID("team.error.color.invalid"), TEAM_ERROR_COLOR_TAKEN("team.error.color.taken"), @@ -251,16 +260,7 @@ public enum MinigameLangKey implements LangKey { //todo this gets rather big. Sl TOOL_SET_ENDLOCATION("tool.set.endLocation"), TOOL_SET_LOBBYLOCATION("tool.set.lobbyLocation"), TOOL_SET_QUITLOCATION("tool.set.quitLocation"), - TOOL_SET_SPECTATORLOCATION("tool.set.spectatorLocation"), - STATISTIC_WINS_NAME("statistic.wins.name"), - STATISTIC_LOSSES_NAME("statistic.losses.name"), - STATISTIC_ATTEMPTS_NAME("statistic.attempts.name"), - STATISTIC_TIME_NAME("statistic.time.name"), - STATISTIC_KILLS_NAME("statistic.kills.name"), - STATISTIC_DEATHS_NAME("statistic.deaths.name"), - STATISTIC_SCORE_NAME("statistic.score.name"), - STATISTIC_REVERTS_NAME("statistic.reverts.name"), - BOOL_TRUE("bool.true"); + TOOL_SET_SPECTATORLOCATION("tool.set.spectatorLocation"); private final @NotNull String path; diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/PlayerKillsMechanic.java b/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/PlayerKillsMechanic.java index 5dd5424e5..2bccc118c 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/PlayerKillsMechanic.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/mechanics/PlayerKillsMechanic.java @@ -23,7 +23,7 @@ public class PlayerKillsMechanic extends GameMechanicBase { @Override public String getMechanicName() { - return GameMechanics.MG_MECHANICS.KILLS.toString(); + return "kills"; } @Override diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItem.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItem.java index b63fff7e3..08f10b872 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItem.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItem.java @@ -1,29 +1,21 @@ package au.com.mineauz.minigames.menu; -import au.com.mineauz.minigames.Minigames; import au.com.mineauz.minigames.managers.MinigameMessageManager; import au.com.mineauz.minigames.managers.language.langkeys.LangKey; -import au.com.mineauz.minigames.objects.IndexedMap; -import au.com.mineauz.minigames.objects.StrIntMapPersistentDataType; import net.kyori.adventure.text.Component; import org.bukkit.Material; -import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.persistence.PersistentDataContainer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Map; public class MenuItem { - private static final StrIntMapPersistentDataType STR_INT_MAP_TYPE = new StrIntMapPersistentDataType(); private final static String BASE_DESCRIPTION_TOKEN = "Base_description"; - private final static NamespacedKey DESCRIPTION_KEY = new NamespacedKey(Minigames.getPlugin(), "DescriptionOrder"); + private final @NotNull List<@NotNull IdComponent> descriptionRegistry = new ArrayList<>(); private @NotNull ItemStack displayItem; private @Nullable Menu container = null; private int slot = 0; @@ -41,12 +33,13 @@ public MenuItem(@Nullable Material displayMat, @NotNull LangKey langKey, @Nullab } public MenuItem(@Nullable Material displayMat, @Nullable Component name, @Nullable List description) { - if (displayMat == null) + if (displayMat == null) { if (description == null) { displayMat = MenuUtility.getSlotFillerItem(); } else { displayMat = MenuUtility.getUnknownDisplayItem(); } + } this.displayItem = new ItemStack(displayMat); ItemMeta meta = this.displayItem.getItemMeta(); meta.displayName(name); @@ -58,58 +51,74 @@ public MenuItem(@Nullable Material displayMat, @Nullable Component name, @Nullab meta.lore(List.of()); this.displayItem.setItemMeta(meta); - setDescriptionPartAtIndex(BASE_DESCRIPTION_TOKEN, 0, description); + setDescriptionPart(BASE_DESCRIPTION_TOKEN, description); } } - public MenuItem(@NotNull Component name, @NotNull ItemStack displayItem) { + public MenuItem(@NotNull ItemStack displayItem, @Nullable Component name) { ItemMeta meta = displayItem.getItemMeta(); - meta.displayName(name); + if (name != null) { + meta.displayName(name); + } + + List lore = meta.lore(); + if (lore != null && !lore.isEmpty()) { + lore.stream().map(c -> new IdComponent(BASE_DESCRIPTION_TOKEN, c)).forEachOrdered(descriptionRegistry::add); + } + displayItem.setItemMeta(meta); this.displayItem = displayItem; } /** * Adds the description part to the end of the lore of an itemStack. - * If a description part with the same type key will get replaced if it was already there. + * If a description part with the same type key will get replaced at the same place if it was already there. * - * @param typeStr unique identifier the description part is registered as + * @param descriptionToken unique identifier the description part is registered as * @param descriptionPart the part of description to get written. If null the part will get removed. */ - public void setDescriptionPartAtEnd(@NotNull String typeStr, - @Nullable List<@NotNull Component> descriptionPart) { // todo maybe instead of Persistent data container just use a map here; the menu will not get saved anyways + public void setDescriptionPart(final @NotNull String descriptionToken, + @Nullable List<@NotNull Component> descriptionPart) { ItemMeta itemMeta = displayItem.getItemMeta(); - PersistentDataContainer container = itemMeta.getPersistentDataContainer(); - IndexedMap descriptionRegistry = container.get(DESCRIPTION_KEY, STR_INT_MAP_TYPE); - if (descriptionRegistry == null) { + if (descriptionRegistry.isEmpty()) { if (descriptionPart != null && !descriptionPart.isEmpty()) { // add // set part as lore, as it is the first entry - descriptionRegistry = new IndexedMap<>(); - descriptionRegistry.put(typeStr, descriptionPart.size()); + descriptionPart.stream().map(c -> new IdComponent(descriptionToken, c)).forEachOrdered(descriptionRegistry::add); itemMeta.lore(descriptionPart); - itemMeta.getPersistentDataContainer().set(DESCRIPTION_KEY, STR_INT_MAP_TYPE, descriptionRegistry); displayItem.setItemMeta(itemMeta); } // nothing to remove, when there was nothing } else { - removeDescriptionPart(itemMeta, descriptionRegistry, typeStr); + if (descriptionPart == null || descriptionPart.isEmpty()) { // remove + descriptionRegistry.stream().filter(idC -> idC.id().equals(descriptionToken)).forEach(descriptionRegistry::remove); + } else { + int index = -1; + + // check for last position and remove last description part registered under this token + Iterator idCIterator = descriptionRegistry.iterator(); + for (int i = 0; idCIterator.hasNext(); i++) { + IdComponent idCToCheck = idCIterator.next(); - if (descriptionPart != null) { // replace / add - List loreList = new ArrayList<>(); - List oldLoreList = itemMeta.lore(); + if (idCToCheck.id().equals(descriptionToken)) { + idCIterator.remove(); - if (oldLoreList != null) { - loreList.addAll(oldLoreList); // just in case the list is unmodifiable + if (index == -1) { + index = i; + } + } else if (index > -1) { + break; // already over it + } } - loreList.addAll(descriptionPart); - itemMeta.lore(loreList); - descriptionRegistry.put(typeStr, descriptionPart.size()); - } else { // remove - descriptionRegistry.remove(typeStr); + if (index >= 0) { // replace + descriptionRegistry.addAll(index, descriptionPart.stream().map(c -> new IdComponent(descriptionToken, c)).toList()); + } else { // add at end + descriptionPart.stream().map(c -> new IdComponent(descriptionToken, c)).forEachOrdered(descriptionRegistry::add); + } } + itemMeta.lore(descriptionRegistry.stream().map(IdComponent::component).toList()); displayItem.setItemMeta(itemMeta); } } @@ -119,104 +128,68 @@ public void setDescriptionPartAtEnd(@NotNull String typeStr, * A description part with the same type key will get removed if one was already present in the description. * This will not skip over values if a higher position was provided * - * @param typeStr unique identifier the description part is registered as - * @param postion the position to insert the part at. () + * @param descriptionToken unique identifier the description part is registered as + * @param postion the position to insert the part at. (Positions are of description parts - NOT elements of Components!) * @param descriptionPart the part of description to get inserted */ - public void setDescriptionPartAtIndex(@NotNull String typeStr, int postion, - @NotNull List<@NotNull Component> descriptionPart) { + public void setDescriptionPartAtIndex(final @NotNull String descriptionToken, int postion, + final @Nullable List<@NotNull Component> descriptionPart) { ItemMeta itemMeta = displayItem.getItemMeta(); - PersistentDataContainer container = itemMeta.getPersistentDataContainer(); - IndexedMap descriptionRegistry = container.get(DESCRIPTION_KEY, STR_INT_MAP_TYPE); - - if (descriptionRegistry == null) { - if (!descriptionPart.isEmpty()) { // add - ignoring index + if (descriptionRegistry.isEmpty()) { + if (descriptionPart != null && !descriptionPart.isEmpty()) { // add - ignoring index // set part as lore, as it is the first entry - descriptionRegistry = new IndexedMap<>(); - descriptionRegistry.put(typeStr, descriptionPart.size()); + descriptionPart.stream().map(c -> new IdComponent(descriptionToken, c)).forEachOrdered(descriptionRegistry::add); itemMeta.lore(descriptionPart); - itemMeta.getPersistentDataContainer().set(DESCRIPTION_KEY, STR_INT_MAP_TYPE, descriptionRegistry); displayItem.setItemMeta(itemMeta); } } else { // todo Math.clamp in Java 21 postion = Math.max(0, Math.min(postion, descriptionRegistry.size())); - if (postion >= descriptionRegistry.getKeyIndex(typeStr)) { - postion--; - } - removeDescriptionPart(itemMeta, descriptionRegistry, typeStr); - if (!descriptionPart.isEmpty()) { - int startingPoint = 0; - Iterator lengthIter = descriptionRegistry.values().iterator(); // don't modify with this iterator unless you have overwritten the standard one in IndexedMap! + removeDescriptionPart(descriptionToken); - for (int i = 0; lengthIter.hasNext() && i < postion; i++) { - Integer length = lengthIter.next(); + if (descriptionPart != null && !descriptionPart.isEmpty()) { + if (descriptionRegistry.isEmpty()) { // after removed the last entry the registry might be empty now! + // set part as lore, as it is the first entry + descriptionPart.stream().map(c -> new IdComponent(descriptionToken, c)).forEachOrdered(descriptionRegistry::add); + } else { + int workingPos = 0; + String lastId = null; - if (length != null && length > 0) { - startingPoint += length; - } else { - // well crap. invalid data! - Minigames.getCmpnntLogger().warn("Found empty description data. Ignoring it for now."); - //todo we need a iterator of IndexedMap --> code it! - } - } + for (int i = 0; i < descriptionRegistry.size(); i++) { + IdComponent idC = descriptionRegistry.get(i); - List loreList = new ArrayList<>(); - List oldLoreList = itemMeta.lore(); - if (oldLoreList != null) { - loreList.addAll(oldLoreList); // just in case the list is unmodifiable - loreList.addAll(startingPoint, descriptionPart); - } else { - loreList = descriptionPart; - } + if (lastId == null || !lastId.equals(idC.id())) { + if (workingPos == postion) { + descriptionRegistry.addAll(i, descriptionPart.stream().map(c -> new IdComponent(descriptionToken, c)).toList()); - itemMeta.lore(loreList); - } + break; + } - descriptionRegistry.put(typeStr, descriptionPart.size()); - itemMeta.getPersistentDataContainer().set(DESCRIPTION_KEY, STR_INT_MAP_TYPE, descriptionRegistry); + lastId = idC.id(); + workingPos++; + } + } // for loop + } // else + } // description part empty + + itemMeta.lore(descriptionRegistry.stream().map(IdComponent::component).toList()); displayItem.setItemMeta(itemMeta); } } - private static void removeDescriptionPart(@NotNull ItemMeta itemMeta, @NotNull IndexedMap descriptionRegistry, @NotNull String typeStr) { - if (descriptionRegistry.containsKey(typeStr)) { - Integer lastPartLength = descriptionRegistry.get(typeStr); - - if (lastPartLength != null && lastPartLength > 0) { - int startingPoint = 0; - for (Map.Entry entryBefore : descriptionRegistry.entrySet()) { - if (typeStr.equals(entryBefore.getKey())) { - break; - } else { - Integer lengthBefore = entryBefore.getValue(); - if (lengthBefore != null) { - startingPoint += entryBefore.getValue(); - } else { - // well crap. invalid data! - Minigames.getCmpnntLogger().warn("Found empty description data. Ignoring it for now."); - //todo we need a iterator of IndexedMap --> code it! - } - } - } + public void removeDescriptionPart(@NotNull String descriptionToken) { + boolean found = false; + for (Iterator it = descriptionRegistry.iterator(); it.hasNext(); ) { + IdComponent idCToCheck = it.next(); - List loreList = itemMeta.lore(); - if (loreList != null) { - for (int i = startingPoint; i < startingPoint + lastPartLength && i < loreList.size(); i++) { - loreList.remove(i); - } - } else { - // well crap. invalid data! - Minigames.getCmpnntLogger().error("Menu item has empty lore but tried to remove a part of it. Clearing all parts mow. Please open an Issue!"); - descriptionRegistry.clear(); - } - } else { - // well crap. invalid data! - Minigames.getCmpnntLogger().warn("Menu item trying to remove empty description data."); - descriptionRegistry.remove(typeStr); + if (idCToCheck.id().equals(descriptionToken)) { + found = true; + + it.remove(); + } else if (found) { + break; } } } @@ -228,8 +201,7 @@ public List getDescription() { /** * Sets the description unter the base description token. * - * @param description - * @see #setDescriptionPartAtEnd(String, List) + * @see #setDescriptionPart(String, List) * @see #setDescriptionPartAtIndex(String, int, List) */ public void setBaseDescriptionPart(List description) { @@ -237,25 +209,32 @@ public void setBaseDescriptionPart(List description) { } public @NotNull Component getName() { - return displayItem.displayName(); + Component displayName = displayItem.getItemMeta().displayName(); + return displayName == null ? Component.translatable(displayItem.translationKey()) : displayName; } public @NotNull ItemStack getDisplayItem() { return displayItem; } + /** + * overwrites name with last name and lore with lore registered in {@link #setDescriptionPart(String, List)} and + * {@link #setDescriptionPartAtIndex(String, int, List)}, + * however this will set the BaseDescription to the new lore - potentially clearing it + * + * @see #setBaseDescriptionPart(List) + */ public void setDisplayItem(@NotNull ItemStack item) { - ItemMeta ometa = displayItem.getItemMeta(); + ItemMeta originalMeta = displayItem.getItemMeta(); displayItem = item.clone(); - ItemMeta nmeta = displayItem.getItemMeta(); - nmeta.displayName(ometa.displayName()); - nmeta.lore(nmeta.lore()); - try { - nmeta.getPersistentDataContainer().readFromBytes(ometa.getPersistentDataContainer().serializeToBytes()); - } catch (IOException e) { - Minigames.getCmpnntLogger().error("Could not carry over persistent data from one menuItem to another. Description Data might got lost!", e); - } - displayItem.setItemMeta(nmeta); + ItemMeta newMeta = displayItem.getItemMeta(); + newMeta.displayName(originalMeta.displayName()); + + List newBaseLore = newMeta.lore(); // save temporary + newMeta.lore(descriptionRegistry.stream().map(IdComponent::component).toList()); + displayItem.setItemMeta(newMeta); + + setBaseDescriptionPart(newBaseLore); } public void update() { @@ -310,4 +289,7 @@ public int getSlot() { public void setSlot(int slot) { this.slot = slot; } + + private record IdComponent(@NotNull String id, @NotNull Component component) { + } } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemBlockData.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemBlockData.java index 6f5c249e0..f4e5fe90e 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemBlockData.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemBlockData.java @@ -29,12 +29,12 @@ public MenuItemBlockData(@NotNull Material displayMat, @Nullable Component name, @NotNull Callback callback) { super(displayMat, name); this.dataCallback = callback; - setDescriptionPartAtEnd(DESCRIPTION_TOKEN, createDescription(dataCallback.getValue())); + setDescriptionPart(DESCRIPTION_TOKEN, createDescription(dataCallback.getValue())); } @Override public void update() { - setDescriptionPartAtEnd(DESCRIPTION_TOKEN, createDescription(this.dataCallback.getValue())); + setDescriptionPart(DESCRIPTION_TOKEN, createDescription(this.dataCallback.getValue())); } /** @@ -95,7 +95,7 @@ public void checkValidEntry(String entry) { try { BlockData d = Bukkit.createBlockData(entry); dataCallback.setValue(d); - setDescriptionPartAtEnd(DESCRIPTION_TOKEN, createDescription(dataCallback.getValue())); + setDescriptionPart(DESCRIPTION_TOKEN, createDescription(dataCallback.getValue())); // update the display item if (d.getMaterial().isItem()) { diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemBoolean.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemBoolean.java index 8ecc9c07b..c67689763 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemBoolean.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemBoolean.java @@ -45,7 +45,7 @@ public MenuItemBoolean(@Nullable Material displayMat, @Nullable Component name, public void updateDescription() { LangKey boolKey = toggle.getValue() ? MinigameLangKey.BOOL_TRUE : MinigameLangKey.BOOL_FALSE; - setDescriptionPartAtEnd(DESCRIPTION_TOKEN, MinigameMessageManager.getMgMessageList(boolKey)); + setDescriptionPart(DESCRIPTION_TOKEN, MinigameMessageManager.getMgMessageList(boolKey)); } @Override diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemComponent.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemComponent.java index ac0e2d220..f6c4aa3a9 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemComponent.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemComponent.java @@ -15,6 +15,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.time.Duration; import java.util.List; public class MenuItemComponent extends MenuItem { @@ -55,7 +56,7 @@ public void updateDescription() { // limit to a still readable size settingComp = MinigameUtils.limitIgnoreFormat(settingComp, 20); - setDescriptionPartAtEnd(DESCRIPTION_VALUE_TOKEN, List.of(settingComp)); + setDescriptionPart(DESCRIPTION_VALUE_TOKEN, List.of(settingComp)); } @Override @@ -63,14 +64,17 @@ public ItemStack onDoubleClick() { MinigamePlayer mgPlayer = getContainer().getViewer(); mgPlayer.setNoClose(true); mgPlayer.getPlayer().closeInventory(); + + final int reopenSeconds = 20; MinigameMessageManager.sendMgMessage(mgPlayer, MinigameMessageType.INFO, MgMenuLangKey.MENU_STRING_ENTERCHAT, - Placeholder.component(MinigamePlaceHolderKey.TYPE.getKey(), getName())); + Placeholder.component(MinigamePlaceHolderKey.TYPE.getKey(), getName()), + Placeholder.component(MinigamePlaceHolderKey.TIME.getKey(), MinigameUtils.convertTime(Duration.ofSeconds(reopenSeconds)))); if (allowNull) { MinigameMessageManager.sendMgMessage(mgPlayer, MinigameMessageType.INFO, MgMenuLangKey.MENU_STRING_ALLOWNULL, Placeholder.component(MinigamePlaceHolderKey.TYPE.getKey(), getName())); } mgPlayer.setManualEntry(this); - getContainer().startReopenTimer(20); + getContainer().startReopenTimer(reopenSeconds); return null; } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemDecimal.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemDecimal.java index b32aab294..dba0cc128 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemDecimal.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemDecimal.java @@ -78,7 +78,7 @@ public void updateDescription() { description = Component.text(form.format(value.getValue()), NamedTextColor.GREEN); } - setDescriptionPartAtEnd(DESCRIPTION_TOKEN, List.of(description)); + setDescriptionPart(DESCRIPTION_TOKEN, List.of(description)); } @Override diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemDisplayLoadout.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemDisplayLoadout.java index 5ba02f045..0f2d570af 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemDisplayLoadout.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemDisplayLoadout.java @@ -33,7 +33,7 @@ public MenuItemDisplayLoadout(@Nullable Material displayMat, @Nullable Component super(displayMat, name); this.loadout = loadout; this.minigame = minigame; - if (!loadout.isDeleteable()) { + if (!loadout.isDeletable()) { allowDelete = false; } } @@ -41,7 +41,7 @@ public MenuItemDisplayLoadout(@Nullable Material displayMat, @Nullable Component public MenuItemDisplayLoadout(@Nullable Material displayMat, @Nullable Component name, @NotNull PlayerLoadout loadout) { super(displayMat, name); this.loadout = loadout; - if (!loadout.isDeleteable()) { + if (!loadout.isDeletable()) { allowDelete = false; } } @@ -52,7 +52,7 @@ public MenuItemDisplayLoadout(@Nullable Material displayMat, @Nullable Component super(displayMat, name, description); this.loadout = loadout; this.minigame = minigame; - if (!loadout.isDeleteable()) { + if (!loadout.isDeletable()) { allowDelete = false; } } @@ -61,7 +61,7 @@ public MenuItemDisplayLoadout(@Nullable Material displayMat, @Nullable Component @Nullable List<@NotNull Component> description, @NotNull PlayerLoadout loadout) { super(displayMat, name, description); this.loadout = loadout; - if (!loadout.isDeleteable()) { + if (!loadout.isDeletable()) { allowDelete = false; } } @@ -115,14 +115,14 @@ public ItemStack onClick() { Menu potionMenu = new Menu(5, getContainer().getName(), getContainer().getViewer()); potionMenu.setPreviousPage(loadoutMenu); - potionMenu.addItem(new MenuItemPotionAdd(MenuUtility.getCreateMaterial(), MgMenuLangKey.MENU_POTIONADD_NAME, loadout), potionMenu.getSize() - 1); + potionMenu.addItem(new MenuItemStatusEffectAdd(MenuUtility.getCreateMaterial(), MgMenuLangKey.MENU_STATUSEFFECTADD_NAME, loadout), potionMenu.getSize() - 1); potionMenu.addItem(menuItemBack, potionMenu.getSize() - 2); List description = MinigameMessageManager.getMgMessageList(MgMenuLangKey.MENU_DELETE_SHIFTRIGHTCLICK); List potionMenuItems = new ArrayList<>(); for (PotionEffect eff : loadout.getAllPotionEffects()) { - potionMenuItems.add(new MenuItemPotion(Material.POTION, Component.translatable(eff.getType().translationKey()), description, eff, loadout)); + potionMenuItems.add(new MenuItemStatusEffect(Material.POTION, Component.translatable(eff.getType().translationKey()), description, eff, loadout)); } potionMenu.addItems(potionMenuItems); @@ -134,7 +134,7 @@ public ItemStack onClick() { loadoutMenu.addItem(new MenuItemSaveLoadoutPage(MenuUtility.getSaveMaterial(), MgMenuLangKey.MENU_DISPLAYLOADOUT_SAVE_NAME, loadout, getContainer()), 44); final int numOfSlots = loadout.allowOffHand() ? 41 : 40; for (int i = numOfSlots; i < 42; i++) { - loadoutMenu.addItem(new MenuItem(null, Component.empty()), i); + loadoutMenu.addItem(new MenuItem((Material) null, Component.empty()), i); } loadoutMenu.displayMenu(getContainer().getViewer()); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemEnum.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemEnum.java index 70bc7191f..66ec781e2 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemEnum.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemEnum.java @@ -52,25 +52,25 @@ protected final void updateDescription() { int position = enumList.indexOf(callback.getValue()); if (position == -1) { - setDescriptionPartAtEnd(DESCRIPTION_VALUE_TOKEN, - List.of(MinigameMessageManager.getMgMessage(MgMenuLangKey.MENU_ENUM_ERROR))); + setDescriptionPart(DESCRIPTION_VALUE_TOKEN, List.of( + MinigameMessageManager.getMgMessage(MgMenuLangKey.MENU_ITERABLE_ERROR_UNKNOWN))); + } else { + int last = position - 1; + int next = position + 1; + if (last < 0) { + last = enumList.size() - 1; + } + if (next >= enumList.size()) { + next = 0; + } + + List options = new ArrayList<>(3); + options.add(Component.text(getEnumName(enumList.get(last)), NamedTextColor.GRAY)); + options.add(Component.text(getEnumName(enumList.get(position)), NamedTextColor.GREEN)); + options.add(Component.text(getEnumName(enumList.get(next)), NamedTextColor.GRAY)); + + setDescriptionPart(DESCRIPTION_VALUE_TOKEN, options); } - - int last = position - 1; - int next = position + 1; - if (last < 0) { - last = enumList.size() - 1; - } - if (next >= enumList.size()) { - next = 0; - } - - List options = new ArrayList<>(3); - options.add(Component.text(getEnumName(enumList.get(last)), NamedTextColor.GRAY)); - options.add(Component.text(getEnumName(enumList.get(position)), NamedTextColor.GREEN)); - options.add(Component.text(getEnumName(enumList.get(next)), NamedTextColor.GRAY)); - - setDescriptionPartAtEnd(DESCRIPTION_VALUE_TOKEN, options); } private String getEnumName(T val) { diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemInteger.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemInteger.java index 239704654..a3e41614f 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemInteger.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemInteger.java @@ -9,8 +9,8 @@ import au.com.mineauz.minigames.managers.language.langkeys.MgMenuLangKey; import au.com.mineauz.minigames.objects.MinigamePlayer; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -22,8 +22,8 @@ public class MenuItemInteger extends MenuItem { private final static String DESCRIPTION_TOKEN = "Integer_description"; private final Callback value; - private final Integer min; - private final Integer max; + private final Integer min; // inclusive + private final Integer max; // inclusive public MenuItemInteger(@Nullable Material displayMat, @NotNull LangKey langKey, @NotNull Callback value, @Nullable Integer min, @Nullable Integer max) { @@ -62,7 +62,7 @@ public MenuItemInteger(@Nullable Material displayMat, @Nullable Component name, } public void updateDescription() { - setDescriptionPartAtEnd(DESCRIPTION_TOKEN, List.of(Component.text(value.getValue(), NamedTextColor.GREEN))); + setDescriptionPart(DESCRIPTION_TOKEN, List.of(Component.text(value.getValue(), NamedTextColor.GREEN))); } @Override @@ -106,12 +106,15 @@ public ItemStack onDoubleClick() { MinigamePlayer mgPlayer = getContainer().getViewer(); mgPlayer.setNoClose(true); mgPlayer.getPlayer().closeInventory(); + final int reopenSeconds = 10; MinigameMessageManager.sendMgMessage(mgPlayer, MinigameMessageType.INFO, MgMenuLangKey.MENU_NUMBER_ENTERCHAT, Placeholder.component(MinigamePlaceHolderKey.TYPE.getKey(), getName()), Placeholder.component(MinigamePlaceHolderKey.TIME.getKey(), MinigameUtils.convertTime(Duration.ofSeconds(reopenSeconds))), - Placeholder.unparsed(MinigamePlaceHolderKey.MIN.getKey(), this.min == null ? "N/A" : this.min.toString()), + Placeholder.unparsed(MinigamePlaceHolderKey.MIN.getKey(), this.min == null ? "N/A" : this.min.toString()), //todo don't hardcode N/A Placeholder.unparsed(MinigamePlaceHolderKey.MAX.getKey(), this.max == null ? "N/A" : this.max.toString())); + + mgPlayer.setManualEntry(this); getContainer().startReopenTimer(reopenSeconds); return null; @@ -125,16 +128,19 @@ public void checkValidEntry(String entry) { value.setValue(entryValue); updateDescription(); - getContainer().cancelReopenTimer(); - getContainer().displayMenu(getContainer().getViewer()); + } else { + MinigameMessageManager.sendMgMessage(getContainer().getViewer(), MinigameMessageType.ERROR, + MgCommandLangKey.COMMAND_ERROR_OUTOFBOUNDS, + Placeholder.unparsed(MinigamePlaceHolderKey.MIN.getKey(), this.min == null ? "N/A" : this.min.toString()), + Placeholder.unparsed(MinigamePlaceHolderKey.MAX.getKey(), this.max == null ? "N/A" : this.max.toString())); } } else { - getContainer().cancelReopenTimer(); - getContainer().displayMenu(getContainer().getViewer()); - MinigameMessageManager.sendMgMessage(getContainer().getViewer(), MinigameMessageType.ERROR, MgCommandLangKey.COMMAND_ERROR_NOTNUMBER, Placeholder.unparsed(MinigamePlaceHolderKey.TEXT.getKey(), entry)); } + + getContainer().cancelReopenTimer(); + getContainer().displayMenu(getContainer().getViewer()); } } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemItemNbt.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemItemNbt.java index 1daafabba..bb916901e 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemItemNbt.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemItemNbt.java @@ -4,6 +4,7 @@ import org.apache.commons.text.WordUtils; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -17,6 +18,8 @@ * Amounts are not supported here. */ public class MenuItemItemNbt extends MenuItem { + private final static String DESCRIPTION_TOKEN = "Nbt_description"; + /** * NEVER EVER confuse this item with the display item of MenuItem! * this one contains the pure data as it should get written to config if needed. @@ -40,9 +43,9 @@ public MenuItemItemNbt(@Nullable Material displayMat, @Nullable Component name, } public MenuItemItemNbt(@NotNull ItemStack itemStack, Component name, @NotNull Callback c) { - super(name, itemStack.clone()); // clone to not overwrite lore / name + super(itemStack.clone(), name); // clone to not overwrite lore / name - setDescriptionPartAtEnd("MenuItemItemNbt", createDescription(itemStack)); + setDescriptionPart(DESCRIPTION_TOKEN, createDescription(itemStack)); itemCallback = c; } @@ -58,7 +61,7 @@ public ItemStack onClickWithItem(ItemStack item) { // cloned one as display item since it gets changed to display name / description / other meta setDisplayItem(workItemStack.clone()); // please note, the item used to create the components is the original - not cloned one! - setDescriptionPartAtEnd("MenuItemItemNbt", createDescription(workItemStack)); + setDescriptionPart(DESCRIPTION_TOKEN, createDescription(workItemStack)); return super.onClickWithItem(itemCallback.getValue()); } @@ -78,21 +81,24 @@ public ItemStack getItem() { public void processNewName(@NotNull Component newName) { ItemStack oldData = itemCallback.getValue(); - setDescriptionPartAtEnd("MenuItemItemNbt", createDescription(oldData.getType(), newName, oldData.lore())); + setDescriptionPart(DESCRIPTION_TOKEN, createDescription(oldData.getType(), newName, oldData.lore())); } public void processNewLore(@Nullable List<@NotNull Component> newLore) { ItemStack oldData = itemCallback.getValue(); - setDescriptionPartAtEnd("MenuItemItemNbt", createDescription(oldData.getType(), oldData.displayName(), newLore)); + setDescriptionPart(DESCRIPTION_TOKEN, createDescription(oldData.getType(), oldData.displayName(), newLore)); } - private List createDescription(@NotNull ItemStack data) { - return createDescription(data.getType(), data.displayName(), data.lore()); + private List createDescription(@NotNull ItemStack itemStack) { + ItemMeta meta = itemStack.getItemMeta(); + return createDescription(itemStack.getType(), meta.displayName(), meta.lore()); } - private List createDescription(@NotNull Material type, @NotNull Component displayName, @Nullable List<@NotNull Component> lore) { + private List createDescription(@NotNull Material type, @Nullable Component displayName, @Nullable List<@NotNull Component> lore) { List result = new ArrayList<>(); - result.add(Component.text("Name: ").append(displayName)); + if (displayName != null) { + result.add(Component.text("Name: ").append(displayName)); + } result.add(Component.text("Material: " + WordUtils.capitalizeFully(type.name()))); if (lore != null) { diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemList.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemList.java index 94c57519e..9275b88aa 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemList.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemList.java @@ -8,8 +8,8 @@ import au.com.mineauz.minigames.managers.language.langkeys.MgMenuLangKey; import au.com.mineauz.minigames.objects.MinigamePlayer; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -56,31 +56,42 @@ public MenuItemList(@Nullable Material displayMat, @Nullable Component name, } public void updateDescription() { - List description; - int pos = options.indexOf(value.getValue()); - int before = pos - 1; - int after = pos + 1; - if (before < 0) { - before = options.size() - 1; - } - if (after == options.size()) { - after = 0; + if (options.isEmpty()) { + return; } - description = new ArrayList<>(); - description.add(Component.text(options.get(before).toString(), NamedTextColor.GRAY)); - description.add(Component.text(options.get(pos).toString(), NamedTextColor.GREEN)); - description.add(Component.text(options.get(after).toString(), NamedTextColor.GRAY)); + int pos = options.indexOf(value.getValue()); + + if (pos == -1) { + setDescriptionPart(DESCRIPTION_TOKEN, + MinigameMessageManager.getMgMessageList(MgMenuLangKey.MENU_ITERABLE_ERROR_UNKNOWN)); + } else { + List description = new ArrayList<>(); + + int before = pos - 1; + int after = pos + 1; + if (before < 0) { + before = options.size() - 1; + } + if (after == options.size()) { + after = 0; + } + + description.add(Component.text(options.get(before).toString(), NamedTextColor.GRAY)); + description.add(Component.text(options.get(pos).toString(), NamedTextColor.GREEN)); + description.add(Component.text(options.get(after).toString(), NamedTextColor.GRAY)); - setDescriptionPartAtEnd(DESCRIPTION_TOKEN, description); + setDescriptionPart(DESCRIPTION_TOKEN, description); + } } @Override public ItemStack onClick() { int ind = options.lastIndexOf(value.getValue()); ind++; - if (ind == options.size()) + if (ind == options.size()) { ind = 0; + } value.setValue(options.get(ind)); updateDescription(); @@ -92,8 +103,9 @@ public ItemStack onClick() { public ItemStack onRightClick() { int ind = options.lastIndexOf(value.getValue()); ind--; - if (ind == -1) + if (ind == -1) { ind = options.size() - 1; + } value.setValue(options.get(ind)); updateDescription(); @@ -111,7 +123,6 @@ public ItemStack onDoubleClick() { MinigameMessageManager.sendMgMessage(mgPlayer, MinigameMessageType.INFO, MgMenuLangKey.MENU_LIST_ENTERCHAT, Placeholder.component(MinigamePlaceHolderKey.TYPE.getKey(), getName()), Placeholder.component(MinigamePlaceHolderKey.TIME.getKey(), MinigameUtils.convertTime(Duration.ofSeconds(reopenSeconds)))); - mgPlayer.setManualEntry(this); String optionsStr = String.join(", ", options.stream().map(Object::toString).toList()); if (optionsStr.length() > 8000) { @@ -120,7 +131,10 @@ public ItemStack onDoubleClick() { MinigameMessageManager.sendMgMessage(mgPlayer, MinigameMessageType.INFO, MgMenuLangKey.MENU_LIST_OPTION, Placeholder.unparsed(MinigamePlaceHolderKey.TEXT.getKey(), optionsStr)); } + + mgPlayer.setManualEntry(this); getContainer().startReopenTimer(reopenSeconds); + return null; } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemLong.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemLong.java index 05f9fb5ea..505cfd908 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemLong.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemLong.java @@ -62,7 +62,7 @@ public MenuItemLong(@Nullable Material displayMat, @Nullable Component name, @Nu } public void updateDescription() { - setDescriptionPartAtEnd(DESCRIPTION_TOKEN, List.of(Component.text(value.getValue(), NamedTextColor.GREEN))); + setDescriptionPart(DESCRIPTION_TOKEN, List.of(Component.text(value.getValue(), NamedTextColor.GREEN))); } @Override diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemMaterial.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemMaterial.java index 3cb006066..4d7bd1d63 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemMaterial.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemMaterial.java @@ -47,7 +47,7 @@ public ItemStack onShiftRightClick() { } public void updateDescription() { - setDescriptionPartAtEnd(DESCRIPTION_TOKEN, List.of( + setDescriptionPart(DESCRIPTION_TOKEN, List.of( MinigameMessageManager.getMgMessage(MgMenuLangKey.MENU_MATERIAL_DESCRIOPTION, Placeholder.component(MinigamePlaceHolderKey.MATERIAL.getKey(), Component.translatable(materialCallback.getValue().translationKey()))))); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemNewLine.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemNewLine.java index e695fb0ad..ada5be9c6 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemNewLine.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemNewLine.java @@ -1,12 +1,13 @@ package au.com.mineauz.minigames.menu; import net.kyori.adventure.text.Component; +import org.bukkit.Material; import org.bukkit.inventory.ItemStack; public class MenuItemNewLine extends MenuItem { public MenuItemNewLine() { - super(null, Component.text("NL")); // since it will never be visible anyway we can hardcode the name + super((Material) null, Component.text("NL")); // since it will never be visible anyway we can hardcode the name } @Override diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemRewardGroup.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemRewardGroup.java index 82a80b25e..6850f4886 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemRewardGroup.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemRewardGroup.java @@ -11,8 +11,8 @@ import au.com.mineauz.minigames.minigame.reward.Rewards; import au.com.mineauz.minigames.objects.MinigamePlayer; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -20,11 +20,11 @@ import java.time.Duration; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; public class MenuItemRewardGroup extends MenuItem { private final static String DESCRIPTION_TOKEN = "RewardGroup_description"; + private final static @NotNull List<@NotNull RewardRarity> options = List.of(RewardRarity.values()); private final @NotNull RewardGroup group; private final @NotNull Rewards rewards; @@ -46,8 +46,6 @@ public MenuItemRewardGroup(@Nullable Material displayMat, @Nullable Component na } public void updateDescription() { - List options = Arrays.asList(RewardRarity.values()); - int pos = options.indexOf(group.getRarity()); int before = pos - 1; int after = pos + 1; @@ -58,18 +56,25 @@ public void updateDescription() { after = 0; } - List description = new ArrayList<>(); + List description = new ArrayList<>(3); description.add(Component.text(options.get(before).toString(), NamedTextColor.GRAY)); description.add(Component.text(group.getRarity().toString(), NamedTextColor.GREEN)); description.add(Component.text(options.get(after).toString(), NamedTextColor.GRAY)); - setDescriptionPartAtEnd(DESCRIPTION_TOKEN, description); + setDescriptionPart(DESCRIPTION_TOKEN, description); } @Override public ItemStack onClick() { - group.setRarity(group.getRarity().getNextRarity()); + int ind = options.lastIndexOf(group.getRarity()); + ind++; + if (ind == options.size()) { + ind = 0; + } + + group.setRarity(options.get(ind)); + updateDescription(); return getDisplayItem(); @@ -77,7 +82,13 @@ public ItemStack onClick() { @Override public ItemStack onRightClick() { - group.setRarity(group.getRarity().getPreviousRarity()); + int ind = options.lastIndexOf(group.getRarity()); + ind--; + if (ind == -1) { + ind = options.size() - 1; + } + + group.setRarity(options.get(ind)); updateDescription(); return getDisplayItem(); @@ -116,7 +127,7 @@ public ItemStack onShiftRightClick() { } @Override - public ItemStack onDoubleClick() { + public ItemStack onShiftClick() { Menu rewardMenu = new Menu(5, getName(), getContainer().getViewer()); rewardMenu.setPreviousPage(getContainer()); @@ -126,12 +137,12 @@ public ItemStack onDoubleClick() { MinigameMessageManager.getMgMessage(MgMenuLangKey.MENU_REWARD_SAVE_NAME, Placeholder.component(MinigamePlaceHolderKey.REWARD.getKey(), getName())), rewardMenu.getPreviousPage()), 44); - List mi = new ArrayList<>(); + List menuItems = new ArrayList<>(group.getItems().size()); for (RewardType item : group.getItems()) { - mi.add(item.getMenuItem()); + menuItems.add(item.getMenuItem()); } - rewardMenu.addItems(mi); + rewardMenu.addItems(menuItems); rewardMenu.displayMenu(getContainer().getViewer()); return null; } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemRewardGroupAdd.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemRewardGroupAdd.java index 9b3943f42..55087a461 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemRewardGroupAdd.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemRewardGroupAdd.java @@ -1,5 +1,6 @@ package au.com.mineauz.minigames.menu; +import au.com.mineauz.minigames.MinigameUtils; import au.com.mineauz.minigames.managers.MinigameMessageManager; import au.com.mineauz.minigames.managers.language.MinigameMessageType; import au.com.mineauz.minigames.managers.language.MinigamePlaceHolderKey; @@ -16,6 +17,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.time.Duration; import java.util.List; public class MenuItemRewardGroupAdd extends MenuItem { @@ -43,7 +45,8 @@ public ItemStack onClick() { mgPlayer.setNoClose(true); mgPlayer.getPlayer().closeInventory(); final int reopenSeconds = 30; - MinigameMessageManager.sendMgMessage(mgPlayer, MinigameMessageType.INFO, MgMenuLangKey.MENU_REWARD_ENTERCHAT); + MinigameMessageManager.sendMgMessage(mgPlayer, MinigameMessageType.INFO, MgMenuLangKey.MENU_REWARD_ENTERCHAT, + Placeholder.component(MinigamePlaceHolderKey.TIME.getKey(), MinigameUtils.convertTime(Duration.ofSeconds(reopenSeconds)))); mgPlayer.setManualEntry(this); getContainer().startReopenTimer(reopenSeconds); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemPotion.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemStatusEffect.java similarity index 76% rename from Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemPotion.java rename to Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemStatusEffect.java index 41bf08659..d64665805 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemPotion.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemStatusEffect.java @@ -15,21 +15,21 @@ import java.util.ArrayList; import java.util.List; -public class MenuItemPotion extends MenuItem { +public class MenuItemStatusEffect extends MenuItem { private final static String DESCRIPTION_TOKEN = "Potion_description"; private final @NotNull PotionEffect eff; private final @NotNull PlayerLoadout loadout; - public MenuItemPotion(@Nullable Material displayMat, @Nullable Component name, @NotNull PotionEffect eff, - @NotNull PlayerLoadout loadout) { + public MenuItemStatusEffect(@Nullable Material displayMat, @Nullable Component name, @NotNull PotionEffect eff, + @NotNull PlayerLoadout loadout) { super(displayMat, name); this.eff = eff; this.loadout = loadout; updateDescription(); } - public MenuItemPotion(@Nullable Material displayMat, @Nullable Component name, @Nullable List<@NotNull Component> description, - @NotNull PotionEffect eff, @NotNull PlayerLoadout loadout) { + public MenuItemStatusEffect(@Nullable Material displayMat, @Nullable Component name, @Nullable List<@NotNull Component> description, + @NotNull PotionEffect eff, @NotNull PlayerLoadout loadout) { super(displayMat, name, description); this.eff = eff; this.loadout = loadout; @@ -38,19 +38,19 @@ public MenuItemPotion(@Nullable Material displayMat, @Nullable Component name, @ public void updateDescription() { List description = new ArrayList<>(); - description.add(MinigameMessageManager.getMgMessage(MgMenuLangKey.MENU_POTION_LEVEL, + description.add(MinigameMessageManager.getMgMessage(MgMenuLangKey.MENU_STATUSEFFECT_LEVEL, Placeholder.unparsed(MinigamePlaceHolderKey.NUMBER.getKey(), String.valueOf(eff.getAmplifier() + 1)))); if (eff.isInfinite()) { - description.add(MinigameMessageManager.getMgMessage(MgMenuLangKey.MENU_POTION_DURATION, + description.add(MinigameMessageManager.getMgMessage(MgMenuLangKey.MENU_STATUSEFFECT_DURATION, Placeholder.component(MinigamePlaceHolderKey.NUMBER.getKey(), MinigameMessageManager.getMgMessage(MgMenuLangKey.MENU_NUMBER_INFINITE)))); } else { - description.add(MinigameMessageManager.getMgMessage(MgMenuLangKey.MENU_POTION_DURATION, + description.add(MinigameMessageManager.getMgMessage(MgMenuLangKey.MENU_STATUSEFFECT_DURATION, Placeholder.unparsed(MinigamePlaceHolderKey.NUMBER.getKey(), String.valueOf(eff.getDuration())))); } - setDescriptionPartAtEnd(DESCRIPTION_TOKEN, description); + setDescriptionPart(DESCRIPTION_TOKEN, description); } @Override diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemPotionAdd.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemStatusEffectAdd.java similarity index 85% rename from Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemPotionAdd.java rename to Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemStatusEffectAdd.java index c1dc4c915..58dfb2263 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemPotionAdd.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemStatusEffectAdd.java @@ -23,21 +23,21 @@ import java.util.List; import java.util.concurrent.TimeUnit; -public class MenuItemPotionAdd extends MenuItem { +public class MenuItemStatusEffectAdd extends MenuItem { private final @NotNull PlayerLoadout loadout; - public MenuItemPotionAdd(@Nullable Material displayMat, @NotNull LangKey langKey, @NotNull PlayerLoadout loadout) { + public MenuItemStatusEffectAdd(@Nullable Material displayMat, @NotNull LangKey langKey, @NotNull PlayerLoadout loadout) { super(displayMat, langKey); this.loadout = loadout; } - public MenuItemPotionAdd(@Nullable Material displayMat, @Nullable Component name, @NotNull PlayerLoadout loadout) { + public MenuItemStatusEffectAdd(@Nullable Material displayMat, @Nullable Component name, @NotNull PlayerLoadout loadout) { super(displayMat, name); this.loadout = loadout; } - public MenuItemPotionAdd(@Nullable Material displayMat, @Nullable Component name, - @Nullable List<@NotNull Component> description, @NotNull PlayerLoadout loadout) { + public MenuItemStatusEffectAdd(@Nullable Material displayMat, @Nullable Component name, + @Nullable List<@NotNull Component> description, @NotNull PlayerLoadout loadout) { super(displayMat, name, description); this.loadout = loadout; } @@ -50,7 +50,7 @@ public ItemStack onClick() { // time for a player to write a valid potion into chat int reopenSeconds = 30; - MinigameMessageManager.sendMgMessage(mgPlayer, MinigameMessageType.INFO, MgMenuLangKey.MENU_POTIONADD_ENTERCHAT, + MinigameMessageManager.sendMgMessage(mgPlayer, MinigameMessageType.INFO, MgMenuLangKey.MENU_STATUSEFFECTADD_ENTERCHAT, Placeholder.component(MinigamePlaceHolderKey.TIME.getKey(), MinigameUtils.convertTime(Duration.ofSeconds(reopenSeconds)))); mgPlayer.setManualEntry(this); @@ -78,7 +78,7 @@ public void checkValidEntry(String entry) { PotionEffect peff = new PotionEffect(eff, dur.intValue(), level); for (int slot : getContainer().getUsedSlots()) { - if (getContainer().getMenuItem(slot) instanceof MenuItemPotion pot) { + if (getContainer().getMenuItem(slot) instanceof MenuItemStatusEffect pot) { if (pot.getEffect().getType() == peff.getType()) { pot.onShiftRightClick(); break; @@ -87,7 +87,7 @@ public void checkValidEntry(String entry) { } for (int i = 0; i < 36; i++) { if (!getContainer().hasMenuItem(i)) { - getContainer().addItem(new MenuItemPotion(Material.POTION, Component.text(eff.getName().toLowerCase().replace("_", " ")), des, peff, loadout), i); + getContainer().addItem(new MenuItemStatusEffect(Material.POTION, Component.text(eff.getName().toLowerCase().replace("_", " ")), des, peff, loadout), i); loadout.addPotionEffect(peff); break; } @@ -101,7 +101,7 @@ public void checkValidEntry(String entry) { Placeholder.unparsed(MinigamePlaceHolderKey.TEXT.getKey(), split[2])); } } else { - MinigameMessageManager.sendMgMessage(getContainer().getViewer(), MinigameMessageType.ERROR, MgCommandLangKey.COMMAND_ERROR_NOTPOTION, + MinigameMessageManager.sendMgMessage(getContainer().getViewer(), MinigameMessageType.ERROR, MgCommandLangKey.COMMAND_ERROR_NOTSTATUSEFFECT, Placeholder.unparsed(MinigamePlaceHolderKey.TEXT.getKey(), split[2])); } @@ -111,7 +111,7 @@ public void checkValidEntry(String entry) { getContainer().cancelReopenTimer(); getContainer().displayMenu(getContainer().getViewer()); - MinigameMessageManager.sendMgMessage(getContainer().getViewer(), MinigameMessageType.ERROR, MgMenuLangKey.MENU_POTIONADD_ERROR_SYNTAX); + MinigameMessageManager.sendMgMessage(getContainer().getViewer(), MinigameMessageType.ERROR, MgMenuLangKey.MENU_STATUSEFFECTADD_ERROR_SYNTAX); } } } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemString.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemString.java index 839a9087b..d1e43ab32 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemString.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemString.java @@ -1,5 +1,6 @@ package au.com.mineauz.minigames.menu; +import au.com.mineauz.minigames.MinigameUtils; import au.com.mineauz.minigames.managers.MinigameMessageManager; import au.com.mineauz.minigames.managers.language.MinigameMessageType; import au.com.mineauz.minigames.managers.language.MinigamePlaceHolderKey; @@ -14,6 +15,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.time.Duration; import java.util.List; public class MenuItemString extends MenuItem { @@ -54,11 +56,11 @@ public void setAllowNull(boolean allow) { public void updateDescription() { String setting = stringCallback.getValue(); if (setting == null) { - setDescriptionPartAtEnd(DESCRIPTION_TOKEN, List.of( + setDescriptionPart(DESCRIPTION_TOKEN, List.of( MinigameMessageManager.getMgMessage(MgMenuLangKey.MENU_ELEMENTNOTSET).color(NamedTextColor.GRAY))); } else if (setting.length() > 20) { setting = setting.substring(0, 17) + "..."; - setDescriptionPartAtEnd(DESCRIPTION_TOKEN, List.of(Component.text(setting, NamedTextColor.GREEN))); + setDescriptionPart(DESCRIPTION_TOKEN, List.of(Component.text(setting, NamedTextColor.GREEN))); } } @@ -67,14 +69,16 @@ public ItemStack onDoubleClick() { MinigamePlayer mgPlayer = getContainer().getViewer(); mgPlayer.setNoClose(true); mgPlayer.getPlayer().closeInventory(); + final int reopenSeconds = 20; MinigameMessageManager.sendMgMessage(mgPlayer, MinigameMessageType.INFO, MgMenuLangKey.MENU_STRING_ENTERCHAT, - Placeholder.component(MinigamePlaceHolderKey.TYPE.getKey(), getName())); + Placeholder.component(MinigamePlaceHolderKey.TYPE.getKey(), getName()), + Placeholder.component(MinigamePlaceHolderKey.TIME.getKey(), MinigameUtils.convertTime(Duration.ofSeconds(reopenSeconds)))); if (allowNull) { MinigameMessageManager.sendMgMessage(mgPlayer, MinigameMessageType.INFO, MgMenuLangKey.MENU_STRING_ALLOWNULL, Placeholder.component(MinigamePlaceHolderKey.TYPE.getKey(), getName())); } mgPlayer.setManualEntry(this); - getContainer().startReopenTimer(20); + getContainer().startReopenTimer(reopenSeconds); return null; } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemTeam.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemTeam.java index 04d71821a..99158afcc 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemTeam.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemTeam.java @@ -22,7 +22,7 @@ public class MenuItemTeam extends MenuItem { public MenuItemTeam(@Nullable Component name, @NotNull Team team) { super(Material.LEATHER_CHESTPLATE, name); - setDescriptionPartAtEnd(DESCRIPTION_TOKEN, MinigameMessageManager.getMgMessageList(MgMenuLangKey.MENU_DELETE_RIGHTCLICK)); + setDescriptionPart(DESCRIPTION_TOKEN, MinigameMessageManager.getMgMessageList(MgMenuLangKey.MENU_DELETE_RIGHTCLICK)); this.team = team; setTeamIcon(); } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemTime.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemTime.java index 37cd6a618..7e9ad8d39 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemTime.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuItemTime.java @@ -32,6 +32,6 @@ public MenuItemTime(@Nullable Material displayMat, @Nullable Component name, @Nu @Override public void updateDescription() { Component timeComponent = MinigameUtils.convertTime(Duration.ofMillis(value.getValue()), true).color(NamedTextColor.GREEN); - setDescriptionPartAtEnd(DESCRIPTION_TOKEN, List.of(timeComponent)); + setDescriptionPart(DESCRIPTION_TOKEN, List.of(timeComponent)); } } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuUtility.java b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuUtility.java index 4ef1b13f3..df55a73d8 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuUtility.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/menu/MenuUtility.java @@ -14,7 +14,7 @@ public class MenuUtility { } public static @NotNull Material getSaveMaterial() { - return Material.REDSTONE_TORCH; + return Material.GREEN_BED; } public static @NotNull Material getCreateMaterial() { diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/Minigame.java b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/Minigame.java index 054673d65..645801611 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/Minigame.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/Minigame.java @@ -1286,7 +1286,7 @@ public void setValue(FloorDegenerator.DegeneratorType value) { if (!playerLoadout.getItemSlots().isEmpty()) { material = playerLoadout.getItem((Integer) playerLoadout.getItemSlots().toArray()[0]).getType(); } - if (playerLoadout.isDeleteable()) { + if (playerLoadout.isDeletable()) { mi.add(new MenuItemDisplayLoadout(material, playerLoadout.getDisplayName(), MinigameMessageManager.getMgMessageList(MgMenuLangKey.MENU_DELETE_SHIFTRIGHTCLICK), playerLoadout, this)); } else { diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/modules/LoadoutModule.java b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/modules/LoadoutModule.java index 2c10f8331..6fa774210 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/modules/LoadoutModule.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/modules/LoadoutModule.java @@ -33,7 +33,7 @@ public class LoadoutModule extends MinigameModule { public LoadoutModule(@NotNull Minigame mgm, @NotNull String name) { super(mgm, name); PlayerLoadout def = new PlayerLoadout("default"); - def.setDeleteable(false); + def.setDeletable(false); extraLoadouts.put("default", def); } @@ -97,12 +97,13 @@ public void save(FileConfiguration config) { @Override public void load(FileConfiguration config) { - //TODO: Remove entire load after 1.7 + //TODO: Remove entire load after 1.7 <-- figure out if it's save to do so, I believe the loadouts handle loading themselves if (config.contains(getMinigame() + ".loadout")) { Set keys = config.getConfigurationSection(getMinigame() + ".loadout").getKeys(false); for (String key : keys) { - if (key.matches("[-]?[0-9]+")) + if (key.matches("[-]?[0-9]+")) { getLoadout("default").addItem(config.getItemStack(getMinigame() + ".loadout." + key), Integer.parseInt(key)); + } } if (config.contains(getMinigame() + ".loadout.potions")) { keys = config.getConfigurationSection(getMinigame() + ".loadout.potions").getKeys(false); @@ -231,7 +232,8 @@ public void displaySelectionMenu(final MinigamePlayer mgPlayer, final boolean eq mgPlayer.setLoadout(loadout); mgPlayer.getPlayer().closeInventory(); if (!equip) { - MinigameMessageManager.sendMgMessage(mgPlayer, MinigameMessageType.INFO, MinigameLangKey.PLAYER_LOADOUT_NEXTRESPAWN); + MinigameMessageManager.sendMgMessage(mgPlayer, MinigameMessageType.INFO, MinigameLangKey.PLAYER_LOADOUT_NEXTRESPAWN, + Placeholder.component(MinigamePlaceHolderKey.LOADOUT.getKey(), loadout.getDisplayName())); } else { MinigameMessageManager.sendMgMessage(mgPlayer, MinigameMessageType.INFO, MinigameLangKey.PLAYER_LOADOUT_EQUIPPED, Placeholder.component(MinigamePlaceHolderKey.LOADOUT.getKey(), loadout.getDisplayName())); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/modules/TeamsModule.java b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/modules/TeamsModule.java index b029bc448..7d2f0c358 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/modules/TeamsModule.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/modules/TeamsModule.java @@ -219,9 +219,14 @@ public void addEditMenuOptions(Menu previousMenu) { Menu menu = new Menu(6, MgMenuLangKey.MENU_TEAM_NAME, previousMenu.getViewer()); menu.setPreviousPage(previousMenu); List menuItems = new ArrayList<>(); + + List teamColors = new ArrayList<>(teams.keySet()); + teamColors.add(TeamColor.NONE); menuItems.add(new MenuItemList<>(Material.PAPER, MgMenuLangKey.MENU_TEAM_DEFAULTWIN_NAME, - getDefaultWinnerCallback(), List.of(TeamColor.values()))); + getDefaultWinnerCallback(), teamColors)); + menuItems.add(new MenuItemNewLine()); + for (Team team : this.teams.values()) { menuItems.add(new MenuItemTeam(team.getColoredDisplayName(), team)); } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/CommandReward.java b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/CommandReward.java index 44093eb44..04572aaa4 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/CommandReward.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/CommandReward.java @@ -1,13 +1,15 @@ package au.com.mineauz.minigames.minigame.reward; +import au.com.mineauz.minigames.MinigameUtils; import au.com.mineauz.minigames.managers.MinigameMessageManager; +import au.com.mineauz.minigames.managers.language.MinigameMessageType; +import au.com.mineauz.minigames.managers.language.MinigamePlaceHolderKey; import au.com.mineauz.minigames.managers.language.langkeys.MgMenuLangKey; -import au.com.mineauz.minigames.menu.Callback; import au.com.mineauz.minigames.menu.MenuItem; -import au.com.mineauz.minigames.menu.MenuItemString; import au.com.mineauz.minigames.objects.MinigamePlayer; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; @@ -15,8 +17,8 @@ import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; +import java.time.Duration; import java.util.ArrayList; -import java.util.Collections; import java.util.List; public class CommandReward extends RewardType { @@ -62,27 +64,13 @@ public void loadReward(String path, ConfigurationSection config) { command = config.getString(path); } - private class CommandRewardItem extends MenuItemString { + private class CommandRewardItem extends MenuItem { + private final static @NotNull List<@NotNull RewardRarity> options = List.of(RewardRarity.values()); private final CommandReward reward; - private final @NotNull List<@NotNull RewardRarity> options = new ArrayList<>(); public CommandRewardItem(CommandReward reward) { - super(Material.COMMAND_BLOCK, Component.text("/" + command), new Callback<>() { - - @Override - public String getValue() { - return command; - } - - @Override - public void setValue(String value) { - if (value.startsWith("./")) - value = value.replace("./", "/"); - command = value; - } - }); - - Collections.addAll(options, RewardRarity.values()); + super(Material.COMMAND_BLOCK, Component.text("/" + command)); + this.reward = reward; updateDescription(); } @@ -97,9 +85,7 @@ public void updateName(String newName) { getDisplayItem().setItemMeta(meta); } - @Override public void updateDescription() { - List description; int pos = options.indexOf(getRarity()); int before = pos - 1; int after = pos + 1; @@ -110,27 +96,23 @@ public void updateDescription() { after = 0; } - description = new ArrayList<>(); + List description = new ArrayList<>(5); description.add(options.get(before).getDisplayName().color(NamedTextColor.GRAY)); description.add(getRarity().getDisplayName().color(NamedTextColor.GREEN)); description.add(options.get(after).getDisplayName().color(NamedTextColor.GRAY)); description.add(MinigameMessageManager.getMgMessage(MgMenuLangKey.MENU_EDIT_SHIFTLEFT).color(NamedTextColor.DARK_PURPLE)); description.addAll(MinigameMessageManager.getMgMessageList(MgMenuLangKey.MENU_DELETE_SHIFTRIGHTCLICK)); - setDescriptionPartAtEnd(DESCRIPTION_TOKEN, description); - } - - @Override - public ItemStack onDoubleClick() { - return getDisplayItem(); + setDescriptionPart(DESCRIPTION_TOKEN, description); } @Override public ItemStack onClick() { int ind = options.lastIndexOf(getRarity()); ind++; - if (ind == options.size()) + if (ind == options.size()) { ind = 0; + } setRarity(options.get(ind)); updateDescription(); @@ -161,13 +143,31 @@ public ItemStack onShiftRightClick() { @Override public ItemStack onShiftClick() { - super.onDoubleClick(); + MinigamePlayer mgPlayer = getContainer().getViewer(); + mgPlayer.setNoClose(true); + mgPlayer.getPlayer().closeInventory(); + final int reopenSeconds = 40; + MinigameMessageManager.sendMgMessage(mgPlayer, MinigameMessageType.INFO, MgMenuLangKey.MENU_STRING_ENTERCHAT, + Placeholder.component(MinigamePlaceHolderKey.TYPE.getKey(), getName()), + Placeholder.component(MinigamePlaceHolderKey.TIME.getKey(), MinigameUtils.convertTime(Duration.ofSeconds(reopenSeconds)))); + + mgPlayer.setManualEntry(this); + getContainer().startReopenTimer(reopenSeconds); + return null; } @Override public void checkValidEntry(String entry) { - super.checkValidEntry(entry); + if (entry.startsWith("./")) { + entry = entry.replace("./", "/"); + } + command = entry; + + updateDescription(); + getContainer().cancelReopenTimer(); + getContainer().displayMenu(getContainer().getViewer()); + updateName(entry); } } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/ItemReward.java b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/ItemReward.java index 5fb821ed9..ca986d0fb 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/ItemReward.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/ItemReward.java @@ -5,9 +5,7 @@ import au.com.mineauz.minigames.managers.language.MinigamePlaceHolderKey; import au.com.mineauz.minigames.managers.language.langkeys.MgMenuLangKey; import au.com.mineauz.minigames.managers.language.langkeys.MinigameLangKey; -import au.com.mineauz.minigames.menu.Callback; import au.com.mineauz.minigames.menu.MenuItem; -import au.com.mineauz.minigames.menu.MenuItemItemNbt; import au.com.mineauz.minigames.objects.MinigamePlayer; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -15,10 +13,10 @@ import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -82,82 +80,82 @@ public void setRewardItem(ItemStack item) { this.item = item; } - private class MenuItemReward extends MenuItemItemNbt { - private final static String DESCRIPTION_TOKEN = "Reward_description"; + private class MenuItemReward extends MenuItem { + private final static String DESCRIPTION_REWARD_TOKEN = "Reward_description"; private final @NotNull ItemReward reward; - private final @NotNull List options; + private final @NotNull List rarities; public MenuItemReward(@NotNull ItemReward reward) { - super(Material.DIAMOND, Component.translatable(Material.DIAMOND.translationKey()), new Callback<>() { - @Override - public ItemStack getValue() { - return item; - } - - @Override - public void setValue(ItemStack value) { - item = value; - } - }); - setDisplayItem(reward.getRewardItem()); - options = Arrays.asList(RewardRarity.values()); + super(reward.item.clone(), reward.item.getItemMeta().displayName()); + + rarities = List.of(RewardRarity.values()); this.reward = reward; - updateDescription(); - } + updateDescriptionRarity(); + } @Override - public ItemStack onClickWithItem(ItemStack item) { + public ItemStack onClickWithItem(@NotNull ItemStack item) { setRewardItem(item.clone()); - return super.onClickWithItem(item); + setDisplayItem(item); + + // update lore + updateDescriptionRarity(); + + // update display name + ItemMeta meta = super.getDisplayItem().getItemMeta(); + meta.displayName(item.getItemMeta().displayName()); + super.getDisplayItem().setItemMeta(meta); + + return super.getDisplayItem(); } - public void updateDescription() { + public void updateDescriptionRarity() { List description; - int pos = options.indexOf(getRarity()); + int pos = rarities.indexOf(getRarity()); int before = pos - 1; int after = pos + 1; if (before == -1) { - before = options.size() - 1; + before = rarities.size() - 1; } - if (after == options.size()) { + if (after == rarities.size()) { after = 0; } description = new ArrayList<>(); - description.add(options.get(before).getDisplayName().color(NamedTextColor.GRAY)); + description.add(rarities.get(before).getDisplayName().color(NamedTextColor.GRAY)); description.add(getRarity().getDisplayName().color(NamedTextColor.GREEN)); - description.add(options.get(after).getDisplayName().color(NamedTextColor.GRAY)); + description.add(rarities.get(after).getDisplayName().color(NamedTextColor.GRAY)); description.add(MinigameMessageManager.getMgMessage( MgMenuLangKey.MENU_DELETE_SHIFTRIGHTCLICK).color(NamedTextColor.DARK_PURPLE)); - setDescriptionPartAtEnd(DESCRIPTION_TOKEN, description); + setDescriptionPartAtIndex(DESCRIPTION_REWARD_TOKEN, 0, description); } @Override public ItemStack onClick() { - int ind = options.lastIndexOf(getRarity()); + int ind = rarities.lastIndexOf(getRarity()); ind++; - if (ind == options.size()) { + if (ind == rarities.size()) { ind = 0; } - setRarity(options.get(ind)); - updateDescription(); + setRarity(rarities.get(ind)); + updateDescriptionRarity(); return getDisplayItem(); } @Override public ItemStack onRightClick() { - int ind = options.lastIndexOf(getRarity()); + int ind = rarities.lastIndexOf(getRarity()); ind--; if (ind == -1) { - ind = options.size() - 1; + ind = rarities.size() - 1; } - setRarity(options.get(ind)); - updateDescription(); + setRarity(rarities.get(ind)); + updateDescriptionRarity(); return getDisplayItem(); } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/MoneyReward.java b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/MoneyReward.java index 4eccca2b1..e5b72b8d1 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/MoneyReward.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/MoneyReward.java @@ -110,7 +110,7 @@ public void updateDescription() { description.add(MinigameMessageManager.getMgMessage(MgMenuLangKey.MENU_CHANGE_SHIFTCLICK).color(NamedTextColor.DARK_PURPLE)); description.add(MinigameMessageManager.getMgMessage(MgMenuLangKey.MENU_DELETE_SHIFTRIGHTCLICK).color(NamedTextColor.DARK_PURPLE)); - setDescriptionPartAtEnd(DESCRIPTION_TOKEN, description); + setDescriptionPart(DESCRIPTION_TOKEN, description); } @Override diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/RewardRarity.java b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/RewardRarity.java index f80419b31..2d7555823 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/RewardRarity.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/RewardRarity.java @@ -38,22 +38,27 @@ public double getRarity() { return rarity; } - public @NotNull RewardRarity getPreviousRarity() { + /** + * get the next highest rarity or itself if it already is the highest one + */ + public @NotNull RewardRarity getHigherRarity() { return switch (this) { case VERY_COMMON -> COMMON; case COMMON -> NORMAL; case NORMAL -> RARE; - default -> VERY_RARE; + case RARE, VERY_RARE -> VERY_RARE; }; - } - public @NotNull RewardRarity getNextRarity() { + /** + * get the next lowest rarity or itself if it already is the lowest one + */ + public @NotNull RewardRarity getLowerRarity() { return switch (this) { case VERY_RARE -> RARE; case RARE -> NORMAL; case NORMAL -> COMMON; - default -> VERY_COMMON; + case COMMON, VERY_COMMON -> VERY_COMMON; }; } diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/Rewards.java b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/Rewards.java index f1598f6ab..40ceae26f 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/Rewards.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/Rewards.java @@ -13,6 +13,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.concurrent.ThreadLocalRandom; public class Rewards { @@ -24,33 +25,33 @@ public boolean isEmpty() { } public List getReward() { - double rand = Math.random(); + double rand = ThreadLocalRandom.current().nextDouble(); RewardRarity rarity; - List itemsCopy = new ArrayList<>(); - itemsCopy.addAll(items); - itemsCopy.addAll(groups); - Collections.shuffle(itemsCopy); + List itemsCopyList = new ArrayList<>(); + itemsCopyList.addAll(items); + itemsCopyList.addAll(groups); + Collections.shuffle(itemsCopyList); - if (rand > RewardRarity.VERY_COMMON.getRarity()) + if (rand > RewardRarity.VERY_COMMON.getRarity()) { rarity = RewardRarity.VERY_COMMON; - else if (rand > RewardRarity.COMMON.getRarity()) + } else if (rand > RewardRarity.COMMON.getRarity()) { rarity = RewardRarity.COMMON; - else if (rand > RewardRarity.NORMAL.getRarity()) + } else if (rand > RewardRarity.NORMAL.getRarity()) { rarity = RewardRarity.NORMAL; - else if (rand > RewardRarity.RARE.getRarity()) + } else if (rand > RewardRarity.RARE.getRarity()) { rarity = RewardRarity.RARE; - else + } else { rarity = RewardRarity.VERY_RARE; + } - - if (!itemsCopy.isEmpty()) { + if (!itemsCopyList.isEmpty()) { RewardType item = null; RewardGroup group = null; - RewardRarity orarity = rarity; - boolean up = true; + final RewardRarity originalRarity = rarity; + boolean up = false; while (item == null && group == null) { - for (Object ritem : itemsCopy) { + for (Object ritem : itemsCopyList) { if (ritem instanceof RewardType ri) { if (ri.getRarity() == rarity) { item = ri; @@ -65,21 +66,22 @@ else if (rand > RewardRarity.RARE.getRarity()) } } - if (rarity == RewardRarity.VERY_COMMON) { - rarity = orarity; - up = false; + // nothing in the list with the same rarity + // only go up if there is no way further down + if (rarity == RewardRarity.VERY_COMMON && !up) { + rarity = originalRarity; + up = true; } - if (up) - rarity = rarity.getNextRarity(); - else { - rarity = rarity.getPreviousRarity(); + if (up) { + rarity = rarity.getHigherRarity(); + } else { + rarity = rarity.getLowerRarity(); } } + if (item != null) { - List items = new ArrayList<>(); - items.add(item); - return items; + return List.of(item); } else { return group.getItems(); } @@ -132,7 +134,7 @@ public Menu createMenu(Component name, MinigamePlayer player, Menu parent) { mi.add(item.getMenuItem()); } - List des = MinigameMessageManager.getMgMessageList(MgMenuLangKey.MENU_EDIT_DOUBLECLICK); + List des = MinigameMessageManager.getMgMessageList(MgMenuLangKey.MENU_EDIT_SHIFTLEFT); for (RewardGroup group : groups) { MenuItemRewardGroup rwg = new MenuItemRewardGroup(Material.CHEST, MinigameMessageManager.getMgMessage(MgMenuLangKey.MENU_REWARD_GROUP_NAME, diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/scheme/HierarchyRewardScheme.java b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/scheme/HierarchyRewardScheme.java index 4e45faf54..57b7a7db9 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/scheme/HierarchyRewardScheme.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/minigame/reward/scheme/HierarchyRewardScheme.java @@ -233,7 +233,7 @@ private void updateDescription() { MinigameMessageManager.getMgMessage(MgMenuLangKey.MENU_DELETE_SHIFTRIGHTCLICK) ); - setDescriptionPartAtEnd(DESCRIPTION_TOKEN, description); + setDescriptionPart(DESCRIPTION_TOKEN, description); // Update name ItemStack item = getDisplayItem(); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/objects/IndexedMap.java b/Minigames/src/main/java/au/com/mineauz/minigames/objects/IndexedMap.java deleted file mode 100644 index ea5f013e8..000000000 --- a/Minigames/src/main/java/au/com/mineauz/minigames/objects/IndexedMap.java +++ /dev/null @@ -1,85 +0,0 @@ -package au.com.mineauz.minigames.objects; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -/** - * An ordered map, where every key value pair is linked to an index - * Keep in mind that it does not override any of the complex methods, they have to get coded if needed! - */ -public class IndexedMap extends HashMap implements Map { - private final @NotNull LinkedList<@Nullable K> keyList = new LinkedList<>(); - - @Override - public V put(K key, V value) { - if (!keyList.contains(key)) { - keyList.add(key); - } - return super.put(key, value); - } - - @Override - public void putAll(Map m) { - for (Map.Entry entry : m.entrySet()) { - put(entry.getKey(), entry.getValue()); - } - } - - @Override - public V remove(Object key) { - keyList.remove(key); - - return super.remove(key); - } - - @Override - public void clear() { - keyList.clear(); - super.clear(); - } - - public @NotNull List<@Nullable K> getKeys() { - return keyList; - } - - /** - * Returns the index of the occurrence of the specified key in this map, - * or -1 if this list does not contain the element. - * - * @param key – element to search for - * @return the index of the occurrence of the specified key in this list, or -1 if this map does not contain the key - */ - public int getKeyIndex(K key) { - return keyList.indexOf(key); - } - - public @Nullable K getKeyAt(int index) { - if (keyList.size() > index && index >= 0) { - return keyList.get(index); - } - return null; - } - - public @Nullable V getValueAt(int index) { - K key = getKeyAt(index); - if (key != null) { - return get(key); - } - return null; - } - - public @Nullable V removeIndex(int index) { - K key = getKeyAt(index); - - if (key != null) { - return remove(key); - } else { - return null; - } - } -} diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/objects/ResourcePack.java b/Minigames/src/main/java/au/com/mineauz/minigames/objects/ResourcePack.java index 2ab43f4f0..c788c971e 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/objects/ResourcePack.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/objects/ResourcePack.java @@ -296,7 +296,7 @@ public URL getUrl() { @Override public @NotNull Map serialize() { final Map result = new HashMap<>(); - result.put("name", this.displayName); + result.put("name", MiniMessage.miniMessage().serialize(this.displayName)); result.put("url", this.url.toString()); result.put("description", this.description); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/objects/StrIntMapPersistentDataType.java b/Minigames/src/main/java/au/com/mineauz/minigames/objects/StrIntMapPersistentDataType.java deleted file mode 100644 index b2a804458..000000000 --- a/Minigames/src/main/java/au/com/mineauz/minigames/objects/StrIntMapPersistentDataType.java +++ /dev/null @@ -1,37 +0,0 @@ -package au.com.mineauz.minigames.objects; - -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import org.bukkit.persistence.PersistentDataAdapterContext; -import org.bukkit.persistence.PersistentDataType; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Type; -import java.util.LinkedHashMap; - -public class StrIntMapPersistentDataType implements PersistentDataType> { - private final Type MAP_TYPE = new TypeToken>() { - }.getType(); - private final Gson GSON = new Gson(); - - @Override - public @NotNull Class getPrimitiveType() { - return String.class; - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - @Override - public @NotNull Class> getComplexType() { - return (Class>) ((Class) LinkedHashMap.class); - } - - @Override - public @NotNull String toPrimitive(@NotNull IndexedMap complex, @NotNull PersistentDataAdapterContext context) { - return GSON.toJson(complex, MAP_TYPE); - } - - @Override - public @NotNull IndexedMap fromPrimitive(@NotNull String primitive, @NotNull PersistentDataAdapterContext context) { - return GSON.fromJson(primitive, MAP_TYPE); - } -} diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/signs/LoadoutSign.java b/Minigames/src/main/java/au/com/mineauz/minigames/signs/LoadoutSign.java index a64f7cfeb..96b475c2d 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/signs/LoadoutSign.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/signs/LoadoutSign.java @@ -78,7 +78,8 @@ public boolean signUse(@NotNull Sign sign, @NotNull MinigamePlayer mgPlayer) { if (mgm.getType() == MinigameType.SINGLEPLAYER || mgm.hasStarted()) { if (sign.getSide(Side.FRONT).getLine(3).equalsIgnoreCase("respawn")) { - MinigameMessageManager.sendMgMessage(mgPlayer, MinigameMessageType.INFO, MinigameLangKey.PLAYER_LOADOUT_NEXTRESPAWN); + MinigameMessageManager.sendMgMessage(mgPlayer, MinigameMessageType.INFO, MinigameLangKey.PLAYER_LOADOUT_NEXTRESPAWN, + Placeholder.component(MinigamePlaceHolderKey.LOADOUT.getKey(), loadout.getDisplayName())); } else if (sign.getSide(Side.FRONT).getLine(3).equalsIgnoreCase("temporary")) { MinigameMessageManager.sendMgMessage(mgPlayer, MinigameMessageType.INFO, MinigameLangKey.PLAYER_LOADOUT_TEMPORARILY); loadout.equipLoadout(mgPlayer); diff --git a/Minigames/src/main/java/au/com/mineauz/minigames/signs/RewardSign.java b/Minigames/src/main/java/au/com/mineauz/minigames/signs/RewardSign.java index eb60829e0..01f380884 100644 --- a/Minigames/src/main/java/au/com/mineauz/minigames/signs/RewardSign.java +++ b/Minigames/src/main/java/au/com/mineauz/minigames/signs/RewardSign.java @@ -113,7 +113,7 @@ public boolean signUse(@NotNull Sign sign, @NotNull MinigamePlayer mgPlayer) { menuItems.add(item.getMenuItem()); } - List des = MinigameMessageManager.getMgMessageList(MgMenuLangKey.MENU_EDIT_DOUBLECLICK); + List des = MinigameMessageManager.getMgMessageList(MgMenuLangKey.MENU_EDIT_SHIFTLEFT); for (RewardGroup group : rew.getGroups()) { MenuItemRewardGroup rwg = new MenuItemRewardGroup(Material.CHEST, MinigameMessageManager.getMgMessage(MgMenuLangKey.MENU_REWARD_GROUP_NAME, diff --git a/Minigames/src/main/resources/messages.properties b/Minigames/src/main/resources/messages.properties index c54e87003..f089def53 100644 --- a/Minigames/src/main/resources/messages.properties +++ b/Minigames/src/main/resources/messages.properties @@ -54,7 +54,7 @@ command.error.notInMinigame.self=You are not in a minigame! command.error.notMaterial= is not a valid material! command.error.notNumber= is not a number! command.error.notPlayer=No player found by the name ! -command.error.notPotion= is not a valid potion name! +command.error.notStatusEffect= is not a valid effect name! command.error.notTeam=There is no team assigned to . command.error.notTime= is not a valid time, value must be a number! command.error.playerNotInMinigame= is not playing a Minigame! @@ -417,6 +417,7 @@ menu.ctf.capturePoint.name=CTF Flag is Capture Point menu.ctf.flagBackManually.description=If enabled, the flag can be broughtback to the base manually menu.ctf.flagBackManually.name=Bring Flag Back Manually menu.ctf.name=CTF Settings +#todo duplicate menu.defaultWinningTeam.name=Default Winning Team menu.delete.RightClick=(Right Click to delete) menu.delete.ShiftRightClick=Shift + Right Click to Delete @@ -439,11 +440,9 @@ menu.displayLoadout.usePermissions.name=Use Permissions menu.displayLoadout.xpLevel.description=Use -1 to notuse loadout levels menu.displayLoadout.xpLevel.name=XP Level menu.displayName.name=Display Name -menu.edit.doubleClick=Double Click to edit menu.edit.shiftLeft=Shift + Left Click to change menu.effects.save.name=Save effects menu.elementNotSet=Not Set -menu.enum.error=*ERROR* menu.executor.action=Actions: menu.executor.edit=(Left click to edit) menu.executor.trigger=Trigger: @@ -465,6 +464,7 @@ menu.infected.percent.name=Infected Percent menu.infected.team.infected.name=Infected Team menu.infected.team.survivor.name=Survivor Team menu.invert.name=Invert +menu.iterable.error.unknown=*ERROR* menu.list.enterChat=Enter the name of the option into chat for , the menu will automatically reopen in