Skip to content

Commit

Permalink
Lang rework 24
Browse files Browse the repository at this point in the history
Minigames compiles! Merry Christmas
Therefore this includes fixes for missed errors since testing is on the table
  • Loading branch information
FireInstall committed Feb 17, 2024
1 parent b8c2b33 commit 7c7b3bb
Show file tree
Hide file tree
Showing 56 changed files with 1,421 additions and 755 deletions.
8 changes: 4 additions & 4 deletions Minigames/src/main/java/au/com/mineauz/minigames/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface MinigameTag<T> {
* MinigameTag representing vanilla potions with negative effect(s).
* Also represents all potions with exclusive negative effects, which aren't in the value list.
*/
MinigameTag<PotionEffectType> NEGATIVE_POTION = new MinigameTag<>() {
MinigameTag<PotionEffectType> NEGATIVE_POTION_EFFECT = new MinigameTag<>() {
@Override
public boolean isTagged(PotionEffectType item) {
return getValues().contains(item);
Expand Down Expand Up @@ -47,7 +47,7 @@ public Set<PotionEffectType> 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<PotionEffectType> POSITIVE_POTION = new MinigameTag<>() {
MinigameTag<PotionEffectType> POSITIVE_POTION_EFFECT = new MinigameTag<>() {
@Override
public boolean isTagged(PotionEffectType item) {
return getValues().contains(item);
Expand Down Expand Up @@ -87,7 +87,7 @@ public Set<PotionEffectType> getValues() {
/**
* MinigameTag representing vanilla potions with both, positive and negative, effects
*/
MinigameTag<Set<PotionEffectType>> MIXED_POTION = new MinigameTag<>() {
MinigameTag<Set<PotionEffectType>> MIXED_POTION_EFFECT = new MinigameTag<>() {

@Override
public boolean isTagged(Set<PotionEffectType> item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class PlayerLoadout {
private final Map<Integer, ItemStack> itemSlot = new HashMap<>();
private final List<PotionEffect> potions = new ArrayList<>();
private final Map<Class<? extends LoadoutAddon>, Object> addonValues = new HashMap<>();
private String loadoutName = "default";
private String loadoutName;
private boolean usePermission = false;
private boolean fallDamage = true;
private boolean hunger = false;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command

public List<String> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<>() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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!");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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<Object, Object> translationPair : defaults.entrySet()) {
for (Map.Entry<Object, Object> 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;
}
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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));
}

Expand All @@ -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));
}

Expand All @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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));
}

Expand Down
Loading

0 comments on commit 7c7b3bb

Please sign in to comment.