Fix generating unset commands for temporary nodes

This commit is contained in:
Luck 2017-07-07 19:39:31 +01:00
parent b12ce943f7
commit 0befa6a491
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
7 changed files with 23 additions and 46 deletions

View File

@ -169,12 +169,8 @@ public class MetaInfo extends SharedSubCommand {
), '¥')); ), '¥'));
boolean group = !(holder instanceof User); boolean group = !(holder instanceof User);
String command = NodeFactory.nodeAsCommand(node, group ? holder.getObjectName() : holder.getFriendlyName(), group) String command = NodeFactory.nodeAsCommand(node, group ? holder.getObjectName() : holder.getFriendlyName(), group, false)
.replace("/luckperms", "/" + label) .replace("/luckperms", "/" + label);
.replace("permission set", "permission unset")
.replace("parent add", "parent remove")
.replace(" true", "")
.replace(" false", "");
return component -> { return component -> {
component.hoverEvent(hoverEvent); component.hoverEvent(hoverEvent);
@ -198,12 +194,8 @@ public class MetaInfo extends SharedSubCommand {
), '¥')); ), '¥'));
boolean group = !(holder instanceof User); boolean group = !(holder instanceof User);
String command = NodeFactory.nodeAsCommand(node, group ? holder.getObjectName() : holder.getFriendlyName(), group) String command = NodeFactory.nodeAsCommand(node, group ? holder.getObjectName() : holder.getFriendlyName(), group, false)
.replace("/luckperms", "/" + label) .replace("/luckperms", "/" + label);
.replace("permission set", "permission unset")
.replace("parent add", "parent remove")
.replace(" true", "")
.replace(" false", "");
return component -> { return component -> {
component.hoverEvent(hoverEvent); component.hoverEvent(hoverEvent);

View File

@ -128,12 +128,8 @@ public class ParentInfo extends SharedSubCommand {
), Constants.FORMAT_CHAR)); ), Constants.FORMAT_CHAR));
boolean group = !(holder instanceof User); boolean group = !(holder instanceof User);
String command = NodeFactory.nodeAsCommand(node, group ? holder.getObjectName() : holder.getFriendlyName(), group) String command = NodeFactory.nodeAsCommand(node, group ? holder.getObjectName() : holder.getFriendlyName(), group, false)
.replace("/luckperms", "/" + label) .replace("/luckperms", "/" + label);
.replace("permission set", "permission unset")
.replace("parent add", "parent remove")
.replace(" true", "")
.replace(" false", "");
return component -> { return component -> {
component.hoverEvent(hoverEvent); component.hoverEvent(hoverEvent);

View File

@ -159,12 +159,8 @@ public class PermissionInfo extends SharedSubCommand {
), '¥')); ), '¥'));
boolean group = !(holder instanceof User); boolean group = !(holder instanceof User);
String command = NodeFactory.nodeAsCommand(node, group ? holder.getObjectName() : holder.getFriendlyName(), group) String command = NodeFactory.nodeAsCommand(node, group ? holder.getObjectName() : holder.getFriendlyName(), group, false)
.replace("/luckperms", "/" + label) .replace("/luckperms", "/" + label);
.replace("permission set", "permission unset")
.replace("parent add", "parent remove")
.replace(" true", "")
.replace(" false", "");
return component -> { return component -> {
component.hoverEvent(hoverEvent); component.hoverEvent(hoverEvent);

View File

@ -196,12 +196,8 @@ public class GroupListMembers extends SubCommand<Group> {
"&7Click to remove this parent from " + holderName "&7Click to remove this parent from " + holderName
), Constants.FORMAT_CHAR)); ), Constants.FORMAT_CHAR));
String command = NodeFactory.nodeAsCommand(perm.asNode(), holderName, group) String command = NodeFactory.nodeAsCommand(perm.asNode(), holderName, group, false)
.replace("/luckperms", "/" + label) .replace("/luckperms", "/" + label);
.replace("permission set", "permission unset")
.replace("parent add", "parent remove")
.replace(" true", "")
.replace(" false", "");
return component -> { return component -> {
component.hoverEvent(hoverEvent); component.hoverEvent(hoverEvent);

View File

@ -195,12 +195,8 @@ public class SearchCommand extends SingleCommand {
"&7Click to remove this node from " + holderName "&7Click to remove this node from " + holderName
), Constants.FORMAT_CHAR)); ), Constants.FORMAT_CHAR));
String command = NodeFactory.nodeAsCommand(perm.asNode(), holderName, group) String command = NodeFactory.nodeAsCommand(perm.asNode(), holderName, group, false)
.replace("/luckperms", "/" + label) .replace("/luckperms", "/" + label);
.replace("permission set", "permission unset")
.replace("parent add", "parent remove")
.replace(" true", "")
.replace(" false", "");
return component -> { return component -> {
component.hoverEvent(hoverEvent); component.hoverEvent(hoverEvent);

View File

@ -135,33 +135,34 @@ public class NodeFactory {
return new NodeBuilder("suffix." + priority + "." + MetaUtils.escapeCharacters(suffix)); return new NodeBuilder("suffix." + priority + "." + MetaUtils.escapeCharacters(suffix));
} }
public static String nodeAsCommand(Node node, String id, boolean group) { public static String nodeAsCommand(Node node, String id, boolean group, boolean set) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("/luckperms ").append(group ? "group " : "user ").append(id).append(" "); sb.append("/luckperms ").append(group ? "group " : "user ").append(id).append(" ");
if (node.isGroupNode()) { if (node.isGroupNode()) {
if (node.isTemporary()) { if (node.isTemporary()) {
sb.append("parent addtemp "); sb.append(set ? "parent addtemp " : "parent removetemp ");
sb.append(node.getGroupName()); sb.append(node.getGroupName());
sb.append(" ").append(node.getExpiryUnixTime());
} else { } else {
sb.append("parent add "); sb.append(set ? "parent add " : "parent remove ");
sb.append(node.getGroupName()); sb.append(node.getGroupName());
} }
return appendContextToCommand(sb, node).toString(); return appendContextToCommand(sb, node).toString();
} }
sb.append(node.isTemporary() ? "permission settemp " : "permission set "); sb.append(node.isTemporary() ? (set ? "permission settemp " : "permission unsettemp ") : (set ? "permission set " : "permission unset "));
if (node.getPermission().contains(" ")) { if (node.getPermission().contains(" ")) {
sb.append("\"").append(node.getPermission()).append("\""); sb.append("\"").append(node.getPermission()).append("\"");
} else { } else {
sb.append(node.getPermission()); sb.append(node.getPermission());
} }
sb.append(" ").append(node.getValue()); if (set) {
sb.append(" ").append(node.getValue());
if (node.isTemporary()) { if (node.isTemporary()) {
sb.append(" ").append(node.getExpiryUnixTime()); sb.append(" ").append(node.getExpiryUnixTime());
}
} }
return appendContextToCommand(sb, node).toString(); return appendContextToCommand(sb, node).toString();

View File

@ -132,7 +132,7 @@ public class Exporter implements Runnable {
.forEach(group -> { .forEach(group -> {
write(writer, "# Export group: " + group.getName()); write(writer, "# Export group: " + group.getName());
for (Node node : group.getNodes().values()) { for (Node node : group.getNodes().values()) {
write(writer, NodeFactory.nodeAsCommand(node, group.getName(), true)); write(writer, NodeFactory.nodeAsCommand(node, group.getName(), true, true));
} }
write(writer, ""); write(writer, "");
log.logAllProgress("Exported {} groups so far.", groupCount.incrementAndGet()); log.logAllProgress("Exported {} groups so far.", groupCount.incrementAndGet());
@ -240,7 +240,7 @@ public class Exporter implements Runnable {
continue; continue;
} }
output.add(NodeFactory.nodeAsCommand(node, user.getUuid().toString(), false)); output.add(NodeFactory.nodeAsCommand(node, user.getUuid().toString(), false, true));
} }
if (!user.getPrimaryGroup().getStoredValue().equalsIgnoreCase("default")) { if (!user.getPrimaryGroup().getStoredValue().equalsIgnoreCase("default")) {