Skip to content

Commit 65db09d

Browse files
committed
Fixed commands and added some more comments.
1 parent 62f2d72 commit 65db09d

12 files changed

Lines changed: 359 additions & 31 deletions

plugin.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ commands:
1717
/<command> request: Make a request to the moderators
1818
check:
1919
description: Check request queue
20-
permission: modreq.check
2120
usage: |
2221
/<command> <p:#|#>: Check request queue or a specific request
2322
tp-id:

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<version>3.0</version>
77
<packaging>jar</packaging>
88
<name>ModReq</name>
9-
<description>Moderator Request Sytem</description>
9+
<description>Moderator Request System</description>
1010
<url>https://github.com/NerdNu/ModReq</url>
1111
<scm>
1212
<connection>scm:git:https://github.com/NerdNu/ModReq.git</connection>

src/nu/nerd/modreq/commands/CheckCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* @since 3.0
2525
*/
2626
public class CheckCommand implements CommandHandler {
27+
2728
private final ModReq plugin;
2829
private RequestTable reqTable;
2930
private Map<String, String> environment;
@@ -131,7 +132,7 @@ public boolean execute(Player player, String name, String[] args) {
131132
sendMessage(player, configuration.GENERAL__NO_REQUESTS, environment, configuration);
132133
} else {
133134
messageRequestListToPlayer(player, requests, finalPage, requests.size(),
134-
false, environment, configuration, plugin, plugin.getNoteTable());
135+
true, environment, configuration, plugin, plugin.getNoteTable());
135136
}
136137
});
137138
});

src/nu/nerd/modreq/commands/CommandRegistry.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,20 @@
1212
public class CommandRegistry {
1313
private final Map<String, CommandHandler> commands = new HashMap<>();
1414

15+
/**
16+
* Register a command and store it for recalling
17+
* @param commandName What the player types in chat
18+
* @param commandHandler The instance of that command's class
19+
*/
1520
public void register(String commandName, CommandHandler commandHandler) {
1621
commands.put(commandName.toLowerCase(), commandHandler);
1722
}
1823

24+
/**
25+
* Get the instance of a command's class
26+
* @param commandName What the player types in chat
27+
* @return The instance of that command's class
28+
*/
1929
public CommandHandler getHandler(String commandName) {
2030
return commands.get(commandName.toLowerCase());
2131
}

src/nu/nerd/modreq/commands/DoneCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public boolean execute(Player player, String name, String[] args) {
114114
environment.put("close_message", doneMessage);
115115
environment.put("mod", playerName);
116116
environment.put("request_id", String.valueOf(requestId));
117-
if (doneMessage.length() != 0) {
117+
if (!doneMessage.isEmpty()) {
118118
sendMessage(requestCreator, configuration.GENERAL__COMPLETED_MESSAGE,
119119
environment, configuration);
120120
} else {

src/nu/nerd/modreq/commands/MRNoteCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,6 @@ public boolean execute(Player player, String name, String[] args) {
101101
}
102102
});
103103
});
104-
return false;
104+
return true;
105105
}
106106
}

src/nu/nerd/modreq/commands/ModreqCommand.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.bukkit.Bukkit;
88
import org.bukkit.ChatColor;
99
import org.bukkit.entity.Player;
10+
import org.bukkit.scheduler.BukkitScheduler;
1011

