Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to disable optimized multiplier permission lookup #309

Merged
merged 4 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,26 @@ public class BukkitLuckPermsHook extends LuckPermsHook implements Listener {

private final String prefix = "auraskills.multiplier.";
private final Map<UUID, Set<String>> permissionCache = new ConcurrentHashMap<>();
private final boolean usePermissionCache;

public BukkitLuckPermsHook(AuraSkillsPlugin plugin, ConfigurationNode config) {
super(plugin, config);

this.usePermissionCache = config.node("use_permission_cache").getBoolean(true);

if (!this.usePermissionCache) return;

luckPerms.getEventBus().subscribe(NodeAddEvent.class,
event -> handleEvent(event.getNode(), event.getTarget()));

luckPerms.getEventBus().subscribe(NodeRemoveEvent.class,
event -> handleEvent(event.getNode(), event.getTarget()));
}

public boolean usePermissionCache() {
return usePermissionCache;
}

private void handleEvent(Node node, PermissionHolder target) {
if (!(node instanceof PermissionNode) && !(node instanceof InheritanceNode)) return;

Expand All @@ -56,7 +65,7 @@ private void handleEvent(Node node, PermissionHolder target) {
() -> {
Player player = Bukkit.getPlayer(user.getUniqueId());
// In case if someone logs out in that 500 ms timeframe
if(player == null || !player.isOnline()) return;
if (player == null || !player.isOnline()) return;
permissionCache.put(user.getUniqueId(), getMultiplierPermissions(user.getUniqueId()));
},
500,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public double getPermissionMultiplier(@Nullable Skill skill) {
}
double multiplier = 0.0;

if (plugin.getHookManager().isRegistered(BukkitLuckPermsHook.class)) {
if (plugin.getHookManager().isRegistered(BukkitLuckPermsHook.class)
&& plugin.getHookManager().getHook(BukkitLuckPermsHook.class).usePermissionCache()) {
Set<String> permissions = plugin.getHookManager().getHook(BukkitLuckPermsHook.class).getMultiplierPermissions(player);
for (String permission : permissions) {
multiplier += getMultiplierFromPermission(permission, skill);
Expand Down Expand Up @@ -169,7 +170,8 @@ public int getPermissionJobLimit() {
if (value > highestLimit) {
highestLimit = value;
}
} catch (NumberFormatException ignored) {}
} catch (NumberFormatException ignored) {
}
}
}
return highestLimit;
Expand Down
9 changes: 5 additions & 4 deletions common/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sql:
max_lifetime: 1800000
keepalive_time: 0
default_language: en
languages: [en, es, fr, de, zh-CN, zh-TW, pt-BR, it, cs, pl, uk, ko, nl, ja, ru, id, vi, tr, fi, th]
languages: [ en, es, fr, de, zh-CN, zh-TW, pt-BR, it, cs, pl, uk, ko, nl, ja, ru, id, vi, tr, fi, th ]
try_detect_client_language: false
hooks:
HolographicDisplays:
Expand All @@ -34,6 +34,7 @@ hooks:
enabled: true
LuckPerms:
enabled: true
use_permission_cache: true
Oraxen:
enabled: true
PlaceholderAPI:
Expand Down Expand Up @@ -168,7 +169,7 @@ damage_holograms:
colors:
default: gray
critical:
digits: [white, yellow, gold, red, dark_red, dark_purple, light_purple, blue, dark_blue]
digits: [ white, yellow, gold, red, dark_red, dark_purple, light_purple, blue, dark_blue ]
leaderboards:
update_period: 6000
update_delay: 6000
Expand Down Expand Up @@ -228,10 +229,10 @@ requirement:
prevent_weapon_use: true
prevent_block_place: true
prevent_interact: true
global: []
global: [ ]
armor:
prevent_armor_equip: true
global: []
global: [ ]
critical:
enabled:
sword: true
Expand Down
Loading