@@ -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
0 commit comments