1112
import java.util.Map;
1213
import java.util.concurrent.CompletableFuture;
@@ -25,7 +26,7 @@ public class ModreqCommand implements CommandHandler {
2526
private RequestTable reqTable;
2627
private Map<String, String> environment;
2728
private Configuration configuration;
28-
private CompletableFuture<Void> future;
29+
private BukkitScheduler bukkitScheduler = Bukkit.getScheduler();
2930

3031
/**
3132
* Creates a new {@code ModreqCommand} instance.
@@ -38,14 +39,12 @@ public ModreqCommand(ModReq plugin) {
3839
this.reqTable = plugin.getReqTable();
3940
this.environment = plugin.getEnvironment();
4041
this.configuration = plugin.getConfiguration();
41-
this.future = plugin.getCompleteableFuture();
4242
}
4343

4444
@Override
4545
public boolean execute(Player player, String name, String[] args) {
4646

4747
reqTable.getNumRequestFromUser(player.getUniqueId()).thenAccept(numRequests -> {
48-
Bukkit.getScheduler().runTask(plugin, () -> {
4948
if (numRequests < configuration.MAX_REQUESTS) {
5049
Request req = new Request();
5150
req.setPlayerUUID(player.getUniqueId());
@@ -64,15 +63,19 @@ public boolean execute(Player player, String name, String[] args) {
6463
req.setRequestLocation(location);
6564
req.setStatus(Request.RequestStatus.OPEN);
6665

67-
reqTable.save(req);
68-
environment.put("request_id", String.valueOf(req.getId()));
69-
messageMods(configuration.MOD__NEW_REQUEST, environment, configuration);
70-
sendMessage(player, configuration.GENERAL__REQUEST_FILED, environment, configuration);
66+
reqTable.saveAndGetId(req).thenAccept(savedReq -> {
67+
bukkitScheduler.runTask(plugin, () -> {
68+
environment.put("request_id", String.valueOf(req.getId()));
69+
messageMods(configuration.MOD__NEW_REQUEST, environment, configuration);
70+
sendMessage(player, configuration.GENERAL__REQUEST_FILED, environment, configuration);
71+
});
72+
});
7173
} else {
72-
environment.put("max_requests", Integer.toString(configuration.MAX_REQUESTS));
73-
sendMessage(player, configuration.GENERAL__MAX_REQUESTS, environment, configuration);
74+
bukkitScheduler.runTask(plugin, () -> {
75+
environment.put("max_requests", Integer.toString(configuration.MAX_REQUESTS));
76+
sendMessage(player, configuration.GENERAL__MAX_REQUESTS, environment, configuration);
77+
});
7478
}
75-
});
7679
});
7780
return true;
7881
}

src/nu/nerd/modreq/commands/ReopenCommand.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ public boolean execute(Player player, String name, String[] args) {
6666
request.setCloseSeenByUser(false);
6767
reqTable.save(request);
6868

69-
environment.put("mod", player.getName());
70-
environment.put("request_id", String.valueOf(request.getId()));
7169
bukkitScheduler.runTask(plugin, () -> {
70+
environment.put("mod", player.getName());
71+
environment.put("request_id", String.valueOf(request.getId()));
72+
7273
messageMods(configuration.MOD__REOPENED, environment, configuration);
74+
75+
environment.remove("mod");
76+
environment.remove("request_id");
7377
});
74-
environment.remove("mod");
75-
environment.remove("request_id");
7678
}
7779
});
7880
return true;

src/nu/nerd/modreq/database/Note.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
import java.util.UUID;
77

8+
/**
9+
* Represents the note table in the database.
10+
*
11+
* @version 1.0
12+
* @since 3.0
13+
*/
814
@DatabaseTable(tableName = "modreq_notes")
915
public class Note {
1016

@@ -38,53 +44,71 @@ public class Note {
3844
@DatabaseField
3945
private String noteBody;
4046

47+
// ----------------------------------------------------------------------------
48+
4149
public Note(){}
4250

51+
// ----------------------------------------------------------------------------
52+
4353
/**
54+
* Returns the modeq's ID
4455
* @return the id
4556
*/
4657
public int getId() {
4758
return id;
4859
}
4960

5061
/**
62+
* Sets the modreq's ID
5163
* @param id the id to set
5264
*/
5365
public void setId(int id) {
5466
this.id = id;
5567
}
5668

69+
/**
70+
* Sets the player's UUID
71+
* @param playerUUID The player's UUID
72+
*/
5773
public void setPlayerUUID(UUID playerUUID) {
5874
this.playerUUID = playerUUID;
5975
}
6076

77+
/**
78+
* Returns the player's UUID
79+
* @return the player's UUID
80+
*/
6181
public UUID getPlayerUUID() {
6282
return this.playerUUID;
6383
}
6484

6585
/**
86+
* Returns the player
6687
* @return the player
6788
*/
6889
public String getPlayer() {
6990
return player;
7091
}
7192

7293
/**
94+
* Sets the player
7395
* @param player the player to set
7496
*/
7597
public void setPlayer(String player) {
7698
this.player = player;
7799
}
78100

79101
/**
80-
* @return the requestId
102+
* Returns the request ID
103+
* @return the request ID
81104
*/
82105
public int getRequestId() {
83106
return requestId;
84107
}
85108

86109
/**
87-
* @param requestId the requestId to set
110+
* Sets the request ID
111+
* @param requestId the request ID to set
88112
*/
89113
public void setRequestId(int requestId) {
90114
this.requestId = requestId;

src/nu/nerd/modreq/database/NoteTable.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,33 @@
88
import com.j256.ormlite.stmt.QueryBuilder;
99
import nu.nerd.modreq.ModReq;
1010

11+
/**
12+
* Represents the interaction between the notes table in the database and the plugin.
13+
*
14+
* @version 1.0
15+
* @since 3.0
16+
*/
1117
public class NoteTable {
1218

19+
/**
20+
* The data access object for the notes table.
21+
*/
1322
private final Dao<Note, Integer> noteDao;
1423

24+
/**
25+
* Creates a new {@code NoteTable} instance.
26+
*
27+
* @param plugin The main plugin instance, used for fetching the Note DAO.
28+
*/
1529
public NoteTable(ModReq plugin) {
1630
this.noteDao = plugin.getNoteDao();
1731
}
1832

33+
/**
34+
* Gets the notes attached to a request.
35+
* @param request The request being queried.
36+
* @return The notes the specified request has attached to it.
37+
*/
1938
public CompletableFuture<List<Note>> getRequestNotes(Request request) {
2039
return CompletableFuture.supplyAsync(() -> {
2140
try{
@@ -28,6 +47,11 @@ public CompletableFuture<List<Note>> getRequestNotes(Request request) {
2847
});
2948
}
3049

50+
/**
51+
* Gets the amount of notes a request has.
52+
* @param request The request being queried.
53+
* @return The amount of notes the specified request has.
54+
*/
3155
public CompletableFuture<Integer> getNoteCount(Request request) {
3256
return CompletableFuture.supplyAsync(() -> {
3357
try {
@@ -38,6 +62,10 @@ public CompletableFuture<Integer> getNoteCount(Request request) {
3862
});
3963
}
4064

65+
/**
66+
* Removes the note from the database.
67+
* @param note The note being removed.
68+
*/
4169
public void remove(Note note) {
4270
CompletableFuture.runAsync(() -> {
4371
try{
@@ -48,6 +76,10 @@ public void remove(Note note) {
4876
});
4977
}
5078

79+
/**
80+
* Saves the note to the database.
81+
* @param note The note being saved.
82+
*/
5183
public void save(Note note) {
5284
CompletableFuture.runAsync(() -> {
5385
try{

0 commit comments

Comments
 (0)