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