Skip to content

Commit

Permalink
lang 15 rework
Browse files Browse the repository at this point in the history
Menus start
  • Loading branch information
FireInstall committed Feb 6, 2024
1 parent 72241b1 commit e2739ff
Show file tree
Hide file tree
Showing 71 changed files with 759 additions and 458 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class MinigameUtils {
* using the same time unit more than once is permitted.
* If no time unit follows a number, it gets treated as seconds.
*
* @return the parsed duration, or null if not possible
* @return the parsed duration in milliseconds, or null if not possible
*/
public static @Nullable Long parsePeriod(@NotNull String periodStr) {
Matcher matcher = PERIOD_PATTERN.matcher(periodStr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public boolean onCommand(final @NotNull CommandSender sender, @NotNull String @N
if (field == null) {
MinigameMessageManager.sendMgMessage(sender, MinigameMessageType.ERROR, MgCommandLangKey.COMMAND_SCOREBOARD_ERROR_NOTFIELD,
Placeholder.unparsed(MinigamePlaceHolderKey.TEXT.getKey(), args[2]),
Placeholder.unparsed(MinigamePlaceHolderKey.SCORE.getKey(), stat.getDisplayName()));
Placeholder.component(MinigamePlaceHolderKey.SCORE.getKey(), stat.getDisplayName()));
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Minigame miniga
Placeholder.unparsed(MinigamePlaceHolderKey.MINIGAME.getKey(), minigame.getName(false)),
Placeholder.unparsed(MinigamePlaceHolderKey.NUMBER.getKey(), String.valueOf(val)));
} else {
MinigameMessageManager.sendMgMessage(sender, MinigameMessageType.INFO, MgCommandLangKey.COMMAND_ERROR_RANGE,
MinigameMessageManager.sendMgMessage(sender, MinigameMessageType.INFO, MgCommandLangKey.COMMAND_ERROR_OUTOFBOUNDS,
Placeholder.unparsed(MinigamePlaceHolderKey.MIN.getKey(), "1"),
Placeholder.unparsed(MinigamePlaceHolderKey.MAX.getKey(), "99"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Minigame miniga
}

} else { // not valid number
MinigameMessageManager.sendMgMessage(sender, MinigameMessageType.ERROR, MgCommandLangKey.COMMAND_ERROR_RANGE,
MinigameMessageManager.sendMgMessage(sender, MinigameMessageType.ERROR, MgCommandLangKey.COMMAND_ERROR_OUTOFBOUNDS,
Placeholder.unparsed(MinigamePlaceHolderKey.MIN.getKey(), "0"),
Placeholder.unparsed(MinigamePlaceHolderKey.MAX.getKey(), String.valueOf(Integer.MAX_VALUE)));
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package au.com.mineauz.minigames.config;

import au.com.mineauz.minigames.managers.language.langkeys.LangKey;
import au.com.mineauz.minigames.menu.Callback;
import au.com.mineauz.minigames.menu.MenuItem;
import au.com.mineauz.minigames.menu.MenuItemBoolean;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

Expand All @@ -31,8 +34,8 @@ public void loadValue(String path, FileConfiguration config) {
}

@Override
public MenuItem getMenuItem(Component name, Material displayItem) {
return new MenuItemBoolean(name, displayItem, new Callback<>() {
public MenuItem getMenuItem(@NotNull LangKey langKey, @Nullable Material displayMaterial) {
return new MenuItemBoolean(langKey, displayMaterial, new Callback<>() {

@Override
public Boolean getValue() {
Expand All @@ -43,14 +46,18 @@ public Boolean getValue() {
public void setValue(Boolean value) {
setFlag(value);
}


});
}

@Override
public MenuItem getMenuItem(Component name, Material displayItem, List<Component> description) {
return new MenuItemBoolean(name, description, displayItem, new Callback<>() {
public MenuItem getMenuItem(@Nullable Component name, @Nullable Material displayMaterial) {
return getMenuItem(name, displayMaterial, null);
}

@Override
public MenuItem getMenuItem(@Nullable Component name, @Nullable Material displayMaterial,
@Nullable List<@NotNull Component> description) {
return new MenuItemBoolean(name, description, displayMaterial, new Callback<>() {

@Override
public Boolean getValue() {
Expand All @@ -61,9 +68,6 @@ public Boolean getValue() {
public void setValue(Boolean value) {
setFlag(value);
}


});
}

}
12 changes: 10 additions & 2 deletions Minigames/src/main/java/au/com/mineauz/minigames/config/Flag.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package au.com.mineauz.minigames.config;

import au.com.mineauz.minigames.managers.MinigameMessageManager;
import au.com.mineauz.minigames.managers.language.langkeys.LangKey;
import au.com.mineauz.minigames.menu.Callback;
import au.com.mineauz.minigames.menu.MenuItem;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

Expand Down Expand Up @@ -56,7 +60,11 @@ public void setValue(T value) {

public abstract void loadValue(String path, FileConfiguration config);

public abstract MenuItem getMenuItem(Component name, Material displayItem);
public MenuItem getMenuItem(@NotNull LangKey langKey, @Nullable Material displayMaterial) {
return getMenuItem(MinigameMessageManager.getMgMessage(langKey), displayMaterial);
}

public abstract MenuItem getMenuItem(@Nullable Component name, @Nullable Material displayMaterial);

public abstract MenuItem getMenuItem(Component name, Material displayItem, List<Component> description);
public abstract MenuItem getMenuItem(@Nullable Component name, @Nullable Material displayItem, @Nullable List<@NotNull Component> description);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import au.com.mineauz.minigames.menu.Callback;
import au.com.mineauz.minigames.menu.MenuItem;
import au.com.mineauz.minigames.menu.MenuItemDecimal;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

Expand All @@ -27,62 +30,25 @@ public void loadValue(String path, FileConfiguration config) {
}

@Override
public MenuItem getMenuItem(String name, Material displayItem) {
return new MenuItemDecimal(name, displayItem, new Callback<>() {

@Override
public Double getValue() {
return getFlag().doubleValue();
}

@Override
public void setValue(Double value) {
setFlag(value.floatValue());
}


}, 1d, 1d, 0d, Double.POSITIVE_INFINITY);
public MenuItem getMenuItem(@Nullable Component name, @Nullable Material displayMat) {
return this.getMenuItem(name, displayMat, null);
}

@Override
public MenuItem getMenuItem(String name, Material displayItem,
List<String> description) {
return new MenuItemDecimal(name, description, displayItem, new Callback<>() {

@Override
public Double getValue() {
return getFlag().doubleValue();
}

@Override
public void setValue(Double value) {
setFlag(value.floatValue());
}


}, 1d, 1d, 0d, Double.POSITIVE_INFINITY);
public MenuItem getMenuItem(@Nullable Component name, @Nullable Material displayMat,
@Nullable List<@NotNull Component> description) {
return this.getMenuItem(name, displayMat, description, 1d, 1d, 0d, Double.POSITIVE_INFINITY);
}

public MenuItem getMenuItem(String name, Material displayItem, double lowerinc, double upperinc, Double min, Double max) {
return new MenuItemDecimal(name, displayItem, new Callback<>() {

@Override
public Double getValue() {
return getFlag().doubleValue();
}

@Override
public void setValue(Double value) {
setFlag(value.floatValue());
}


}, lowerinc, upperinc, min, max);
public MenuItem getMenuItem(@Nullable Component name, @Nullable Material displayMat,
double lowerinc, double upperinc, @Nullable Double min, @Nullable Double max) {
return this.getMenuItem(name, displayMat, null, lowerinc, upperinc, min, max);
}

public MenuItem getMenuItem(String name, Material displayItem,
List<String> description, double lowerinc, double upperinc, Double min, Double max) {
return new MenuItemDecimal(name, description, displayItem, new Callback<>() {
public MenuItem getMenuItem(@Nullable Component name, @Nullable Material displayMat,
@Nullable List<@NotNull Component> description,
double lowerinc, double upperinc, @Nullable Double min, @Nullable Double max) {
return new MenuItemDecimal(name, description, displayMat, new Callback<>() {

@Override
public Double getValue() {
Expand All @@ -94,8 +60,6 @@ public void setValue(Double value) {
setFlag(value.floatValue());
}


}, lowerinc, upperinc, min, max);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public void loadValue(String path, FileConfiguration config) {
}

@Override
public MenuItem getMenuItem(@NotNull Component name, @Nullable Material displayItem) {
public MenuItem getMenuItem(@Nullable Component name, @Nullable Material displayItem) {
return getMenuItem(name, displayItem, null);
}

@Override
public MenuItem getMenuItem(@NotNull Component name, @Nullable Material displayItem,
public MenuItem getMenuItem(@Nullable Component name, @Nullable Material displayItem,
@Nullable List<@NotNull Component> description) {
return null; //todo
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ 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_NOTTEAM("command.error.notTeam"),
COMMAND_ERROR_NOTTIME("command.error.notTime"),
COMMAND_ERROR_NOTTYPE("command.error.noType"),
COMMAND_ERROR_PLAYERNOTINMINIGAME("command.error.playerNotInMinigame"),
COMMAND_ERROR_RANGE("command.error.range"),
COMMAND_ERROR_OUTOFBOUNDS("command.error.OutOfBounds"),
COMMAND_ERROR_SENDERNOTAPLAYER("command.error.senderNotAPlayer"),
COMMAND_ERROR_UNKNOWN_PARAM("command.error.unknown.parameter"),
COMMAND_GLOBALLOADOUT_DESCRIPTION("command.globalLoadout.description"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package au.com.mineauz.minigames.managers.language.langkeys;

import org.jetbrains.annotations.NotNull;

public enum MgMenuLangKey implements LangKey {
MENU_HIERARCHY_ENTERCHAT("menu.hierarchy.enterChat"),
MENU_POTIONADD_ENTERCHAT("menu.potionAdd.enterChat"),
MENU_DELETE_SHIFTRIGHTCLICK("menu.delete.ShiftRightClick"),
MENU_DELETE_RIGHTCLICK("menu.delete.RightClick"),
MENU_POTIONADD_NAME("menu.potionAdd.name"),
MENU_POTIONADD_ERROR_SYNTAX("menu.potionAdd.error.syntax"),
MENU_FLAGADD_ENTERCHAT("menu.flagAdd.enterChat"),
MENU_FLAGADD_NAME("menu.flagAdd.name"),
MENU_DEFAULTWINNINGTEAM_NAME("menu.defaultWinningTeam.name"),
MENU_TEAMADD_NAME("menu.teamAdd.name"),
MENU_TEAM_DISPLAYNAME("menu.team.displayName"),
MENU_TEAM_MAXPLAYERS("menu.team.maxPlayers"),
MENU_PAGE_BACK("menu.page.back"),
MENU_TEAM_AUTOBALANCE("menu.team.autobalance"),
MENU_TEAM_NAMEVISIBILITY_NAME("menu.team.nameVisibility.name"),
MENU_TEAM_NAMEVISIBILITY_HIDEOWNTEAM("menu.team.nameVisibility.hideOwnTeam"),
MENU_TEAM_NAMEVISIBILITY_HIDEOTHERTEAM("menu.team.nameVisibility.hideOtherTeam"),
MENU_TEAM_NAMEVISIBILITY_NEVERVISIBLE("menu.team.nameVisibility.neverVisible"),
MENU_TEAM_NAMEVISIBILITY_ALWAYSVISIBLE("menu.team.nameVisibility.alwaysVisible"),
MENU_WHITELIST_ERROR_CONTAINS("menu.whitelist.error.contains"),
MENU_WHITELIST_ENTERCHAT("menu.whitelist.enterChat"),
MENU_BLOCKDATA_CLICKBLOCK("menu.blockData.clickBlock"),
MENU_BLOCKDATA_ERROR_INVALID("menu.blockData.error.invalid"),
MENU_DECIMAL_ENTERCHAT("menu.decimal.enterChat"),
MENU_MONEYREWARD_MENU_NAME("menu.moneyReward.menu.name"),
MENU_MONEYREWARD_ITEM_NAME("menu.moneyReward.item.name"),
MENU_PLAYSOUND_SOUND_NAME("menu.playSound.sound.name"),
MENU_PLAYSOUND_MENU_NAME("menu.playSound.menu.name"),
MENU_PLAYSOUND_PRIVATEPLAYBACK_NAME("menu.playSound.privatePlayback.name"),
MENU_PLAYSOUND_VOLUME_NAME("menu.playSound.volume.name"),
MENU_PLAYSOUND_PITCH_NAME("menu.playSound.pitch.name"),
MENU_PAGE_NEXT("menu.page.next"),
MENU_PAGE_PREVIOUS("menu.page.previous");

private final @NotNull String path;

MgMenuLangKey(@NotNull String path) {
this.path = path;
}

public @NotNull String getPath() {
return path;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
public enum MinigameLangKey implements LangKey { //todo this gets rather big. Slit it into smaller digestible parts: tool, ?...
CONFIG_BLACKLIST("config.blacklist"),
CONFIG_WHITELIST("config.whitelist"),
MENU_ENTERCHAT("menu.enterChat"),
MINIGAME_ERROR_FULL("minigame.error.full"),
MINIGAME_ERROR_INCORRECTSTART("minigame.error.incorrectStart"),
MINIGAME_ERROR_INVALIDMECHANIC("minigame.error.invalidMechanic"),
Expand Down Expand Up @@ -230,7 +229,10 @@ public enum MinigameLangKey implements LangKey { //todo this gets rather big. Sl
TOOL_SET_LOBBYLOCATION("tool.set.lobbyLocation"),
TOOL_SET_QUITLOCATION("tool.set.quitLocation"),
TOOL_SET_SPECTATORLOCATION("tool.set.spectatorLocation"),
MINIGAME_ERROR_NOTTEAMGAME("minigame.error.notTeamGame");
MINIGAME_ERROR_NOTTEAMGAME("minigame.error.notTeamGame"),
TEAM_ADD("team.add"),
TEAM_ERROR_COLOR_TAKEN("team.error.color.taken"),
TEAM_ERROR_COLOR_INVALID("team.error.color.invalid");

private final @NotNull String path;

Expand Down
31 changes: 25 additions & 6 deletions Minigames/src/main/java/au/com/mineauz/minigames/menu/Menu.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
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.managers.language.langkeys.MgMenuLangKey;
import au.com.mineauz.minigames.objects.MinigamePlayer;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.util.*;

Expand All @@ -23,7 +27,18 @@ public class Menu {
private int reopenTimerID = -1;
private Inventory inv = null;

public Menu(int rows, Component name, MinigamePlayer viewer) {
public Menu(int rows, @NotNull LangKey langKey, @NotNull MinigamePlayer viewer) {
if (rows > 6)
rows = 6;
else if (rows < 2)
rows = 2;
this.rows = rows;
this.name = MinigameMessageManager.getMgMessage(langKey);
pageView = new ItemStack[rows * 9];
this.viewer = viewer;
}

public Menu(int rows, Component name, @NotNull MinigamePlayer viewer) {
if (rows > 6)
rows = 6;
else if (rows < 2)
Expand Down Expand Up @@ -51,6 +66,10 @@ public boolean addItem(MenuItem item, int slot) {
return false;
}

private boolean isNewLine(@NotNull MenuItem menuItem) {
return menuItem.getName() != null && PlainTextComponentSerializer.plainText().serialize(menuItem.getName()).equalsIgnoreCase("NL");
}

public void addItem(MenuItem item) {
int inc = 0;
Menu m = this;
Expand All @@ -67,7 +86,7 @@ public void addItem(MenuItem item) {
if (m.getClicked(inc) == null) {
m.addItem(item, inc);
break;
} else if (m.getClicked(inc).getName() != null && ChatColor.stripColor(m.getClicked(inc).getName()).equals("NL")) {
} else if (isNewLine(m.getClicked(inc))) {
for (int i = 1; i < 10; i++) {
if ((inc + i) % 9 == 0) {
inc += i;
Expand All @@ -83,7 +102,7 @@ public void addItems(List<MenuItem> items) {
Menu curPage = this;
int inc = 0;
for (MenuItem it : items) {
if (it.getName() != null && ChatColor.stripColor(it.getName()).equals("NL")) {
if (isNewLine(it)) {
curPage.addItem(it, inc);
for (int i = 1; i < 10; i++) {
if ((inc + i) % 9 == 0) {
Expand All @@ -107,10 +126,10 @@ public void addItems(List<MenuItem> items) {

public void addPage() {
Menu nextPage = new Menu(rows, name, viewer);
addItem(new MenuItemPage("Next Page", MenuUtility.getBackMaterial(), nextPage), 9 * (rows - 1) + 5);
addItem(new MenuItemPage(MgMenuLangKey.MENU_PAGE_NEXT, MenuUtility.getBackMaterial(), nextPage), 9 * (rows - 1) + 5);
setNextPage(nextPage);
nextPage.setPreviousPage(this);
nextPage.addItem(new MenuItemPage("Previous Page", MenuUtility.getBackMaterial(), this), 9 * (rows - 1) + 3);
nextPage.addItem(new MenuItemPage(MgMenuLangKey.MENU_PAGE_PREVIOUS, MenuUtility.getBackMaterial(), this), 9 * (rows - 1) + 3);
for (int j = 9 * (rows - 1) + 6; j < 9 * rows; j++) {
if (getClicked(j) != null)
nextPage.addItem(getClicked(j), j);
Expand Down
Loading

0 comments on commit e2739ff

Please sign in to comment.