Skip to content

Commit

Permalink
implement delete command(implement #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
kory33 committed Apr 10, 2017
1 parent 786eab2 commit dc03ea5
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.github.kory33.signvote.command.subcommand.AddScoreCommandExecutor;
import com.github.kory33.signvote.command.subcommand.CloseCommandExecutor;
import com.github.kory33.signvote.command.subcommand.CreateCommandExecutor;
import com.github.kory33.signvote.command.subcommand.DeleteCommandExecutor;
import com.github.kory33.signvote.command.subcommand.DeleteVPCommandExecutor;
import com.github.kory33.signvote.command.subcommand.HelpCommandExecutor;
import com.github.kory33.signvote.command.subcommand.OpenCommandExecutor;
Expand All @@ -34,6 +35,7 @@ public SignVoteCommandExecutor(SignVote plugin) {
commandMaps.put(SubCommands.CLOSE, new CloseCommandExecutor(plugin));
commandMaps.put(SubCommands.VOTE, new VoteCommandExecutor(plugin));
commandMaps.put(SubCommands.DELETEVP, new DeleteVPCommandExecutor(plugin));
commandMaps.put(SubCommands.DELETE, new DeleteCommandExecutor(plugin));

this.subCommandExecutorMap = Collections.unmodifiableMap(commandMaps);
this.defaultCommandExecutor = new HelpCommandExecutor(plugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class MessageConfigurationNodes {
public static final String F_SESSION_CREATED = COMMAND_ROOT + ".create.created";
public static final String SESSION_ALREADY_EXISTS = COMMAND_ROOT + ".create.error.sessionexists";

public static final String DELETE_SESS_COMMAND_HELP = COMMAND_ROOT + ".delete.help";
public static final String F_SESSION_DELETED = COMMAND_ROOT + ".delete.deleted";

public static final String DELETE_VP_COMMAND_HELP = COMMAND_ROOT + ".deletevp.help";
public static final String F_VOTEPOINT_DELETED = COMMAND_ROOT + ".deletevp.deleted";

Expand All @@ -33,6 +36,7 @@ public class MessageConfigurationNodes {
public static final String INVALID_VOTE_SCORE = COMMAND_ROOT + ".vote.error.invalidscore";
public static final String REACHED_VOTE_SCORE_LIMIT = COMMAND_ROOT + ".vote.error.reachedlimit";
public static final String VOTEPOINT_ALREADY_VOTED = COMMAND_ROOT + ".vote.error.alreadyvoted";


public static final String GENERIC_COMMAND_ERROR = COMMAND_ROOT + ".generic.error";
public static final String COMMAND_ONLY_FOR_PLAYERS = GENERIC_COMMAND_ERROR + ".onlyforplayers";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public class PermissionNodes {
public static final String CLOSE_SESSION = BASE_NODE + ".closesession";

public static final String DELETE_VOTEPOINT = BASE_NODE + ".deletevotepoint";

public static final String DELETE_SESSION = BASE_NODE + ".deletesession";
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public class SubCommands {
public static final String CREATE = "create";
public static final String DELETE = "delete";
public static final String ADD_SCORE = "addscore";
public static final String OPEN = "open";
public static final String CLOSE = "close";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.bukkit.block.Sign;

import com.github.kory33.signvote.Utils.FileUtils;
import com.github.kory33.signvote.collection.BijectiveHashMap;
import com.github.kory33.signvote.model.VotePoint;
import com.github.kory33.signvote.session.VoteSession;
Expand Down Expand Up @@ -71,6 +72,18 @@ private void saveSession(VoteSession session) {
* Save all the sessions.
*/
public void saveAllSessions() {
// purge non-existent sessions
for (File sessionDirectory: this.sessionSaveDirectory.listFiles()) {
String sessionName = sessionDirectory.getName();
if (!this.sessionMap.containsKey(sessionName)) {
try {
FileUtils.deleteFolderRecursively(sessionDirectory);
} catch (IOException e) {
this.logger.log(Level.SEVERE, "Failed to purge session folder " + sessionName, e);
}
}
}

for (VoteSession session: sessionMap.values()) {
this.saveSession(session);
}
Expand Down Expand Up @@ -116,4 +129,8 @@ public VotePoint getVotePoint(Sign sign) {

return null;
}

public void deleteSession(VoteSession targetVoteSession) {
this.sessionMap.removeValue(targetVoteSession);
}
}
6 changes: 5 additions & 1 deletion src/main/resources/messages.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
"command": {
"help": "§e/signvote <create|addscore|open|close|vote>\nRun subcommands without arguments to see their help.",
"help": "§e/signvote <create|delete|addscore|open|close|vote|deletevp>\nRun subcommands without arguments to see their help.",
"create": {
"help": "/signvote create <session name> - create a new session with the given name",
"created": "§aSession §6{0} §acreated!",
"error": {
"sessionexists": "§csession already exists!"
}
},
"delete": {
"help": "/signvote deletesess <session name> - delete the specified vote session.",
"deleted": "§aSession §6{0} §ahas been successfully §cDELETED"
},
"deletevp": {
"help": "/signvote deletevp <session name> <votepoint name> - delete the specified votepoint",
"deleted": "§aVotepoint §6{0} §ais successfully deleted from session §6{1}"
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ permissions:
signvote.closesession:
description: allows a player to close an opened session
default: op
signvote.deletesession:
description: allows a player to delete an existing session
default: op
signvote.deletevotepoint:
description: allows a player to delete a votepoint
default: op

0 comments on commit dc03ea5

Please sign in to comment.