Change promote / demote behaviour at the end of tracks - towards #112

This commit is contained in:
Luck 2017-01-15 13:22:50 +00:00
parent 7d24e748b7
commit 32fd484b58
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
4 changed files with 53 additions and 6 deletions

View File

@ -139,8 +139,20 @@ public class UserDemote extends SubCommand<User> {
}
if (previous == null) {
Message.USER_DEMOTE_ERROR_ENDOFTRACK.send(sender, track.getName());
return CommandResult.STATE_ERROR;
try {
user.unsetPermission(oldNode);
} catch (ObjectLacksException ignored) {}
Message.USER_DEMOTE_ENDOFTRACK.send(sender, track.getName(), user.getName(), old);
LogEntry.build().actor(sender).acted(user)
.action("demote " + args.stream().collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(user, sender, plugin);
plugin.getApiProvider().fireEventAsync(new UserDemoteEvent(new TrackLink(track), new UserLink(user), old, null));
return CommandResult.SUCCESS;
}
if (!plugin.getStorage().loadGroup(previous).join()) {

View File

@ -119,8 +119,37 @@ public class UserPromote extends SubCommand<User> {
nodes.removeIf(g -> !track.containsGroup(g.getGroupName()));
if (nodes.isEmpty()) {
Message.USER_TRACK_ERROR_NOT_CONTAIN_GROUP.send(sender);
return CommandResult.FAILURE;
String first = track.getGroups().get(0);
Group nextGroup = plugin.getGroupManager().getIfLoaded(first);
if (nextGroup == null) {
Message.USER_PROMOTE_ERROR_MALFORMED.send(sender, false);
return CommandResult.LOADING_ERROR;
}
try {
user.setPermission(NodeFactory.newBuilder("group." + first).setServer(server).setWorld(world).build());
} catch (ObjectAlreadyHasException ignored) {}
switch (ContextHelper.determine(server, world)) {
case NONE:
Message.USER_TRACK_ADDED_TO_FIRST.send(sender, user.getName(), first);
break;
case SERVER:
Message.USER_TRACK_ADDED_TO_FIRST_SERVER.send(sender, user.getName(), first, server);
break;
case SERVER_AND_WORLD:
Message.USER_TRACK_ADDED_TO_FIRST_SERVER_WORLD.send(sender, user.getName(), first, server, world);
break;
}
LogEntry.build().actor(sender).acted(user)
.action("promote " + args.stream().collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
save(user, sender, plugin);
plugin.getApiProvider().fireEventAsync(new UserPromoteEvent(new TrackLink(track), new UserLink(user), null, first));
return CommandResult.SUCCESS;
}
if (nodes.size() != 1) {

View File

@ -310,6 +310,9 @@ public enum Message {
USER_PRIMARYGROUP_ERROR_ALREADYHAS("The user already has this group set as their primary group.", true),
USER_PRIMARYGROUP_ERROR_NOTMEMBER("&b{0}&a was not already a member of &b{1}&a, adding them now.", true),
USER_TRACK_ERROR_NOT_CONTAIN_GROUP("The user specified isn't already in any groups on this track.", true),
USER_TRACK_ADDED_TO_FIRST("&b{0}&a isn't in any groups on this track, so they were added to the first group, &b{1}&a.", true),
USER_TRACK_ADDED_TO_FIRST_SERVER("&b{0}&a isn't in any groups on this track, so they were added to the first group, &b{1}&a, on server &b{2}&a.", true),
USER_TRACK_ADDED_TO_FIRST_SERVER_WORLD("&b{0}&a isn't in any groups on this track, so they were added to the first group, &b{1}&a, on server &b{2}&a, world &b{3}&a.", true),
USER_PROMOTE_SUCCESS("&aPromoting user along track &b{0}&a from &b{1}&a to &b{2}&a.", true),
USER_PROMOTE_SUCCESS_SERVER("&aPromoting user along track &b{0}&a from &b{1}&a to &b{2}&a on server &b{3}&a.", true),
USER_PROMOTE_SUCCESS_SERVER_WORLD("&aPromoting user along track &b{0}&a from &b{1}&a to &b{2}&a on server &b{3}&a, world &b{4}&a.", true),
@ -322,7 +325,7 @@ public enum Message {
USER_DEMOTE_SUCCESS("&aDemoting user along track &b{0}&a from &b{1}&a to &b{2}&a.", true),
USER_DEMOTE_SUCCESS_SERVER("&aDemoting user along track &b{0}&a from &b{1}&a to &b{2}&a on server &b{3}&a.", true),
USER_DEMOTE_SUCCESS_SERVER_WORLD("&aDemoting user along track &b{0}&a from &b{1}&a to &b{2}&a on server &b{3}&a, world &b{4}&a.", true),
USER_DEMOTE_ERROR_ENDOFTRACK("The end of track &4{0}&c was reached. Unable to demote user.", true),
USER_DEMOTE_ENDOFTRACK("The end of track &4{0}&c was reached, so &4{1}&c was removed from &4{2}&c.", true),
USER_DEMOTE_ERROR_MALFORMED(
"{PREFIX}The previous group on the track, {0}, no longer exists. Unable to demote user." + "\n" +
"{PREFIX}Either create the group, or remove it from the track and try again.",

View File

@ -261,6 +261,9 @@ user-primarygroup-success: "&b{0}&a's primary group was set to &b{1}&a."
user-primarygroup-error-alreadyhas: "The user already has this group set as their primary group."
user-primarygroup-error-notmember: "&b{0}&a was not already a member of &b{1}&a, adding them now."
user-track-error-not-contain-group: "The user specified isn't already in any groups on this track."
user-track-added-to-first: "&b{0}&a isn't in any groups on this track, so they were added to the first group, &b{1}&a."
user-track-added-to-first-server: "&b{0}&a isn't in any groups on this track, so they were added to the first group, &b{1}&a, on server &b{2}&a."
user-track-added-to-first-server-world: "&b{0}&a isn't in any groups on this track, so they were added to the first group, &b{1}&a, on server &b{2}&a, world &b{3}&a."
user-promote-success: "&aPromoting user along track &b{0}&a from &b{1}&a to &b{2}&a."
user-promote-success-server: "&aPromoting user along track &b{0}&a from &b{1}&a to &b{2}&a on server &b{3}&a."
user-promote-success-server-world: "&aPromoting user along track &b{0}&a from &b{1}&a to &b{2}&a on server &b{3}&a, world &b{4}&a."
@ -271,7 +274,7 @@ user-promote-error-malformed: >
user-demote-success: "&aDemoting user along track &b{0}&a from &b{1}&a to &b{2}&a."
user-demote-success-server: "&aDemoting user along track &b{0}&a from &b{1}&a to &b{2}&a on server &b{3}&a."
user-demote-success-server-world: "&aDemoting user along track &b{0}&a from &b{1}&a to &b{2}&a on server &b{3}&a, world &b{4}&a."
user-demote-error-endoftrack: "The end of track &4{0}&c was reached. Unable to demote user."
user-demote-endoftrack: "The end of track &4{0}&c was reached, so &4{1}&c was removed from &4{2}&c."
user-demote-error-malformed: >
{PREFIX}The previous group on the track, {0}, no longer exists. Unable to demote user.\n
{PREFIX}Either create the group, or remove it from the track and try again.