From 96cfcf78e90c80e77852eb9521263e6da86173b3 Mon Sep 17 00:00:00 2001 From: MachiganMC Date: Sat, 7 Oct 2023 02:27:59 +0200 Subject: [PATCH 1/3] refactor(vault): change way to hook providers Also the Permission provider has been added to get permission of an offline player. This has be done to easily add more providers in the future but also avoid code repetitions (like logging if Vault is enabled). --- .../com/gamingmesh/jobs/HookEconomyTask.java | 114 ++++++------------ .../gamingmesh/jobs/HookPermissionTask.java | 15 +++ .../java/com/gamingmesh/jobs/HookVault.java | 60 +++++++++ src/main/java/com/gamingmesh/jobs/Jobs.java | 102 +++++----------- 4 files changed, 141 insertions(+), 150 deletions(-) create mode 100644 src/main/java/com/gamingmesh/jobs/HookPermissionTask.java create mode 100644 src/main/java/com/gamingmesh/jobs/HookVault.java diff --git a/src/main/java/com/gamingmesh/jobs/HookEconomyTask.java b/src/main/java/com/gamingmesh/jobs/HookEconomyTask.java index ab51d1e7..eda9dd14 100644 --- a/src/main/java/com/gamingmesh/jobs/HookEconomyTask.java +++ b/src/main/java/com/gamingmesh/jobs/HookEconomyTask.java @@ -1,80 +1,34 @@ -/** - * Jobs Plugin for Bukkit - * Copyright (C) 2011 Zak Ford - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.gamingmesh.jobs; - -import org.bukkit.plugin.RegisteredServiceProvider; - -import com.gamingmesh.jobs.economy.BlackholeEconomy; -import com.gamingmesh.jobs.economy.VaultEconomy; - -import net.Zrips.CMILib.Messages.CMIMessages; -import net.milkbowl.vault.economy.Economy; - -public class HookEconomyTask implements Runnable { - - private Jobs plugin; - - public HookEconomyTask(Jobs plugin) { - this.plugin = plugin; - } - - enum hookResult { - novault, noeconomy, pass; - - } - - @Override - public void run() { - - hookResult result = setVault(); - - if (result.equals(hookResult.pass)) { - return; - } - - // no Economy found - Jobs.setEconomy(new BlackholeEconomy()); - Jobs.getPluginLogger().severe("==================== " + plugin.getDescription().getName() + " ===================="); - if (result.equals(hookResult.novault)) { - Jobs.getPluginLogger().severe("Vault is required by this plugin for economy support!"); - Jobs.getPluginLogger().severe("Please install them first!"); - Jobs.getPluginLogger().severe("You can find the latest versions here:"); - Jobs.getPluginLogger().severe("https://www.spigotmc.org/resources/34315/"); - } else { - Jobs.getPluginLogger().severe("Vault detected but economy plugin still missing!"); - Jobs.getPluginLogger().severe("Please install Vault supporting economy plugin!"); - } - Jobs.getPluginLogger().severe("=============================================="); - } - - private hookResult setVault() { - if (!plugin.getServer().getPluginManager().isPluginEnabled("Vault")) - return hookResult.novault; - - RegisteredServiceProvider provider = plugin.getServer().getServicesManager().getRegistration(Economy.class); - if (provider == null) { - return hookResult.noeconomy; - } - - Jobs.setEconomy(new VaultEconomy(provider.getProvider())); - CMIMessages.consoleMessage("&e[" + plugin.getDescription().getName() + "] Successfully linked with Vault. (" + provider.getProvider().getName() + ")"); - return hookResult.pass; - } - -} +/** + * Jobs Plugin for Bukkit + * Copyright (C) 2011 Zak Ford + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.gamingmesh.jobs; + +import com.gamingmesh.jobs.economy.VaultEconomy; +import net.milkbowl.vault.economy.Economy; + +public class HookEconomyTask extends HookVault { + + public HookEconomyTask(Class providerClass) { + super(providerClass); + } + + @Override + void runIfProviderIsFound() { + Jobs.setEconomy(new VaultEconomy(provider.getProvider())); + } +} diff --git a/src/main/java/com/gamingmesh/jobs/HookPermissionTask.java b/src/main/java/com/gamingmesh/jobs/HookPermissionTask.java new file mode 100644 index 00000000..422cf00a --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/HookPermissionTask.java @@ -0,0 +1,15 @@ +package com.gamingmesh.jobs; + +import net.milkbowl.vault.permission.Permission; + +public class HookPermissionTask extends HookVault { + + public HookPermissionTask(Class providerClass) { + super(providerClass); + } + + @Override + void runIfProviderIsFound() { + Jobs.setVaultPermission(this.provider.getProvider()); + } +} diff --git a/src/main/java/com/gamingmesh/jobs/HookVault.java b/src/main/java/com/gamingmesh/jobs/HookVault.java new file mode 100644 index 00000000..5861795c --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/HookVault.java @@ -0,0 +1,60 @@ +package com.gamingmesh.jobs; + +import net.Zrips.CMILib.Messages.CMIMessages; +import org.bukkit.plugin.RegisteredServiceProvider; + +public abstract class HookVault { + private static Boolean vaultEnable = null; + protected Class providerClass; + protected RegisteredServiceProvider provider; + + protected HookVault(Class providerClass) { + this.providerClass = providerClass; + if (!isVaultEnable())return; + this.provider = Jobs.getInstance().getServer().getServicesManager().getRegistration(this.providerClass); + if (this.provider != null) { + logProviderConnected(); + runIfProviderIsFound(); + } else { + logProviderNotFound(); + } + } + + public static boolean isVaultEnable() { + if (vaultEnable == null) { + setIsVaultEnable(); + if (!vaultEnable) + logIfVaultIsNotEnable(); + } + return vaultEnable; + } + + private static void setIsVaultEnable() { + vaultEnable = Jobs.getInstance().getServer().getPluginManager().isPluginEnabled("Vault"); + } + + public static void logIfVaultIsNotEnable() { + if (vaultEnable)return; + Jobs.getPluginLogger().severe("==================== " + Jobs.getInstance().getName() + " ===================="); + Jobs.getPluginLogger().severe("Vault is required by this plugin for economy support!"); + Jobs.getPluginLogger().severe("Please install them first!"); + Jobs.getPluginLogger().severe("You can find the latest versions here:"); + Jobs.getPluginLogger().severe("https://www.spigotmc.org/resources/34315/"); + Jobs.getPluginLogger().severe("=============================================="); + } + + public void logProviderNotFound() { + if (this.provider == null && isVaultEnable()) { + Jobs.getPluginLogger().severe("==================== " + Jobs.getInstance().getDescription().getName() + " ===================="); + Jobs.getPluginLogger().severe("Vault detected but " + this.providerClass.getSimpleName() + " plugin still missing!"); + Jobs.getPluginLogger().severe("Please install Vault supporting " + this.providerClass.getSimpleName() + " plugin!"); + Jobs.getPluginLogger().severe("=============================================="); + } + } + + protected void logProviderConnected() { + CMIMessages.consoleMessage("&e[" + Jobs.getInstance().getName() + "] Successfully linked with Vault. (" + provider.getPlugin().getName() + ")"); + } + + abstract void runIfProviderIsFound(); +} diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index e6f55167..2867177f 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -18,28 +18,6 @@ package com.gamingmesh.jobs; -import java.io.File; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; -import java.util.WeakHashMap; -import java.util.logging.Logger; - -import org.bukkit.Bukkit; -import org.bukkit.block.Block; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.HandlerList; -import org.bukkit.plugin.java.JavaPlugin; - import com.gamingmesh.jobs.Gui.GuiManager; import com.gamingmesh.jobs.Placeholders.Placeholder; import com.gamingmesh.jobs.Placeholders.PlaceholderAPIHook; @@ -47,40 +25,8 @@ import com.gamingmesh.jobs.Signs.SignUtil; import com.gamingmesh.jobs.api.JobsExpGainEvent; import com.gamingmesh.jobs.api.JobsPrePaymentEvent; import com.gamingmesh.jobs.commands.JobsCommands; -import com.gamingmesh.jobs.config.BlockProtectionManager; -import com.gamingmesh.jobs.config.BossBarManager; -import com.gamingmesh.jobs.config.ConfigManager; -import com.gamingmesh.jobs.config.ExploreManager; -import com.gamingmesh.jobs.config.GeneralConfigManager; -import com.gamingmesh.jobs.config.LanguageManager; -import com.gamingmesh.jobs.config.NameTranslatorManager; -import com.gamingmesh.jobs.config.RestrictedAreaManager; -import com.gamingmesh.jobs.config.RestrictedBlockManager; -import com.gamingmesh.jobs.config.ScheduleManager; -import com.gamingmesh.jobs.config.ShopManager; -import com.gamingmesh.jobs.config.TitleManager; -import com.gamingmesh.jobs.config.YmlMaker; -import com.gamingmesh.jobs.container.ActionInfo; -import com.gamingmesh.jobs.container.ActionType; -import com.gamingmesh.jobs.container.ArchivedJobs; -import com.gamingmesh.jobs.container.BlockProtection; -import com.gamingmesh.jobs.container.Boost; -import com.gamingmesh.jobs.container.Convert; -import com.gamingmesh.jobs.container.CurrencyLimit; -import com.gamingmesh.jobs.container.CurrencyType; -import com.gamingmesh.jobs.container.DBAction; -import com.gamingmesh.jobs.container.FastPayment; -import com.gamingmesh.jobs.container.Job; -import com.gamingmesh.jobs.container.JobInfo; -import com.gamingmesh.jobs.container.JobProgression; -import com.gamingmesh.jobs.container.JobsPlayer; -import com.gamingmesh.jobs.container.JobsWorld; -import com.gamingmesh.jobs.container.LoadStatus; -import com.gamingmesh.jobs.container.Log; -import com.gamingmesh.jobs.container.PlayerInfo; -import com.gamingmesh.jobs.container.PlayerPoints; -import com.gamingmesh.jobs.container.Quest; -import com.gamingmesh.jobs.container.QuestProgression; +import com.gamingmesh.jobs.config.*; +import com.gamingmesh.jobs.container.*; import com.gamingmesh.jobs.container.blockOwnerShip.BlockOwnerShip; import com.gamingmesh.jobs.container.blockOwnerShip.BlockTypes; import com.gamingmesh.jobs.dao.JobsClassLoader; @@ -93,32 +39,35 @@ import com.gamingmesh.jobs.economy.Economy; import com.gamingmesh.jobs.economy.PaymentData; import com.gamingmesh.jobs.hooks.HookManager; import com.gamingmesh.jobs.i18n.Language; -import com.gamingmesh.jobs.listeners.JobsListener; -import com.gamingmesh.jobs.listeners.JobsPayment1_14Listener; -import com.gamingmesh.jobs.listeners.JobsPaymentListener; -import com.gamingmesh.jobs.listeners.PistonProtectionListener; -import com.gamingmesh.jobs.listeners.JobsPayment1_16Listener; -import com.gamingmesh.jobs.listeners.PlayerSignEdit1_20Listeners; +import com.gamingmesh.jobs.listeners.*; import com.gamingmesh.jobs.selection.SelectionManager; -import com.gamingmesh.jobs.stuff.Loging; -import com.gamingmesh.jobs.stuff.TabComplete; -import com.gamingmesh.jobs.stuff.ToggleBarHandling; -import com.gamingmesh.jobs.stuff.Util; -import com.gamingmesh.jobs.stuff.VersionChecker; +import com.gamingmesh.jobs.stuff.*; import com.gamingmesh.jobs.stuff.complement.Complement; import com.gamingmesh.jobs.stuff.complement.Complement1; import com.gamingmesh.jobs.stuff.complement.Complement2; import com.gamingmesh.jobs.stuff.complement.JobsChatEvent; import com.gamingmesh.jobs.tasks.BufferedPaymentThread; import com.gamingmesh.jobs.tasks.DatabaseSaveThread; - import net.Zrips.CMILib.ActionBar.CMIActionBar; import net.Zrips.CMILib.Items.CMIMaterial; import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.RawMessages.RawMessage; -import net.Zrips.CMILib.Version.Version; import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; +import net.Zrips.CMILib.Version.Version; +import net.milkbowl.vault.permission.Permission; +import org.bukkit.Bukkit; +import org.bukkit.block.Block; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.sql.SQLException; +import java.util.*; +import java.util.logging.Logger; public final class Jobs extends JavaPlugin { @@ -142,6 +91,8 @@ public final class Jobs extends JavaPlugin { private static GeneralConfigManager gConfigManager; private static BufferedEconomy economy; + + private static Permission vaultPermission; private static PermissionHandler permissionHandler; private static PermissionManager permissionManager; @@ -691,6 +642,10 @@ public final class Jobs extends JavaPlugin { economy = new BufferedEconomy(getInstance(), eco); } + public static void setVaultPermission(Permission permission) { + vaultPermission = permission; + } + /** * Gets the economy handler * @return the economy handler @@ -699,6 +654,10 @@ public final class Jobs extends JavaPlugin { return economy; } + public static Permission getVaultPermission() { + return vaultPermission; + } + /** * Gets the version check manager * @return the version check manager @@ -762,7 +721,10 @@ public final class Jobs extends JavaPlugin { } // register economy - CMIScheduler.get().runTask(new HookEconomyTask(this)); + CMIScheduler.get().runTask(() -> new HookEconomyTask(net.milkbowl.vault.economy.Economy.class)); + + // register permission from vault + CMIScheduler.get().runTask(() -> new HookPermissionTask(Permission.class)); dao.loadBlockProtection(); getExploreManager().load(); From 72f745aeb3de3ce14831445a1f1e2dfae3418839 Mon Sep 17 00:00:00 2001 From: MachiganMC Date: Sat, 7 Oct 2023 02:29:47 +0200 Subject: [PATCH 2/3] feat(tops): add possibility to be hidder from tops To do that, the part of the command 'top' and 'gtop' has been moved into an asynchronous thread because of 'unsafe Vault lookups from LuckPerms'. If it enable, LP prevent a plugin to check a perm of an online player on the main thread. Two new nodes perms have been added : - `jobs.hidetop.`: to be hidden from a specific job top (replace by * to be hidden from all). - `jobs.hidegtop`: to be hidden from the jobs global top. --- .../gamingmesh/jobs/commands/list/gtop.java | 57 ++++++++++++------- .../gamingmesh/jobs/commands/list/top.java | 54 ++++++++++++------ src/main/resources/plugin.yml | 6 ++ 3 files changed, 80 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/gtop.java b/src/main/java/com/gamingmesh/jobs/commands/list/gtop.java index 6eaab9cd..5a70aa0d 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/gtop.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/gtop.java @@ -1,21 +1,21 @@ package com.gamingmesh.jobs.commands.list; -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.scoreboard.DisplaySlot; - import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.TopList; import com.gamingmesh.jobs.i18n.Language; - import net.Zrips.CMILib.Container.PageInfo; import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.Scoreboards.CMIScoreboard; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.DisplaySlot; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; public class gtop implements Cmd { @@ -52,10 +52,17 @@ public class gtop implements Cmd { int amount = Jobs.getGCManager().JobsTopAmount; PageInfo pi = new PageInfo(amount, Jobs.getPlayerManager().getPlayersCache().size(), page); - List FullList = Jobs.getJobsDAO().getGlobalTopList(pi.getStart()); + Bukkit.getScheduler().runTaskAsynchronously(Jobs.getInstance(), () -> showGlobalTop(sender, pi, amount)); + return true; + } + + private static void showGlobalTop(CommandSender sender, PageInfo pi, int amount) { + Player player = (Player) sender; + List FullList = Jobs.getJobsDAO().getGlobalTopList(pi.getStart()) + .stream().filter(gtop::hasToBeSeenInGlobalTop).collect(Collectors.toList()); if (FullList.isEmpty()) { Language.sendMessage(sender, "command.gtop.error.nojob"); - return true; + return; } if (!Jobs.getGCManager().ShowToplistInScoreboard) { @@ -67,11 +74,11 @@ public class gtop implements Cmd { break; Language.sendMessage(sender, "command.gtop.output.list", - "%number%", pi.getPositionForOutput(i), - "%playername%", One.getPlayerInfo().getName(), - "%playerdisplayname%", One.getPlayerInfo().getDisplayName(), - "%level%", One.getLevel(), - "%exp%", One.getExp()); + "%number%", pi.getPositionForOutput(i), + "%playername%", One.getPlayerInfo().getName(), + "%playerdisplayname%", One.getPlayerInfo().getDisplayName(), + "%level%", One.getLevel(), + "%exp%", One.getExp()); ++i; } } else { @@ -82,10 +89,10 @@ public class gtop implements Cmd { break; ls.add(Jobs.getLanguage().getMessage("scoreboard.line", - "%number%", pi.getPositionForOutput(i), - "%playername%", one.getPlayerInfo().getName(), - "%playerdisplayname%", one.getPlayerInfo().getDisplayName(), - "%level%", one.getLevel())); + "%number%", pi.getPositionForOutput(i), + "%playername%", one.getPlayerInfo().getName(), + "%playerdisplayname%", one.getPlayerInfo().getDisplayName(), + "%level%", one.getLevel())); ++i; } @@ -93,6 +100,16 @@ public class gtop implements Cmd { } pi.autoPagination(sender, "jobs gtop"); - return true; + } + + private static boolean hasToBeSeenInGlobalTop(TopList topList) { + Player player = topList.getPlayerInfo().getJobsPlayer().getPlayer(); + if (player != null) + return !player.hasPermission("jobs.hidegtop"); + return !Jobs.getVaultPermission().playerHas( + null, + Bukkit.getOfflinePlayer(topList.getPlayerInfo().getUuid()), + "jobs.hidegtop" + ); } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/top.java b/src/main/java/com/gamingmesh/jobs/commands/list/top.java index 09dc77b5..d2f7abcd 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/top.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/top.java @@ -1,22 +1,23 @@ package com.gamingmesh.jobs.commands.list; -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.scoreboard.DisplaySlot; - import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.TopList; import com.gamingmesh.jobs.i18n.Language; - import net.Zrips.CMILib.Container.PageInfo; import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.Scoreboards.CMIScoreboard; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.DisplaySlot; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; public class top implements Cmd { @@ -56,11 +57,19 @@ public class top implements Cmd { int workingIn = Jobs.getUsedSlots(job); PageInfo pi = new PageInfo(Jobs.getGCManager().JobsTopAmount, workingIn, page); + final int finalPage = page; + Bukkit.getScheduler().runTaskAsynchronously(Jobs.getInstance(), () ->showTop(sender, job, pi, finalPage) ); + return true; + } + + private static void showTop(CommandSender sender, Job job, PageInfo pi, int page) { + Player player = (Player) sender; + List fullList = Jobs.getJobsDAO().toplist(job.getName(), pi.getStart()) + .stream().filter(topList -> hasToBeSeenInTop(topList, job)).collect(Collectors.toList()); - List fullList = Jobs.getJobsDAO().toplist(job.getName(), pi.getStart()); if (fullList.isEmpty()) { CMIMessages.sendMessage(sender, LC.info_NoInformation); - return true; + return; } int place = 1; @@ -69,15 +78,16 @@ public class top implements Cmd { Language.sendMessage(sender, "command.top.output.topline", "%jobname%", job.getName(), "%amount%", Jobs.getGCManager().JobsTopAmount); for (TopList one : fullList) { + System.out.println(one.getPlayerInfo().getName()); if (place > Jobs.getGCManager().JobsTopAmount) break; Language.sendMessage(sender, "command.top.output.list", - "%number%", ((page - 1) * Jobs.getGCManager().JobsTopAmount) + place, - "%playername%", one.getPlayerInfo().getName(), - "%playerdisplayname%", one.getPlayerInfo().getDisplayName(), - "%level%", one.getLevel(), - "%exp%", one.getExp()); + "%number%", ((page - 1) * Jobs.getGCManager().JobsTopAmount) + place, + "%playername%", one.getPlayerInfo().getName(), + "%playerdisplayname%", one.getPlayerInfo().getDisplayName(), + "%level%", one.getLevel(), + "%exp%", one.getExp()); place++; } pi.autoPagination(sender, "jobs top " + job.getName()); @@ -88,7 +98,7 @@ public class top implements Cmd { if (place > Jobs.getGCManager().JobsTopAmount) break; ls.add(Jobs.getLanguage().getMessage("scoreboard.line", "%number%", ((page - 1) * Jobs.getGCManager().JobsTopAmount) + place, - "%playername%", one.getPlayerInfo().getName(), "%playerdisplayname%", one.getPlayerInfo().getDisplayName(), "%level%", one.getLevel())); + "%playername%", one.getPlayerInfo().getName(), "%playerdisplayname%", one.getPlayerInfo().getDisplayName(), "%level%", one.getLevel())); place++; } @@ -96,6 +106,16 @@ public class top implements Cmd { pi.autoPagination(sender, "jobs top " + job.getName()); } - return true; } + + private static boolean hasToBeSeenInTop(TopList topList, Job job) { + Player player = topList.getPlayerInfo().getJobsPlayer().getPlayer(); + if (player != null) + return !player.hasPermission("jobs.hidetop.*") || !player.hasPermission("jobs.hidetop." + job.getName().toLowerCase()); + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(topList.getPlayerInfo().getUuid()); + return ! + (Jobs.getVaultPermission().playerHas(null, offlinePlayer, "jobs.hidetop.*") + || Jobs.getVaultPermission().playerHas(null, offlinePlayer, "jobs.hidetop." + job.getName().toLowerCase())); + } + } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b3c422a8..4c90794d 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -232,3 +232,9 @@ permissions: jobs.area.remove: description: Grants access to the area remove command default: op + jobs.hidetop.*: + description: Prevent player to be shown in all job top + default: false + jobs.hidegtop: + description: Prevent player to be shown in the global jobs top + default: false From 8fcbcdd80d4dadbf526b3a10c42a01eaac92a816 Mon Sep 17 00:00:00 2001 From: MachiganMC Date: Sat, 7 Oct 2023 02:42:52 +0200 Subject: [PATCH 3/3] fix(vault): check vault before checking providers Because of the new providers hookers, a use of the proviers class was perform before checking if Vault was enabled. And if Vault was not enabled there was a `NoClassDefFoundError`. Now a first Vault check is done before the use of the providers class. --- src/main/java/com/gamingmesh/jobs/Jobs.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index 2867177f..7dd3761a 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -720,11 +720,14 @@ public final class Jobs extends JavaPlugin { complement = new Complement1(); } - // register economy - CMIScheduler.get().runTask(() -> new HookEconomyTask(net.milkbowl.vault.economy.Economy.class)); + if (HookVault.isVaultEnable()) { + // register economy + CMIScheduler.get().runTask(() -> new HookEconomyTask(net.milkbowl.vault.economy.Economy.class)); + + // register permission from vault + CMIScheduler.get().runTask(() -> new HookPermissionTask(Permission.class)); + } - // register permission from vault - CMIScheduler.get().runTask(() -> new HookPermissionTask(Permission.class)); dao.loadBlockProtection(); getExploreManager().load();