mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 11:38:40 +01:00
bug fixes
This commit is contained in:
parent
0831585a27
commit
9f5e194a6e
@ -151,20 +151,26 @@ public interface Node extends Map.Entry<String, Boolean> {
|
||||
|
||||
/**
|
||||
* @return the time in Unix time when this node will expire
|
||||
* @throws IllegalStateException if the node is not temporary
|
||||
*/
|
||||
long getExpiryUnixTime();
|
||||
|
||||
/**
|
||||
* @return the {@link Date} when this node will expire
|
||||
* @throws IllegalStateException if the node is not temporary
|
||||
*/
|
||||
Date getExpiry();
|
||||
|
||||
/**
|
||||
* @return the number of seconds until this permission will expire
|
||||
* @throws IllegalStateException if the node is not temporary
|
||||
*/
|
||||
long getSecondsTilExpiry();
|
||||
|
||||
/**
|
||||
* Return true if the node has expired.
|
||||
* This also returns false if the node is not temporary
|
||||
*
|
||||
* @return true if this node has expired
|
||||
*/
|
||||
boolean hasExpired();
|
||||
|
@ -55,7 +55,7 @@ import static me.lucko.luckperms.utils.ArgumentChecker.unescapeCharacters;
|
||||
*
|
||||
* Registered on normal priority so other plugins can override.
|
||||
*/
|
||||
class VaultChatHook extends Chat {
|
||||
public class VaultChatHook extends Chat {
|
||||
|
||||
@Setter
|
||||
private LPBukkitPlugin plugin;
|
||||
|
@ -33,7 +33,7 @@ import me.lucko.luckperms.groups.Group;
|
||||
import me.lucko.luckperms.users.User;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
class VaultPermissionHook extends Permission {
|
||||
public class VaultPermissionHook extends Permission {
|
||||
|
||||
@Setter
|
||||
private LPBukkitPlugin plugin;
|
||||
|
@ -145,13 +145,13 @@ public abstract class SubCommand<T> {
|
||||
}
|
||||
|
||||
protected static void save(User user, Sender sender, LuckPermsPlugin plugin) {
|
||||
user.refreshPermissions();
|
||||
|
||||
if (plugin.getDatastore().saveUser(user)) {
|
||||
Message.USER_SAVE_SUCCESS.send(sender);
|
||||
} else {
|
||||
Message.USER_SAVE_ERROR.send(sender);
|
||||
}
|
||||
|
||||
user.refreshPermissions();
|
||||
}
|
||||
|
||||
protected static void save(Group group, Sender sender, LuckPermsPlugin plugin) {
|
||||
|
@ -45,7 +45,7 @@ public class GroupSetPermission extends SubCommand<Group> {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
String node = args.get(0);
|
||||
String node = args.get(0).replace("{SPACE}", " ");
|
||||
String bool = args.get(1).toLowerCase();
|
||||
|
||||
if (ArgumentChecker.checkNode(node)) {
|
||||
|
@ -47,7 +47,7 @@ public class GroupSetTempPermission extends SubCommand<Group> {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
String node = args.get(0);
|
||||
String node = args.get(0).replace("{SPACE}", " ");
|
||||
String bool = args.get(1).toLowerCase();
|
||||
|
||||
if (ArgumentChecker.checkNode(node)) {
|
||||
|
@ -45,7 +45,7 @@ public class GroupUnSetPermission extends SubCommand<Group> {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
String node = args.get(0);
|
||||
String node = args.get(0).replace("{SPACE}", " ");
|
||||
|
||||
if (ArgumentChecker.checkNode(node)) {
|
||||
sendUsage(sender, label);
|
||||
|
@ -46,7 +46,7 @@ public class GroupUnsetTempPermission extends SubCommand<Group> {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
|
||||
String node = args.get(0);
|
||||
String node = args.get(0).replace("{SPACE}", " ");
|
||||
|
||||
if (ArgumentChecker.checkNode(node)) {
|
||||
sendUsage(sender, label);
|
||||
|
@ -43,7 +43,6 @@ public class UserClear extends SubCommand<User> {
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
user.clearNodes();
|
||||
plugin.getUserManager().giveDefaults(user);
|
||||
Message.CLEAR_SUCCESS.send(sender, user.getName());
|
||||
LogEntry.build().actor(sender).acted(user).action("clear").build().submit(plugin, sender);
|
||||
|
||||
|
@ -46,7 +46,7 @@ public class UserSetPermission extends SubCommand<User> {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
String node = args.get(0);
|
||||
String node = args.get(0).replace("{SPACE}", " ");
|
||||
String bool = args.get(1).toLowerCase();
|
||||
|
||||
if (ArgumentChecker.checkNode(node)) {
|
||||
|
@ -47,7 +47,7 @@ public class UserSetTempPermission extends SubCommand<User> {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
String node = args.get(0);
|
||||
String node = args.get(0).replace("{SPACE}", " ");
|
||||
String bool = args.get(1).toLowerCase();
|
||||
|
||||
if (ArgumentChecker.checkNode(node)) {
|
||||
|
@ -45,7 +45,7 @@ public class UserUnSetPermission extends SubCommand<User> {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
String node = args.get(0);
|
||||
String node = args.get(0).replace("{SPACE}", " ");
|
||||
|
||||
if (ArgumentChecker.checkNode(node)) {
|
||||
sendUsage(sender, label);
|
||||
|
@ -46,7 +46,7 @@ public class UserUnsetTempPermission extends SubCommand<User> {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
|
||||
String node = args.get(0);
|
||||
String node = args.get(0).replace("{SPACE}", " ");
|
||||
|
||||
if (ArgumentChecker.checkNode(node)) {
|
||||
sendUsage(sender, label);
|
||||
|
@ -81,17 +81,21 @@ public abstract class PermissionHolder {
|
||||
public SortedSet<Node> getPermissions() {
|
||||
// Returns no duplicate nodes. as in, nodes with the same value.
|
||||
|
||||
TreeSet<Node> combined = new TreeSet<>(PRIORITY_COMPARATOR);
|
||||
combined.addAll(nodes);
|
||||
combined.addAll(transientNodes);
|
||||
|
||||
TreeSet<Node> permissions = new TreeSet<>(PRIORITY_COMPARATOR);
|
||||
permissions.addAll(nodes);
|
||||
permissions.addAll(transientNodes);
|
||||
|
||||
Iterator<Node> iterator = permissions.descendingIterator();
|
||||
while (iterator.hasNext()) {
|
||||
Node entry = iterator.next();
|
||||
combined:
|
||||
for (Node node : combined) {
|
||||
for (Node other : permissions) {
|
||||
if (node.equalsIgnoringValue(other)) {
|
||||
continue combined;
|
||||
}
|
||||
}
|
||||
|
||||
permissions.stream()
|
||||
.filter(entry::equalsIgnoringValue) // The node appears again at a higher priority
|
||||
.forEachOrdered(other -> iterator.remove()); // Remove it.
|
||||
permissions.add(node);
|
||||
}
|
||||
|
||||
return permissions;
|
||||
@ -283,7 +287,7 @@ public abstract class PermissionHolder {
|
||||
private static Tristate hasPermission(Set<Node> toQuery, Node node) {
|
||||
for (Node n : toQuery) {
|
||||
if (n.equalsIgnoringValue(node)) {
|
||||
n.getTristate();
|
||||
return n.getTristate();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,8 +178,6 @@ public class FlatfileDatastore extends Datastore {
|
||||
return false;
|
||||
}
|
||||
|
||||
plugin.getUserManager().giveDefaults(user);
|
||||
|
||||
boolean success = doWrite(userFile, writer -> {
|
||||
writer.beginObject();
|
||||
writer.name("uuid").value(user.getUuid().toString());
|
||||
|
@ -146,7 +146,6 @@ public class MongoDBDatastore extends Datastore {
|
||||
|
||||
try (MongoCursor<Document> cursor = c.find(new Document("_id", user.getUuid())).iterator()) {
|
||||
if (!cursor.hasNext()) {
|
||||
plugin.getUserManager().giveDefaults(user);
|
||||
c.insertOne(fromUser(user));
|
||||
} else {
|
||||
Document d = cursor.next();
|
||||
|
@ -184,8 +184,6 @@ abstract class SQLDatastore extends Datastore {
|
||||
boolean onResult(ResultSet resultSet) throws SQLException {
|
||||
boolean success = true;
|
||||
if (!resultSet.next()) {
|
||||
plugin.getUserManager().giveDefaults(user);
|
||||
|
||||
success = runQuery(new QueryPS(USER_INSERT) {
|
||||
@Override
|
||||
void onRun(PreparedStatement preparedStatement) throws SQLException {
|
||||
|
@ -286,11 +286,8 @@ public abstract class User extends PermissionHolder implements Identifiable<UUID
|
||||
* Clear all of the users permission nodes
|
||||
*/
|
||||
public void clearNodes() {
|
||||
String defaultGroupNode = getPlugin().getConfiguration().getDefaultGroupNode();
|
||||
getNodes().clear();
|
||||
try {
|
||||
setPermission(defaultGroupNode, true);
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
getPlugin().getUserManager().giveDefaultIfNeeded(this, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,6 +24,8 @@ package me.lucko.luckperms.users;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.api.data.Callback;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.utils.AbstractManager;
|
||||
import me.lucko.luckperms.utils.Identifiable;
|
||||
@ -51,6 +53,12 @@ public abstract class UserManager extends AbstractManager<UUID, User> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(User u) {
|
||||
giveDefaultIfNeeded(u, true);
|
||||
super.set(u);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy(User from, User to) {
|
||||
to.setNodes(from.getNodes());
|
||||
@ -62,12 +70,27 @@ public abstract class UserManager extends AbstractManager<UUID, User> {
|
||||
* Set a user to the default group
|
||||
* @param user the user to give to
|
||||
*/
|
||||
public void giveDefaults(User user) {
|
||||
// Setup the new user with default values
|
||||
public void giveDefaultIfNeeded(User user, boolean save) {
|
||||
boolean hasGroup = false;
|
||||
for (Node node : user.getPermissions()) {
|
||||
if (node.isGroupNode()) {
|
||||
hasGroup = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasGroup) {
|
||||
user.setPrimaryGroup("default");
|
||||
try {
|
||||
user.setPermission(plugin.getConfiguration().getDefaultGroupNode(), true);
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
user.setPrimaryGroup(plugin.getConfiguration().getDefaultGroupName());
|
||||
user.setPermission("group.default", true);
|
||||
} catch (ObjectAlreadyHasException ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
|
||||
if (save) {
|
||||
plugin.getDatastore().saveUser(user, Callback.empty());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -61,7 +61,7 @@ public abstract class AbstractManager<I, T extends Identifiable<I>> {
|
||||
public void updateOrSet(T t) {
|
||||
if (!isLoaded(t.getId())) {
|
||||
// The object isn't already loaded
|
||||
objects.put(t.getId(), t);
|
||||
set(t);
|
||||
} else {
|
||||
copy(t, objects.get(t.getId()));
|
||||
}
|
||||
|
@ -354,7 +354,7 @@ public class Node implements me.lucko.luckperms.api.Node {
|
||||
}
|
||||
|
||||
public boolean hasExpired() {
|
||||
return expireAt < (System.currentTimeMillis() / 1000L);
|
||||
return isTemporary() && expireAt < (System.currentTimeMillis() / 1000L);
|
||||
}
|
||||
|
||||
public Map<String, String> getExtraContexts() {
|
||||
@ -485,34 +485,26 @@ public class Node implements me.lucko.luckperms.api.Node {
|
||||
}
|
||||
}
|
||||
|
||||
if (other.getServer().isPresent() != this.getServer().isPresent()) {
|
||||
if (other.getServer().isPresent() == this.getServer().isPresent()) {
|
||||
if (other.getServer().isPresent()) {
|
||||
if (!other.getServer().get().equalsIgnoreCase(this.getServer().get())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (other.getWorld().isPresent() != this.getWorld().isPresent()) {
|
||||
if (other.getWorld().isPresent() == this.getWorld().isPresent()) {
|
||||
if (other.getWorld().isPresent()) {
|
||||
if (!other.getWorld().get().equalsIgnoreCase(this.getWorld().get())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!other.getExtraContexts().equals(this.getExtraContexts())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (other.isTemporary() != this.isTemporary()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -522,34 +514,30 @@ public class Node implements me.lucko.luckperms.api.Node {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (other.getServer().isPresent() != this.getServer().isPresent()) {
|
||||
if (other.isTemporary() != this.isTemporary()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (other.getServer().isPresent() == this.getServer().isPresent()) {
|
||||
if (other.getServer().isPresent()) {
|
||||
if (!other.getServer().get().equalsIgnoreCase(this.getServer().get())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (other.getWorld().isPresent() != this.getWorld().isPresent()) {
|
||||
if (other.getWorld().isPresent() == this.getWorld().isPresent()) {
|
||||
if (other.getWorld().isPresent()) {
|
||||
if (!other.getWorld().get().equalsIgnoreCase(this.getWorld().get())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!other.getExtraContexts().equals(this.getExtraContexts())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (other.isTemporary() != this.isTemporary()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user