Skip to content
This repository has been archived by the owner on Aug 3, 2024. It is now read-only.

Commit

Permalink
Some config changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nulli0n committed Jul 11, 2023
1 parent 1cd2112 commit 796282b
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 117 deletions.
11 changes: 0 additions & 11 deletions NexEngine/src/main/java/su/nexmedia/engine/NexEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,11 @@

public class NexEngine extends NexPlugin<NexEngine> {

//private static NexEngine instance;

private final Set<NexPlugin<?>> childrens = new HashSet<>();

private EditorManager editorManager;
private MenuListener menuListener;

public NexEngine() {
//instance = this;
}

/*@NotNull
public static NexEngine get() {
return instance;
}*/

@Override
@NotNull
protected NexEngine getSelf() {
Expand Down
6 changes: 1 addition & 5 deletions NexEngine/src/main/java/su/nexmedia/engine/NexPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ public abstract class NexPlugin<P extends NexPlugin<P>> extends JavaPlugin {
private Logger logger;
private boolean isEngine;

/*@NotNull
public static NexEngine getEngine() {
return NexEngine.get();
}*/

public final boolean isEngine() {
return this.isEngine;
}
Expand Down Expand Up @@ -187,6 +182,7 @@ protected void loadManagers() {
this.langManager = new LangManager<>(this.getSelf());
this.langManager.setup();
this.loadLang();
this.getLangManager().loadDefaults();

this.registerPermissions();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import su.nexmedia.engine.api.placeholder.Placeholder;
import su.nexmedia.engine.api.placeholder.PlaceholderMap;
import su.nexmedia.engine.lang.EngineLang;
import su.nexmedia.engine.utils.Placeholders;
import su.nexmedia.engine.utils.regex.RegexUtil;

import java.util.*;
Expand All @@ -19,10 +20,6 @@

public abstract class AbstractCommand<P extends NexPlugin<P>> implements Placeholder {

public static final String PLACEHOLDER_USAGE = "%command_usage%";
public static final String PLACEHOLDER_DESCRIPTION = "%command_description%";
public static final String PLACEHOLDER_LABEL = "%command_label%";

protected final P plugin;
protected final Map<String, AbstractCommand<P>> childrens;
protected final Set<CommandFlag<?>> commandFlags;
Expand Down Expand Up @@ -62,9 +59,9 @@ public AbstractCommand(@NotNull P plugin, @NotNull String[] aliases, @Nullable S
this.childrens = new TreeMap<>();
this.commandFlags = new HashSet<>();
this.placeholderMap = new PlaceholderMap()
.add(PLACEHOLDER_DESCRIPTION, this::getDescription)
.add(PLACEHOLDER_USAGE, this::getUsage)
.add(PLACEHOLDER_LABEL, this::getLabelFull);
.add(Placeholders.COMMAND_DESCRIPTION, this::getDescription)
.add(Placeholders.COMMAND_USAGE, this::getUsage)
.add(Placeholders.COMMAND_LABEL, this::getLabelFull);

}

Expand Down Expand Up @@ -229,18 +226,13 @@ public void setPlayerOnly(boolean playerOnly) {
}

protected final void printUsage(@NotNull CommandSender sender) {
plugin.getMessage(EngineLang.CORE_COMMAND_USAGE).replace(this.replacePlaceholders()).send(sender);
plugin.getMessage(EngineLang.COMMAND_USAGE).replace(this.replacePlaceholders()).send(sender);
}

protected final void errorPermission(@NotNull CommandSender sender) {
plugin.getMessage(EngineLang.ERROR_PERMISSION_DENY).send(sender);
}

@Deprecated
protected final void errorItem(@NotNull CommandSender sender) {
plugin.getMessage(EngineLang.ERROR_ITEM_INVALID).send(sender);
}

protected final void errorPlayer(@NotNull CommandSender sender) {
plugin.getMessage(EngineLang.ERROR_PLAYER_INVALID).send(sender);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.NexPlugin;
import su.nexmedia.engine.api.placeholder.PlaceholderMap;
import su.nexmedia.engine.utils.*;
import su.nexmedia.engine.utils.message.NexParser;
import su.nexmedia.engine.utils.regex.RegexUtil;
Expand Down Expand Up @@ -45,6 +46,7 @@ public Pattern getPattern() {
}

private final NexPlugin<?> plugin;
private final PlaceholderMap placeholderMap;

private String msgRaw;
private String msgLocalized;
Expand All @@ -55,6 +57,11 @@ public Pattern getPattern() {

public LangMessage(@NotNull NexPlugin<?> plugin, @NotNull String raw) {
this.plugin = plugin;
this.placeholderMap = new PlaceholderMap();
this.plugin.getLangManager().getPlaceholders().forEach((placeholder, value) -> {
this.placeholderMap.add(placeholder, () -> value);
});

this.setRaw(raw);
}

Expand All @@ -66,6 +73,7 @@ public LangMessage(@NotNull NexPlugin<?> plugin, @NotNull String raw) {
this.hasPrefix = from.hasPrefix;
this.sound = from.sound;
this.titleTimes = Arrays.copyOf(from.titleTimes, from.titleTimes.length);
this.placeholderMap = new PlaceholderMap(from.placeholderMap);
}

void setOptions(@NotNull String msg) {
Expand Down Expand Up @@ -208,11 +216,6 @@ public String normalizeLines() {

@NotNull
private UnaryOperator<String> replaceDefaults() {
return str -> {
for (Map.Entry<String, String> entry : this.plugin.getLangManager().getPlaceholders().entrySet()) {
str = str.replace(entry.getKey(), entry.getValue());
}
return Placeholders.forPlugin(plugin).apply(str);
};
return str -> Placeholders.forPlugin(this.plugin).apply(this.placeholderMap.replacer().apply(str));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class AboutSubCommand<P extends NexPlugin<P>> extends AbstractCommand<P>

public AboutSubCommand(@NotNull P plugin) {
super(plugin, new String[]{"about"});
this.setDescription(plugin.getMessage(EngineLang.CORE_COMMAND_ABOUT_DESC));
this.setDescription(plugin.getMessage(EngineLang.COMMAND_ABOUT_DESC));
}

@Override
Expand All @@ -28,9 +28,9 @@ protected void onExecute(@NotNull CommandSender sender, @NotNull CommandResult r
LangColors.YELLOW + ChatColor.BOLD + plugin.getName() + LangColors.ORANGE + " v" + plugin.getDescription().getVersion(),
LangColors.GRAY + plugin.getDescription().getDescription(),
LangColors.GRAY,
LangColors.GREEN + "▪ " + LangColors.GRAY + "API Version: " + LangColors.GREEN + plugin.getDescription().getAPIVersion(),
LangColors.GREEN + "▪ " + LangColors.GRAY + "Made by " + LangColors.GREEN + plugin.getDescription().getAuthors().get(0),
LangColors.GREEN + "▪ " + LangColors.GRAY + "Powered by " + LangColors.GREEN + EngineUtils.ENGINE.getName(),
LangColors.YELLOW + "▪ " + LangColors.GRAY + "API Version: " + LangColors.YELLOW + plugin.getDescription().getAPIVersion(),
LangColors.YELLOW + "▪ " + LangColors.GRAY + "Made by " + LangColors.YELLOW + plugin.getDescription().getAuthors().get(0),
LangColors.YELLOW + "▪ " + LangColors.GRAY + "Powered by " + LangColors.YELLOW + EngineUtils.ENGINE.getName(),
LangColors.GRAY,
LangColors.CYAN + ChatColor.UNDERLINE + "Made in the Urals" + LangColors.CYAN + " © 2019-2023",
LangColors.GRAY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import su.nexmedia.engine.api.command.AbstractCommand;
import su.nexmedia.engine.api.command.CommandResult;
import su.nexmedia.engine.lang.EngineLang;
import su.nexmedia.engine.utils.Placeholders;

public class HelpSubCommand<P extends NexPlugin<P>> extends AbstractCommand<P> {

public HelpSubCommand(@NotNull P plugin) {
super(plugin, new String[]{"help"});
this.setDescription(plugin.getMessage(EngineLang.CORE_COMMAND_HELP_DESC));
this.setDescription(plugin.getMessage(EngineLang.COMMAND_HELP_DESC));
}

@Override
Expand All @@ -21,8 +22,8 @@ protected void onExecute(@NotNull CommandSender sender, @NotNull CommandResult r
return;
}

plugin.getMessage(EngineLang.CORE_COMMAND_HELP_LIST)
.replace(str -> str.contains(AbstractCommand.PLACEHOLDER_LABEL), (line, list) -> {
plugin.getMessage(EngineLang.COMMAND_HELP_LIST)
.replace(str -> str.contains(Placeholders.COMMAND_LABEL), (line, list) -> {
this.parent.getChildrens().forEach(children -> {
if (!children.hasPermission(sender)) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public ReloadSubCommand(@NotNull P plugin, @NotNull Permission permission) {

public ReloadSubCommand(@NotNull P plugin, @NotNull String permission) {
super(plugin, new String[]{"reload"}, permission);
this.setDescription(plugin.getMessage(EngineLang.CORE_COMMAND_RELOAD_DESC));
this.setDescription(plugin.getMessage(EngineLang.COMMAND_RELOAD_DESC));
}

@Override
protected void onExecute(@NotNull CommandSender sender, @NotNull CommandResult result) {
plugin.reload();
plugin.getMessage(EngineLang.CORE_COMMAND_RELOAD_DONE).send(sender);
plugin.getMessage(EngineLang.COMMAND_RELOAD_DONE).send(sender);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import su.nexmedia.engine.NexPlugin;
import su.nexmedia.engine.api.config.JOption;
import su.nexmedia.engine.api.config.JYML;
import su.nexmedia.engine.api.lang.LangColors;
import su.nexmedia.engine.api.manager.AbstractManager;
import su.nexmedia.engine.lang.LangManager;
import su.nexmedia.engine.utils.Placeholders;
import su.nexmedia.engine.utils.ResourceExtractor;

import java.io.File;
import java.io.IOException;
import java.util.Locale;

public class ConfigManager<P extends NexPlugin<P>> extends AbstractManager<P> {

Expand All @@ -35,7 +37,7 @@ protected void onLoad() {
"Localized plugin name. It's used in messages and with internal placeholders.")
.read(config);

this.pluginPrefix = JOption.create("Plugin.Prefix", "&e" + Placeholders.PLUGIN_NAME + " &8» &7",
this.pluginPrefix = JOption.create("Plugin.Prefix", LangColors.YELLOW + Placeholders.PLUGIN_NAME + LangColors.GRAY + " »",
"Plugin prefix. Used in messages.",
"You can use " + Placeholders.PLUGIN_NAME_LOCALIZED + " placeholder for a plugin name.")
.read(config).replace(Placeholders.PLUGIN_NAME, this.pluginName);
Expand All @@ -45,10 +47,10 @@ protected void onLoad() {
"Do not leave this empty. Split multiple names with a comma.")
.read(config).split(",");

this.languageCode = JOption.create("Plugin.Language", "en",
this.languageCode = JOption.create("Plugin.Language", Locale.getDefault().getLanguage(),
"Sets the plugin language.",
"It will use language config from the '" + LangManager.DIR_LANG + "' sub-folder for specified language code.",
"By default it's 'en', so 'messages_en.yml' will be used.")
"By default uses your system's default locale.")
.read(config).toLowerCase();

this.config.saveChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class EditorManager extends AbstractManager<NexEngine> {
private static final Map<Player, InputHandler> CACHE_INPUT = new WeakHashMap<>();
private static final Map<Player, List<String>> CACHE_VALUES = new WeakHashMap<>();

static final String EXIT = "#exit";
public static final String EXIT = "#exit";
static final String VALUES = "#values";
static final int TITLE_STAY = Short.MAX_VALUE;

Expand Down
58 changes: 33 additions & 25 deletions NexEngine/src/main/java/su/nexmedia/engine/lang/EngineLang.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,55 @@

import su.nexmedia.engine.api.lang.LangColors;
import su.nexmedia.engine.api.lang.LangKey;
import su.nexmedia.engine.editor.EditorManager;
import su.nexmedia.engine.utils.Placeholders;

public class EngineLang implements LangColors {

public static final LangKey CORE_COMMAND_USAGE = new LangKey("Core.Command.Usage", "&cUsage: &e/%command_label% &6%command_usage%");
public static final LangKey CORE_COMMAND_HELP_LIST = new LangKey("Core.Command.Help.List", """
<! prefix:"false" !>
&6&m &6&l[ &e&l%plugin_name_localized% &7- &e&lCommands &6&l]&6&m &7
&7
&7 &4&l<> &7- Required, &2&l[] &7- Optional.
&7
&6▪ &e/%command_label% &6%command_usage% &7- %command_description%
&7
""");
public static final LangKey CORE_COMMAND_HELP_DESC = new LangKey("Core.Command.Help.Desc", "Show help page.");
public static final LangKey CORE_COMMAND_ABOUT_DESC = new LangKey("Core.Command.About.Desc", "Some info about the plugin.");
public static final LangKey CORE_COMMAND_RELOAD_DESC = new LangKey("Core.Command.Reload.Desc", "Reload the plugin.");
public static final LangKey CORE_COMMAND_RELOAD_DONE = new LangKey("Core.Command.Reload.Done", "Reloaded!");
public static final LangKey COMMAND_USAGE = LangKey.of("Command.Usage",
"<! prefix:\"false\" !>" +
"\n" + GRAY +
"\n" + RED + "Error: " + GRAY + "Wrong arguments!" +
"\n" + RED + "Usage: " + YELLOW + "/" + Placeholders.COMMAND_LABEL + " " + LIGHT_YELLOW + Placeholders.COMMAND_USAGE +
"\n" + GRAY);
public static final LangKey COMMAND_HELP_LIST = LangKey.of("Command.Help.List",
"<! prefix:\"false\" !>" +
"\n" + GRAY +
"\n" + YELLOW + "&l" + Placeholders.PLUGIN_NAME_LOCALIZED + GRAY + " - " + YELLOW + "&lCommands:" +
"\n" + GRAY +
"\n" + RED + "&l<> " + GRAY + "- Required, " + GREEN + "&l[] " + GRAY + "- Optional." +
"\n" + GRAY +
"\n" + LIGHT_YELLOW + "▪ " + YELLOW + "/" + Placeholders.COMMAND_LABEL + " " + LIGHT_YELLOW + Placeholders.COMMAND_USAGE + " " + GRAY + "- " + Placeholders.COMMAND_DESCRIPTION +
"\n" + GRAY);
public static final LangKey COMMAND_HELP_DESC = LangKey.of("Command.Help.Desc", "Show help page.");
public static final LangKey COMMAND_ABOUT_DESC = LangKey.of("Command.About.Desc", "Some info about the plugin.");
public static final LangKey COMMAND_RELOAD_DESC = LangKey.of("Command.Reload.Desc", "Reload the whole plugin.");
public static final LangKey COMMAND_RELOAD_DONE = LangKey.of("Command.Reload.Done", "All data & configuration has been reloaded!");

public static final LangKey TIME_DAY = new LangKey("Time.Day", "%s%d.");
public static final LangKey TIME_HOUR = new LangKey("Time.Hour", "%s%h.");
public static final LangKey TIME_MIN = new LangKey("Time.Min", "%s%min.");
public static final LangKey TIME_SEC = new LangKey("Time.Sec", "%s%sec.");

public static final LangKey OTHER_YES = new LangKey("Other.Yes", "&aYes");
public static final LangKey OTHER_NO = new LangKey("Other.No", "&cNo");
public static final LangKey OTHER_ANY = new LangKey("Other.Any", "Any");
public static final LangKey OTHER_NONE = new LangKey("Other.None", "None");
public static final LangKey OTHER_NEVER = new LangKey("Other.Never", "Never");
public static final LangKey OTHER_ONE_TIMED = new LangKey("Other.OneTimed", "One-Timed");
public static final LangKey OTHER_UNLIMITED = new LangKey("Other.Unlimited", "Unlimited");
public static final LangKey OTHER_INFINITY = new LangKey("Other.Infinity", "∞");
public static final LangKey OTHER_YES = LangKey.of("Other.Yes", GREEN + "Yes");
public static final LangKey OTHER_NO = LangKey.of("Other.No", RED + "No");
public static final LangKey OTHER_ANY = LangKey.of("Other.Any", "Any");
public static final LangKey OTHER_NONE = LangKey.of("Other.None", "None");
public static final LangKey OTHER_NEVER = LangKey.of("Other.Never", "Never");
public static final LangKey OTHER_ONE_TIMED = LangKey.of("Other.OneTimed", "One-Timed");
public static final LangKey OTHER_UNLIMITED = LangKey.of("Other.Unlimited", "Unlimited");
public static final LangKey OTHER_INFINITY = LangKey.of("Other.Infinity", "∞");

public static final LangKey ERROR_PLAYER_INVALID = LangKey.of("Error.Player.Invalid", RED + "Player not found.");
public static final LangKey ERROR_WORLD_INVALID = LangKey.of("Error.World.Invalid", RED + "World not found.");
public static final LangKey ERROR_NUMBER_INVALID = LangKey.of("Error.Number.Invalid", "&7%num% &cis not a valid number.");
public static final LangKey ERROR_NUMBER_INVALID = LangKey.of("Error.Number.Invalid", RED + "%num% is not a valid number.");
public static final LangKey ERROR_PERMISSION_DENY = LangKey.of("Error.Permission.Deny", RED + "You don't have permissions to do that!");
@Deprecated public static final LangKey ERROR_ITEM_INVALID = LangKey.of("Error.Item.Invalid", RED + "You must hold an item!");
public static final LangKey ERROR_COMMAND_SELF = LangKey.of("Error.Command.Self", RED + "This command is not applicable to yourself.");
public static final LangKey ERROR_COMMAND_SENDER = LangKey.of("Error.Command.Sender", RED + "This command is for players only.");

public static final LangKey EDITOR_TIP_EXIT = LangKey.of("Editor.Tip.Exit", "<! prefix:\"false\" !> <? showText:\"&7Click me or type &f#exit\" run_command:\"/#exit\" ?>&bClick to exit the &dEdit Mode</>");
public static final LangKey EDITOR_TIP_EXIT = LangKey.of("Editor.Tip.Exit",
"<! prefix:\"false\" !>" +
"<? showText:\"" + GRAY + "Click me or type " + RED + EditorManager.EXIT + "\" run_command:\"/" + EditorManager.EXIT + "\" ?>" + GRAY + "Click here to " + RED + "[Exit Edit Mode]</>");
public static final LangKey EDITOR_TITLE_DONE = LangKey.of("Editor.Title.Done", "&a&lDone!");
public static final LangKey EDITOR_TITLE_EDIT = LangKey.of("Editor.Title.Edit", "&a&l< Edit Mode >");
public static final LangKey EDITOR_TITLE_ERROR = LangKey.of("Editor.Title.Error", "&c&lError!");
Expand Down
Loading

0 comments on commit 796282b

Please sign in to comment.