From e4ca78fa5701301b1272b64cf616cda7a7d7d33d Mon Sep 17 00:00:00 2001 From: Zrips Date: Tue, 15 Nov 2022 13:16:17 +0200 Subject: [PATCH] Default behavior for default jobs command --- src/main/java/com/gamingmesh/jobs/Jobs.java | 1638 +++++++++-------- .../jobs/commands/JobsCommands.java | 547 +++--- .../jobs/config/GeneralConfigManager.java | 24 + 3 files changed, 1128 insertions(+), 1081 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index 52389006..bfcc9c01 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -170,26 +170,26 @@ public final class Jobs extends JavaPlugin { private static final int MAX_ENTRIES = 5; public static final LinkedHashMap FASTPAYMENT = new LinkedHashMap(MAX_ENTRIES + 1, .75F, false) { - protected boolean removeEldestEntry(Map.Entry eldest) { - return size() > MAX_ENTRIES; - } + protected boolean removeEldestEntry(Map.Entry eldest) { + return size() > MAX_ENTRIES; + } }; protected static VersionChecker versionCheckManager; protected static SelectionManager smanager; public Complement getComplement() { - return complement; + return complement; } public boolean isKyoriSupported() { - return kyoriSupported; + return kyoriSupported; } public static JobsClassLoader getJobsClassloader() { - if (classLoader == null) - classLoader = new JobsClassLoader(Jobs.getInstance()); - return classLoader; + if (classLoader == null) + classLoader = new JobsClassLoader(Jobs.getInstance()); + return classLoader; } /** @@ -200,7 +200,7 @@ public final class Jobs extends JavaPlugin { * @return {@link BlockOwnerShip}, otherwise {@link Optional#empty()} */ public Optional getBlockOwnerShip(CMIMaterial type) { - return getBlockOwnerShip(type, true); + return getBlockOwnerShip(type, true); } /** @@ -213,15 +213,15 @@ public final class Jobs extends JavaPlugin { * @return {@link BlockOwnerShip}, otherwise {@link Optional#empty()} */ public Optional getBlockOwnerShip(CMIMaterial type, boolean addNew) { - BlockOwnerShip b = blockOwnerShipsMaterial.get(type); + BlockOwnerShip b = blockOwnerShipsMaterial.get(type); - if (addNew && b == null) { - b = new BlockOwnerShip(type); - blockOwnerShipsMaterial.put(type, b); - blockOwnerShipsBlockType.put(b.getType(), b); - } + if (addNew && b == null) { + b = new BlockOwnerShip(type); + blockOwnerShipsMaterial.put(type, b); + blockOwnerShipsBlockType.put(b.getType(), b); + } - return Optional.ofNullable(b); + return Optional.ofNullable(b); } /** @@ -231,127 +231,131 @@ public final class Jobs extends JavaPlugin { * @return {@link BlockOwnerShip}, otherwise {@link Optional#empty()} */ public Optional getBlockOwnerShip(BlockTypes type) { - BlockOwnerShip b = blockOwnerShipsBlockType.get(type); - if (b != null) - return Optional.ofNullable(b); + BlockOwnerShip b = blockOwnerShipsBlockType.get(type); + if (b != null) + return Optional.ofNullable(b); - return Optional.empty(); + return Optional.empty(); } public void removeBlockOwnerShip(org.bukkit.block.Block block) { - BlockOwnerShip ship = blockOwnerShipsMaterial.get(CMIMaterial.get(block)); - if (ship != null) - ship.remove(block); + BlockOwnerShip ship = blockOwnerShipsMaterial.get(CMIMaterial.get(block)); + if (ship != null) + ship.remove(block); } /** * @return a set of block owner ships. */ public HashMap getBlockOwnerShips() { - return blockOwnerShipsMaterial; + return blockOwnerShipsMaterial; } private Placeholder placeholder; private boolean placeholderAPIEnabled = false; public Placeholder getPlaceholderAPIManager() { - if (placeholder == null) - placeholder = new Placeholder(this); - return placeholder; + if (placeholder == null) + placeholder = new Placeholder(this); + return placeholder; } private boolean setupPlaceHolderAPI() { - org.bukkit.plugin.Plugin papi = getServer().getPluginManager().getPlugin("PlaceholderAPI"); - if (papi == null || !papi.isEnabled()) - return false; + org.bukkit.plugin.Plugin papi = getServer().getPluginManager().getPlugin("PlaceholderAPI"); + if (papi == null || !papi.isEnabled()) + return false; - try { - if (Integer.parseInt(papi - .getDescription().getVersion().replaceAll("[^\\d]", "")) >= 2100 && new PlaceholderAPIHook(this).register()) { - consoleMsg("&6PlaceholderAPI &ehooked."); - } - } catch (NumberFormatException ex) { - return false; - } + try { + if (Integer.parseInt(papi + .getDescription().getVersion().replaceAll("[^\\d]", "")) >= 2100 && new PlaceholderAPIHook(this).register()) { + consoleMsg("&6PlaceholderAPI &ehooked."); + } + } catch (NumberFormatException ex) { + return false; + } - return true; + return true; } public static Loging getLoging() { - if (loging == null) - loging = new Loging(); - return loging; + if (loging == null) + loging = new Loging(); + return loging; } public static BlockProtectionManager getBpManager() { - if (bpManager == null) - bpManager = new BlockProtectionManager(); - return bpManager; + if (bpManager == null) + bpManager = new BlockProtectionManager(); + return bpManager; } public static JobsManager getDBManager() { - if (dbManager == null) - dbManager = new JobsManager(getInstance()); - return dbManager; + if (dbManager == null) + dbManager = new JobsManager(getInstance()); + return dbManager; } public static ShopManager getShopManager() { - if (shopManager == null) { - shopManager = new ShopManager(); - } - return shopManager; + if (shopManager == null) { + shopManager = new ShopManager(); + } + return shopManager; } public static ConfigManager getConfigManager() { - if (configManager == null) - configManager = new ConfigManager(); - return configManager; + if (configManager == null) + configManager = new ConfigManager(); + return configManager; } public static GeneralConfigManager getGCManager() { - if (gConfigManager == null) - gConfigManager = new GeneralConfigManager(); - return gConfigManager; + return getGeneralConfigManager(); + } + + public static GeneralConfigManager getGeneralConfigManager() { + if (gConfigManager == null) + gConfigManager = new GeneralConfigManager(); + return gConfigManager; } /** * @return {@link PlayerManager} */ public static PlayerManager getPlayerManager() { - if (pManager == null) - pManager = new PlayerManager(getInstance()); - return pManager; + if (pManager == null) + pManager = new PlayerManager(getInstance()); + return pManager; } public static RestrictedBlockManager getRestrictedBlockManager() { - if (rbManager == null) { - rbManager = new RestrictedBlockManager(); - } + if (rbManager == null) { + rbManager = new RestrictedBlockManager(); + } - return rbManager; + return rbManager; } public static RestrictedAreaManager getRestrictedAreaManager() { - if (raManager == null) { - raManager = new RestrictedAreaManager(); - } + if (raManager == null) { + raManager = new RestrictedAreaManager(); + } - return raManager; + return raManager; } /** * @return {@link TitleManager} */ public static TitleManager getTitleManager() { - if (titleManager == null) { - titleManager = new TitleManager(); - } + if (titleManager == null) { + titleManager = new TitleManager(); + } - return titleManager; + return titleManager; } public static BossBarManager getBBManager() { - return bbManager; + return bbManager; } /** @@ -359,50 +363,50 @@ public final class Jobs extends JavaPlugin { * @return the schedule manager */ public static ScheduleManager getScheduleManager() { - if (scheduleManager == null) { - scheduleManager = new ScheduleManager(getInstance()); - } + if (scheduleManager == null) { + scheduleManager = new ScheduleManager(getInstance()); + } - return scheduleManager; + return scheduleManager; } public static NameTranslatorManager getNameTranslatorManager() { - if (nameTranslatorManager == null) { - nameTranslatorManager = new NameTranslatorManager(); - } + if (nameTranslatorManager == null) { + nameTranslatorManager = new NameTranslatorManager(); + } - return nameTranslatorManager; + return nameTranslatorManager; } public GuiManager getGUIManager() { - if (guiManager == null) - guiManager = new GuiManager(this); - return guiManager; + if (guiManager == null) + guiManager = new GuiManager(this); + return guiManager; } public static JobsCommands getCommandManager() { - if (cManager == null) { - cManager = new JobsCommands(getInstance()); - } - return cManager; + if (cManager == null) { + cManager = new JobsCommands(getInstance()); + } + return cManager; } @Deprecated public static ExploreManager getExplore() { - return getExploreManager(); + return getExploreManager(); } public static ExploreManager getExploreManager() { - if (exploreManager == null) - exploreManager = new ExploreManager(); - return exploreManager; + if (exploreManager == null) + exploreManager = new ExploreManager(); + return exploreManager; } /** * @return returns this class object instance */ public static Jobs getInstance() { - return JavaPlugin.getPlugin(Jobs.class); + return JavaPlugin.getPlugin(Jobs.class); } /** @@ -410,11 +414,11 @@ public final class Jobs extends JavaPlugin { * @return the sign manager */ public static SignUtil getSignUtil() { - if (signManager == null) { - signManager = new SignUtil(getInstance()); - } + if (signManager == null) { + signManager = new SignUtil(getInstance()); + } - return signManager; + return signManager; } /** @@ -422,17 +426,17 @@ public final class Jobs extends JavaPlugin { * @return the language manager */ public static Language getLanguage() { - if (lManager == null) - lManager = new Language(); - return lManager; + if (lManager == null) + lManager = new Language(); + return lManager; } public static LanguageManager getLanguageManager() { - if (lmManager == null) { - lmManager = new LanguageManager(); - } + if (lmManager == null) { + lmManager = new LanguageManager(); + } - return lmManager; + return lmManager; } /** @@ -440,13 +444,13 @@ public final class Jobs extends JavaPlugin { * @return the plugin logger */ public static Logger getPluginLogger() { - return getInstance().getLogger(); + return getInstance().getLogger(); } public static File getFolder() { - File folder = getInstance().getDataFolder(); - folder.mkdirs(); - return folder; + File folder = getInstance().getDataFolder(); + folder.mkdirs(); + return folder; } /** @@ -454,7 +458,7 @@ public final class Jobs extends JavaPlugin { * @param dao - the DAO */ public static void setDAO(JobsDAO dao) { - Jobs.dao = dao; + Jobs.dao = dao; } /** @@ -462,7 +466,7 @@ public final class Jobs extends JavaPlugin { * @return the DAO */ public static JobsDAO getJobsDAO() { - return dao; + return dao; } /** @@ -470,7 +474,7 @@ public final class Jobs extends JavaPlugin { * @param jobs - list of jobs */ public static void setJobs(List jobs) { - Jobs.jobs = jobs; + Jobs.jobs = jobs; } /** @@ -479,7 +483,7 @@ public final class Jobs extends JavaPlugin { * @return an unmodifiable list of jobs */ public static List getJobs() { - return Collections.unmodifiableList(jobs); + return Collections.unmodifiableList(jobs); } /** @@ -487,7 +491,7 @@ public final class Jobs extends JavaPlugin { * @param noneJob - the none job */ public static void setNoneJob(Job noneJob) { - Jobs.noneJob = noneJob; + Jobs.noneJob = noneJob; } /** @@ -495,7 +499,7 @@ public final class Jobs extends JavaPlugin { * @return the none job */ public static Job getNoneJob() { - return noneJob; + return noneJob; } /** @@ -504,12 +508,12 @@ public final class Jobs extends JavaPlugin { * @return the job that matches the name */ public static Job getJob(String jobName) { - for (Job job : jobs) { - if (job.getName().equalsIgnoreCase(jobName) || job.getJobFullName().equalsIgnoreCase(jobName)) - return job; - } + for (Job job : jobs) { + if (job.getName().equalsIgnoreCase(jobName) || job.getJobFullName().equalsIgnoreCase(jobName)) + return job; + } - return null; + return null; } /** @@ -519,86 +523,86 @@ public final class Jobs extends JavaPlugin { * @return {@link Job} */ public static Job getJob(int id) { - for (Job job : jobs) { - if (job.getId() == id || job.getLegacyId() == id) { - return job; - } - } + for (Job job : jobs) { + if (job.getId() == id || job.getLegacyId() == id) { + return job; + } + } - return null; + return null; } public boolean isPlaceholderAPIEnabled() { - return placeholderAPIEnabled; + return placeholderAPIEnabled; } private static void startup() { - reload(true); + reload(true); - // This goes in sync to avoid issues while loading data - loadAllPlayersData(); - for (Player online : Bukkit.getServer().getOnlinePlayers()) - getPlayerManager().playerJoin(online); + // This goes in sync to avoid issues while loading data + loadAllPlayersData(); + for (Player online : Bukkit.getServer().getOnlinePlayers()) + getPlayerManager().playerJoin(online); } public static void loadAllPlayersData() { - long time = System.currentTimeMillis(); - HashMap temp = new HashMap<>(getPlayerManager().getPlayersInfoUUIDMap()); - Map> playersJobs = dao.getAllJobs(); - Map playersPoints = dao.getAllPoints(); - Map> playersLogs = dao.getAllLogs(); - Map playersArchives = dao.getAllArchivedJobs(); - Map playersLimits = dao.loadPlayerLimits(); - for (Iterator it = temp.values().iterator(); it.hasNext();) { - PlayerInfo one = it.next(); - int id = one.getID(); - JobsPlayer jPlayer = getPlayerManager().getJobsPlayerOffline( - one, - playersJobs.get(id), - playersPoints.get(id), - playersLogs.get(id), - playersArchives.get(id), - playersLimits.get(id)); - if (jPlayer != null) - getPlayerManager().addPlayerToCache(jPlayer); - } - if (!getPlayerManager().getPlayersCache().isEmpty()) - consoleMsg("&ePreloaded &6" + getPlayerManager().getPlayersCache().size() + " &eplayers data in &6" + ((int) ((System.currentTimeMillis() - time) / 1000.0D * 100.0D) / 100.0D)); + long time = System.currentTimeMillis(); + HashMap temp = new HashMap<>(getPlayerManager().getPlayersInfoUUIDMap()); + Map> playersJobs = dao.getAllJobs(); + Map playersPoints = dao.getAllPoints(); + Map> playersLogs = dao.getAllLogs(); + Map playersArchives = dao.getAllArchivedJobs(); + Map playersLimits = dao.loadPlayerLimits(); + for (Iterator it = temp.values().iterator(); it.hasNext();) { + PlayerInfo one = it.next(); + int id = one.getID(); + JobsPlayer jPlayer = getPlayerManager().getJobsPlayerOffline( + one, + playersJobs.get(id), + playersPoints.get(id), + playersLogs.get(id), + playersArchives.get(id), + playersLimits.get(id)); + if (jPlayer != null) + getPlayerManager().addPlayerToCache(jPlayer); + } + if (!getPlayerManager().getPlayersCache().isEmpty()) + consoleMsg("&ePreloaded &6" + getPlayerManager().getPlayersCache().size() + " &eplayers data in &6" + ((int) ((System.currentTimeMillis() - time) / 1000.0D * 100.0D) / 100.0D)); } public static void convertDatabase() { - try { - List archivelist = dao.convertDatabase(); + try { + List archivelist = dao.convertDatabase(); - getDBManager().switchDataBase(); - getPlayerManager().reload(); + getDBManager().switchDataBase(); + getPlayerManager().reload(); - dao.truncateAllTables(); + dao.truncateAllTables(); - for (Job one : Jobs.getJobs()) { - dao.recordNewJobName(one, one.getId()); - } - for (JobsWorld one : Util.getJobsWorlds().values()) { - dao.recordNewWorld(one.getName(), one.getId()); - } + for (Job one : Jobs.getJobs()) { + dao.recordNewJobName(one, one.getId()); + } + for (JobsWorld one : Util.getJobsWorlds().values()) { + dao.recordNewWorld(one.getName(), one.getId()); + } - getPlayerManager().convertChacheOfPlayers(true); + getPlayerManager().convertChacheOfPlayers(true); - dao.continueConvertions(archivelist); - getPlayerManager().clearMaps(); - getPlayerManager().clearCache(); + dao.continueConvertions(archivelist); + getPlayerManager().clearMaps(); + getPlayerManager().clearCache(); - dao.saveExplore(); + dao.saveExplore(); // Do we really need to convert Block protection? // Jobs.getJobsDAO().saveBlockProtection(); - } catch (SQLException e) { - e.printStackTrace(); - Jobs.consoleMsg("&cCan't write data to data base, please send error log to dev's."); - return; - } + } catch (SQLException e) { + e.printStackTrace(); + Jobs.consoleMsg("&cCan't write data to data base, please send error log to dev's."); + return; + } - reload(); - loadAllPlayersData(); + reload(); + loadAllPlayersData(); } /** @@ -609,34 +613,34 @@ public final class Jobs extends JavaPlugin { * @return true if the player have the given action */ public static boolean isPlayerHaveAction(JobsPlayer jPlayer, ActionType type) { - if (jPlayer == null || type == null) - return false; + if (jPlayer == null || type == null) + return false; - boolean found = false; + boolean found = false; - for (JobProgression prog : jPlayer.getJobProgression()) { - for (JobInfo info : prog.getJob().getJobInfo(type)) { - if (info.getActionType() == type) { - found = true; - break; - } - } + for (JobProgression prog : jPlayer.getJobProgression()) { + for (JobInfo info : prog.getJob().getJobInfo(type)) { + if (info.getActionType() == type) { + found = true; + break; + } + } - if (!found) { - for (Quest q : prog.getJob().getQuests()) { - if (q != null && q.hasAction(type)) { - found = true; - break; - } - } - } + if (!found) { + for (Quest q : prog.getJob().getQuests()) { + if (q != null && q.hasAction(type)) { + found = true; + break; + } + } + } - if (found) { - break; - } - } + if (found) { + break; + } + } - return found; + return found; } /** @@ -645,7 +649,7 @@ public final class Jobs extends JavaPlugin { * @return the number of slots */ public static int getUsedSlots(Job job) { - return usedSlots.getOrDefault(job, 0); + return usedSlots.getOrDefault(job, 0); } /** @@ -653,9 +657,9 @@ public final class Jobs extends JavaPlugin { * @param job - the job someone is taking */ public static void takeSlot(Job job) { - Integer used = usedSlots.get(job); - if (used != null) - usedSlots.put(job, used + 1); + Integer used = usedSlots.get(job); + if (used != null) + usedSlots.put(job, used + 1); } /** @@ -663,9 +667,9 @@ public final class Jobs extends JavaPlugin { * @param job - the job someone is leaving */ public static void leaveSlot(Job job) { - Integer used = usedSlots.get(job); - if (used != null) - usedSlots.put(job, used - 1); + Integer used = usedSlots.get(job); + if (used != null) + usedSlots.put(job, used - 1); } /** @@ -673,15 +677,15 @@ public final class Jobs extends JavaPlugin { * @return the permission handler */ public static PermissionHandler getPermissionHandler() { - if (permissionHandler == null) - permissionHandler = new PermissionHandler(getInstance()); - return permissionHandler; + if (permissionHandler == null) + permissionHandler = new PermissionHandler(getInstance()); + return permissionHandler; } public static PermissionManager getPermissionManager() { - if (permissionManager == null) - permissionManager = new PermissionManager(); - return permissionManager; + if (permissionManager == null) + permissionManager = new PermissionManager(); + return permissionManager; } /** @@ -689,7 +693,7 @@ public final class Jobs extends JavaPlugin { * @param eco - the economy handler */ public static void setEconomy(Economy eco) { - economy = new BufferedEconomy(getInstance(), eco); + economy = new BufferedEconomy(getInstance(), eco); } /** @@ -697,7 +701,7 @@ public final class Jobs extends JavaPlugin { * @return the economy handler */ public static BufferedEconomy getEconomy() { - return economy; + return economy; } /** @@ -705,10 +709,10 @@ public final class Jobs extends JavaPlugin { * @return the version check manager */ public static VersionChecker getVersionCheckManager() { - if (versionCheckManager == null) - versionCheckManager = new VersionChecker(getInstance()); + if (versionCheckManager == null) + versionCheckManager = new VersionChecker(getInstance()); - return versionCheckManager; + return versionCheckManager; } private final static String prefix = "&6------------- &2Jobs &6-------------"; @@ -716,207 +720,207 @@ public final class Jobs extends JavaPlugin { @Override public void onEnable() { - CMIMessages.consoleMessage(prefix); + CMIMessages.consoleMessage(prefix); - try { - Class.forName("net.kyori.adventure.text.Component"); - org.bukkit.inventory.meta.ItemMeta.class.getDeclaredMethod("displayName"); - kyoriSupported = true; - } catch (NoSuchMethodException | ClassNotFoundException e) { - } + try { + Class.forName("net.kyori.adventure.text.Component"); + org.bukkit.inventory.meta.ItemMeta.class.getDeclaredMethod("displayName"); + kyoriSupported = true; + } catch (NoSuchMethodException | ClassNotFoundException e) { + } - placeholderAPIEnabled = setupPlaceHolderAPI(); + placeholderAPIEnabled = setupPlaceHolderAPI(); - try { - new YmlMaker(getFolder(), "shopItems.yml").saveDefaultConfig(); - new YmlMaker(getFolder(), "restrictedBlocks.yml").saveDefaultConfig(); + try { + new YmlMaker(getFolder(), "shopItems.yml").saveDefaultConfig(); + new YmlMaker(getFolder(), "restrictedBlocks.yml").saveDefaultConfig(); - bbManager = new BossBarManager(this); + bbManager = new BossBarManager(this); - Optional.ofNullable(getCommand("jobs")).ifPresent(j -> { - j.setExecutor(getCommandManager()); - j.setTabCompleter(new TabComplete()); - }); + Optional.ofNullable(getCommand("jobs")).ifPresent(j -> { + j.setExecutor(getCommandManager()); + j.setTabCompleter(new TabComplete()); + }); - startup(); + startup(); - if (status.equals(LoadStatus.MYSQLFailure) || status.equals(LoadStatus.SQLITEFailure)) { - CMIMessages.consoleMessage("&cCould not connect to " + (status.equals(LoadStatus.MYSQLFailure) ? "MySQL" : "SqLite") + "!"); - CMIMessages.consoleMessage("&cPlugin will be disabled"); - this.onDisable(); - this.setEnabled(false); - return; - } + if (status.equals(LoadStatus.MYSQLFailure) || status.equals(LoadStatus.SQLITEFailure)) { + CMIMessages.consoleMessage("&cCould not connect to " + (status.equals(LoadStatus.MYSQLFailure) ? "MySQL" : "SqLite") + "!"); + CMIMessages.consoleMessage("&cPlugin will be disabled"); + this.onDisable(); + this.setEnabled(false); + return; + } - if (getGCManager().SignsEnabled) { - new YmlMaker(getFolder(), "Signs.yml").saveDefaultConfig(); - } + if (getGCManager().SignsEnabled) { + new YmlMaker(getFolder(), "Signs.yml").saveDefaultConfig(); + } - HookManager.loadHooks(); - registerListeners(); + HookManager.loadHooks(); + registerListeners(); - if (Version.isCurrentEqualOrHigher(Version.v1_16_R3) && kyoriSupported) { - complement = new Complement2(); - //getServer().getPluginManager().registerEvents(new KyoriChatEvent(this), this); - } else { - complement = new Complement1(); - } + if (Version.isCurrentEqualOrHigher(Version.v1_16_R3) && kyoriSupported) { + complement = new Complement2(); + //getServer().getPluginManager().registerEvents(new KyoriChatEvent(this), this); + } else { + complement = new Complement1(); + } - // register economy - getServer().getScheduler().runTask(this, new HookEconomyTask(this)); + // register economy + getServer().getScheduler().runTask(this, new HookEconomyTask(this)); - dao.loadBlockProtection(); - getExploreManager().load(); - getCommandManager().fillCommands(); - getDBManager().getDB().triggerTableIdUpdate(); + dao.loadBlockProtection(); + getExploreManager().load(); + getCommandManager().fillCommands(); + getDBManager().getDB().triggerTableIdUpdate(); - consoleMsg("&ePlugin has been enabled successfully."); - } catch (Throwable e) { - e.printStackTrace(); - System.out.println("There was some issues when starting plugin. Please contact dev about this. Plugin will be disabled."); - setEnabled(false); - } + consoleMsg("&ePlugin has been enabled successfully."); + } catch (Throwable e) { + e.printStackTrace(); + System.out.println("There was some issues when starting plugin. Please contact dev about this. Plugin will be disabled."); + setEnabled(false); + } - CMIMessages.consoleMessage(suffix); + CMIMessages.consoleMessage(suffix); } private static void registerListeners() { - org.bukkit.plugin.PluginManager pm = getInstance().getServer().getPluginManager(); + org.bukkit.plugin.PluginManager pm = getInstance().getServer().getPluginManager(); - if (Version.isCurrentEqualOrHigher(Version.v1_9_R1)) { - pm.registerEvents(new com.gamingmesh.jobs.listeners.Listener1_9(), getInstance()); - } + if (Version.isCurrentEqualOrHigher(Version.v1_9_R1)) { + pm.registerEvents(new com.gamingmesh.jobs.listeners.Listener1_9(), getInstance()); + } - pm.registerEvents(new JobsListener(getInstance()), getInstance()); - pm.registerEvents(new JobsPaymentListener(getInstance()), getInstance()); - if (Version.isCurrentEqualOrHigher(Version.v1_14_R1)) { - pm.registerEvents(new JobsPayment14Listener(), getInstance()); - } + pm.registerEvents(new JobsListener(getInstance()), getInstance()); + pm.registerEvents(new JobsPaymentListener(getInstance()), getInstance()); + if (Version.isCurrentEqualOrHigher(Version.v1_14_R1)) { + pm.registerEvents(new JobsPayment14Listener(), getInstance()); + } - if (getGCManager().useBlockProtection) { - pm.registerEvents(new PistonProtectionListener(), getInstance()); - } + if (getGCManager().useBlockProtection) { + pm.registerEvents(new PistonProtectionListener(), getInstance()); + } - pm.registerEvents(new JobsChatEvent(getInstance()), getInstance()); + pm.registerEvents(new JobsChatEvent(getInstance()), getInstance()); - if (HookManager.getMcMMOManager().CheckmcMMO()) { - HookManager.setMcMMOlistener(); - } - if (HookManager.checkMythicMobs()) { - HookManager.getMythicManager().registerListener(); - } + if (HookManager.getMcMMOManager().CheckmcMMO()) { + HookManager.setMcMMOlistener(); + } + if (HookManager.checkMythicMobs()) { + HookManager.getMythicManager().registerListener(); + } } public static void reload() { - reload(false); + reload(false); } public static void reload(boolean startup) { - // unregister all registered listeners by this plugin and register again - if (!startup) { - HandlerList.unregisterAll(getInstance()); - registerListeners(); - } + // unregister all registered listeners by this plugin and register again + if (!startup) { + HandlerList.unregisterAll(getInstance()); + registerListeners(); + } - if (saveTask != null) { - saveTask.shutdown(); - } + if (saveTask != null) { + saveTask.shutdown(); + } - if (paymentThread != null) { - paymentThread.shutdown(); - } + if (paymentThread != null) { + paymentThread.shutdown(); + } - smanager = new SelectionManager(); + smanager = new SelectionManager(); - getGCManager().reload(); - getLanguage().reload(); - getConfigManager().reload(); + getGCManager().reload(); + getLanguage().reload(); + getConfigManager().reload(); - hasLimitedItems = Jobs.getJobs().stream().anyMatch(job -> !job.getLimitedItems().isEmpty()); + hasLimitedItems = Jobs.getJobs().stream().anyMatch(job -> !job.getLimitedItems().isEmpty()); - getDBManager().getDB().loadAllJobsWorlds(); - getDBManager().getDB().loadAllJobsNames(); + getDBManager().getDB().loadAllJobsWorlds(); + getDBManager().getDB().loadAllJobsNames(); - if (Version.isCurrentEqualOrLower(Version.v1_13_R1)) { - getInstance().getBlockOwnerShip(CMIMaterial.LEGACY_BREWING_STAND).ifPresent(BlockOwnerShip::load); - getInstance().getBlockOwnerShip(CMIMaterial.LEGACY_BURNING_FURNACE).ifPresent(BlockOwnerShip::load); - } else { - getInstance().getBlockOwnerShip(CMIMaterial.FURNACE).ifPresent(BlockOwnerShip::load); - getInstance().getBlockOwnerShip(CMIMaterial.BREWING_STAND).ifPresent(BlockOwnerShip::load); - } - if (Version.isCurrentEqualOrHigher(Version.v1_14_R1)) { - getInstance().getBlockOwnerShip(CMIMaterial.BLAST_FURNACE).ifPresent(BlockOwnerShip::load); - getInstance().getBlockOwnerShip(CMIMaterial.SMOKER).ifPresent(BlockOwnerShip::load); - } + if (Version.isCurrentEqualOrLower(Version.v1_13_R1)) { + getInstance().getBlockOwnerShip(CMIMaterial.LEGACY_BREWING_STAND).ifPresent(BlockOwnerShip::load); + getInstance().getBlockOwnerShip(CMIMaterial.LEGACY_BURNING_FURNACE).ifPresent(BlockOwnerShip::load); + } else { + getInstance().getBlockOwnerShip(CMIMaterial.FURNACE).ifPresent(BlockOwnerShip::load); + getInstance().getBlockOwnerShip(CMIMaterial.BREWING_STAND).ifPresent(BlockOwnerShip::load); + } + if (Version.isCurrentEqualOrHigher(Version.v1_14_R1)) { + getInstance().getBlockOwnerShip(CMIMaterial.BLAST_FURNACE).ifPresent(BlockOwnerShip::load); + getInstance().getBlockOwnerShip(CMIMaterial.SMOKER).ifPresent(BlockOwnerShip::load); + } - ToggleBarHandling.load(); - usedSlots.clear(); - for (Job job : jobs) { - usedSlots.put(job, dao.getSlotsTaken(job)); - } - getPlayerManager().reload(); - getPermissionHandler().registerPermissions(); + ToggleBarHandling.load(); + usedSlots.clear(); + for (Job job : jobs) { + usedSlots.put(job, dao.getSlotsTaken(job)); + } + getPlayerManager().reload(); + getPermissionHandler().registerPermissions(); - // set the system to auto save - saveTask = new DatabaseSaveThread(getGCManager().getSavePeriod()); - saveTask.start(); + // set the system to auto save + saveTask = new DatabaseSaveThread(getGCManager().getSavePeriod()); + saveTask.start(); - // schedule payouts to buffered payments - paymentThread = new BufferedPaymentThread(getGCManager().getEconomyBatchDelay()); - paymentThread.start(); + // schedule payouts to buffered payments + paymentThread = new BufferedPaymentThread(getGCManager().getEconomyBatchDelay()); + paymentThread.start(); - dao.loadPlayerData(); + dao.loadPlayerData(); - // Schedule - if (getGCManager().enableSchedule) { - try { - getScheduleManager().load(); - getScheduleManager().start(); - } catch (Throwable e) { - e.printStackTrace(); - } - } else - getScheduleManager().cancel(); + // Schedule + if (getGCManager().enableSchedule) { + try { + getScheduleManager().load(); + getScheduleManager().start(); + } catch (Throwable e) { + e.printStackTrace(); + } + } else + getScheduleManager().cancel(); } @Override public void onDisable() { - CMIMessages.consoleMessage(prefix); - HandlerList.unregisterAll(this); + CMIMessages.consoleMessage(prefix); + HandlerList.unregisterAll(this); - if (dao != null) { - dao.saveExplore(); - } + if (dao != null) { + dao.saveExplore(); + } - blockOwnerShipsMaterial.values().forEach(BlockOwnerShip::save); - ToggleBarHandling.save(); + blockOwnerShipsMaterial.values().forEach(BlockOwnerShip::save); + ToggleBarHandling.save(); - if (saveTask != null) - saveTask.shutdown(); + if (saveTask != null) + saveTask.shutdown(); - if (paymentThread != null) - paymentThread.shutdown(); + if (paymentThread != null) + paymentThread.shutdown(); - if (pManager != null) { - pManager.removePlayerAdditions(); - pManager.saveAll(); - } + if (pManager != null) { + pManager.removePlayerAdditions(); + pManager.saveAll(); + } - if (dao != null) { - dao.closeConnections(); - } + if (dao != null) { + dao.closeConnections(); + } - CMIMessages.consoleMessage(suffix); + CMIMessages.consoleMessage(suffix); } private static void checkDailyQuests(JobsPlayer jPlayer, Job job, ActionInfo info) { - if (!job.getQuests().isEmpty()) { - for (QuestProgression one : jPlayer.getQuestProgressions(job, info.getType())) { - one.processQuest(jPlayer, info); - } - } + if (!job.getQuests().isEmpty()) { + for (QuestProgression one : jPlayer.getQuestProgressions(job, info.getType())) { + one.processQuest(jPlayer, info); + } + } } /** @@ -927,7 +931,7 @@ public final class Jobs extends JavaPlugin { * @see #action(JobsPlayer, ActionInfo, Block, Entity, LivingEntity) */ public static void action(JobsPlayer jPlayer, ActionInfo info) { - action(jPlayer, info, null, null, null); + action(jPlayer, info, null, null, null); } /** @@ -939,7 +943,7 @@ public final class Jobs extends JavaPlugin { * @see #action(JobsPlayer, ActionInfo, Block, Entity, LivingEntity) */ public static void action(JobsPlayer jPlayer, ActionInfo info, Block block) { - action(jPlayer, info, block, null, null); + action(jPlayer, info, block, null, null); } /** @@ -951,7 +955,7 @@ public final class Jobs extends JavaPlugin { * @see #action(JobsPlayer, ActionInfo, Block, Entity, LivingEntity) */ public static void action(JobsPlayer jPlayer, ActionInfo info, Entity ent) { - action(jPlayer, info, null, ent, null); + action(jPlayer, info, null, ent, null); } /** @@ -965,7 +969,7 @@ public final class Jobs extends JavaPlugin { * @see #action(JobsPlayer, ActionInfo, Block, Entity, LivingEntity) */ public static void action(JobsPlayer jPlayer, ActionInfo info, Entity ent, LivingEntity victim) { - action(jPlayer, info, null, ent, victim); + action(jPlayer, info, null, ent, victim); } /** @@ -990,529 +994,529 @@ public final class Jobs extends JavaPlugin { * @param block {@link Block} */ public static void action(JobsPlayer jPlayer, ActionInfo info, Block block, Entity ent, LivingEntity victim) { - if (jPlayer == null) - return; + if (jPlayer == null) + return; - List progression = jPlayer.getJobProgression(); - int numjobs = progression.size(); + List progression = jPlayer.getJobProgression(); + int numjobs = progression.size(); - if (!isBpOk(jPlayer, info, block, true)) - return; - - // no job - if (numjobs == 0) { - if (noneJob == null || noneJob.isWorldBlackListed(block) || noneJob.isWorldBlackListed(block, ent) || noneJob.isWorldBlackListed(victim)) - return; - - JobInfo jobinfo = noneJob.getJobInfo(info, 1); - - checkDailyQuests(jPlayer, noneJob, info); - - if (jobinfo == null) - return; + if (!isBpOk(jPlayer, info, block, true)) + return; + + // no job + if (numjobs == 0) { + if (noneJob == null || noneJob.isWorldBlackListed(block) || noneJob.isWorldBlackListed(block, ent) || noneJob.isWorldBlackListed(victim)) + return; + + JobInfo jobinfo = noneJob.getJobInfo(info, 1); + + checkDailyQuests(jPlayer, noneJob, info); + + if (jobinfo == null) + return; - double income = jobinfo.getIncome(1, numjobs, jPlayer.maxJobsEquation); - double pointAmount = jobinfo.getPoints(1, numjobs, jPlayer.maxJobsEquation); - - if (income == 0D && pointAmount == 0D) - return; + double income = jobinfo.getIncome(1, numjobs, jPlayer.maxJobsEquation); + double pointAmount = jobinfo.getPoints(1, numjobs, jPlayer.maxJobsEquation); + + if (income == 0D && pointAmount == 0D) + return; - Boost boost = getPlayerManager().getFinalBonus(jPlayer, noneJob); + Boost boost = getPlayerManager().getFinalBonus(jPlayer, noneJob); - JobsPrePaymentEvent jobsPrePaymentEvent = new JobsPrePaymentEvent(jPlayer.getPlayer(), noneJob, income, - pointAmount, block, ent, victim, info); - Bukkit.getServer().getPluginManager().callEvent(jobsPrePaymentEvent); - // If event is canceled, don't do anything - if (jobsPrePaymentEvent.isCancelled()) { - income = 0D; - pointAmount = 0D; - } else { - income = jobsPrePaymentEvent.getAmount(); - pointAmount = jobsPrePaymentEvent.getPoints(); - } - - // Calculate income - if (income != 0D) { - income = boost.getFinalAmount(CurrencyType.MONEY, income); - - if (gConfigManager.useMinimumOveralPayment && income > 0) { - double maxLimit = income * gConfigManager.MinimumOveralPaymentLimit; - - if (income < maxLimit) - income = maxLimit; - } - } - - // Calculate points - if (pointAmount != 0D) { - pointAmount = boost.getFinalAmount(CurrencyType.POINTS, pointAmount); - - if (gConfigManager.useMinimumOveralPoints && pointAmount > 0) { - double maxLimit = pointAmount * gConfigManager.MinimumOveralPointsLimit; - - if (pointAmount < maxLimit) - pointAmount = maxLimit; - } - } - - if (!jPlayer.isUnderLimit(CurrencyType.MONEY, income)) { - if (gConfigManager.useMaxPaymentCurve) { - double percentOver = jPlayer.percentOverLimit(CurrencyType.MONEY); - double percentLoss = 100 / ((1 / gConfigManager.maxPaymentCurveFactor * percentOver * percentOver) + 1); - - income = income - (income * percentLoss / 100); - } else - income = 0D; - if (gConfigManager.getLimit(CurrencyType.MONEY).getStopWith().contains(CurrencyType.POINTS)) - pointAmount = 0D; - } - - if (!jPlayer.isUnderLimit(CurrencyType.POINTS, pointAmount)) { - pointAmount = 0D; - if (gConfigManager.getLimit(CurrencyType.POINTS).getStopWith().contains(CurrencyType.MONEY)) - income = 0D; - } - - if (income == 0D && pointAmount == 0D) - return; - - if (info.getType() == ActionType.BREAK && block != null) - getBpManager().remove(block); - - if (pointAmount != 0D) - jPlayer.setSaved(false); - - Map payments = new HashMap<>(); - if (income != 0D) - payments.put(CurrencyType.MONEY, income); - if (pointAmount != 0D) - payments.put(CurrencyType.POINTS, pointAmount); - - economy.pay(jPlayer, payments); - - if (gConfigManager.LoggingUse) { - Map amounts = new HashMap<>(); - amounts.put(CurrencyType.MONEY, income); - getLoging().recordToLog(jPlayer, info, amounts); - } - - } else { - List expiredJobs = new ArrayList<>(); - for (JobProgression prog : progression) { - if (prog.getJob().isWorldBlackListed(block) || prog.getJob().isWorldBlackListed(block, ent) - || prog.getJob().isWorldBlackListed(victim)) - continue; - - if (jPlayer.isLeftTimeEnded(prog.getJob())) { - expiredJobs.add(prog.getJob()); - } - - JobInfo jobinfo = prog.getJob().getJobInfo(info, prog.getLevel()); - - checkDailyQuests(jPlayer, prog.getJob(), info); - - if (jobinfo == null || (gConfigManager.disablePaymentIfMaxLevelReached && prog.getLevel() >= prog.getJob().getMaxLevel())) { - continue; - } - - double income = jobinfo.getIncome(prog.getLevel(), numjobs, jPlayer.maxJobsEquation); - double pointAmount = jobinfo.getPoints(prog.getLevel(), numjobs, jPlayer.maxJobsEquation); - double expAmount = jobinfo.getExperience(prog.getLevel(), numjobs, jPlayer.maxJobsEquation); - - if (income == 0D && pointAmount == 0D && expAmount == 0D) - continue; - - if (gConfigManager.addXpPlayer()) { - Player player = jPlayer.getPlayer(); - if (player != null) { - /* - * Minecraft experience is calculated in whole numbers only. - * Calculate the fraction of an experience point and perform a dice roll. - * That way jobs that give fractions of experience points will slowly give - * experience in the aggregate - */ - int expInt = (int) expAmount; - double remainder = expAmount - expInt; - if (Math.abs(remainder) > Math.random()) { - if (expAmount < 0) - expInt--; - else - expInt++; - } - - if (expInt < 0 && getPlayerExperience(player) < -expInt) { - player.setLevel(0); - player.setTotalExperience(0); - player.setExp(0); - } else - player.giveExp(expInt); - } - } - - Boost boost = getPlayerManager().getFinalBonus(jPlayer, prog.getJob(), ent, victim); - - JobsPrePaymentEvent jobsPrePaymentEvent = new JobsPrePaymentEvent(jPlayer.getPlayer(), prog.getJob(), income, - pointAmount, block, ent, victim, info); - - Bukkit.getServer().getPluginManager().callEvent(jobsPrePaymentEvent); - // If event is canceled, don't do anything - if (jobsPrePaymentEvent.isCancelled()) { - income = 0D; - pointAmount = 0D; - } else { - income = jobsPrePaymentEvent.getAmount(); - pointAmount = jobsPrePaymentEvent.getPoints(); - } - - // Calculate income - if (income != 0D) { - income = boost.getFinalAmount(CurrencyType.MONEY, income); - - if (gConfigManager.useMinimumOveralPayment && income > 0) { - double maxLimit = income * gConfigManager.MinimumOveralPaymentLimit; - - if (income < maxLimit) - income = maxLimit; - } - } - - // Calculate points - if (pointAmount != 0D) { - pointAmount = boost.getFinalAmount(CurrencyType.POINTS, pointAmount); - - if (gConfigManager.useMinimumOveralPoints && pointAmount > 0) { - double maxLimit = pointAmount * gConfigManager.MinimumOveralPointsLimit; - - if (pointAmount < maxLimit) - pointAmount = maxLimit; - } - } - - // Calculate exp - if (expAmount != 0D) { - expAmount = boost.getFinalAmount(CurrencyType.EXP, expAmount); - - if (gConfigManager.useMinimumOveralExp && expAmount > 0) { - double maxLimit = expAmount * gConfigManager.minimumOveralExpLimit; - - if (expAmount < maxLimit) - expAmount = maxLimit; - } - } - - if (!jPlayer.isUnderLimit(CurrencyType.MONEY, income)) { - income = 0D; - - CurrencyLimit cLimit = gConfigManager.getLimit(CurrencyType.MONEY); - - if (cLimit.getStopWith().contains(CurrencyType.EXP)) - expAmount = 0D; - - if (cLimit.getStopWith().contains(CurrencyType.POINTS)) - pointAmount = 0D; - } - - if (!jPlayer.isUnderLimit(CurrencyType.EXP, expAmount)) { - expAmount = 0D; - - CurrencyLimit cLimit = gConfigManager.getLimit(CurrencyType.EXP); - - if (cLimit.getStopWith().contains(CurrencyType.MONEY)) - income = 0D; - - if (cLimit.getStopWith().contains(CurrencyType.POINTS)) - pointAmount = 0D; - } - - if (!jPlayer.isUnderLimit(CurrencyType.POINTS, pointAmount)) { - pointAmount = 0D; - - CurrencyLimit cLimit = gConfigManager.getLimit(CurrencyType.POINTS); - - if (cLimit.getStopWith().contains(CurrencyType.MONEY)) - income = 0D; - - if (cLimit.getStopWith().contains(CurrencyType.EXP)) - expAmount = 0D; - } - - if (income == 0D && pointAmount == 0D && expAmount == 0D) - continue; - - // JobsPayment event - JobsExpGainEvent jobsExpGainEvent = new JobsExpGainEvent(jPlayer.getPlayer(), prog.getJob(), expAmount, - block, ent, victim, info); - Bukkit.getServer().getPluginManager().callEvent(jobsExpGainEvent); - // If event is canceled, don't do anything - expAmount = jobsExpGainEvent.isCancelled() ? 0D : jobsExpGainEvent.getExp(); - - try { - if (expAmount != 0D && gConfigManager.BossBarEnabled) - if (gConfigManager.BossBarShowOnEachAction) - bbManager.ShowJobProgression(jPlayer, prog, expAmount); - else - jPlayer.getUpdateBossBarFor().add(prog.getJob().getName()); - } catch (Throwable e) { - e.printStackTrace(); - consoleMsg("&c[Jobs] Some issues with boss bar feature accured, try disabling it to avoid it."); - } - - Map payments = new HashMap<>(); - if (income != 0D) - payments.put(CurrencyType.MONEY, income); - if (pointAmount != 0D) - payments.put(CurrencyType.POINTS, pointAmount); - if (expAmount != 0D) - payments.put(CurrencyType.EXP, expAmount); - - FASTPAYMENT.put(jPlayer.getUniqueId(), new FastPayment(jPlayer, info, new BufferedPayment(jPlayer.getPlayer(), payments), prog - .getJob())); - - economy.pay(jPlayer, payments); - int oldLevel = prog.getLevel(); - - if (gConfigManager.LoggingUse) { - Map amounts = new HashMap<>(); - amounts.put(CurrencyType.MONEY, income); - amounts.put(CurrencyType.EXP, expAmount); - amounts.put(CurrencyType.POINTS, pointAmount); - getLoging().recordToLog(jPlayer, info, amounts); - } - - if (prog.addExperience(expAmount)) - getPlayerManager().performLevelUp(jPlayer, prog.getJob(), oldLevel); - } - - //need to update bp - if (block != null) { - BlockProtection bp = getBpManager().getBp(block.getLocation()); - if (bp != null) - bp.setPaid(true); - } - - expiredJobs.forEach(j -> getPlayerManager().leaveJob(jPlayer, j)); - } + JobsPrePaymentEvent jobsPrePaymentEvent = new JobsPrePaymentEvent(jPlayer.getPlayer(), noneJob, income, + pointAmount, block, ent, victim, info); + Bukkit.getServer().getPluginManager().callEvent(jobsPrePaymentEvent); + // If event is canceled, don't do anything + if (jobsPrePaymentEvent.isCancelled()) { + income = 0D; + pointAmount = 0D; + } else { + income = jobsPrePaymentEvent.getAmount(); + pointAmount = jobsPrePaymentEvent.getPoints(); + } + + // Calculate income + if (income != 0D) { + income = boost.getFinalAmount(CurrencyType.MONEY, income); + + if (gConfigManager.useMinimumOveralPayment && income > 0) { + double maxLimit = income * gConfigManager.MinimumOveralPaymentLimit; + + if (income < maxLimit) + income = maxLimit; + } + } + + // Calculate points + if (pointAmount != 0D) { + pointAmount = boost.getFinalAmount(CurrencyType.POINTS, pointAmount); + + if (gConfigManager.useMinimumOveralPoints && pointAmount > 0) { + double maxLimit = pointAmount * gConfigManager.MinimumOveralPointsLimit; + + if (pointAmount < maxLimit) + pointAmount = maxLimit; + } + } + + if (!jPlayer.isUnderLimit(CurrencyType.MONEY, income)) { + if (gConfigManager.useMaxPaymentCurve) { + double percentOver = jPlayer.percentOverLimit(CurrencyType.MONEY); + double percentLoss = 100 / ((1 / gConfigManager.maxPaymentCurveFactor * percentOver * percentOver) + 1); + + income = income - (income * percentLoss / 100); + } else + income = 0D; + if (gConfigManager.getLimit(CurrencyType.MONEY).getStopWith().contains(CurrencyType.POINTS)) + pointAmount = 0D; + } + + if (!jPlayer.isUnderLimit(CurrencyType.POINTS, pointAmount)) { + pointAmount = 0D; + if (gConfigManager.getLimit(CurrencyType.POINTS).getStopWith().contains(CurrencyType.MONEY)) + income = 0D; + } + + if (income == 0D && pointAmount == 0D) + return; + + if (info.getType() == ActionType.BREAK && block != null) + getBpManager().remove(block); + + if (pointAmount != 0D) + jPlayer.setSaved(false); + + Map payments = new HashMap<>(); + if (income != 0D) + payments.put(CurrencyType.MONEY, income); + if (pointAmount != 0D) + payments.put(CurrencyType.POINTS, pointAmount); + + economy.pay(jPlayer, payments); + + if (gConfigManager.LoggingUse) { + Map amounts = new HashMap<>(); + amounts.put(CurrencyType.MONEY, income); + getLoging().recordToLog(jPlayer, info, amounts); + } + + } else { + List expiredJobs = new ArrayList<>(); + for (JobProgression prog : progression) { + if (prog.getJob().isWorldBlackListed(block) || prog.getJob().isWorldBlackListed(block, ent) + || prog.getJob().isWorldBlackListed(victim)) + continue; + + if (jPlayer.isLeftTimeEnded(prog.getJob())) { + expiredJobs.add(prog.getJob()); + } + + JobInfo jobinfo = prog.getJob().getJobInfo(info, prog.getLevel()); + + checkDailyQuests(jPlayer, prog.getJob(), info); + + if (jobinfo == null || (gConfigManager.disablePaymentIfMaxLevelReached && prog.getLevel() >= prog.getJob().getMaxLevel())) { + continue; + } + + double income = jobinfo.getIncome(prog.getLevel(), numjobs, jPlayer.maxJobsEquation); + double pointAmount = jobinfo.getPoints(prog.getLevel(), numjobs, jPlayer.maxJobsEquation); + double expAmount = jobinfo.getExperience(prog.getLevel(), numjobs, jPlayer.maxJobsEquation); + + if (income == 0D && pointAmount == 0D && expAmount == 0D) + continue; + + if (gConfigManager.addXpPlayer()) { + Player player = jPlayer.getPlayer(); + if (player != null) { + /* + * Minecraft experience is calculated in whole numbers only. + * Calculate the fraction of an experience point and perform a dice roll. + * That way jobs that give fractions of experience points will slowly give + * experience in the aggregate + */ + int expInt = (int) expAmount; + double remainder = expAmount - expInt; + if (Math.abs(remainder) > Math.random()) { + if (expAmount < 0) + expInt--; + else + expInt++; + } + + if (expInt < 0 && getPlayerExperience(player) < -expInt) { + player.setLevel(0); + player.setTotalExperience(0); + player.setExp(0); + } else + player.giveExp(expInt); + } + } + + Boost boost = getPlayerManager().getFinalBonus(jPlayer, prog.getJob(), ent, victim); + + JobsPrePaymentEvent jobsPrePaymentEvent = new JobsPrePaymentEvent(jPlayer.getPlayer(), prog.getJob(), income, + pointAmount, block, ent, victim, info); + + Bukkit.getServer().getPluginManager().callEvent(jobsPrePaymentEvent); + // If event is canceled, don't do anything + if (jobsPrePaymentEvent.isCancelled()) { + income = 0D; + pointAmount = 0D; + } else { + income = jobsPrePaymentEvent.getAmount(); + pointAmount = jobsPrePaymentEvent.getPoints(); + } + + // Calculate income + if (income != 0D) { + income = boost.getFinalAmount(CurrencyType.MONEY, income); + + if (gConfigManager.useMinimumOveralPayment && income > 0) { + double maxLimit = income * gConfigManager.MinimumOveralPaymentLimit; + + if (income < maxLimit) + income = maxLimit; + } + } + + // Calculate points + if (pointAmount != 0D) { + pointAmount = boost.getFinalAmount(CurrencyType.POINTS, pointAmount); + + if (gConfigManager.useMinimumOveralPoints && pointAmount > 0) { + double maxLimit = pointAmount * gConfigManager.MinimumOveralPointsLimit; + + if (pointAmount < maxLimit) + pointAmount = maxLimit; + } + } + + // Calculate exp + if (expAmount != 0D) { + expAmount = boost.getFinalAmount(CurrencyType.EXP, expAmount); + + if (gConfigManager.useMinimumOveralExp && expAmount > 0) { + double maxLimit = expAmount * gConfigManager.minimumOveralExpLimit; + + if (expAmount < maxLimit) + expAmount = maxLimit; + } + } + + if (!jPlayer.isUnderLimit(CurrencyType.MONEY, income)) { + income = 0D; + + CurrencyLimit cLimit = gConfigManager.getLimit(CurrencyType.MONEY); + + if (cLimit.getStopWith().contains(CurrencyType.EXP)) + expAmount = 0D; + + if (cLimit.getStopWith().contains(CurrencyType.POINTS)) + pointAmount = 0D; + } + + if (!jPlayer.isUnderLimit(CurrencyType.EXP, expAmount)) { + expAmount = 0D; + + CurrencyLimit cLimit = gConfigManager.getLimit(CurrencyType.EXP); + + if (cLimit.getStopWith().contains(CurrencyType.MONEY)) + income = 0D; + + if (cLimit.getStopWith().contains(CurrencyType.POINTS)) + pointAmount = 0D; + } + + if (!jPlayer.isUnderLimit(CurrencyType.POINTS, pointAmount)) { + pointAmount = 0D; + + CurrencyLimit cLimit = gConfigManager.getLimit(CurrencyType.POINTS); + + if (cLimit.getStopWith().contains(CurrencyType.MONEY)) + income = 0D; + + if (cLimit.getStopWith().contains(CurrencyType.EXP)) + expAmount = 0D; + } + + if (income == 0D && pointAmount == 0D && expAmount == 0D) + continue; + + // JobsPayment event + JobsExpGainEvent jobsExpGainEvent = new JobsExpGainEvent(jPlayer.getPlayer(), prog.getJob(), expAmount, + block, ent, victim, info); + Bukkit.getServer().getPluginManager().callEvent(jobsExpGainEvent); + // If event is canceled, don't do anything + expAmount = jobsExpGainEvent.isCancelled() ? 0D : jobsExpGainEvent.getExp(); + + try { + if (expAmount != 0D && gConfigManager.BossBarEnabled) + if (gConfigManager.BossBarShowOnEachAction) + bbManager.ShowJobProgression(jPlayer, prog, expAmount); + else + jPlayer.getUpdateBossBarFor().add(prog.getJob().getName()); + } catch (Throwable e) { + e.printStackTrace(); + consoleMsg("&c[Jobs] Some issues with boss bar feature accured, try disabling it to avoid it."); + } + + Map payments = new HashMap<>(); + if (income != 0D) + payments.put(CurrencyType.MONEY, income); + if (pointAmount != 0D) + payments.put(CurrencyType.POINTS, pointAmount); + if (expAmount != 0D) + payments.put(CurrencyType.EXP, expAmount); + + FASTPAYMENT.put(jPlayer.getUniqueId(), new FastPayment(jPlayer, info, new BufferedPayment(jPlayer.getPlayer(), payments), prog + .getJob())); + + economy.pay(jPlayer, payments); + int oldLevel = prog.getLevel(); + + if (gConfigManager.LoggingUse) { + Map amounts = new HashMap<>(); + amounts.put(CurrencyType.MONEY, income); + amounts.put(CurrencyType.EXP, expAmount); + amounts.put(CurrencyType.POINTS, pointAmount); + getLoging().recordToLog(jPlayer, info, amounts); + } + + if (prog.addExperience(expAmount)) + getPlayerManager().performLevelUp(jPlayer, prog.getJob(), oldLevel); + } + + //need to update bp + if (block != null) { + BlockProtection bp = getBpManager().getBp(block.getLocation()); + if (bp != null) + bp.setPaid(true); + } + + expiredJobs.forEach(j -> getPlayerManager().leaveJob(jPlayer, j)); + } } private static boolean isBpOk(JobsPlayer player, ActionInfo info, Block block, boolean inform) { - if (block == null || !gConfigManager.useBlockProtection) - return true; + if (block == null || !gConfigManager.useBlockProtection) + return true; - if (info.getType() == ActionType.BREAK) { - if (block.hasMetadata("JobsExploit")) { - //player.sendMessage("This block is protected using Rukes' system!"); - return false; - } + if (info.getType() == ActionType.BREAK) { + if (block.hasMetadata("JobsExploit")) { + //player.sendMessage("This block is protected using Rukes' system!"); + return false; + } - BlockProtection bp = getBpManager().getBp(block.getLocation()); - if (bp != null) { - long time = bp.getTime(); - Integer cd = getBpManager().getBlockDelayTime(block); + BlockProtection bp = getBpManager().getBp(block.getLocation()); + if (bp != null) { + long time = bp.getTime(); + Integer cd = getBpManager().getBlockDelayTime(block); - if (time == -1L) { - getBpManager().remove(block); - return false; - } + if (time == -1L) { + getBpManager().remove(block); + return false; + } - if (time < System.currentTimeMillis() && bp.getAction() != DBAction.DELETE) { - getBpManager().remove(block); - return true; - } + if (time < System.currentTimeMillis() && bp.getAction() != DBAction.DELETE) { + getBpManager().remove(block); + return true; + } - if ((time > System.currentTimeMillis() || bp.isPaid()) && bp.getAction() != DBAction.DELETE) { - if (inform && player.canGetPaid(info)) { - int sec = Math.round((time - System.currentTimeMillis()) / 1000L); - CMIActionBar.send(player.getPlayer(), lManager.getMessage("message.blocktimer", "[time]", sec)); - } + if ((time > System.currentTimeMillis() || bp.isPaid()) && bp.getAction() != DBAction.DELETE) { + if (inform && player.canGetPaid(info)) { + int sec = Math.round((time - System.currentTimeMillis()) / 1000L); + CMIActionBar.send(player.getPlayer(), lManager.getMessage("message.blocktimer", "[time]", sec)); + } - return false; - } + return false; + } - getBpManager().add(block, cd); + getBpManager().add(block, cd); - if ((cd == null || cd == 0) && gConfigManager.useGlobalTimer) { - getBpManager().add(block, gConfigManager.globalblocktimer); - } + if ((cd == null || cd == 0) && gConfigManager.useGlobalTimer) { + getBpManager().add(block, gConfigManager.globalblocktimer); + } - } else if (gConfigManager.useGlobalTimer) { - getBpManager().add(block, gConfigManager.globalblocktimer); - } - } else if (info.getType() == ActionType.PLACE) { - BlockProtection bp = getBpManager().getBp(block.getLocation()); - if (bp != null) { - Long time = bp.getTime(); - Integer cd = getBpManager().getBlockDelayTime(block); - if (time != -1L) { - if (time < System.currentTimeMillis() && bp.getAction() != DBAction.DELETE) { - getBpManager().add(block, cd); - return true; - } + } else if (gConfigManager.useGlobalTimer) { + getBpManager().add(block, gConfigManager.globalblocktimer); + } + } else if (info.getType() == ActionType.PLACE) { + BlockProtection bp = getBpManager().getBp(block.getLocation()); + if (bp != null) { + Long time = bp.getTime(); + Integer cd = getBpManager().getBlockDelayTime(block); + if (time != -1L) { + if (time < System.currentTimeMillis() && bp.getAction() != DBAction.DELETE) { + getBpManager().add(block, cd); + return true; + } - if ((time > System.currentTimeMillis() || bp.isPaid()) && bp.getAction() != DBAction.DELETE) { - if (inform && player.canGetPaid(info)) { - int sec = Math.round((time - System.currentTimeMillis()) / 1000L); - CMIActionBar.send(player.getPlayer(), lManager.getMessage("message.blocktimer", "[time]", sec)); - } + if ((time > System.currentTimeMillis() || bp.isPaid()) && bp.getAction() != DBAction.DELETE) { + if (inform && player.canGetPaid(info)) { + int sec = Math.round((time - System.currentTimeMillis()) / 1000L); + CMIActionBar.send(player.getPlayer(), lManager.getMessage("message.blocktimer", "[time]", sec)); + } - getBpManager().add(block, cd); - return false; - } + getBpManager().add(block, cd); + return false; + } - // Lets add protection in any case - getBpManager().add(block, cd); - } else if (bp.isPaid() && bp.getTime() == -1L && cd != null && cd == -1) { - getBpManager().add(block, cd); - return false; - } else - getBpManager().add(block, cd); - } else - getBpManager().add(block, getBpManager().getBlockDelayTime(block)); - } + // Lets add protection in any case + getBpManager().add(block, cd); + } else if (bp.isPaid() && bp.getTime() == -1L && cd != null && cd == -1) { + getBpManager().add(block, cd); + return false; + } else + getBpManager().add(block, cd); + } else + getBpManager().add(block, getBpManager().getBlockDelayTime(block)); + } - return true; + return true; } private static int getPlayerExperience(Player player) { - return (expToLevel(player.getLevel()) + Math.round(deltaLevelToExp(player.getLevel()) * player.getExp())); + return (expToLevel(player.getLevel()) + Math.round(deltaLevelToExp(player.getLevel()) * player.getExp())); } // total xp calculation based by lvl private static int expToLevel(int level) { - if (Version.isCurrentEqualOrLower(Version.v1_7_R4)) { - if (level <= 16) - return 17 * level; - else if (level <= 31) - return ((3 * level * level) / 2) - ((59 * level) / 2) + 360; - else - return ((7 * level * level) / 2) - ((303 * level) / 2) + 2220; - } - if (level <= 16) - return (level * level) + (6 * level); - else if (level <= 31) - return (int) ((2.5 * level * level) - (40.5 * level) + 360); - else - return (int) ((4.5 * level * level) - (162.5 * level) + 2220); + if (Version.isCurrentEqualOrLower(Version.v1_7_R4)) { + if (level <= 16) + return 17 * level; + else if (level <= 31) + return ((3 * level * level) / 2) - ((59 * level) / 2) + 360; + else + return ((7 * level * level) / 2) - ((303 * level) / 2) + 2220; + } + if (level <= 16) + return (level * level) + (6 * level); + else if (level <= 31) + return (int) ((2.5 * level * level) - (40.5 * level) + 360); + else + return (int) ((4.5 * level * level) - (162.5 * level) + 2220); } // xp calculation for one current lvl private static int deltaLevelToExp(int level) { - if (Version.isCurrentEqualOrLower(Version.v1_7_R4)) { - if (level <= 16) - return 17; - else if (level <= 31) - return 3 * level - 31; - else - return 7 * level - 155; - } - if (level <= 16) - return 2 * level + 7; - else if (level <= 31) - return 5 * level - 38; - else - return 9 * level - 158; + if (Version.isCurrentEqualOrLower(Version.v1_7_R4)) { + if (level <= 16) + return 17; + else if (level <= 31) + return 3 * level - 31; + else + return 7 * level - 155; + } + if (level <= 16) + return 2 * level + 7; + else if (level <= 31) + return 5 * level - 38; + else + return 9 * level - 158; } public static void perform(JobsPlayer jPlayer, ActionInfo info, BufferedPayment payment, Job job) { - double expPayment = payment.get(CurrencyType.EXP); + double expPayment = payment.get(CurrencyType.EXP); - JobsExpGainEvent jobsExpGainEvent = new JobsExpGainEvent(payment.getOfflinePlayer(), job, expPayment); - Bukkit.getServer().getPluginManager().callEvent(jobsExpGainEvent); - // If event is canceled, don't do anything - if (jobsExpGainEvent.isCancelled()) - return; + JobsExpGainEvent jobsExpGainEvent = new JobsExpGainEvent(payment.getOfflinePlayer(), job, expPayment); + Bukkit.getServer().getPluginManager().callEvent(jobsExpGainEvent); + // If event is canceled, don't do anything + if (jobsExpGainEvent.isCancelled()) + return; - boolean limited = true; - for (CurrencyType one : CurrencyType.values()) { - if (jPlayer.isUnderLimit(one, payment.get(one))) { - limited = false; - break; - } - } + boolean limited = true; + for (CurrencyType one : CurrencyType.values()) { + if (jPlayer.isUnderLimit(one, payment.get(one))) { + limited = false; + break; + } + } - if (limited) - return; + if (limited) + return; - economy.pay(jPlayer, payment.getPayment()); + economy.pay(jPlayer, payment.getPayment()); - JobProgression prog = jPlayer.getJobProgression(job); - int oldLevel = prog.getLevel(); + JobProgression prog = jPlayer.getJobProgression(job); + int oldLevel = prog.getLevel(); - if (gConfigManager.LoggingUse) { - getLoging().recordToLog(jPlayer, info, payment.getPayment()); - } + if (gConfigManager.LoggingUse) { + getLoging().recordToLog(jPlayer, info, payment.getPayment()); + } - if (prog.addExperience(expPayment)) - getPlayerManager().performLevelUp(jPlayer, prog.getJob(), oldLevel); + if (prog.addExperience(expPayment)) + getPlayerManager().performLevelUp(jPlayer, prog.getJob(), oldLevel); } public static void consoleMsg(String msg) { - if (msg != null) { - Bukkit.getServer().getConsoleSender().sendMessage(CMIChatColor.translate(msg)); - } + if (msg != null) { + Bukkit.getServer().getConsoleSender().sendMessage(CMIChatColor.translate(msg)); + } } public static SelectionManager getSelectionManager() { - return smanager; + return smanager; } public static boolean hasPermission(Object sender, String perm, boolean rawEnable) { - if (!(sender instanceof Player) || ((Player) sender).hasPermission(perm)) - return true; + if (!(sender instanceof Player) || ((Player) sender).hasPermission(perm)) + return true; - if (!rawEnable) { - CMIMessages.sendMessage(sender, LC.info_NoPermission); - return false; - } - new RawMessage().addText(LC.info_NoPermission.getLocale()).addHover("&2" + perm).show((Player) sender); - return false; + if (!rawEnable) { + CMIMessages.sendMessage(sender, LC.info_NoPermission); + return false; + } + new RawMessage().addText(LC.info_NoPermission.getLocale()).addHover("&2" + perm).show((Player) sender); + return false; } public void showPagination(CommandSender sender, PageInfo pi, String cmd) { - showPagination(sender, pi.getTotalPages(), pi.getCurrentPage(), pi.getTotalEntries(), cmd, null); + showPagination(sender, pi.getTotalPages(), pi.getCurrentPage(), pi.getTotalEntries(), cmd, null); } public void showPagination(CommandSender sender, PageInfo pi, String cmd, String pagePref) { - showPagination(sender, pi.getTotalPages(), pi.getCurrentPage(), pi.getTotalEntries(), cmd, pagePref); + showPagination(sender, pi.getTotalPages(), pi.getCurrentPage(), pi.getTotalEntries(), cmd, pagePref); } public void showPagination(CommandSender sender, int pageCount, int currentPage, int totalEntries, String cmd, String pagePref) { - if (!(sender instanceof Player)) - return; + if (!(sender instanceof Player)) + return; - if (!cmd.startsWith("/")) - cmd = "/" + cmd; + if (!cmd.startsWith("/")) + cmd = "/" + cmd; - if (pageCount == 1) - return; + if (pageCount == 1) + return; - String pagePrefix = pagePref == null ? "" : pagePref; + String pagePrefix = pagePref == null ? "" : pagePref; - int nextPage = currentPage + 1; - nextPage = currentPage < pageCount ? nextPage : currentPage; + int nextPage = currentPage + 1; + nextPage = currentPage < pageCount ? nextPage : currentPage; - int prevpage = currentPage - 1; - if (currentPage <= 1) { - prevpage = currentPage; - } + int prevpage = currentPage - 1; + if (currentPage <= 1) { + prevpage = currentPage; + } - RawMessage rm = new RawMessage() - .addText((currentPage > 1 ? LC.info_prevPage.getLocale() : LC.info_prevPageOff.getLocale())) - .addHover(currentPage > 1 ? LC.info_prevPageHover.getLocale() : LC.info_lastPageHover.getLocale()) - .addCommand(currentPage > 1 ? cmd + " " + pagePrefix + prevpage : cmd + " " + pagePrefix + pageCount); + RawMessage rm = new RawMessage() + .addText((currentPage > 1 ? LC.info_prevPage.getLocale() : LC.info_prevPageOff.getLocale())) + .addHover(currentPage > 1 ? LC.info_prevPageHover.getLocale() : LC.info_lastPageHover.getLocale()) + .addCommand(currentPage > 1 ? cmd + " " + pagePrefix + prevpage : cmd + " " + pagePrefix + pageCount); - rm.addText(LC.info_pageCount.getLocale("[current]", currentPage, "[total]", pageCount)) - .addHover(LC.info_pageCountHover.getLocale("[totalEntries]", totalEntries)); + rm.addText(LC.info_pageCount.getLocale("[current]", currentPage, "[total]", pageCount)) + .addHover(LC.info_pageCountHover.getLocale("[totalEntries]", totalEntries)); - rm.addText(pageCount > currentPage ? LC.info_nextPage.getLocale() : LC.info_nextPageOff.getLocale()) - .addHover(pageCount > currentPage ? LC.info_nextPageHover.getLocale() : LC.info_firstPageHover.getLocale()) - .addCommand(pageCount > currentPage ? cmd + " " + pagePrefix + nextPage : cmd + " " + pagePrefix + 1); + rm.addText(pageCount > currentPage ? LC.info_nextPage.getLocale() : LC.info_nextPageOff.getLocale()) + .addHover(pageCount > currentPage ? LC.info_nextPageHover.getLocale() : LC.info_firstPageHover.getLocale()) + .addCommand(pageCount > currentPage ? cmd + " " + pagePrefix + nextPage : cmd + " " + pagePrefix + 1); - if (pageCount != 0) - rm.show(sender); + if (pageCount != 0) + rm.show(sender); } public static boolean hasLimitedItems() { - return hasLimitedItems; + return hasLimitedItems; } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java b/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java index b2134d00..6b9ff67f 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java +++ b/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Set; import java.util.TreeSet; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -24,6 +25,7 @@ import com.gamingmesh.jobs.container.Title; import com.gamingmesh.jobs.stuff.Util; import net.Zrips.CMILib.ActionBar.CMIActionBar; +import net.Zrips.CMILib.Container.CMIArray; import net.Zrips.CMILib.Container.PageInfo; import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Messages.CMIMessages; @@ -40,202 +42,219 @@ public class JobsCommands implements CommandExecutor { protected Jobs plugin; public JobsCommands(Jobs plugin) { - this.plugin = plugin; + this.plugin = plugin; } public Set getCommands() { - return commandList; + return commandList; } @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (sender instanceof Player && !Jobs.getGCManager().canPerformActionInWorld(((Player) sender).getWorld()) - && !sender.hasPermission("jobs.disabledworld.commands")) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.worldisdisabled")); - return true; - } + if (sender instanceof Player && !Jobs.getGCManager().canPerformActionInWorld(((Player) sender).getWorld()) + && !sender.hasPermission("jobs.disabledworld.commands")) { + sender.sendMessage(Jobs.getLanguage().getMessage("general.error.worldisdisabled")); + return true; + } - if (args.length == 0) - return help(sender, 1); + helpBrake: if (args.length == 0) { - if ((args.length == 1 || args.length == 2) && (args[0].equals("?") || args[0].equalsIgnoreCase("help"))) { - int page = 1; - if (args.length == 2) - try { - page = Integer.parseInt(args[1]); - } catch (NumberFormatException e) { - CMIMessages.sendMessage(sender, LC.info_UseInteger); - return true; - } - return help(sender, page); - } + if (!Jobs.getGeneralConfigManager().helpPageBehavior.isEmpty() && sender instanceof Player) { + if (Jobs.getGeneralConfigManager().helpPageBehavior.get(0).equals("browse")) { + args = CMIArray.addLast(args, "browse"); + break helpBrake; + } - String cmd = args[0].toLowerCase(); - Cmd cmdClass = getCmdClass(cmd); - if (cmdClass == null) { - CMIMessages.sendMessage(sender, LC.info_NoCommand); - return true; - } + boolean result = false; + for (String one : Jobs.getGeneralConfigManager().helpPageBehavior) { + one = one.replace("[playerName]", sender.getName()); + if (Bukkit.dispatchCommand(Bukkit.getConsoleSender(), one)) + result = true; + } + return result; + } - if (!hasCommandPermission(sender, cmd)) { - if (sender instanceof Player) { - new RawMessage().addText(LC.info_NoPermission.getLocale()) - .addHover("&2" + label + ".command." + cmd).show(sender); - } else - CMIMessages.sendMessage(sender, LC.info_NoPermission); - return true; - } + return help(sender, 1); + } - String[] myArgs = reduceArgs(args); - if (myArgs.length > 0 && myArgs[myArgs.length - 1].equals("?")) { - sendUsage(sender, cmd); - return true; - } + if ((args.length == 1 || args.length == 2) && (args[0].equals("?") || args[0].equalsIgnoreCase("help"))) { + int page = 1; + if (args.length == 2) + try { + page = Integer.parseInt(args[1]); + } catch (NumberFormatException e) { + CMIMessages.sendMessage(sender, LC.info_UseInteger); + return true; + } + return help(sender, page); + } - return cmdClass.perform(plugin, sender, myArgs) || help(sender, 1); + String cmd = args[0].toLowerCase(); + Cmd cmdClass = getCmdClass(cmd); + if (cmdClass == null) { + CMIMessages.sendMessage(sender, LC.info_NoCommand); + return true; + } + + if (!hasCommandPermission(sender, cmd)) { + if (sender instanceof Player) { + new RawMessage().addText(LC.info_NoPermission.getLocale()) + .addHover("&2" + label + ".command." + cmd).show(sender); + } else + CMIMessages.sendMessage(sender, LC.info_NoPermission); + return true; + } + + String[] myArgs = reduceArgs(args); + if (myArgs.length > 0 && myArgs[myArgs.length - 1].equals("?")) { + sendUsage(sender, cmd); + return true; + } + + return cmdClass.perform(plugin, sender, myArgs) || help(sender, 1); } private static String[] reduceArgs(String[] args) { - return args.length <= 1 ? new String[0] : Arrays.copyOfRange(args, 1, args.length); + return args.length <= 1 ? new String[0] : Arrays.copyOfRange(args, 1, args.length); } private static boolean hasCommandPermission(CommandSender sender, String cmd) { - return sender.hasPermission("jobs.command." + cmd); + return sender.hasPermission("jobs.command." + cmd); } private static String getUsage(String cmd) { - String cmdString = Jobs.getLanguage().getMessage("command.help.output.cmdFormat", "[command]", Jobs.getLanguage().getMessage("command.help.output.label") + " " + cmd); - String msg = Jobs.getLanguage().getMessage("command." + cmd + ".help.args"); + String cmdString = Jobs.getLanguage().getMessage("command.help.output.cmdFormat", "[command]", Jobs.getLanguage().getMessage("command.help.output.label") + " " + cmd); + String msg = Jobs.getLanguage().getMessage("command." + cmd + ".help.args"); - cmdString = cmdString.replace("[arguments]", !msg.isEmpty() ? msg : ""); - return cmdString; + cmdString = cmdString.replace("[arguments]", !msg.isEmpty() ? msg : ""); + return cmdString; } public void sendUsage(CommandSender sender, String cmd) { - String message = Jobs.getLanguage().getMessage("command.help.output.cmdUsage"); - message = message.replace("[command]", getUsage(cmd)); - sender.sendMessage(message); - sender.sendMessage(Jobs.getLanguage().getMessage("command.help.output.helpPageDescription", "[description]", Jobs.getLanguage().getMessage("command." + cmd + ".help.info"))); + String message = Jobs.getLanguage().getMessage("command.help.output.cmdUsage"); + message = message.replace("[command]", getUsage(cmd)); + sender.sendMessage(message); + sender.sendMessage(Jobs.getLanguage().getMessage("command.help.output.helpPageDescription", "[description]", Jobs.getLanguage().getMessage("command." + cmd + ".help.info"))); } protected boolean help(CommandSender sender, int page) { - Set commands = getCommands(sender); - if (commands.isEmpty()) { - CMIMessages.sendMessage(sender, LC.info_NoPermission); - return true; - } + Set commands = getCommands(sender); + if (commands.isEmpty()) { + CMIMessages.sendMessage(sender, LC.info_NoPermission); + return true; + } - if (page < 1) { - CMIActionBar.send(sender, Jobs.getLanguage().getMessage("general.error.noHelpPage")); - return true; - } + if (page < 1) { + CMIActionBar.send(sender, Jobs.getLanguage().getMessage("general.error.noHelpPage")); + return true; + } - PageInfo pi = new PageInfo(10, commands.size(), page); - if (page > pi.getTotalPages()) { - CMIActionBar.send(sender, Jobs.getLanguage().getMessage("general.error.noHelpPage")); - return true; - } + PageInfo pi = new PageInfo(10, commands.size(), page); + if (page > pi.getTotalPages()) { + CMIActionBar.send(sender, Jobs.getLanguage().getMessage("general.error.noHelpPage")); + return true; + } - RawMessage rm = new RawMessage(); - rm.addText(Jobs.getLanguage().getMessage("command.help.output.title")); + RawMessage rm = new RawMessage(); + rm.addText(Jobs.getLanguage().getMessage("command.help.output.title")); - boolean pl = sender instanceof Player; + boolean pl = sender instanceof Player; - // Old format + // Old format // sender.sendMessage(Jobs.getLanguage().getMessage("command.help.output.title")); - for (String one : commands) { - if (!pi.isEntryOk()) - continue; - if (pi.isBreak()) - break; + for (String one : commands) { + if (!pi.isEntryOk()) + continue; + if (pi.isBreak()) + break; - // Old format + // Old format // sender.sendMessage(Jobs.getLanguage().getMessage("command.help.output.cmdInfoFormat", "[command]", getUsage(one), "[description]", Jobs.getLanguage().getMessage("command." + one // + ".help.info"))); - if (pl) { - rm.addText("\n" + getUsage(one)); - rm.addHover(Jobs.getLanguage().getMessage("command." + one + ".help.info")); - rm.addSuggestion("/" + Jobs.getLanguage().getMessage("command.help.output.label").toLowerCase() + " " + one + " "); - } else { - rm.addText("\n" + Jobs.getLanguage().getMessage("command.help.output.cmdInfoFormat", "[command]", getUsage(one), "[description]", Jobs.getLanguage().getMessage("command." + one - + ".help.info"))); - } + if (pl) { + rm.addText("\n" + getUsage(one)); + rm.addHover(Jobs.getLanguage().getMessage("command." + one + ".help.info")); + rm.addSuggestion("/" + Jobs.getLanguage().getMessage("command.help.output.label").toLowerCase() + " " + one + " "); + } else { + rm.addText("\n" + Jobs.getLanguage().getMessage("command.help.output.cmdInfoFormat", "[command]", getUsage(one), "[description]", Jobs.getLanguage().getMessage("command." + one + + ".help.info"))); + } - } + } - rm.show(sender); + rm.show(sender); - plugin.showPagination(sender, pi, LABEL + " ?"); - return true; + plugin.showPagination(sender, pi, LABEL + " ?"); + return true; } public Set getCommands(CommandSender sender) { - Set temp = new TreeSet<>(); - boolean senderIsPlayer = sender instanceof Player; + Set temp = new TreeSet<>(); + boolean senderIsPlayer = sender instanceof Player; - for (String cmd : commandList) { - if (senderIsPlayer && !hasCommandPermission(sender, cmd)) - continue; + for (String cmd : commandList) { + if (senderIsPlayer && !hasCommandPermission(sender, cmd)) + continue; - temp.add(cmd); - } + temp.add(cmd); + } - return temp; + return temp; } public void fillCommands() { - List lm = new ArrayList<>(); - try { - lm = Util.getFilesFromPackage(PACKAGEPATH); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } + List lm = new ArrayList<>(); + try { + lm = Util.getFilesFromPackage(PACKAGEPATH); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } - for (String one : lm) { - Class newClass = getClass(one); - if (newClass != null) - commandList.add(newClass.getSimpleName()); - } + for (String one : lm) { + Class newClass = getClass(one); + if (newClass != null) + commandList.add(newClass.getSimpleName()); + } } private static Class getClass(String cmd) { - try { - return Class.forName(PACKAGEPATH + "." + cmd.toLowerCase()); - } catch (ClassNotFoundException e) { - } - return null; + try { + return Class.forName(PACKAGEPATH + "." + cmd.toLowerCase()); + } catch (ClassNotFoundException e) { + } + return null; } private static Cmd getCmdClass(String cmd) { - try { - Class nmsClass = getClass(cmd); - if (nmsClass != null && Cmd.class.isAssignableFrom(nmsClass)) { - return (Cmd) nmsClass.getConstructor().newInstance(); - } - } catch (Exception e) { - } - return null; + try { + Class nmsClass = getClass(cmd); + if (nmsClass != null && Cmd.class.isAssignableFrom(nmsClass)) { + return (Cmd) nmsClass.getConstructor().newInstance(); + } + } catch (Exception e) { + } + return null; } /** * Check Job joining permission */ public boolean hasJobPermission(CommandSender sender, Job job) { - return sender.hasPermission("jobs.use") && sender.hasPermission("jobs.join." + job.getName().toLowerCase()); + return sender.hasPermission("jobs.use") && sender.hasPermission("jobs.join." + job.getName().toLowerCase()); } public void sendValidActions(CommandSender sender) { - StringBuilder builder = new StringBuilder(); - boolean first = true; - for (ActionType action : ActionType.values()) { - if (!first) - builder.append(','); - builder.append(action.getName()); - first = false; + StringBuilder builder = new StringBuilder(); + boolean first = true; + for (ActionType action : ActionType.values()) { + if (!first) + builder.append(','); + builder.append(action.getName()); + first = false; - } - sender.sendMessage(Jobs.getLanguage().getMessage("command.info.help.actions", "%actions%", builder.toString())); + } + sender.sendMessage(Jobs.getLanguage().getMessage("command.info.help.actions", "%actions%", builder.toString())); } /** @@ -246,76 +265,76 @@ public class JobsCommands implements CommandExecutor { * @return the message */ public void jobInfoMessage(CommandSender sender, JobsPlayer player, Job job, String type, int page) { - if (job == null) { - // job doesn't exist - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return; - } + if (job == null) { + // job doesn't exist + sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); + return; + } - type = type == null ? "" : type.toLowerCase(); + type = type == null ? "" : type.toLowerCase(); - List message = new ArrayList<>(); + List message = new ArrayList<>(); - if (job.getBoost().get(CurrencyType.EXP) != 0D) - message.add(Jobs.getLanguage().getMessage("command.expboost.output.infostats", "%boost%", (job.getBoost().get(CurrencyType.EXP)) + 1)); + if (job.getBoost().get(CurrencyType.EXP) != 0D) + message.add(Jobs.getLanguage().getMessage("command.expboost.output.infostats", "%boost%", (job.getBoost().get(CurrencyType.EXP)) + 1)); - if (job.getBoost().get(CurrencyType.MONEY) != 0D) - message.add(Jobs.getLanguage().getMessage("command.moneyboost.output.infostats", "%boost%", (job.getBoost().get(CurrencyType.MONEY)) + 1)); + if (job.getBoost().get(CurrencyType.MONEY) != 0D) + message.add(Jobs.getLanguage().getMessage("command.moneyboost.output.infostats", "%boost%", (job.getBoost().get(CurrencyType.MONEY)) + 1)); - if (job.getBoost().get(CurrencyType.POINTS) != 0D) - message.add(Jobs.getLanguage().getMessage("command.pointboost.output.infostats", "%boost%", (job.getBoost().get(CurrencyType.POINTS)) + 1)); + if (job.getBoost().get(CurrencyType.POINTS) != 0D) + message.add(Jobs.getLanguage().getMessage("command.pointboost.output.infostats", "%boost%", (job.getBoost().get(CurrencyType.POINTS)) + 1)); - if (Jobs.getGCManager().useDynamicPayment) { - int bonus = (int) ((job.getBonus() * 100) / 100.0); + if (Jobs.getGCManager().useDynamicPayment) { + int bonus = (int) ((job.getBonus() * 100) / 100.0); - if (bonus != 0) { - if (bonus < 0) - message.add(Jobs.getLanguage().getMessage("command.info.help.penalty", "[penalty]", (int) (job.getBonus() * 100) / 100.0 * -1)); - else - message.add(Jobs.getLanguage().getMessage("command.info.help.bonus", "[bonus]", bonus)); - } - } + if (bonus != 0) { + if (bonus < 0) + message.add(Jobs.getLanguage().getMessage("command.info.help.penalty", "[penalty]", (int) (job.getBonus() * 100) / 100.0 * -1)); + else + message.add(Jobs.getLanguage().getMessage("command.info.help.bonus", "[bonus]", bonus)); + } + } - for (ActionType actionType : ActionType.values()) { - if (type.isEmpty() || type.startsWith(actionType.getName().toLowerCase())) { - List info = job.getJobInfo(actionType); - if (info != null && !info.isEmpty()) { - String m = jobInfoMessage(player, job, actionType); - if (m.contains("\n")) - message.addAll(Arrays.asList(m.split("\n"))); - else - message.add(m); - } else if (!type.isEmpty()) { - message.add(Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase() + ".none", "%jobname%", job.getDisplayName())); - } - } - } + for (ActionType actionType : ActionType.values()) { + if (type.isEmpty() || type.startsWith(actionType.getName().toLowerCase())) { + List info = job.getJobInfo(actionType); + if (info != null && !info.isEmpty()) { + String m = jobInfoMessage(player, job, actionType); + if (m.contains("\n")) + message.addAll(Arrays.asList(m.split("\n"))); + else + message.add(m); + } else if (!type.isEmpty()) { + message.add(Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase() + ".none", "%jobname%", job.getDisplayName())); + } + } + } - PageInfo pi = new PageInfo(15, message.size(), page); + PageInfo pi = new PageInfo(15, message.size(), page); - if (page > pi.getTotalPages()) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.info.invalidPage")); - return; - } + if (page > pi.getTotalPages()) { + sender.sendMessage(Jobs.getLanguage().getMessage("general.info.invalidPage")); + return; + } - boolean isPlayer = sender instanceof Player; - for (String one : message) { - if (isPlayer && !pi.isEntryOk()) - continue; - if (isPlayer && pi.isBreak()) - break; - sender.sendMessage(one); - } + boolean isPlayer = sender instanceof Player; + for (String one : message) { + if (isPlayer && !pi.isEntryOk()) + continue; + if (isPlayer && pi.isBreak()) + break; + sender.sendMessage(one); + } - if (isPlayer) { - String t = type.isEmpty() ? "" : " " + type; - String pName = player.getName(); + if (isPlayer) { + String t = type.isEmpty() ? "" : " " + type; + String pName = player.getName(); - if (sender.getName().equalsIgnoreCase(pName)) - plugin.showPagination(sender, pi, "jobs info " + job.getName() + t); - else - plugin.showPagination(sender, pi, "jobs playerinfo " + pName + " " + job.getName() + t); - } + if (sender.getName().equalsIgnoreCase(pName)) + plugin.showPagination(sender, pi, "jobs info " + job.getName() + t); + else + plugin.showPagination(sender, pi, "jobs playerinfo " + pName + " " + job.getName() + t); + } } /** @@ -326,67 +345,67 @@ public class JobsCommands implements CommandExecutor { * @return the message */ public static String jobInfoMessage(JobsPlayer player, Job job, ActionType type) { - // money exp boost - Boost boost = Jobs.getPlayerManager().getFinalBonus(player, job, true); + // money exp boost + Boost boost = Jobs.getPlayerManager().getFinalBonus(player, job, true); - StringBuilder message = new StringBuilder(); + StringBuilder message = new StringBuilder(); - message.append(Jobs.getLanguage().getMessage("command.info.output." + type.getName().toLowerCase() + ".info")); - message.append(":\n"); + message.append(Jobs.getLanguage().getMessage("command.info.output." + type.getName().toLowerCase() + ".info")); + message.append(":\n"); - JobProgression prog = player.getJobProgression(job); - int level = prog != null ? prog.getLevel() : 1; - int numjobs = player.progression.size(); + JobProgression prog = player.getJobProgression(job); + int level = prog != null ? prog.getLevel() : 1; + int numjobs = player.progression.size(); - for (JobInfo info : job.getJobInfo(type)) { + for (JobInfo info : job.getJobInfo(type)) { - String materialName = info.getRealisticName(); + String materialName = info.getRealisticName(); - double income = info.getIncome(level, numjobs, player.maxJobsEquation); + double income = info.getIncome(level, numjobs, player.maxJobsEquation); - income = boost.getFinalAmount(CurrencyType.MONEY, income); - String incomeColor = income >= 0 ? "" : ChatColor.DARK_RED.toString(); + income = boost.getFinalAmount(CurrencyType.MONEY, income); + String incomeColor = income >= 0 ? "" : ChatColor.DARK_RED.toString(); - double xp = info.getExperience(level, numjobs, player.maxJobsEquation); - xp = boost.getFinalAmount(CurrencyType.EXP, xp); - String xpColor = xp >= 0 ? "" : ChatColor.GRAY.toString(); + double xp = info.getExperience(level, numjobs, player.maxJobsEquation); + xp = boost.getFinalAmount(CurrencyType.EXP, xp); + String xpColor = xp >= 0 ? "" : ChatColor.GRAY.toString(); - double points = info.getPoints(level, numjobs, player.maxJobsEquation); - points = boost.getFinalAmount(CurrencyType.POINTS, points); - String pointsColor = xp >= 0 ? "" : ChatColor.RED.toString(); + double points = info.getPoints(level, numjobs, player.maxJobsEquation); + points = boost.getFinalAmount(CurrencyType.POINTS, points); + String pointsColor = xp >= 0 ? "" : ChatColor.RED.toString(); - if (income == 0D && points == 0D && xp == 0D) - continue; + if (income == 0D && points == 0D && xp == 0D) + continue; - message.append(" "); + message.append(" "); - message.append(Jobs.getLanguage().getMessage("command.info.help.material", "%material%", materialName)); - if (prog != null && !info.isInLevelRange(prog.getLevel())) - message.append(ChatColor.RED + " -> "); - else - message.append(" -> "); + message.append(Jobs.getLanguage().getMessage("command.info.help.material", "%material%", materialName)); + if (prog != null && !info.isInLevelRange(prog.getLevel())) + message.append(ChatColor.RED + " -> "); + else + message.append(" -> "); - if (income != 0.0) - message.append(Jobs.getLanguage().getMessage("command.info.help.money", "%money%", incomeColor + String.format(Jobs.getGCManager().getDecimalPlacesMoney(), income))); + if (income != 0.0) + message.append(Jobs.getLanguage().getMessage("command.info.help.money", "%money%", incomeColor + String.format(Jobs.getGCManager().getDecimalPlacesMoney(), income))); - if (points != 0.0) - message.append(Jobs.getLanguage().getMessage("command.info.help.points", "%points%", pointsColor + String.format(Jobs.getGCManager().getDecimalPlacesPoints(), points))); + if (points != 0.0) + message.append(Jobs.getLanguage().getMessage("command.info.help.points", "%points%", pointsColor + String.format(Jobs.getGCManager().getDecimalPlacesPoints(), points))); - if (xp != 0.0) - message.append(Jobs.getLanguage().getMessage("command.info.help.exp", "%exp%", xpColor + String.format(Jobs.getGCManager().getDecimalPlacesExp(), xp))); + if (xp != 0.0) + message.append(Jobs.getLanguage().getMessage("command.info.help.exp", "%exp%", xpColor + String.format(Jobs.getGCManager().getDecimalPlacesExp(), xp))); - if (info.getFromLevel() > 1 && info.getUntilLevel() != -1) - message.append(Jobs.getLanguage().getMessage("command.info.help.levelRange", "%levelFrom%", info.getFromLevel(), "%levelUntil%", info.getUntilLevel())); + if (info.getFromLevel() > 1 && info.getUntilLevel() != -1) + message.append(Jobs.getLanguage().getMessage("command.info.help.levelRange", "%levelFrom%", info.getFromLevel(), "%levelUntil%", info.getUntilLevel())); - if (info.getFromLevel() > 1 && info.getUntilLevel() == -1) - message.append(Jobs.getLanguage().getMessage("command.info.help.levelFrom", "%levelFrom%", info.getFromLevel())); + if (info.getFromLevel() > 1 && info.getUntilLevel() == -1) + message.append(Jobs.getLanguage().getMessage("command.info.help.levelFrom", "%levelFrom%", info.getFromLevel())); - if (info.getFromLevel() == 1 && info.getUntilLevel() != -1) - message.append(Jobs.getLanguage().getMessage("command.info.help.levelUntil", "%levelUntil%", info.getUntilLevel())); + if (info.getFromLevel() == 1 && info.getUntilLevel() != -1) + message.append(Jobs.getLanguage().getMessage("command.info.help.levelUntil", "%levelUntil%", info.getUntilLevel())); - message.append('\n'); - } - return message.toString(); + message.append('\n'); + } + return message.toString(); } /** @@ -395,46 +414,46 @@ public class JobsCommands implements CommandExecutor { * @return the message */ public String jobStatsMessage(JobProgression jobProg) { - boolean isMaxLevelReached = jobProg.getLevel() == jobProg.getJob().getMaxLevel(); - String path = "command.stats.output." + (isMaxLevelReached ? "max-level" - : "message"); + boolean isMaxLevelReached = jobProg.getLevel() == jobProg.getJob().getMaxLevel(); + String path = "command.stats.output." + (isMaxLevelReached ? "max-level" + : "message"); - Title title = Jobs.getTitleManager().getTitle(jobProg.getLevel(), jobProg.getJob().getName()); - String message = Jobs.getLanguage().getMessage(path, - "%joblevel%", jobProg.getLevelFormatted(), - "%jobname%", jobProg.getJob().getDisplayName(), - "%jobxp%", Math.round(jobProg.getExperience() * 100.0) / 100.0, - "%jobmaxxp%", jobProg.getMaxExperience(), - "%titlename%", title == null ? "Unknown" : title.getName()); - return " " + (isMaxLevelReached ? "" : jobProgressMessage(jobProg.getMaxExperience(), jobProg.getExperience())) + " " + message; + Title title = Jobs.getTitleManager().getTitle(jobProg.getLevel(), jobProg.getJob().getName()); + String message = Jobs.getLanguage().getMessage(path, + "%joblevel%", jobProg.getLevelFormatted(), + "%jobname%", jobProg.getJob().getDisplayName(), + "%jobxp%", Math.round(jobProg.getExperience() * 100.0) / 100.0, + "%jobmaxxp%", jobProg.getMaxExperience(), + "%titlename%", title == null ? "Unknown" : title.getName()); + return " " + (isMaxLevelReached ? "" : jobProgressMessage(jobProg.getMaxExperience(), jobProg.getExperience())) + " " + message; } private String pos = ChatColor.DARK_GREEN + "\u258F"; private String pros = ChatColor.YELLOW + "\u258F"; public String jobProgressMessage(double max, double current) { - if (current < 0) - current = 0; + if (current < 0) + current = 0; - if (max < current) - max = current; + if (max < current) + max = current; - if (max < 1) - max = 2; + if (max < 1) + max = 2; - StringBuilder message = new StringBuilder(); - int percentage = (int) ((current * 50.0) / max); - for (int i = 0; i < percentage; i++) { - message.append(pos); - } + StringBuilder message = new StringBuilder(); + int percentage = (int) ((current * 50.0) / max); + for (int i = 0; i < percentage; i++) { + message.append(pos); + } - if (50 - percentage < 0) - percentage = 50; + if (50 - percentage < 0) + percentage = 50; - for (int i = 0; i < 50 - percentage; i++) { - message.append(pros); - } - return message.toString(); + for (int i = 0; i < 50 - percentage; i++) { + message.append(pros); + } + return message.toString(); } /** @@ -443,15 +462,15 @@ public class JobsCommands implements CommandExecutor { * @return the message */ public String jobStatsMessageArchive(JobsPlayer jPlayer, JobProgression jobProg) { - int level = jPlayer.getLevelAfterRejoin(jobProg); - double exp = jPlayer.getExpAfterRejoin(jobProg, level); - int maxExperience = jobProg.getMaxExperience(level); + int level = jPlayer.getLevelAfterRejoin(jobProg); + double exp = jPlayer.getExpAfterRejoin(jobProg, level); + int maxExperience = jobProg.getMaxExperience(level); - String message = Jobs.getLanguage().getMessage("command.stats.output.message", - "%joblevel%", level, - "%jobname%", jobProg.getJob().getDisplayName(), - "%jobxp%", Math.round(exp * 100.0) / 100.0, - "%jobmaxxp%", maxExperience); - return " " + jobProgressMessage(maxExperience, exp) + " " + message; + String message = Jobs.getLanguage().getMessage("command.stats.output.message", + "%joblevel%", level, + "%jobname%", jobProg.getJob().getDisplayName(), + "%jobxp%", Math.round(exp * 100.0) / 100.0, + "%jobmaxxp%", maxExperience); + return " " + jobProgressMessage(maxExperience, exp) + " " + message; } } diff --git a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java index a87aaeb6..e8c00fdc 100644 --- a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -39,6 +39,7 @@ import com.gamingmesh.jobs.CMILib.CMIEnchantment; import com.gamingmesh.jobs.container.CurrencyLimit; import com.gamingmesh.jobs.container.CurrencyType; +import net.Zrips.CMILib.Container.CMIArray; import net.Zrips.CMILib.Container.CMIList; import net.Zrips.CMILib.Equations.Parser; import net.Zrips.CMILib.FileHandler.ConfigReader; @@ -50,6 +51,8 @@ public class GeneralConfigManager { public List BroadcastingLevelUpLevels = new ArrayList<>(); public List DisabledWorldsList = new ArrayList<>(); + public List helpPageBehavior = new ArrayList<>(); + public final Map> whiteListedItems = new HashMap<>(); private final Map currencyLimitUse = new HashMap<>(); @@ -1041,6 +1044,27 @@ public class GeneralConfigManager { c.addComment("JobsGUI.SkipAmount", "Defines by how many slots we need to skip after group"); JobsGUISkipAmount = c.get("JobsGUI.SkipAmount", 2); + c.addComment("Commands.Jobs", "What should happen when performing clean /jobs command", "Options:", + "Default - behaves like before and will open jobs help page with list of commands player can access", + "Browse - will open jobs browse GUI where player can check existing jobs and their actions", + "Last option is to define command you want to perform, use [playerName] variable to replace it with players name who performed it. Multiple commands can be provided too. Commands will be performed from console."); + + + helpPageBehavior.clear(); + if (c.getC().isList("Commands.Jobs")) { + helpPageBehavior.addAll(c.get("Commands.Jobs", Arrays.asList("Default"))); + } else { + helpPageBehavior.add(c.get("Commands.Jobs", "Default")); + } + if (!helpPageBehavior.isEmpty()) { + if (helpPageBehavior.size() == 1 && helpPageBehavior.get(0).equalsIgnoreCase("Default")) + helpPageBehavior.clear(); + if (helpPageBehavior.size() == 1 && helpPageBehavior.get(0).equalsIgnoreCase("Browse")) { + helpPageBehavior.clear(); + helpPageBehavior.add("browse"); + } + } + c.addComment("Commands.PageRow.JobsTop.AmountToShow", "Defines amount of players to be shown in one page for /jobs top & /jobs gtop"); JobsTopAmount = c.get("Commands.PageRow.JobsTop.AmountToShow", 15); c.addComment("Commands.PageRow.Placeholders.AmountToShow", "Defines amount of placeholders to be shown in one page for /jobs placeholders");