Skip to content

Commit

Permalink
Langrework 18
Browse files Browse the repository at this point in the history
  • Loading branch information
FireInstall committed Feb 10, 2024
1 parent 72a3482 commit 9691609
Show file tree
Hide file tree
Showing 53 changed files with 575 additions and 281 deletions.
5 changes: 3 additions & 2 deletions Minigames/src/main/java/au/com/mineauz/minigames/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -627,10 +627,11 @@ private void clickMenu(@NotNull InventoryClickEvent event) {
ItemStack disItem = null;
switch (event.getClick()) {
case LEFT -> {
if (event.getCursor().getType() != Material.AIR)
if (event.getCursor().getType() != Material.AIR) {
disItem = item.onClickWithItem(event.getCursor());
else
} else {
disItem = item.onClick();
}
}
case RIGHT -> disItem = item.onRightClick();
case SHIFT_LEFT -> disItem = item.onShiftClick();
Expand Down
49 changes: 28 additions & 21 deletions Minigames/src/main/java/au/com/mineauz/minigames/PlayerLoadout.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import au.com.mineauz.minigames.minigame.modules.LoadoutModule;
import au.com.mineauz.minigames.minigame.modules.LoadoutModule.LoadoutAddon;
import au.com.mineauz.minigames.objects.MinigamePlayer;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
Expand All @@ -26,7 +28,7 @@ public class PlayerLoadout {
private boolean hunger = false;
private int level = -1;
private boolean deleteable = true;
private String displayname = null;
private Component displayname = null;
private boolean lockInventory = false;
private boolean lockArmour = false;
private boolean allowOffHand = true;
Expand All @@ -38,32 +40,28 @@ public PlayerLoadout(String name) {
team = TeamColor.matchColor(name);
}

public Callback<String> getDisplayNameCallback() {
public Callback<Component> getDisplayNameCallback() {
return new Callback<>() {

@Override
public String getValue() {
public Component getValue() {
return displayname;
}

@Override
public void setValue(String value) {
public void setValue(Component value) {
displayname = value;
}


};
}

public String getDisplayName() {
if (displayname == null) {
return loadoutName;
} else {
return displayname;
}
public @NotNull Component getDisplayName() {
return Objects.requireNonNullElseGet(displayname, () -> Component.text(loadoutName));
}

public void setDisplayName(String name) {
public void setDisplayName(Component name) {
displayname = name;
}

Expand Down Expand Up @@ -493,32 +491,41 @@ public void load(ConfigurationSection section) {
}
}

if (section.contains("usepermissions"))
if (section.contains("usepermissions")) {
setUsePermissions(section.getBoolean("usepermissions"));
}

if (section.contains("falldamage"))
if (section.contains("falldamage")) {
setHasFallDamage(section.getBoolean("falldamage"));
}

if (section.contains("hunger"))
if (section.contains("hunger")) {
setHasHunger(section.getBoolean("hunger"));
}

if (section.contains("displayName"))
setDisplayName(section.getString("displayName"));
if (section.contains("displayName")) {
setDisplayName(MiniMessage.miniMessage().deserialize(section.getString("displayName")));
}

if (section.contains("inventoryLocked"))
if (section.contains("inventoryLocked")) {
setInventoryLocked(section.getBoolean("inventoryLocked"));
}

if (section.contains("armourLocked"))
if (section.contains("armourLocked")) {
setArmourLocked(section.getBoolean("armourLocked"));
}

if (section.contains("team"))
if (section.contains("team")) {
setTeamColor(TeamColor.matchColor(section.getString("team")));
}

if (section.contains("displayInMenu"))
if (section.contains("displayInMenu")) {
setDisplayInMenu(section.getBoolean("displayInMenu"));
}

if (section.contains("allowOffhand"))
if (section.contains("allowOffhand")) {
setAllowOffHand(section.getBoolean("allowOffhand"));
}

if (section.contains("addons")) {
ConfigurationSection addonSection = section.getConfigurationSection("addons");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public RollbackScheduler(List<MgBlockData> blocks, Minigame minigame, MinigamePl
iterator = blocks.iterator();
this.minigame = minigame;
this.modifier = modifier;
int delay = minigame.getRegenDelay() * 20 + 1;
long delay = minigame.getRegenDelay() * 20 + 1;
task = Bukkit.getScheduler().runTaskTimer(Minigames.getPlugin(), this, delay, 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Minigame miniga
if (!mod.getLoadout(ld).getItemSlots().isEmpty()) {
item = mod.getLoadout(ld).getItem((Integer) mod.getLoadout(ld).getItemSlots().toArray()[0]).getType();
}
MenuItemDisplayLoadout mil = new MenuItemDisplayLoadout(ld, des, item, mod.getLoadout(ld), minigame);
MenuItemDisplayLoadout mil = new MenuItemDisplayLoadout(item, ld, des, mod.getLoadout(ld), minigame);
mil.setAllowDelete(mod.getLoadout(ld).isDeleteable());
mi.add(mil);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Minigame miniga
if (args != null) {
Long millis = MinigameUtils.parsePeriod(args[0]);
if (millis != null) {
int time = Integer.parseInt(args[0]);
minigame.setRegenDelay(time);
minigame.setRegenDelay(TimeUnit.MILLISECONDS.toSeconds(millis));
MinigameMessageManager.sendMgMessage(sender, MinigameMessageType.INFO, MgCommandLangKey.COMMAND_SET_REGENDELAY_SUCCESS,
Placeholder.unparsed(MinigamePlaceHolderKey.MINIGAME.getKey(), minigame.getName(false)),
Placeholder.unparsed(MinigamePlaceHolderKey.TIME.getKey(), String.valueOf(TimeUnit.MILLISECONDS.toSeconds(time))));
Placeholder.unparsed(MinigamePlaceHolderKey.TIME.getKey(), String.valueOf(TimeUnit.MILLISECONDS.toSeconds(millis))));
return true;
} else {
MinigameMessageManager.sendMgMessage(sender, MinigameMessageType.ERROR, MgCommandLangKey.COMMAND_ERROR_NOTTIME,
Expand All @@ -64,7 +63,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Minigame miniga

@Override
public @Nullable List<@NotNull String> onTabComplete(@NotNull CommandSender sender, @NotNull Minigame minigame,
@NotNull String @NotNull @Nullable [] args) {
@NotNull String @Nullable [] args) {
return List.of("s", "m", "h");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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;
Expand Down Expand Up @@ -34,7 +33,7 @@ public void loadValue(String path, FileConfiguration config) {
}

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

@Override
Expand All @@ -50,9 +49,9 @@ public void setValue(Boolean value) {
}

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

@Override
public Boolean getValue() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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.MenuItemString;
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;

public class ComponentFlag extends Flag<Component> {
public ComponentFlag(Component value, String name) {
setFlag(value);
setDefaultFlag(value);
setName(name);
}

@Override
public void saveValue(String path, FileConfiguration config) {
config.set(path + "." + getName(), getFlag());
}

@Override
public void loadValue(String path, FileConfiguration config) {
if (config.contains(path + "." + getName())) {
setFlag(config.getString(path + "." + getName()));
} else {
setFlag(getDefaultFlag());
}
}

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

@Override
public String getValue() {
return getFlag();
}

@Override
public void setValue(String value) {
setFlag(value);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public enum MinigamePlaceHolderKey implements PlaceHolderKey {
REGION("region"),
REVERTS("reverts"),
SCORE("score"),
STAT("stat"),
STATE("state"),
TEAM("team"),
TEXT("text"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@
public enum MgMenuLangKey implements LangKey {
MENU_BLOCKDATA_CLICKBLOCK("menu.blockData.clickBlock"),
MENU_BLOCKDATA_ERROR_INVALID("menu.blockData.error.invalid"),
MENU_DECIMAL_ENTERCHAT("menu.decimal.enterChat"),
MENU_DEFAULTWINNINGTEAM_NAME("menu.defaultWinningTeam.name"),
MENU_DELETE_RIGHTCLICK("menu.delete.RightClick"),
MENU_DELETE_SHIFTRIGHTCLICK("menu.delete.ShiftRightClick"),
MENU_DISPLAYLOADOUT_ALLOWFALLDAMAGE_NAME("menu.displayLoadout.allowFallDamage.name"),
MENU_DISPLAYLOADOUT_ALLOWHUNGER_NAME("menu.displayLoadout.allowHunger.name"),
MENU_DISPLAYLOADOUT_ALLOWOFFHAND_NAME("menu.displayLoadout.allowOffhand.name"),
MENU_DISPLAYLOADOUT_DELETE("menu.displayLoadout.delete"),
MENU_DISPLAYLOADOUT_DISPLAYINMENU_NAME("menu.displayLoadout.displayInMenu.name"),
MENU_DISPLAYLOADOUT_DISPLAYNAME_NAME("menu.displayLoadout.displayName.name"),
MENU_DISPLAYLOADOUT_EFFECTS_NAME("menu.displayLoadout.effects.name"),
MENU_DISPLAYLOADOUT_ENTERCHAT("menu.displayLoadout.enterChat"),
MENU_DISPLAYLOADOUT_LOCKARMOR_NAME("menu.displayLoadout.lockArmor.name"),
MENU_DISPLAYLOADOUT_LOCKINVENTORY_NAME("menu.displayLoadout.lockInventory.name"),
MENU_DISPLAYLOADOUT_LOCKTOTEAM_NAME("menu.displayLoadout.lockToTeam.name"),
MENU_DISPLAYLOADOUT_NOTDELETE("menu.displayLoadout.notDelete"),
MENU_DISPLAYLOADOUT_SAVE_NAME("menu.displayLoadout.save.name"),
MENU_DISPLAYLOADOUT_SETTINGS_NAME("menu.displayLoadout.settings.name"),
MENU_DISPLAYLOADOUT_USEPERMISSIONS_DESCRIPTION("menu.displayLoadout.usePermissions.description"),
MENU_DISPLAYLOADOUT_USEPERMISSIONS_NAME("menu.displayLoadout.usePermissions.name"),
MENU_DISPLAYLOADOUT_XPLEVEL_DESCRIPTION("menu.displayLoadout.xpLevel.description"),
MENU_DISPLAYLOADOUT_XPLEVEL_NAME("menu.displayLoadout.xpLevel.name"),
MENU_EFFECTS_SAVE_NAME("menu.effects.save.name"),
MENU_FLAGADD_ENTERCHAT("menu.flagAdd.enterChat"),
MENU_FLAGADD_NAME("menu.flagAdd.name"),
MENU_HIERARCHY_ENTERCHAT("menu.hierarchy.enterChat"),
Expand All @@ -33,7 +43,9 @@ public enum MgMenuLangKey implements LangKey {
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"),
MENU_POTIONADD_NAME("menu.potionAdd.name"), // todo unused
MENU_STRING_ALLOWNULL("menu.string.allowNull"),
MENU_STRING_ENTERCHAT("menu.string.enterChat"),
MENU_TEAMADD_NAME("menu.teamAdd.name"),
MENU_TEAM_AUTOBALANCE("menu.team.autobalance"),
MENU_TEAM_DISPLAYNAME("menu.team.displayName"),
Expand All @@ -43,8 +55,23 @@ public enum MgMenuLangKey implements LangKey {
MENU_TEAM_NAMEVISIBILITY_HIDEOWNTEAM("menu.team.nameVisibility.hideOwnTeam"),
MENU_TEAM_NAMEVISIBILITY_NAME("menu.team.nameVisibility.name"),
MENU_TEAM_NAMEVISIBILITY_NEVERVISIBLE("menu.team.nameVisibility.neverVisible"),
MENU_WHITELIST_ADDMATERIAL_NAME("menu.whitelist.addMaterial.name"),
MENU_WHITELIST_BLOCK_NAME("menu.whitelist.block.name"),
MENU_WHITELIST_ENTERCHAT("menu.whitelist.enterChat"),
MENU_WHITELIST_ERROR_CONTAINS("menu.whitelist.error.contains");
MENU_WHITELIST_ERROR_CONTAINS("menu.whitelist.error.contains"),
MENU_WHITELIST_MODE("menu.whitelist.mode"),
MENU_FLAG_REMOVED("menu.flag.removed"),
MENU_NUMBER_ENTERCHAT("menu.number.enterChat"),
MENU_LIST_ERROR_INVALID("menu.list.error.invalid"),
MENU_LIST_ERROR_TOOLONG("menu.list.error.long"),
MENU_LIST_OPTION("menu.list.options"),
MENU_LIST_ENTERCHAT("menu.list.enterChat"),
MENU_LOADOUT_ADD_ENTERCHAT("menu.loadout.add.enterChat"),
MENU_LOADOUT_ERROR_ALREADYEXISTS("menu.loadout.error.alreadyExists"),
MENU_STAT_DISPLAYNAME("menu.stat.displayname"),
MENU_STAT_STORAGEFORMAT("menu.stat.storageFormat"),
MENU_STAT_EDIT_NAME("menu.stat.edit.name"),
MENU_REWARD_SELECTTYPE_NAME("menu.reward.selectType.name");

private final @NotNull String path;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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.LangKey;
import au.com.mineauz.minigames.managers.language.langkeys.MgCommandLangKey;
import au.com.mineauz.minigames.managers.language.langkeys.MgMenuLangKey;
import au.com.mineauz.minigames.objects.MinigamePlayer;
Expand All @@ -18,6 +19,10 @@
public class MenuItemAddWhitelistBlock extends MenuItem {
private final List<Material> whitelist;

public MenuItemAddWhitelistBlock(LangKey langKey, List<Material> whitelist) {
this(MinigameMessageManager.getMgMessage(langKey), whitelist);
}

public MenuItemAddWhitelistBlock(Component name, List<Material> whitelist) {
super(MenuUtility.getCreateMaterial(), name);
setDescription(List.of("Left Click with item to", "add to whitelist/blacklist", "Click without item to", "manually add item."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,15 @@ public MenuItemBoolean(@Nullable Material displayMat, @Nullable Component name,
updateDescription();
}

public MenuItemBoolean(@Nullable Component name, @Nullable List<@NotNull Component> description,
@Nullable Material displayMat, @NotNull Callback<@NotNull Boolean> toggle) {
public MenuItemBoolean(@Nullable Material displayMat, @NotNull LangKey langKey, @Nullable List<@NotNull Component> description,
@NotNull Callback<@NotNull Boolean> toggle) {
super(displayMat, langKey, description);
this.toggle = toggle;
updateDescription();
}

public MenuItemBoolean(@Nullable Material displayMat, @Nullable Component name, @Nullable List<@NotNull Component> description,
@NotNull Callback<@NotNull Boolean> toggle) {
super(displayMat, name, description);
this.toggle = toggle;
updateDescription();
Expand Down
Loading

0 comments on commit 9691609

Please sign in to comment.