From 86c94786cfb12f24068fd2303db31ce0ab78a0f9 Mon Sep 17 00:00:00 2001 From: Zrips Date: Wed, 3 May 2023 14:26:04 +0300 Subject: [PATCH] Optimize permission check --- .../java/com/gamingmesh/jobs/PermissionManager.java | 12 +++++++++--- .../com/gamingmesh/jobs/commands/list/boost.java | 1 - .../gamingmesh/jobs/commands/list/entitylist.java | 2 +- .../gamingmesh/jobs/container/QuestProgression.java | 9 +++++---- .../com/gamingmesh/jobs/listeners/JobsListener.java | 6 +++--- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/PermissionManager.java b/src/main/java/com/gamingmesh/jobs/PermissionManager.java index 01ee9281..c89f6e55 100644 --- a/src/main/java/com/gamingmesh/jobs/PermissionManager.java +++ b/src/main/java/com/gamingmesh/jobs/PermissionManager.java @@ -53,7 +53,9 @@ public class PermissionManager { jobs_maxblastfurnaces_AMOUNT(remade("jobs.maxblastfurnaces.%AMOUNT%"), 30), jobs_maxsmokers_AMOUNT(remade("jobs.maxsmokers.%AMOUNT%"), 30), jobs_maxbrewingstands_AMOUNT(remade("jobs.maxbrewingstands.%AMOUNT%"), 30), - jobs_world_WORLDNAME(remade("jobs.world.%WORLDNAME%"), 2); + jobs_world_WORLDNAME(remade("jobs.world.%WORLDNAME%"), 2), + jobs_maxquest_JOBNAME_AMOUNT(remade("jobs.maxquest.%JOBNAME%.%AMOUNT%"), 30), + jobs_maxquest_all_AMOUNT(remade("jobs.maxquest.all.%AMOUNT%"), 30); private int reload; private List perms; @@ -93,7 +95,7 @@ public class PermissionManager { } private int getDelay(String perm) { - return permDelay.getOrDefault(perm, 1); + return permDelay.getOrDefault(perm, 1000); } public PermissionManager() { @@ -165,7 +167,11 @@ public class PermissionManager { double amount = Double.NEGATIVE_INFINITY; permissionInfo permInfo = jPlayer.getPermissionsCache(perm); + if (force || getDelay(perm) + permInfo.getTime() < System.currentTimeMillis()) { + + CMIDebug.c("get", force, getDelay(perm) + permInfo.getTime() < System.currentTimeMillis(), getDelay(perm), permInfo.getTime(), perm); + Map perms = getAll(player, perm); for (Map.Entry permission : perms.entrySet()) { if (!permission.getKey().startsWith(perm) || !permission.getValue()) @@ -176,7 +182,7 @@ public class PermissionManager { if (amount == Double.NEGATIVE_INFINITY) amount = 0D; amount += temp; - }else if (temp > amount) + } else if (temp > amount) amount = temp; } catch (NumberFormatException ex) { Jobs.getPluginLogger().log(java.util.logging.Level.WARNING, ex.getLocalizedMessage()); diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/boost.java b/src/main/java/com/gamingmesh/jobs/commands/list/boost.java index d46ef79d..8248709f 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/boost.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/boost.java @@ -167,7 +167,6 @@ public class boost implements Cmd { if (job.getBoost().getTime(curr) != null && job.getBoost().isValid(curr)) { rm.addHover(CMITimeManager.to24hourShort(job.getBoost().getTime(curr) - System.currentTimeMillis())); - CMIDebug.c(job.getBoost().getTime(curr) - System.currentTimeMillis()); } } if (split.length > 1) diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/entitylist.java b/src/main/java/com/gamingmesh/jobs/commands/list/entitylist.java index a9ce5048..f1ebe907 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/entitylist.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/entitylist.java @@ -36,7 +36,7 @@ public class entitylist implements Cmd { msg.append(c2); } - msg.append(CMIText.firstToUpperCase(type.name())); + msg.append(CMIText.everyFirstToUpperCase(type.name())); } CMIMessages.sendMessage(sender, msg.toString()); diff --git a/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java b/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java index 6829e3bc..e38dba16 100644 --- a/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java +++ b/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java @@ -157,23 +157,24 @@ public class QuestProgression { } } + boolean completed = isCompleted(); + Job questJob = quest.getJob(); - if (questJob != null) { + if (questJob != null && completed) { int maxQuest = jPlayer.getPlayerMaxQuest(questJob.getName()); if (maxQuest > 0 && jPlayer.getDoneQuests() >= maxQuest) { return; } } - if (!isCompleted() && - objective != null) { + if (!completed && objective != null) { Integer old = done.getOrDefault(objective, 0); done.put(objective, old < objective.getAmount() ? old + 1 : objective.getAmount()); } jPlayer.setSaved(false); - if (!isCompleted() || !player.isOnline() || givenReward) + if (!completed || !player.isOnline() || givenReward) return; givenReward = true; diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java index 12383444..53a1fd52 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java @@ -531,9 +531,9 @@ public class JobsListener implements Listener { Chunk from = event.getFrom().getChunk(); Chunk to = event.getTo().getChunk(); - if (from != to) { - plugin.getServer().getPluginManager().callEvent(new JobsChunkChangeEvent(event.getPlayer(), from, to)); - } +// if (from != to) { +// plugin.getServer().getPluginManager().callEvent(new JobsChunkChangeEvent(event.getPlayer(), from, to)); +// } } @EventHandler(ignoreCancelled = true)