Skip to content

Commit

Permalink
Add option to disable optimized multiplier permission lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSzabo committed Aug 5, 2024
1 parent 70dd72a commit 586b980
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
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 optimizePermissionLookup;

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

this.optimizePermissionLookup = getConfig().node("optimize_permission_lookup").getBoolean();

if (!this.optimizePermissionLookup) 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 optimizePermissionLookup() {
return optimizePermissionLookup;
}

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).optimizePermissionLookup()) {
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
optimize_permission_lookup: 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

0 comments on commit 586b980

Please sign in to comment.