Remove unnecessary reflection
This commit is contained in:
parent
770b7dc282
commit
ba04fb320b
@ -32,6 +32,7 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.player.*;
|
import org.bukkit.event.player.*;
|
||||||
import org.bukkit.permissions.PermissionAttachment;
|
import org.bukkit.permissions.PermissionAttachment;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
class BukkitListener extends AbstractListener implements Listener {
|
class BukkitListener extends AbstractListener implements Listener {
|
||||||
@ -67,13 +68,14 @@ class BukkitListener extends AbstractListener implements Listener {
|
|||||||
BukkitUser u = (BukkitUser) user;
|
BukkitUser u = (BukkitUser) user;
|
||||||
|
|
||||||
PermissionAttachment attachment = player.addAttachment(plugin);
|
PermissionAttachment attachment = player.addAttachment(plugin);
|
||||||
|
Map<String, Boolean> newPermMap = new ConcurrentHashMap<>();
|
||||||
try {
|
try {
|
||||||
BukkitUser.getPermissionsField().set(attachment, new ConcurrentHashMap<>());
|
BukkitUser.getPermissionsField().set(attachment, newPermMap);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
u.setAttachment(attachment);
|
u.setAttachment(new BukkitUser.PermissionAttachmentHolder(attachment, newPermMap));
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.doAsync(user::refreshPermissions);
|
plugin.doAsync(user::refreshPermissions);
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.users;
|
package me.lucko.luckperms.users;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import me.lucko.luckperms.LPBukkitPlugin;
|
import me.lucko.luckperms.LPBukkitPlugin;
|
||||||
@ -52,7 +54,7 @@ public class BukkitUser extends User {
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
private PermissionAttachment attachment = null;
|
private PermissionAttachmentHolder attachment = null;
|
||||||
|
|
||||||
BukkitUser(UUID uuid, LPBukkitPlugin plugin) {
|
BukkitUser(UUID uuid, LPBukkitPlugin plugin) {
|
||||||
super(uuid, plugin);
|
super(uuid, plugin);
|
||||||
@ -83,7 +85,7 @@ public class BukkitUser extends User {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// The map in the LP PermissionAttachment is a ConcurrentHashMap. We can modify it's contents async.
|
// The map in the LP PermissionAttachment is a ConcurrentHashMap. We can modify it's contents async.
|
||||||
Map<String, Boolean> existing = (Map<String, Boolean>) getPermissionsField().get(attachment);
|
Map<String, Boolean> existing = attachment.getPermissions();
|
||||||
|
|
||||||
boolean different = false;
|
boolean different = false;
|
||||||
if (toApply.size() != existing.size()) {
|
if (toApply.size() != existing.size()) {
|
||||||
@ -107,7 +109,7 @@ public class BukkitUser extends User {
|
|||||||
Shouldn't be too taxing on the server. This only gets called when permissions have actually changed,
|
Shouldn't be too taxing on the server. This only gets called when permissions have actually changed,
|
||||||
which is like once per user per login, assuming their permissions don't get modified. */
|
which is like once per user per login, assuming their permissions don't get modified. */
|
||||||
plugin.doSync(() -> {
|
plugin.doSync(() -> {
|
||||||
attachment.getPermissible().recalculatePermissions();
|
attachment.getAttachment().getPermissible().recalculatePermissions();
|
||||||
plugin.getApiProvider().fireEventAsync(new UserPermissionRefreshEvent(new UserLink(this)));
|
plugin.getApiProvider().fireEventAsync(new UserPermissionRefreshEvent(new UserLink(this)));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -115,4 +117,12 @@ public class BukkitUser extends User {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EqualsAndHashCode
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class PermissionAttachmentHolder {
|
||||||
|
private final PermissionAttachment attachment;
|
||||||
|
private final Map<String, Boolean> permissions;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ public class BukkitUserManager extends UserManager {
|
|||||||
Player player = plugin.getServer().getPlayer(plugin.getUuidCache().getExternalUUID(u.getUuid()));
|
Player player = plugin.getServer().getPlayer(plugin.getUuidCache().getExternalUUID(u.getUuid()));
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
player.removeAttachment(u.getAttachment());
|
player.removeAttachment(u.getAttachment().getAttachment());
|
||||||
}
|
}
|
||||||
u.setAttachment(null);
|
u.setAttachment(null);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user