mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Move language stuff to its own file
This commit is contained in:
1 parent
69375bbd33
commit
7124585602
17 files changed
+93
-73
No files matched your search
@@ -40,6 +40,7 @@ public final class CarbonChat extends JavaPlugin {
|
||||
private ItemStackUtils itemStackUtils;
|
||||
|
||||
private YamlConfiguration modConfig;
|
||||
private YamlConfiguration languageConfig;
|
||||
|
||||
public static final LegacyComponentSerializer LEGACY =
|
||||
LegacyComponentSerializer.builder().extractUrls().character('§').build();
|
||||
@@ -47,8 +48,17 @@ public final class CarbonChat extends JavaPlugin {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Ensure config is present to be modified by the user
|
||||
saveDefaultConfig();
|
||||
saveResource("moderation.yml", false);
|
||||
if (!(new File(getDataFolder(), "config.yml").exists())) {
|
||||
saveDefaultConfig();
|
||||
}
|
||||
|
||||
if (!(new File(getDataFolder(), "moderation.yml").exists())) {
|
||||
saveResource("moderation.yml", false);
|
||||
}
|
||||
|
||||
if (!(new File(getDataFolder(), "language.yml").exists())) {
|
||||
saveResource("language.yml", false);
|
||||
}
|
||||
|
||||
modConfig = new YamlConfiguration();
|
||||
|
||||
@@ -58,6 +68,14 @@ public final class CarbonChat extends JavaPlugin {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
languageConfig = new YamlConfiguration();
|
||||
|
||||
try {
|
||||
languageConfig.load(new File(getDataFolder(), "language.yml"));
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Setup Adventure
|
||||
adventureManager = new AdventureManager(this);
|
||||
|
||||
@@ -147,6 +165,10 @@ public final class CarbonChat extends JavaPlugin {
|
||||
return modConfig;
|
||||
}
|
||||
|
||||
public YamlConfiguration getLanguage() {
|
||||
return languageConfig;
|
||||
}
|
||||
|
||||
public Permission getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class ChatReloadCommand extends BaseCommand {
|
||||
|
||||
carbonChat.getChannelManager().reload();
|
||||
|
||||
Component message = carbonChat.getAdventureManager().processMessage(carbonChat.getConfig().getString("language.reloaded"),
|
||||
Component message = carbonChat.getAdventureManager().processMessage(carbonChat.getLanguage().getString("reloaded"),
|
||||
"br", "\n");
|
||||
|
||||
carbonChat.getAdventureManager().getAudiences().audience(sender).sendMessage(message);
|
||||
|
||||
@@ -36,12 +36,12 @@ public class ClearChatCommand extends BaseCommand {
|
||||
}
|
||||
|
||||
if (player.hasPermission("carbonchat.clearchat.notify")) {
|
||||
String message = carbonChat.getConfig().getString("language.clear-notify");
|
||||
String message = carbonChat.getLanguage().getString("clear-notify");
|
||||
audience.sendMessage(carbonChat.getAdventureManager().processMessage(message, "player", issuer.getName()));
|
||||
}
|
||||
|
||||
if (player.hasPermission("carbonchat.clearchat.exempt")) {
|
||||
String message = carbonChat.getConfig().getString("language.clear-exempt");
|
||||
String message = carbonChat.getLanguage().getString("clear-exempt");
|
||||
audience.sendMessage(carbonChat.getAdventureManager().processMessage(message, "player", issuer.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,16 +24,16 @@ public class IgnoreCommand extends BaseCommand {
|
||||
|
||||
if (user.isIgnoringUser(targetUser)) {
|
||||
user.setIgnoringUser(targetUser, false);
|
||||
user.sendMessage(processMessage(player, carbonChat.getConfig().getString("language.not-ignoring-user")));
|
||||
user.sendMessage(processMessage(player, carbonChat.getLanguage().getString("not-ignoring-user")));
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
||||
Permission permission = carbonChat.getPermission();
|
||||
|
||||
if (permission.playerHas(null, targetUser.asOfflinePlayer(), "carbonchat.ignore.exempt")) {
|
||||
user.sendMessage(processMessage(player, carbonChat.getConfig().getString("language.ignore-exempt")));
|
||||
user.sendMessage(processMessage(player, carbonChat.getLanguage().getString("ignore-exempt")));
|
||||
} else {
|
||||
user.setIgnoringUser(targetUser, true);
|
||||
user.sendMessage(processMessage(player, carbonChat.getConfig().getString("language.ignoring-user")));
|
||||
user.sendMessage(processMessage(player, carbonChat.getLanguage().getString("ignoring-user")));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public class MeCommand extends BaseCommand {
|
||||
}
|
||||
|
||||
String message = String.join(" ", args).replace("</pre>", "");
|
||||
String format = PlaceholderAPI.setPlaceholders(player, carbonChat.getConfig().getString("language.me"));
|
||||
String format = PlaceholderAPI.setPlaceholders(player, carbonChat.getLanguage().getString("me"));
|
||||
|
||||
if (!player.hasPermission("carbonchat.me.formatting")) {
|
||||
format = format.replace("<message>", "<pre><message></pre>");
|
||||
|
||||
@@ -25,7 +25,7 @@ public class MuteCommand extends BaseCommand {
|
||||
|
||||
if (targetUser.isMuted()) {
|
||||
targetUser.setMuted(false);
|
||||
String format = carbonChat.getConfig().getString("language.no-longer-muted");
|
||||
String format = carbonChat.getLanguage().getString("no-longer-muted");
|
||||
|
||||
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||
"player", targetUser.asOfflinePlayer().getName());
|
||||
@@ -37,10 +37,10 @@ public class MuteCommand extends BaseCommand {
|
||||
String format;
|
||||
|
||||
if (permission.playerHas(null, targetUser.asOfflinePlayer(), "carbonchat.mute.exempt")) {
|
||||
format = carbonChat.getConfig().getString("language.mute-exempt");
|
||||
format = carbonChat.getLanguage().getString("mute-exempt");
|
||||
} else {
|
||||
targetUser.setMuted(true);
|
||||
format = carbonChat.getConfig().getString("language.is-now-muted");
|
||||
format = carbonChat.getLanguage().getString("is-now-muted");
|
||||
}
|
||||
|
||||
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||
|
||||
@@ -39,9 +39,9 @@ public class NicknameCommand extends BaseCommand {
|
||||
String message;
|
||||
|
||||
if (nickname == null) {
|
||||
message = carbonChat.getConfig().getString("language.other-nickname-reset");
|
||||
message = carbonChat.getLanguage().getString("other-nickname-reset");
|
||||
} else {
|
||||
message = carbonChat.getConfig().getString("language.other-nickname-set");
|
||||
message = carbonChat.getLanguage().getString("other-nickname-set");
|
||||
}
|
||||
|
||||
sender.sendMessage(carbonChat.getAdventureManager().processMessage(
|
||||
@@ -53,9 +53,9 @@ public class NicknameCommand extends BaseCommand {
|
||||
String message;
|
||||
|
||||
if (nickname == null) {
|
||||
message = carbonChat.getConfig().getString("language.nickname-reset");
|
||||
message = carbonChat.getLanguage().getString("nickname-reset");
|
||||
} else {
|
||||
message = carbonChat.getConfig().getString("language.nickname-set");
|
||||
message = carbonChat.getLanguage().getString("nickname-set");
|
||||
}
|
||||
|
||||
sender.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player,
|
||||
|
||||
@@ -24,7 +24,7 @@ public class ReplyCommand extends BaseCommand {
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
|
||||
if (user.getReplyTarget() == null) {
|
||||
String message = carbonChat.getConfig().getString("language.no-reply-target");
|
||||
String message = carbonChat.getLanguage().getString("no-reply-target");
|
||||
Component component = carbonChat.getAdventureManager().processMessage(message, "br", "\n");
|
||||
user.sendMessage(component);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public class SetColorCommand extends BaseCommand {
|
||||
|
||||
settings.setColor(TextColor.fromHexString(color));
|
||||
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, carbonChat.getConfig().getString("language.channel-color-set"),
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, carbonChat.getLanguage().getString("channel-color-set"),
|
||||
"br", "\n", "color", "<color:" + color + ">", "channel", channel.getName(), "hex", color));
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public class ShadowMuteCommand extends BaseCommand {
|
||||
|
||||
if (targetUser.isShadowMuted()) {
|
||||
targetUser.setShadowMuted(false);
|
||||
String format = carbonChat.getConfig().getString("language.no-longer-shadow-muted");
|
||||
String format = carbonChat.getLanguage().getString("no-longer-shadow-muted");
|
||||
|
||||
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||
"player", targetUser.asOfflinePlayer().getName());
|
||||
@@ -37,10 +37,10 @@ public class ShadowMuteCommand extends BaseCommand {
|
||||
String format;
|
||||
|
||||
if (permission.playerHas(null, targetUser.asOfflinePlayer(), "carbonchat.shadowmute.exempt")) {
|
||||
format = carbonChat.getConfig().getString("language.shadow-mute-exempt");
|
||||
format = carbonChat.getLanguage().getString("shadow-mute-exempt");
|
||||
} else {
|
||||
targetUser.setShadowMuted(true);
|
||||
format = carbonChat.getConfig().getString("language.is-now-shadow-muted");
|
||||
format = carbonChat.getLanguage().getString("is-now-shadow-muted");
|
||||
}
|
||||
|
||||
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||
|
||||
@@ -27,10 +27,10 @@ public class SpyChannelCommand extends BaseCommand {
|
||||
|
||||
if (settings.isSpying()) {
|
||||
settings.setSpying(false);
|
||||
message = carbonChat.getConfig().getString("language.spy-toggled-off");
|
||||
message = carbonChat.getLanguage().getString("spy-toggled-off");
|
||||
} else {
|
||||
settings.setSpying(true);
|
||||
message = carbonChat.getConfig().getString("language.spy-toggled-on");
|
||||
message = carbonChat.getLanguage().getString("spy-toggled-on");
|
||||
}
|
||||
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n",
|
||||
@@ -45,10 +45,10 @@ public class SpyChannelCommand extends BaseCommand {
|
||||
|
||||
if (user.isSpyingWhispers()) {
|
||||
user.setSpyingWhispers(false);
|
||||
message = carbonChat.getConfig().getString("language.spy-whispers-off");
|
||||
message = carbonChat.getLanguage().getString("spy-whispers-off");
|
||||
} else {
|
||||
user.setSpyingWhispers(true);
|
||||
message = carbonChat.getConfig().getString("language.spy-whispers-on");
|
||||
message = carbonChat.getLanguage().getString("spy-whispers-on");
|
||||
}
|
||||
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n"));
|
||||
|
||||
@@ -23,7 +23,7 @@ public class AdventureManager {
|
||||
}
|
||||
|
||||
public Component processMessage(String input, String... placeholders) {
|
||||
switch (carbonChat.getConfig().getString("formatting.type", "minimessage").toLowerCase()) {
|
||||
switch (carbonChat.getLanguage().getString("formatting.type", "minimessage").toLowerCase()) {
|
||||
case "minedown":
|
||||
return processMineDown(input, placeholders);
|
||||
case "minimessage-markdown":
|
||||
|
||||
@@ -61,7 +61,7 @@ public class CommandManager {
|
||||
|
||||
commandManager.getCommandConditions().addCondition(ChatChannel.class,"canuse", (context, execution, value) -> {
|
||||
if (value == null) {
|
||||
throw new ConditionFailedException(carbonChat.getConfig().getString("language.cannot-use-channel"));
|
||||
throw new ConditionFailedException(carbonChat.getLanguage().getString("cannot-use-channel"));
|
||||
}
|
||||
|
||||
ChatUser user = carbonChat.getUserService().wrap(context.getIssuer().getPlayer());
|
||||
@@ -73,7 +73,7 @@ public class CommandManager {
|
||||
|
||||
commandManager.getCommandConditions().addCondition(ChatChannel.class,"exists", (context, execution, value) -> {
|
||||
if (value == null) {
|
||||
throw new ConditionFailedException(carbonChat.getConfig().getString("language.cannot-use-channel"));
|
||||
throw new ConditionFailedException(carbonChat.getLanguage().getString("cannot-use-channel"));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ public class MessageManager {
|
||||
user.setNickname(nickname, true);
|
||||
|
||||
if (user.isOnline()) {
|
||||
String message = carbonChat.getConfig().getString("language.nickname-set");
|
||||
String message = carbonChat.getLanguage().getString("nickname-set");
|
||||
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(user.asPlayer(),
|
||||
message, "nickname", nickname));
|
||||
@@ -69,7 +69,7 @@ public class MessageManager {
|
||||
user.setNickname(null, true);
|
||||
|
||||
if (user.isOnline()) {
|
||||
String message = carbonChat.getConfig().getString("language.nickname-reset");
|
||||
String message = carbonChat.getLanguage().getString("nickname-reset");
|
||||
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(user.asPlayer(), message));
|
||||
}
|
||||
|
||||
@@ -246,8 +246,8 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
||||
return;
|
||||
}
|
||||
|
||||
String toPlayerFormat = carbonChat.getConfig().getString("language.message-to-other");
|
||||
String fromPlayerFormat = carbonChat.getConfig().getString("language.message-from-other");
|
||||
String toPlayerFormat = carbonChat.getLanguage().getString("message-to-other");
|
||||
String fromPlayerFormat = carbonChat.getLanguage().getString("message-from-other");
|
||||
|
||||
String senderName = sender.asOfflinePlayer().getName();
|
||||
String senderOfflineName = senderName;
|
||||
@@ -325,7 +325,7 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
||||
continue;
|
||||
}
|
||||
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessage(carbonChat.getConfig().getString("language.spy-whispers"),
|
||||
user.sendMessage(carbonChat.getAdventureManager().processMessage(carbonChat.getLanguage().getString("spy-whispers"),
|
||||
"br", "\n", "message", message,
|
||||
"targetname", targetOfflineName, "sendername", senderOfflineName,
|
||||
"target", targetName, "sender", senderName));
|
||||
|
||||
@@ -95,46 +95,6 @@ channels:
|
||||
should-bungee: false
|
||||
message-prefix: '!'
|
||||
|
||||
# Options:
|
||||
# 'MiniMessage': https://github.com/KyoriPowered/adventure-docs/blob/feature/minimessage/source/minimessage.rst#the-components
|
||||
# 'MiniMessage-Markdown': https://github.com/KyoriPowered/adventure-docs/blob/feature/minimessage/source/minimessage.rst#markdown
|
||||
# 'MineDown': https://github.com/Phoenix616/MineDown#syntax
|
||||
# Note that the messages provided in the default config utilise MiniMessage, and need to be changed if you're using MineDown
|
||||
formatting:
|
||||
type: 'MiniMessage'
|
||||
|
||||
language:
|
||||
# The following messages are only compatible with MiniMessage/MineDown
|
||||
reloaded: '<yellow>Chat config has been reloaded!'
|
||||
message-to-other: '<green>[<gray>Me <gold>-> <gray><target><reset><green>] <message>'
|
||||
message-from-other: '<green>[<gray><sender><reset> <gold>-> <gray>Me<green>] <message>'
|
||||
spy-whispers: '<yellow>Spy [<gray><sender><reset> <gold>-> <gray><target><reset><yellow>] <message>'
|
||||
no-reply-target: '<red>You have no one to reply to!'
|
||||
empty-channel: 'NONE' #<channel>, set to "NONE" to disable
|
||||
other-nickname-set: '<green><user><reset>''s nickname was set to <nickname><green>!'
|
||||
other-nickname-reset: '<green><user><reset>''s nickname was reset!'
|
||||
|
||||
# The following messages are compatible with PlaceholderAPI and MiniMessage/MineDown
|
||||
me: '<italic><dark_purple>*<displayname> <reset><message>*</dark_purple></italic>'
|
||||
ignoring-user: '<green>You are now ignoring <gold><player><reset><green>!'
|
||||
not-ignoring-user: '<green>You are no longer ignoring <gold><player><reset><green>!'
|
||||
ignore-exempt: '<red>User <player> <red>is exempt from being ignored!'
|
||||
channel-color-set: '<green>You have set <color><channel> <green>color to <hex>!'
|
||||
spy-toggled-on: '<gray>You are now spying on <color><channel> <gray>chat!'
|
||||
spy-toggled-off: '<gray>You are no longer spying on <color><channel> <gray>chat!'
|
||||
spy-whispers-on: '<gray>You are now spying on whispers!'
|
||||
spy-whispers-off: '<gray>You are no longer spying on whispers!'
|
||||
nickname-set: '<green>Your nickname was set to <nickname><reset><green>!'
|
||||
nickname-reset: '<green>Your nickname was reset!'
|
||||
is-now-shadow-muted: '<yellow>Player <player> is now shadow muted!'
|
||||
no-longer-shadow-muted: '<yellow>Player <player> is no longer shadow muted!'
|
||||
shadow-mute-exempt: '<red>Player <player> is exempt from being shadow muted!'
|
||||
is-now-muted: '<yellow>Player <player> is now muted!'
|
||||
no-longer-muted: '<yellow>Player <player> is no longer muted!'
|
||||
mute-exempt: '<red>Player <player> is exempt from being muted!'
|
||||
clear-notify: '<yellow>Chat has been cleared by <player>.'
|
||||
clear-exempt: '<yellow>You were exempt from the clear due to your permissions!'
|
||||
|
||||
contexts:
|
||||
Towny:
|
||||
cancellation-message: '<red>You do not belong to a town!'
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
# Options:
|
||||
# 'MiniMessage': https://github.com/KyoriPowered/adventure-docs/blob/feature/minimessage/source/minimessage.rst#the-components
|
||||
# 'MiniMessage-Markdown': https://github.com/KyoriPowered/adventure-docs/blob/feature/minimessage/source/minimessage.rst#markdown
|
||||
# 'MineDown': https://github.com/Phoenix616/MineDown#syntax
|
||||
# Note that the messages provided in the default config utilise MiniMessage, and need to be changed if you're using MineDown
|
||||
formatting:
|
||||
type: 'MiniMessage'
|
||||
|
||||
# The following messages are only compatible with MiniMessage/MineDown
|
||||
reloaded: '<yellow>Chat config has been reloaded!'
|
||||
message-to-other: '<green>[<gray>Me <gold>-> <gray><target><reset><green>] <message>'
|
||||
message-from-other: '<green>[<gray><sender><reset> <gold>-> <gray>Me<green>] <message>'
|
||||
spy-whispers: '<yellow>Spy [<gray><sender><reset> <gold>-> <gray><target><reset><yellow>] <message>'
|
||||
no-reply-target: '<red>You have no one to reply to!'
|
||||
empty-channel: 'NONE' #<channel>, set to "NONE" to disable
|
||||
other-nickname-set: '<green><user><reset>''s nickname was set to <nickname><green>!'
|
||||
other-nickname-reset: '<green><user><reset>''s nickname was reset!'
|
||||
|
||||
# The following messages are compatible with PlaceholderAPI and MiniMessage/MineDown
|
||||
me: '<italic><dark_purple>*<displayname> <reset><message>*</dark_purple></italic>'
|
||||
ignoring-user: '<green>You are now ignoring <gold><player><reset><green>!'
|
||||
not-ignoring-user: '<green>You are no longer ignoring <gold><player><reset><green>!'
|
||||
ignore-exempt: '<red>User <player> <red>is exempt from being ignored!'
|
||||
channel-color-set: '<green>You have set <color><channel> <green>color to <hex>!'
|
||||
spy-toggled-on: '<gray>You are now spying on <color><channel> <gray>chat!'
|
||||
spy-toggled-off: '<gray>You are no longer spying on <color><channel> <gray>chat!'
|
||||
spy-whispers-on: '<gray>You are now spying on whispers!'
|
||||
spy-whispers-off: '<gray>You are no longer spying on whispers!'
|
||||
nickname-set: '<green>Your nickname was set to <nickname><reset><green>!'
|
||||
nickname-reset: '<green>Your nickname was reset!'
|
||||
is-now-shadow-muted: '<yellow>Player <player> is now shadow muted!'
|
||||
no-longer-shadow-muted: '<yellow>Player <player> is no longer shadow muted!'
|
||||
shadow-mute-exempt: '<red>Player <player> is exempt from being shadow muted!'
|
||||
is-now-muted: '<yellow>Player <player> is now muted!'
|
||||
no-longer-muted: '<yellow>Player <player> is no longer muted!'
|
||||
mute-exempt: '<red>Player <player> is exempt from being muted!'
|
||||
clear-notify: '<yellow>Chat has been cleared by <player>.'
|
||||
clear-exempt: '<yellow>You were exempt from the clear due to your permissions!'
|
||||
Reference in new issue
Block a user