message prefix fix

This commit is contained in:
BuildTools committed 2024-02-01 16:41:57 +05:00
1 parent f9bf102504
commit 814a065d38
4 files changed
+24 -12

No files matched your search

@@ -22,6 +22,6 @@ public class ReloadSubCommand extends AbstractCommand<NightCorePlugin> {
@Override
protected void onExecute(@NotNull CommandSender sender, @NotNull CommandResult result) {
this.plugin.reload();
CoreLang.COMMAND_RELOAD_DONE.getMessage().send(sender);
CoreLang.COMMAND_RELOAD_DONE.getMessage(plugin).send(sender);
}
}
@@ -213,22 +213,22 @@ public abstract class AbstractCommand<P extends NightCorePlugin> implements Nigh
}
protected final void errorUsage(@NotNull CommandSender sender) {
CoreLang.ERROR_COMMAND_USAGE.getMessage().replace(this.replacePlaceholders()).send(sender);
CoreLang.ERROR_COMMAND_USAGE.getMessage(plugin).replace(this.replacePlaceholders()).send(sender);
}
protected final void errorPermission(@NotNull CommandSender sender) {
CoreLang.ERROR_NO_PERMISSION.getMessage().send(sender);
CoreLang.ERROR_NO_PERMISSION.getMessage(plugin).send(sender);
}
protected final void errorPlayer(@NotNull CommandSender sender) {
CoreLang.ERROR_INVALID_PLAYER.getMessage().send(sender);
CoreLang.ERROR_INVALID_PLAYER.getMessage(plugin).send(sender);
}
protected final void errorSender(@NotNull CommandSender sender) {
CoreLang.ERROR_COMMAND_PLAYER_ONLY.getMessage().send(sender);
CoreLang.ERROR_COMMAND_PLAYER_ONLY.getMessage(plugin).send(sender);
}
protected final void errorNumber(@NotNull CommandSender sender, @NotNull String from) {
CoreLang.ERROR_INVALID_NUMBER.getMessage().replace(Placeholders.GENERIC_VALUE, from).send(sender);
CoreLang.ERROR_INVALID_NUMBER.getMessage(plugin).replace(Placeholders.GENERIC_VALUE, from).send(sender);
}
}
@@ -61,6 +61,11 @@ public class LangText extends LangEntry<LangMessage> {
return message;
}
@NotNull
public LangMessage getMessage(@NotNull NightCorePlugin plugin) {
return message.setPrefix(plugin.getPrefix());
}
public void setMessage(@NotNull LangMessage message) {
this.message = message;
}
@@ -7,6 +7,7 @@ import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nightexpress.nightcore.NightCorePlugin;
import su.nightexpress.nightcore.core.CoreConfig;
import su.nightexpress.nightcore.language.tag.MessageDecorator;
@@ -32,10 +33,14 @@ public class LangMessage {
private final WrappedMessage message;
public LangMessage(@NotNull NightCorePlugin plugin, @NotNull String defaultText, @NotNull MessageOptions options) {
this(plugin, defaultText, options, null);
}
public LangMessage(@NotNull NightCorePlugin plugin, @NotNull String defaultText, @NotNull MessageOptions options, @Nullable String prefix) {
this.plugin = plugin;
this.defaultText = defaultText;
this.options = options;
this.message = NightMessage.from(defaultText);
this.message = NightMessage.from(prefix == null ? defaultText : prefix + defaultText);
if (CoreConfig.MODERN_TEXT_PRECOMPILE_LANG.get()) {
this.message.compile();
}
@@ -105,13 +110,15 @@ public class LangMessage {
builder.append(letter);
}
if (options.getOutputType() == OutputType.CHAT && options.hasPrefix()) {
builder.insert(0, plugin.getPrefix());
}
String text = builder.toString();
String prefix = options.getOutputType() == OutputType.CHAT && options.hasPrefix() ? plugin.getPrefix() : null;
return new LangMessage(plugin, text, options);
return new LangMessage(plugin, text, options, prefix);
}
@NotNull
public LangMessage setPrefix(@NotNull String prefix) {
return new LangMessage(this.plugin, this.defaultText, this.options, prefix);
}
@NotNull