Cleanup a bit

This commit is contained in:
Luck 2017-03-11 21:10:27 +00:00
parent 281060a972
commit 9dc2278083
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
7 changed files with 23 additions and 55 deletions

View File

@ -135,8 +135,7 @@ public class MetaUtils {
for (Node n : toRemove) {
try {
holder.unsetPermission(n);
} catch (ObjectLacksException ignored) {
}
} catch (ObjectLacksException ignored) {}
}
Node.Builder metaNode = LuckPerms.getApi().buildNode("meta." + node + "." + value).setValue(true);

View File

@ -34,15 +34,11 @@ import me.lucko.luckperms.common.core.model.Group;
import me.lucko.luckperms.common.core.model.PermissionHolder;
import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.utils.ExtractedContexts;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import me.lucko.luckperms.exceptions.ObjectLacksException;
import net.milkbowl.vault.chat.Chat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static me.lucko.luckperms.api.MetaUtils.escapeCharacters;
import static me.lucko.luckperms.api.MetaUtils.unescapeCharacters;
@ -75,15 +71,7 @@ public class VaultChatHook extends Chat {
perms.log("Setting meta: '" + node + "' for " + holder.getObjectName() + " on world " + world + ", server " + perms.getServer());
perms.getScheduler().execute(() -> {
List<Node> toRemove = holder.getNodes().stream()
.filter(n -> n.isMeta() && n.getMeta().getKey().equals(node))
.collect(Collectors.toList());
toRemove.forEach(n -> {
try {
holder.unsetPermission(n);
} catch (ObjectLacksException ignored) {}
});
holder.removeIf(n -> n.isMeta() && n.getMeta().getKey().equals(node));
Node.Builder metaNode = NodeFactory.makeMetaNode(node, value).setValue(true);
if (!perms.getServer().equalsIgnoreCase("global")) {
@ -93,10 +81,7 @@ public class VaultChatHook extends Chat {
metaNode.setWorld(finalWorld);
}
try {
holder.setPermission(metaNode.build());
} catch (ObjectAlreadyHasException ignored) {}
holder.setPermissionUnchecked(metaNode.build());
perms.save(holder);
});
}
@ -111,15 +96,7 @@ public class VaultChatHook extends Chat {
perms.getScheduler().execute(() -> {
// remove all prefixes/suffixes directly set on the user/group
List<Node> toRemove = holder.getNodes().stream()
.filter(n -> prefix ? n.isPrefix() : n.isSuffix())
.collect(Collectors.toList());
toRemove.forEach(n -> {
try {
holder.unsetPermission(n);
} catch (ObjectLacksException ignored) {}
});
holder.removeIf(n -> prefix ? n.isPrefix() : n.isSuffix());
// find the max inherited priority & add 10
MetaHolder metaHolder = holder.accumulateMeta(null, null, ExtractedContexts.generate(perms.createContextForWorld(finalWorld)));
@ -134,10 +111,7 @@ public class VaultChatHook extends Chat {
chatMetaNode.setWorld(finalWorld);
}
try {
holder.setPermission(chatMetaNode.build());
} catch (ObjectAlreadyHasException ignored) {}
holder.setPermissionUnchecked(chatMetaNode.build());
perms.save(holder);
});
}

View File

@ -88,12 +88,7 @@ public class MetaRemovePrefix extends SharedSubCommand {
toRemove.add(node);
}
toRemove.forEach(n -> {
try {
holder.unsetPermission(n);
} catch (ObjectLacksException ignored) {
}
});
toRemove.forEach(holder::unsetPermissionUnchecked);
Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size());
save(holder, sender, plugin);

View File

@ -88,12 +88,7 @@ public class MetaRemoveSuffix extends SharedSubCommand {
toRemove.add(node);
}
toRemove.forEach(n -> {
try {
holder.unsetPermission(n);
} catch (ObjectLacksException ignored) {
}
});
toRemove.forEach(holder::unsetPermissionUnchecked);
Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size());
save(holder, sender, plugin);

View File

@ -88,11 +88,7 @@ public class MetaRemoveTempPrefix extends SharedSubCommand {
toRemove.add(node);
}
toRemove.forEach(n -> {
try {
holder.unsetPermission(n);
} catch (ObjectLacksException ignored) {}
});
toRemove.forEach(holder::unsetPermissionUnchecked);
Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size());
save(holder, sender, plugin);

View File

@ -88,12 +88,7 @@ public class MetaRemoveTempSuffix extends SharedSubCommand {
toRemove.add(node);
}
toRemove.forEach(n -> {
try {
holder.unsetPermission(n);
} catch (ObjectLacksException ignored) {
}
});
toRemove.forEach(holder::unsetPermissionUnchecked);
Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size());
save(holder, sender, plugin);

View File

@ -438,6 +438,20 @@ public abstract class PermissionHolder {
invalidateCache(false);
}
public boolean removeIfTransient(Predicate<Node> predicate) {
boolean result;
synchronized (nodes) {
result = transientNodes.removeIf(predicate);
}
if (result) {
invalidateCache(false);
}
return result;
}
/**
* Combines and returns this holders nodes in a priority order.
*