Skip to content

Commit 86d2e2a

Browse files
default config options, display chat in console config option and info output formatting
1 parent 7812f44 commit 86d2e2a

File tree

5 files changed

+68
-65
lines changed

5 files changed

+68
-65
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>org.zeroBzeroT.chatCo</groupId>
77
<artifactId>ChatCoPlus</artifactId>
8-
<version>0.27.2</version>
8+
<version>0.27.3</version>
99
<packaging>jar</packaging>
1010
<name>${project.artifactId}</name>
1111

src/main/java/org/zeroBzeroT/chatCo/Main.java

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,22 @@ public class Main extends JavaPlugin {
2121
public static File PermissionConfig;
2222
public static File WhisperLog;
2323
public static File dataFolder;
24-
private static File Configuration;
2524
private static File Help;
2625
public Collection<ChatPlayer> playerList;
27-
public boolean checkForChatDisable;
28-
public boolean checkForIgnores;
2926

3027
public void onDisable() {
3128
playerList.clear();
3229
}
3330

3431
public void onEnable() {
3532
playerList = Collections.synchronizedCollection(new ArrayList<>());
36-
checkForChatDisable = getConfig().getBoolean("ChatCo.chatDisableEnabled", true);
37-
checkForIgnores = getConfig().getBoolean("ChatCo.ignoresEnabled", true);
3833

39-
checkFiles();
40-
readConfig(0);
34+
// Config defaults
35+
getConfig().options().copyDefaults(true);
36+
getConfig().options().copyHeader(true);
37+
38+
saveResourceFiles();
39+
toggleConfigValue(0);
4140

4241
final PluginManager pm = getServer().getPluginManager();
4342

@@ -47,7 +46,7 @@ public void onEnable() {
4746
pm.registerEvents(new Whispers(this), this);
4847
}
4948

50-
if (getConfig().getBoolean("ChatCo.SpoilersEnabled", false)) {
49+
if (getConfig().getBoolean("ChatCo.spoilersEnabled", false)) {
5150
pm.registerEvents(new Spoilers(), this);
5251
}
5352

@@ -57,13 +56,13 @@ public void onEnable() {
5756
}
5857
}
5958

60-
private void readConfig(final int change) {
59+
private void toggleConfigValue(final int change) {
6160
switch (change) {
6261
case 3:
63-
getConfig().set("ChatCo.SpoilersEnabled", true);
62+
getConfig().set("ChatCo.spoilersEnabled", true);
6463
break;
6564
case 4:
66-
getConfig().set("ChatCo.SpoilersEnabled", false);
65+
getConfig().set("ChatCo.spoilersEnabled", false);
6766
break;
6867
case 5:
6968
getConfig().set("ChatCo.whisperChangesEnabled", true);
@@ -90,9 +89,8 @@ private void readConfig(final int change) {
9089
}
9190

9291
@SuppressWarnings("ResultOfMethodCallIgnored")
93-
private void checkFiles() {
92+
private void saveResourceFiles() {
9493
Main.dataFolder = getDataFolder();
95-
Main.Configuration = new File(Main.dataFolder, "config.yml");
9694
Main.PermissionConfig = new File(Main.dataFolder, "permissionConfig.yml");
9795
Main.WhisperLog = new File(Main.dataFolder, "whisperlog.txt");
9896
Main.Help = new File(Main.dataFolder, "help.txt");
@@ -107,9 +105,8 @@ private void checkFiles() {
107105
saveStreamToFile(getResource("help.txt"), Main.Help);
108106
}
109107

110-
if (!Main.Configuration.exists()) {
111-
saveDefaultConfig();
112-
}
108+
// Save the default config file, if it does not exist
109+
saveDefaultConfig();
113110

114111
if (!Main.PermissionConfig.exists()) {
115112
Main.PermissionConfig.getParentFile().mkdirs();
@@ -121,16 +118,16 @@ public boolean onCommand(final CommandSender sender, final Command cmd, final St
121118
if (sender instanceof Player) {
122119
if (cmd.getName().equalsIgnoreCase("togglechat") && getConfig().getBoolean("toggleChatEnabled", true)) {
123120
if (toggleChat((Player) sender)) {
124-
sender.sendMessage(ChatColor.RED + "Your chat is now disabled until you type /togglechat or relog");
121+
sender.sendMessage(ChatColor.RED + "Your chat is now disabled until you type /togglechat or relog.");
125122
} else {
126-
sender.sendMessage(ChatColor.RED + "Your chat has been re-enabled, type /togglechat to disable it again");
123+
sender.sendMessage(ChatColor.RED + "Your chat has been re-enabled, type /togglechat to disable it again.");
127124
}
128125
return true;
129126
} else if (cmd.getName().equalsIgnoreCase("toggletells")) {
130127
if (toggleTells((Player) sender)) {
131-
sender.sendMessage(ChatColor.RED + "You will no longer receive tells, type /toggletells to see them again");
128+
sender.sendMessage(ChatColor.RED + "You will no longer receive tells, type /toggletells to see them again.");
132129
} else {
133-
sender.sendMessage(ChatColor.RED + "You now receive tells, type /toggletells to disable them again");
130+
sender.sendMessage(ChatColor.RED + "You now receive tells, type /toggletells to disable them again.");
134131
}
135132
return true;
136133
} else if (cmd.getName().equalsIgnoreCase("unignoreall") && getConfig().getBoolean("ignoresEnabled", true)) {
@@ -143,19 +140,19 @@ public boolean onCommand(final CommandSender sender, final Command cmd, final St
143140
} else if (cmd.getName().equalsIgnoreCase("ignore") && getConfig().getBoolean("ignoresEnabled", true)) {
144141
try {
145142
if (args.length < 1) {
146-
sender.sendMessage(ChatColor.RED + "You forgot to type the name of the player");
143+
sender.sendMessage(ChatColor.RED + "You forgot to type the name of the player.");
147144
return true;
148145
}
149146

150147
if (args[0].length() > 16) {
151-
sender.sendMessage(ChatColor.RED + "You entered an invalid player name");
148+
sender.sendMessage(ChatColor.RED + "You entered an invalid player name.");
152149
return true;
153150
}
154151

155152
final Player ignorable = Bukkit.getServer().getPlayer(args[0]);
156153

157154
if (ignorable == null) {
158-
sender.sendMessage(ChatColor.RED + "You have entered a player who does not exist or is offline");
155+
sender.sendMessage(ChatColor.RED + "You have entered a player who does not exist or is offline.");
159156
return true;
160157
}
161158

@@ -165,15 +162,15 @@ public boolean onCommand(final CommandSender sender, final Command cmd, final St
165162
e.printStackTrace();
166163
}
167164
} else if (cmd.getName().equalsIgnoreCase("ignorelist") && getConfig().getBoolean("ignoresEnabled", true)) {
168-
sender.sendMessage(ChatColor.WHITE + "Ignored players:");
165+
sender.sendMessage(ChatColor.YELLOW + "Ignored players:");
169166
int i = 0;
170167

171168
for (final String ignores : getChatPlayer((Player) sender).getIgnoreList()) {
172-
sender.sendMessage(ChatColor.WHITE + "" + ChatColor.ITALIC + ignores);
169+
sender.sendMessage(ChatColor.YELLOW + "" + ChatColor.ITALIC + ignores);
173170
++i;
174171
}
175172

176-
sender.sendMessage(ChatColor.WHITE + "" + i + " players ignored");
173+
sender.sendMessage(ChatColor.YELLOW + "" + i + " players ignored.");
177174
return true;
178175
}
179176
}
@@ -189,40 +186,40 @@ public boolean onCommand(final CommandSender sender, final Command cmd, final St
189186
if (args.length >= 2) {
190187
if (args[0].equalsIgnoreCase("spoilers")) {
191188
if (args[1].equalsIgnoreCase("e")) {
192-
readConfig(3);
189+
toggleConfigValue(3);
193190
sender.sendMessage("Spoilers enabled");
194191
} else if (args[1].equalsIgnoreCase("d")) {
195-
readConfig(4);
192+
toggleConfigValue(4);
196193
sender.sendMessage("Spoilers disabled");
197194
}
198195
}
199196

200197
if (args[0].equalsIgnoreCase("whispers")) {
201198
if (args[1].equalsIgnoreCase("e")) {
202-
readConfig(5);
199+
toggleConfigValue(5);
203200
sender.sendMessage("Whisper changes enabled");
204201
} else if (args[1].equalsIgnoreCase("d")) {
205-
readConfig(6);
202+
toggleConfigValue(6);
206203
sender.sendMessage("Whisper changes disabled");
207204
}
208205
}
209206

210207
if (args[0].equalsIgnoreCase("newcommands")) {
211208
if (args[1].equalsIgnoreCase("e")) {
212-
readConfig(7);
209+
toggleConfigValue(7);
213210
sender.sendMessage("New Whisper commands enabled");
214211
} else if (args[1].equalsIgnoreCase("d")) {
215-
readConfig(8);
212+
toggleConfigValue(8);
216213
sender.sendMessage("New whisper commands disabled");
217214
}
218215
}
219216

220217
if (args[0].equalsIgnoreCase("whisperlog")) {
221218
if (args[1].equalsIgnoreCase("e")) {
222-
readConfig(9);
219+
toggleConfigValue(9);
223220
sender.sendMessage("Whisper logging enabled");
224221
} else if (args[1].equalsIgnoreCase("d")) {
225-
readConfig(10);
222+
toggleConfigValue(10);
226223
sender.sendMessage("Whisper logging disabled");
227224
}
228225
}
@@ -270,12 +267,12 @@ private boolean toggleTells(final Player p) {
270267
}
271268

272269
private void ignorePlayer(final Player p, final String target) throws IOException {
273-
String message = ChatColor.WHITE + "Chat messages from " + target + " will be ";
270+
String message = ChatColor.YELLOW + "Chat messages from " + target + " will be ";
274271

275272
if (getChatPlayer(p).isIgnored(target)) {
276-
message += "shown";
273+
message += "shown.";
277274
} else {
278-
message += "hidden";
275+
message += "hidden.";
279276
}
280277

281278
p.sendMessage(message);
@@ -284,7 +281,7 @@ private void ignorePlayer(final Player p, final String target) throws IOExceptio
284281

285282
private void unIgnoreAll(final Player p) throws IOException {
286283
getChatPlayer(p).unIgnoreAll();
287-
String message = ChatColor.WHITE + "Ignore list deleted";
284+
String message = ChatColor.YELLOW + "Ignore list deleted.";
288285
p.sendMessage(message);
289286
}
290287

src/main/java/org/zeroBzeroT/chatCo/PublicChat.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ public class PublicChat implements Listener {
2525
public PublicChat(final Main plugin) {
2626
this.plugin = plugin;
2727
File customConfig = Main.PermissionConfig;
28-
this.permissionConfig = YamlConfiguration.loadConfiguration(customConfig);
28+
permissionConfig = YamlConfiguration.loadConfiguration(customConfig);
2929
}
3030

3131
public String replacePrefixColors(String message, final Player player) {
3232
for (ChatColor color : ChatColor.values()) {
33-
if (this.plugin.getConfig().getString("ChatCo.chatPrefixes." + color.name()) != null && message.startsWith(this.plugin.getConfig().getString("ChatCo.chatPrefixes." + color.name()))) {
33+
if (plugin.getConfig().getString("ChatCo.chatPrefixes." + color.name()) != null && message.startsWith(plugin.getConfig().getString("ChatCo.chatPrefixes." + color.name()))) {
3434

3535
// check for global or player permission
36-
if (this.permissionConfig.getBoolean("ChatCo.chatPrefixes." + color.name(), false) || player.hasPermission("ChatCo.chatPrefixes." + color.name())) {
36+
if (permissionConfig.getBoolean("ChatCo.chatPrefixes." + color.name(), false) || player.hasPermission("ChatCo.chatPrefixes." + color.name())) {
3737
message = color + message;
3838
}
3939

@@ -47,9 +47,9 @@ public String replacePrefixColors(String message, final Player player) {
4747

4848
public String replaceInlineColors(String message, final Player player) {
4949
for (ChatColor color : ChatColor.values()) {
50-
if ((this.permissionConfig.getBoolean("ChatCo.chatColors." + color.name(), false) || player.hasPermission("ChatCo.chatColors." + color.name()))
51-
&& this.plugin.getConfig().getString("ChatCo.chatColors." + color.name()) != null) {
52-
message = message.replace(this.plugin.getConfig().getString("ChatCo.chatColors." + color.name()), color.toString());
50+
if ((permissionConfig.getBoolean("ChatCo.chatColors." + color.name(), false) || player.hasPermission("ChatCo.chatColors." + color.name()))
51+
&& plugin.getConfig().getString("ChatCo.chatColors." + color.name()) != null) {
52+
message = message.replace(plugin.getConfig().getString("ChatCo.chatColors." + color.name()), color.toString());
5353
}
5454
}
5555

@@ -66,8 +66,8 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) {
6666

6767
// Plain message
6868
final Player player = event.getPlayer();
69-
String legacyMessage = this.replacePrefixColors(event.getMessage(), player);
70-
legacyMessage = this.replaceInlineColors(legacyMessage, player);
69+
String legacyMessage = replacePrefixColors(event.getMessage(), player);
70+
legacyMessage = replaceInlineColors(legacyMessage, player);
7171

7272
// Do not send empty messages
7373
if (ChatColor.stripColor(legacyMessage).trim().length() == 0) {
@@ -91,13 +91,17 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) {
9191
message.addExtra(componentFromLegacyText("> "));
9292
message.addExtra(messageText);
9393

94+
// Send to console
95+
if (plugin.getConfig().getBoolean("ChatCo.chatToConsole", true))
96+
plugin.getLogger().info(message.toLegacyText());
97+
9498
// Send to the players
9599
for (Player recipient : event.getRecipients()) {
96100
try {
97-
ChatPlayer chatPlayer = this.plugin.getChatPlayer(recipient);
101+
ChatPlayer chatPlayer = plugin.getChatPlayer(recipient);
98102

99-
if ((!chatPlayer.chatDisabled || !this.plugin.checkForChatDisable) &&
100-
(!chatPlayer.isIgnored(player.getName()) || !this.plugin.checkForIgnores)) {
103+
if ((!chatPlayer.chatDisabled || !plugin.getConfig().getBoolean("ChatCo.chatDisableEnabled", true)) &&
104+
(!chatPlayer.isIgnored(player.getName()) || !plugin.getConfig().getBoolean("ChatCo.ignoresEnabled", true))) {
101105
recipient.spigot().sendMessage(message);
102106
}
103107

@@ -109,11 +113,11 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) {
109113

110114
@EventHandler
111115
public void onPlayerQuit(final PlayerQuitEvent e) {
112-
this.plugin.remove(e.getPlayer());
116+
plugin.remove(e.getPlayer());
113117
}
114118

115119
@EventHandler
116120
public void onPlayerKick(final PlayerKickEvent e) {
117-
this.plugin.remove(e.getPlayer());
121+
plugin.remove(e.getPlayer());
118122
}
119123
}

src/main/java/org/zeroBzeroT/chatCo/Whispers.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event)
3838

3939
if (plugin.getConfig().getBoolean("ChatCo.lastCommand", true) && (args[0].equalsIgnoreCase("/l") || args[0].equalsIgnoreCase("/last"))) {
4040
if (args.length == 1) {
41-
sender.sendMessage(ChatColor.WHITE + "Usage: /l <message>");
41+
sender.sendMessage(ChatColor.YELLOW + "Usage: /l <message>");
4242
event.setCancelled(true);
4343
return;
4444
}
@@ -47,9 +47,9 @@ public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event)
4747

4848
if ((target == null && plugin.getChatPlayer(sender).LastReceiver != null)
4949
|| Utils.isVanished(target)) {
50-
sender.sendMessage(ChatColor.RED + "The last person you sent a private message to is offline");
50+
sender.sendMessage(ChatColor.RED + "The last person you sent a private message to is offline.");
5151
} else if (target == null) {
52-
sender.sendMessage(ChatColor.RED + "You have not initiated any private message in this session");
52+
sender.sendMessage(ChatColor.RED + "You have not initiated any private message in this session.");
5353
} else {
5454
String message = Arrays.stream(args).skip(1).collect(Collectors.joining(" "));
5555
sendPrivateMessage(sender, target, message);
@@ -58,7 +58,7 @@ public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event)
5858
event.setCancelled(true);
5959
} else if (plugin.getConfig().getBoolean("ChatCo.replyCommands", true) && (args[0].equalsIgnoreCase("/r") || args[0].equalsIgnoreCase("/reply"))) {
6060
if (args.length == 1) {
61-
sender.sendMessage(ChatColor.WHITE + "Usage: /r <message>");
61+
sender.sendMessage(ChatColor.YELLOW + "Usage: /r <message>");
6262
event.setCancelled(true);
6363
return;
6464
}
@@ -67,9 +67,9 @@ public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event)
6767

6868
if ((target == null && plugin.getChatPlayer(sender).LastMessenger != null)
6969
|| Utils.isVanished(target)) {
70-
sender.sendMessage(ChatColor.RED + "The last person you received a private message from is offline");
70+
sender.sendMessage(ChatColor.RED + "The last person you received a private message from is offline.");
7171
} else if (target == null) {
72-
sender.sendMessage(ChatColor.RED + "You have not received any private messages in this session");
72+
sender.sendMessage(ChatColor.RED + "You have not received any private messages in this session.");
7373
} else {
7474
String message = Arrays.stream(args).skip(1).collect(Collectors.joining(" "));
7575
sendPrivateMessage(sender, target, message);
@@ -78,15 +78,15 @@ public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event)
7878
event.setCancelled(true);
7979
} else if (args[0].equalsIgnoreCase("/tell") || args[0].equalsIgnoreCase("/msg") || args[0].equalsIgnoreCase("/t") || args[0].equalsIgnoreCase("/w") || args[0].equalsIgnoreCase("/whisper") || args[0].equalsIgnoreCase("/pm")) {
8080
if (args.length < 3) {
81-
sender.sendMessage(ChatColor.WHITE + "Usage: /w <player> <message>");
81+
sender.sendMessage(ChatColor.YELLOW + "Usage: /w <player> <message>");
8282
event.setCancelled(true);
8383
return;
8484
}
8585

8686
final Player target = Bukkit.getPlayerExact(args[1]);
8787

8888
if (target == null || Utils.isVanished(target)) {
89-
sender.sendMessage(ChatColor.RED + args[1] + " is offline");
89+
sender.sendMessage(ChatColor.RED + args[1] + " is offline.");
9090
event.setCancelled(true);
9191
return;
9292
}
@@ -173,9 +173,9 @@ private void sendPrivateMessage(Player sender, Player receiver, String message)
173173
sender.spigot().sendMessage(senderMessage);
174174

175175
if (isIgnoring && plugin.getConfig().getBoolean("ChatCo.ignoreMessageEnabled", true)) {
176-
sender.sendMessage(ChatColor.RED + receiver.getName() + " is ignoring you");
176+
sender.sendMessage(ChatColor.RED + receiver.getName() + " is ignoring you.");
177177
} else if (doNotSend && plugin.getConfig().getBoolean("ChatCo.chatDisabledMessageEnabled", true)) {
178-
sender.sendMessage(ChatColor.RED + receiver.getName() + "'s chat is disabled");
178+
sender.sendMessage(ChatColor.RED + receiver.getName() + "'s chat is disabled.");
179179
} else if (!doNotSend && !isIgnoring) {
180180
receiver.spigot().sendMessage(receiverMessage);
181181

0 commit comments

Comments
 (0)