mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-08-30 16:09:33 +02:00
Fix promote/demote commands and primary groups conflicting
This commit is contained in:
parent
a1afc70bcb
commit
0fe251b6ec
|
@ -35,6 +35,7 @@ import me.lucko.luckperms.common.commands.CommandResult;
|
||||||
import me.lucko.luckperms.common.commands.SubCommand;
|
import me.lucko.luckperms.common.commands.SubCommand;
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
||||||
|
import me.lucko.luckperms.common.commands.utils.ContextHelper;
|
||||||
import me.lucko.luckperms.common.commands.utils.Util;
|
import me.lucko.luckperms.common.commands.utils.Util;
|
||||||
import me.lucko.luckperms.common.constants.Message;
|
import me.lucko.luckperms.common.constants.Message;
|
||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
|
@ -49,7 +50,6 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -116,13 +116,7 @@ public class UserDemote extends SubCommand<User> {
|
||||||
nodes.add(node);
|
nodes.add(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<Node> it = nodes.iterator();
|
nodes.removeIf(g -> !track.containsGroup(g.getGroupName()));
|
||||||
while (it.hasNext()) {
|
|
||||||
Node g = it.next();
|
|
||||||
if (!track.containsGroup(g.getGroupName())) {
|
|
||||||
it.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nodes.isEmpty()) {
|
if (nodes.isEmpty()) {
|
||||||
Message.USER_TRACK_ERROR_NOT_CONTAIN_GROUP.send(sender);
|
Message.USER_TRACK_ERROR_NOT_CONTAIN_GROUP.send(sender);
|
||||||
|
@ -134,7 +128,8 @@ public class UserDemote extends SubCommand<User> {
|
||||||
return CommandResult.FAILURE;
|
return CommandResult.FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String old = nodes.stream().findAny().get().getGroupName();
|
final Node oldNode = nodes.stream().findAny().get();
|
||||||
|
final String old = oldNode.getGroupName();
|
||||||
final String previous;
|
final String previous;
|
||||||
try {
|
try {
|
||||||
previous = track.getPrevious(old);
|
previous = track.getPrevious(old);
|
||||||
|
@ -160,26 +155,26 @@ public class UserDemote extends SubCommand<User> {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
user.unsetPermission(nodes.stream().findAny().get());
|
user.unsetPermission(old);
|
||||||
} catch (ObjectLacksException ignored) {
|
} catch (ObjectLacksException ignored) {}
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
user.setPermission(NodeFactory.newBuilder("group." + previousGroup.getName()).setServer(server).setWorld(world).build());
|
user.setPermission(NodeFactory.newBuilder("group." + previousGroup.getName()).setServer(server).setWorld(world).build());
|
||||||
} catch (ObjectAlreadyHasException ignored) {
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
}
|
|
||||||
|
|
||||||
if (server == null && world == null) {
|
if (server == null && world == null && user.getPrimaryGroup().equalsIgnoreCase(old)) {
|
||||||
user.setPrimaryGroup(previousGroup.getName());
|
user.setPrimaryGroup(previousGroup.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server == null) {
|
switch (ContextHelper.determine(server, world)) {
|
||||||
Message.USER_DEMOTE_SUCCESS.send(sender, track.getName(), old, previousGroup.getDisplayName());
|
case NONE:
|
||||||
} else {
|
Message.USER_DEMOTE_SUCCESS.send(sender, track.getName(), old, previousGroup.getDisplayName());
|
||||||
if (world == null) {
|
break;
|
||||||
|
case SERVER:
|
||||||
Message.USER_DEMOTE_SUCCESS_SERVER.send(sender, track.getName(), old, previousGroup.getDisplayName(), server);
|
Message.USER_DEMOTE_SUCCESS_SERVER.send(sender, track.getName(), old, previousGroup.getDisplayName(), server);
|
||||||
} else {
|
break;
|
||||||
|
case SERVER_AND_WORLD:
|
||||||
Message.USER_DEMOTE_SUCCESS_SERVER_WORLD.send(sender, track.getName(), old, previousGroup.getDisplayName(), server, world);
|
Message.USER_DEMOTE_SUCCESS_SERVER_WORLD.send(sender, track.getName(), old, previousGroup.getDisplayName(), server, world);
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Message.EMPTY.send(sender, Util.listToArrowSep(track.getGroups(), previousGroup.getDisplayName(), old, true));
|
Message.EMPTY.send(sender, Util.listToArrowSep(track.getGroups(), previousGroup.getDisplayName(), old, true));
|
||||||
|
|
|
@ -35,6 +35,7 @@ import me.lucko.luckperms.common.commands.CommandResult;
|
||||||
import me.lucko.luckperms.common.commands.SubCommand;
|
import me.lucko.luckperms.common.commands.SubCommand;
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
||||||
|
import me.lucko.luckperms.common.commands.utils.ContextHelper;
|
||||||
import me.lucko.luckperms.common.commands.utils.Util;
|
import me.lucko.luckperms.common.commands.utils.Util;
|
||||||
import me.lucko.luckperms.common.constants.Message;
|
import me.lucko.luckperms.common.constants.Message;
|
||||||
import me.lucko.luckperms.common.constants.Permission;
|
import me.lucko.luckperms.common.constants.Permission;
|
||||||
|
@ -49,7 +50,6 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -116,13 +116,7 @@ public class UserPromote extends SubCommand<User> {
|
||||||
nodes.add(node);
|
nodes.add(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<Node> it = nodes.iterator();
|
nodes.removeIf(g -> !track.containsGroup(g.getGroupName()));
|
||||||
while (it.hasNext()) {
|
|
||||||
Node g = it.next();
|
|
||||||
if (!track.containsGroup(g.getGroupName())) {
|
|
||||||
it.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nodes.isEmpty()) {
|
if (nodes.isEmpty()) {
|
||||||
Message.USER_TRACK_ERROR_NOT_CONTAIN_GROUP.send(sender);
|
Message.USER_TRACK_ERROR_NOT_CONTAIN_GROUP.send(sender);
|
||||||
|
@ -134,7 +128,8 @@ public class UserPromote extends SubCommand<User> {
|
||||||
return CommandResult.FAILURE;
|
return CommandResult.FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String old = nodes.stream().findAny().get().getGroupName();
|
final Node oldNode = nodes.stream().findAny().get();
|
||||||
|
final String old = oldNode.getGroupName();
|
||||||
final String next;
|
final String next;
|
||||||
try {
|
try {
|
||||||
next = track.getNext(old);
|
next = track.getNext(old);
|
||||||
|
@ -160,26 +155,26 @@ public class UserPromote extends SubCommand<User> {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
user.unsetPermission(nodes.stream().findAny().get());
|
user.unsetPermission(oldNode);
|
||||||
} catch (ObjectLacksException ignored) {
|
} catch (ObjectLacksException ignored) {}
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
user.setPermission(NodeFactory.newBuilder("group." + nextGroup.getName()).setServer(server).setWorld(world).build());
|
user.setPermission(NodeFactory.newBuilder("group." + nextGroup.getName()).setServer(server).setWorld(world).build());
|
||||||
} catch (ObjectAlreadyHasException ignored) {
|
} catch (ObjectAlreadyHasException ignored) {}
|
||||||
}
|
|
||||||
|
|
||||||
if (server == null && world == null) {
|
if (server == null && world == null && user.getPrimaryGroup().equalsIgnoreCase(old)) {
|
||||||
user.setPrimaryGroup(nextGroup.getName());
|
user.setPrimaryGroup(nextGroup.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server == null) {
|
switch (ContextHelper.determine(server, world)) {
|
||||||
Message.USER_PROMOTE_SUCCESS.send(sender, track.getName(), old, nextGroup.getDisplayName());
|
case NONE:
|
||||||
} else {
|
Message.USER_PROMOTE_SUCCESS.send(sender, track.getName(), old, nextGroup.getDisplayName());
|
||||||
if (world == null) {
|
break;
|
||||||
|
case SERVER:
|
||||||
Message.USER_PROMOTE_SUCCESS_SERVER.send(sender, track.getName(), old, nextGroup.getDisplayName(), server);
|
Message.USER_PROMOTE_SUCCESS_SERVER.send(sender, track.getName(), old, nextGroup.getDisplayName(), server);
|
||||||
} else {
|
break;
|
||||||
|
case SERVER_AND_WORLD:
|
||||||
Message.USER_PROMOTE_SUCCESS_SERVER_WORLD.send(sender, track.getName(), old, nextGroup.getDisplayName(), server, world);
|
Message.USER_PROMOTE_SUCCESS_SERVER_WORLD.send(sender, track.getName(), old, nextGroup.getDisplayName(), server, world);
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Message.EMPTY.send(sender, Util.listToArrowSep(track.getGroups(), old, nextGroup.getDisplayName(), false));
|
Message.EMPTY.send(sender, Util.listToArrowSep(track.getGroups(), old, nextGroup.getDisplayName(), false));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user