mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-25 20:16:13 +01:00
Merge pull request #1669 from MachiganMC/master
Add possibility to be hidden from jobs tops
This commit is contained in:
commit
11972ffe1d
@ -18,63 +18,17 @@
|
|||||||
|
|
||||||
package com.gamingmesh.jobs;
|
package com.gamingmesh.jobs;
|
||||||
|
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
|
||||||
|
|
||||||
import com.gamingmesh.jobs.economy.BlackholeEconomy;
|
|
||||||
import com.gamingmesh.jobs.economy.VaultEconomy;
|
import com.gamingmesh.jobs.economy.VaultEconomy;
|
||||||
|
|
||||||
import net.Zrips.CMILib.Messages.CMIMessages;
|
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
|
||||||
public class HookEconomyTask implements Runnable {
|
public class HookEconomyTask extends HookVault<Economy> {
|
||||||
|
|
||||||
private Jobs plugin;
|
|
||||||
|
|
||||||
public HookEconomyTask(Jobs plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum hookResult {
|
|
||||||
novault, noeconomy, pass;
|
|
||||||
|
|
||||||
|
public HookEconomyTask(Class<Economy> providerClass) {
|
||||||
|
super(providerClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
void runIfProviderIsFound() {
|
||||||
|
|
||||||
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<Economy> provider = plugin.getServer().getServicesManager().getRegistration(Economy.class);
|
|
||||||
if (provider == null) {
|
|
||||||
return hookResult.noeconomy;
|
|
||||||
}
|
|
||||||
|
|
||||||
Jobs.setEconomy(new VaultEconomy(provider.getProvider()));
|
Jobs.setEconomy(new VaultEconomy(provider.getProvider()));
|
||||||
CMIMessages.consoleMessage("&e[" + plugin.getDescription().getName() + "] Successfully linked with Vault. (" + provider.getProvider().getName() + ")");
|
|
||||||
return hookResult.pass;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
15
src/main/java/com/gamingmesh/jobs/HookPermissionTask.java
Normal file
15
src/main/java/com/gamingmesh/jobs/HookPermissionTask.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package com.gamingmesh.jobs;
|
||||||
|
|
||||||
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
|
||||||
|
public class HookPermissionTask extends HookVault<Permission> {
|
||||||
|
|
||||||
|
public HookPermissionTask(Class<Permission> providerClass) {
|
||||||
|
super(providerClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void runIfProviderIsFound() {
|
||||||
|
Jobs.setVaultPermission(this.provider.getProvider());
|
||||||
|
}
|
||||||
|
}
|
60
src/main/java/com/gamingmesh/jobs/HookVault.java
Normal file
60
src/main/java/com/gamingmesh/jobs/HookVault.java
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package com.gamingmesh.jobs;
|
||||||
|
|
||||||
|
import net.Zrips.CMILib.Messages.CMIMessages;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
|
||||||
|
public abstract class HookVault<T> {
|
||||||
|
private static Boolean vaultEnable = null;
|
||||||
|
protected Class<T> providerClass;
|
||||||
|
protected RegisteredServiceProvider<T> provider;
|
||||||
|
|
||||||
|
protected HookVault(Class<T> 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();
|
||||||
|
}
|
@ -18,28 +18,6 @@
|
|||||||
|
|
||||||
package com.gamingmesh.jobs;
|
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.Gui.GuiManager;
|
||||||
import com.gamingmesh.jobs.Placeholders.Placeholder;
|
import com.gamingmesh.jobs.Placeholders.Placeholder;
|
||||||
import com.gamingmesh.jobs.Placeholders.PlaceholderAPIHook;
|
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.JobsExpGainEvent;
|
||||||
import com.gamingmesh.jobs.api.JobsPrePaymentEvent;
|
import com.gamingmesh.jobs.api.JobsPrePaymentEvent;
|
||||||
import com.gamingmesh.jobs.commands.JobsCommands;
|
import com.gamingmesh.jobs.commands.JobsCommands;
|
||||||
import com.gamingmesh.jobs.config.BlockProtectionManager;
|
import com.gamingmesh.jobs.config.*;
|
||||||
import com.gamingmesh.jobs.config.BossBarManager;
|
import com.gamingmesh.jobs.container.*;
|
||||||
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.container.blockOwnerShip.BlockOwnerShip;
|
import com.gamingmesh.jobs.container.blockOwnerShip.BlockOwnerShip;
|
||||||
import com.gamingmesh.jobs.container.blockOwnerShip.BlockTypes;
|
import com.gamingmesh.jobs.container.blockOwnerShip.BlockTypes;
|
||||||
import com.gamingmesh.jobs.dao.JobsClassLoader;
|
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.economy.PaymentData;
|
||||||
import com.gamingmesh.jobs.hooks.HookManager;
|
import com.gamingmesh.jobs.hooks.HookManager;
|
||||||
import com.gamingmesh.jobs.i18n.Language;
|
import com.gamingmesh.jobs.i18n.Language;
|
||||||
import com.gamingmesh.jobs.listeners.JobsListener;
|
import com.gamingmesh.jobs.listeners.*;
|
||||||
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.selection.SelectionManager;
|
import com.gamingmesh.jobs.selection.SelectionManager;
|
||||||
import com.gamingmesh.jobs.stuff.Loging;
|
import com.gamingmesh.jobs.stuff.*;
|
||||||
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.complement.Complement;
|
import com.gamingmesh.jobs.stuff.complement.Complement;
|
||||||
import com.gamingmesh.jobs.stuff.complement.Complement1;
|
import com.gamingmesh.jobs.stuff.complement.Complement1;
|
||||||
import com.gamingmesh.jobs.stuff.complement.Complement2;
|
import com.gamingmesh.jobs.stuff.complement.Complement2;
|
||||||
import com.gamingmesh.jobs.stuff.complement.JobsChatEvent;
|
import com.gamingmesh.jobs.stuff.complement.JobsChatEvent;
|
||||||
import com.gamingmesh.jobs.tasks.BufferedPaymentThread;
|
import com.gamingmesh.jobs.tasks.BufferedPaymentThread;
|
||||||
import com.gamingmesh.jobs.tasks.DatabaseSaveThread;
|
import com.gamingmesh.jobs.tasks.DatabaseSaveThread;
|
||||||
|
|
||||||
import net.Zrips.CMILib.ActionBar.CMIActionBar;
|
import net.Zrips.CMILib.ActionBar.CMIActionBar;
|
||||||
import net.Zrips.CMILib.Items.CMIMaterial;
|
import net.Zrips.CMILib.Items.CMIMaterial;
|
||||||
import net.Zrips.CMILib.Locale.LC;
|
import net.Zrips.CMILib.Locale.LC;
|
||||||
import net.Zrips.CMILib.Messages.CMIMessages;
|
import net.Zrips.CMILib.Messages.CMIMessages;
|
||||||
import net.Zrips.CMILib.RawMessages.RawMessage;
|
import net.Zrips.CMILib.RawMessages.RawMessage;
|
||||||
import net.Zrips.CMILib.Version.Version;
|
|
||||||
import net.Zrips.CMILib.Version.Schedulers.CMIScheduler;
|
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 {
|
public final class Jobs extends JavaPlugin {
|
||||||
|
|
||||||
@ -142,6 +91,8 @@ public final class Jobs extends JavaPlugin {
|
|||||||
private static GeneralConfigManager gConfigManager;
|
private static GeneralConfigManager gConfigManager;
|
||||||
|
|
||||||
private static BufferedEconomy economy;
|
private static BufferedEconomy economy;
|
||||||
|
|
||||||
|
private static Permission vaultPermission;
|
||||||
private static PermissionHandler permissionHandler;
|
private static PermissionHandler permissionHandler;
|
||||||
private static PermissionManager permissionManager;
|
private static PermissionManager permissionManager;
|
||||||
|
|
||||||
@ -691,6 +642,10 @@ public final class Jobs extends JavaPlugin {
|
|||||||
economy = new BufferedEconomy(getInstance(), eco);
|
economy = new BufferedEconomy(getInstance(), eco);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setVaultPermission(Permission permission) {
|
||||||
|
vaultPermission = permission;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the economy handler
|
* Gets the economy handler
|
||||||
* @return the economy handler
|
* @return the economy handler
|
||||||
@ -699,6 +654,10 @@ public final class Jobs extends JavaPlugin {
|
|||||||
return economy;
|
return economy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Permission getVaultPermission() {
|
||||||
|
return vaultPermission;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the version check manager
|
* Gets the version check manager
|
||||||
* @return the version check manager
|
* @return the version check manager
|
||||||
@ -761,8 +720,14 @@ public final class Jobs extends JavaPlugin {
|
|||||||
complement = new Complement1();
|
complement = new Complement1();
|
||||||
}
|
}
|
||||||
|
|
||||||
// register economy
|
if (HookVault.isVaultEnable()) {
|
||||||
CMIScheduler.get().runTask(new HookEconomyTask(this));
|
// register economy
|
||||||
|
CMIScheduler.get().runTask(() -> new HookEconomyTask(net.milkbowl.vault.economy.Economy.class));
|
||||||
|
|
||||||
|
// register permission from vault
|
||||||
|
CMIScheduler.get().runTask(() -> new HookPermissionTask(Permission.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
dao.loadBlockProtection();
|
dao.loadBlockProtection();
|
||||||
getExploreManager().load();
|
getExploreManager().load();
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
package com.gamingmesh.jobs.commands.list;
|
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.Jobs;
|
||||||
import com.gamingmesh.jobs.commands.Cmd;
|
import com.gamingmesh.jobs.commands.Cmd;
|
||||||
import com.gamingmesh.jobs.container.TopList;
|
import com.gamingmesh.jobs.container.TopList;
|
||||||
import com.gamingmesh.jobs.i18n.Language;
|
import com.gamingmesh.jobs.i18n.Language;
|
||||||
|
|
||||||
import net.Zrips.CMILib.Container.PageInfo;
|
import net.Zrips.CMILib.Container.PageInfo;
|
||||||
import net.Zrips.CMILib.Locale.LC;
|
import net.Zrips.CMILib.Locale.LC;
|
||||||
import net.Zrips.CMILib.Messages.CMIMessages;
|
import net.Zrips.CMILib.Messages.CMIMessages;
|
||||||
import net.Zrips.CMILib.Scoreboards.CMIScoreboard;
|
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 {
|
public class gtop implements Cmd {
|
||||||
|
|
||||||
@ -52,10 +52,17 @@ public class gtop implements Cmd {
|
|||||||
int amount = Jobs.getGCManager().JobsTopAmount;
|
int amount = Jobs.getGCManager().JobsTopAmount;
|
||||||
PageInfo pi = new PageInfo(amount, Jobs.getPlayerManager().getPlayersCache().size(), page);
|
PageInfo pi = new PageInfo(amount, Jobs.getPlayerManager().getPlayersCache().size(), page);
|
||||||
|
|
||||||
List<TopList> 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<TopList> FullList = Jobs.getJobsDAO().getGlobalTopList(pi.getStart())
|
||||||
|
.stream().filter(gtop::hasToBeSeenInGlobalTop).collect(Collectors.toList());
|
||||||
if (FullList.isEmpty()) {
|
if (FullList.isEmpty()) {
|
||||||
Language.sendMessage(sender, "command.gtop.error.nojob");
|
Language.sendMessage(sender, "command.gtop.error.nojob");
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Jobs.getGCManager().ShowToplistInScoreboard) {
|
if (!Jobs.getGCManager().ShowToplistInScoreboard) {
|
||||||
@ -67,11 +74,11 @@ public class gtop implements Cmd {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
Language.sendMessage(sender, "command.gtop.output.list",
|
Language.sendMessage(sender, "command.gtop.output.list",
|
||||||
"%number%", pi.getPositionForOutput(i),
|
"%number%", pi.getPositionForOutput(i),
|
||||||
"%playername%", One.getPlayerInfo().getName(),
|
"%playername%", One.getPlayerInfo().getName(),
|
||||||
"%playerdisplayname%", One.getPlayerInfo().getDisplayName(),
|
"%playerdisplayname%", One.getPlayerInfo().getDisplayName(),
|
||||||
"%level%", One.getLevel(),
|
"%level%", One.getLevel(),
|
||||||
"%exp%", One.getExp());
|
"%exp%", One.getExp());
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -82,10 +89,10 @@ public class gtop implements Cmd {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
ls.add(Jobs.getLanguage().getMessage("scoreboard.line",
|
ls.add(Jobs.getLanguage().getMessage("scoreboard.line",
|
||||||
"%number%", pi.getPositionForOutput(i),
|
"%number%", pi.getPositionForOutput(i),
|
||||||
"%playername%", one.getPlayerInfo().getName(),
|
"%playername%", one.getPlayerInfo().getName(),
|
||||||
"%playerdisplayname%", one.getPlayerInfo().getDisplayName(),
|
"%playerdisplayname%", one.getPlayerInfo().getDisplayName(),
|
||||||
"%level%", one.getLevel()));
|
"%level%", one.getLevel()));
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,6 +100,16 @@ public class gtop implements Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pi.autoPagination(sender, "jobs gtop");
|
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"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,23 @@
|
|||||||
package com.gamingmesh.jobs.commands.list;
|
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.Jobs;
|
||||||
import com.gamingmesh.jobs.commands.Cmd;
|
import com.gamingmesh.jobs.commands.Cmd;
|
||||||
import com.gamingmesh.jobs.container.Job;
|
import com.gamingmesh.jobs.container.Job;
|
||||||
import com.gamingmesh.jobs.container.TopList;
|
import com.gamingmesh.jobs.container.TopList;
|
||||||
import com.gamingmesh.jobs.i18n.Language;
|
import com.gamingmesh.jobs.i18n.Language;
|
||||||
|
|
||||||
import net.Zrips.CMILib.Container.PageInfo;
|
import net.Zrips.CMILib.Container.PageInfo;
|
||||||
import net.Zrips.CMILib.Locale.LC;
|
import net.Zrips.CMILib.Locale.LC;
|
||||||
import net.Zrips.CMILib.Messages.CMIMessages;
|
import net.Zrips.CMILib.Messages.CMIMessages;
|
||||||
import net.Zrips.CMILib.Scoreboards.CMIScoreboard;
|
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 {
|
public class top implements Cmd {
|
||||||
|
|
||||||
@ -56,11 +57,19 @@ public class top implements Cmd {
|
|||||||
|
|
||||||
int workingIn = Jobs.getUsedSlots(job);
|
int workingIn = Jobs.getUsedSlots(job);
|
||||||
PageInfo pi = new PageInfo(Jobs.getGCManager().JobsTopAmount, workingIn, page);
|
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<TopList> fullList = Jobs.getJobsDAO().toplist(job.getName(), pi.getStart())
|
||||||
|
.stream().filter(topList -> hasToBeSeenInTop(topList, job)).collect(Collectors.toList());
|
||||||
|
|
||||||
List<TopList> fullList = Jobs.getJobsDAO().toplist(job.getName(), pi.getStart());
|
|
||||||
if (fullList.isEmpty()) {
|
if (fullList.isEmpty()) {
|
||||||
CMIMessages.sendMessage(sender, LC.info_NoInformation);
|
CMIMessages.sendMessage(sender, LC.info_NoInformation);
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int place = 1;
|
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);
|
Language.sendMessage(sender, "command.top.output.topline", "%jobname%", job.getName(), "%amount%", Jobs.getGCManager().JobsTopAmount);
|
||||||
|
|
||||||
for (TopList one : fullList) {
|
for (TopList one : fullList) {
|
||||||
|
System.out.println(one.getPlayerInfo().getName());
|
||||||
if (place > Jobs.getGCManager().JobsTopAmount)
|
if (place > Jobs.getGCManager().JobsTopAmount)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
Language.sendMessage(sender, "command.top.output.list",
|
Language.sendMessage(sender, "command.top.output.list",
|
||||||
"%number%", ((page - 1) * Jobs.getGCManager().JobsTopAmount) + place,
|
"%number%", ((page - 1) * Jobs.getGCManager().JobsTopAmount) + place,
|
||||||
"%playername%", one.getPlayerInfo().getName(),
|
"%playername%", one.getPlayerInfo().getName(),
|
||||||
"%playerdisplayname%", one.getPlayerInfo().getDisplayName(),
|
"%playerdisplayname%", one.getPlayerInfo().getDisplayName(),
|
||||||
"%level%", one.getLevel(),
|
"%level%", one.getLevel(),
|
||||||
"%exp%", one.getExp());
|
"%exp%", one.getExp());
|
||||||
place++;
|
place++;
|
||||||
}
|
}
|
||||||
pi.autoPagination(sender, "jobs top " + job.getName());
|
pi.autoPagination(sender, "jobs top " + job.getName());
|
||||||
@ -88,7 +98,7 @@ public class top implements Cmd {
|
|||||||
if (place > Jobs.getGCManager().JobsTopAmount)
|
if (place > Jobs.getGCManager().JobsTopAmount)
|
||||||
break;
|
break;
|
||||||
ls.add(Jobs.getLanguage().getMessage("scoreboard.line", "%number%", ((page - 1) * Jobs.getGCManager().JobsTopAmount) + place,
|
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++;
|
place++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,6 +106,16 @@ public class top implements Cmd {
|
|||||||
|
|
||||||
pi.autoPagination(sender, "jobs top " + job.getName());
|
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()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -232,3 +232,9 @@ permissions:
|
|||||||
jobs.area.remove:
|
jobs.area.remove:
|
||||||
description: Grants access to the area remove command
|
description: Grants access to the area remove command
|
||||||
default: op
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user