|
@@ -0,0 +1,619 @@
|
|
1
|
+package com.ianonavy.disciplinerecord;
|
|
2
|
+
|
|
3
|
+import java.io.File;
|
|
4
|
+import java.io.FileOutputStream;
|
|
5
|
+import java.io.IOException;
|
|
6
|
+import java.io.InputStream;
|
|
7
|
+import java.io.OutputStream;
|
|
8
|
+import java.util.logging.Logger;
|
|
9
|
+
|
|
10
|
+import org.bukkit.Bukkit;
|
|
11
|
+import org.bukkit.ChatColor;
|
|
12
|
+import org.bukkit.Server;
|
|
13
|
+import org.bukkit.command.Command;
|
|
14
|
+import org.bukkit.command.CommandSender;
|
|
15
|
+import org.bukkit.configuration.file.FileConfiguration;
|
|
16
|
+import org.bukkit.configuration.file.YamlConfiguration;
|
|
17
|
+import org.bukkit.entity.Player;
|
|
18
|
+import org.bukkit.plugin.PluginDescriptionFile;
|
|
19
|
+import org.bukkit.plugin.java.JavaPlugin;
|
|
20
|
+
|
|
21
|
+/**
|
|
22
|
+ * Plugin for Minecraft Bukkit servers that manages a discipline record.
|
|
23
|
+ *
|
|
24
|
+ * @author ianonavy
|
|
25
|
+ * @version 1.0
|
|
26
|
+ */
|
|
27
|
+public class Main extends JavaPlugin {
|
|
28
|
+
|
|
29
|
+ boolean enabled;
|
|
30
|
+
|
|
31
|
+ // Get the logger
|
|
32
|
+ public final Logger logger = Logger.getLogger("Minecraft");
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+ // Configuration files
|
|
36
|
+ File configFile;
|
|
37
|
+ File recordFile;
|
|
38
|
+ FileConfiguration config;
|
|
39
|
+ FileConfiguration record;
|
|
40
|
+
|
|
41
|
+ Recorder recorder;
|
|
42
|
+
|
|
43
|
+ // Tag used for server logs.
|
|
44
|
+ static String pluginTag = ChatColor.YELLOW + "[Discipline Record] " + ChatColor.WHITE;
|
|
45
|
+
|
|
46
|
+ /**
|
|
47
|
+ * Constructor for the Discipline Record plugin.
|
|
48
|
+ */
|
|
49
|
+ public Main() {
|
|
50
|
+ enabled = true;
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+ /**
|
|
54
|
+ * Called when the plugin is disabled.
|
|
55
|
+ */
|
|
56
|
+ @Override
|
|
57
|
+ public void onDisable() {
|
|
58
|
+ saveYamls();
|
|
59
|
+ PluginDescriptionFile pdfFile = this.getDescription();
|
|
60
|
+ this.logger.info("[" + pdfFile.getName() + "] v. " + pdfFile.getVersion() + " disabled.");
|
|
61
|
+ }
|
|
62
|
+
|
|
63
|
+ /**
|
|
64
|
+ * Called when the plugin is enabled.
|
|
65
|
+ */
|
|
66
|
+ @Override
|
|
67
|
+ public void onEnable() {
|
|
68
|
+ PluginDescriptionFile pdfFile = this.getDescription();
|
|
69
|
+
|
|
70
|
+ // Open files.
|
|
71
|
+ configFile = new File(getDataFolder(), "config.yml");
|
|
72
|
+ recordFile = new File(getDataFolder(), "record.yml");
|
|
73
|
+
|
|
74
|
+ try {
|
|
75
|
+ firstRun();
|
|
76
|
+ } catch (Exception e) {
|
|
77
|
+ e.printStackTrace();
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+ // Load configuration and record.
|
|
81
|
+ config = new YamlConfiguration();
|
|
82
|
+ record = new YamlConfiguration();
|
|
83
|
+ loadYamls();
|
|
84
|
+
|
|
85
|
+ // Check enabled.
|
|
86
|
+ if (config.isSet("enabled")) {
|
|
87
|
+ if (!config.getBoolean("enabled", true)) {
|
|
88
|
+ this.logger.info("[" + pdfFile.getName() + "] v. " + pdfFile.getVersion() + " disabled in config.yml.");
|
|
89
|
+ enabled = false;
|
|
90
|
+ return;
|
|
91
|
+ }
|
|
92
|
+ } else {
|
|
93
|
+ config.set("enabled", true);
|
|
94
|
+ }
|
|
95
|
+ Server server = Bukkit.getServer();
|
|
96
|
+ recorder = new Recorder(server, (YamlConfiguration) config, (YamlConfiguration) record, configFile, recordFile);
|
|
97
|
+
|
|
98
|
+ enabled = true;
|
|
99
|
+ this.logger.info("[" + pdfFile.getName() + "] v. " + pdfFile.getVersion() + " enabled.");
|
|
100
|
+ }
|
|
101
|
+
|
|
102
|
+ /**
|
|
103
|
+ * Sets up the default config files for the first run.
|
|
104
|
+ */
|
|
105
|
+ private void firstRun() throws Exception {
|
|
106
|
+ if(!configFile.exists()){
|
|
107
|
+ configFile.getParentFile().mkdirs();
|
|
108
|
+ copy(getResource("config.yml"), configFile);
|
|
109
|
+ }
|
|
110
|
+ if(!recordFile.exists()){
|
|
111
|
+ recordFile.getParentFile().mkdirs();
|
|
112
|
+ copy(getResource("record.yml"), recordFile);
|
|
113
|
+ }
|
|
114
|
+ }
|
|
115
|
+
|
|
116
|
+ /**
|
|
117
|
+ * Copies a file from one to another
|
|
118
|
+ * @param in the input stream to copy the original file from
|
|
119
|
+ * @param file the output file that serves as the copy destination
|
|
120
|
+ */
|
|
121
|
+ private void copy(InputStream in, File file) {
|
|
122
|
+ try {
|
|
123
|
+ OutputStream out = new FileOutputStream(file);
|
|
124
|
+ byte[] buf = new byte[1024];
|
|
125
|
+ int len;
|
|
126
|
+ while((len=in.read(buf))>0){
|
|
127
|
+ out.write(buf,0,len);
|
|
128
|
+ }
|
|
129
|
+ out.close();
|
|
130
|
+ in.close();
|
|
131
|
+ } catch (Exception e) {
|
|
132
|
+ e.printStackTrace();
|
|
133
|
+ }
|
|
134
|
+ }
|
|
135
|
+
|
|
136
|
+ /**
|
|
137
|
+ * Saves the record YAML.
|
|
138
|
+ */
|
|
139
|
+ public void saveYamls() {
|
|
140
|
+ try {
|
|
141
|
+ record.save(recordFile);
|
|
142
|
+ } catch (IOException e) {
|
|
143
|
+ e.printStackTrace();
|
|
144
|
+ }
|
|
145
|
+ }
|
|
146
|
+
|
|
147
|
+ /**
|
|
148
|
+ * Loads the configuration file and record YAML files.
|
|
149
|
+ */
|
|
150
|
+ public void loadYamls() {
|
|
151
|
+ try {
|
|
152
|
+ config.load(configFile);
|
|
153
|
+ record.load(recordFile);
|
|
154
|
+ } catch (Exception e) {
|
|
155
|
+ e.printStackTrace();
|
|
156
|
+ }
|
|
157
|
+ }
|
|
158
|
+
|
|
159
|
+ /**
|
|
160
|
+ * Command listener which passes commands on top separate methods for further execution.
|
|
161
|
+ * However, it also checks for permissions and whether the plugin is enabled in the config.
|
|
162
|
+ * @param sender the player who sent the command
|
|
163
|
+ * @param command the command object to be handled
|
|
164
|
+ * @param command_string a string version of the command name
|
|
165
|
+ * @param args the arguments passed to the command
|
|
166
|
+ * @return whether the syntax of the command was correct (i.e. correct number of arguments)
|
|
167
|
+ */
|
|
168
|
+ @Override
|
|
169
|
+ public boolean onCommand(CommandSender sender, Command command, String commandString, String[] args) {
|
|
170
|
+ if (enabled && commandString.equalsIgnoreCase("dr")) {
|
|
171
|
+ if (args.length > 0) {
|
|
172
|
+ String effectiveCommand = args[0];
|
|
173
|
+
|
|
174
|
+ if (effectiveCommand.equalsIgnoreCase("minor")) {
|
|
175
|
+ if (sender.hasPermission("disciplinerecord.minor")) {
|
|
176
|
+ return minorOffense(sender, args);
|
|
177
|
+ }
|
|
178
|
+ } else if (effectiveCommand.equalsIgnoreCase("major")) {
|
|
179
|
+ if (sender.hasPermission("disciplinerecord.major")) {
|
|
180
|
+ return majorOffense(sender, args);
|
|
181
|
+ }
|
|
182
|
+ } else if (effectiveCommand.equalsIgnoreCase("check")) {
|
|
183
|
+ if (sender.hasPermission("disciplinerecord.check")) {
|
|
184
|
+ return check(sender, args);
|
|
185
|
+ }
|
|
186
|
+ } else if (effectiveCommand.equalsIgnoreCase("checkminor")) {
|
|
187
|
+ if (sender.hasPermission("disciplinerecord.checkminor")) {
|
|
188
|
+ return checkMinor(sender, args);
|
|
189
|
+ }
|
|
190
|
+ } else if (effectiveCommand.equalsIgnoreCase("checkmajor")) {
|
|
191
|
+ if (sender.hasPermission("disciplinerecord.checkmajor")) {
|
|
192
|
+ return checkMajor(sender, args);
|
|
193
|
+ }
|
|
194
|
+ } else if (effectiveCommand.equalsIgnoreCase("setminor")) {
|
|
195
|
+ if (sender.hasPermission("disciplinerecord.setminor")) {
|
|
196
|
+ return setMinor(sender, args);
|
|
197
|
+ }
|
|
198
|
+ } else if (effectiveCommand.equalsIgnoreCase("setmajor")) {
|
|
199
|
+ if (sender.hasPermission("disciplinerecord.setmajor")) {
|
|
200
|
+ return setMajor(sender, args);
|
|
201
|
+ }
|
|
202
|
+ } else if (effectiveCommand.equalsIgnoreCase("pardonminor")) {
|
|
203
|
+ if (sender.hasPermission("disciplinerecord.pardonminor")) {
|
|
204
|
+ return pardonMinor(sender, args);
|
|
205
|
+ }
|
|
206
|
+ } else if (effectiveCommand.equalsIgnoreCase("pardonmajor")) {
|
|
207
|
+ if (sender.hasPermission("disciplinerecord.pardonmajor")) {
|
|
208
|
+ return pardonMajor(sender, args);
|
|
209
|
+ }
|
|
210
|
+ } else {
|
|
211
|
+ return help(sender, args);
|
|
212
|
+ }
|
|
213
|
+ } else {
|
|
214
|
+ return help(sender, args);
|
|
215
|
+ }
|
|
216
|
+ }
|
|
217
|
+ return true;
|
|
218
|
+ }
|
|
219
|
+
|
|
220
|
+ /**
|
|
221
|
+ * This command handler parses the arguments for a valid username. It only accesses the record
|
|
222
|
+ * if the player is currently online and sends messages to both the command sender and the
|
|
223
|
+ * player. However, it is very likely that the player will not see this message. In particular,
|
|
224
|
+ * this handler adds a single minor offense to the record for a player.
|
|
225
|
+ * @param sender the player who sent the command
|
|
226
|
+ * @param args the arguments passed to this command
|
|
227
|
+ * @return whether the syntax of the command was correct (i.e. correct number of arguments)
|
|
228
|
+ */
|
|
229
|
+ public boolean minorOffense(CommandSender sender, String[] args) {
|
|
230
|
+ Server server = Bukkit.getServer();
|
|
231
|
+ String playerName = "";
|
|
232
|
+ String reason = "";
|
|
233
|
+
|
|
234
|
+ if (args.length > 1) {
|
|
235
|
+ playerName = args[1];
|
|
236
|
+ if (args.length > 2) {
|
|
237
|
+ for (int i = 2; i < args.length; i++) {
|
|
238
|
+ reason += args[i] + " ";
|
|
239
|
+ }
|
|
240
|
+ }
|
|
241
|
+ Player player = server.getPlayer(playerName);
|
|
242
|
+ if (player != null) {
|
|
243
|
+ playerName = player.getName(); // Gets the full name.
|
|
244
|
+ recorder.incrementMinor(playerName, reason);
|
|
245
|
+ sender.sendMessage(pluginTag + "Minor offense tally added to " + player.getDisplayName());
|
|
246
|
+ player.sendMessage(pluginTag + "A " + ChatColor.YELLOW + "minor offense" + ChatColor.WHITE + " has been added to your discipline record!");
|
|
247
|
+ if (!reason.isEmpty()) {
|
|
248
|
+ player.sendMessage(ChatColor.BLUE + "Reason: " + ChatColor.WHITE + reason);
|
|
249
|
+ }
|
|
250
|
+ int numOffenses = recorder.getMinor(playerName);
|
|
251
|
+ player.sendMessage(pluginTag + "You now have " + ChatColor.RED + numOffenses + ChatColor.WHITE + " minor offense" + ((numOffenses == 1) ? "." : "s."));
|
|
252
|
+ } else {
|
|
253
|
+ sender.sendMessage(pluginTag + ChatColor.RED + playerName + " is not online!");
|
|
254
|
+ }
|
|
255
|
+ return true;
|
|
256
|
+ } else {
|
|
257
|
+ sender.sendMessage(pluginTag + " Usage: /dr minor <name> [reason]");
|
|
258
|
+ return true; // Suppress default usage message.
|
|
259
|
+ }
|
|
260
|
+ }
|
|
261
|
+
|
|
262
|
+ /**
|
|
263
|
+ * This command handler parses the arguments for a valid username. It only accesses the record
|
|
264
|
+ * if the player is currently online and sends messages to both the command sender and the
|
|
265
|
+ * player. However, it is very likely that the player will not see this message. In particular,
|
|
266
|
+ * this handler adds a single major offense to the record for a player.
|
|
267
|
+ * @param sender the player who sent the command
|
|
268
|
+ * @param args the arguments passed to this command
|
|
269
|
+ * @return whether the syntax of the command was correct (i.e. correct number of arguments)
|
|
270
|
+ */
|
|
271
|
+ public boolean majorOffense(CommandSender sender, String[] args) {
|
|
272
|
+ Server server = Bukkit.getServer();
|
|
273
|
+ String playerName = "";
|
|
274
|
+ String reason = "";
|
|
275
|
+
|
|
276
|
+ if (args.length > 1) {
|
|
277
|
+ playerName = args[1];
|
|
278
|
+ if (args.length > 2) {
|
|
279
|
+ for (int i = 2; i < args.length; i++) {
|
|
280
|
+ reason += args[i] + " ";
|
|
281
|
+ }
|
|
282
|
+ }
|
|
283
|
+ Player player = server.getPlayer(playerName);
|
|
284
|
+ if (player != null) {
|
|
285
|
+ playerName = player.getName(); // Gets the full name.
|
|
286
|
+ recorder.incrementMajor(playerName, reason);
|
|
287
|
+ sender.sendMessage(pluginTag + " Major offense tally added to " + player.getDisplayName());
|
|
288
|
+ player.sendMessage(pluginTag + "A " + ChatColor.RED + "major offense" + ChatColor.WHITE + " has been added to your discipline record!");
|
|
289
|
+ if (!reason.isEmpty()) {
|
|
290
|
+ player.sendMessage(ChatColor.BLUE + "Reason: " + ChatColor.WHITE + reason);
|
|
291
|
+ }
|
|
292
|
+ int numOffenses = recorder.getMajor(playerName);
|
|
293
|
+ player.sendMessage(pluginTag + "You now have " + ChatColor.RED + numOffenses + ChatColor.WHITE + " major offense" + ((numOffenses == 1) ? "." : "s."));
|
|
294
|
+ } else {
|
|
295
|
+ sender.sendMessage(pluginTag + ChatColor.RED + playerName + " is not online!");
|
|
296
|
+ }
|
|
297
|
+ return true;
|
|
298
|
+ } else {
|
|
299
|
+ sender.sendMessage(pluginTag + " Usage: /dr major <name> [reason]");
|
|
300
|
+ return true; // Suppress default usage message.
|
|
301
|
+ }
|
|
302
|
+ }
|
|
303
|
+
|
|
304
|
+ /**
|
|
305
|
+ * This command is intended to be used by any player who wants to check the total number of
|
|
306
|
+ * offenses they have in the record.
|
|
307
|
+ * @param sender the player wishing to check his or her record
|
|
308
|
+ * @param args the arguments passed to this command
|
|
309
|
+ * @return whether the syntax of the command was correct (i.e. correct number of arguments)
|
|
310
|
+ */
|
|
311
|
+ public boolean check(CommandSender sender, String[] args) {
|
|
312
|
+ if (args.length > 1) { // If checking another player name,
|
|
313
|
+ String playerName = args[1];
|
|
314
|
+
|
|
315
|
+ if (sender.hasPermission("disciplinerecord.check.others")) { // check permissions
|
|
316
|
+ int numMinor = recorder.getMinor(playerName);
|
|
317
|
+ int numMajor = recorder.getMajor(playerName);
|
|
318
|
+ sender.sendMessage(pluginTag + playerName + " has " + ChatColor.RED + numMinor + ChatColor.WHITE + " minor offense" + ((numMinor == 1) ? "" : "s") + " and " + ChatColor.RED + numMajor + ChatColor.WHITE + " major offense" + ((numMajor == 1) ? "." : "s."));
|
|
319
|
+ } else {
|
|
320
|
+ sender.sendMessage(pluginTag + ChatColor.RED + "You do not have permission to check others' discipline record!");
|
|
321
|
+ }
|
|
322
|
+
|
|
323
|
+ return true;
|
|
324
|
+ } else {
|
|
325
|
+ int numMinor = recorder.getMinor(sender.getName());
|
|
326
|
+ int numMajor = recorder.getMajor(sender.getName());
|
|
327
|
+ sender.sendMessage(pluginTag + "You have " + ChatColor.RED + numMinor + ChatColor.WHITE + " minor offense" + ((numMinor == 1) ? "" : "s") + " and " + ChatColor.RED + numMajor + ChatColor.WHITE + " major offense" + ((numMajor == 1) ? "." : "s."));
|
|
328
|
+ return true;
|
|
329
|
+ }
|
|
330
|
+ }
|
|
331
|
+
|
|
332
|
+ /**
|
|
333
|
+ * This command is intended to be used by any player who wants to check the number of minor
|
|
334
|
+ * offenses they have in the record.
|
|
335
|
+ * @param sender the player wishing to check his or her record
|
|
336
|
+ * @param args the arguments passed to this command
|
|
337
|
+ * @return whether the syntax of the command was correct (i.e. correct number of arguments)
|
|
338
|
+ */
|
|
339
|
+ public boolean checkMinor(CommandSender sender, String[] args) {
|
|
340
|
+ if (args.length > 1) { // If checking another player name,
|
|
341
|
+ String playerName = args[1];
|
|
342
|
+
|
|
343
|
+ if (sender.hasPermission("disciplinerecord.check.others")) { // check permissions
|
|
344
|
+ int numMinor = recorder.getMinor(playerName);
|
|
345
|
+ sender.sendMessage(pluginTag + playerName + " has " + ChatColor.RED + numMinor + ChatColor.WHITE + " minor offense" + ((numMinor == 1) ? "." : "s."));
|
|
346
|
+ } else {
|
|
347
|
+ sender.sendMessage(pluginTag + ChatColor.RED + "You do not have permission to check others' discipline record!");
|
|
348
|
+ }
|
|
349
|
+ return true;
|
|
350
|
+ } else {
|
|
351
|
+ int numOffenses = recorder.getMinor(sender.getName());
|
|
352
|
+ sender.sendMessage(pluginTag + "You have " + ChatColor.RED + numOffenses + ChatColor.WHITE + " minor offense" + ((numOffenses == 1) ? "." : "s."));
|
|
353
|
+ return true;
|
|
354
|
+ }
|
|
355
|
+ }
|
|
356
|
+
|
|
357
|
+ /**
|
|
358
|
+ * This command is intended to be used by any player who wants to check the number of major
|
|
359
|
+ * offenses they have in the record.
|
|
360
|
+ * @param sender the player wishing to check his or her record
|
|
361
|
+ * @param args the arguments passed to this command
|
|
362
|
+ * @return whether the syntax of the command was correct (i.e. correct number of arguments)
|
|
363
|
+ */
|
|
364
|
+ public boolean checkMajor(CommandSender sender, String[] args) {
|
|
365
|
+ if (args.length > 1) { // If checking another player name,
|
|
366
|
+ String playerName = args[1];
|
|
367
|
+
|
|
368
|
+ if (sender.hasPermission("disciplinerecord.check.others")) { // check permissions
|
|
369
|
+ int numMajor = recorder.getMajor(playerName);
|
|
370
|
+ sender.sendMessage(pluginTag + playerName + " has " + ChatColor.RED + numMajor + ChatColor.WHITE + " major offense" + ((numMajor == 1) ? "." : "s."));
|
|
371
|
+ return true;
|
|
372
|
+ } else {
|
|
373
|
+ sender.sendMessage(pluginTag + ChatColor.RED + "You do not have permission to check others' discipline record!");
|
|
374
|
+ }
|
|
375
|
+ return true;
|
|
376
|
+ } else {
|
|
377
|
+ int numOffenses = recorder.getMajor(sender.getName());
|
|
378
|
+ sender.sendMessage(pluginTag + "You have " + ChatColor.RED + numOffenses + ChatColor.WHITE + " major offense" + ((numOffenses == 1) ? "." : "s."));
|
|
379
|
+ return true;
|
|
380
|
+ }
|
|
381
|
+ }
|
|
382
|
+
|
|
383
|
+ /**
|
|
384
|
+ * This command specifically sets the number of minor offenses of a player to a particular
|
|
385
|
+ * number. It does not require the user to be online.
|
|
386
|
+ * @param sender the sender of the command
|
|
387
|
+ * @param args the arguments associated with this command
|
|
388
|
+ * @return whether the syntax of the command was correct (i.e. correct number of arguments)
|
|
389
|
+ */
|
|
390
|
+ public boolean setMinor(CommandSender sender, String[] args) {
|
|
391
|
+ Server server = Bukkit.getServer();
|
|
392
|
+ String playerName = "";
|
|
393
|
+ int number = 0;
|
|
394
|
+
|
|
395
|
+ if (args.length > 2) {
|
|
396
|
+ playerName = args[1];
|
|
397
|
+ try {
|
|
398
|
+ number = Integer.parseInt(args[2]);
|
|
399
|
+ } catch (Exception ex) {
|
|
400
|
+ sender.sendMessage(pluginTag + "Invalid number!");
|
|
401
|
+ return false;
|
|
402
|
+ }
|
|
403
|
+
|
|
404
|
+ Player player = server.getPlayer(playerName);
|
|
405
|
+ if (player != null) {
|
|
406
|
+ playerName = player.getName(); // Gets the full name if online.
|
|
407
|
+ player.sendMessage(pluginTag + "The number of minor offenses you have has been reset to " + ChatColor.RED + number);
|
|
408
|
+ }
|
|
409
|
+ recorder.setMinor(playerName, number);
|
|
410
|
+ sender.sendMessage(pluginTag + " Set number of minor offenses for " + playerName + " to " + number);
|
|
411
|
+ return true;
|
|
412
|
+ } else {
|
|
413
|
+ sender.sendMessage(pluginTag + " Usage: /dr setminor <name> <number>");
|
|
414
|
+ return true; // Suppress default usage message.
|
|
415
|
+ }
|
|
416
|
+ }
|
|
417
|
+
|
|
418
|
+ /**
|
|
419
|
+ * This command specifically sets the number of major offenses of a player to a particular
|
|
420
|
+ * number. It does not require the user to be online.
|
|
421
|
+ * @param sender the sender of the command
|
|
422
|
+ * @param args the arguments associated with this command
|
|
423
|
+ * @return whether the syntax of the command was correct (i.e. correct number of arguments)
|
|
424
|
+ */
|
|
425
|
+ public boolean setMajor(CommandSender sender, String[] args) {
|
|
426
|
+ Server server = Bukkit.getServer();
|
|
427
|
+ String playerName = "";
|
|
428
|
+ int number = 0;
|
|
429
|
+
|
|
430
|
+ if (args.length > 2) {
|
|
431
|
+ playerName = args[1];
|
|
432
|
+ try {
|
|
433
|
+ number = Integer.parseInt(args[2]);
|
|
434
|
+ } catch (Exception ex) {
|
|
435
|
+ sender.sendMessage("Invalid number!");
|
|
436
|
+ return false;
|
|
437
|
+ }
|
|
438
|
+
|
|
439
|
+ Player player = server.getPlayer(playerName);
|
|
440
|
+ if (player != null) {
|
|
441
|
+ playerName = player.getName(); // Gets the full name if online.
|
|
442
|
+ player.sendMessage(pluginTag + "The number of major offenses you have has been reset to " + ChatColor.RED + number);
|
|
443
|
+ }
|
|
444
|
+ recorder.setMajor(playerName, number);
|
|
445
|
+ sender.sendMessage(pluginTag + " Set number of major offenses for " + playerName + " to " + number);
|
|
446
|
+ return true;
|
|
447
|
+ } else {
|
|
448
|
+ sender.sendMessage(pluginTag + " Usage: /dr setmajor <name> <number>");
|
|
449
|
+ return true; // Suppress default usage message.
|
|
450
|
+ }
|
|
451
|
+ }
|
|
452
|
+
|
|
453
|
+ /**
|
|
454
|
+ * This command pardons a player of all of his minor offenses.
|
|
455
|
+ * @param sender the sender of this command
|
|
456
|
+ * @param args an array containing a single element which is the username of the player to
|
|
457
|
+ * pardon
|
|
458
|
+ * @return whether the syntax of the command was correct (i.e. correct number of arguments)
|
|
459
|
+ */
|
|
460
|
+ public boolean pardonMinor(CommandSender sender, String[] args) {
|
|
461
|
+ Server server = Bukkit.getServer();
|
|
462
|
+ String playerName = "";
|
|
463
|
+
|
|
464
|
+ if (args.length > 1) {
|
|
465
|
+ playerName = args[1];
|
|
466
|
+ Player player = server.getPlayer(playerName);
|
|
467
|
+ if (player != null) {
|
|
468
|
+ playerName = player.getName(); // Gets the full name if online.
|
|
469
|
+ player.sendMessage(pluginTag + "Good news! All of your minor offenses have been pardoned.");
|
|
470
|
+
|
|
471
|
+ }
|
|
472
|
+ recorder.pardonMinor(playerName);
|
|
473
|
+ sender.sendMessage(pluginTag + "Pardoning all minor offenses for " + playerName);
|
|
474
|
+ return true;
|
|
475
|
+ } else {
|
|
476
|
+ sender.sendMessage(pluginTag + " Usage: /dr pardonminor <name>");
|
|
477
|
+ return true; // Suppress default usage message.
|
|
478
|
+ }
|
|
479
|
+ }
|
|
480
|
+
|
|
481
|
+ /**
|
|
482
|
+ * This command pardons a player of all of his major offenses.
|
|
483
|
+ * @param sender the sender of this command
|
|
484
|
+ * @param args an array containing a single element which is the username of the player to
|
|
485
|
+ * pardon
|
|
486
|
+ * @return whether the syntax of the command was correct (i.e. correct number of arguments)
|
|
487
|
+ */
|
|
488
|
+ public boolean pardonMajor(CommandSender sender, String[] args) {
|
|
489
|
+ Server server = Bukkit.getServer();
|
|
490
|
+ String playerName = "";
|
|
491
|
+
|
|
492
|
+ if (args.length > 1) {
|
|
493
|
+ playerName = args[1];
|
|
494
|
+ Player player = server.getPlayer(playerName);
|
|
495
|
+ if (player != null) {
|
|
496
|
+ playerName = player.getName(); // Gets the full name if online.
|
|
497
|
+ player.sendMessage("Good news! All of your major offenses have been pardoned.");
|
|
498
|
+ }
|
|
499
|
+ recorder.pardonMajor(playerName);
|
|
500
|
+ sender.sendMessage(pluginTag + " Pardoning all major offenses for " + playerName);
|
|
501
|
+ return true;
|
|
502
|
+ } else {
|
|
503
|
+ sender.sendMessage(pluginTag + " Usage: /dr pardonmajor <name>");
|
|
504
|
+ return true; // Suppress default usage message.
|
|
505
|
+ }
|
|
506
|
+ }
|
|
507
|
+
|
|
508
|
+ /**
|
|
509
|
+ * Displays the appropriate help context.
|
|
510
|
+ * @param sender the sender of the command
|
|
511
|
+ * @param args the arguments passed to the command
|
|
512
|
+ * @return whether the syntax of the command was correct (i.e. correct number of arguments)
|
|
513
|
+ */
|
|
514
|
+ public boolean help(CommandSender sender, String[] args) {
|
|
515
|
+ if (args.length > 1 && args[0].equalsIgnoreCase("help")) { // If command passed to help
|
|
516
|
+ String command = args[1];
|
|
517
|
+ String commandName, description, usage = "";
|
|
518
|
+
|
|
519
|
+ // Check if the user has permission to see that command.
|
|
520
|
+ if (sender.hasPermission("disciplinerecord.minor") && command.equalsIgnoreCase("minor")) {
|
|
521
|
+ commandName = "minor";
|
|
522
|
+ description = "adds a minor offense to a player's Discipline Record. Optionally add a reason.";
|
|
523
|
+ usage = "/dr minor <player> [reason]";
|
|
524
|
+
|
|
525
|
+ } else if (sender.hasPermission("disciplinerecord.major") && command.equalsIgnoreCase("major")) {
|
|
526
|
+ commandName = "major";
|
|
527
|
+ description = "adds a major offense to a player's Discipline Record. Optionally add a reason.";
|
|
528
|
+ usage = "/dr major <player> [reason]";
|
|
529
|
+
|
|
530
|
+ } else if (sender.hasPermission("disciplinerecord.check") && command.equalsIgnoreCase("check")) {
|
|
531
|
+ commandName = "check";
|
|
532
|
+ description = "checks your discipline record and tells you how many offenses you have.";
|
|
533
|
+ usage = "/dr check";
|
|
534
|
+
|
|
535
|
+ if (sender.hasPermission("disciplinerecord.check.others")) {
|
|
536
|
+ description += " Optionally, you can specify another player's name and check his or her record.";
|
|
537
|
+ usage += " [player]";
|
|
538
|
+ }
|
|
539
|
+
|
|
540
|
+ } else if (sender.hasPermission("disciplinerecord.checkminor") && command.equalsIgnoreCase("checkminor")) {
|
|
541
|
+ commandName = "checkminor";
|
|
542
|
+ description = "checks your discipline record and tells you how many minor offenses you have.";
|
|
543
|
+ usage = "/dr checkminor";
|
|
544
|
+
|
|
545
|
+ if (sender.hasPermission("disciplinerecord.check.others")) {
|
|
546
|
+ description += " Optionally, you can specify another player's name and check his or her record.";
|
|
547
|
+ usage += " [player]";
|
|
548
|
+ }
|
|
549
|
+
|
|
550
|
+ } else if (sender.hasPermission("disciplinerecord.checkmajor") && command.equalsIgnoreCase("checkmajor")) {
|
|
551
|
+ commandName = "checkmajor";
|
|
552
|
+ description = "checks your discipline record and tells you how many minor offenses you have.";
|
|
553
|
+ usage = "/dr checkmajor";
|
|
554
|
+
|
|
555
|
+ if (sender.hasPermission("disciplinerecord.check.others")) {
|
|
556
|
+ description += " Optionally, you can specify another player's name and check his or her record.";
|
|
557
|
+ usage += " [player]";
|
|
558
|
+ }
|
|
559
|
+
|
|
560
|
+ } else if (sender.hasPermission("disciplinerecord.setminor") && command.equalsIgnoreCase("setminor")) {
|
|
561
|
+ commandName = "setminor";
|
|
562
|
+ description = "sets a player's number of minor offenses to a specific number.";
|
|
563
|
+ usage = "/dr setminor <player> <number>";
|
|
564
|
+
|
|
565
|
+ } else if (sender.hasPermission("disciplinerecord.setmajor") && command.equalsIgnoreCase("setmajor")) {
|
|
566
|
+ commandName = "setmajor";
|
|
567
|
+ description = "sets a player's number of major offenses to a specific number.";
|
|
568
|
+ usage = "/dr setmajor <player> <number>";
|
|
569
|
+
|
|
570
|
+ } else if (sender.hasPermission("disciplinerecord.pardonminor") && command.equalsIgnoreCase("pardonminor")) {
|
|
571
|
+ commandName = "pardonminor";
|
|
572
|
+ description = "pardon's a player of all minor offenses.";
|
|
573
|
+ usage = "/dr pardonminor <player>";
|
|
574
|
+
|
|
575
|
+ } else if (sender.hasPermission("disciplinerecord.pardonmajor") && command.equalsIgnoreCase("pardonmajor")) {
|
|
576
|
+ commandName = "pardonmajor";
|
|
577
|
+ description = "pardon's a player of all major offenses.";
|
|
578
|
+ usage = "/dr pardonmajor <player>";
|
|
579
|
+
|
|
580
|
+ } else {
|
|
581
|
+ sendDefaultHelp(sender);
|
|
582
|
+ return true;
|
|
583
|
+ }
|
|
584
|
+
|
|
585
|
+ sender.sendMessage("");
|
|
586
|
+ sender.sendMessage(ChatColor.GREEN + commandName + " " + ChatColor.WHITE + description);
|
|
587
|
+ sender.sendMessage("");
|
|
588
|
+ sender.sendMessage(ChatColor.GRAY + "Usage: " + ChatColor.YELLOW + usage);
|
|
589
|
+ return true;
|
|
590
|
+ } else {
|
|
591
|
+ sendDefaultHelp(sender);
|
|
592
|
+ return true;
|
|
593
|
+ }
|
|
594
|
+ }
|
|
595
|
+
|
|
596
|
+ public void sendDefaultHelp(CommandSender sender) {
|
|
597
|
+ sender.sendMessage("");
|
|
598
|
+ sender.sendMessage(ChatColor.YELLOW + "Discipline Record" + ChatColor.WHITE + " is a plugin that helps keep a record of the number of times that players break rules. There are " + ChatColor.GREEN + "two" + ChatColor.WHITE + " types of rules: " + ChatColor.YELLOW + "minor" + ChatColor.WHITE + " and " + ChatColor.RED + "major.");
|
|
599
|
+ sender.sendMessage("");
|
|
600
|
+ String availableCommands = "";
|
|
601
|
+
|
|
602
|
+ ChatColor color = ChatColor.GREEN;
|
|
603
|
+ if (sender.hasPermission("disciplinerecord.minor")) availableCommands += color + "minor" + ChatColor.WHITE + ", ";
|
|
604
|
+ if (sender.hasPermission("disciplinerecord.major")) availableCommands += color + "major" + ChatColor.WHITE + ", ";
|
|
605
|
+ if (sender.hasPermission("disciplinerecord.check")) availableCommands += color + "check" + ChatColor.WHITE + ", ";
|
|
606
|
+ if (sender.hasPermission("disciplinerecord.checkminor")) availableCommands += color + "checkminor" + ChatColor.WHITE + ", ";
|
|
607
|
+ if (sender.hasPermission("disciplinerecord.checkmajor")) availableCommands += color + "checkmajor" + ChatColor.WHITE + ", ";
|
|
608
|
+ if (sender.hasPermission("disciplinerecord.setminor")) availableCommands += color + "setminor" + ChatColor.WHITE + ", ";
|
|
609
|
+ if (sender.hasPermission("disciplinerecord.setmajor")) availableCommands += color + "setmajor" + ChatColor.WHITE + ", ";
|
|
610
|
+ if (sender.hasPermission("disciplinerecord.pardonminor")) availableCommands += color + "pardonminor" + ChatColor.WHITE + ", ";
|
|
611
|
+ if (sender.hasPermission("disciplinerecord.pardonmajor")) availableCommands += color + "pardonmajor" + ChatColor.WHITE + ", ";
|
|
612
|
+ availableCommands = availableCommands.substring(0, availableCommands.length() - 2); // Remove trailing comma.
|
|
613
|
+
|
|
614
|
+ sender.sendMessage(ChatColor.RED + "Commands: " + ChatColor.WHITE + availableCommands);
|
|
615
|
+ sender.sendMessage("");
|
|
616
|
+ sender.sendMessage("Type /dr help <command> for more info about each command.");
|
|
617
|
+ }
|
|
618
|
+
|
|
619
|
+}
|