From b29da9ceadd401afafa0907754dff4bb29e3ed0f Mon Sep 17 00:00:00 2001 From: Narimm Date: Fri, 28 Dec 2018 08:00:05 +1000 Subject: [PATCH] Add a feature that will decrease earnings at cap by a factored amount using the equation (100/((1/factor*percentOver*percentOver)+1)) ie a pop growth curve. --- src/main/java/com/gamingmesh/jobs/Jobs.java | 2737 +++++++++-------- .../jobs/config/GeneralConfigManager.java | 2077 ++++++------- .../jobs/config/LanguageManager.java | 1373 ++++----- .../gamingmesh/jobs/container/JobsPlayer.java | 1934 ++++++------ .../gamingmesh/jobs/economy/PaymentData.java | 287 +- 5 files changed, 4218 insertions(+), 4190 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index a699bd0d..0dc1cd5f 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -1,1366 +1,1371 @@ -/** - * Jobs Plugin for Bukkit - * Copyright (C) 2011 Zak Ford - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.gamingmesh.jobs; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; -import java.util.UUID; -import java.util.WeakHashMap; -import java.util.logging.Logger; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.block.Block; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.java.JavaPlugin; - -import com.gamingmesh.jobs.CMILib.ActionBarTitleMessages; -import com.gamingmesh.jobs.CMILib.ItemManager; -import com.gamingmesh.jobs.CMILib.RawMessage; -import com.gamingmesh.jobs.CMILib.VersionChecker; -import com.gamingmesh.jobs.Gui.GuiManager; -import com.gamingmesh.jobs.MyPet.MyPetManager; -import com.gamingmesh.jobs.MythicMobs.MythicMobInterface; -import com.gamingmesh.jobs.MythicMobs.MythicMobs2; -import com.gamingmesh.jobs.MythicMobs.MythicMobs4; -import com.gamingmesh.jobs.Placeholders.Placeholder; -import com.gamingmesh.jobs.Placeholders.PlaceholderAPIHook; -import com.gamingmesh.jobs.Signs.SignUtil; -import com.gamingmesh.jobs.WorldGuard.WorldGuardManager; -import com.gamingmesh.jobs.api.JobsExpGainEvent; -import com.gamingmesh.jobs.commands.JobsCommands; -import com.gamingmesh.jobs.config.BlockProtectionManager; -import com.gamingmesh.jobs.config.BossBarManager; -import com.gamingmesh.jobs.config.ConfigManager; -import com.gamingmesh.jobs.config.ExploreManager; -import com.gamingmesh.jobs.config.GeneralConfigManager; -import com.gamingmesh.jobs.config.LanguageManager; -import com.gamingmesh.jobs.config.NameTranslatorManager; -import com.gamingmesh.jobs.config.RestrictedAreaManager; -import com.gamingmesh.jobs.config.RestrictedBlockManager; -import com.gamingmesh.jobs.config.ScheduleManager; -import com.gamingmesh.jobs.config.ShopManager; -import com.gamingmesh.jobs.config.TitleManager; -import com.gamingmesh.jobs.config.YmlMaker; -import com.gamingmesh.jobs.container.ActionInfo; -import com.gamingmesh.jobs.container.ActionType; -import com.gamingmesh.jobs.container.ArchivedJobs; -import com.gamingmesh.jobs.container.BlockProtection; -import com.gamingmesh.jobs.container.Boost; -import com.gamingmesh.jobs.container.CurrencyType; -import com.gamingmesh.jobs.container.DBAction; -import com.gamingmesh.jobs.container.FastPayment; -import com.gamingmesh.jobs.container.Job; -import com.gamingmesh.jobs.container.JobInfo; -import com.gamingmesh.jobs.container.JobProgression; -import com.gamingmesh.jobs.container.JobsPlayer; -import com.gamingmesh.jobs.container.Log; -import com.gamingmesh.jobs.container.PlayerInfo; -import com.gamingmesh.jobs.container.PlayerPoints; -import com.gamingmesh.jobs.container.QuestProgression; -import com.gamingmesh.jobs.dao.JobsClassLoader; -import com.gamingmesh.jobs.dao.JobsDAO; -import com.gamingmesh.jobs.dao.JobsDAOData; -import com.gamingmesh.jobs.dao.JobsManager; -import com.gamingmesh.jobs.economy.BufferedEconomy; -import com.gamingmesh.jobs.economy.BufferedPayment; -import com.gamingmesh.jobs.economy.Economy; -import com.gamingmesh.jobs.economy.PaymentData; -import com.gamingmesh.jobs.i18n.Language; -import com.gamingmesh.jobs.listeners.JobsListener; -import com.gamingmesh.jobs.listeners.JobsPaymentListener; -import com.gamingmesh.jobs.listeners.McMMOlistener; -import com.gamingmesh.jobs.listeners.PistonProtectionListener; -import com.gamingmesh.jobs.selection.SelectionManager; -import com.gamingmesh.jobs.stuff.CMIScoreboardManager; -import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling; -import com.gamingmesh.jobs.stuff.Loging; -import com.gamingmesh.jobs.stuff.PageInfo; -import com.gamingmesh.jobs.stuff.TabComplete; -import com.gamingmesh.jobs.tasks.BufferedPaymentThread; -import com.gamingmesh.jobs.tasks.DatabaseSaveThread; - -public class Jobs extends JavaPlugin { - private static String version = ""; - private static PlayerManager pManager = null; - private static JobsCommands cManager = null; - private static Language lManager = null; - private static LanguageManager lmManager = null; - private static SignUtil signManager = null; - private CMIScoreboardManager CMIScoreboardManager = null; - private static ScheduleManager scheduleManager = null; - private static NameTranslatorManager NameTranslatorManager = null; - private static GuiManager GUIManager = null; - private static ExploreManager exploreManager = null; - private static TitleManager titleManager = null; - private static RestrictedBlockManager RBManager = null; - private static RestrictedAreaManager RAManager = null; - private static BossBarManager BBManager = null; - private static ShopManager shopManager = null; - private static Loging loging = null; - private static BlockProtectionManager BpManager = null; - - private static JobsManager DBManager = null; - - private static PistonProtectionListener PistonProtectionListener = null; - private static McMMOlistener McMMOlistener = null; - - private static MythicMobInterface MythicManager = null; - private static MyPetManager myPetManager = null; - private static WorldGuardManager worldGuardManager = null; - - private static ConfigManager configManager = null; - private static GeneralConfigManager GconfigManager = null; - - private static Reflections reflections = null; - - private static Logger pLogger = null; - private static JobsClassLoader classLoader = null; - private static JobsDAO dao = null; - private static List jobs = null; - private static Job noneJob = null; - private static WeakHashMap usedSlots = new WeakHashMap<>(); - public static WeakHashMap actionbartoggle = new WeakHashMap<>(); - public static WeakHashMap BossBartoggle = new WeakHashMap<>(); -// public static WeakHashMap GlobalBoost = new WeakHashMap(); - private static BufferedEconomy economy = null; - private static PermissionHandler permissionHandler = null; - private static PermissionManager permissionManager = null; - -// private static ItemManager itemManager; - - public static BufferedPaymentThread paymentThread = null; - private static DatabaseSaveThread saveTask = null; - - public static HashMap FastPayment = new HashMap<>(); - - private static NMS nms = null; - - private static ActionBarTitleMessages actionbar = null; - - protected static VersionChecker versionCheckManager = null; - - protected static SelectionManager smanager = null; - - public void setMcMMOlistener() { - McMMOlistener = new McMMOlistener(this); - } - - public static McMMOlistener getMcMMOlistener() { - return McMMOlistener; - } - - public void setPistonProtectionListener() { - PistonProtectionListener = new PistonProtectionListener(); - } - - public static PistonProtectionListener getPistonProtectionListener() { - return PistonProtectionListener; - } - - public void setMyPetManager() { - myPetManager = new MyPetManager(); - } - - public static MyPetManager getMyPetManager() { - return myPetManager; - } - - private Placeholder Placeholder; - private boolean PlaceholderAPIEnabled = false; - - public Placeholder getPlaceholderAPIManager() { - if (Placeholder == null) - Placeholder = new Placeholder(this); - return Placeholder; - } - - private boolean setupPlaceHolderAPI() { - if (!getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) - return false; - if ((new PlaceholderAPIHook(this)).hook()) - consoleMsg("&e[Jobs] PlaceholderAPI hooked."); - return true; - } - - public static WorldGuardManager getWorldGuardManager() { - return worldGuardManager; - } - - public void setMythicManager() { - try { - Class.forName("net.elseland.xikage.MythicMobs.API.MythicMobsAPI"); - MythicManager = new MythicMobs2(this); - } catch (ClassNotFoundException e) { - try { - Class.forName("io.lumine.xikage.mythicmobs.api.bukkit.BukkitAPIHelper"); - MythicManager = new MythicMobs4(this); - } catch (ClassNotFoundException ex) { - } - } - if (MythicManager != null) - consoleMsg("&e[Jobs] MythicMobs detected."); - } - - private boolean setWorldGuard() { - Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard"); - if (plugin != null) { - worldGuardManager = new WorldGuardManager(); - consoleMsg("&e[Jobs] WorldGuard detected."); - return true; - } - return false; - } - - public static MythicMobInterface getMythicManager() { - return MythicManager; - } - - public void setLoging() { - loging = new Loging(); - } - - public static Loging getLoging() { - return loging; - } - - public void setBpManager() { - BpManager = new BlockProtectionManager(); - } - - public static BlockProtectionManager getBpManager() { - return BpManager; - } - - public static Reflections getReflections() { - if (reflections == null) - reflections = new Reflections(); - return reflections; - } - - public static JobsManager getDBManager() { - if (DBManager == null) - DBManager = new JobsManager(instance); - return DBManager; - } - - public static void setShopManager() { - shopManager = new ShopManager(); - } - - public static ShopManager getShopManager() { - return shopManager; - } - - public void setConfigManager() { - configManager = new ConfigManager(); - } - - public static ConfigManager getConfigManager() { - return configManager; - } - - public void setGCManager() { - GconfigManager = new GeneralConfigManager(this); - } - - public static GeneralConfigManager getGCManager() { - return GconfigManager; - } - - public void setActionBar() { - actionbar = new ActionBarTitleMessages(); - } - - public static ActionBarTitleMessages getActionBar() { - return actionbar; - } - - public static void setNms(NMS nms) { - Jobs.nms = nms; - } - - public static NMS getNms() { - return nms; - } - - /** - * Returns player manager - * @return the player manager - */ - public static PlayerManager getPlayerManager() { - return pManager; - } - - public void setPlayerManager() { - pManager = new PlayerManager(); - } - - public static void setRestrictedBlockManager() { - RBManager = new RestrictedBlockManager(); - } - - public static RestrictedBlockManager getRestrictedBlockManager() { - return RBManager; - } - - public static void setRestrictedAreaManager() { - RAManager = new RestrictedAreaManager(); - } - - public static RestrictedAreaManager getRestrictedAreaManager() { - return RAManager; - } - - public static void setTitleManager() { - titleManager = new TitleManager(); - } - - public static TitleManager gettitleManager() { - return titleManager; - } - - public void setBBManager() { - BBManager = new BossBarManager(this); - } - - public static BossBarManager getBBManager() { - return BBManager; - } - - public static WeakHashMap getActionbarToggleList() { - return actionbartoggle; - } - - public static WeakHashMap getBossBarToggleList() { - return BossBartoggle; - } - - /** - * Returns schedule manager - * @return the schedule manager - */ - public static ScheduleManager getScheduleManager() { - return scheduleManager; - } - - public static void setScheduleManager(Jobs plugin) { - scheduleManager = new ScheduleManager(plugin); - } - - public static NameTranslatorManager getNameTranslatorManager() { - return NameTranslatorManager; - } - - public static void setNameTranslatorManager() { - NameTranslatorManager = new NameTranslatorManager(); - } - - public static GuiManager getGUIManager() { - return GUIManager; - } - - public void setGUIManager() { - GUIManager = new GuiManager(); - } - - public static JobsCommands getCommandManager() { - return cManager; - } - - public void setCommandManager() { - cManager = new JobsCommands(this); - } - - public static ExploreManager getExplore() { - return exploreManager; - } - - public void setExplore() { - exploreManager = new ExploreManager(); - } - - /** - * Returns scoreboard manager - * @return the scoreboard manager - */ - public CMIScoreboardManager getCMIScoreboardManager() { - if (CMIScoreboardManager == null) - CMIScoreboardManager = new CMIScoreboardManager(this); - return CMIScoreboardManager; - } - - protected static Jobs instance; - - public static Jobs getInstance() { - return instance; - } - - /** - * Returns sign manager - * @return the sign manager - */ - public static SignUtil getSignUtil() { - return signManager; - } - - public static void setSignUtil(Jobs plugin) { - signManager = new SignUtil(plugin); - } - - /** - * Returns language manager - * @return the language manager - */ - public static Language getLanguage() { - return lManager; - } - - public void setLanguage() { - lManager = new Language(this); - } - - public static LanguageManager getLanguageManager() { - return lmManager; - } - - public static void setLanguageManager() { - lmManager = new LanguageManager(); - } - - /** - * Sets the plugin logger - */ - public void setPluginLogger(Logger pLogger) { - Jobs.pLogger = pLogger; - } - - /** - * Retrieves the plugin logger - * @return the plugin logger - */ - public static Logger getPluginLogger() { - return pLogger; - } - - public static File getFolder() { - File folder = Jobs.getInstance().getDataFolder(); - if (!folder.exists()) - folder.mkdirs(); - return folder; - } - - /** - * Sets the Data Access Object - * @param dao - the DAO - */ - public static void setDAO(JobsDAO dao) { - Jobs.dao = dao; - } - - /** - * Get the Data Access Object - * @return the DAO - */ - public static JobsDAO getJobsDAO() { - return dao; - } - - /** - * Sets the list of jobs - * @param jobs - list of jobs - */ - public static void setJobs(List jobs) { - Jobs.jobs = jobs; - } - - /** - * Retrieves the list of active jobs - * @return list of jobs - */ - public static List getJobs() { - return Collections.unmodifiableList(jobs); - } - - /** - * Sets the none job - * @param noneJob - the none job - */ - public static void setNoneJob(Job noneJob) { - Jobs.noneJob = noneJob; - } - - /** - * Retrieves the "none" job - * @return the none job - */ - public static Job getNoneJob() { - return noneJob; - } - - /** - * Function to return the job information that matches the jobName given - * @param jobName - the ame of the job given - * @return the job that matches the name - */ - public static Job getJob(String jobName) { - for (Job job : jobs) { - if (job.getName().equalsIgnoreCase(jobName)) - return job; - } - return null; - } - - /** - * Executes startup - * @throws IOException - */ - public void startup() { - try { - reload(); - } catch (IOException e1) { - e1.printStackTrace(); - } - - loadAllPlayersData(); - // add all online players - for (Player online : Bukkit.getServer().getOnlinePlayers()) { - pManager.playerJoin(online); - } - } - - public static void loadAllPlayersData() { - long time = System.currentTimeMillis(); - // Cloning to avoid issues - HashMap temp = new HashMap<>(pManager.getPlayersInfoUUIDMap()); - HashMap> playersJobs = dao.getAllJobs(); - HashMap playersPoints = dao.getAllPoints(); - HashMap> playersLogs = dao.getAllLogs(); - HashMap playersArchives = dao.getAllArchivedJobs(); - HashMap playersLimits = dao.loadPlayerLimits(); - Iterator> it = temp.entrySet().iterator(); - while (it.hasNext()) { - Entry one = it.next(); - try { - int id = one.getValue().getID(); - JobsPlayer jPlayer = pManager.getJobsPlayerOffline( - one.getValue(), - playersJobs.get(id), - playersPoints.get(id), - playersLogs.get(id), - playersArchives.get(id), - playersLimits.get(id)); - if (jPlayer == null) - continue; - pManager.addPlayerToCache(jPlayer); - } catch (Exception e) { - e.printStackTrace(); - } - } - - dao.getMap().clear(); - if (pManager.getPlayersCache().size() != 0) - consoleMsg("&e[Jobs] Preloaded " + pManager.getPlayersCache().size() + " players data in " + ((int) (((System.currentTimeMillis() - time) - / 1000d) * 100) / 100D)); - } - - /** - * Reloads all data - * @throws IOException - */ - public static void reload() throws IOException { - - if (saveTask != null) { - saveTask.shutdown(); - saveTask = null; - } - - if (paymentThread != null) { - paymentThread.shutdown(); - paymentThread = null; - } - smanager = new SelectionManager(); - if (dao != null) { - dao.closeConnections(); - } - - GconfigManager.reload(); - lManager.reload(); - configManager.reload(); - FurnaceBrewingHandling.load(); - usedSlots.clear(); - for (Job job : jobs) { - usedSlots.put(job, dao.getSlotsTaken(job)); - } - pManager.reload(); - permissionHandler.registerPermissions(); - - // set the system to auto save - if (GconfigManager.getSavePeriod() > 0) { - saveTask = new DatabaseSaveThread(GconfigManager.getSavePeriod()); - saveTask.start(); - } - - // schedule payouts to buffered payments - paymentThread = new BufferedPaymentThread(GconfigManager.getEconomyBatchDelay()); - paymentThread.start(); - - dao.loadPlayerData(); - - // Schedule - scheduleManager.load(); - scheduleManager.start(); - - permissionManager = new PermissionManager(); - } - - /** - * Executes clean shutdown - */ - public static void shutdown() { - if (saveTask != null) - saveTask.shutdown(); - - if (paymentThread != null) - paymentThread.shutdown(); - - pManager.saveAll(); - - if (dao != null) { - dao.closeConnections(); - } - } - - /** - * Executes close connections - */ - public static void ChangeDatabase() { - DBManager.switchDataBase(); - pManager.reload(); - } - - /** - * Function to get the number of slots used on the server for this job - * @param job - the job - * @return the number of slots - */ - public static int getUsedSlots(Job job) { - if (usedSlots.containsKey(job)) - return usedSlots.get(job); - return 0; - } - - /** - * Function to increase the number of used slots for a job - * @param job - the job someone is taking - */ - public static void takeSlot(Job job) { - if (usedSlots.containsKey(job)) - usedSlots.put(job, usedSlots.get(job) + 1); - } - - /** - * Function to decrease the number of used slots for a job - * @param job - the job someone is leaving - */ - public static void leaveSlot(Job job) { - if (usedSlots.containsKey(job)) - usedSlots.put(job, usedSlots.get(job) - 1); - } - - /** - * Returns the jobs classloader - * @return the classloader - */ - public static JobsClassLoader getJobsClassloader() { - return classLoader; - } - - public void setJobsClassloader() { - classLoader = new JobsClassLoader(this); - } - - /** - * Sets the permission handler - * @param h - the permission handler - */ - public void setPermissionHandler(PermissionHandler permissionHandler) { - Jobs.permissionHandler = permissionHandler; - } - - /** - * Gets the permission handler - * @return the permission handler - */ - public static PermissionHandler getPermissionHandler() { - return permissionHandler; - } - - public static PermissionManager getPermissionManager() { - return permissionManager; - } - -// public static ItemManager getItemManager() { -// return itemManager; -// } - - /** - * Sets the economy handler - * @param eco - the economy handler - */ - public static void setEconomy(Jobs plugin, Economy eco) { - economy = new BufferedEconomy(plugin, eco); - } - - /** - * Gets the economy handler - * @return the economy handler - */ - public static BufferedEconomy getEconomy() { - return economy; - } - - /** - * Gets the version check manager - * @return the version check manager - */ - public static VersionChecker getVersionCheckManager() { - return versionCheckManager; - } - - @Override - public void onEnable() { - - instance = this; - setEnabled(true); - - versionCheckManager = new VersionChecker(this); - - ItemManager.load(); - - version = versionCheckManager.getVersion().getShortVersion(); - -// itemManager = new ItemManager(this); - - try { - Class nmsClass; - nmsClass = Class.forName("com.gamingmesh.jobs.nmsUtil." + version); - if (NMS.class.isAssignableFrom(nmsClass)) { - setNms((NMS) nmsClass.getConstructor().newInstance()); - } else { - System.out.println("Something went wrong, please note down version and contact author, version: " + version); - setEnabled(false); - } - } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException - | SecurityException e) { - System.out.println("Your server version is not compatible with this plugins version! Plugin will be disabled: " + version); - setEnabled(false); - e.printStackTrace(); - return; - } - try { - if (setupPlaceHolderAPI()) { - consoleMsg("&ePlaceholderAPI was found - Enabling capabilities."); - PlaceholderAPIEnabled = true; - } - } catch (Exception e) { - e.printStackTrace(); - } - - try { - - setActionBar(); - YmlMaker jobConfig = new YmlMaker(this, "jobConfig.yml"); - jobConfig.saveDefaultConfig(); - - YmlMaker jobSchedule = new YmlMaker(this, "schedule.yml"); - jobSchedule.saveDefaultConfig(); - - YmlMaker jobShopItems = new YmlMaker(this, "shopItems.yml"); - jobShopItems.saveDefaultConfig(); - - YmlMaker restrictedBlocks = new YmlMaker(this, "restrictedBlocks.yml"); - restrictedBlocks.saveDefaultConfig(); - - setPermissionHandler(new PermissionHandler(this)); - setPluginLogger(getLogger()); - setJobsClassloader(); - setPlayerManager(); - setLanguage(); - setGUIManager(); - setExplore(); - setBBManager(); - setLoging(); - setGCManager(); - setConfigManager(); - setCommandManager(); - setBpManager(); - - getCommand("jobs").setExecutor(cManager); - this.getCommand("jobs").setTabCompleter(new TabComplete()); - - startup(); - - if (GconfigManager.SignsEnabled) { - YmlMaker jobSigns = new YmlMaker(this, "Signs.yml"); - jobSigns.saveDefaultConfig(); - } - - // register the listeners - getServer().getPluginManager().registerEvents(new JobsListener(this), this); - getServer().getPluginManager().registerEvents(new JobsPaymentListener(this), this); - - setMcMMOlistener(); - if (McMMOlistener.CheckmcMMO()) - getServer().getPluginManager().registerEvents(McMMOlistener, this); - - setMyPetManager(); - setWorldGuard(); - - setMythicManager(); - if (MythicManager != null && MythicManager.Check() && GconfigManager.MythicMobsEnabled) - MythicManager.registerListener(); - - setPistonProtectionListener(); - if (GconfigManager.useBlockProtection) - getServer().getPluginManager().registerEvents(PistonProtectionListener, this); - - // register economy - Bukkit.getScheduler().runTask(this, new HookEconomyTask(this)); - - // all loaded properly. - - dao.loadBlockProtection(); - exploreManager.load(); - - consoleMsg("&e[Jobs] Plugin has been enabled successfully."); - - cManager.fillCommands(); - - } catch (Exception e) { - e.printStackTrace(); - System.out.println("There was some issues when starting plugin. Please contact dev about this. Plugin will be disabled."); - setEnabled(false); - } - } - - @Override - public void onDisable() { - try { - GUIManager.CloseInventories(); - shopManager.CloseInventories(); - dao.saveExplore(); - dao.saveBlockProtection(); - FurnaceBrewingHandling.save(); - } catch (Exception e) { - e.printStackTrace(); - } - shutdown(); - consoleMsg("&e[Jobs] &2Plugin has been disabled successfully."); - setEnabled(false); - } - - @SuppressWarnings("unused") - @Deprecated - private static void checkDailyQuests(JobsPlayer jPlayer, JobProgression prog, ActionInfo info) { - checkDailyQuests(jPlayer, prog.getJob(), info); - } - - private static void checkDailyQuests(JobsPlayer jPlayer, Job job, ActionInfo info) { - if (!job.getQuests().isEmpty()) { - List q = jPlayer.getQuestProgressions(job, info.getType()); - for (QuestProgression one : q) { - if (one != null) - one.processQuest(jPlayer, info); - } - } - } - - /** - * Performed an action - * - * Give correct experience and income - * @param jPlayer - the player - * @param action - the action - * @param multiplier - the payment/xp multiplier - */ - - public static void action(JobsPlayer jPlayer, ActionInfo info) { - action(jPlayer, info, null, null, null); - } - - public static void action(JobsPlayer jPlayer, ActionInfo info, Block block) { - action(jPlayer, info, block, null, null); - } - - public static void action(JobsPlayer jPlayer, ActionInfo info, Entity ent) { - action(jPlayer, info, null, ent, null); - } - - public static void action(JobsPlayer jPlayer, ActionInfo info, Entity ent, LivingEntity victim) { - action(jPlayer, info, null, ent, victim); - } - - public static void action(JobsPlayer jPlayer, ActionInfo info, Block block, Entity ent, LivingEntity victim) { - - if (jPlayer == null) - return; - - List progression = jPlayer.getJobProgression(); - int numjobs = progression.size(); - // no job - - if (!isBpOk(jPlayer, info, block, true)) - return; - - if (numjobs == 0) { - - if (noneJob == null) - return; - JobInfo jobinfo = noneJob.getJobInfo(info, 1); - - checkDailyQuests(jPlayer, noneJob, info); - - if (jobinfo == null) - return; - - Double income = jobinfo.getIncome(1, numjobs); - Double pointAmount = jobinfo.getPoints(1, numjobs); - - if (income == 0D && pointAmount == 0D) - return; - - Boost boost = pManager.getFinalBonus(jPlayer, Jobs.getNoneJob()); - - // Calculate income - - if (income != 0D) { - income = income + (income * boost.getFinal(CurrencyType.MONEY)); - if (GconfigManager.useMinimumOveralPayment && income > 0) { - double maxLimit = income * GconfigManager.MinimumOveralPaymentLimit; - if (income < maxLimit) - income = maxLimit; - } - } - - // Calculate points - - if (pointAmount != 0D) { - pointAmount = pointAmount + (pointAmount * boost.getFinal(CurrencyType.POINTS)); - if (GconfigManager.useMinimumOveralPoints && pointAmount > 0) { - double maxLimit = pointAmount * GconfigManager.MinimumOveralPaymentLimit; - if (pointAmount < maxLimit) - pointAmount = maxLimit; - } - } - - if (!jPlayer.isUnderLimit(CurrencyType.MONEY, income)) { - 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) - BpManager.remove(block); - - if (pointAmount != 0D) - jPlayer.setSaved(false); - - economy.pay(jPlayer, income, pointAmount, 0.0); - - if (GconfigManager.LoggingUse) { - HashMap amounts = new HashMap<>(); - amounts.put(CurrencyType.MONEY, income); - loging.recordToLog(jPlayer, info, amounts); - } - - } else { - for (JobProgression prog : progression) { - int level = prog.getLevel(); - - JobInfo jobinfo = prog.getJob().getJobInfo(info, level); - - checkDailyQuests(jPlayer, prog.getJob(), info); - - if (jobinfo == null) - continue; - - Double income = jobinfo.getIncome(level, numjobs); - Double pointAmount = jobinfo.getPoints(level, numjobs); - Double expAmount = jobinfo.getExperience(level, numjobs); - - 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 = expAmount.intValue(); - double remainder = expAmount.doubleValue() - expInt; - if (Math.abs(remainder) > Math.random()) { - if (expAmount.doubleValue() < 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 = pManager.getFinalBonus(jPlayer, prog.getJob(), ent, victim); - - // 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.MinimumOveralPaymentLimit; - if (pointAmount < maxLimit) - pointAmount = maxLimit; - } - } - - // Calculate exp - expAmount = boost.getFinalAmount(CurrencyType.EXP, expAmount); - - if (GconfigManager.useMinimumOveralPayment && expAmount > 0) { - double maxLimit = expAmount * GconfigManager.MinimumOveralPaymentLimit; - if (expAmount < maxLimit) - expAmount = maxLimit; - } - - if (!jPlayer.isUnderLimit(CurrencyType.MONEY, income)) { - income = 0D; - if (GconfigManager.getLimit(CurrencyType.MONEY).getStopWith().contains(CurrencyType.EXP)) - expAmount = 0D; - if (GconfigManager.getLimit(CurrencyType.MONEY).getStopWith().contains(CurrencyType.POINTS)) - pointAmount = 0D; - } - - if (!jPlayer.isUnderLimit(CurrencyType.EXP, expAmount)) { - expAmount = 0D; - if (GconfigManager.getLimit(CurrencyType.EXP).getStopWith().contains(CurrencyType.MONEY)) - income = 0D; - if (GconfigManager.getLimit(CurrencyType.EXP).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 (GconfigManager.getLimit(CurrencyType.POINTS).getStopWith().contains(CurrencyType.EXP)) - expAmount = 0D; - } - - if (income == 0D && pointAmount == 0D && expAmount == 0D) - continue; - - try { - if (expAmount != 0D && GconfigManager.BossBarEnabled) - if (GconfigManager.BossBarShowOnEachAction) - BBManager.ShowJobProgression(jPlayer, prog); - else - jPlayer.getUpdateBossBarFor().add(prog.getJob().getName()); - } catch (Exception e) { - consoleMsg("&c[Jobs] Some issues with boss bar feature accured, try disabling it to avoid it."); - } - - // JobsPayment event - JobsExpGainEvent JobsExpGainEvent = new JobsExpGainEvent(jPlayer.getPlayer(), prog.getJob(), expAmount); - Bukkit.getServer().getPluginManager().callEvent(JobsExpGainEvent); - // If event is canceled, don't do anything - if (JobsExpGainEvent.isCancelled()) - expAmount = 0D; - else - expAmount = JobsExpGainEvent.getExp(); - - FastPayment.clear(); - FastPayment.put(jPlayer.getPlayerUUID(), new FastPayment(jPlayer, info, new BufferedPayment(jPlayer.getPlayer(), income, pointAmount, expAmount), prog - .getJob())); - - economy.pay(jPlayer, income, pointAmount, expAmount); - int oldLevel = prog.getLevel(); - - if (GconfigManager.LoggingUse) { - HashMap amounts = new HashMap<>(); - amounts.put(CurrencyType.MONEY, income); - amounts.put(CurrencyType.EXP, expAmount); - amounts.put(CurrencyType.POINTS, pointAmount); - loging.recordToLog(jPlayer, info, amounts); - } - - if (prog.addExperience(expAmount)) - pManager.performLevelUp(jPlayer, prog.getJob(), oldLevel); - } - - //need to update bp - if (block != null) { - BlockProtection bp = BpManager.getBp(block.getLocation()); - if (bp != null) - bp.setPaid(true); - } - } - } - - private static boolean isBpOk(JobsPlayer player, ActionInfo info, Block block, boolean inform) { - 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; - } - BlockProtection bp = BpManager.getBp(block.getLocation()); - if (bp != null) { - Long time = bp.getTime(); - Integer cd = BpManager.getBlockDelayTime(block); - - if (time == -1L) { - BpManager.add(block, cd); - return false; - } - if ((time < System.currentTimeMillis()) && (bp.getAction() != DBAction.DELETE)) { - BpManager.remove(block); - return true; - } - if (time > System.currentTimeMillis() || bp.isPaid() && bp.getAction() != DBAction.DELETE) { - int sec = Math.round((time - System.currentTimeMillis()) / 1000L); - if (inform) { - if (player.canGetPaid(info)) - actionbar.send(player.getPlayer(), lManager.getMessage("message.blocktimer", "[time]", sec)); - } - return false; - } - BpManager.add(block, cd); - if ((cd == null || cd == 0) && GconfigManager.useGlobalTimer) { - BpManager.add(block, GconfigManager.globalblocktimer); - } - } else if (GconfigManager.useGlobalTimer) { - BpManager.add(block, GconfigManager.globalblocktimer); - } - } else if (info.getType() == ActionType.PLACE) { - BlockProtection bp = BpManager.getBp(block.getLocation()); - if (bp != null) { - Long time = bp.getTime(); - Integer cd = BpManager.getBlockDelayTime(block); - - if (time != -1L) { - if (time < System.currentTimeMillis() && bp.getAction() != DBAction.DELETE) { - BpManager.add(block, cd); - return true; - } - if (time > System.currentTimeMillis() || bp.isPaid() && bp.getAction() != DBAction.DELETE) { - int sec = Math.round((time - System.currentTimeMillis()) / 1000L); - if (inform) { - if (player.canGetPaid(info)) - actionbar.send(player.getPlayer(), lManager.getMessage("message.blocktimer", "[time]", sec)); - } - BpManager.add(block, cd); - return false; - } - } else if (bp.isPaid().booleanValue() && bp.getTime() == -1L && cd != null && cd == -1) { - BpManager.add(block, cd); - return false; - } else - BpManager.add(block, cd); - } else - BpManager.add(block, BpManager.getBlockDelayTime(block)); - } - - return true; - } - - private static int getPlayerExperience(Player player) { - int bukkitExp = (ExpToLevel(player.getLevel()) + Math.round(deltaLevelToExp(player.getLevel()) * player.getExp())); - return bukkitExp; - } - - // total xp calculation based by lvl - private static int ExpToLevel(int level) { - if (version.equals("1_7")) { - 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.equals("1_7")) { - 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) { - // JobsPayment event - JobsExpGainEvent JobsExpGainEvent = new JobsExpGainEvent(payment.getOfflinePlayer(), job, payment.getExp()); - Bukkit.getServer().getPluginManager().callEvent(JobsExpGainEvent); - // If event is canceled, don't do anything - if (JobsExpGainEvent.isCancelled()) - return; - - if (!jPlayer.isUnderLimit(CurrencyType.MONEY, payment.getAmount())) - return; - if (!jPlayer.isUnderLimit(CurrencyType.EXP, payment.getExp())) - return; - if (!jPlayer.isUnderLimit(CurrencyType.POINTS, payment.getPoints())) - return; - - economy.pay(jPlayer, payment.getAmount(), payment.getPoints(), payment.getExp()); - - JobProgression prog = jPlayer.getJobProgression(job); - - int oldLevel = prog.getLevel(); - - if (GconfigManager.LoggingUse) { - HashMap amounts = new HashMap<>(); - amounts.put(CurrencyType.MONEY, payment.getAmount()); - amounts.put(CurrencyType.EXP, payment.getExp()); - amounts.put(CurrencyType.POINTS, payment.getPoints()); - loging.recordToLog(jPlayer, info, amounts); - } - - if (prog.addExperience(payment.getExp())) - pManager.performLevelUp(jPlayer, prog.getJob(), oldLevel); - } - - public static void consoleMsg(String msg) { - Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', msg)); - } - - public static SelectionManager getSelectionManager() { - return smanager; - } - - public static boolean hasPermission(Object sender, String perm, boolean rawEnable) { - if (sender instanceof Player) { - if (((Player) sender).hasPermission(perm)) - return true; - if (!rawEnable) { - ((Player) sender).sendMessage(lManager.getMessage("general.error.permission")); - return false; - } - RawMessage rm = new RawMessage(); - rm.add(lManager.getMessage("general.error.permission"), "&2" + perm); - rm.show((Player) sender); - return false; - } - return true; - } - - public void ShowPagination(CommandSender sender, PageInfo pi, String cmd) { - ShowPagination(sender, pi.getTotalPages(), pi.getCurrentPage(), cmd, null); - } - - public void ShowPagination(CommandSender sender, PageInfo pi, String cmd, String pagePref) { - ShowPagination(sender, pi.getTotalPages(), pi.getCurrentPage(), cmd, pagePref); - } - - public void ShowPagination(CommandSender sender, int pageCount, int CurrentPage, String cmd) { - ShowPagination(sender, pageCount, CurrentPage, cmd, null); - } - - public void ShowPagination(CommandSender sender, int pageCount, int CurrentPage, String cmd, String pagePref) { - if (!(sender instanceof Player)) - return; - if (!cmd.startsWith("/")) - cmd = "/" + cmd; - if (pageCount == 1) - return; - String pagePrefix = pagePref == null ? "" : pagePref; - int NextPage = CurrentPage + 1; - NextPage = CurrentPage < pageCount ? NextPage : CurrentPage; - int Prevpage = CurrentPage - 1; - Prevpage = CurrentPage > 1 ? Prevpage : CurrentPage; - - RawMessage rm = new RawMessage(); - rm.add((CurrentPage > 1 ? lManager.getMessage("command.help.output.prevPage") : lManager.getMessage("command.help.output.prevPageOff")), - CurrentPage > 1 ? "<<<" : null, CurrentPage > 1 ? cmd + " " + pagePrefix + Prevpage : null); - rm.add(lManager.getMessage("command.help.output.pageCount", "[current]", CurrentPage, "[total]", pageCount)); - rm.add(pageCount > CurrentPage ? lManager.getMessage("command.help.output.nextPage") : lManager.getMessage("command.help.output.nextPageOff"), - pageCount > CurrentPage ? ">>>" : null, pageCount > CurrentPage ? cmd + " " + pagePrefix + NextPage : null); - if (pageCount != 0) - rm.show(sender); - } - - public boolean isPlaceholderAPIEnabled() { - return PlaceholderAPIEnabled; - } -} +/** + * Jobs Plugin for Bukkit + * Copyright (C) 2011 Zak Ford + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.gamingmesh.jobs; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; +import java.util.UUID; +import java.util.WeakHashMap; +import java.util.logging.Logger; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.block.Block; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; + +import com.gamingmesh.jobs.CMILib.ActionBarTitleMessages; +import com.gamingmesh.jobs.CMILib.ItemManager; +import com.gamingmesh.jobs.CMILib.RawMessage; +import com.gamingmesh.jobs.CMILib.VersionChecker; +import com.gamingmesh.jobs.Gui.GuiManager; +import com.gamingmesh.jobs.MyPet.MyPetManager; +import com.gamingmesh.jobs.MythicMobs.MythicMobInterface; +import com.gamingmesh.jobs.MythicMobs.MythicMobs2; +import com.gamingmesh.jobs.MythicMobs.MythicMobs4; +import com.gamingmesh.jobs.Placeholders.Placeholder; +import com.gamingmesh.jobs.Placeholders.PlaceholderAPIHook; +import com.gamingmesh.jobs.Signs.SignUtil; +import com.gamingmesh.jobs.WorldGuard.WorldGuardManager; +import com.gamingmesh.jobs.api.JobsExpGainEvent; +import com.gamingmesh.jobs.commands.JobsCommands; +import com.gamingmesh.jobs.config.BlockProtectionManager; +import com.gamingmesh.jobs.config.BossBarManager; +import com.gamingmesh.jobs.config.ConfigManager; +import com.gamingmesh.jobs.config.ExploreManager; +import com.gamingmesh.jobs.config.GeneralConfigManager; +import com.gamingmesh.jobs.config.LanguageManager; +import com.gamingmesh.jobs.config.NameTranslatorManager; +import com.gamingmesh.jobs.config.RestrictedAreaManager; +import com.gamingmesh.jobs.config.RestrictedBlockManager; +import com.gamingmesh.jobs.config.ScheduleManager; +import com.gamingmesh.jobs.config.ShopManager; +import com.gamingmesh.jobs.config.TitleManager; +import com.gamingmesh.jobs.config.YmlMaker; +import com.gamingmesh.jobs.container.ActionInfo; +import com.gamingmesh.jobs.container.ActionType; +import com.gamingmesh.jobs.container.ArchivedJobs; +import com.gamingmesh.jobs.container.BlockProtection; +import com.gamingmesh.jobs.container.Boost; +import com.gamingmesh.jobs.container.CurrencyType; +import com.gamingmesh.jobs.container.DBAction; +import com.gamingmesh.jobs.container.FastPayment; +import com.gamingmesh.jobs.container.Job; +import com.gamingmesh.jobs.container.JobInfo; +import com.gamingmesh.jobs.container.JobProgression; +import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.container.Log; +import com.gamingmesh.jobs.container.PlayerInfo; +import com.gamingmesh.jobs.container.PlayerPoints; +import com.gamingmesh.jobs.container.QuestProgression; +import com.gamingmesh.jobs.dao.JobsClassLoader; +import com.gamingmesh.jobs.dao.JobsDAO; +import com.gamingmesh.jobs.dao.JobsDAOData; +import com.gamingmesh.jobs.dao.JobsManager; +import com.gamingmesh.jobs.economy.BufferedEconomy; +import com.gamingmesh.jobs.economy.BufferedPayment; +import com.gamingmesh.jobs.economy.Economy; +import com.gamingmesh.jobs.economy.PaymentData; +import com.gamingmesh.jobs.i18n.Language; +import com.gamingmesh.jobs.listeners.JobsListener; +import com.gamingmesh.jobs.listeners.JobsPaymentListener; +import com.gamingmesh.jobs.listeners.McMMOlistener; +import com.gamingmesh.jobs.listeners.PistonProtectionListener; +import com.gamingmesh.jobs.selection.SelectionManager; +import com.gamingmesh.jobs.stuff.CMIScoreboardManager; +import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling; +import com.gamingmesh.jobs.stuff.Loging; +import com.gamingmesh.jobs.stuff.PageInfo; +import com.gamingmesh.jobs.stuff.TabComplete; +import com.gamingmesh.jobs.tasks.BufferedPaymentThread; +import com.gamingmesh.jobs.tasks.DatabaseSaveThread; + +public class Jobs extends JavaPlugin { + private static String version = ""; + private static PlayerManager pManager = null; + private static JobsCommands cManager = null; + private static Language lManager = null; + private static LanguageManager lmManager = null; + private static SignUtil signManager = null; + private CMIScoreboardManager CMIScoreboardManager = null; + private static ScheduleManager scheduleManager = null; + private static NameTranslatorManager NameTranslatorManager = null; + private static GuiManager GUIManager = null; + private static ExploreManager exploreManager = null; + private static TitleManager titleManager = null; + private static RestrictedBlockManager RBManager = null; + private static RestrictedAreaManager RAManager = null; + private static BossBarManager BBManager = null; + private static ShopManager shopManager = null; + private static Loging loging = null; + private static BlockProtectionManager BpManager = null; + + private static JobsManager DBManager = null; + + private static PistonProtectionListener PistonProtectionListener = null; + private static McMMOlistener McMMOlistener = null; + + private static MythicMobInterface MythicManager = null; + private static MyPetManager myPetManager = null; + private static WorldGuardManager worldGuardManager = null; + + private static ConfigManager configManager = null; + private static GeneralConfigManager GconfigManager = null; + + private static Reflections reflections = null; + + private static Logger pLogger = null; + private static JobsClassLoader classLoader = null; + private static JobsDAO dao = null; + private static List jobs = null; + private static Job noneJob = null; + private static WeakHashMap usedSlots = new WeakHashMap<>(); + public static WeakHashMap actionbartoggle = new WeakHashMap<>(); + public static WeakHashMap BossBartoggle = new WeakHashMap<>(); +// public static WeakHashMap GlobalBoost = new WeakHashMap(); + private static BufferedEconomy economy = null; + private static PermissionHandler permissionHandler = null; + private static PermissionManager permissionManager = null; + +// private static ItemManager itemManager; + + public static BufferedPaymentThread paymentThread = null; + private static DatabaseSaveThread saveTask = null; + + public static HashMap FastPayment = new HashMap<>(); + + private static NMS nms = null; + + private static ActionBarTitleMessages actionbar = null; + + protected static VersionChecker versionCheckManager = null; + + protected static SelectionManager smanager = null; + + public void setMcMMOlistener() { + McMMOlistener = new McMMOlistener(this); + } + + public static McMMOlistener getMcMMOlistener() { + return McMMOlistener; + } + + public void setPistonProtectionListener() { + PistonProtectionListener = new PistonProtectionListener(); + } + + public static PistonProtectionListener getPistonProtectionListener() { + return PistonProtectionListener; + } + + public void setMyPetManager() { + myPetManager = new MyPetManager(); + } + + public static MyPetManager getMyPetManager() { + return myPetManager; + } + + private Placeholder Placeholder; + private boolean PlaceholderAPIEnabled = false; + + public Placeholder getPlaceholderAPIManager() { + if (Placeholder == null) + Placeholder = new Placeholder(this); + return Placeholder; + } + + private boolean setupPlaceHolderAPI() { + if (!getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) + return false; + if ((new PlaceholderAPIHook(this)).hook()) + consoleMsg("&e[Jobs] PlaceholderAPI hooked."); + return true; + } + + public static WorldGuardManager getWorldGuardManager() { + return worldGuardManager; + } + + public void setMythicManager() { + try { + Class.forName("net.elseland.xikage.MythicMobs.API.MythicMobsAPI"); + MythicManager = new MythicMobs2(this); + } catch (ClassNotFoundException e) { + try { + Class.forName("io.lumine.xikage.mythicmobs.api.bukkit.BukkitAPIHelper"); + MythicManager = new MythicMobs4(this); + } catch (ClassNotFoundException ex) { + } + } + if (MythicManager != null) + consoleMsg("&e[Jobs] MythicMobs detected."); + } + + private boolean setWorldGuard() { + Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard"); + if (plugin != null) { + worldGuardManager = new WorldGuardManager(); + consoleMsg("&e[Jobs] WorldGuard detected."); + return true; + } + return false; + } + + public static MythicMobInterface getMythicManager() { + return MythicManager; + } + + public void setLoging() { + loging = new Loging(); + } + + public static Loging getLoging() { + return loging; + } + + public void setBpManager() { + BpManager = new BlockProtectionManager(); + } + + public static BlockProtectionManager getBpManager() { + return BpManager; + } + + public static Reflections getReflections() { + if (reflections == null) + reflections = new Reflections(); + return reflections; + } + + public static JobsManager getDBManager() { + if (DBManager == null) + DBManager = new JobsManager(instance); + return DBManager; + } + + public static void setShopManager() { + shopManager = new ShopManager(); + } + + public static ShopManager getShopManager() { + return shopManager; + } + + public void setConfigManager() { + configManager = new ConfigManager(); + } + + public static ConfigManager getConfigManager() { + return configManager; + } + + public void setGCManager() { + GconfigManager = new GeneralConfigManager(this); + } + + public static GeneralConfigManager getGCManager() { + return GconfigManager; + } + + public void setActionBar() { + actionbar = new ActionBarTitleMessages(); + } + + public static ActionBarTitleMessages getActionBar() { + return actionbar; + } + + public static void setNms(NMS nms) { + Jobs.nms = nms; + } + + public static NMS getNms() { + return nms; + } + + /** + * Returns player manager + * @return the player manager + */ + public static PlayerManager getPlayerManager() { + return pManager; + } + + public void setPlayerManager() { + pManager = new PlayerManager(); + } + + public static void setRestrictedBlockManager() { + RBManager = new RestrictedBlockManager(); + } + + public static RestrictedBlockManager getRestrictedBlockManager() { + return RBManager; + } + + public static void setRestrictedAreaManager() { + RAManager = new RestrictedAreaManager(); + } + + public static RestrictedAreaManager getRestrictedAreaManager() { + return RAManager; + } + + public static void setTitleManager() { + titleManager = new TitleManager(); + } + + public static TitleManager gettitleManager() { + return titleManager; + } + + public void setBBManager() { + BBManager = new BossBarManager(this); + } + + public static BossBarManager getBBManager() { + return BBManager; + } + + public static WeakHashMap getActionbarToggleList() { + return actionbartoggle; + } + + public static WeakHashMap getBossBarToggleList() { + return BossBartoggle; + } + + /** + * Returns schedule manager + * @return the schedule manager + */ + public static ScheduleManager getScheduleManager() { + return scheduleManager; + } + + public static void setScheduleManager(Jobs plugin) { + scheduleManager = new ScheduleManager(plugin); + } + + public static NameTranslatorManager getNameTranslatorManager() { + return NameTranslatorManager; + } + + public static void setNameTranslatorManager() { + NameTranslatorManager = new NameTranslatorManager(); + } + + public static GuiManager getGUIManager() { + return GUIManager; + } + + public void setGUIManager() { + GUIManager = new GuiManager(); + } + + public static JobsCommands getCommandManager() { + return cManager; + } + + public void setCommandManager() { + cManager = new JobsCommands(this); + } + + public static ExploreManager getExplore() { + return exploreManager; + } + + public void setExplore() { + exploreManager = new ExploreManager(); + } + + /** + * Returns scoreboard manager + * @return the scoreboard manager + */ + public CMIScoreboardManager getCMIScoreboardManager() { + if (CMIScoreboardManager == null) + CMIScoreboardManager = new CMIScoreboardManager(this); + return CMIScoreboardManager; + } + + protected static Jobs instance; + + public static Jobs getInstance() { + return instance; + } + + /** + * Returns sign manager + * @return the sign manager + */ + public static SignUtil getSignUtil() { + return signManager; + } + + public static void setSignUtil(Jobs plugin) { + signManager = new SignUtil(plugin); + } + + /** + * Returns language manager + * @return the language manager + */ + public static Language getLanguage() { + return lManager; + } + + public void setLanguage() { + lManager = new Language(this); + } + + public static LanguageManager getLanguageManager() { + return lmManager; + } + + public static void setLanguageManager() { + lmManager = new LanguageManager(); + } + + /** + * Sets the plugin logger + */ + public void setPluginLogger(Logger pLogger) { + Jobs.pLogger = pLogger; + } + + /** + * Retrieves the plugin logger + * @return the plugin logger + */ + public static Logger getPluginLogger() { + return pLogger; + } + + public static File getFolder() { + File folder = Jobs.getInstance().getDataFolder(); + if (!folder.exists()) + folder.mkdirs(); + return folder; + } + + /** + * Sets the Data Access Object + * @param dao - the DAO + */ + public static void setDAO(JobsDAO dao) { + Jobs.dao = dao; + } + + /** + * Get the Data Access Object + * @return the DAO + */ + public static JobsDAO getJobsDAO() { + return dao; + } + + /** + * Sets the list of jobs + * @param jobs - list of jobs + */ + public static void setJobs(List jobs) { + Jobs.jobs = jobs; + } + + /** + * Retrieves the list of active jobs + * @return list of jobs + */ + public static List getJobs() { + return Collections.unmodifiableList(jobs); + } + + /** + * Sets the none job + * @param noneJob - the none job + */ + public static void setNoneJob(Job noneJob) { + Jobs.noneJob = noneJob; + } + + /** + * Retrieves the "none" job + * @return the none job + */ + public static Job getNoneJob() { + return noneJob; + } + + /** + * Function to return the job information that matches the jobName given + * @param jobName - the ame of the job given + * @return the job that matches the name + */ + public static Job getJob(String jobName) { + for (Job job : jobs) { + if (job.getName().equalsIgnoreCase(jobName)) + return job; + } + return null; + } + + /** + * Executes startup + * @throws IOException + */ + public void startup() { + try { + reload(); + } catch (IOException e1) { + e1.printStackTrace(); + } + + loadAllPlayersData(); + // add all online players + for (Player online : Bukkit.getServer().getOnlinePlayers()) { + pManager.playerJoin(online); + } + } + + public static void loadAllPlayersData() { + long time = System.currentTimeMillis(); + // Cloning to avoid issues + HashMap temp = new HashMap<>(pManager.getPlayersInfoUUIDMap()); + HashMap> playersJobs = dao.getAllJobs(); + HashMap playersPoints = dao.getAllPoints(); + HashMap> playersLogs = dao.getAllLogs(); + HashMap playersArchives = dao.getAllArchivedJobs(); + HashMap playersLimits = dao.loadPlayerLimits(); + Iterator> it = temp.entrySet().iterator(); + while (it.hasNext()) { + Entry one = it.next(); + try { + int id = one.getValue().getID(); + JobsPlayer jPlayer = pManager.getJobsPlayerOffline( + one.getValue(), + playersJobs.get(id), + playersPoints.get(id), + playersLogs.get(id), + playersArchives.get(id), + playersLimits.get(id)); + if (jPlayer == null) + continue; + pManager.addPlayerToCache(jPlayer); + } catch (Exception e) { + e.printStackTrace(); + } + } + + dao.getMap().clear(); + if (pManager.getPlayersCache().size() != 0) + consoleMsg("&e[Jobs] Preloaded " + pManager.getPlayersCache().size() + " players data in " + ((int) (((System.currentTimeMillis() - time) + / 1000d) * 100) / 100D)); + } + + /** + * Reloads all data + * @throws IOException + */ + public static void reload() throws IOException { + + if (saveTask != null) { + saveTask.shutdown(); + saveTask = null; + } + + if (paymentThread != null) { + paymentThread.shutdown(); + paymentThread = null; + } + smanager = new SelectionManager(); + if (dao != null) { + dao.closeConnections(); + } + + GconfigManager.reload(); + lManager.reload(); + configManager.reload(); + FurnaceBrewingHandling.load(); + usedSlots.clear(); + for (Job job : jobs) { + usedSlots.put(job, dao.getSlotsTaken(job)); + } + pManager.reload(); + permissionHandler.registerPermissions(); + + // set the system to auto save + if (GconfigManager.getSavePeriod() > 0) { + saveTask = new DatabaseSaveThread(GconfigManager.getSavePeriod()); + saveTask.start(); + } + + // schedule payouts to buffered payments + paymentThread = new BufferedPaymentThread(GconfigManager.getEconomyBatchDelay()); + paymentThread.start(); + + dao.loadPlayerData(); + + // Schedule + scheduleManager.load(); + scheduleManager.start(); + + permissionManager = new PermissionManager(); + } + + /** + * Executes clean shutdown + */ + public static void shutdown() { + if (saveTask != null) + saveTask.shutdown(); + + if (paymentThread != null) + paymentThread.shutdown(); + + pManager.saveAll(); + + if (dao != null) { + dao.closeConnections(); + } + } + + /** + * Executes close connections + */ + public static void ChangeDatabase() { + DBManager.switchDataBase(); + pManager.reload(); + } + + /** + * Function to get the number of slots used on the server for this job + * @param job - the job + * @return the number of slots + */ + public static int getUsedSlots(Job job) { + if (usedSlots.containsKey(job)) + return usedSlots.get(job); + return 0; + } + + /** + * Function to increase the number of used slots for a job + * @param job - the job someone is taking + */ + public static void takeSlot(Job job) { + if (usedSlots.containsKey(job)) + usedSlots.put(job, usedSlots.get(job) + 1); + } + + /** + * Function to decrease the number of used slots for a job + * @param job - the job someone is leaving + */ + public static void leaveSlot(Job job) { + if (usedSlots.containsKey(job)) + usedSlots.put(job, usedSlots.get(job) - 1); + } + + /** + * Returns the jobs classloader + * @return the classloader + */ + public static JobsClassLoader getJobsClassloader() { + return classLoader; + } + + public void setJobsClassloader() { + classLoader = new JobsClassLoader(this); + } + + /** + * Sets the permission handler + * @param permissionHandler - the permission handler + */ + public void setPermissionHandler(PermissionHandler permissionHandler) { + Jobs.permissionHandler = permissionHandler; + } + + /** + * Gets the permission handler + * @return the permission handler + */ + public static PermissionHandler getPermissionHandler() { + return permissionHandler; + } + + public static PermissionManager getPermissionManager() { + return permissionManager; + } + +// public static ItemManager getItemManager() { +// return itemManager; +// } + + /** + * Sets the economy handler + * @param eco - the economy handler + */ + public static void setEconomy(Jobs plugin, Economy eco) { + economy = new BufferedEconomy(plugin, eco); + } + + /** + * Gets the economy handler + * @return the economy handler + */ + public static BufferedEconomy getEconomy() { + return economy; + } + + /** + * Gets the version check manager + * @return the version check manager + */ + public static VersionChecker getVersionCheckManager() { + return versionCheckManager; + } + + @Override + public void onEnable() { + + instance = this; + setEnabled(true); + + versionCheckManager = new VersionChecker(this); + + ItemManager.load(); + + version = versionCheckManager.getVersion().getShortVersion(); + +// itemManager = new ItemManager(this); + + try { + Class nmsClass; + nmsClass = Class.forName("com.gamingmesh.jobs.nmsUtil." + version); + if (NMS.class.isAssignableFrom(nmsClass)) { + setNms((NMS) nmsClass.getConstructor().newInstance()); + } else { + System.out.println("Something went wrong, please note down version and contact author, version: " + version); + setEnabled(false); + } + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException + | SecurityException e) { + System.out.println("Your server version is not compatible with this plugins version! Plugin will be disabled: " + version); + setEnabled(false); + e.printStackTrace(); + return; + } + try { + if (setupPlaceHolderAPI()) { + consoleMsg("&ePlaceholderAPI was found - Enabling capabilities."); + PlaceholderAPIEnabled = true; + } + } catch (Exception e) { + e.printStackTrace(); + } + + try { + + setActionBar(); + YmlMaker jobConfig = new YmlMaker(this, "jobConfig.yml"); + jobConfig.saveDefaultConfig(); + + YmlMaker jobSchedule = new YmlMaker(this, "schedule.yml"); + jobSchedule.saveDefaultConfig(); + + YmlMaker jobShopItems = new YmlMaker(this, "shopItems.yml"); + jobShopItems.saveDefaultConfig(); + + YmlMaker restrictedBlocks = new YmlMaker(this, "restrictedBlocks.yml"); + restrictedBlocks.saveDefaultConfig(); + + setPermissionHandler(new PermissionHandler(this)); + setPluginLogger(getLogger()); + setJobsClassloader(); + setPlayerManager(); + setLanguage(); + setGUIManager(); + setExplore(); + setBBManager(); + setLoging(); + setGCManager(); + setConfigManager(); + setCommandManager(); + setBpManager(); + + getCommand("jobs").setExecutor(cManager); + this.getCommand("jobs").setTabCompleter(new TabComplete()); + + startup(); + + if (GconfigManager.SignsEnabled) { + YmlMaker jobSigns = new YmlMaker(this, "Signs.yml"); + jobSigns.saveDefaultConfig(); + } + + // register the listeners + getServer().getPluginManager().registerEvents(new JobsListener(this), this); + getServer().getPluginManager().registerEvents(new JobsPaymentListener(this), this); + + setMcMMOlistener(); + if (McMMOlistener.CheckmcMMO()) + getServer().getPluginManager().registerEvents(McMMOlistener, this); + + setMyPetManager(); + setWorldGuard(); + + setMythicManager(); + if (MythicManager != null && MythicManager.Check() && GconfigManager.MythicMobsEnabled) + MythicManager.registerListener(); + + setPistonProtectionListener(); + if (GconfigManager.useBlockProtection) + getServer().getPluginManager().registerEvents(PistonProtectionListener, this); + + // register economy + Bukkit.getScheduler().runTask(this, new HookEconomyTask(this)); + + // all loaded properly. + + dao.loadBlockProtection(); + exploreManager.load(); + + consoleMsg("&e[Jobs] Plugin has been enabled successfully."); + + cManager.fillCommands(); + + } catch (Exception e) { + e.printStackTrace(); + System.out.println("There was some issues when starting plugin. Please contact dev about this. Plugin will be disabled."); + setEnabled(false); + } + } + + @Override + public void onDisable() { + try { + GUIManager.CloseInventories(); + shopManager.CloseInventories(); + dao.saveExplore(); + dao.saveBlockProtection(); + FurnaceBrewingHandling.save(); + } catch (Exception e) { + e.printStackTrace(); + } + shutdown(); + consoleMsg("&e[Jobs] &2Plugin has been disabled successfully."); + setEnabled(false); + } + + @SuppressWarnings("unused") + @Deprecated + private static void checkDailyQuests(JobsPlayer jPlayer, JobProgression prog, ActionInfo info) { + checkDailyQuests(jPlayer, prog.getJob(), info); + } + + private static void checkDailyQuests(JobsPlayer jPlayer, Job job, ActionInfo info) { + if (!job.getQuests().isEmpty()) { + List q = jPlayer.getQuestProgressions(job, info.getType()); + for (QuestProgression one : q) { + if (one != null) + one.processQuest(jPlayer, info); + } + } + } + + /** + * Performed an action + * + * Give correct experience and income + * @param jPlayer - the player + * @param info - the action + */ + + public static void action(JobsPlayer jPlayer, ActionInfo info) { + action(jPlayer, info, null, null, null); + } + + public static void action(JobsPlayer jPlayer, ActionInfo info, Block block) { + action(jPlayer, info, block, null, null); + } + + public static void action(JobsPlayer jPlayer, ActionInfo info, Entity ent) { + action(jPlayer, info, null, ent, null); + } + + public static void action(JobsPlayer jPlayer, ActionInfo info, Entity ent, LivingEntity victim) { + action(jPlayer, info, null, ent, victim); + } + + public static void action(JobsPlayer jPlayer, ActionInfo info, Block block, Entity ent, LivingEntity victim) { + + if (jPlayer == null) + return; + + List progression = jPlayer.getJobProgression(); + int numjobs = progression.size(); + // no job + + if (!isBpOk(jPlayer, info, block, true)) + return; + + if (numjobs == 0) { + + if (noneJob == null) + return; + JobInfo jobinfo = noneJob.getJobInfo(info, 1); + + checkDailyQuests(jPlayer, noneJob, info); + + if (jobinfo == null) + return; + + Double income = jobinfo.getIncome(1, numjobs); + Double pointAmount = jobinfo.getPoints(1, numjobs); + + if (income == 0D && pointAmount == 0D) + return; + + Boost boost = pManager.getFinalBonus(jPlayer, Jobs.getNoneJob()); + + // Calculate income + + if (income != 0D) { + income = income + (income * boost.getFinal(CurrencyType.MONEY)); + if (GconfigManager.useMinimumOveralPayment && income > 0) { + double maxLimit = income * GconfigManager.MinimumOveralPaymentLimit; + if (income < maxLimit) + income = maxLimit; + } + } + + // Calculate points + + if (pointAmount != 0D) { + pointAmount = pointAmount + (pointAmount * boost.getFinal(CurrencyType.POINTS)); + if (GconfigManager.useMinimumOveralPoints && pointAmount > 0) { + double maxLimit = pointAmount * GconfigManager.MinimumOveralPaymentLimit; + if (pointAmount < maxLimit) + pointAmount = maxLimit; + } + } + if (!jPlayer.isUnderLimit(CurrencyType.MONEY, income)) { + if(GconfigManager.useMaxPaymentCurve ){ + double percentOver =jPlayer.percentOverLimit(CurrencyType.MONEY); + float factor = GconfigManager.maxPaymentCurveFactor; + double percentLoss = 100/((1/factor*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) + BpManager.remove(block); + + if (pointAmount != 0D) + jPlayer.setSaved(false); + + economy.pay(jPlayer, income, pointAmount, 0.0); + + if (GconfigManager.LoggingUse) { + HashMap amounts = new HashMap<>(); + amounts.put(CurrencyType.MONEY, income); + loging.recordToLog(jPlayer, info, amounts); + } + + } else { + for (JobProgression prog : progression) { + int level = prog.getLevel(); + + JobInfo jobinfo = prog.getJob().getJobInfo(info, level); + + checkDailyQuests(jPlayer, prog.getJob(), info); + + if (jobinfo == null) + continue; + + Double income = jobinfo.getIncome(level, numjobs); + Double pointAmount = jobinfo.getPoints(level, numjobs); + Double expAmount = jobinfo.getExperience(level, numjobs); + + 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 = expAmount.intValue(); + double remainder = expAmount.doubleValue() - expInt; + if (Math.abs(remainder) > Math.random()) { + if (expAmount.doubleValue() < 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 = pManager.getFinalBonus(jPlayer, prog.getJob(), ent, victim); + + // 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.MinimumOveralPaymentLimit; + if (pointAmount < maxLimit) + pointAmount = maxLimit; + } + } + + // Calculate exp + expAmount = boost.getFinalAmount(CurrencyType.EXP, expAmount); + + if (GconfigManager.useMinimumOveralPayment && expAmount > 0) { + double maxLimit = expAmount * GconfigManager.MinimumOveralPaymentLimit; + if (expAmount < maxLimit) + expAmount = maxLimit; + } + + if (!jPlayer.isUnderLimit(CurrencyType.MONEY, income)) { + income = 0D; + if (GconfigManager.getLimit(CurrencyType.MONEY).getStopWith().contains(CurrencyType.EXP)) + expAmount = 0D; + if (GconfigManager.getLimit(CurrencyType.MONEY).getStopWith().contains(CurrencyType.POINTS)) + pointAmount = 0D; + } + + if (!jPlayer.isUnderLimit(CurrencyType.EXP, expAmount)) { + expAmount = 0D; + if (GconfigManager.getLimit(CurrencyType.EXP).getStopWith().contains(CurrencyType.MONEY)) + income = 0D; + if (GconfigManager.getLimit(CurrencyType.EXP).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 (GconfigManager.getLimit(CurrencyType.POINTS).getStopWith().contains(CurrencyType.EXP)) + expAmount = 0D; + } + + if (income == 0D && pointAmount == 0D && expAmount == 0D) + continue; + + try { + if (expAmount != 0D && GconfigManager.BossBarEnabled) + if (GconfigManager.BossBarShowOnEachAction) + BBManager.ShowJobProgression(jPlayer, prog); + else + jPlayer.getUpdateBossBarFor().add(prog.getJob().getName()); + } catch (Exception e) { + consoleMsg("&c[Jobs] Some issues with boss bar feature accured, try disabling it to avoid it."); + } + + // JobsPayment event + JobsExpGainEvent JobsExpGainEvent = new JobsExpGainEvent(jPlayer.getPlayer(), prog.getJob(), expAmount); + Bukkit.getServer().getPluginManager().callEvent(JobsExpGainEvent); + // If event is canceled, don't do anything + if (JobsExpGainEvent.isCancelled()) + expAmount = 0D; + else + expAmount = JobsExpGainEvent.getExp(); + + FastPayment.clear(); + FastPayment.put(jPlayer.getPlayerUUID(), new FastPayment(jPlayer, info, new BufferedPayment(jPlayer.getPlayer(), income, pointAmount, expAmount), prog + .getJob())); + + economy.pay(jPlayer, income, pointAmount, expAmount); + int oldLevel = prog.getLevel(); + + if (GconfigManager.LoggingUse) { + HashMap amounts = new HashMap<>(); + amounts.put(CurrencyType.MONEY, income); + amounts.put(CurrencyType.EXP, expAmount); + amounts.put(CurrencyType.POINTS, pointAmount); + loging.recordToLog(jPlayer, info, amounts); + } + + if (prog.addExperience(expAmount)) + pManager.performLevelUp(jPlayer, prog.getJob(), oldLevel); + } + + //need to update bp + if (block != null) { + BlockProtection bp = BpManager.getBp(block.getLocation()); + if (bp != null) + bp.setPaid(true); + } + } + } + + private static boolean isBpOk(JobsPlayer player, ActionInfo info, Block block, boolean inform) { + 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; + } + BlockProtection bp = BpManager.getBp(block.getLocation()); + if (bp != null) { + Long time = bp.getTime(); + Integer cd = BpManager.getBlockDelayTime(block); + + if (time == -1L) { + BpManager.add(block, cd); + return false; + } + if ((time < System.currentTimeMillis()) && (bp.getAction() != DBAction.DELETE)) { + BpManager.remove(block); + return true; + } + if (time > System.currentTimeMillis() || bp.isPaid() && bp.getAction() != DBAction.DELETE) { + int sec = Math.round((time - System.currentTimeMillis()) / 1000L); + if (inform) { + if (player.canGetPaid(info)) + actionbar.send(player.getPlayer(), lManager.getMessage("message.blocktimer", "[time]", sec)); + } + return false; + } + BpManager.add(block, cd); + if ((cd == null || cd == 0) && GconfigManager.useGlobalTimer) { + BpManager.add(block, GconfigManager.globalblocktimer); + } + } else if (GconfigManager.useGlobalTimer) { + BpManager.add(block, GconfigManager.globalblocktimer); + } + } else if (info.getType() == ActionType.PLACE) { + BlockProtection bp = BpManager.getBp(block.getLocation()); + if (bp != null) { + Long time = bp.getTime(); + Integer cd = BpManager.getBlockDelayTime(block); + + if (time != -1L) { + if (time < System.currentTimeMillis() && bp.getAction() != DBAction.DELETE) { + BpManager.add(block, cd); + return true; + } + if (time > System.currentTimeMillis() || bp.isPaid() && bp.getAction() != DBAction.DELETE) { + int sec = Math.round((time - System.currentTimeMillis()) / 1000L); + if (inform) { + if (player.canGetPaid(info)) + actionbar.send(player.getPlayer(), lManager.getMessage("message.blocktimer", "[time]", sec)); + } + BpManager.add(block, cd); + return false; + } + } else if (bp.isPaid().booleanValue() && bp.getTime() == -1L && cd != null && cd == -1) { + BpManager.add(block, cd); + return false; + } else + BpManager.add(block, cd); + } else + BpManager.add(block, BpManager.getBlockDelayTime(block)); + } + + return true; + } + + private static int getPlayerExperience(Player player) { + int bukkitExp = (ExpToLevel(player.getLevel()) + Math.round(deltaLevelToExp(player.getLevel()) * player.getExp())); + return bukkitExp; + } + + // total xp calculation based by lvl + private static int ExpToLevel(int level) { + if (version.equals("1_7")) { + 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.equals("1_7")) { + 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) { + // JobsPayment event + JobsExpGainEvent JobsExpGainEvent = new JobsExpGainEvent(payment.getOfflinePlayer(), job, payment.getExp()); + Bukkit.getServer().getPluginManager().callEvent(JobsExpGainEvent); + // If event is canceled, don't do anything + if (JobsExpGainEvent.isCancelled()) + return; + + if (!jPlayer.isUnderLimit(CurrencyType.MONEY, payment.getAmount())) + return; + if (!jPlayer.isUnderLimit(CurrencyType.EXP, payment.getExp())) + return; + if (!jPlayer.isUnderLimit(CurrencyType.POINTS, payment.getPoints())) + return; + + economy.pay(jPlayer, payment.getAmount(), payment.getPoints(), payment.getExp()); + + JobProgression prog = jPlayer.getJobProgression(job); + + int oldLevel = prog.getLevel(); + + if (GconfigManager.LoggingUse) { + HashMap amounts = new HashMap<>(); + amounts.put(CurrencyType.MONEY, payment.getAmount()); + amounts.put(CurrencyType.EXP, payment.getExp()); + amounts.put(CurrencyType.POINTS, payment.getPoints()); + loging.recordToLog(jPlayer, info, amounts); + } + + if (prog.addExperience(payment.getExp())) + pManager.performLevelUp(jPlayer, prog.getJob(), oldLevel); + } + + public static void consoleMsg(String msg) { + Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', msg)); + } + + public static SelectionManager getSelectionManager() { + return smanager; + } + + public static boolean hasPermission(Object sender, String perm, boolean rawEnable) { + if (sender instanceof Player) { + if (((Player) sender).hasPermission(perm)) + return true; + if (!rawEnable) { + ((Player) sender).sendMessage(lManager.getMessage("general.error.permission")); + return false; + } + RawMessage rm = new RawMessage(); + rm.add(lManager.getMessage("general.error.permission"), "&2" + perm); + rm.show((Player) sender); + return false; + } + return true; + } + + public void ShowPagination(CommandSender sender, PageInfo pi, String cmd) { + ShowPagination(sender, pi.getTotalPages(), pi.getCurrentPage(), cmd, null); + } + + public void ShowPagination(CommandSender sender, PageInfo pi, String cmd, String pagePref) { + ShowPagination(sender, pi.getTotalPages(), pi.getCurrentPage(), cmd, pagePref); + } + + public void ShowPagination(CommandSender sender, int pageCount, int CurrentPage, String cmd) { + ShowPagination(sender, pageCount, CurrentPage, cmd, null); + } + + public void ShowPagination(CommandSender sender, int pageCount, int CurrentPage, String cmd, String pagePref) { + if (!(sender instanceof Player)) + return; + if (!cmd.startsWith("/")) + cmd = "/" + cmd; + if (pageCount == 1) + return; + String pagePrefix = pagePref == null ? "" : pagePref; + int NextPage = CurrentPage + 1; + NextPage = CurrentPage < pageCount ? NextPage : CurrentPage; + int Prevpage = CurrentPage - 1; + Prevpage = CurrentPage > 1 ? Prevpage : CurrentPage; + + RawMessage rm = new RawMessage(); + rm.add((CurrentPage > 1 ? lManager.getMessage("command.help.output.prevPage") : lManager.getMessage("command.help.output.prevPageOff")), + CurrentPage > 1 ? "<<<" : null, CurrentPage > 1 ? cmd + " " + pagePrefix + Prevpage : null); + rm.add(lManager.getMessage("command.help.output.pageCount", "[current]", CurrentPage, "[total]", pageCount)); + rm.add(pageCount > CurrentPage ? lManager.getMessage("command.help.output.nextPage") : lManager.getMessage("command.help.output.nextPageOff"), + pageCount > CurrentPage ? ">>>" : null, pageCount > CurrentPage ? cmd + " " + pagePrefix + NextPage : null); + if (pageCount != 0) + rm.show(sender); + } + + public boolean isPlaceholderAPIEnabled() { + return PlaceholderAPIEnabled; + } +} diff --git a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java index 71fd1f7d..ecbaa84b 100644 --- a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -1,1035 +1,1042 @@ -/** - * Jobs Plugin for Bukkit - * Copyright (C) 2011 Zak Ford - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.gamingmesh.jobs.config; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import com.gamingmesh.jobs.Jobs; -import com.gamingmesh.jobs.CMILib.ItemManager.CMIMaterial; -import com.gamingmesh.jobs.resources.jfep.Parser; -import com.gamingmesh.jobs.container.CurrencyLimit; -import com.gamingmesh.jobs.container.CurrencyType; -import com.gamingmesh.jobs.container.LocaleReader; -import com.gamingmesh.jobs.container.Schedule; -import com.gamingmesh.jobs.CMILib.VersionChecker.Version; - -public class GeneralConfigManager { - private Jobs plugin; - public List BroadcastingLevelUpLevels = new ArrayList<>(); - protected Locale locale; - protected int savePeriod; - protected boolean economyAsync; - protected boolean isBroadcastingSkillups; - protected boolean isBroadcastingLevelups; - protected boolean payInCreative; - protected boolean payExploringWhenFlying; - protected boolean addXpPlayer; - protected boolean hideJobsWithoutPermission; - protected int maxJobs; - protected boolean payNearSpawner; - protected boolean modifyChat; - public String modifyChatPrefix; - public String modifyChatSuffix; - public String modifyChatSeparator; - protected int economyBatchDelay; - protected boolean saveOnDisconnect; - protected boolean MultiServerCompatability; -// public boolean LocalOfflinePlayersData; - public boolean MythicMobsEnabled; - public boolean LoggingUse; - public boolean PaymentMethodsMoney; - public boolean PaymentMethodsPoints; - public boolean PaymentMethodsExp; - private HashMap generalMulti = new HashMap<>(); - public int getSelectionTooldID; - - private int ResetTimeHour; - private int ResetTimeMinute; - - // Limits - public HashMap currencyLimitUse = new HashMap<>(); - - public boolean PayForRenaming, PayForEachCraft, SignsEnabled, - SignsColorizeJobName, ShowToplistInScoreboard, useGlobalTimer, useCoreProtect, BlockPlaceUse, - EnableAnounceMessage, useSilkTouchProtection, UseCustomNames, - UseJobsBrowse, PreventSlimeSplit, PreventMagmaCubeSplit, PreventHopperFillUps, PreventBrewingStandFillUps, - BrowseUseNewLook; - public int globalblocktimer, CowMilkingTimer, - CoreProtectInterval, BlockPlaceInterval, InfoUpdateInterval; - public Double TreeFellerMultiplier, gigaDrillMultiplier, superBreakerMultiplier; - public String localeString = ""; - - private boolean FurnacesReassign, BrewingStandsReassign; - private int FurnacesMaxDefault, BrewingStandsMaxDefault, BrowseAmountToShow; - - public boolean useBlockProtection; - public int BlockProtectionDays; - - public boolean useMinimumOveralPayment; - public boolean useMinimumOveralPoints; - public boolean useBreederFinder = false; - private boolean useTnTFinder = false; - public boolean CancelCowMilking; - public boolean fixAtMaxLevel, ToggleActionBar, TitleChangeChat, TitleChangeActionBar, LevelChangeChat, - LevelChangeActionBar, SoundLevelupUse, SoundTitleChangeUse, UseServerAccount, EmptyServerAcountChat, - EmptyServerAcountActionBar, ActionBarsMessageByDefault, ShowTotalWorkers, ShowPenaltyBonus, useDynamicPayment, - JobsGUIOpenOnBrowse, JobsGUIShowChatBrowse, JobsGUISwitcheButtons, JobsGUIOpenOnJoin; - - private int JobsGUIRows, JobsGUIBackButton, - JobsGUIStartPosition, - JobsGUIGroupAmount, - JobsGUISkipAmount; - - private String DecimalPlacesMoney, DecimalPlacesExp, DecimalPlacesPoints; - - public ItemStack guiBackButton; - public ItemStack guiFiller; - - public int JobsTopAmount; - - public Integer levelLossPercentageFromMax, levelLossPercentage, SoundLevelupVolume, SoundLevelupPitch, SoundTitleChangeVolume, - SoundTitleChangePitch, ToplistInScoreboardInterval; - public double MinimumOveralPaymentLimit; - public double MinimumOveralPointsLimit; - - public boolean MonsterDamageUse = false; - public double MonsterDamagePercentage; - - public double DynamicPaymentMaxPenalty; - public double DynamicPaymentMaxBonus; - public double TaxesAmount; - public String SoundLevelupSound, SoundTitleChangeSound, ServerAcountName, ServertaxesAcountName; - public ArrayList keys; - public boolean hideJobsInfoWithoutPermission; - public boolean UseTaxes; - public boolean TransferToServerAccount; - public boolean TakeFromPlayersPayment; - - public int AutoJobJoinDelay; - public boolean AutoJobJoinUse; - - public boolean AllowDelevel; - - //BossBar - public boolean BossBarEnabled; - public boolean BossBarShowOnEachAction; - public int BossBarTimer; - public boolean BossBarsMessageByDefault; - - public Parser DynamicPaymentEquation; - - public boolean DisabledWorldsUse; - public List DisabledWorldsList = new ArrayList<>(); - - public List BoostSchedule = new ArrayList<>(); - - public HashMap> commandArgs = new HashMap<>(); - - public boolean DBCleaningJobsUse; - public int DBCleaningJobsLvl; - public boolean DBCleaningUsersUse; - public int DBCleaningUsersDays; - - private boolean ShowNewVersion; - - public HashMap> getCommandArgs() { - return commandArgs; - } - - public CurrencyLimit getLimit(CurrencyType type) { - return currencyLimitUse.get(type); - } - - public GeneralConfigManager(Jobs plugin) { - this.plugin = plugin; - } - - public void setBreederFinder(boolean state) { - this.useBreederFinder = state; - } - - public boolean isUseBreederFinder() { - return this.useBreederFinder; - } - - public void setTntFinder(boolean state) { - this.useTnTFinder = state; - } - - public boolean isUseTntFinder() { - return this.useTnTFinder; - } - - /** - * Get how often in minutes to save job information - * @return how often in minutes to save job information - */ - public synchronized int getSavePeriod() { - return savePeriod; - } - - /** - * Should we use asynchronous economy calls - * @return true - use async - * @return false - use sync - */ - public synchronized boolean isEconomyAsync() { - return economyAsync; - } - - /** - * Function that tells if the system is set to broadcast on skill up - * @return true - broadcast on skill up - * @return false - do not broadcast on skill up - */ - public synchronized boolean isBroadcastingSkillups() { - return isBroadcastingSkillups; - } - - /** - * Function that tells if the system is set to broadcast on level up - * @return true - broadcast on level up - * @return false - do not broadcast on level up - */ - public synchronized boolean isBroadcastingLevelups() { - return isBroadcastingLevelups; - } - - /** - * Function that tells if the player should be paid while in creative - * @return true - pay in creative - * @return false - do not pay in creative - */ - public synchronized boolean payInCreative() { - return payInCreative; - } - - /** - * Function that tells if the player should be paid while exploring and flying - * @return true - pay - * @return false - do not - */ - public synchronized boolean payExploringWhenFlying() { - return payExploringWhenFlying; - } - - public synchronized boolean addXpPlayer() { - return addXpPlayer; - } - - /** - * Function to check if jobs should be hidden to players that lack permission to join the job - * @return - */ - public synchronized boolean getHideJobsWithoutPermission() { - return hideJobsWithoutPermission; - } - - /** - * Function to return the maximum number of jobs a player can join - * @return - */ - public synchronized int getMaxJobs() { - return maxJobs; - } - - /** - * Function to check if you get paid near a spawner is enabled - * @return true - you get paid - * @return false - you don't get paid - */ - public synchronized boolean payNearSpawner() { - return payNearSpawner; - } - - public synchronized boolean getModifyChat() { - return modifyChat; - } - - public String getModifyChatPrefix() { - return modifyChatPrefix; - } - - public String getModifyChatSuffix() { - return modifyChatSuffix; - } - - public String getModifyChatSeparator() { - return modifyChatSeparator; - } - - public synchronized int getEconomyBatchDelay() { - return economyBatchDelay; - } - - public synchronized boolean saveOnDisconnect() { - return saveOnDisconnect; - } - - public synchronized boolean MultiServerCompatability() { - return MultiServerCompatability; - } - - public synchronized Locale getLocale() { - return locale; - } - - public boolean canPerformActionInWorld(Entity ent) { - if (ent == null) - return true; - if (ent.getWorld() == null) - return true; - return canPerformActionInWorld(ent.getWorld()); - } - - public boolean canPerformActionInWorld(Player player) { - if (player == null) - return true; - return canPerformActionInWorld(player.getWorld()); - } - - public boolean canPerformActionInWorld(World world) { - if (world == null) - return true; - if (!this.DisabledWorldsUse) - return true; - return canPerformActionInWorld(world.getName()); - } - - public boolean canPerformActionInWorld(String world) { - if (world == null) - return true; - if (!this.DisabledWorldsUse) - return true; - if (this.DisabledWorldsList.isEmpty()) - return true; - if (this.DisabledWorldsList.contains(world)) - return false; - return true; - } - - public synchronized void reload() { - // general settings - loadGeneralSettings(); - Jobs.getJobsDAO().cleanJobs(); - Jobs.getJobsDAO().cleanUsers(); - // Load locale - Jobs.setLanguageManager(); - Jobs.getLanguageManager().load(); - // title settings - Jobs.setTitleManager(); - Jobs.gettitleManager().load(); - // restricted areas - Jobs.setRestrictedAreaManager(); - Jobs.getRestrictedAreaManager().load(); - // restricted blocks - Jobs.setRestrictedBlockManager(); - Jobs.getRestrictedBlockManager().load(); - // Item/Block/mobs name list - Jobs.setNameTranslatorManager(); - Jobs.getNameTranslatorManager().load(); - // signs information - Jobs.setSignUtil(this.plugin); - Jobs.getSignUtil().LoadSigns(); - // Schedule - Jobs.setScheduleManager(this.plugin); - // Shop - Jobs.setShopManager(); - Jobs.getShopManager().load(); - } - - /** - * Method to load the general configuration - * - * loads from Jobs/generalConfig.yml - */ - private synchronized void loadGeneralSettings() { - File f = new File(Jobs.getFolder(), "generalConfig.yml"); - YamlConfiguration conf = YamlConfiguration.loadConfiguration(f); - CommentedYamlConfiguration write = new CommentedYamlConfiguration(); - LocaleReader c = new LocaleReader(conf, write); - - StringBuilder header = new StringBuilder(); - header.append("General configuration."); - header.append(System.getProperty("line.separator")); - header.append(" The general configuration for the jobs plugin mostly includes how often the plugin"); - header.append(System.getProperty("line.separator")); - header.append("saves user data (when the user is in the game), the storage method, whether"); - header.append(System.getProperty("line.separator")); - header.append("to broadcast a message to the server when a user goes up a skill level."); - header.append(System.getProperty("line.separator")); - header.append(" It also allows admins to set the maximum number of jobs a player can have at"); - header.append(System.getProperty("line.separator")); - header.append("any one time."); - header.append(System.getProperty("line.separator")); - - c.getC().options().copyDefaults(true); - - c.getW().options().header(header.toString()); - - c.getW().addComment("locale-language", "Default language.", "Example: en, ru", "File in locale folder with same name should exist. Example: messages_ru.yml"); - localeString = c.get("locale-language", "en"); - try { - int i = localeString.indexOf('_'); - if (i == -1) { - locale = new Locale(localeString); - } else { - locale = new Locale(localeString.substring(0, i), localeString.substring(i + 1)); - } - } catch (IllegalArgumentException e) { - locale = Locale.getDefault(); - Jobs.getPluginLogger().warning("Invalid locale \"" + localeString + "\" defaulting to " + locale.getLanguage()); - } - - Jobs.getDBManager().start(c); - -// c.getW().addComment("storage-method", "storage method, can be MySQL, sqlite"); -// storageMethod = c.get("storage-method", "sqlite"); -// if (storageMethod.equalsIgnoreCase("mysql")) { -// startMysql(); -// } else if (storageMethod.equalsIgnoreCase("sqlite")) { -// startSqlite(); -// } else { -// Jobs.getPluginLogger().warning("Invalid storage method! Changing method to sqlite!"); -// c.getC().set("storage-method", "sqlite"); -// startSqlite(); -// } -// -// c.getW().addComment("mysql-username", "Requires Mysql."); -// c.get("mysql-username", "root"); -// c.get("mysql-password", ""); -// c.get("mysql-hostname", "localhost:3306"); -// c.get("mysql-database", "minecraft"); -// c.get("mysql-table-prefix", "jobs_"); - - c.getW().addComment("save-period", "How often in minutes you want it to save. This must be a non-zero number"); - c.get("save-period", 10); - if (c.getW().getInt("save-period") <= 0) { - Jobs.getPluginLogger().severe("Save period must be greater than 0! Defaulting to 10 minutes!"); - c.getW().set("save-period", 10); - } - savePeriod = c.getW().getInt("save-period"); - - c.getW().addComment("save-on-disconnect", "Should player data be saved on disconnect?", - "Player data is always periodically auto-saved and autosaved during a clean shutdown.", - "Only enable this if you have a multi-server setup, or have a really good reason for enabling this.", "Turning this on will decrease database performance."); - saveOnDisconnect = c.get("save-on-disconnect", false); - - c.getW().addComment("selectionTool", "Tool used when selecting bounds for restricted area"); - if (CMIMaterial.get(getSelectionTooldID) == null) - getSelectionTooldID = 294; - else - getSelectionTooldID = c.get("selectionTool", 294); - - c.getW().addComment("MultiServerCompatability", "Enable if you are using one data base for multiple servers across bungee network", - "This will force to load players data every time he is logging in to have most up to date data instead of having preloaded data", - "This will enable automatically save-on-disconnect feature"); - MultiServerCompatability = c.get("MultiServerCompatability", false); - if (MultiServerCompatability) - saveOnDisconnect = true; - - c.getW().addComment("Optimizations.NewVersion", - "When set to true staff will be informed about new Jobs plugin version", "You need to have jobs.versioncheck permission node"); - ShowNewVersion = c.get("Optimizations.NewVersion", true); - - c.getW().addComment("Optimizations.DecimalPlaces.Money", - "Decimal places to be shown"); - DecimalPlacesMoney = "%." + c.get("Optimizations.DecimalPlaces.Money", 2) + "f"; - DecimalPlacesExp = "%." + c.get("Optimizations.DecimalPlaces.Exp", 2) + "f"; - DecimalPlacesPoints = "%." + c.get("Optimizations.DecimalPlaces.Points", 2) + "f"; - - c.getW().addComment("Optimizations.DBCleaning.Jobs.Use", - "Warning!!! before enabling this feature, please make data base backup, just in case there will be some issues with data base cleaning", - "When set to true, jobs data base will be cleaned on each startup to avoid having not used jobs", - "keep in mind that this will only clean actual jobs, but not recorded players"); - DBCleaningJobsUse = c.get("Optimizations.DBCleaning.Jobs.Use", false); - c.getW().addComment("Optimizations.DBCleaning.Jobs.Level", "Any one who has jobs level equal or less then set, hies job will be removed from data base"); - DBCleaningJobsLvl = c.get("Optimizations.DBCleaning.Jobs.Level", 1); - - c.getW().addComment("Optimizations.DBCleaning.Users.Use", - "Warning!!! before enabling this feature, please make data base backup, just in case there will be some issues with data base cleaning", - "When set to true, data base will be cleaned on each startup from user data to avoid having old player data"); - DBCleaningUsersUse = c.get("Optimizations.DBCleaning.Users.Use", false); - c.getW().addComment("Optimizations.DBCleaning.Users.Days", "Any one who not played for defined amount of days, will be removed from data base"); - DBCleaningUsersDays = c.get("Optimizations.DBCleaning.Users.Days", 60); - - c.getW().addComment("Optimizations.AutoJobJoin.Use", "Use or not auto join jobs feature", - "If you are not using auto join feature, keep it disabled"); - AutoJobJoinUse = c.get("Optimizations.AutoJobJoin.Use", false); - c.getW().addComment("Optimizations.AutoJobJoin.Delay", "Delay in seconds to perform auto join job if used after player joins server", - "If you using offline server, try to keep it slightly more than your login plugin gives time to enter password", - "For player to auto join job add permission node jobs.autojoin.[jobname]", - "Op players are ignored"); - AutoJobJoinDelay = c.get("Optimizations.AutoJobJoin.Delay", 15); - - c.getW().addComment("Optimizations.AllowDelevel", "When set to true players who gets negative experience can delevel job up to level 1", - "ATTENTION! Set it to true only if you certain that commands performed on level up will not cause issues if player start level and delevel in a row."); - AllowDelevel = c.get("Optimizations.AllowDelevel", false); - -// c.getW().addComment("Optimizations.UseLocalOfflinePlayersData", "With this set to true, offline player data will be taken from local player data files", -// "This will eliminate small lag spikes when request is being send to mojangs servers for offline players data", -// "Theroticali this should work without issues, but if you havving some, just disable", -// "But then you can feal some small (100-200ms) lag spikes while performings some jobs commands"); -// LocalOfflinePlayersData = c.get("Optimizations.UseLocalOfflinePlayersData", true); - - c.getW().addComment("Optimizations.DisabledWorlds.Use", "By setting this to true, Jobs plugin will be disabled in given worlds", - "Only commands can be performed from disabled worlds with jobs.disabledworld.commands permission node"); - DisabledWorldsUse = c.get("Optimizations.DisabledWorlds.Use", false); - DisabledWorldsList = c.getStringList("Optimizations.DisabledWorlds.List", Arrays.asList(Bukkit.getWorlds().get(0).getName())); - -// c.getW().addComment("Optimizations.Purge.Use", "By setting this to true, Jobs plugin will clean data base on startup from all jobs with level 1 and at 0 exp"); -// PurgeUse = c.get("Optimizations.Purge.Use", false); - - c.getW().addComment("Logging.Use", "With this set to true all players jobs actions will be logged to database for easy to see statistics", - "This is still in development and in feature it will expand"); - LoggingUse = c.get("Logging.Use", false); - - c.getW().addComment("broadcast.on-skill-up.use", "Do all players get a message when someone goes up a skill level?"); - isBroadcastingSkillups = c.get("broadcast.on-skill-up.use", false); - - c.getW().addComment("broadcast.on-level-up.use", "Do all players get a message when someone goes up a level?"); - isBroadcastingLevelups = c.get("broadcast.on-level-up.use", false); - c.getW().addComment("broadcast.on-level-up.levels", "For what levels you want to broadcast message? Keep it at 0 if you want for all of them"); - BroadcastingLevelUpLevels = c.getIntList("broadcast.on-level-up.levels", Arrays.asList(0)); - - c.getW().addComment("DailyQuests.ResetTime", "Defines time in 24hour format when we want to give out new daily quests", - "Any daily quests given before reset will be invalid and new ones will be given out"); - ResetTimeHour = c.get("DailyQuests.ResetTime.Hour", 4); - ResetTimeMinute = c.get("DailyQuests.ResetTime.Minute", 0); - - c.getW().addComment("max-jobs", "Maximum number of jobs a player can join.", "Use 0 for no maximum", "Keep in mind that jobs.max.[amount] will bypass this setting"); - maxJobs = c.get("max-jobs", 3); - - c.getW().addComment("hide-jobs-without-permission", "Hide jobs from player if they lack the permission to join the job"); - hideJobsWithoutPermission = c.get("hide-jobs-without-permission", false); - - c.getW().addComment("hide-jobsinfo-without-permission", "Hide jobs info from player if they lack the permission to join the job"); - hideJobsInfoWithoutPermission = c.get("hide-jobsinfo-without-permission", false); - - c.getW().addComment("enable-pay-near-spawner", - "Option to allow payment to be made when killing mobs from a spawner.", - "Use jobs.nearspawner.[amount] to define multiplayer. Example jobs.nearspawner.-0.5 will pay half of payment, jobs.nearspawner.-1 will not pay at all"); - payNearSpawner = c.get("enable-pay-near-spawner", false); - - c.getW().addComment("enable-pay-creative", "Option to allow payment to be made in creative mode. This ignoring when a group has 'jobs.paycreative' permission."); - payInCreative = c.get("enable-pay-creative", false); - - c.getW().addComment("enable-pay-for-exploring-when-flying", "Option to allow payment to be made for exploring when player flies"); - payExploringWhenFlying = c.get("enable-pay-for-exploring-when-flying", false); - - c.getW().addComment("add-xp-player", "Adds the Jobs xp received to the player's Minecraft XP bar"); - addXpPlayer = c.get("add-xp-player", false); - - c.getW().addComment("modify-chat", "Modifys chat to add chat titles. If you're using a chat manager, you may add the tag {jobs} to your chat format and disable this."); - modifyChat = c.get("modify-chat.use", true); - modifyChatPrefix = c.get("modify-chat.prefix", "&c[", true); - modifyChatSuffix = c.get("modify-chat.suffix", "&c]&r ", true); - modifyChatSeparator = c.get("modify-chat.separator", " ", true); - - c.getW().addComment("UseCustomNames", "Do you want to use custom item/block/mob/enchant/color names", - "With this set to true names like Stone:1 will be translated to Granite", "Name list is in TranslatableWords.yml file"); - UseCustomNames = c.get("UseCustomNames", true); - - c.getW().addComment("economy-batch-delay", "Changes how often, in seconds, players are paid out. Default is 5 seconds.", - "Setting this too low may cause tick lag. Increase this to improve economy performance (at the cost of delays in payment)"); - economyBatchDelay = c.get("economy-batch-delay", 5); - - c.getW().addComment("economy-async", "Enable async economy calls.", "Disable this if you have issues with payments or your plugin is not thread safe."); - economyAsync = c.get("economy-async", true); - - c.getW().addComment("Economy.PaymentMethods", - "By disabling one of thies, players no longer will get particular payment.", - "Useful for removing particular payment method without editing whole jobConfig file"); - PaymentMethodsMoney = c.get("Economy.PaymentMethods.Money", true); - PaymentMethodsPoints = c.get("Economy.PaymentMethods.Points", true); - PaymentMethodsExp = c.get("Economy.PaymentMethods.Exp", true); - - c.getW().addComment("Economy.GeneralMulti", - "Can be used to change payment amounts for all jobs and all actions if you want to readjust them", - "Amounts are in percentage, above 0 will increase payments", - "Amount belove 0 will decrease payments", - "If action pays negative amount, then value above 0 will increase that negative value", - "So is placing diamond ore takes from you 10 bucks, then by setting 50 for money income, you will be charged 15 bucks for placing it", - "If you are getting paid 10 for placing wood, then same value of 50 for money income, will result you getting 15 bucks", - "This only effects base income value"); - for (CurrencyType one : CurrencyType.values()) { - generalMulti.put(one, c.get("Economy.GeneralMulti." + one.name(), 0D) / 100D); - } - - c.getW().addComment("Economy.MinimumOveralPayment.use", - "Determines minimum payment. In example if player uses McMMO treefeller and earns only 20%, but at same time he gets 25% penalty from dynamic payment. He can 'get' negative amount of money", - "This will limit it to particular percentage", "Works only when original payment is above 0"); - useMinimumOveralPayment = c.get("Economy.MinimumOveralPayment.use", true); - MinimumOveralPaymentLimit = c.get("Economy.MinimumOveralPayment.limit", 0.1); - c.getW().addComment("Economy.MinimumOveralPoints.use", - "Determines minimum payment. In example if player uses McMMO treefeller and earns only 20%, but at same time he gets 25% penalty from dynamic payment. He can 'get' negative amount of money", - "This will limit it to particular percentage", "Works only when original payment is above 0"); - useMinimumOveralPoints = c.get("Economy.MinimumOveralPoints.use", true); - MinimumOveralPointsLimit = c.get("Economy.MinimumOveralPoints.limit", 0.1); - - c.getW().addComment("Economy.DynamicPayment.use", "Do you want to use dinamic payment dependent on how many players already working for jobs", - "This can help automatically lift up payments for not so popular jobs and lower for most popular ones"); - useDynamicPayment = c.get("Economy.DynamicPayment.use", false); - - String maxExpEquationInput = c.get("Economy.DynamicPayment.equation", "((totalworkers / totaljobs) - jobstotalplayers)/10.0"); - try { - DynamicPaymentEquation = new Parser(maxExpEquationInput); - // test equation - DynamicPaymentEquation.setVariable("totalworkers", 100); - DynamicPaymentEquation.setVariable("totaljobs", 10); - DynamicPaymentEquation.setVariable("jobstotalplayers", 10); - DynamicPaymentEquation.getValue(); - } catch (Exception e) { - Jobs.consoleMsg("&cDynamic payment equation has an invalid property. Disabling feature!"); - useDynamicPayment = false; - } - - DynamicPaymentMaxPenalty = c.get("Economy.DynamicPayment.MaxPenalty", 25.0); - DynamicPaymentMaxBonus = c.get("Economy.DynamicPayment.MaxBonus", 100.0); - - c.getW().addComment("Economy.UseServerAcount", "Server economy account", "With this enabled, players will get money from defined user (server account)", - "If this account don't have enough money to pay for players for, player will get message"); - UseServerAccount = c.get("Economy.UseServerAcount", false); - c.getW().addComment("Economy.AcountName", "Username should be with Correct capitalization"); - ServerAcountName = c.get("Economy.AcountName", "Server"); - c.getW().addComment("Economy.Taxes.use", "Do you want to use taxes feature for jobs payment"); - UseTaxes = c.get("Economy.Taxes.use", false); - c.getW().addComment("Economy.Taxes.AccountName", "Username should be with Correct capitalization, it can be same as setup in server account before"); - ServertaxesAcountName = c.get("Economy.Taxes.AccountName", "Server"); - c.getW().addComment("Economy.Taxes.Amount", "Amount in percentage"); - TaxesAmount = c.get("Economy.Taxes.Amount", 15.0); - c.getW().addComment("Economy.Taxes.TransferToServerAccount", "Do you want to transfer taxes to server account"); - TransferToServerAccount = c.get("Economy.Taxes.TransferToServerAccount", true); - c.getW().addComment("Economy.Taxes.TakeFromPlayersPayment", - "With this true, taxes will be taken from players payment and he will get less money than its shown in jobs info", - "When its false player will get full payment and server account will get taxes amount to hes account"); - TakeFromPlayersPayment = c.get("Economy.Taxes.TakeFromPlayersPayment", false); - - // Money limit - CurrencyLimit limit = new CurrencyLimit(); - c.getW().addComment("Economy.Limit.Money", "Money gain limit", "With this enabled, players will be limited how much they can make in defined time", - "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours"); - limit.setEnabled(c.get("Economy.Limit.Money.Use", false)); - List list = new ArrayList<>(); - c.getW().addComment("Economy.Limit.Money.StopWithExp", "Do you want to stop money gain when exp limit reached?"); - if (c.get("Economy.Limit.Money.StopWithExp", false)) - list.add(CurrencyType.EXP); - c.getW().addComment("Economy.Limit.Money.StopWithPoint", "Do you want to stop money gain when point limit reached?"); - if (c.get("Economy.Limit.Money.StopWithPoint", false)) - list.add(CurrencyType.POINTS); - limit.setStopWith(list); - c.getW().addComment("Economy.Limit.Money.MoneyLimit", - "Equation to calculate max limit. Option to use total level to include players total amount levels of current jobs", - "You can always use simple number to set money limit", - "Default equation is: 500+500*(totallevel/100), this will add 1% from 500 for each level player have", - "So player with 2 jobs with level 15 and 22 will have 685 limit"); - String MoneyLimit = c.get("Economy.Limit.Money.MoneyLimit", "500+500*(totallevel/100)"); - try { - Parser Equation = new Parser(MoneyLimit); - Equation.setVariable("totallevel", 1); - Equation.getValue(); - limit.setMaxEquation(Equation); - } catch (Exception e) { - Jobs.getPluginLogger().warning("MoneyLimit has an invalid value. Disabling money limit!"); - limit.setEnabled(false); - } - c.getW().addComment("Economy.Limit.Money.TimeLimit", "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours"); - limit.setTimeLimit(c.get("Economy.Limit.Money.TimeLimit", 3600)); - c.getW().addComment("Economy.Limit.Money.AnnouncementDelay", "Delay between announcements about reached money limit", - "Keep this from 30 to 5 min (300), as players can get annoyed of constant message displaying"); - limit.setAnnouncementDelay(c.get("Economy.Limit.Money.AnnouncementDelay", 30)); - currencyLimitUse.put(CurrencyType.MONEY, limit); - - // Point limit - limit = new CurrencyLimit(); - list = new ArrayList<>(); - c.getW().addComment("Economy.Limit.Point", "Point gain limit", "With this enabled, players will be limited how much they can make in defined time"); - limit.setEnabled(c.get("Economy.Limit.Point.Use", false)); - c.getW().addComment("Economy.Limit.Point.StopWithExp", "Do you want to stop Point gain when exp limit reached?"); - if (c.get("Economy.Limit.Point.StopWithExp", false)) - list.add(CurrencyType.EXP); - c.getW().addComment("Economy.Limit.Point.StopWithMoney", "Do you want to stop Point gain when money limit reached?"); - if (c.get("Economy.Limit.Point.StopWithMoney", false)) - list.add(CurrencyType.MONEY); - limit.setStopWith(list); - c.getW().addComment("Economy.Limit.Point.Limit", - "Equation to calculate max limit. Option to use total level to include players total amount levels of current jobs", - "You can always use simple number to set limit", - "Default equation is: 500+500*(totallevel/100), this will add 1% from 500 for each level player have", - "So player with 2 jobs with level 15 and 22 will have 685 limit"); - String PointLimit = c.get("Economy.Limit.Point.Limit", "500+500*(totallevel/100)"); - try { - Parser Equation = new Parser(PointLimit); - Equation.setVariable("totallevel", 1); - Equation.getValue(); - limit.setMaxEquation(Equation); - } catch (Exception e) { - Jobs.getPluginLogger().warning("PointLimit has an invalid value. Disabling money limit!"); - limit.setEnabled(false); - } - c.getW().addComment("Economy.Limit.Point.TimeLimit", "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours"); - limit.setTimeLimit(c.get("Economy.Limit.Point.TimeLimit", 3600)); - c.getW().addComment("Economy.Limit.Point.AnnouncementDelay", "Delay between announcements about reached limit", - "Keep this from 30 to 5 min (300), as players can get annoyed of constant message displaying"); - limit.setAnnouncementDelay(c.get("Economy.Limit.Point.AnnouncementDelay", 30)); - currencyLimitUse.put(CurrencyType.POINTS, limit); - - // Exp limit - limit = new CurrencyLimit(); - list = new ArrayList<>(); - c.getW().addComment("Economy.Limit.Exp", "Exp gain limit", "With this enabled, players will be limited how much they can get in defined time", - "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours"); - limit.setEnabled(c.get("Economy.Limit.Exp.Use", false)); - c.getW().addComment("Economy.Limit.Exp.StopWithMoney", "Do you want to stop exp gain when money limit reached?"); - if (c.get("Economy.Limit.Exp.StopWithMoney", false)) - list.add(CurrencyType.MONEY); - c.getW().addComment("Economy.Limit.Exp.StopWithPoint", "Do you want to stop exp gain when point limit reached?"); - if (c.get("Economy.Limit.Exp.StopWithPoint", false)) - list.add(CurrencyType.POINTS); - limit.setStopWith(list); - c.getW().addComment("Economy.Limit.Exp.Limit", "Equation to calculate max money limit. Option to use total level to include players total amount of current jobs", - "You can always use simple number to set exp limit", - "Default equation is: 5000+5000*(totallevel/100), this will add 1% from 5000 for each level player have", - "So player with 2 jobs with level 15 and 22 will have 6850 limit"); - String expLimit = c.get("Economy.Limit.Exp.Limit", "5000+5000*(totallevel/100)"); - try { - Parser Equation = new Parser(expLimit); - Equation.setVariable("totallevel", 1); - Equation.getValue(); - limit.setMaxEquation(Equation); - } catch (Exception e) { - Jobs.getPluginLogger().warning("ExpLimit has an invalid value. Disabling money limit!"); - limit.setEnabled(false); - } - c.getW().addComment("Economy.Limit.Exp.TimeLimit", "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours"); - limit.setTimeLimit(c.get("Economy.Limit.Exp.TimeLimit", 3600)); - c.getW().addComment("Economy.Limit.Exp.AnnouncementDelay", "Delay between announcements about reached Exp limit", - "Keep this from 30 to 5 min (300), as players can get annoyed of constant message displaying"); - limit.setAnnouncementDelay(c.get("Economy.Limit.Exp.AnnouncementDelay", 30)); - currencyLimitUse.put(CurrencyType.EXP, limit); - - c.getW().addComment("Economy.Repair.PayForRenaming", "Do you want to give money for only renaming items in anvil", - "Players will get full pay as they would for remaining two items when they only renaming one", - "This is not big issue, but if you want to disable it, you can"); - PayForRenaming = c.get("Economy.Repair.PayForRenaming", true); - - c.getW().addComment("Economy.Crafting.PayForEachCraft", - "With this true, player will get money for all crafted items instead of each crafting action (like with old payment mechanic)", - "By default its false, as you can make ALOT of money if prices kept from old payment mechanics"); - PayForEachCraft = c.get("Economy.Crafting.PayForEachCraft", false); - - c.getW().addComment("Economy.MilkingCow.CancelMilking", "With this true, when timer is still going, cow milking event will be canceled", - "With this false, player will get bucket of milk, but still no payment"); - CancelCowMilking = c.get("Economy.MilkingCow.CancelMilking", false); - c.getW().addComment("Economy.MilkingCow.Timer", - "How ofter player can milk cows in seconds. Keep in mind that by default player can milk cow indefinitely and as often as he wants", - "Set to 0 if you want to disable timer"); - CowMilkingTimer = c.get("Economy.MilkingCow.Timer", 30) * 1000; - - c.getW().addComment("ExploitProtections.Furnaces.Reassign", - "When enabled, players interacted furnaces will be saved into file and will be reassigned after restart to keep giving out money", - "Players will no longer need to click on furnace to get paid from it after server restart"); - FurnacesReassign = c.get("ExploitProtections.Furnaces.Reassign", true); - c.getW().addComment("ExploitProtections.Furnaces.MaxDefaultAvailable", - "Defines max available furnaces each player can have to get paid from", - "This can be overridden with jobs.maxfurnaces.[amount] permission node"); - FurnacesMaxDefault = c.get("ExploitProtections.Furnaces.MaxDefaultAvailable", 20); - - c.getW().addComment("ExploitProtections.BrewingStands.Reassign", - "When enabled, players interacted brewing stands will be saved into file and will be reassigned after restart to keep giving out money", - "Players will no longer need to click on brewing stand to get paid from it after server restart"); - BrewingStandsReassign = c.get("ExploitProtections.BrewingStands.Reassign", true); - c.getW().addComment("ExploitProtections.BrewingStands.MaxDefaultAvailable", - "Defines max available brewing stands each player can have to get paid from", - "Set to 0 if you want to disable this limitation", - "This can be overridden with jobs.maxbrewingstands.[amount] permission node"); - BrewingStandsMaxDefault = c.get("ExploitProtections.BrewingStands.MaxDefaultAvailable", 20); - - c.getW().addComment("ExploitProtections.General.PlaceAndBreakProtection", - "Enable blocks protection, like ore, from exploiting by placing and destroying same block again and again.", - "Modify restrictedBlocks.yml for blocks you want to protect"); - useBlockProtection = c.get("ExploitProtections.General.PlaceAndBreakProtection", true); - - c.getW().addComment("ExploitProtections.General.KeepDataFor", - "For how long in days to keep block protection data in data base", "This will clean block data which ones have -1 as cooldown value", - "Data base cleanup will be performed on each server startup"); - BlockProtectionDays = c.get("ExploitProtections.General.KeepDataFor", 14); - - c.getW().addComment("ExploitProtections.General.GlobalBlockTimer", "All blocks will be protected X sec after player places it on ground."); - useGlobalTimer = c.get("ExploitProtections.General.GlobalBlockTimer.use", true); - globalblocktimer = c.get("ExploitProtections.General.GlobalBlockTimer.timer", 3); - - c.getW().addComment("ExploitProtections.General.SilkTouchProtection", "Enable silk touch protection.", - "With this enabled players wont get paid for breaked blocks from restrictedblocks list with silk touch tool."); - useSilkTouchProtection = c.get("ExploitProtections.General.SilkTouchProtection", false); - - c.getW().addComment("ExploitProtections.General.MonsterDamage.Use", "This section controls how much damage player should do to monster for player to get paid", - "This prevents from killing monsters in one hit when they suffer in example fall damage"); - MonsterDamageUse = c.get("ExploitProtections.General.MonsterDamage.Use", false); - MonsterDamagePercentage = c.get("ExploitProtections.General.MonsterDamage.Percentage", 60); - - c.getW().addComment("ExploitProtections.McMMO", "McMMO abilities"); - c.getW().addComment("ExploitProtections.McMMO.TreeFellerMultiplier", "Players will get part of money from cutting trees with treefeller ability enabled.", - "0.2 means 20% of original price"); - TreeFellerMultiplier = c.get("ExploitProtections.McMMO.TreeFellerMultiplier", 0.2); - c.getW().addComment("ExploitProtections.McMMO.gigaDrillMultiplier", "Players will get part of money from braking blocks with gigaDrill ability enabled.", - "0.2 means 20% of original price"); - gigaDrillMultiplier = c.get("ExploitProtections.McMMO.gigaDrillMultiplier", 0.2); - c.getW().addComment("ExploitProtections.McMMO.superBreakerMultiplier", "Players will get part of money from braking blocks with super breaker ability enabled.", - "0.2 means 20% of original price"); - superBreakerMultiplier = c.get("ExploitProtections.McMMO.superBreakerMultiplier", 0.2); - - c.getW().addComment("ExploitProtections.MythicMobs", "MythicMobs plugin support", "Disable if you having issues with it or using old version"); - MythicMobsEnabled = c.get("ExploitProtections.MythicMobs.enabled", true); - - c.getW().addComment("ExploitProtections.Spawner.PreventSlimeSplit", "Prevent slime splitting when they are from spawner", - "Protects agains exploiting as new splited slimes is treated as naturally spawned and not from spawner"); - PreventSlimeSplit = c.get("ExploitProtections.Spawner.PreventSlimeSplit", true); - c.getW().addComment("ExploitProtections.Spawner.PreventMagmaCubeSplit", "Prevent magmacube splitting when they are from spawner"); - PreventMagmaCubeSplit = c.get("ExploitProtections.Spawner.PreventMagmaCubeSplit", true); - - c.getW().addComment("ExploitProtections.Smelt.PreventHopperFillUps", "Prevent payments when hoppers moving items into furnace", "Player will not get paid, but items will be smelted"); - PreventHopperFillUps = c.get("ExploitProtections.Smelt.PreventHopperFillUps", true); - c.getW().addComment("ExploitProtections.Smelt.PreventMagmaCubeSplit", "Prevent payments when hoppers moving items into brewing stands", - "Player will not get paid, but items will be brewd as they supose too"); - PreventBrewingStandFillUps = c.get("ExploitProtections.Brew.PreventBrewingStandFillUps", true); - - c.getW().addComment("use-breeder-finder", "Breeder finder.", - "If you are not using breeding payment, you can disable this to save little resources. Really little."); - useBreederFinder = c.get("use-breeder-finder", true); - - c.getW().addComment("old-job", - "Old job save", "Players can leave job and return later with some level loss during that", - "You can fix players level if hes job level is at max level"); - levelLossPercentage = c.get("old-job.level-loss-percentage", 30); - fixAtMaxLevel = c.get("old-job.fix-at-max-level", true); - c.getW().addComment("old-job.level-loss-from-max-level", - "Percentage to loose when leaving job at max level", - "Only works when fix-at-max-level is set to false"); - levelLossPercentageFromMax = c.get("old-job.level-loss-from-max-level", levelLossPercentage); - - c.getW().addComment("ActionBars.Messages.EnabledByDefault", "When this set to true player will see action bar messages by default"); - ActionBarsMessageByDefault = c.get("ActionBars.Messages.EnabledByDefault", true); - - c.getW().addComment("BossBar.Enabled", "Enables BossBar feature", "Works only from 1.9 mc version"); - BossBarEnabled = c.get("BossBar.Enabled", true); - - if (BossBarEnabled == true) { - if (Jobs.getVersionCheckManager().getVersion().isLower(Version.v1_9_R1)) { - Jobs.consoleMsg("&c[Jobs] Your server version don't support BossBar. This feature will be disabled."); - c.getW().set("BossBar.Enabled", false); - BossBarEnabled = false; - } - } - - c.getW().addComment("BossBar.Messages.EnabledByDefault", "When this set to true player will see Bossbar messages by default"); - BossBarsMessageByDefault = c.get("BossBar.Messages.EnabledByDefault", true); - - c.getW().addComment("BossBar.ShowOnEachAction", "If enabled boss bar will update after each action", - "If disabled, BossBar will update only on each payment. This can save some server resources"); - BossBarShowOnEachAction = c.get("BossBar.ShowOnEachAction", false); - c.getW().addComment("BossBar.Timer", "How long in sec to show BossBar for player", - "If you have disabled ShowOnEachAction, then keep this number higher than payment interval for better experience"); - BossBarTimer = c.get("BossBar.Timer", economyBatchDelay + 1); - - c.getW().addComment("ShowActionBars", "You can enable/disable message shown for players in action bar"); - TitleChangeActionBar = c.get("ShowActionBars.OnTitleChange", true); - LevelChangeActionBar = c.get("ShowActionBars.OnLevelChange", true); - EmptyServerAcountActionBar = c.get("ShowActionBars.OnEmptyServerAcount", true); - - c.getW().addComment("ShowChatMessage", "Chat messages", "You can enable/disable message shown for players in chat"); - TitleChangeChat = c.get("ShowChatMessage.OnTitleChange", true); - LevelChangeChat = c.get("ShowChatMessage.OnLevelChange", true); - EmptyServerAcountChat = c.get("ShowChatMessage.OnEmptyServerAcount", true); - - c.getW().addComment("Sounds", "Sounds", "Extra sounds on some events", - "All sounds can be found in https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html"); - SoundLevelupUse = c.get("Sounds.LevelUp.use", true); - SoundLevelupSound = c.get("Sounds.LevelUp.sound", "ENTITY_PLAYER_LEVELUP"); - SoundLevelupVolume = c.get("Sounds.LevelUp.volume", 1); - SoundLevelupPitch = c.get("Sounds.LevelUp.pitch", 3); - SoundTitleChangeUse = c.get("Sounds.TitleChange.use", true); - SoundTitleChangeSound = c.get("Sounds.TitleChange.sound", "ENTITY_PLAYER_LEVELUP"); - SoundTitleChangeVolume = c.get("Sounds.TitleChange.volume", 1); - SoundTitleChangePitch = c.get("Sounds.TitleChange.pitch", 3); - - c.getW().addComment("Signs", "You can disable this to save SMALL amount of server resources"); - SignsEnabled = c.get("Signs.Enable", true); - SignsColorizeJobName = c.get("Signs.Colors.ColorizeJobName", true); - c.getW().addComment("Signs.InfoUpdateInterval", - "This is interval in sec in which signs will be updated. This is not continues update, signs are updated only on levelup, job leave, job join or similar action."); - c.getW().addComment("Signs.InfoUpdateInterval", - "This is update for same job signs, to avoid huge lag if you have bunch of same type signs. Keep it from 1 to as many sec you want"); - InfoUpdateInterval = c.get("Signs.InfoUpdateInterval", 5); - - c.getW().addComment("Scoreboard.ShowToplist", "This will enables to show top list in scoreboard instead of chat"); - ShowToplistInScoreboard = c.get("Scoreboard.ShowToplist", true); - - c.getW().addComment("Scoreboard.interval", "For how long to show scoreboard"); - ToplistInScoreboardInterval = c.get("Scoreboard.interval", 10); - - c.getW().addComment("JobsBrowse.ShowTotalWorkers", "Do you want to show total amount of workers for job in jobs browse window"); - ShowTotalWorkers = c.get("JobsBrowse.ShowTotalWorkers", true); - c.getW().addComment("JobsBrowse.ShowPenaltyBonus", "Do you want to show penalty and bonus in jobs browse window. Only works if this feature is enabled"); - ShowPenaltyBonus = c.get("JobsBrowse.ShowPenaltyBonus", true); - - c.getW().addComment("JobsBrowse.UseNewLook", "Defines if you want to use new /jobs browse look or old one"); - BrowseUseNewLook = c.get("JobsBrowse.UseNewLook", true); - c.getW().addComment("JobsBrowse.AmountToShow", "Defines amount of jobs to be shown in one page for /jobs browse"); - BrowseAmountToShow = c.get("JobsBrowse.AmountToShow", 5); - - c.getW().addComment("JobsGUI.OpenOnBrowse", "Do you want to show GUI when performing /jobs browse command"); - JobsGUIOpenOnBrowse = c.get("JobsGUI.OpenOnBrowse", true); - c.getW().addComment("JobsGUI.ShowChatBrowse", "Do you want to show chat information when performing /jobs browse command"); - JobsGUIShowChatBrowse = c.get("JobsGUI.ShowChatBrowse", true); - c.getW().addComment("JobsGUI.SwitcheButtons", "With true left mouse button will join job and right will show more info", - "With false left mouse button will show more info, right will join job", "Don't forget to adjust locale file"); - JobsGUISwitcheButtons = c.get("JobsGUI.SwitcheButtons", false); - c.getW().addComment("JobsGUI.Rows", "Defines size in rows of GUI"); - JobsGUIRows = c.get("JobsGUI.Rows", 5); - c.getW().addComment("JobsGUI.BackButtonSlot", "Defines back button slot in GUI"); - JobsGUIBackButton = c.get("JobsGUI.BackButtonSlot", 37); - c.getW().addComment("JobsGUI.StartPosition", "Defines start position in gui from which job icons will be shown"); - JobsGUIStartPosition = c.get("JobsGUI.StartPosition", 11); - c.getW().addComment("JobsGUI.GroupAmount", "Defines By how many jobs we need to group up"); - JobsGUIGroupAmount = c.get("JobsGUI.GroupAmount", 7); - c.getW().addComment("JobsGUI.SkipAmount", "Defines By how many slot we need to skip after group"); - JobsGUISkipAmount = c.get("JobsGUI.SkipAmount", 2); - - c.getW().addComment("JobsTop.AmountToShow", "Defines amount of players to be shown in one page for /jobs top & /jobs gtop"); - JobsTopAmount = c.get("JobsTop.AmountToShow", 15); - - CMIMaterial tmat = null; - tmat = CMIMaterial.get(c.get("JobsGUI.BackButton.Material", "JACK_O_LANTERN")); - guiBackButton = tmat == null ? CMIMaterial.JACK_O_LANTERN.newItemStack() : tmat.newItemStack(); - - tmat = CMIMaterial.get(c.get("JobsGUI.Filler.Material", "STAINED_GLASS_PANE")); - guiFiller = tmat == null ? CMIMaterial.GREEN_STAINED_GLASS_PANE.newItemStack() : tmat.newItemStack(); - -// c.getW().addComment("Schedule.Boost.Enable", "Do you want to enable scheduler for global boost"); -// useGlobalBoostScheduler = c.get("Schedule.Boost.Enable", false); - - try { - c.getW().save(f); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public int getSelectionTooldID() { - return getSelectionTooldID; - } - - public boolean isShowNewVersion() { - return ShowNewVersion; - } - - public int getResetTimeHour() { - return ResetTimeHour; - } - - public void setResetTimeHour(int resetTimeHour) { - ResetTimeHour = resetTimeHour; - } - - public int getResetTimeMinute() { - return ResetTimeMinute; - } - - public void setResetTimeMinute(int resetTimeMinute) { - ResetTimeMinute = resetTimeMinute; - } - - public boolean isFurnacesReassign() { - return FurnacesReassign; - } - - public boolean isBrewingStandsReassign() { - return BrewingStandsReassign; - } - - public int getFurnacesMaxDefault() { - return FurnacesMaxDefault; - } - - public int getBrewingStandsMaxDefault() { - return BrewingStandsMaxDefault; - } - - public int getBrowseAmountToShow() { - return BrowseAmountToShow; - } - - public String getDecimalPlacesMoney() { - return DecimalPlacesMoney; - } - - public String getDecimalPlacesExp() { - return DecimalPlacesExp; - } - - public String getDecimalPlacesPoints() { - return DecimalPlacesPoints; - } - - public int getJobsGUIRows() { - if (JobsGUIRows < 1) - JobsGUIRows = 1; - return JobsGUIRows; - } - - public int getJobsGUIBackButton() { - if (JobsGUIBackButton < 1) - JobsGUIBackButton = 1; - if (JobsGUIBackButton > JobsGUIRows * 9) - JobsGUIBackButton = JobsGUIRows * 9; - return JobsGUIBackButton - 1; - } - - public int getJobsGUIStartPosition() { - if (JobsGUIBackButton < 1) - JobsGUIBackButton = 1; - return JobsGUIStartPosition - 1; - } - - public int getJobsGUIGroupAmount() { - return JobsGUIGroupAmount; - } - - public int getJobsGUISkipAmount() { - return JobsGUISkipAmount; - } - - public Double getGeneralMulti(CurrencyType type) { - return generalMulti.get(type); - } - -} +/** + * Jobs Plugin for Bukkit + * Copyright (C) 2011 Zak Ford + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.gamingmesh.jobs.config; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; + +import com.gamingmesh.jobs.economy.Economy; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.CMILib.ItemManager.CMIMaterial; +import com.gamingmesh.jobs.resources.jfep.Parser; +import com.gamingmesh.jobs.container.CurrencyLimit; +import com.gamingmesh.jobs.container.CurrencyType; +import com.gamingmesh.jobs.container.LocaleReader; +import com.gamingmesh.jobs.container.Schedule; +import com.gamingmesh.jobs.CMILib.VersionChecker.Version; + +public class GeneralConfigManager { + private Jobs plugin; + public List BroadcastingLevelUpLevels = new ArrayList<>(); + protected Locale locale; + protected int savePeriod; + protected boolean economyAsync; + protected boolean isBroadcastingSkillups; + protected boolean isBroadcastingLevelups; + protected boolean payInCreative; + protected boolean payExploringWhenFlying; + protected boolean addXpPlayer; + protected boolean hideJobsWithoutPermission; + protected int maxJobs; + protected boolean payNearSpawner; + protected boolean modifyChat; + public String modifyChatPrefix; + public String modifyChatSuffix; + public String modifyChatSeparator; + protected int economyBatchDelay; + protected boolean saveOnDisconnect; + protected boolean MultiServerCompatability; +// public boolean LocalOfflinePlayersData; + public boolean MythicMobsEnabled; + public boolean LoggingUse; + public boolean PaymentMethodsMoney; + public boolean PaymentMethodsPoints; + public boolean PaymentMethodsExp; + private HashMap generalMulti = new HashMap<>(); + public int getSelectionTooldID; + + private int ResetTimeHour; + private int ResetTimeMinute; + + // Limits + public HashMap currencyLimitUse = new HashMap<>(); + + public boolean PayForRenaming, PayForEachCraft, SignsEnabled, + SignsColorizeJobName, ShowToplistInScoreboard, useGlobalTimer, useCoreProtect, BlockPlaceUse, + EnableAnounceMessage, useSilkTouchProtection, UseCustomNames, + UseJobsBrowse, PreventSlimeSplit, PreventMagmaCubeSplit, PreventHopperFillUps, PreventBrewingStandFillUps, + BrowseUseNewLook; + public int globalblocktimer, CowMilkingTimer, + CoreProtectInterval, BlockPlaceInterval, InfoUpdateInterval; + public Double TreeFellerMultiplier, gigaDrillMultiplier, superBreakerMultiplier; + public String localeString = ""; + + private boolean FurnacesReassign, BrewingStandsReassign; + private int FurnacesMaxDefault, BrewingStandsMaxDefault, BrowseAmountToShow; + + public boolean useBlockProtection; + public int BlockProtectionDays; + + public boolean useMinimumOveralPayment; + public boolean useMinimumOveralPoints; + public boolean useBreederFinder = false; + private boolean useTnTFinder = false; + public boolean CancelCowMilking; + public boolean fixAtMaxLevel, ToggleActionBar, TitleChangeChat, TitleChangeActionBar, LevelChangeChat, + LevelChangeActionBar, SoundLevelupUse, SoundTitleChangeUse, UseServerAccount, EmptyServerAcountChat, + EmptyServerAcountActionBar, ActionBarsMessageByDefault, ShowTotalWorkers, ShowPenaltyBonus, useDynamicPayment, + JobsGUIOpenOnBrowse, JobsGUIShowChatBrowse, JobsGUISwitcheButtons, JobsGUIOpenOnJoin; + + private int JobsGUIRows, JobsGUIBackButton, + JobsGUIStartPosition, + JobsGUIGroupAmount, + JobsGUISkipAmount; + + private String DecimalPlacesMoney, DecimalPlacesExp, DecimalPlacesPoints; + + public ItemStack guiBackButton; + public ItemStack guiFiller; + + public int JobsTopAmount; + + public Integer levelLossPercentageFromMax, levelLossPercentage, SoundLevelupVolume, SoundLevelupPitch, SoundTitleChangeVolume, + SoundTitleChangePitch, ToplistInScoreboardInterval; + public double MinimumOveralPaymentLimit; + public double MinimumOveralPointsLimit; + + public boolean MonsterDamageUse = false; + public double MonsterDamagePercentage; + public double DynamicPaymentMaxPenalty; + public double DynamicPaymentMaxBonus; + public boolean useMaxPaymentCurve; + public float maxPaymentCurveFactor; + public double TaxesAmount; + public String SoundLevelupSound, SoundTitleChangeSound, ServerAcountName, ServertaxesAcountName; + public ArrayList keys; + public boolean hideJobsInfoWithoutPermission; + public boolean UseTaxes; + public boolean TransferToServerAccount; + public boolean TakeFromPlayersPayment; + + public int AutoJobJoinDelay; + public boolean AutoJobJoinUse; + + public boolean AllowDelevel; + + //BossBar + public boolean BossBarEnabled; + public boolean BossBarShowOnEachAction; + public int BossBarTimer; + public boolean BossBarsMessageByDefault; + + public Parser DynamicPaymentEquation; + + public boolean DisabledWorldsUse; + public List DisabledWorldsList = new ArrayList<>(); + + public List BoostSchedule = new ArrayList<>(); + + public HashMap> commandArgs = new HashMap<>(); + + public boolean DBCleaningJobsUse; + public int DBCleaningJobsLvl; + public boolean DBCleaningUsersUse; + public int DBCleaningUsersDays; + + private boolean ShowNewVersion; + + public HashMap> getCommandArgs() { + return commandArgs; + } + + public CurrencyLimit getLimit(CurrencyType type) { + return currencyLimitUse.get(type); + } + + public GeneralConfigManager(Jobs plugin) { + this.plugin = plugin; + } + + public void setBreederFinder(boolean state) { + this.useBreederFinder = state; + } + + public boolean isUseBreederFinder() { + return this.useBreederFinder; + } + + public void setTntFinder(boolean state) { + this.useTnTFinder = state; + } + + public boolean isUseTntFinder() { + return this.useTnTFinder; + } + + /** + * Get how often in minutes to save job information + * @return how often in minutes to save job information + */ + public synchronized int getSavePeriod() { + return savePeriod; + } + + /** + * Should we use asynchronous economy calls + * @return true - use async + * @return false - use sync + */ + public synchronized boolean isEconomyAsync() { + return economyAsync; + } + + /** + * Function that tells if the system is set to broadcast on skill up + * @return true - broadcast on skill up + * @return false - do not broadcast on skill up + */ + public synchronized boolean isBroadcastingSkillups() { + return isBroadcastingSkillups; + } + + /** + * Function that tells if the system is set to broadcast on level up + * @return true - broadcast on level up + * @return false - do not broadcast on level up + */ + public synchronized boolean isBroadcastingLevelups() { + return isBroadcastingLevelups; + } + + /** + * Function that tells if the player should be paid while in creative + * @return true - pay in creative + * @return false - do not pay in creative + */ + public synchronized boolean payInCreative() { + return payInCreative; + } + + /** + * Function that tells if the player should be paid while exploring and flying + * @return true - pay + * @return false - do not + */ + public synchronized boolean payExploringWhenFlying() { + return payExploringWhenFlying; + } + + public synchronized boolean addXpPlayer() { + return addXpPlayer; + } + + /** + * Function to check if jobs should be hidden to players that lack permission to join the job + * @return + */ + public synchronized boolean getHideJobsWithoutPermission() { + return hideJobsWithoutPermission; + } + + /** + * Function to return the maximum number of jobs a player can join + * @return + */ + public synchronized int getMaxJobs() { + return maxJobs; + } + + /** + * Function to check if you get paid near a spawner is enabled + * @return true - you get paid + * @return false - you don't get paid + */ + public synchronized boolean payNearSpawner() { + return payNearSpawner; + } + + public synchronized boolean getModifyChat() { + return modifyChat; + } + + public String getModifyChatPrefix() { + return modifyChatPrefix; + } + + public String getModifyChatSuffix() { + return modifyChatSuffix; + } + + public String getModifyChatSeparator() { + return modifyChatSeparator; + } + + public synchronized int getEconomyBatchDelay() { + return economyBatchDelay; + } + + public synchronized boolean saveOnDisconnect() { + return saveOnDisconnect; + } + + public synchronized boolean MultiServerCompatability() { + return MultiServerCompatability; + } + + public synchronized Locale getLocale() { + return locale; + } + + public boolean canPerformActionInWorld(Entity ent) { + if (ent == null) + return true; + if (ent.getWorld() == null) + return true; + return canPerformActionInWorld(ent.getWorld()); + } + + public boolean canPerformActionInWorld(Player player) { + if (player == null) + return true; + return canPerformActionInWorld(player.getWorld()); + } + + public boolean canPerformActionInWorld(World world) { + if (world == null) + return true; + if (!this.DisabledWorldsUse) + return true; + return canPerformActionInWorld(world.getName()); + } + + public boolean canPerformActionInWorld(String world) { + if (world == null) + return true; + if (!this.DisabledWorldsUse) + return true; + if (this.DisabledWorldsList.isEmpty()) + return true; + if (this.DisabledWorldsList.contains(world)) + return false; + return true; + } + + public synchronized void reload() { + // general settings + loadGeneralSettings(); + Jobs.getJobsDAO().cleanJobs(); + Jobs.getJobsDAO().cleanUsers(); + // Load locale + Jobs.setLanguageManager(); + Jobs.getLanguageManager().load(); + // title settings + Jobs.setTitleManager(); + Jobs.gettitleManager().load(); + // restricted areas + Jobs.setRestrictedAreaManager(); + Jobs.getRestrictedAreaManager().load(); + // restricted blocks + Jobs.setRestrictedBlockManager(); + Jobs.getRestrictedBlockManager().load(); + // Item/Block/mobs name list + Jobs.setNameTranslatorManager(); + Jobs.getNameTranslatorManager().load(); + // signs information + Jobs.setSignUtil(this.plugin); + Jobs.getSignUtil().LoadSigns(); + // Schedule + Jobs.setScheduleManager(this.plugin); + // Shop + Jobs.setShopManager(); + Jobs.getShopManager().load(); + } + + /** + * Method to load the general configuration + * + * loads from Jobs/generalConfig.yml + */ + private synchronized void loadGeneralSettings() { + File f = new File(Jobs.getFolder(), "generalConfig.yml"); + YamlConfiguration conf = YamlConfiguration.loadConfiguration(f); + CommentedYamlConfiguration write = new CommentedYamlConfiguration(); + LocaleReader c = new LocaleReader(conf, write); + + StringBuilder header = new StringBuilder(); + header.append("General configuration."); + header.append(System.getProperty("line.separator")); + header.append(" The general configuration for the jobs plugin mostly includes how often the plugin"); + header.append(System.getProperty("line.separator")); + header.append("saves user data (when the user is in the game), the storage method, whether"); + header.append(System.getProperty("line.separator")); + header.append("to broadcast a message to the server when a user goes up a skill level."); + header.append(System.getProperty("line.separator")); + header.append(" It also allows admins to set the maximum number of jobs a player can have at"); + header.append(System.getProperty("line.separator")); + header.append("any one time."); + header.append(System.getProperty("line.separator")); + + c.getC().options().copyDefaults(true); + + c.getW().options().header(header.toString()); + + c.getW().addComment("locale-language", "Default language.", "Example: en, ru", "File in locale folder with same name should exist. Example: messages_ru.yml"); + localeString = c.get("locale-language", "en"); + try { + int i = localeString.indexOf('_'); + if (i == -1) { + locale = new Locale(localeString); + } else { + locale = new Locale(localeString.substring(0, i), localeString.substring(i + 1)); + } + } catch (IllegalArgumentException e) { + locale = Locale.getDefault(); + Jobs.getPluginLogger().warning("Invalid locale \"" + localeString + "\" defaulting to " + locale.getLanguage()); + } + + Jobs.getDBManager().start(c); + +// c.getW().addComment("storage-method", "storage method, can be MySQL, sqlite"); +// storageMethod = c.get("storage-method", "sqlite"); +// if (storageMethod.equalsIgnoreCase("mysql")) { +// startMysql(); +// } else if (storageMethod.equalsIgnoreCase("sqlite")) { +// startSqlite(); +// } else { +// Jobs.getPluginLogger().warning("Invalid storage method! Changing method to sqlite!"); +// c.getC().set("storage-method", "sqlite"); +// startSqlite(); +// } +// +// c.getW().addComment("mysql-username", "Requires Mysql."); +// c.get("mysql-username", "root"); +// c.get("mysql-password", ""); +// c.get("mysql-hostname", "localhost:3306"); +// c.get("mysql-database", "minecraft"); +// c.get("mysql-table-prefix", "jobs_"); + + c.getW().addComment("save-period", "How often in minutes you want it to save. This must be a non-zero number"); + c.get("save-period", 10); + if (c.getW().getInt("save-period") <= 0) { + Jobs.getPluginLogger().severe("Save period must be greater than 0! Defaulting to 10 minutes!"); + c.getW().set("save-period", 10); + } + savePeriod = c.getW().getInt("save-period"); + + c.getW().addComment("save-on-disconnect", "Should player data be saved on disconnect?", + "Player data is always periodically auto-saved and autosaved during a clean shutdown.", + "Only enable this if you have a multi-server setup, or have a really good reason for enabling this.", "Turning this on will decrease database performance."); + saveOnDisconnect = c.get("save-on-disconnect", false); + + c.getW().addComment("selectionTool", "Tool used when selecting bounds for restricted area"); + if (CMIMaterial.get(getSelectionTooldID) == null) + getSelectionTooldID = 294; + else + getSelectionTooldID = c.get("selectionTool", 294); + + c.getW().addComment("MultiServerCompatability", "Enable if you are using one data base for multiple servers across bungee network", + "This will force to load players data every time he is logging in to have most up to date data instead of having preloaded data", + "This will enable automatically save-on-disconnect feature"); + MultiServerCompatability = c.get("MultiServerCompatability", false); + if (MultiServerCompatability) + saveOnDisconnect = true; + + c.getW().addComment("Optimizations.NewVersion", + "When set to true staff will be informed about new Jobs plugin version", "You need to have jobs.versioncheck permission node"); + ShowNewVersion = c.get("Optimizations.NewVersion", true); + + c.getW().addComment("Optimizations.DecimalPlaces.Money", + "Decimal places to be shown"); + DecimalPlacesMoney = "%." + c.get("Optimizations.DecimalPlaces.Money", 2) + "f"; + DecimalPlacesExp = "%." + c.get("Optimizations.DecimalPlaces.Exp", 2) + "f"; + DecimalPlacesPoints = "%." + c.get("Optimizations.DecimalPlaces.Points", 2) + "f"; + + c.getW().addComment("Optimizations.DBCleaning.Jobs.Use", + "Warning!!! before enabling this feature, please make data base backup, just in case there will be some issues with data base cleaning", + "When set to true, jobs data base will be cleaned on each startup to avoid having not used jobs", + "keep in mind that this will only clean actual jobs, but not recorded players"); + DBCleaningJobsUse = c.get("Optimizations.DBCleaning.Jobs.Use", false); + c.getW().addComment("Optimizations.DBCleaning.Jobs.Level", "Any one who has jobs level equal or less then set, hies job will be removed from data base"); + DBCleaningJobsLvl = c.get("Optimizations.DBCleaning.Jobs.Level", 1); + + c.getW().addComment("Optimizations.DBCleaning.Users.Use", + "Warning!!! before enabling this feature, please make data base backup, just in case there will be some issues with data base cleaning", + "When set to true, data base will be cleaned on each startup from user data to avoid having old player data"); + DBCleaningUsersUse = c.get("Optimizations.DBCleaning.Users.Use", false); + c.getW().addComment("Optimizations.DBCleaning.Users.Days", "Any one who not played for defined amount of days, will be removed from data base"); + DBCleaningUsersDays = c.get("Optimizations.DBCleaning.Users.Days", 60); + + c.getW().addComment("Optimizations.AutoJobJoin.Use", "Use or not auto join jobs feature", + "If you are not using auto join feature, keep it disabled"); + AutoJobJoinUse = c.get("Optimizations.AutoJobJoin.Use", false); + c.getW().addComment("Optimizations.AutoJobJoin.Delay", "Delay in seconds to perform auto join job if used after player joins server", + "If you using offline server, try to keep it slightly more than your login plugin gives time to enter password", + "For player to auto join job add permission node jobs.autojoin.[jobname]", + "Op players are ignored"); + AutoJobJoinDelay = c.get("Optimizations.AutoJobJoin.Delay", 15); + + c.getW().addComment("Optimizations.AllowDelevel", "When set to true players who gets negative experience can delevel job up to level 1", + "ATTENTION! Set it to true only if you certain that commands performed on level up will not cause issues if player start level and delevel in a row."); + AllowDelevel = c.get("Optimizations.AllowDelevel", false); + +// c.getW().addComment("Optimizations.UseLocalOfflinePlayersData", "With this set to true, offline player data will be taken from local player data files", +// "This will eliminate small lag spikes when request is being send to mojangs servers for offline players data", +// "Theroticali this should work without issues, but if you havving some, just disable", +// "But then you can feal some small (100-200ms) lag spikes while performings some jobs commands"); +// LocalOfflinePlayersData = c.get("Optimizations.UseLocalOfflinePlayersData", true); + + c.getW().addComment("Optimizations.DisabledWorlds.Use", "By setting this to true, Jobs plugin will be disabled in given worlds", + "Only commands can be performed from disabled worlds with jobs.disabledworld.commands permission node"); + DisabledWorldsUse = c.get("Optimizations.DisabledWorlds.Use", false); + DisabledWorldsList = c.getStringList("Optimizations.DisabledWorlds.List", Arrays.asList(Bukkit.getWorlds().get(0).getName())); + +// c.getW().addComment("Optimizations.Purge.Use", "By setting this to true, Jobs plugin will clean data base on startup from all jobs with level 1 and at 0 exp"); +// PurgeUse = c.get("Optimizations.Purge.Use", false); + + c.getW().addComment("Logging.Use", "With this set to true all players jobs actions will be logged to database for easy to see statistics", + "This is still in development and in feature it will expand"); + LoggingUse = c.get("Logging.Use", false); + + c.getW().addComment("broadcast.on-skill-up.use", "Do all players get a message when someone goes up a skill level?"); + isBroadcastingSkillups = c.get("broadcast.on-skill-up.use", false); + + c.getW().addComment("broadcast.on-level-up.use", "Do all players get a message when someone goes up a level?"); + isBroadcastingLevelups = c.get("broadcast.on-level-up.use", false); + c.getW().addComment("broadcast.on-level-up.levels", "For what levels you want to broadcast message? Keep it at 0 if you want for all of them"); + BroadcastingLevelUpLevels = c.getIntList("broadcast.on-level-up.levels", Arrays.asList(0)); + + c.getW().addComment("DailyQuests.ResetTime", "Defines time in 24hour format when we want to give out new daily quests", + "Any daily quests given before reset will be invalid and new ones will be given out"); + ResetTimeHour = c.get("DailyQuests.ResetTime.Hour", 4); + ResetTimeMinute = c.get("DailyQuests.ResetTime.Minute", 0); + + c.getW().addComment("max-jobs", "Maximum number of jobs a player can join.", "Use 0 for no maximum", "Keep in mind that jobs.max.[amount] will bypass this setting"); + maxJobs = c.get("max-jobs", 3); + + c.getW().addComment("hide-jobs-without-permission", "Hide jobs from player if they lack the permission to join the job"); + hideJobsWithoutPermission = c.get("hide-jobs-without-permission", false); + + c.getW().addComment("hide-jobsinfo-without-permission", "Hide jobs info from player if they lack the permission to join the job"); + hideJobsInfoWithoutPermission = c.get("hide-jobsinfo-without-permission", false); + + c.getW().addComment("enable-pay-near-spawner", + "Option to allow payment to be made when killing mobs from a spawner.", + "Use jobs.nearspawner.[amount] to define multiplayer. Example jobs.nearspawner.-0.5 will pay half of payment, jobs.nearspawner.-1 will not pay at all"); + payNearSpawner = c.get("enable-pay-near-spawner", false); + + c.getW().addComment("enable-pay-creative", "Option to allow payment to be made in creative mode. This ignoring when a group has 'jobs.paycreative' permission."); + payInCreative = c.get("enable-pay-creative", false); + + c.getW().addComment("enable-pay-for-exploring-when-flying", "Option to allow payment to be made for exploring when player flies"); + payExploringWhenFlying = c.get("enable-pay-for-exploring-when-flying", false); + + c.getW().addComment("add-xp-player", "Adds the Jobs xp received to the player's Minecraft XP bar"); + addXpPlayer = c.get("add-xp-player", false); + + c.getW().addComment("modify-chat", "Modifys chat to add chat titles. If you're using a chat manager, you may add the tag {jobs} to your chat format and disable this."); + modifyChat = c.get("modify-chat.use", true); + modifyChatPrefix = c.get("modify-chat.prefix", "&c[", true); + modifyChatSuffix = c.get("modify-chat.suffix", "&c]&r ", true); + modifyChatSeparator = c.get("modify-chat.separator", " ", true); + + c.getW().addComment("UseCustomNames", "Do you want to use custom item/block/mob/enchant/color names", + "With this set to true names like Stone:1 will be translated to Granite", "Name list is in TranslatableWords.yml file"); + UseCustomNames = c.get("UseCustomNames", true); + + c.getW().addComment("economy-batch-delay", "Changes how often, in seconds, players are paid out. Default is 5 seconds.", + "Setting this too low may cause tick lag. Increase this to improve economy performance (at the cost of delays in payment)"); + economyBatchDelay = c.get("economy-batch-delay", 5); + + c.getW().addComment("economy-async", "Enable async economy calls.", "Disable this if you have issues with payments or your plugin is not thread safe."); + economyAsync = c.get("economy-async", true); + + c.getW().addComment("Economy.PaymentMethods", + "By disabling one of thies, players no longer will get particular payment.", + "Useful for removing particular payment method without editing whole jobConfig file"); + PaymentMethodsMoney = c.get("Economy.PaymentMethods.Money", true); + PaymentMethodsPoints = c.get("Economy.PaymentMethods.Points", true); + PaymentMethodsExp = c.get("Economy.PaymentMethods.Exp", true); + + c.getW().addComment("Economy.GeneralMulti", + "Can be used to change payment amounts for all jobs and all actions if you want to readjust them", + "Amounts are in percentage, above 0 will increase payments", + "Amount belove 0 will decrease payments", + "If action pays negative amount, then value above 0 will increase that negative value", + "So is placing diamond ore takes from you 10 bucks, then by setting 50 for money income, you will be charged 15 bucks for placing it", + "If you are getting paid 10 for placing wood, then same value of 50 for money income, will result you getting 15 bucks", + "This only effects base income value"); + for (CurrencyType one : CurrencyType.values()) { + generalMulti.put(one, c.get("Economy.GeneralMulti." + one.name(), 0D) / 100D); + } + + c.getW().addComment("Economy.MinimumOveralPayment.use", + "Determines minimum payment. In example if player uses McMMO treefeller and earns only 20%, but at same time he gets 25% penalty from dynamic payment. He can 'get' negative amount of money", + "This will limit it to particular percentage", "Works only when original payment is above 0"); + useMinimumOveralPayment = c.get("Economy.MinimumOveralPayment.use", true); + MinimumOveralPaymentLimit = c.get("Economy.MinimumOveralPayment.limit", 0.1); + c.getW().addComment("Economy.MinimumOveralPoints.use", + "Determines minimum payment. In example if player uses McMMO treefeller and earns only 20%, but at same time he gets 25% penalty from dynamic payment. He can 'get' negative amount of money", + "This will limit it to particular percentage", "Works only when original payment is above 0"); + useMinimumOveralPoints = c.get("Economy.MinimumOveralPoints.use", true); + MinimumOveralPointsLimit = c.get("Economy.MinimumOveralPoints.limit", 0.1); + + c.getW().addComment("Economy.DynamicPayment.use", "Do you want to use dinamic payment dependent on how many players already working for jobs", + "This can help automatically lift up payments for not so popular jobs and lower for most popular ones"); + useDynamicPayment = c.get("Economy.DynamicPayment.use", false); + + String maxExpEquationInput = c.get("Economy.DynamicPayment.equation", "((totalworkers / totaljobs) - jobstotalplayers)/10.0"); + try { + DynamicPaymentEquation = new Parser(maxExpEquationInput); + // test equation + DynamicPaymentEquation.setVariable("totalworkers", 100); + DynamicPaymentEquation.setVariable("totaljobs", 10); + DynamicPaymentEquation.setVariable("jobstotalplayers", 10); + DynamicPaymentEquation.getValue(); + } catch (Exception e) { + Jobs.consoleMsg("&cDynamic payment equation has an invalid property. Disabling feature!"); + useDynamicPayment = false; + } + + DynamicPaymentMaxPenalty = c.get("Economy.DynamicPayment.MaxPenalty", 25.0); + DynamicPaymentMaxBonus = c.get("Economy.DynamicPayment.MaxBonus", 100.0); + c.getW().addComment("Economy.MaxPayment.curve.use", "Enabling this feature will mean players will still earn once they reach cap but " + + "will loose a percentage the higher over cap they go. Controlled by a factor. math is ```100/((1/factor*percentOver^2)+1)```"); + useMaxPaymentCurve = c.get("Economy.MaxPayment.curve.use",false); + int temp = c.get("Economy.MaxPayment.curve.factor",10); + maxPaymentCurveFactor = ((float)temp)/1000; + c.getW().addComment("Economy.UseServerAcount", "Server economy account", "With this enabled, players will get money from defined user (server account)", + "If this account don't have enough money to pay for players for, player will get message"); + UseServerAccount = c.get("Economy.UseServerAcount", false); + c.getW().addComment("Economy.AcountName", "Username should be with Correct capitalization"); + ServerAcountName = c.get("Economy.AcountName", "Server"); + c.getW().addComment("Economy.Taxes.use", "Do you want to use taxes feature for jobs payment"); + UseTaxes = c.get("Economy.Taxes.use", false); + c.getW().addComment("Economy.Taxes.AccountName", "Username should be with Correct capitalization, it can be same as setup in server account before"); + ServertaxesAcountName = c.get("Economy.Taxes.AccountName", "Server"); + c.getW().addComment("Economy.Taxes.Amount", "Amount in percentage"); + TaxesAmount = c.get("Economy.Taxes.Amount", 15.0); + c.getW().addComment("Economy.Taxes.TransferToServerAccount", "Do you want to transfer taxes to server account"); + TransferToServerAccount = c.get("Economy.Taxes.TransferToServerAccount", true); + c.getW().addComment("Economy.Taxes.TakeFromPlayersPayment", + "With this true, taxes will be taken from players payment and he will get less money than its shown in jobs info", + "When its false player will get full payment and server account will get taxes amount to hes account"); + TakeFromPlayersPayment = c.get("Economy.Taxes.TakeFromPlayersPayment", false); + + // Money limit + CurrencyLimit limit = new CurrencyLimit(); + c.getW().addComment("Economy.Limit.Money", "Money gain limit", "With this enabled, players will be limited how much they can make in defined time", + "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours"); + limit.setEnabled(c.get("Economy.Limit.Money.Use", false)); + List list = new ArrayList<>(); + c.getW().addComment("Economy.Limit.Money.StopWithExp", "Do you want to stop money gain when exp limit reached?"); + if (c.get("Economy.Limit.Money.StopWithExp", false)) + list.add(CurrencyType.EXP); + c.getW().addComment("Economy.Limit.Money.StopWithPoint", "Do you want to stop money gain when point limit reached?"); + if (c.get("Economy.Limit.Money.StopWithPoint", false)) + list.add(CurrencyType.POINTS); + limit.setStopWith(list); + c.getW().addComment("Economy.Limit.Money.MoneyLimit", + "Equation to calculate max limit. Option to use total level to include players total amount levels of current jobs", + "You can always use simple number to set money limit", + "Default equation is: 500+500*(totallevel/100), this will add 1% from 500 for each level player have", + "So player with 2 jobs with level 15 and 22 will have 685 limit"); + String MoneyLimit = c.get("Economy.Limit.Money.MoneyLimit", "500+500*(totallevel/100)"); + try { + Parser Equation = new Parser(MoneyLimit); + Equation.setVariable("totallevel", 1); + Equation.getValue(); + limit.setMaxEquation(Equation); + } catch (Exception e) { + Jobs.getPluginLogger().warning("MoneyLimit has an invalid value. Disabling money limit!"); + limit.setEnabled(false); + } + c.getW().addComment("Economy.Limit.Money.TimeLimit", "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours"); + limit.setTimeLimit(c.get("Economy.Limit.Money.TimeLimit", 3600)); + c.getW().addComment("Economy.Limit.Money.AnnouncementDelay", "Delay between announcements about reached money limit", + "Keep this from 30 to 5 min (300), as players can get annoyed of constant message displaying"); + limit.setAnnouncementDelay(c.get("Economy.Limit.Money.AnnouncementDelay", 30)); + currencyLimitUse.put(CurrencyType.MONEY, limit); + + // Point limit + limit = new CurrencyLimit(); + list = new ArrayList<>(); + c.getW().addComment("Economy.Limit.Point", "Point gain limit", "With this enabled, players will be limited how much they can make in defined time"); + limit.setEnabled(c.get("Economy.Limit.Point.Use", false)); + c.getW().addComment("Economy.Limit.Point.StopWithExp", "Do you want to stop Point gain when exp limit reached?"); + if (c.get("Economy.Limit.Point.StopWithExp", false)) + list.add(CurrencyType.EXP); + c.getW().addComment("Economy.Limit.Point.StopWithMoney", "Do you want to stop Point gain when money limit reached?"); + if (c.get("Economy.Limit.Point.StopWithMoney", false)) + list.add(CurrencyType.MONEY); + limit.setStopWith(list); + c.getW().addComment("Economy.Limit.Point.Limit", + "Equation to calculate max limit. Option to use total level to include players total amount levels of current jobs", + "You can always use simple number to set limit", + "Default equation is: 500+500*(totallevel/100), this will add 1% from 500 for each level player have", + "So player with 2 jobs with level 15 and 22 will have 685 limit"); + String PointLimit = c.get("Economy.Limit.Point.Limit", "500+500*(totallevel/100)"); + try { + Parser Equation = new Parser(PointLimit); + Equation.setVariable("totallevel", 1); + Equation.getValue(); + limit.setMaxEquation(Equation); + } catch (Exception e) { + Jobs.getPluginLogger().warning("PointLimit has an invalid value. Disabling money limit!"); + limit.setEnabled(false); + } + c.getW().addComment("Economy.Limit.Point.TimeLimit", "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours"); + limit.setTimeLimit(c.get("Economy.Limit.Point.TimeLimit", 3600)); + c.getW().addComment("Economy.Limit.Point.AnnouncementDelay", "Delay between announcements about reached limit", + "Keep this from 30 to 5 min (300), as players can get annoyed of constant message displaying"); + limit.setAnnouncementDelay(c.get("Economy.Limit.Point.AnnouncementDelay", 30)); + currencyLimitUse.put(CurrencyType.POINTS, limit); + + // Exp limit + limit = new CurrencyLimit(); + list = new ArrayList<>(); + c.getW().addComment("Economy.Limit.Exp", "Exp gain limit", "With this enabled, players will be limited how much they can get in defined time", + "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours"); + limit.setEnabled(c.get("Economy.Limit.Exp.Use", false)); + c.getW().addComment("Economy.Limit.Exp.StopWithMoney", "Do you want to stop exp gain when money limit reached?"); + if (c.get("Economy.Limit.Exp.StopWithMoney", false)) + list.add(CurrencyType.MONEY); + c.getW().addComment("Economy.Limit.Exp.StopWithPoint", "Do you want to stop exp gain when point limit reached?"); + if (c.get("Economy.Limit.Exp.StopWithPoint", false)) + list.add(CurrencyType.POINTS); + limit.setStopWith(list); + c.getW().addComment("Economy.Limit.Exp.Limit", "Equation to calculate max money limit. Option to use total level to include players total amount of current jobs", + "You can always use simple number to set exp limit", + "Default equation is: 5000+5000*(totallevel/100), this will add 1% from 5000 for each level player have", + "So player with 2 jobs with level 15 and 22 will have 6850 limit"); + String expLimit = c.get("Economy.Limit.Exp.Limit", "5000+5000*(totallevel/100)"); + try { + Parser Equation = new Parser(expLimit); + Equation.setVariable("totallevel", 1); + Equation.getValue(); + limit.setMaxEquation(Equation); + } catch (Exception e) { + Jobs.getPluginLogger().warning("ExpLimit has an invalid value. Disabling money limit!"); + limit.setEnabled(false); + } + c.getW().addComment("Economy.Limit.Exp.TimeLimit", "Time in seconds: 60 = 1 min, 3600 = 1 hour, 86400 = 24 hours"); + limit.setTimeLimit(c.get("Economy.Limit.Exp.TimeLimit", 3600)); + c.getW().addComment("Economy.Limit.Exp.AnnouncementDelay", "Delay between announcements about reached Exp limit", + "Keep this from 30 to 5 min (300), as players can get annoyed of constant message displaying"); + limit.setAnnouncementDelay(c.get("Economy.Limit.Exp.AnnouncementDelay", 30)); + currencyLimitUse.put(CurrencyType.EXP, limit); + + c.getW().addComment("Economy.Repair.PayForRenaming", "Do you want to give money for only renaming items in anvil", + "Players will get full pay as they would for remaining two items when they only renaming one", + "This is not big issue, but if you want to disable it, you can"); + PayForRenaming = c.get("Economy.Repair.PayForRenaming", true); + + c.getW().addComment("Economy.Crafting.PayForEachCraft", + "With this true, player will get money for all crafted items instead of each crafting action (like with old payment mechanic)", + "By default its false, as you can make ALOT of money if prices kept from old payment mechanics"); + PayForEachCraft = c.get("Economy.Crafting.PayForEachCraft", false); + + c.getW().addComment("Economy.MilkingCow.CancelMilking", "With this true, when timer is still going, cow milking event will be canceled", + "With this false, player will get bucket of milk, but still no payment"); + CancelCowMilking = c.get("Economy.MilkingCow.CancelMilking", false); + c.getW().addComment("Economy.MilkingCow.Timer", + "How ofter player can milk cows in seconds. Keep in mind that by default player can milk cow indefinitely and as often as he wants", + "Set to 0 if you want to disable timer"); + CowMilkingTimer = c.get("Economy.MilkingCow.Timer", 30) * 1000; + + c.getW().addComment("ExploitProtections.Furnaces.Reassign", + "When enabled, players interacted furnaces will be saved into file and will be reassigned after restart to keep giving out money", + "Players will no longer need to click on furnace to get paid from it after server restart"); + FurnacesReassign = c.get("ExploitProtections.Furnaces.Reassign", true); + c.getW().addComment("ExploitProtections.Furnaces.MaxDefaultAvailable", + "Defines max available furnaces each player can have to get paid from", + "This can be overridden with jobs.maxfurnaces.[amount] permission node"); + FurnacesMaxDefault = c.get("ExploitProtections.Furnaces.MaxDefaultAvailable", 20); + + c.getW().addComment("ExploitProtections.BrewingStands.Reassign", + "When enabled, players interacted brewing stands will be saved into file and will be reassigned after restart to keep giving out money", + "Players will no longer need to click on brewing stand to get paid from it after server restart"); + BrewingStandsReassign = c.get("ExploitProtections.BrewingStands.Reassign", true); + c.getW().addComment("ExploitProtections.BrewingStands.MaxDefaultAvailable", + "Defines max available brewing stands each player can have to get paid from", + "Set to 0 if you want to disable this limitation", + "This can be overridden with jobs.maxbrewingstands.[amount] permission node"); + BrewingStandsMaxDefault = c.get("ExploitProtections.BrewingStands.MaxDefaultAvailable", 20); + + c.getW().addComment("ExploitProtections.General.PlaceAndBreakProtection", + "Enable blocks protection, like ore, from exploiting by placing and destroying same block again and again.", + "Modify restrictedBlocks.yml for blocks you want to protect"); + useBlockProtection = c.get("ExploitProtections.General.PlaceAndBreakProtection", true); + + c.getW().addComment("ExploitProtections.General.KeepDataFor", + "For how long in days to keep block protection data in data base", "This will clean block data which ones have -1 as cooldown value", + "Data base cleanup will be performed on each server startup"); + BlockProtectionDays = c.get("ExploitProtections.General.KeepDataFor", 14); + + c.getW().addComment("ExploitProtections.General.GlobalBlockTimer", "All blocks will be protected X sec after player places it on ground."); + useGlobalTimer = c.get("ExploitProtections.General.GlobalBlockTimer.use", true); + globalblocktimer = c.get("ExploitProtections.General.GlobalBlockTimer.timer", 3); + + c.getW().addComment("ExploitProtections.General.SilkTouchProtection", "Enable silk touch protection.", + "With this enabled players wont get paid for breaked blocks from restrictedblocks list with silk touch tool."); + useSilkTouchProtection = c.get("ExploitProtections.General.SilkTouchProtection", false); + + c.getW().addComment("ExploitProtections.General.MonsterDamage.Use", "This section controls how much damage player should do to monster for player to get paid", + "This prevents from killing monsters in one hit when they suffer in example fall damage"); + MonsterDamageUse = c.get("ExploitProtections.General.MonsterDamage.Use", false); + MonsterDamagePercentage = c.get("ExploitProtections.General.MonsterDamage.Percentage", 60); + + c.getW().addComment("ExploitProtections.McMMO", "McMMO abilities"); + c.getW().addComment("ExploitProtections.McMMO.TreeFellerMultiplier", "Players will get part of money from cutting trees with treefeller ability enabled.", + "0.2 means 20% of original price"); + TreeFellerMultiplier = c.get("ExploitProtections.McMMO.TreeFellerMultiplier", 0.2); + c.getW().addComment("ExploitProtections.McMMO.gigaDrillMultiplier", "Players will get part of money from braking blocks with gigaDrill ability enabled.", + "0.2 means 20% of original price"); + gigaDrillMultiplier = c.get("ExploitProtections.McMMO.gigaDrillMultiplier", 0.2); + c.getW().addComment("ExploitProtections.McMMO.superBreakerMultiplier", "Players will get part of money from braking blocks with super breaker ability enabled.", + "0.2 means 20% of original price"); + superBreakerMultiplier = c.get("ExploitProtections.McMMO.superBreakerMultiplier", 0.2); + + c.getW().addComment("ExploitProtections.MythicMobs", "MythicMobs plugin support", "Disable if you having issues with it or using old version"); + MythicMobsEnabled = c.get("ExploitProtections.MythicMobs.enabled", true); + + c.getW().addComment("ExploitProtections.Spawner.PreventSlimeSplit", "Prevent slime splitting when they are from spawner", + "Protects agains exploiting as new splited slimes is treated as naturally spawned and not from spawner"); + PreventSlimeSplit = c.get("ExploitProtections.Spawner.PreventSlimeSplit", true); + c.getW().addComment("ExploitProtections.Spawner.PreventMagmaCubeSplit", "Prevent magmacube splitting when they are from spawner"); + PreventMagmaCubeSplit = c.get("ExploitProtections.Spawner.PreventMagmaCubeSplit", true); + + c.getW().addComment("ExploitProtections.Smelt.PreventHopperFillUps", "Prevent payments when hoppers moving items into furnace", "Player will not get paid, but items will be smelted"); + PreventHopperFillUps = c.get("ExploitProtections.Smelt.PreventHopperFillUps", true); + c.getW().addComment("ExploitProtections.Smelt.PreventMagmaCubeSplit", "Prevent payments when hoppers moving items into brewing stands", + "Player will not get paid, but items will be brewd as they supose too"); + PreventBrewingStandFillUps = c.get("ExploitProtections.Brew.PreventBrewingStandFillUps", true); + + c.getW().addComment("use-breeder-finder", "Breeder finder.", + "If you are not using breeding payment, you can disable this to save little resources. Really little."); + useBreederFinder = c.get("use-breeder-finder", true); + + c.getW().addComment("old-job", + "Old job save", "Players can leave job and return later with some level loss during that", + "You can fix players level if hes job level is at max level"); + levelLossPercentage = c.get("old-job.level-loss-percentage", 30); + fixAtMaxLevel = c.get("old-job.fix-at-max-level", true); + c.getW().addComment("old-job.level-loss-from-max-level", + "Percentage to loose when leaving job at max level", + "Only works when fix-at-max-level is set to false"); + levelLossPercentageFromMax = c.get("old-job.level-loss-from-max-level", levelLossPercentage); + + c.getW().addComment("ActionBars.Messages.EnabledByDefault", "When this set to true player will see action bar messages by default"); + ActionBarsMessageByDefault = c.get("ActionBars.Messages.EnabledByDefault", true); + + c.getW().addComment("BossBar.Enabled", "Enables BossBar feature", "Works only from 1.9 mc version"); + BossBarEnabled = c.get("BossBar.Enabled", true); + + if (BossBarEnabled == true) { + if (Jobs.getVersionCheckManager().getVersion().isLower(Version.v1_9_R1)) { + Jobs.consoleMsg("&c[Jobs] Your server version don't support BossBar. This feature will be disabled."); + c.getW().set("BossBar.Enabled", false); + BossBarEnabled = false; + } + } + + c.getW().addComment("BossBar.Messages.EnabledByDefault", "When this set to true player will see Bossbar messages by default"); + BossBarsMessageByDefault = c.get("BossBar.Messages.EnabledByDefault", true); + + c.getW().addComment("BossBar.ShowOnEachAction", "If enabled boss bar will update after each action", + "If disabled, BossBar will update only on each payment. This can save some server resources"); + BossBarShowOnEachAction = c.get("BossBar.ShowOnEachAction", false); + c.getW().addComment("BossBar.Timer", "How long in sec to show BossBar for player", + "If you have disabled ShowOnEachAction, then keep this number higher than payment interval for better experience"); + BossBarTimer = c.get("BossBar.Timer", economyBatchDelay + 1); + + c.getW().addComment("ShowActionBars", "You can enable/disable message shown for players in action bar"); + TitleChangeActionBar = c.get("ShowActionBars.OnTitleChange", true); + LevelChangeActionBar = c.get("ShowActionBars.OnLevelChange", true); + EmptyServerAcountActionBar = c.get("ShowActionBars.OnEmptyServerAcount", true); + + c.getW().addComment("ShowChatMessage", "Chat messages", "You can enable/disable message shown for players in chat"); + TitleChangeChat = c.get("ShowChatMessage.OnTitleChange", true); + LevelChangeChat = c.get("ShowChatMessage.OnLevelChange", true); + EmptyServerAcountChat = c.get("ShowChatMessage.OnEmptyServerAcount", true); + + c.getW().addComment("Sounds", "Sounds", "Extra sounds on some events", + "All sounds can be found in https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html"); + SoundLevelupUse = c.get("Sounds.LevelUp.use", true); + SoundLevelupSound = c.get("Sounds.LevelUp.sound", "ENTITY_PLAYER_LEVELUP"); + SoundLevelupVolume = c.get("Sounds.LevelUp.volume", 1); + SoundLevelupPitch = c.get("Sounds.LevelUp.pitch", 3); + SoundTitleChangeUse = c.get("Sounds.TitleChange.use", true); + SoundTitleChangeSound = c.get("Sounds.TitleChange.sound", "ENTITY_PLAYER_LEVELUP"); + SoundTitleChangeVolume = c.get("Sounds.TitleChange.volume", 1); + SoundTitleChangePitch = c.get("Sounds.TitleChange.pitch", 3); + + c.getW().addComment("Signs", "You can disable this to save SMALL amount of server resources"); + SignsEnabled = c.get("Signs.Enable", true); + SignsColorizeJobName = c.get("Signs.Colors.ColorizeJobName", true); + c.getW().addComment("Signs.InfoUpdateInterval", + "This is interval in sec in which signs will be updated. This is not continues update, signs are updated only on levelup, job leave, job join or similar action."); + c.getW().addComment("Signs.InfoUpdateInterval", + "This is update for same job signs, to avoid huge lag if you have bunch of same type signs. Keep it from 1 to as many sec you want"); + InfoUpdateInterval = c.get("Signs.InfoUpdateInterval", 5); + + c.getW().addComment("Scoreboard.ShowToplist", "This will enables to show top list in scoreboard instead of chat"); + ShowToplistInScoreboard = c.get("Scoreboard.ShowToplist", true); + + c.getW().addComment("Scoreboard.interval", "For how long to show scoreboard"); + ToplistInScoreboardInterval = c.get("Scoreboard.interval", 10); + + c.getW().addComment("JobsBrowse.ShowTotalWorkers", "Do you want to show total amount of workers for job in jobs browse window"); + ShowTotalWorkers = c.get("JobsBrowse.ShowTotalWorkers", true); + c.getW().addComment("JobsBrowse.ShowPenaltyBonus", "Do you want to show penalty and bonus in jobs browse window. Only works if this feature is enabled"); + ShowPenaltyBonus = c.get("JobsBrowse.ShowPenaltyBonus", true); + + c.getW().addComment("JobsBrowse.UseNewLook", "Defines if you want to use new /jobs browse look or old one"); + BrowseUseNewLook = c.get("JobsBrowse.UseNewLook", true); + c.getW().addComment("JobsBrowse.AmountToShow", "Defines amount of jobs to be shown in one page for /jobs browse"); + BrowseAmountToShow = c.get("JobsBrowse.AmountToShow", 5); + + c.getW().addComment("JobsGUI.OpenOnBrowse", "Do you want to show GUI when performing /jobs browse command"); + JobsGUIOpenOnBrowse = c.get("JobsGUI.OpenOnBrowse", true); + c.getW().addComment("JobsGUI.ShowChatBrowse", "Do you want to show chat information when performing /jobs browse command"); + JobsGUIShowChatBrowse = c.get("JobsGUI.ShowChatBrowse", true); + c.getW().addComment("JobsGUI.SwitcheButtons", "With true left mouse button will join job and right will show more info", + "With false left mouse button will show more info, right will join job", "Don't forget to adjust locale file"); + JobsGUISwitcheButtons = c.get("JobsGUI.SwitcheButtons", false); + c.getW().addComment("JobsGUI.Rows", "Defines size in rows of GUI"); + JobsGUIRows = c.get("JobsGUI.Rows", 5); + c.getW().addComment("JobsGUI.BackButtonSlot", "Defines back button slot in GUI"); + JobsGUIBackButton = c.get("JobsGUI.BackButtonSlot", 37); + c.getW().addComment("JobsGUI.StartPosition", "Defines start position in gui from which job icons will be shown"); + JobsGUIStartPosition = c.get("JobsGUI.StartPosition", 11); + c.getW().addComment("JobsGUI.GroupAmount", "Defines By how many jobs we need to group up"); + JobsGUIGroupAmount = c.get("JobsGUI.GroupAmount", 7); + c.getW().addComment("JobsGUI.SkipAmount", "Defines By how many slot we need to skip after group"); + JobsGUISkipAmount = c.get("JobsGUI.SkipAmount", 2); + + c.getW().addComment("JobsTop.AmountToShow", "Defines amount of players to be shown in one page for /jobs top & /jobs gtop"); + JobsTopAmount = c.get("JobsTop.AmountToShow", 15); + + CMIMaterial tmat = null; + tmat = CMIMaterial.get(c.get("JobsGUI.BackButton.Material", "JACK_O_LANTERN")); + guiBackButton = tmat == null ? CMIMaterial.JACK_O_LANTERN.newItemStack() : tmat.newItemStack(); + + tmat = CMIMaterial.get(c.get("JobsGUI.Filler.Material", "STAINED_GLASS_PANE")); + guiFiller = tmat == null ? CMIMaterial.GREEN_STAINED_GLASS_PANE.newItemStack() : tmat.newItemStack(); + +// c.getW().addComment("Schedule.Boost.Enable", "Do you want to enable scheduler for global boost"); +// useGlobalBoostScheduler = c.get("Schedule.Boost.Enable", false); + + try { + c.getW().save(f); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public int getSelectionTooldID() { + return getSelectionTooldID; + } + + public boolean isShowNewVersion() { + return ShowNewVersion; + } + + public int getResetTimeHour() { + return ResetTimeHour; + } + + public void setResetTimeHour(int resetTimeHour) { + ResetTimeHour = resetTimeHour; + } + + public int getResetTimeMinute() { + return ResetTimeMinute; + } + + public void setResetTimeMinute(int resetTimeMinute) { + ResetTimeMinute = resetTimeMinute; + } + + public boolean isFurnacesReassign() { + return FurnacesReassign; + } + + public boolean isBrewingStandsReassign() { + return BrewingStandsReassign; + } + + public int getFurnacesMaxDefault() { + return FurnacesMaxDefault; + } + + public int getBrewingStandsMaxDefault() { + return BrewingStandsMaxDefault; + } + + public int getBrowseAmountToShow() { + return BrowseAmountToShow; + } + + public String getDecimalPlacesMoney() { + return DecimalPlacesMoney; + } + + public String getDecimalPlacesExp() { + return DecimalPlacesExp; + } + + public String getDecimalPlacesPoints() { + return DecimalPlacesPoints; + } + + public int getJobsGUIRows() { + if (JobsGUIRows < 1) + JobsGUIRows = 1; + return JobsGUIRows; + } + + public int getJobsGUIBackButton() { + if (JobsGUIBackButton < 1) + JobsGUIBackButton = 1; + if (JobsGUIBackButton > JobsGUIRows * 9) + JobsGUIBackButton = JobsGUIRows * 9; + return JobsGUIBackButton - 1; + } + + public int getJobsGUIStartPosition() { + if (JobsGUIBackButton < 1) + JobsGUIBackButton = 1; + return JobsGUIStartPosition - 1; + } + + public int getJobsGUIGroupAmount() { + return JobsGUIGroupAmount; + } + + public int getJobsGUISkipAmount() { + return JobsGUISkipAmount; + } + + public Double getGeneralMulti(CurrencyType type) { + return generalMulti.get(type); + } + +} diff --git a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java index e2c23521..9bfe0e3a 100644 --- a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java @@ -1,686 +1,687 @@ -package com.gamingmesh.jobs.config; - -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Enumeration; -import java.util.Iterator; -import java.util.List; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; - -import org.bukkit.configuration.file.YamlConfiguration; - -import com.gamingmesh.jobs.Jobs; -import com.gamingmesh.jobs.container.LocaleReader; - -public class LanguageManager { - - public LanguageManager() { - } - - private List languages = new ArrayList<>(); - - public List getLanguages() { - return languages; - } - - public static List getClassesFromPackage(String pckgname, String cleaner) throws ClassNotFoundException { - List result = new ArrayList<>(); - try { - for (URL jarURL : ((URLClassLoader) Jobs.class.getClassLoader()).getURLs()) { - try { - result.addAll(getClassesInSamePackageFromJar(pckgname, jarURL.toURI().getPath(), cleaner)); - } catch (URISyntaxException e) { - } - } - } catch (NullPointerException x) { - throw new ClassNotFoundException(pckgname + " does not appear to be a valid package (Null pointer exception)"); - } - return result; - } - - private static List getClassesInSamePackageFromJar(String packageName, String jarPath, String cleaner) { - JarFile jarFile = null; - List listOfCommands = new ArrayList<>(); - try { - jarFile = new JarFile(jarPath); - Enumeration en = jarFile.entries(); - while (en.hasMoreElements()) { - JarEntry entry = en.nextElement(); - String entryName = entry.getName(); - packageName = packageName.replace(".", "/"); - if (entryName != null && entryName.endsWith(".yml") && entryName.startsWith(packageName)) { - String name = entryName.replace(packageName, "").replace(".yml", "").replace("/", ""); - if (name.contains("$")) - name = name.split("\\$")[0]; - if (cleaner != null) - name = name.replace(cleaner, ""); - listOfCommands.add(name); - } - } - } catch (Exception e) { - } finally { - if (jarFile != null) - try { - jarFile.close(); - } catch (Exception e) { - } - } - return listOfCommands; - } - - /** - * Method to load the language file configuration - * - * loads from Jobs/locale/messages_en.yml - */ - synchronized void load() { - - // This should be present to copy over default locale files into locale folder if file doesn't exist. Grabs all files from plugin file. - languages = new ArrayList<>(); - try { - languages.addAll(getClassesFromPackage("locale", "messages_")); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - for (Iterator e1 = this.languages.iterator(); e1.hasNext();) { - String lang = e1.next(); - YmlMaker langFile = new YmlMaker(Jobs.getInstance(), "locale" + File.separator + "messages_" + lang + ".yml"); - langFile.saveDefaultConfig(); - } - //Up to here. - - String ls = Jobs.getGCManager().localeString; - - if (ls == null || ls.equals("")) - return; - - languages.clear(); - languages.add("en"); - - File customLocaleFile = new File(Jobs.getFolder(), "locale" + File.separator + "messages_" + ls + ".yml"); - if (!customLocaleFile.exists() && !ls.equalsIgnoreCase("en")) - languages.add(ls); - - for (String lang : languages) { - File f = new File(Jobs.getFolder(), "locale" + File.separator + "messages_" + lang + ".yml"); - - // Fail safe if file get corrupted and being created with corrupted data, we need to recreate it - if ((f.length() / 1024) > 1024) { - f.delete(); - f = new File(Jobs.getFolder(), "locale" + File.separator + "messages_" + lang + ".yml"); - } - - YamlConfiguration config = YamlConfiguration.loadConfiguration(f); - CommentedYamlConfiguration writer = new CommentedYamlConfiguration(); - - LocaleReader c = new LocaleReader(config, writer); - - c.getC().options().copyDefaults(true); - - Jobs.getGCManager().commandArgs.clear(); - - c.get("economy.error.nomoney", "&cSorry, no money left in national bank!"); - c.get("limitedItem.error.levelup", "&cYou need to levelup in [jobname] to use this item!"); - c.get("general.Spawner", "&r[type] Spawner"); - c.get("general.info.toplineseparator", "&7*********************** &6%playername% &7***********************"); - c.get("general.info.separator", "&7*******************************************************"); - c.get("general.info.time.days", "&e%days% &6days "); - c.get("general.info.time.hours", "&e%hours% &6hours "); - c.get("general.info.time.mins", "&e%mins% &6min "); - c.get("general.info.time.secs", "&e%secs% &6sec "); - c.get("general.info.invalidPage", "&cInvalid page"); - c.get("general.info.true", "&2True"); - c.get("general.info.false", "&cFalse"); - c.get("general.admin.error", "&cThere was an error in the command."); - c.get("general.admin.success", "&eYour command has been performed."); - c.get("general.error.noHelpPage", "&cThere is no help page by this number!"); - c.get("general.error.notNumber", "&ePlease use numbers!"); - c.get("general.error.job", "&cThe job you have selected does not exist!"); - c.get("general.error.noCommand", "&cThere is no command by this name!"); - c.get("general.error.permission", "&cYou do not have permission to do that!"); - c.get("general.error.noinfo", "&cNo information found!"); - c.get("general.error.noinfoByPlayer", "&cNo information found by [%playername%] player name!"); - c.get("general.error.ingame", "&cYou can use this command only in game!"); - c.get("general.error.fromconsole", "&cYou can use this command only from console!"); - c.get("general.error.worldisdisabled", "&cYou can't use command in this world!"); - - c.get("general.error.newFurnaceRegistration", "&eRegistered new ownership for furnace &7[current]&e/&f[max]"); - c.get("general.error.newBrewingRegistration", "&eRegistered new ownership for brewing stand &7[current]&e/&f[max]"); - c.get("general.error.noFurnaceRegistration", "&cYou reached max furnace count!"); - c.get("general.error.noBrewingRegistration", "&cYou reached max brewing stand count!"); - - c.get("command.help.output.info", "Type /jobs [cmd] ? for more information about a command."); - c.get("command.help.output.cmdUsage", "&2Usage: &7[command]"); - c.get("command.help.output.label", "Jobs"); - - c.get("command.help.output.cmdInfoFormat", "[command] &f- &2[description]"); - c.get("command.help.output.cmdFormat", "&7/[command]&f[arguments]"); - c.get("command.help.output.helpPageDescription", "&2* [description]"); - - c.get("command.help.output.title", "&e-------&e ======= &6Jobs &e======= &e-------"); - c.get("command.help.output.page", "&e-----&e ====== Page &6[1] &eof &6[2] &e====== &e-----"); - c.get("command.help.output.fliperSimbols", "&e----------"); - - c.get("command.help.output.prevPage", "&2----<< &6Prev "); - c.get("command.help.output.prevPageOff", "&7----<< Prev "); - c.get("command.help.output.nextPage", "&6 Next &2>>----"); - c.get("command.help.output.nextPageOff", "&7 Next >>----"); - c.get("command.help.output.pageCount", "&2[current]/[total]"); - - c.get("command.moneyboost.help.info", "Boosts Money gain for all players"); - c.get("command.moneyboost.help.args", "[jobname] [rate]"); - Jobs.getGCManager().commandArgs.put("moneyboost", Arrays.asList("[jobname]", "[rate]")); - c.get("command.moneyboost.output.allreset", "All money boost turned off"); - c.get("command.moneyboost.output.jobsboostreset", "Money boost for %jobname% was turned off"); - c.get("command.moneyboost.output.nothingtoreset", "Nothing to reset"); - c.get("command.moneyboost.output.boostalladded", "Money boost of %boost% added for all jobs!"); - c.get("command.moneyboost.output.boostadded", "Money boost of &e%boost% &aadded for &e%jobname%!"); - c.get("command.moneyboost.output.infostats", "&c-----> &aMoney rate x%boost% enabled&c <-------"); - - c.get("command.pointboost.help.info", "Boosts points gain for all players"); - c.get("command.pointboost.help.args", "[jobname] [rate]"); - Jobs.getGCManager().commandArgs.put("pointboost", Arrays.asList("[jobname]", "[rate]")); - c.get("command.pointboost.output.allreset", "All points boost turned off"); - c.get("command.pointboost.output.jobsboostreset", "Points boost for %jobname% was turned off"); - c.get("command.pointboost.output.nothingtoreset", "Nothing to reset"); - c.get("command.pointboost.output.boostalladded", "Points boost of %boost% added for all jobs!"); - c.get("command.pointboost.output.boostadded", "Points boost of &e%boost% &aadded for &e%jobname%!"); - c.get("command.pointboost.output.infostats", "&c-----> &aPoints rate x%boost% enabled&c <-------"); - - c.get("command.expboost.help.info", "Boosts Exp gain for all players"); - c.get("command.expboost.help.args", "[jobname] [rate]"); - Jobs.getGCManager().commandArgs.put("expboost", Arrays.asList("[jobname]", "[rate]")); - c.get("command.expboost.output.allreset", "All exp boost turned off"); - c.get("command.expboost.output.jobsboostreset", "Exp boost for %jobname% was turned off"); - c.get("command.expboost.output.nothingtoreset", "Nothing to reset"); - c.get("command.expboost.output.boostalladded", "Exp boost of %boost% added for all jobs!"); - c.get("command.expboost.output.boostadded", "Exp boost of &e%boost% &aadded for &e%jobname%!"); - c.get("command.expboost.output.infostats", "&c-----> &aExp rate x%boost% enabled&c <-------"); - - c.get("command.itembonus.help.info", "Check item bonus"); - c.get("command.itembonus.help.args", ""); - c.get("command.itembonus.output.list", "&e[jobname]: %money% %points% %exp%"); - - c.get("command.edititembonus.help.info", "Edit item boost bonus"); - c.get("command.edititembonus.help.args", "list/add/remove [jobname] [itemBoostName]"); - Jobs.getGCManager().commandArgs.put("edititembonus", Arrays.asList("list%%add%%remove", "[jobname]", "[jobitemname]")); - - c.get("command.bonus.help.info", "Show job bonuses"); - c.get("command.bonus.help.args", "[jobname]"); - Jobs.getGCManager().commandArgs.put("bonus", Arrays.asList("[jobname]")); - c.get("command.bonus.output.topline", "&7**************** &2[money] &6[points] &e[exp] &7****************"); - c.get("command.bonus.output.permission", " &ePerm bonus: %money% %points% %exp%"); - c.get("command.bonus.output.item", " &eItem bonus: %money% %points% %exp%"); - c.get("command.bonus.output.global", " &eGlobal bonus: %money% %points% %exp%"); - c.get("command.bonus.output.dynamic", " &eDynamic bonus: %money% %points% %exp%"); - c.get("command.bonus.output.nearspawner", " &eSpawner bonus: %money% %points% %exp%"); - c.get("command.bonus.output.petpay", " &ePetPay bonus: %money% %points% %exp%"); - c.get("command.bonus.output.area", " &eArea bonus: %money% %points% %exp%"); - c.get("command.bonus.output.mcmmo", " &eMcMMO bonus: %money% %points% %exp%"); - c.get("command.bonus.output.final", " &eFinal bonus: %money% %points% %exp%"); - c.get("command.bonus.output.finalExplanation", " &eDoes not include Petpay and Near spawner bonus/penalty"); - - c.get("command.convert.help.info", - "Converts data base system from one system to another. if you currently running sqlite, this will convert to Mysql and vise versa."); - c.get("command.convert.help.args", ""); - - c.get("command.limit.help.info", "Shows payment limits for jobs"); - c.get("command.limit.help.args", ""); - c.get("command.limit.output.moneytime", "&eTime left until money limit resets: &2%time%"); - c.get("command.limit.output.moneyLimit", "&eMoney limit: &2%current%&e/&2%total%"); - c.get("command.limit.output.exptime", "&eTime left until Exp limit resets: &2%time%"); - c.get("command.limit.output.expLimit", "&eExp limit: &2%current%&e/&2%total%"); - c.get("command.limit.output.pointstime", "&eTime left until Point limit resets: &2%time%"); - c.get("command.limit.output.pointsLimit", "&ePoint limit: &2%current%&e/&2%total%"); - c.get("command.limit.output.reachedmoneylimit", "&4You have reached money limit in given time!"); - c.get("command.limit.output.reachedmoneylimit2", "&eYou can check your limit with &2/jobs limit &ecommand"); - c.get("command.limit.output.reachedexplimit", "&4You have reached exp limit in given time!"); - c.get("command.limit.output.reachedexplimit2", "&eYou can check your limit with &2/jobs limit &ecommand"); - c.get("command.limit.output.reachedpointslimit", "&4You have reached exp limit in given time!"); - c.get("command.limit.output.reachedpointslimit2", "&eYou can check your limit with &2/jobs limit &ecommand"); - c.get("command.limit.output.notenabled", "&eMoney limit is not enabled"); - - c.get("command.resetlimit.help.info", "Resets players payment limits"); - c.get("command.resetlimit.help.args", "[playername]"); - Jobs.getGCManager().commandArgs.put("resetlimit", Arrays.asList("[playername]")); - c.get("command.resetlimit.output.reseted", "&ePayment limits have been reset for: &2%playername%"); - - c.get("command.resetquest.help.info", "Resets players quest"); - c.get("command.resetquest.help.args", "[playername] [jobname]"); - Jobs.getGCManager().commandArgs.put("resetquest", Arrays.asList("[playername]", "[jobname]")); - c.get("command.resetquest.output.reseted", "&eQuest have been reset for: &2%playername%"); - c.get("command.resetquest.output.noQuests", "&eCan't find any quests"); - - c.get("command.points.help.info", "Shows how much points player have."); - c.get("command.points.help.args", "[playername]"); - Jobs.getGCManager().commandArgs.put("points", Arrays.asList("[playername]")); - c.get("command.points.currentpoints", " &eCurrent point amount: &6%currentpoints%"); - c.get("command.points.totalpoints", " &eTotal amount of collected points until now: &6%totalpoints%"); - - c.get("command.editpoints.help.info", "Edit players points."); - c.get("command.editpoints.help.args", "set/add/take [playername] [amount]"); - Jobs.getGCManager().commandArgs.put("editpoints", Arrays.asList("set%%add%%take", "[playername]")); - c.get("command.editpoints.output.set", "&ePlayers (&6%playername%&e) points was set to &6%amount%"); - c.get("command.editpoints.output.add", "&ePlayer (&6%playername%&e) got aditinal &6%amount% &epoints. Now he has &6%total%"); - c.get("command.editpoints.output.take", "&ePlayer (&6%playername%&e) lost &6%amount% &epoints. Now he has &6%total%"); - - c.get("command.editjobs.help.info", "Edit current jobs."); - c.get("command.editjobs.help.args", ""); - c.get("command.editjobs.help.list.job", "&eJobs:"); - c.get("command.editjobs.help.list.jobs", " -> [&e%jobname%&r]"); - c.get("command.editjobs.help.list.actions", " -> [&e%actionname%&r]"); - c.get("command.editjobs.help.list.material", " -> [&e%materialname%&r] "); - c.get("command.editjobs.help.list.materialRemove", "&c[X]"); - c.get("command.editjobs.help.list.materialAdd", " -> &e[&2+&e]"); - c.get("command.editjobs.help.list.money", " -> &eMoney: &6%amount%"); - c.get("command.editjobs.help.list.exp", " -> &eExp: &6%amount%"); - c.get("command.editjobs.help.list.points", " -> &ePoints: &6%amount%"); - c.get("command.editjobs.help.modify.newValue", "&eEnter new value"); - c.get("command.editjobs.help.modify.enter", "&eEnter new name or press "); - c.get("command.editjobs.help.modify.hand", "&6HAND "); - c.get("command.editjobs.help.modify.handHover", "&6Press to grab info from item in your hand"); - c.get("command.editjobs.help.modify.or", "&eor "); - c.get("command.editjobs.help.modify.look", "&6LOOKING AT"); - c.get("command.editjobs.help.modify.lookHover", "&6Press to grab info from block you are looking"); - - c.get("command.blockinfo.help.info", "Shows block information you looking at."); - c.get("command.blockinfo.help.args", ""); - c.get("command.blockinfo.output.name", " &eBlock name: &6%blockname%"); - c.get("command.blockinfo.output.id", " &eBlock id: &6%blockid%"); - c.get("command.blockinfo.output.data", " &eBlock data: &6%blockdata%"); - c.get("command.blockinfo.output.usage", " &eUsage: &6%first% &eor &6%second%"); - - c.get("command.iteminfo.help.info", "Shows item information you holding."); - c.get("command.iteminfo.help.args", ""); - c.get("command.iteminfo.output.name", " &eItem name: &6%itemname%"); - c.get("command.iteminfo.output.id", " &eItem id: &6%itemid%"); - c.get("command.iteminfo.output.data", " &eItem data: &6%itemdata%"); - c.get("command.iteminfo.output.usage", " &eUsage: &6%first% &eor &6%second%"); - - - c.get("command.placeholders.help.info", "List out all placeholders"); - c.get("command.placeholders.help.args", "(parse) (placeholder)"); - c.get("command.placeholders.output.list", "&e[place]. &7[placeholder]"); - c.get("command.placeholders.output.outputResult", " &eresult: &7[result]"); - c.get("command.placeholders.output.parse", "&6[placeholder] &7by [source] &6result &8|&f[result]&8|"); - - - c.get("command.entitylist.help.info", "Shows all possible entities can be used with plugin."); - c.get("command.entitylist.help.args", ""); - - c.get("command.stats.help.info", "Show the level you are in each job you are part of."); - c.get("command.stats.help.args", "[playername]"); - Jobs.getGCManager().commandArgs.put("stats", Arrays.asList("[playername]")); - c.get("command.stats.error.nojob", "Please join a job first."); - c.get("command.stats.output", " lvl%joblevel% %jobname% : %jobxp%/%jobmaxxp% xp"); - - c.get("command.shop.help.info", "Opens special jobs shop."); - c.get("command.shop.help.args", ""); - c.get("command.shop.info.title", "&e------- &8Jobs shop &e-------"); - c.get("command.shop.info.currentPoints", "&eYou have: &6%currentpoints%"); - c.get("command.shop.info.price", "&ePrice: &6%price%"); - c.get("command.shop.info.reqJobs", "&eRequired jobs:"); - c.get("command.shop.info.reqJobsList", " &6%jobsname%&e: &e%level% lvl"); - c.get("command.shop.info.reqTotalLevel", "&6Required total level: &e%totalLevel%"); - c.get("command.shop.info.cantOpen", "&cCan't open this page"); - c.get("command.shop.info.NoPermForItem", "&cYou don't have required permissions for this item!"); - c.get("command.shop.info.NoPermToBuy", "&cNo permissions to buy this item"); - c.get("command.shop.info.NoJobReqForitem", "&cYou don't have required job (&6%jobname%&e) with required (&6%joblevel%&e) level"); - c.get("command.shop.info.NoPoints", "&cYou don't have enough points"); - c.get("command.shop.info.NoTotalLevel", "&cTotal jobs level is too low (%totalLevel%)"); - c.get("command.shop.info.Paid", "&eYou have paid &6%amount% &efor this item"); - c.get("command.shop.info.reqJobsList", " &6%jobsname%&e: &e%level% lvl"); - - c.get("command.archive.help.info", "Shows all jobs saved in archive by user."); - c.get("command.archive.help.args", "[playername]"); - Jobs.getGCManager().commandArgs.put("archive", Arrays.asList("[playername]")); - c.get("command.archive.error.nojob", "There is no jobs saved."); - - c.get("command.give.help.info", "Gives item by jobs name and item category name. Player name is optional"); - c.get("command.give.help.args", "[playername] [jobname] [jobitemname]"); - Jobs.getGCManager().commandArgs.put("give", Arrays.asList("[playername]", "[jobname]", "[jobitemname]")); - c.get("command.give.output.notonline", "&4Player [%playername%] is not online!"); - c.get("command.give.output.noitem", "&4Can't find any item by given name!"); - - c.get("command.info.help.title", "&2*** &eJobs&2 ***"); - c.get("command.info.help.info", "Show how much each job is getting paid and for what."); - c.get("command.info.help.penalty", "&eThis job have &c[penalty]% &epenalty because of too many players working in it."); - c.get("command.info.help.bonus", "&eThis job have &2[bonus]% &ebonus because not enough players working in it."); - c.get("command.info.help.args", "[jobname] [action]"); - Jobs.getGCManager().commandArgs.put("info", Arrays.asList("[jobname]", "[action]")); - c.get("command.info.help.actions", "&eValid actions are: &f%actions%"); - c.get("command.info.help.max", " - &emax level:&f "); - c.get("command.info.help.newMax", " &eMax level: &f[max]"); - c.get("command.info.help.material", "&7%material%"); - - c.get("command.info.help.levelRange", " &a(&e%levelFrom% &a- &e%levelUntil% &alevels)"); - c.get("command.info.help.levelFrom", " &a(from &e%levelFrom% &alevel)"); - c.get("command.info.help.levelUntil", " &a(until &e%levelUntil% &alevel)"); - - c.get("command.info.help.money", " &2%money%\u0024"); - c.get("command.info.help.points", " &6%points%pts"); - c.get("command.info.help.exp", " &e%exp%xp"); - - c.get("command.info.gui.pickjob", "&ePick your job!"); - c.get("command.info.gui.jobinfo", "&e[jobname] info!"); - c.get("command.info.gui.actions", "&eValid actions are:"); - c.get("command.info.gui.leftClick", "&eLeft Click for more info"); - c.get("command.info.gui.rightClick", "&eRight click to join job"); - c.get("command.info.gui.leftSlots", "&eLeft slots:&f "); - c.get("command.info.gui.working", "&2&nAlready working"); - c.get("command.info.gui.max", "&eMax level:&f "); - c.get("command.info.gui.back", "&e<<< Back"); - - c.get("command.info.output.break.info", "&eBreak"); - c.get("command.info.output.break.none", "%jobname% does not get money for breaking blocks."); - c.get("command.info.output.tntbreak.info", "&eTNTBreak"); - c.get("command.info.output.tntbreak.none", "%jobname% does not get money for breaking blocks with tnt."); - c.get("command.info.output.place.info", "&ePlace"); - c.get("command.info.output.place.none", "%jobname% does not get money for placing blocks."); - c.get("command.info.output.kill.info", "&eKill"); - c.get("command.info.output.kill.none", "%jobname% does not get money for killing monsters."); - c.get("command.info.output.mmkill.info", "&eMMKill"); - c.get("command.info.output.mmkill.none", "%jobname% does not get money for killing Mythic monsters."); - c.get("command.info.output.fish.info", "&eFish"); - c.get("command.info.output.fish.none", "%jobname% does not get money from fishing."); - c.get("command.info.output.craft.info", "&eCraft"); - c.get("command.info.output.craft.none", "%jobname% does not get money from crafting."); - c.get("command.info.output.drink.info", "&eDrink"); - c.get("command.info.output.drink.none", "%jobname% does not get money for drinking."); - c.get("command.info.output.smelt.info", "&eSmelt"); - c.get("command.info.output.smelt.none", "%jobname% does not get money from smelting."); - c.get("command.info.output.brew.info", "&eBrew"); - c.get("command.info.output.brew.none", "%jobname% does not get money from brewing."); - c.get("command.info.output.eat.info", "&eEat"); - c.get("command.info.output.eat.none", "%jobname% does not get money from eating food."); - c.get("command.info.output.dye.info", "&eDye"); - c.get("command.info.output.dye.none", "%jobname% does not get money from dyeing."); - c.get("command.info.output.enchant.info", "&eEnchant"); - c.get("command.info.output.enchant.none", "%jobname% does not get money from enchanting."); - c.get("command.info.output.vtrade.info", "&eVillager trade"); - c.get("command.info.output.vtrade.none", "%jobname% does not get money for trading a villager."); - c.get("command.info.output.repair.info", "&eRepair"); - c.get("command.info.output.repair.none", "%jobname% does not get money from repairing."); - c.get("command.info.output.breed.info", "&eBreed"); - c.get("command.info.output.breed.none", "%jobname% does not get money from breeding."); - c.get("command.info.output.tame.info", "&eTame"); - c.get("command.info.output.tame.none", "%jobname% does not get money from taming."); - c.get("command.info.output.milk.info", "&eMilk"); - c.get("command.info.output.milk.none", "%jobname% does not get money from milking cows."); - c.get("command.info.output.shear.info", "&eShear"); - c.get("command.info.output.shear.none", "%jobname% does not get money from shearing sheeps."); - c.get("command.info.output.explore.info", "&eExplore"); - c.get("command.info.output.explore.none", "%jobname% does not get money from exploring."); - c.get("command.info.output.custom-kill.info", "&eCustom kill"); - c.get("command.info.output.custom-kill.none", "%jobname% does not get money from custom player kills."); - - c.get("command.playerinfo.help.info", "Show how much each job is getting paid and for what on another player."); - c.get("command.playerinfo.help.args", "[playername] [jobname] [action]"); - Jobs.getGCManager().commandArgs.put("playerinfo", Arrays.asList("[playername]", "[jobname]", "[action]")); - - c.get("command.join.help.info", "Join the selected job."); - c.get("command.join.help.args", "[jobname]"); - Jobs.getGCManager().commandArgs.put("join", Arrays.asList("[jobname]")); - c.get("command.join.error.alreadyin", "You are already in the job %jobname%."); - c.get("command.join.error.fullslots", "You cannot join the job %jobname%, there are no slots available."); - c.get("command.join.error.maxjobs", "You have already joined too many jobs."); - c.get("command.join.error.rejoin", "&cCan't rejoin this job. Wait [time]"); - c.get("command.join.rejoin", "&aClick to rejoin this job: "); - c.get("command.join.success", "You have joined the job %jobname%."); - c.get("command.join.confirm", "&2Click to confirm join action for &7[jobname] &2job."); - - c.get("command.leave.help.info", "Leave the selected job."); - c.get("command.leave.help.args", "[oldplayerjob]"); - Jobs.getGCManager().commandArgs.put("leave", Arrays.asList("[oldplayerjob]")); - c.get("command.leave.success", "You have left the job %jobname%."); - - c.get("command.leaveall.help.info", "Leave all your jobs."); - c.get("command.leaveall.error.nojobs", "You do not have any jobs to leave!"); - c.get("command.leaveall.success", "You have left all your jobs."); - - c.get("command.explored.help.info", "Check who visited this chunk"); - c.get("command.explored.error.noexplore", "No one visited this chunk"); - c.get("command.explored.list", "&e%place%. %playername%"); - - c.get("command.browse.help.info", "List the jobs available to you."); - c.get("command.browse.error.nojobs", "There are no jobs you can join."); - c.get("command.browse.output.header", "You are allowed to join the following jobs:"); - c.get("command.browse.output.footer", "For more information type in /jobs info [JobName]"); - c.get("command.browse.output.totalWorkers", " &7Workers: &e[amount]"); - c.get("command.browse.output.penalty", " &4Penalty: &c[amount]%"); - c.get("command.browse.output.bonus", " &2Bonus: &a[amount]%"); - - c.get("command.browse.output.newHeader", "&2========== [amount] Available Jobs ========="); - c.get("command.browse.output.description", "[description]"); - c.get("command.browse.output.list", " &8[place]. &7[jobname]"); - - c.get("command.browse.output.console.newHeader", "&2========== [amount] Available Jobs ========="); - c.get("command.browse.output.console.description", "[description]"); - c.get("command.browse.output.console.totalWorkers", " &7Workers: &e[amount]"); - c.get("command.browse.output.console.penalty", " &4Penalty: &c[amount]%"); - c.get("command.browse.output.console.bonus", " &2Bonus: &a[amount]%"); - c.get("command.browse.output.console.list", " &6[jobname]"); - c.get("command.browse.output.console.newMax", " &eMax level: &f[max]"); - - c.get("command.browse.output.click", "&bClick on the job to see more info about it!"); - c.get("command.browse.output.detailed", "&bClick to see more detailed list on job actions"); - - c.get("command.browse.output.jobHeader", "&2========== [jobname] ========="); - c.get("command.browse.output.chooseJob", "&7&n&oChoose this job"); - c.get("command.browse.output.chooseJobHover", "&7Click here to get this job"); - - c.get("command.clearownership.help.info", "Clear block ownership"); - c.get("command.clearownership.help.args", "[playername]"); - Jobs.getGCManager().commandArgs.put("clearownership", Arrays.asList("[playername]")); - c.get("command.clearownership.output.cleared", "&2Removed &7[furnaces] &2furnaces and &7[brewing] &2brewing stands"); - - c.get("command.quests.help.info", "List available quests"); - c.get("command.quests.help.args", "[playername]"); - Jobs.getGCManager().commandArgs.put("quests", Arrays.asList("[playername]")); - c.get("command.quests.error.noquests", "&cThere are no quests"); - c.get("command.quests.toplineseparator", "&7*********************** &6[playerName]&2(&f[questsDone]&2) &7***********************"); - c.get("command.quests.output.completed", "&2 !Completed!&r "); - c.get("command.quests.output.questLine", "[progress] &7[questName] &f[done]&7/&8[required]"); - c.get("command.quests.output.hover", Arrays.asList("&f[jobName]", "[desc]", "&7New quest in: [time]")); - - c.get("command.fire.help.info", "Fire the player from the job."); - c.get("command.fire.help.args", "[playername] [jobname]"); - Jobs.getGCManager().commandArgs.put("fire", Arrays.asList("[playername]", "[jobname]")); - c.get("command.fire.error.nojob", "Player does not have the job %jobname%."); - c.get("command.fire.output.target", "You have been fired from %jobname%."); - - c.get("command.fireall.help.info", "Fire player from all their jobs."); - c.get("command.fireall.help.args", "[playername]"); - Jobs.getGCManager().commandArgs.put("fireall", Arrays.asList("[playername]")); - c.get("command.fireall.error.nojobs", "Player does not have any jobs to be fired from!"); - c.get("command.fireall.output.target", "You have been fired from all your jobs."); - - c.get("command.employ.help.info", "Employ the player to the job."); - c.get("command.employ.help.args", "[playername] [jobname]"); - Jobs.getGCManager().commandArgs.put("employ", Arrays.asList("[playername]", "[jobname]")); - c.get("command.employ.error.alreadyin", "Player is already in the job %jobname%."); - c.get("command.employ.output.target", "You have been employed as a %jobname%."); - - c.get("command.top.help.info", "Shows top %amount% players by jobs name."); - c.get("command.top.help.args", "[jobname]"); - Jobs.getGCManager().commandArgs.put("top", Arrays.asList("[jobname]")); - c.get("command.top.error.nojob", "Can't find any job with this name."); - c.get("command.top.output.topline", "&aTop&e %amount% &aplayers by &e%jobname% &ajob"); - c.get("command.top.output.list", "&e%number%&a. &e%playername% &alvl &e%level% &awith&e %exp% &aexp"); - c.get("command.top.output.prev", "&e<<<<< Prev page &2|"); - c.get("command.top.output.next", "&2|&e Next Page >>>>"); - c.get("command.top.output.show", "&2Show from &e[from] &2until &e[until] &2top list"); - - c.get("command.gtop.help.info", "Shows top %amount% players by global jobs level."); - c.get("command.gtop.help.args", ""); - c.get("command.gtop.error.nojob", "Can't find any information."); - c.get("command.gtop.output.topline", "&aTop&e %amount% &aplayers by global job level"); - c.get("command.gtop.output.list", "&e%number%&a. &e%playername% &alvl &e%level% &awith&e %exp% &aexp"); - c.get("command.gtop.output.prev", "&e<<<<< Prev page &2|"); - c.get("command.gtop.output.next", "&2|&e Next Page >>>>"); - c.get("command.gtop.output.show", "&2Show from &e[from] &2until &e[until] &2global top list"); - - c.get("command.area.help.info", "Modify restricted areas."); - c.get("command.area.help.args", "add/remove/info/list"); - Jobs.getGCManager().commandArgs.put("area", Arrays.asList("add%%remove%%info%%list")); - c.get("command.area.help.addUsage", "&eUsage: &6/Jobs area add [areaName/wg:worldGuardAreaName] [bonus]"); - c.get("command.area.help.removeUsage", "&eUsage: &6/Jobs area remove [areaName]"); - c.get("command.area.output.addedNew", "&eAdded new restricted area with &6%bonus% &ebonus"); - c.get("command.area.output.removed", "&eRemoved restricted area &6%name%"); - c.get("command.area.output.list", "&e%number%&a. &e%areaname% &e%worldname% (&a%x1%:%y1%:%z1%/&e%x2%:%y2%:%z2%) &6%bonus%"); - c.get("command.area.output.wgList", "&e%number%&a. WorldGuard: &e%areaname% &6%bonus%"); - c.get("command.area.output.noAreas", "&eThere is no saved restricted areas"); - c.get("command.area.output.noAreasByLoc", "&eThere is no restricted areas in this location"); - c.get("command.area.output.areaList", "&eRestricted areas by your location: &6%list%"); - c.get("command.area.output.selected1", "&eSelected first point: &6%x%:%y%:%z%"); - c.get("command.area.output.selected2", "&eSelected second point: &6%x%:%y%:%z%"); - c.get("command.area.output.select", "&eSelect 2 points with selection tool (%tool%)"); - c.get("command.area.output.exist", "&eRestriction area by this name already exist"); - c.get("command.area.output.dontExist", "&eRestriction area by this name don't exist"); - c.get("command.area.output.wgDontExist", "&eWorldGuard area by this name don't exist"); - - c.get("command.log.help.info", "Shows statistics."); - c.get("command.log.help.args", "[playername]"); - Jobs.getGCManager().commandArgs.put("log", Arrays.asList("[playername]")); - c.get("command.log.output.topline", "&7************************* &6%playername% &7*************************"); - c.get("command.log.output.ls", "&7* &6%number%. &3%action%: &6%item% &eqty: %qty% %money%%exp%%points%"); - c.get("command.log.output.money", "&6money: %amount% "); - c.get("command.log.output.exp", "&eexp: %amount% "); - c.get("command.log.output.points", "&6points: %amount%"); - c.get("command.log.output.bottomline", "&7***********************************************************"); - c.get("command.log.output.prev", "&e<<<<< Prev page &2|"); - c.get("command.log.output.next", "&2|&e Next Page >>>>"); - c.get("command.log.output.nodata", "&cData not found"); - - c.get("command.glog.help.info", "Shows global statistics."); - c.get("command.glog.help.args", ""); - c.get("command.glog.output.topline", "&7*********************** &6Global statistics &7***********************"); - c.get("command.glog.output.ls", "&7* &6%number%. &3%action%: &6%item% &eqty: %qty% %money%%exp%%points%"); - c.get("command.glog.output.money", "&6money: %amount% "); - c.get("command.glog.output.exp", "&eexp: %amount% "); - c.get("command.glog.output.points", "&6points: %amount%"); - c.get("command.glog.output.bottomline", "&7**************************************************************"); - c.get("command.glog.output.nodata", "&cData not found"); - - c.get("command.transfer.help.info", "Transfer a player's job from an old job to a new job."); - c.get("command.transfer.help.args", "[playername] [oldjob] [newjob]"); - Jobs.getGCManager().commandArgs.put("transfer", Arrays.asList("[playername]", "[oldjob]", "[newjob]")); - c.get("command.transfer.output.target", "You have been transferred from %oldjobname% to %newjobname%."); - - c.get("command.promote.help.info", "Promote the player X levels in a job."); - c.get("command.promote.help.args", "[playername] [jobname] [levels]"); - Jobs.getGCManager().commandArgs.put("promote", Arrays.asList("[playername]", "[jobname]", "[levels]")); - c.get("command.promote.output.target", "You have been promoted %levelsgained% levels in %jobname%."); - - c.get("command.exp.help.info", "Change the player exp for job."); - c.get("command.exp.help.args", "[playername] [jobname] set/add/take [amount]"); - Jobs.getGCManager().commandArgs.put("exp", Arrays.asList("[playername]", "[jobname]", "set%%add%%take")); - c.get("command.exp.output.target", "&eYour exp was changed for %jobname% &eand now you at &6%level%lvl &eand with &6%exp%exp."); - - c.get("command.level.help.info", "Change the player level for job."); - c.get("command.level.help.args", "[playername] [jobname] set/add/take [amount]"); - Jobs.getGCManager().commandArgs.put("level", Arrays.asList("[playername]", "[jobname]", "set%%add%%take")); - c.get("command.level.output.target", "&eYour level was changed for %jobname% &eand now you at &6%level%lvl &eand with &6%exp%exp."); - - c.get("command.demote.help.info", "Demote the player X levels in a job."); - c.get("command.demote.help.args", "[playername] [jobname] [levels]"); - Jobs.getGCManager().commandArgs.put("demote", Arrays.asList("[playername]", "[jobname]", "[levels]")); - c.get("command.demote.output.target", "You have been demoted %levelslost% levels in %jobname%."); - - c.get("command.grantxp.help.info", "Grant the player X experience in a job."); - c.get("command.grantxp.help.args", "[playername] [jobname] [xp]"); - Jobs.getGCManager().commandArgs.put("grantxp", Arrays.asList("[playername]", "[jobname]", "[xp]")); - c.get("command.grantxp.output.target", "You have been granted %xpgained% experience in %jobname%."); - - c.get("command.removexp.help.info", "Remove X experience from the player in a job."); - c.get("command.removexp.help.args", "[playername] [jobname] [xp]"); - Jobs.getGCManager().commandArgs.put("removexp", Arrays.asList("[playername]", "[jobname]", "[xp]")); - c.get("command.removexp.output.target", "You have lost %xplost% experience in %jobname%."); - - c.get("command.signupdate.help.info", "Manualy updates sign by its name"); - c.get("command.signupdate.help.args", "[jobname]"); - Jobs.getGCManager().commandArgs.put("signupdate", Arrays.asList("[jobname]")); - - c.get("command.bp.help.info", "Shows Block protection arround you in 10 block radius"); - c.get("command.bp.help.args", ""); - c.get("command.bp.output.found", "&eFound &6%amount% &eprotected blocks around you"); - c.get("command.bp.output.notFound", "&eNo protected blocks found around you"); - - c.get("command.reload.help.info", "Reload configurations."); - - c.get("command.toggle.help.info", "Toggles payment output on action bar or bossbar."); - c.get("command.toggle.help.args", "actionbar/bossbar"); - Jobs.getGCManager().commandArgs.put("toggle", Arrays.asList("actionbar%%bossbar")); - c.get("command.toggle.output.turnedoff", "&4This feature are turned off!"); - c.get("command.toggle.output.paid.main", "&aYou got:"); - c.get("command.toggle.output.paid.money", "&e[amount] money"); - c.get("command.toggle.output.paid.exp", "&7[exp] exp"); - c.get("command.toggle.output.paid.points", "&6[points] points"); - c.get("command.toggle.output.on", "&aToggled: &aON"); - c.get("command.toggle.output.off", "&aToggled: &4OFF"); - - c.get("message.skillup.broadcast", "%playername% has been promoted to a %titlename% %jobname%."); - c.get("message.skillup.nobroadcast", "Congratulations, you have been promoted to a %titlename% %jobname%."); - - c.get("message.levelup.broadcast", "%playername% is now a level %joblevel% %jobname%."); - c.get("message.levelup.nobroadcast", "You are now a level %joblevel% %jobname%."); - - c.get("message.cowtimer", "&eYou still need to wait &6%time% &esec to get paid for this job."); - c.get("message.blocktimer", "&eYou need to wait: &3[time] &esec more to get paid for this!"); - c.get("message.placeblocktimer", "&eYou can't place block faster than &6[time] &esec interval in same place!"); - c.get("message.taxes", "&3[amount] &eserver taxes where transfered to this account"); - - c.get("message.boostStarted", "&eJobs boost time have been started!"); - c.get("message.boostStoped", "&eJobs boost time have been ended!"); - - c.get("message.crafting.fullinventory", "&cYour inventory is full!"); - - c.get("signs.List", "&0[number].&8[player]&7:&4[level]"); - c.get("signs.SpecialList.p1", "&b** &8First &b**"); - c.get("signs.SpecialList.p2", "&b** &8Second &b**"); - c.get("signs.SpecialList.p3", "&b** &8Third &b**"); - c.get("signs.SpecialList.p4", "&b** &8Fourth &b**"); - c.get("signs.SpecialList.p5", "&b** &8Fifth &b**"); - c.get("signs.SpecialList.p6", "&b** &8Sixth &b**"); - c.get("signs.SpecialList.p7", "&b** &8Seventh &b**"); - c.get("signs.SpecialList.p8", "&b** &8Eight &b**"); - c.get("signs.SpecialList.p9", "&b** &8Ninth &b**"); - c.get("signs.SpecialList.p10", "&b** &8Tenth &b**"); - c.get("signs.SpecialList.name", "&9[player]"); - c.get("signs.SpecialList.level", "&8[level] level"); - c.get("signs.SpecialList.bottom", "&b************"); - c.get("signs.cantcreate", "&4You can't create this sign!"); - c.get("signs.cantdestroy", "&4You can't destroy this sign!"); - c.get("signs.topline", "&0[Jobs]"); - c.get("signs.secondline.join", "&0Join"); - c.get("signs.secondline.leave", "&0Leave"); - c.get("signs.secondline.toggle", "&0Toggle"); - c.get("signs.secondline.top", "&0Top"); - c.get("signs.secondline.browse", "&0Browse"); - c.get("signs.secondline.stats", "&0Stats"); - c.get("signs.secondline.limit", "&0Limit"); - c.get("signs.secondline.info", "&0Info"); - c.get("signs.secondline.archive", "&0Archive"); - - //c.get("scoreboard.clear", "&eIf you want to remove scoreboard, type &2/jobs top clear"); - c.get("scoreboard.topline", "&2Top &e%jobname%"); - c.get("scoreboard.gtopline", "&2Global top list"); - c.get("scoreboard.line", "&2%number%. &e%playername% (&6%level%&e)"); - - Jobs.getGCManager().keys = new ArrayList<>(c.getC().getConfigurationSection("signs.secondline").getKeys(false)); - - // Write back config - try { - c.getW().save(f); - } catch (IOException e) { - e.printStackTrace(); - } - } - } -} +package com.gamingmesh.jobs.config; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Enumeration; +import java.util.Iterator; +import java.util.List; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +import org.bukkit.configuration.file.YamlConfiguration; + +import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.container.LocaleReader; + +public class LanguageManager { + + public LanguageManager() { + } + + private List languages = new ArrayList<>(); + + public List getLanguages() { + return languages; + } + + public static List getClassesFromPackage(String pckgname, String cleaner) throws ClassNotFoundException { + List result = new ArrayList<>(); + try { + for (URL jarURL : ((URLClassLoader) Jobs.class.getClassLoader()).getURLs()) { + try { + result.addAll(getClassesInSamePackageFromJar(pckgname, jarURL.toURI().getPath(), cleaner)); + } catch (URISyntaxException e) { + } + } + } catch (NullPointerException x) { + throw new ClassNotFoundException(pckgname + " does not appear to be a valid package (Null pointer exception)"); + } + return result; + } + + private static List getClassesInSamePackageFromJar(String packageName, String jarPath, String cleaner) { + JarFile jarFile = null; + List listOfCommands = new ArrayList<>(); + try { + jarFile = new JarFile(jarPath); + Enumeration en = jarFile.entries(); + while (en.hasMoreElements()) { + JarEntry entry = en.nextElement(); + String entryName = entry.getName(); + packageName = packageName.replace(".", "/"); + if (entryName != null && entryName.endsWith(".yml") && entryName.startsWith(packageName)) { + String name = entryName.replace(packageName, "").replace(".yml", "").replace("/", ""); + if (name.contains("$")) + name = name.split("\\$")[0]; + if (cleaner != null) + name = name.replace(cleaner, ""); + listOfCommands.add(name); + } + } + } catch (Exception e) { + } finally { + if (jarFile != null) + try { + jarFile.close(); + } catch (Exception e) { + } + } + return listOfCommands; + } + + /** + * Method to load the language file configuration + * + * loads from Jobs/locale/messages_en.yml + */ + synchronized void load() { + + // This should be present to copy over default locale files into locale folder if file doesn't exist. Grabs all files from plugin file. + languages = new ArrayList<>(); + try { + languages.addAll(getClassesFromPackage("locale", "messages_")); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + for (Iterator e1 = this.languages.iterator(); e1.hasNext();) { + String lang = e1.next(); + YmlMaker langFile = new YmlMaker(Jobs.getInstance(), "locale" + File.separator + "messages_" + lang + ".yml"); + langFile.saveDefaultConfig(); + } + //Up to here. + + String ls = Jobs.getGCManager().localeString; + + if (ls == null || ls.equals("")) + return; + + languages.clear(); + languages.add("en"); + + File customLocaleFile = new File(Jobs.getFolder(), "locale" + File.separator + "messages_" + ls + ".yml"); + if (!customLocaleFile.exists() && !ls.equalsIgnoreCase("en")) + languages.add(ls); + + for (String lang : languages) { + File f = new File(Jobs.getFolder(), "locale" + File.separator + "messages_" + lang + ".yml"); + + // Fail safe if file get corrupted and being created with corrupted data, we need to recreate it + if ((f.length() / 1024) > 1024) { + f.delete(); + f = new File(Jobs.getFolder(), "locale" + File.separator + "messages_" + lang + ".yml"); + } + + YamlConfiguration config = YamlConfiguration.loadConfiguration(f); + CommentedYamlConfiguration writer = new CommentedYamlConfiguration(); + + LocaleReader c = new LocaleReader(config, writer); + + c.getC().options().copyDefaults(true); + + Jobs.getGCManager().commandArgs.clear(); + + c.get("economy.error.nomoney", "&cSorry, no money left in national bank!"); + c.get("limitedItem.error.levelup", "&cYou need to levelup in [jobname] to use this item!"); + c.get("general.Spawner", "&r[type] Spawner"); + c.get("general.info.toplineseparator", "&7*********************** &6%playername% &7***********************"); + c.get("general.info.separator", "&7*******************************************************"); + c.get("general.info.time.days", "&e%days% &6days "); + c.get("general.info.time.hours", "&e%hours% &6hours "); + c.get("general.info.time.mins", "&e%mins% &6min "); + c.get("general.info.time.secs", "&e%secs% &6sec "); + c.get("general.info.invalidPage", "&cInvalid page"); + c.get("general.info.true", "&2True"); + c.get("general.info.false", "&cFalse"); + c.get("general.admin.error", "&cThere was an error in the command."); + c.get("general.admin.success", "&eYour command has been performed."); + c.get("general.error.noHelpPage", "&cThere is no help page by this number!"); + c.get("general.error.notNumber", "&ePlease use numbers!"); + c.get("general.error.job", "&cThe job you have selected does not exist!"); + c.get("general.error.noCommand", "&cThere is no command by this name!"); + c.get("general.error.permission", "&cYou do not have permission to do that!"); + c.get("general.error.noinfo", "&cNo information found!"); + c.get("general.error.noinfoByPlayer", "&cNo information found by [%playername%] player name!"); + c.get("general.error.ingame", "&cYou can use this command only in game!"); + c.get("general.error.fromconsole", "&cYou can use this command only from console!"); + c.get("general.error.worldisdisabled", "&cYou can't use command in this world!"); + + c.get("general.error.newFurnaceRegistration", "&eRegistered new ownership for furnace &7[current]&e/&f[max]"); + c.get("general.error.newBrewingRegistration", "&eRegistered new ownership for brewing stand &7[current]&e/&f[max]"); + c.get("general.error.noFurnaceRegistration", "&cYou reached max furnace count!"); + c.get("general.error.noBrewingRegistration", "&cYou reached max brewing stand count!"); + + c.get("command.help.output.info", "Type /jobs [cmd] ? for more information about a command."); + c.get("command.help.output.cmdUsage", "&2Usage: &7[command]"); + c.get("command.help.output.label", "Jobs"); + + c.get("command.help.output.cmdInfoFormat", "[command] &f- &2[description]"); + c.get("command.help.output.cmdFormat", "&7/[command]&f[arguments]"); + c.get("command.help.output.helpPageDescription", "&2* [description]"); + + c.get("command.help.output.title", "&e-------&e ======= &6Jobs &e======= &e-------"); + c.get("command.help.output.page", "&e-----&e ====== Page &6[1] &eof &6[2] &e====== &e-----"); + c.get("command.help.output.fliperSimbols", "&e----------"); + + c.get("command.help.output.prevPage", "&2----<< &6Prev "); + c.get("command.help.output.prevPageOff", "&7----<< Prev "); + c.get("command.help.output.nextPage", "&6 Next &2>>----"); + c.get("command.help.output.nextPageOff", "&7 Next >>----"); + c.get("command.help.output.pageCount", "&2[current]/[total]"); + + c.get("command.moneyboost.help.info", "Boosts Money gain for all players"); + c.get("command.moneyboost.help.args", "[jobname] [rate]"); + Jobs.getGCManager().commandArgs.put("moneyboost", Arrays.asList("[jobname]", "[rate]")); + c.get("command.moneyboost.output.allreset", "All money boost turned off"); + c.get("command.moneyboost.output.jobsboostreset", "Money boost for %jobname% was turned off"); + c.get("command.moneyboost.output.nothingtoreset", "Nothing to reset"); + c.get("command.moneyboost.output.boostalladded", "Money boost of %boost% added for all jobs!"); + c.get("command.moneyboost.output.boostadded", "Money boost of &e%boost% &aadded for &e%jobname%!"); + c.get("command.moneyboost.output.infostats", "&c-----> &aMoney rate x%boost% enabled&c <-------"); + + c.get("command.pointboost.help.info", "Boosts points gain for all players"); + c.get("command.pointboost.help.args", "[jobname] [rate]"); + Jobs.getGCManager().commandArgs.put("pointboost", Arrays.asList("[jobname]", "[rate]")); + c.get("command.pointboost.output.allreset", "All points boost turned off"); + c.get("command.pointboost.output.jobsboostreset", "Points boost for %jobname% was turned off"); + c.get("command.pointboost.output.nothingtoreset", "Nothing to reset"); + c.get("command.pointboost.output.boostalladded", "Points boost of %boost% added for all jobs!"); + c.get("command.pointboost.output.boostadded", "Points boost of &e%boost% &aadded for &e%jobname%!"); + c.get("command.pointboost.output.infostats", "&c-----> &aPoints rate x%boost% enabled&c <-------"); + + c.get("command.expboost.help.info", "Boosts Exp gain for all players"); + c.get("command.expboost.help.args", "[jobname] [rate]"); + Jobs.getGCManager().commandArgs.put("expboost", Arrays.asList("[jobname]", "[rate]")); + c.get("command.expboost.output.allreset", "All exp boost turned off"); + c.get("command.expboost.output.jobsboostreset", "Exp boost for %jobname% was turned off"); + c.get("command.expboost.output.nothingtoreset", "Nothing to reset"); + c.get("command.expboost.output.boostalladded", "Exp boost of %boost% added for all jobs!"); + c.get("command.expboost.output.boostadded", "Exp boost of &e%boost% &aadded for &e%jobname%!"); + c.get("command.expboost.output.infostats", "&c-----> &aExp rate x%boost% enabled&c <-------"); + + c.get("command.itembonus.help.info", "Check item bonus"); + c.get("command.itembonus.help.args", ""); + c.get("command.itembonus.output.list", "&e[jobname]: %money% %points% %exp%"); + + c.get("command.edititembonus.help.info", "Edit item boost bonus"); + c.get("command.edititembonus.help.args", "list/add/remove [jobname] [itemBoostName]"); + Jobs.getGCManager().commandArgs.put("edititembonus", Arrays.asList("list%%add%%remove", "[jobname]", "[jobitemname]")); + + c.get("command.bonus.help.info", "Show job bonuses"); + c.get("command.bonus.help.args", "[jobname]"); + Jobs.getGCManager().commandArgs.put("bonus", Arrays.asList("[jobname]")); + c.get("command.bonus.output.topline", "&7**************** &2[money] &6[points] &e[exp] &7****************"); + c.get("command.bonus.output.permission", " &ePerm bonus: %money% %points% %exp%"); + c.get("command.bonus.output.item", " &eItem bonus: %money% %points% %exp%"); + c.get("command.bonus.output.global", " &eGlobal bonus: %money% %points% %exp%"); + c.get("command.bonus.output.dynamic", " &eDynamic bonus: %money% %points% %exp%"); + c.get("command.bonus.output.nearspawner", " &eSpawner bonus: %money% %points% %exp%"); + c.get("command.bonus.output.petpay", " &ePetPay bonus: %money% %points% %exp%"); + c.get("command.bonus.output.area", " &eArea bonus: %money% %points% %exp%"); + c.get("command.bonus.output.mcmmo", " &eMcMMO bonus: %money% %points% %exp%"); + c.get("command.bonus.output.final", " &eFinal bonus: %money% %points% %exp%"); + c.get("command.bonus.output.finalExplanation", " &eDoes not include Petpay and Near spawner bonus/penalty"); + + c.get("command.convert.help.info", + "Converts data base system from one system to another. if you currently running sqlite, this will convert to Mysql and vise versa."); + c.get("command.convert.help.args", ""); + + c.get("command.limit.help.info", "Shows payment limits for jobs"); + c.get("command.limit.help.args", ""); + c.get("command.limit.output.moneytime", "&eTime left until money limit resets: &2%time%"); + c.get("command.limit.output.moneyLimit", "&eMoney limit: &2%current%&e/&2%total%"); + c.get("command.limit.output.exptime", "&eTime left until Exp limit resets: &2%time%"); + c.get("command.limit.output.expLimit", "&eExp limit: &2%current%&e/&2%total%"); + c.get("command.limit.output.pointstime", "&eTime left until Point limit resets: &2%time%"); + c.get("command.limit.output.pointsLimit", "&ePoint limit: &2%current%&e/&2%total%"); + c.get("command.limit.output.reachedmoneylimit", "&4You have reached money limit in given time!"); + c.get("command.limit.output.reachedmoneylimit2", "&eYou can check your limit with &2/jobs limit &ecommand"); + c.get("command.limit.output.reachedmoneylimit3", "&eMoney earned is now reduced exponentially...but you still earn a little!!"); + c.get("command.limit.output.reachedexplimit", "&4You have reached exp limit in given time!"); + c.get("command.limit.output.reachedexplimit2", "&eYou can check your limit with &2/jobs limit &ecommand"); + c.get("command.limit.output.reachedpointslimit", "&4You have reached exp limit in given time!"); + c.get("command.limit.output.reachedpointslimit2", "&eYou can check your limit with &2/jobs limit &ecommand"); + c.get("command.limit.output.notenabled", "&eMoney limit is not enabled"); + + c.get("command.resetlimit.help.info", "Resets players payment limits"); + c.get("command.resetlimit.help.args", "[playername]"); + Jobs.getGCManager().commandArgs.put("resetlimit", Arrays.asList("[playername]")); + c.get("command.resetlimit.output.reseted", "&ePayment limits have been reset for: &2%playername%"); + + c.get("command.resetquest.help.info", "Resets players quest"); + c.get("command.resetquest.help.args", "[playername] [jobname]"); + Jobs.getGCManager().commandArgs.put("resetquest", Arrays.asList("[playername]", "[jobname]")); + c.get("command.resetquest.output.reseted", "&eQuest have been reset for: &2%playername%"); + c.get("command.resetquest.output.noQuests", "&eCan't find any quests"); + + c.get("command.points.help.info", "Shows how much points player have."); + c.get("command.points.help.args", "[playername]"); + Jobs.getGCManager().commandArgs.put("points", Arrays.asList("[playername]")); + c.get("command.points.currentpoints", " &eCurrent point amount: &6%currentpoints%"); + c.get("command.points.totalpoints", " &eTotal amount of collected points until now: &6%totalpoints%"); + + c.get("command.editpoints.help.info", "Edit players points."); + c.get("command.editpoints.help.args", "set/add/take [playername] [amount]"); + Jobs.getGCManager().commandArgs.put("editpoints", Arrays.asList("set%%add%%take", "[playername]")); + c.get("command.editpoints.output.set", "&ePlayers (&6%playername%&e) points was set to &6%amount%"); + c.get("command.editpoints.output.add", "&ePlayer (&6%playername%&e) got aditinal &6%amount% &epoints. Now he has &6%total%"); + c.get("command.editpoints.output.take", "&ePlayer (&6%playername%&e) lost &6%amount% &epoints. Now he has &6%total%"); + + c.get("command.editjobs.help.info", "Edit current jobs."); + c.get("command.editjobs.help.args", ""); + c.get("command.editjobs.help.list.job", "&eJobs:"); + c.get("command.editjobs.help.list.jobs", " -> [&e%jobname%&r]"); + c.get("command.editjobs.help.list.actions", " -> [&e%actionname%&r]"); + c.get("command.editjobs.help.list.material", " -> [&e%materialname%&r] "); + c.get("command.editjobs.help.list.materialRemove", "&c[X]"); + c.get("command.editjobs.help.list.materialAdd", " -> &e[&2+&e]"); + c.get("command.editjobs.help.list.money", " -> &eMoney: &6%amount%"); + c.get("command.editjobs.help.list.exp", " -> &eExp: &6%amount%"); + c.get("command.editjobs.help.list.points", " -> &ePoints: &6%amount%"); + c.get("command.editjobs.help.modify.newValue", "&eEnter new value"); + c.get("command.editjobs.help.modify.enter", "&eEnter new name or press "); + c.get("command.editjobs.help.modify.hand", "&6HAND "); + c.get("command.editjobs.help.modify.handHover", "&6Press to grab info from item in your hand"); + c.get("command.editjobs.help.modify.or", "&eor "); + c.get("command.editjobs.help.modify.look", "&6LOOKING AT"); + c.get("command.editjobs.help.modify.lookHover", "&6Press to grab info from block you are looking"); + + c.get("command.blockinfo.help.info", "Shows block information you looking at."); + c.get("command.blockinfo.help.args", ""); + c.get("command.blockinfo.output.name", " &eBlock name: &6%blockname%"); + c.get("command.blockinfo.output.id", " &eBlock id: &6%blockid%"); + c.get("command.blockinfo.output.data", " &eBlock data: &6%blockdata%"); + c.get("command.blockinfo.output.usage", " &eUsage: &6%first% &eor &6%second%"); + + c.get("command.iteminfo.help.info", "Shows item information you holding."); + c.get("command.iteminfo.help.args", ""); + c.get("command.iteminfo.output.name", " &eItem name: &6%itemname%"); + c.get("command.iteminfo.output.id", " &eItem id: &6%itemid%"); + c.get("command.iteminfo.output.data", " &eItem data: &6%itemdata%"); + c.get("command.iteminfo.output.usage", " &eUsage: &6%first% &eor &6%second%"); + + + c.get("command.placeholders.help.info", "List out all placeholders"); + c.get("command.placeholders.help.args", "(parse) (placeholder)"); + c.get("command.placeholders.output.list", "&e[place]. &7[placeholder]"); + c.get("command.placeholders.output.outputResult", " &eresult: &7[result]"); + c.get("command.placeholders.output.parse", "&6[placeholder] &7by [source] &6result &8|&f[result]&8|"); + + + c.get("command.entitylist.help.info", "Shows all possible entities can be used with plugin."); + c.get("command.entitylist.help.args", ""); + + c.get("command.stats.help.info", "Show the level you are in each job you are part of."); + c.get("command.stats.help.args", "[playername]"); + Jobs.getGCManager().commandArgs.put("stats", Arrays.asList("[playername]")); + c.get("command.stats.error.nojob", "Please join a job first."); + c.get("command.stats.output", " lvl%joblevel% %jobname% : %jobxp%/%jobmaxxp% xp"); + + c.get("command.shop.help.info", "Opens special jobs shop."); + c.get("command.shop.help.args", ""); + c.get("command.shop.info.title", "&e------- &8Jobs shop &e-------"); + c.get("command.shop.info.currentPoints", "&eYou have: &6%currentpoints%"); + c.get("command.shop.info.price", "&ePrice: &6%price%"); + c.get("command.shop.info.reqJobs", "&eRequired jobs:"); + c.get("command.shop.info.reqJobsList", " &6%jobsname%&e: &e%level% lvl"); + c.get("command.shop.info.reqTotalLevel", "&6Required total level: &e%totalLevel%"); + c.get("command.shop.info.cantOpen", "&cCan't open this page"); + c.get("command.shop.info.NoPermForItem", "&cYou don't have required permissions for this item!"); + c.get("command.shop.info.NoPermToBuy", "&cNo permissions to buy this item"); + c.get("command.shop.info.NoJobReqForitem", "&cYou don't have required job (&6%jobname%&e) with required (&6%joblevel%&e) level"); + c.get("command.shop.info.NoPoints", "&cYou don't have enough points"); + c.get("command.shop.info.NoTotalLevel", "&cTotal jobs level is too low (%totalLevel%)"); + c.get("command.shop.info.Paid", "&eYou have paid &6%amount% &efor this item"); + c.get("command.shop.info.reqJobsList", " &6%jobsname%&e: &e%level% lvl"); + + c.get("command.archive.help.info", "Shows all jobs saved in archive by user."); + c.get("command.archive.help.args", "[playername]"); + Jobs.getGCManager().commandArgs.put("archive", Arrays.asList("[playername]")); + c.get("command.archive.error.nojob", "There is no jobs saved."); + + c.get("command.give.help.info", "Gives item by jobs name and item category name. Player name is optional"); + c.get("command.give.help.args", "[playername] [jobname] [jobitemname]"); + Jobs.getGCManager().commandArgs.put("give", Arrays.asList("[playername]", "[jobname]", "[jobitemname]")); + c.get("command.give.output.notonline", "&4Player [%playername%] is not online!"); + c.get("command.give.output.noitem", "&4Can't find any item by given name!"); + + c.get("command.info.help.title", "&2*** &eJobs&2 ***"); + c.get("command.info.help.info", "Show how much each job is getting paid and for what."); + c.get("command.info.help.penalty", "&eThis job have &c[penalty]% &epenalty because of too many players working in it."); + c.get("command.info.help.bonus", "&eThis job have &2[bonus]% &ebonus because not enough players working in it."); + c.get("command.info.help.args", "[jobname] [action]"); + Jobs.getGCManager().commandArgs.put("info", Arrays.asList("[jobname]", "[action]")); + c.get("command.info.help.actions", "&eValid actions are: &f%actions%"); + c.get("command.info.help.max", " - &emax level:&f "); + c.get("command.info.help.newMax", " &eMax level: &f[max]"); + c.get("command.info.help.material", "&7%material%"); + + c.get("command.info.help.levelRange", " &a(&e%levelFrom% &a- &e%levelUntil% &alevels)"); + c.get("command.info.help.levelFrom", " &a(from &e%levelFrom% &alevel)"); + c.get("command.info.help.levelUntil", " &a(until &e%levelUntil% &alevel)"); + + c.get("command.info.help.money", " &2%money%\u0024"); + c.get("command.info.help.points", " &6%points%pts"); + c.get("command.info.help.exp", " &e%exp%xp"); + + c.get("command.info.gui.pickjob", "&ePick your job!"); + c.get("command.info.gui.jobinfo", "&e[jobname] info!"); + c.get("command.info.gui.actions", "&eValid actions are:"); + c.get("command.info.gui.leftClick", "&eLeft Click for more info"); + c.get("command.info.gui.rightClick", "&eRight click to join job"); + c.get("command.info.gui.leftSlots", "&eLeft slots:&f "); + c.get("command.info.gui.working", "&2&nAlready working"); + c.get("command.info.gui.max", "&eMax level:&f "); + c.get("command.info.gui.back", "&e<<< Back"); + + c.get("command.info.output.break.info", "&eBreak"); + c.get("command.info.output.break.none", "%jobname% does not get money for breaking blocks."); + c.get("command.info.output.tntbreak.info", "&eTNTBreak"); + c.get("command.info.output.tntbreak.none", "%jobname% does not get money for breaking blocks with tnt."); + c.get("command.info.output.place.info", "&ePlace"); + c.get("command.info.output.place.none", "%jobname% does not get money for placing blocks."); + c.get("command.info.output.kill.info", "&eKill"); + c.get("command.info.output.kill.none", "%jobname% does not get money for killing monsters."); + c.get("command.info.output.mmkill.info", "&eMMKill"); + c.get("command.info.output.mmkill.none", "%jobname% does not get money for killing Mythic monsters."); + c.get("command.info.output.fish.info", "&eFish"); + c.get("command.info.output.fish.none", "%jobname% does not get money from fishing."); + c.get("command.info.output.craft.info", "&eCraft"); + c.get("command.info.output.craft.none", "%jobname% does not get money from crafting."); + c.get("command.info.output.drink.info", "&eDrink"); + c.get("command.info.output.drink.none", "%jobname% does not get money for drinking."); + c.get("command.info.output.smelt.info", "&eSmelt"); + c.get("command.info.output.smelt.none", "%jobname% does not get money from smelting."); + c.get("command.info.output.brew.info", "&eBrew"); + c.get("command.info.output.brew.none", "%jobname% does not get money from brewing."); + c.get("command.info.output.eat.info", "&eEat"); + c.get("command.info.output.eat.none", "%jobname% does not get money from eating food."); + c.get("command.info.output.dye.info", "&eDye"); + c.get("command.info.output.dye.none", "%jobname% does not get money from dyeing."); + c.get("command.info.output.enchant.info", "&eEnchant"); + c.get("command.info.output.enchant.none", "%jobname% does not get money from enchanting."); + c.get("command.info.output.vtrade.info", "&eVillager trade"); + c.get("command.info.output.vtrade.none", "%jobname% does not get money for trading a villager."); + c.get("command.info.output.repair.info", "&eRepair"); + c.get("command.info.output.repair.none", "%jobname% does not get money from repairing."); + c.get("command.info.output.breed.info", "&eBreed"); + c.get("command.info.output.breed.none", "%jobname% does not get money from breeding."); + c.get("command.info.output.tame.info", "&eTame"); + c.get("command.info.output.tame.none", "%jobname% does not get money from taming."); + c.get("command.info.output.milk.info", "&eMilk"); + c.get("command.info.output.milk.none", "%jobname% does not get money from milking cows."); + c.get("command.info.output.shear.info", "&eShear"); + c.get("command.info.output.shear.none", "%jobname% does not get money from shearing sheeps."); + c.get("command.info.output.explore.info", "&eExplore"); + c.get("command.info.output.explore.none", "%jobname% does not get money from exploring."); + c.get("command.info.output.custom-kill.info", "&eCustom kill"); + c.get("command.info.output.custom-kill.none", "%jobname% does not get money from custom player kills."); + + c.get("command.playerinfo.help.info", "Show how much each job is getting paid and for what on another player."); + c.get("command.playerinfo.help.args", "[playername] [jobname] [action]"); + Jobs.getGCManager().commandArgs.put("playerinfo", Arrays.asList("[playername]", "[jobname]", "[action]")); + + c.get("command.join.help.info", "Join the selected job."); + c.get("command.join.help.args", "[jobname]"); + Jobs.getGCManager().commandArgs.put("join", Arrays.asList("[jobname]")); + c.get("command.join.error.alreadyin", "You are already in the job %jobname%."); + c.get("command.join.error.fullslots", "You cannot join the job %jobname%, there are no slots available."); + c.get("command.join.error.maxjobs", "You have already joined too many jobs."); + c.get("command.join.error.rejoin", "&cCan't rejoin this job. Wait [time]"); + c.get("command.join.rejoin", "&aClick to rejoin this job: "); + c.get("command.join.success", "You have joined the job %jobname%."); + c.get("command.join.confirm", "&2Click to confirm join action for &7[jobname] &2job."); + + c.get("command.leave.help.info", "Leave the selected job."); + c.get("command.leave.help.args", "[oldplayerjob]"); + Jobs.getGCManager().commandArgs.put("leave", Arrays.asList("[oldplayerjob]")); + c.get("command.leave.success", "You have left the job %jobname%."); + + c.get("command.leaveall.help.info", "Leave all your jobs."); + c.get("command.leaveall.error.nojobs", "You do not have any jobs to leave!"); + c.get("command.leaveall.success", "You have left all your jobs."); + + c.get("command.explored.help.info", "Check who visited this chunk"); + c.get("command.explored.error.noexplore", "No one visited this chunk"); + c.get("command.explored.list", "&e%place%. %playername%"); + + c.get("command.browse.help.info", "List the jobs available to you."); + c.get("command.browse.error.nojobs", "There are no jobs you can join."); + c.get("command.browse.output.header", "You are allowed to join the following jobs:"); + c.get("command.browse.output.footer", "For more information type in /jobs info [JobName]"); + c.get("command.browse.output.totalWorkers", " &7Workers: &e[amount]"); + c.get("command.browse.output.penalty", " &4Penalty: &c[amount]%"); + c.get("command.browse.output.bonus", " &2Bonus: &a[amount]%"); + + c.get("command.browse.output.newHeader", "&2========== [amount] Available Jobs ========="); + c.get("command.browse.output.description", "[description]"); + c.get("command.browse.output.list", " &8[place]. &7[jobname]"); + + c.get("command.browse.output.console.newHeader", "&2========== [amount] Available Jobs ========="); + c.get("command.browse.output.console.description", "[description]"); + c.get("command.browse.output.console.totalWorkers", " &7Workers: &e[amount]"); + c.get("command.browse.output.console.penalty", " &4Penalty: &c[amount]%"); + c.get("command.browse.output.console.bonus", " &2Bonus: &a[amount]%"); + c.get("command.browse.output.console.list", " &6[jobname]"); + c.get("command.browse.output.console.newMax", " &eMax level: &f[max]"); + + c.get("command.browse.output.click", "&bClick on the job to see more info about it!"); + c.get("command.browse.output.detailed", "&bClick to see more detailed list on job actions"); + + c.get("command.browse.output.jobHeader", "&2========== [jobname] ========="); + c.get("command.browse.output.chooseJob", "&7&n&oChoose this job"); + c.get("command.browse.output.chooseJobHover", "&7Click here to get this job"); + + c.get("command.clearownership.help.info", "Clear block ownership"); + c.get("command.clearownership.help.args", "[playername]"); + Jobs.getGCManager().commandArgs.put("clearownership", Arrays.asList("[playername]")); + c.get("command.clearownership.output.cleared", "&2Removed &7[furnaces] &2furnaces and &7[brewing] &2brewing stands"); + + c.get("command.quests.help.info", "List available quests"); + c.get("command.quests.help.args", "[playername]"); + Jobs.getGCManager().commandArgs.put("quests", Arrays.asList("[playername]")); + c.get("command.quests.error.noquests", "&cThere are no quests"); + c.get("command.quests.toplineseparator", "&7*********************** &6[playerName]&2(&f[questsDone]&2) &7***********************"); + c.get("command.quests.output.completed", "&2 !Completed!&r "); + c.get("command.quests.output.questLine", "[progress] &7[questName] &f[done]&7/&8[required]"); + c.get("command.quests.output.hover", Arrays.asList("&f[jobName]", "[desc]", "&7New quest in: [time]")); + + c.get("command.fire.help.info", "Fire the player from the job."); + c.get("command.fire.help.args", "[playername] [jobname]"); + Jobs.getGCManager().commandArgs.put("fire", Arrays.asList("[playername]", "[jobname]")); + c.get("command.fire.error.nojob", "Player does not have the job %jobname%."); + c.get("command.fire.output.target", "You have been fired from %jobname%."); + + c.get("command.fireall.help.info", "Fire player from all their jobs."); + c.get("command.fireall.help.args", "[playername]"); + Jobs.getGCManager().commandArgs.put("fireall", Arrays.asList("[playername]")); + c.get("command.fireall.error.nojobs", "Player does not have any jobs to be fired from!"); + c.get("command.fireall.output.target", "You have been fired from all your jobs."); + + c.get("command.employ.help.info", "Employ the player to the job."); + c.get("command.employ.help.args", "[playername] [jobname]"); + Jobs.getGCManager().commandArgs.put("employ", Arrays.asList("[playername]", "[jobname]")); + c.get("command.employ.error.alreadyin", "Player is already in the job %jobname%."); + c.get("command.employ.output.target", "You have been employed as a %jobname%."); + + c.get("command.top.help.info", "Shows top %amount% players by jobs name."); + c.get("command.top.help.args", "[jobname]"); + Jobs.getGCManager().commandArgs.put("top", Arrays.asList("[jobname]")); + c.get("command.top.error.nojob", "Can't find any job with this name."); + c.get("command.top.output.topline", "&aTop&e %amount% &aplayers by &e%jobname% &ajob"); + c.get("command.top.output.list", "&e%number%&a. &e%playername% &alvl &e%level% &awith&e %exp% &aexp"); + c.get("command.top.output.prev", "&e<<<<< Prev page &2|"); + c.get("command.top.output.next", "&2|&e Next Page >>>>"); + c.get("command.top.output.show", "&2Show from &e[from] &2until &e[until] &2top list"); + + c.get("command.gtop.help.info", "Shows top %amount% players by global jobs level."); + c.get("command.gtop.help.args", ""); + c.get("command.gtop.error.nojob", "Can't find any information."); + c.get("command.gtop.output.topline", "&aTop&e %amount% &aplayers by global job level"); + c.get("command.gtop.output.list", "&e%number%&a. &e%playername% &alvl &e%level% &awith&e %exp% &aexp"); + c.get("command.gtop.output.prev", "&e<<<<< Prev page &2|"); + c.get("command.gtop.output.next", "&2|&e Next Page >>>>"); + c.get("command.gtop.output.show", "&2Show from &e[from] &2until &e[until] &2global top list"); + + c.get("command.area.help.info", "Modify restricted areas."); + c.get("command.area.help.args", "add/remove/info/list"); + Jobs.getGCManager().commandArgs.put("area", Arrays.asList("add%%remove%%info%%list")); + c.get("command.area.help.addUsage", "&eUsage: &6/Jobs area add [areaName/wg:worldGuardAreaName] [bonus]"); + c.get("command.area.help.removeUsage", "&eUsage: &6/Jobs area remove [areaName]"); + c.get("command.area.output.addedNew", "&eAdded new restricted area with &6%bonus% &ebonus"); + c.get("command.area.output.removed", "&eRemoved restricted area &6%name%"); + c.get("command.area.output.list", "&e%number%&a. &e%areaname% &e%worldname% (&a%x1%:%y1%:%z1%/&e%x2%:%y2%:%z2%) &6%bonus%"); + c.get("command.area.output.wgList", "&e%number%&a. WorldGuard: &e%areaname% &6%bonus%"); + c.get("command.area.output.noAreas", "&eThere is no saved restricted areas"); + c.get("command.area.output.noAreasByLoc", "&eThere is no restricted areas in this location"); + c.get("command.area.output.areaList", "&eRestricted areas by your location: &6%list%"); + c.get("command.area.output.selected1", "&eSelected first point: &6%x%:%y%:%z%"); + c.get("command.area.output.selected2", "&eSelected second point: &6%x%:%y%:%z%"); + c.get("command.area.output.select", "&eSelect 2 points with selection tool (%tool%)"); + c.get("command.area.output.exist", "&eRestriction area by this name already exist"); + c.get("command.area.output.dontExist", "&eRestriction area by this name don't exist"); + c.get("command.area.output.wgDontExist", "&eWorldGuard area by this name don't exist"); + + c.get("command.log.help.info", "Shows statistics."); + c.get("command.log.help.args", "[playername]"); + Jobs.getGCManager().commandArgs.put("log", Arrays.asList("[playername]")); + c.get("command.log.output.topline", "&7************************* &6%playername% &7*************************"); + c.get("command.log.output.ls", "&7* &6%number%. &3%action%: &6%item% &eqty: %qty% %money%%exp%%points%"); + c.get("command.log.output.money", "&6money: %amount% "); + c.get("command.log.output.exp", "&eexp: %amount% "); + c.get("command.log.output.points", "&6points: %amount%"); + c.get("command.log.output.bottomline", "&7***********************************************************"); + c.get("command.log.output.prev", "&e<<<<< Prev page &2|"); + c.get("command.log.output.next", "&2|&e Next Page >>>>"); + c.get("command.log.output.nodata", "&cData not found"); + + c.get("command.glog.help.info", "Shows global statistics."); + c.get("command.glog.help.args", ""); + c.get("command.glog.output.topline", "&7*********************** &6Global statistics &7***********************"); + c.get("command.glog.output.ls", "&7* &6%number%. &3%action%: &6%item% &eqty: %qty% %money%%exp%%points%"); + c.get("command.glog.output.money", "&6money: %amount% "); + c.get("command.glog.output.exp", "&eexp: %amount% "); + c.get("command.glog.output.points", "&6points: %amount%"); + c.get("command.glog.output.bottomline", "&7**************************************************************"); + c.get("command.glog.output.nodata", "&cData not found"); + + c.get("command.transfer.help.info", "Transfer a player's job from an old job to a new job."); + c.get("command.transfer.help.args", "[playername] [oldjob] [newjob]"); + Jobs.getGCManager().commandArgs.put("transfer", Arrays.asList("[playername]", "[oldjob]", "[newjob]")); + c.get("command.transfer.output.target", "You have been transferred from %oldjobname% to %newjobname%."); + + c.get("command.promote.help.info", "Promote the player X levels in a job."); + c.get("command.promote.help.args", "[playername] [jobname] [levels]"); + Jobs.getGCManager().commandArgs.put("promote", Arrays.asList("[playername]", "[jobname]", "[levels]")); + c.get("command.promote.output.target", "You have been promoted %levelsgained% levels in %jobname%."); + + c.get("command.exp.help.info", "Change the player exp for job."); + c.get("command.exp.help.args", "[playername] [jobname] set/add/take [amount]"); + Jobs.getGCManager().commandArgs.put("exp", Arrays.asList("[playername]", "[jobname]", "set%%add%%take")); + c.get("command.exp.output.target", "&eYour exp was changed for %jobname% &eand now you at &6%level%lvl &eand with &6%exp%exp."); + + c.get("command.level.help.info", "Change the player level for job."); + c.get("command.level.help.args", "[playername] [jobname] set/add/take [amount]"); + Jobs.getGCManager().commandArgs.put("level", Arrays.asList("[playername]", "[jobname]", "set%%add%%take")); + c.get("command.level.output.target", "&eYour level was changed for %jobname% &eand now you at &6%level%lvl &eand with &6%exp%exp."); + + c.get("command.demote.help.info", "Demote the player X levels in a job."); + c.get("command.demote.help.args", "[playername] [jobname] [levels]"); + Jobs.getGCManager().commandArgs.put("demote", Arrays.asList("[playername]", "[jobname]", "[levels]")); + c.get("command.demote.output.target", "You have been demoted %levelslost% levels in %jobname%."); + + c.get("command.grantxp.help.info", "Grant the player X experience in a job."); + c.get("command.grantxp.help.args", "[playername] [jobname] [xp]"); + Jobs.getGCManager().commandArgs.put("grantxp", Arrays.asList("[playername]", "[jobname]", "[xp]")); + c.get("command.grantxp.output.target", "You have been granted %xpgained% experience in %jobname%."); + + c.get("command.removexp.help.info", "Remove X experience from the player in a job."); + c.get("command.removexp.help.args", "[playername] [jobname] [xp]"); + Jobs.getGCManager().commandArgs.put("removexp", Arrays.asList("[playername]", "[jobname]", "[xp]")); + c.get("command.removexp.output.target", "You have lost %xplost% experience in %jobname%."); + + c.get("command.signupdate.help.info", "Manualy updates sign by its name"); + c.get("command.signupdate.help.args", "[jobname]"); + Jobs.getGCManager().commandArgs.put("signupdate", Arrays.asList("[jobname]")); + + c.get("command.bp.help.info", "Shows Block protection arround you in 10 block radius"); + c.get("command.bp.help.args", ""); + c.get("command.bp.output.found", "&eFound &6%amount% &eprotected blocks around you"); + c.get("command.bp.output.notFound", "&eNo protected blocks found around you"); + + c.get("command.reload.help.info", "Reload configurations."); + + c.get("command.toggle.help.info", "Toggles payment output on action bar or bossbar."); + c.get("command.toggle.help.args", "actionbar/bossbar"); + Jobs.getGCManager().commandArgs.put("toggle", Arrays.asList("actionbar%%bossbar")); + c.get("command.toggle.output.turnedoff", "&4This feature are turned off!"); + c.get("command.toggle.output.paid.main", "&aYou got:"); + c.get("command.toggle.output.paid.money", "&e[amount] money"); + c.get("command.toggle.output.paid.exp", "&7[exp] exp"); + c.get("command.toggle.output.paid.points", "&6[points] points"); + c.get("command.toggle.output.on", "&aToggled: &aON"); + c.get("command.toggle.output.off", "&aToggled: &4OFF"); + + c.get("message.skillup.broadcast", "%playername% has been promoted to a %titlename% %jobname%."); + c.get("message.skillup.nobroadcast", "Congratulations, you have been promoted to a %titlename% %jobname%."); + + c.get("message.levelup.broadcast", "%playername% is now a level %joblevel% %jobname%."); + c.get("message.levelup.nobroadcast", "You are now a level %joblevel% %jobname%."); + + c.get("message.cowtimer", "&eYou still need to wait &6%time% &esec to get paid for this job."); + c.get("message.blocktimer", "&eYou need to wait: &3[time] &esec more to get paid for this!"); + c.get("message.placeblocktimer", "&eYou can't place block faster than &6[time] &esec interval in same place!"); + c.get("message.taxes", "&3[amount] &eserver taxes where transfered to this account"); + + c.get("message.boostStarted", "&eJobs boost time have been started!"); + c.get("message.boostStoped", "&eJobs boost time have been ended!"); + + c.get("message.crafting.fullinventory", "&cYour inventory is full!"); + + c.get("signs.List", "&0[number].&8[player]&7:&4[level]"); + c.get("signs.SpecialList.p1", "&b** &8First &b**"); + c.get("signs.SpecialList.p2", "&b** &8Second &b**"); + c.get("signs.SpecialList.p3", "&b** &8Third &b**"); + c.get("signs.SpecialList.p4", "&b** &8Fourth &b**"); + c.get("signs.SpecialList.p5", "&b** &8Fifth &b**"); + c.get("signs.SpecialList.p6", "&b** &8Sixth &b**"); + c.get("signs.SpecialList.p7", "&b** &8Seventh &b**"); + c.get("signs.SpecialList.p8", "&b** &8Eight &b**"); + c.get("signs.SpecialList.p9", "&b** &8Ninth &b**"); + c.get("signs.SpecialList.p10", "&b** &8Tenth &b**"); + c.get("signs.SpecialList.name", "&9[player]"); + c.get("signs.SpecialList.level", "&8[level] level"); + c.get("signs.SpecialList.bottom", "&b************"); + c.get("signs.cantcreate", "&4You can't create this sign!"); + c.get("signs.cantdestroy", "&4You can't destroy this sign!"); + c.get("signs.topline", "&0[Jobs]"); + c.get("signs.secondline.join", "&0Join"); + c.get("signs.secondline.leave", "&0Leave"); + c.get("signs.secondline.toggle", "&0Toggle"); + c.get("signs.secondline.top", "&0Top"); + c.get("signs.secondline.browse", "&0Browse"); + c.get("signs.secondline.stats", "&0Stats"); + c.get("signs.secondline.limit", "&0Limit"); + c.get("signs.secondline.info", "&0Info"); + c.get("signs.secondline.archive", "&0Archive"); + + //c.get("scoreboard.clear", "&eIf you want to remove scoreboard, type &2/jobs top clear"); + c.get("scoreboard.topline", "&2Top &e%jobname%"); + c.get("scoreboard.gtopline", "&2Global top list"); + c.get("scoreboard.line", "&2%number%. &e%playername% (&6%level%&e)"); + + Jobs.getGCManager().keys = new ArrayList<>(c.getC().getConfigurationSection("signs.secondline").getKeys(false)); + + // Write back config + try { + c.getW().save(f); + } catch (IOException e) { + e.printStackTrace(); + } + } + } +} diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index 574cba53..6ba16814 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -1,961 +1,973 @@ -/** - * Jobs Plugin for Bukkit - * Copyright (C) 2011 Zak Ford - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.gamingmesh.jobs.container; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map.Entry; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import com.gamingmesh.jobs.Jobs; -import com.gamingmesh.jobs.dao.JobsDAO; -import com.gamingmesh.jobs.economy.PaymentData; -import com.gamingmesh.jobs.resources.jfep.Parser; -import com.gamingmesh.jobs.stuff.ChatColor; -import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling; -import com.gamingmesh.jobs.stuff.TimeManage; - -public class JobsPlayer { - // the player the object belongs to - private String userName; - // progression of the player in each job - public UUID playerUUID; - public ArrayList progression = new ArrayList<>(); - private ArchivedJobs archivedJobs = new ArchivedJobs(); - - private PaymentData paymentLimits = null; - - private HashMap> boostCounter = new HashMap<>(); - - // display honorific - private String honorific; - // player save status - private volatile boolean isSaved = true; - // player online status - private volatile boolean isOnline = false; - - private HashMap limits = new HashMap<>(); - - private int userid = -1; - - private List barMap = new ArrayList<>(); - private List updateBossBarFor = new ArrayList<>(); - // save lock -// public final Object saveLock = new Object(); - - // log - private HashMap logList = new HashMap<>(); - - private Long seen = System.currentTimeMillis(); - - private HashMap permissionsCache = null; - private Long lastPermissionUpdate = -1L; - - private HashMap> qProgression = new HashMap<>(); - private int doneQuests = 0; - - public JobsPlayer(String userName) { - this.userName = userName; - } - - public ArchivedJobs getArchivedJobs() { - return archivedJobs; - } - - public JobProgression getArchivedJobProgression(Job job) { - return archivedJobs.getArchivedJobProgression(job); - } - - public void setArchivedJobs(ArchivedJobs archivedJob) { - this.archivedJobs = archivedJob; - } - - public int getTotalLevels() { - int i = 0; - for (JobProgression job : progression) { - i += job.getLevel(); - } - return i; - } - - public void setPaymentLimit(PaymentData paymentLimits) { - this.paymentLimits = paymentLimits; - } - - public PaymentData getPaymentLimit() { - if (paymentLimits == null) { - paymentLimits = Jobs.getJobsDAO().getPlayersLimits(this); - } - if (paymentLimits == null) - paymentLimits = new PaymentData(); - return paymentLimits; - } - - public boolean isUnderLimit(CurrencyType type, Double amount) { - Player player = this.getPlayer(); - if (player == null) - return true; - if (amount == 0) - return true; - CurrencyLimit limit = Jobs.getGCManager().getLimit(type); - if (!limit.isEnabled()) - return true; - PaymentData data = getPaymentLimit(); - Integer value = this.limits.get(type); - if (data.IsReachedLimit(type, value == null ? 0 : value)) { - if (player.isOnline() && !data.isInformed() && !data.isReseted()) { - player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.reached" + type.getName().toLowerCase() + "limit")); - player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.reached" + type.getName().toLowerCase() + "limit2")); - data.setInformed(); - } - if (data.IsAnnounceTime(limit.getAnnouncementDelay()) && player.isOnline()) { - Jobs.getActionBar().send(player, Jobs.getLanguage().getMessage("command.limit.output." + type.getName().toLowerCase() + "time", "%time%", TimeManage.to24hourShort(data.GetLeftTime(type)))); - } - if (data.isReseted()) - data.setReseted(false); - return false; - } - data.AddAmount(type, amount); - return true; - } - - public void loadLogFromDao() { - Jobs.getJobsDAO().loadLog(this); - } - - public synchronized List getUpdateBossBarFor() { - return updateBossBarFor; - } - - public synchronized void clearUpdateBossBarFor() { - updateBossBarFor.clear(); - } - - public synchronized List getBossBarInfo() { - return barMap; - } - - public synchronized void hideBossBars() { - for (BossBarInfo one : this.barMap) { - one.getBar().setVisible(false); - } - } - - public HashMap getLog() { - return logList; - } - - public void setLog(HashMap logList) { - this.logList = logList; - } - - public void setUserId(int userid) { - this.userid = userid; - } - - public int getUserId() { - return userid; - } - - /** - * Get the player - * @return the player - */ - public Player getPlayer() { - if (this.playerUUID != null) { - return Bukkit.getPlayer(this.playerUUID); - } - return null; - } - - /** - * Get the Boost - * @return the Boost - */ - public double getBoost(String JobName, CurrencyType type) { - return getBoost(JobName, type, false); - } - - public double getBoost(String JobName, CurrencyType type, boolean force) { - double Boost = 0D; - if (!this.isOnline()) - return Boost; - if (type == null) - return Boost; - - long time = System.currentTimeMillis(); - - if (this.boostCounter.containsKey(JobName)) { - ArrayList counterList = boostCounter.get(JobName); - for (BoostCounter counter : counterList) { - if (counter.getType() != type) - continue; - if (force || time - counter.getTime() > 1000 * 60) { - Boost = getPlayerBoostNew(JobName, type); - counter.setBoost(Boost); - counter.setTime(time); - return Boost; - } - return counter.getBoost(); - } - Boost = getPlayerBoostNew(JobName, type); - counterList.add(new BoostCounter(type, Boost, time)); - return Boost; - } - - Boost = getPlayerBoostNew(JobName, type); - - ArrayList counterList = new ArrayList<>(); - counterList.add(new BoostCounter(type, Boost, time)); - - boostCounter.put(JobName, counterList); - return Boost; - } - - private Double getPlayerBoostNew(String JobName, CurrencyType type) { - Double Boost = null; - Double v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost." + JobName + "." + type.getName().toLowerCase(), true); - Boost = v1; - v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost." + JobName + ".all"); - if (Boost == null || v1 != null && v1 > Boost) - Boost = v1; - v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost.all.all"); - if (Boost == null || v1 != null && v1 > Boost) - Boost = v1; - v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost.all." + type.getName().toLowerCase()); - if (Boost == null || v1 != null && v1 > Boost) - Boost = v1; - return Boost == null ? 0D : Boost; - } - - // New method is in use -// private Double getPlayerBoost(String JobName, CurrencyType type) { -// double Boost = 0D; -// if (Perm.hasPermission(player, "jobs.boost." + JobName + "." + type.getName().toLowerCase()) || -// Perm.hasPermission(player, "jobs.boost." + JobName + ".all") || -// Perm.hasPermission(player, "jobs.boost.all.all") || -// Perm.hasPermission(player, "jobs.boost.all." + type.getName().toLowerCase())) { -// Boost = Jobs.getGCManager().Boost.get(type); -// } -// return Boost; -// } - - /** - * Reloads max experience for this job. - */ - public void reloadMaxExperience() { - for (JobProgression prog : progression) { - prog.reloadMaxExperience(); - } - } - - /** - * Reloads limit for this player. - */ - public void reload(CurrencyType type) { - int TotalLevel = 0; - for (JobProgression prog : progression) { - TotalLevel += prog.getLevel(); - } - Parser eq = Jobs.getGCManager().currencyLimitUse.get(type).getMaxEquation(); - eq.setVariable("totallevel", TotalLevel); - limits.put(type, (int) eq.getValue()); - setSaved(false); - } - - public void reloadLimits() { - for (CurrencyType type : CurrencyType.values()) { - reload(type); - } - } - - public int getLimit(CurrencyType type) { - if (type == null) - return 0; - Integer value = this.limits.get(type); - return value == null ? 0 : value; - } - - public void resetPaymentLimit() { - if (paymentLimits == null) - getPaymentLimit(); - if (paymentLimits != null) - paymentLimits.resetLimits(); - setSaved(false); - } - - /** - * Get the list of job progressions - * @return the list of job progressions - */ - public List getJobProgression() { - return Collections.unmodifiableList(progression); - } - - /** - * Check if have permission - * @return true if have - */ - public boolean havePermission(String perm) { - Player player = Bukkit.getPlayer(this.getPlayerUUID()); - if (player != null) - return player.hasPermission(perm); - return false; - } - - /** - * Get the job progression with the certain job - * @return the job progression - */ - public JobProgression getJobProgression(Job job) { - for (JobProgression prog : progression) { - if (prog.getJob().isSame(job)) - return prog; - } - return null; - } - - /** - * get the userName - * @return the userName - */ - public String getUserName() { - Player player = Bukkit.getPlayer(this.getPlayerUUID()); - if (player != null) - userName = player.getName(); - return userName; - } - - /** - * get the playerUUID - * @return the playerUUID - */ - public UUID getPlayerUUID() { - return this.playerUUID; - } - - public void setPlayerUUID(UUID playerUUID) { - this.playerUUID = playerUUID; - } - - public String getDisplayHonorific() { - if (honorific == null) - reloadHonorific(); - return honorific; - } - - /** - * Player joins a job - * @param job - the job joined - */ - public boolean joinJob(Job job) { -// synchronized (saveLock) { - if (!isInJob(job)) { - int level = 1; - int exp = 0; - - JobProgression archived = this.getArchivedJobProgression(job); - if (archived != null) { - level = getLevelAfterRejoin(archived); - exp = getExpAfterRejoin(archived, level); - Jobs.getJobsDAO().deleteArchive(this, job); - } - - progression.add(new JobProgression(job, this, level, exp)); - reloadMaxExperience(); - reloadLimits(); - reloadHonorific(); - Jobs.getPermissionHandler().recalculatePermissions(this); - return true; - } - return false; -// } - } - - public int getLevelAfterRejoin(JobProgression jp) { - if (jp == null) - return 1; - - int level = jp.getLevel(); - - level = (int) ((level - (level * (Jobs.getGCManager().levelLossPercentage / 100.0)))); - if (level < 1) - level = 1; - - Job job = jp.getJob(); - int maxLevel = this.getMaxJobLevelAllowed(job); - if (jp.getLevel() == maxLevel) { - if (Jobs.getGCManager().fixAtMaxLevel) { - level = jp.getLevel(); - } else { - level = jp.getLevel(); - level = (int) ((level - (level * (Jobs.getGCManager().levelLossPercentageFromMax / 100.0)))); - if (level < 1) - level = 1; - } - } - - return level; - } - - public int getExpAfterRejoin(JobProgression jp, int level) { - if (jp == null) - return 1; - Integer max = jp.getMaxExperience(level); - Double exp = jp.getExperience(); - if (exp > max) - exp = max.doubleValue(); - - if (exp > 0) { - Job job = jp.getJob(); - int maxLevel = this.getMaxJobLevelAllowed(job); - if (jp.getLevel() == maxLevel) { - if (!Jobs.getGCManager().fixAtMaxLevel) - exp = (exp - (exp * (Jobs.getGCManager().levelLossPercentageFromMax / 100.0))); - } else { - exp = (exp - (exp * (Jobs.getGCManager().levelLossPercentage / 100.0))); - } - } - return exp.intValue(); - } - - /** - * Player leaves a job - * @param job - the job left - */ - public boolean leaveJob(Job job) { -// synchronized (saveLock) { - JobProgression prog = getJobProgression(job); - if (prog != null) { - progression.remove(prog); - reloadMaxExperience(); - reloadLimits(); - reloadHonorific(); - Jobs.getPermissionHandler().recalculatePermissions(this); - return true; - } - return false; -// } - } - - /** - * Leave all jobs - * @return on success - */ - public boolean leaveAllJobs() { -// synchronized (saveLock) { - progression.clear(); - reloadHonorific(); - Jobs.getPermissionHandler().recalculatePermissions(this); - return true; -// } - } - - /** - * Promotes player in job - * @param job - the job being promoted - * @param levels - number of levels to promote - */ - public void promoteJob(Job job, int levels) { -// synchronized (saveLock) { - JobProgression prog = getJobProgression(job); - if (prog == null) - return; - if (levels <= 0) - return; - int oldLevel = prog.getLevel(); - int newLevel = oldLevel + levels; - - int maxLevel = job.getMaxLevel(this); - - if (maxLevel > 0 && newLevel > maxLevel) { - newLevel = maxLevel; - } - setLevel(job, newLevel); - Jobs.getPlayerManager().performCommandOnLevelUp(this, job, newLevel - 1); -// } - } - - /** - * Demotes player in job - * @param job - the job being deomoted - * @param levels - number of levels to demote - */ - public void demoteJob(Job job, int levels) { -// synchronized (saveLock) { - JobProgression prog = getJobProgression(job); - if (prog == null) - return; - if (levels <= 0) - return; - int newLevel = prog.getLevel() - levels; - if (newLevel < 1) { - newLevel = 1; - } - setLevel(job, newLevel); -// } - } - - /** - * Sets player to a specific level - * @param job - the job - * @param level - the level - */ - private void setLevel(Job job, int level) { -// synchronized (saveLock) { - JobProgression prog = getJobProgression(job); - if (prog == null) - return; - - if (level != prog.getLevel()) { - prog.setLevel(level); - reloadHonorific(); - Jobs.getPermissionHandler().recalculatePermissions(this); - } -// } - } - - /** - * Player leaves a job - * @param oldjob - the old job - * @param newjob - the new job - */ - public boolean transferJob(Job oldjob, Job newjob) { -// synchronized (saveLock) { - if (!isInJob(newjob)) { - for (JobProgression prog : progression) { - if (!prog.getJob().isSame(oldjob)) - continue; - - prog.setJob(newjob); - - int maxLevel = getMaxJobLevelAllowed(newjob); - - if (newjob.getMaxLevel() > 0 && prog.getLevel() > maxLevel) { - prog.setLevel(maxLevel); - } - reloadMaxExperience(); - reloadLimits(); - reloadHonorific(); - Jobs.getPermissionHandler().recalculatePermissions(this); - - return true; - } - } - return false; -// } - } - - public int getMaxJobLevelAllowed(Job job) { - int maxLevel = 0; - if (this.havePermission("jobs." + job.getName() + ".vipmaxlevel")) - maxLevel = job.getVipMaxLevel() > job.getMaxLevel() ? job.getVipMaxLevel() : job.getMaxLevel(); - else - maxLevel = job.getMaxLevel(); - int tMax = Jobs.getPermissionManager().getMaxPermission(this, "jobs." + job.getName() + ".vipmaxlevel").intValue(); - if (tMax > maxLevel) - maxLevel = tMax; - return maxLevel; - } - - /** - * Checks if the player is in this job. - * @param job - the job - * @return true - they are in the job - * @return false - they are not in the job - */ - public boolean isInJob(Job job) { - if (job == null) - return false; - for (JobProgression prog : progression) { - if (prog.getJob().isSame(job)) - return true; - } - return false; - } - - /** - * Function that reloads your honorific - */ - public void reloadHonorific() { - StringBuilder builder = new StringBuilder(); - int numJobs = progression.size(); - boolean gotTitle = false; - - if (numJobs > 0) { - for (JobProgression prog : progression) { - DisplayMethod method = prog.getJob().getDisplayMethod(); - if (method.equals(DisplayMethod.NONE)) - continue; - if (gotTitle) { - builder.append(Jobs.getGCManager().getModifyChatSeparator()); - gotTitle = false; - } - Title title = Jobs.gettitleManager().getTitle(prog.getLevel(), prog.getJob().getName()); - - if (numJobs == 1) { - if (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.TITLE)) { - if (title != null) { - String honorificpart = title.getChatColor() + title.getName() + ChatColor.WHITE; - if (honorificpart.contains("{level}")) - honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel())); - builder.append(honorificpart); - gotTitle = true; - } - } - if (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.JOB)) { - if (gotTitle) { - builder.append(" "); - } - String honorificpart = prog.getJob().getChatColor() + prog.getJob().getName() + ChatColor.WHITE; - if (honorificpart.contains("{level}")) - honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel())); - builder.append(honorificpart); - gotTitle = true; - } - } - - if (numJobs > 1 && (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.TITLE)) || method.equals(DisplayMethod.SHORT_FULL) || method.equals(DisplayMethod.SHORT_TITLE)) { - // add title to honorific - if (title != null) { - String honorificpart = title.getChatColor() + title.getShortName() + ChatColor.WHITE; - if (honorificpart.contains("{level}")) - honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel())); - builder.append(honorificpart); - gotTitle = true; - } - } - - if (numJobs > 1 && (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.JOB)) || method.equals(DisplayMethod.SHORT_FULL) || method.equals( - DisplayMethod.SHORT_JOB)) { - String honorificpart = prog.getJob().getChatColor() + prog.getJob().getShortName() + ChatColor.WHITE; - if (honorificpart.contains("{level}")) - honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel())); - builder.append(honorificpart); - gotTitle = true; - } - } - } else { - Job nonejob = Jobs.getNoneJob(); - if (nonejob != null) { - DisplayMethod metod = nonejob.getDisplayMethod(); - if (metod.equals(DisplayMethod.FULL) || metod.equals(DisplayMethod.TITLE)) { - String honorificpart = Jobs.getNoneJob().getChatColor() + Jobs.getNoneJob().getName() + ChatColor.WHITE; - if (honorificpart.contains("{level}")) - honorificpart = honorificpart.replace("{level}", ""); - builder.append(honorificpart); - } - - if (metod.equals(DisplayMethod.SHORT_FULL) || metod.equals(DisplayMethod.SHORT_TITLE) || metod.equals(DisplayMethod.SHORT_JOB)) { - String honorificpart = Jobs.getNoneJob().getChatColor() + Jobs.getNoneJob().getShortName() + ChatColor.WHITE; - if (honorificpart.contains("{level}")) - honorificpart = honorificpart.replace("{level}", ""); - builder.append(honorificpart); - } - } - } - - honorific = builder.toString().trim(); - if (honorific.length() > 0) - honorific = Jobs.getGCManager().getModifyChatPrefix() + honorific + Jobs.getGCManager().getModifyChatSuffix(); - - } - - /** - * Performs player save - * @param dao - */ - public void save() { -// synchronized (saveLock) { - if (!isSaved()) { - JobsDAO dao = Jobs.getJobsDAO(); - dao.save(this); - dao.saveLog(this); - dao.savePoints(this); - dao.recordPlayersLimits(this); - dao.updateSeen(this); - setSaved(true); - - if (this.getPlayer() == null || !this.getPlayer().isOnline()) { - Jobs.getPlayerManager().addPlayerToCache(this); - Jobs.getPlayerManager().removePlayer(this.getPlayer()); - } - } -// } - } - - /** - * Perform connect - */ - public void onConnect() { - isOnline = true; - } - - /** - * Perform disconnect - * - */ - public void onDisconnect() { -// Jobs.getJobsDAO().savePoints(this); - clearBossMaps(); - isOnline = false; - Jobs.getPlayerManager().addPlayerToCache(this); - } - - public void clearBossMaps() { - for (BossBarInfo one : barMap) { - one.cancel(); - } - barMap.clear(); - } - - /** - * Whether or not player is online - * @return true if online, otherwise false - */ - public boolean isOnline() { - if (this.getPlayer() != null) - return this.getPlayer().isOnline(); - return isOnline; - } - - public boolean isSaved() { - return isSaved; - } - - public void setSaved(boolean isSaved) { - this.isSaved = isSaved; - } - - public Long getSeen() { - return seen; - } - - public void setSeen(Long seen) { - this.seen = seen; - } - - public HashMap getPermissionsCache() { - return permissionsCache; - } - - public void setPermissionsCache(HashMap permissionsCache) { - this.permissionsCache = permissionsCache; - } - - public void setPermissionsCache(String permission, Boolean state) { - this.permissionsCache.put(permission, state); - } - - public Long getLastPermissionUpdate() { - return lastPermissionUpdate; - } - - public void setLastPermissionUpdate(Long lastPermissionUpdate) { - this.lastPermissionUpdate = lastPermissionUpdate; - } - - public boolean canGetPaid(ActionInfo info) { - - List progression = getJobProgression(); - int numjobs = progression.size(); - - if (numjobs == 0) { - if (Jobs.getNoneJob() == null) - return false; - JobInfo jobinfo = Jobs.getNoneJob().getJobInfo(info, 1); - if (jobinfo == null) - return false; - Double income = jobinfo.getIncome(1, numjobs); - Double points = jobinfo.getPoints(1, numjobs); - if (income == 0D && points == 0D) - return false; - } - - for (JobProgression prog : progression) { - int level = prog.getLevel(); - JobInfo jobinfo = prog.getJob().getJobInfo(info, level); - if (jobinfo == null) - continue; - Double income = jobinfo.getIncome(level, numjobs); - Double pointAmount = jobinfo.getPoints(level, numjobs); - Double expAmount = jobinfo.getExperience(level, numjobs); - if (income != 0D || pointAmount != 0D || expAmount != 0D) - return true; - } - - return false; - } - - public boolean inDailyQuest(Job job, String questName) { - - HashMap qpl = this.qProgression.get(job.getName()); - if (qpl == null) - return false; - - for (Entry one : qpl.entrySet()) { - if (one.getValue().getQuest().getConfigName().equalsIgnoreCase(questName)) - return true; - } - - return false; - } - - private List getQuestNameList(Job job, ActionType type) { - List ls = new ArrayList<>(); - if (!this.isInJob(job)) - return ls; - - HashMap qpl = this.qProgression.get(job.getName()); - - if (qpl == null) - return ls; - - for (Entry one : qpl.entrySet()) { - QuestProgression prog = one.getValue(); - if (!prog.isEnded() && (type == null || type.name().equals(prog.getQuest().getAction().name()))) - ls.add(prog.getQuest().getConfigName().toLowerCase()); - } - - return ls; - } - - public void resetQuests() { - for (JobProgression one : this.getJobProgression()) { - for (QuestProgression oneQ : this.getQuestProgressions(one.getJob())) { - oneQ.setValidUntil(0L); - } - } - getQuestProgressions(); - } - - public List getQuestProgressions() { - List g = new ArrayList<>(); - for (JobProgression one : this.getJobProgression()) { - g.addAll(this.getQuestProgressions(one.getJob())); - } - return g; - } - - public List getQuestProgressions(Job job) { - return getQuestProgressions(job, null); - } - - public List getQuestProgressions(Job job, ActionType type) { - if (!this.isInJob(job)) - return new ArrayList<>(); - HashMap g = new HashMap<>(); - - if (this.qProgression.get(job.getName()) != null) - g = new HashMap<>(this.qProgression.get(job.getName())); - - HashMap tmp = new HashMap<>(); - - for (Entry one : (new HashMap(g)).entrySet()) { - QuestProgression qp = one.getValue(); - if (qp == null || !qp.isValid()) { - Quest q = job.getNextQuest(getQuestNameList(job, type), this.getJobProgression(job).getLevel()); - - if (q == null) - continue; - - qp = new QuestProgression(q); - - if (g.size() >= job.getMaxDailyQuests()) - continue; - - g.put(qp.getQuest().getConfigName(), qp); - } - - if (type == null || type.name().equals(qp.getQuest().getAction().name())) - tmp.put(qp.getQuest().getConfigName(), qp); - } - - this.qProgression.put(job.getName(), g); - - if (g.size() < job.getMaxDailyQuests()) { - for (int i = g.size(); i < job.getMaxDailyQuests(); i++) { - Quest q = job.getNextQuest(getQuestNameList(job, type), this.getJobProgression(job).getLevel()); - - if (q == null) - continue; - QuestProgression qp = new QuestProgression(q); - g.put(qp.getQuest().getConfigName(), qp); - - if (type == null || type.name().equals(qp.getQuest().getAction().name())) - tmp.put(qp.getQuest().getConfigName(), qp); - } - } - - this.qProgression.put(job.getName(), g); - - List pr = new ArrayList<>(); - for (Entry one : tmp.entrySet()) { - pr.add(one.getValue()); - } - - return pr; - } - - public int getDoneQuests() { - return doneQuests; - } - - public void setDoneQuests(int doneQuests) { - this.doneQuests = doneQuests; - } - - public void addDoneQuest() { - this.doneQuests++; - } - - public int getFurnaceCount() { - return FurnaceBrewingHandling.getTotalFurnaces(this.getPlayerUUID()); - } - - public int getBrewingStandCount() { - return FurnaceBrewingHandling.getTotalBrewingStands(this.getPlayerUUID()); - } - - public int getMaxBrewingStandsAllowed() { - Double maxV = Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxbrewingstands"); - - if (maxV == null || maxV == 0) - maxV = (double) Jobs.getGCManager().getBrewingStandsMaxDefault(); - - int max = maxV.intValue(); - return max; - } - - public int getMaxFurnacesAllowed() { - Double maxV = Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxfurnaces"); - - if (maxV == null || maxV == 0) - maxV = (double) Jobs.getGCManager().getFurnacesMaxDefault(); - - int max = maxV.intValue(); - - return max; - } -} +/** + * Jobs Plugin for Bukkit + * Copyright (C) 2011 Zak Ford + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.gamingmesh.jobs.container; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; +import java.util.UUID; + +import com.gamingmesh.jobs.commands.list.info; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.dao.JobsDAO; +import com.gamingmesh.jobs.economy.PaymentData; +import com.gamingmesh.jobs.resources.jfep.Parser; +import com.gamingmesh.jobs.stuff.ChatColor; +import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling; +import com.gamingmesh.jobs.stuff.TimeManage; + +public class JobsPlayer { + // the player the object belongs to + private String userName; + // progression of the player in each job + public UUID playerUUID; + public ArrayList progression = new ArrayList<>(); + private ArchivedJobs archivedJobs = new ArchivedJobs(); + + private PaymentData paymentLimits = null; + + private HashMap> boostCounter = new HashMap<>(); + + // display honorific + private String honorific; + // player save status + private volatile boolean isSaved = true; + // player online status + private volatile boolean isOnline = false; + + private HashMap limits = new HashMap<>(); + + private int userid = -1; + + private List barMap = new ArrayList<>(); + private List updateBossBarFor = new ArrayList<>(); + // save lock +// public final Object saveLock = new Object(); + + // log + private HashMap logList = new HashMap<>(); + + private Long seen = System.currentTimeMillis(); + + private HashMap permissionsCache = null; + private Long lastPermissionUpdate = -1L; + + private HashMap> qProgression = new HashMap<>(); + private int doneQuests = 0; + + public JobsPlayer(String userName) { + this.userName = userName; + } + + public ArchivedJobs getArchivedJobs() { + return archivedJobs; + } + + public JobProgression getArchivedJobProgression(Job job) { + return archivedJobs.getArchivedJobProgression(job); + } + + public void setArchivedJobs(ArchivedJobs archivedJob) { + this.archivedJobs = archivedJob; + } + + public int getTotalLevels() { + int i = 0; + for (JobProgression job : progression) { + i += job.getLevel(); + } + return i; + } + + public void setPaymentLimit(PaymentData paymentLimits) { + this.paymentLimits = paymentLimits; + } + + public PaymentData getPaymentLimit() { + if (paymentLimits == null) { + paymentLimits = Jobs.getJobsDAO().getPlayersLimits(this); + } + if (paymentLimits == null) + paymentLimits = new PaymentData(); + return paymentLimits; + } + + public boolean isUnderLimit(CurrencyType type, Double amount) { + Player player = this.getPlayer(); + if (player == null) + return true; + if (amount == 0) + return true; + CurrencyLimit limit = Jobs.getGCManager().getLimit(type); + if (!limit.isEnabled()) + return true; + PaymentData data = getPaymentLimit(); + Integer value = this.limits.get(type); + if (data.IsReachedLimit(type, value == null ? 0 : value)) { + if (player.isOnline() && !data.isInformed() && !data.isReseted()) { + if(Jobs.getGCManager().useMaxPaymentCurve) { + player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.reached" + type.getName().toLowerCase() + "limit")); + player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.reached" + type.getName().toLowerCase() + "limit2")); + player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.reached" + type.getName().toLowerCase() + "limit3")); + }else { + player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.reached" + type.getName().toLowerCase() + "limit")); + player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.reached" + type.getName().toLowerCase() + "limit2")); + } + data.setInformed(); + + } + if (data.IsAnnounceTime(limit.getAnnouncementDelay()) && player.isOnline()) { + Jobs.getActionBar().send(player, Jobs.getLanguage().getMessage("command.limit.output." + type.getName().toLowerCase() + "time", "%time%", TimeManage.to24hourShort(data.GetLeftTime(type)))); + } + if (data.isReseted()) + data.setReseted(false); + return false; + } + data.AddAmount(type, amount); + return true; + } + public double percentOverLimit(CurrencyType type){ + Integer value = this.limits.get(type); + PaymentData data = getPaymentLimit(); + return data.percentOverLimit(type,value == null ? 0 : value); + } + + public void loadLogFromDao() { + Jobs.getJobsDAO().loadLog(this); + } + + public synchronized List getUpdateBossBarFor() { + return updateBossBarFor; + } + + public synchronized void clearUpdateBossBarFor() { + updateBossBarFor.clear(); + } + + public synchronized List getBossBarInfo() { + return barMap; + } + + public synchronized void hideBossBars() { + for (BossBarInfo one : this.barMap) { + one.getBar().setVisible(false); + } + } + + public HashMap getLog() { + return logList; + } + + public void setLog(HashMap logList) { + this.logList = logList; + } + + public void setUserId(int userid) { + this.userid = userid; + } + + public int getUserId() { + return userid; + } + + /** + * Get the player + * @return the player + */ + public Player getPlayer() { + if (this.playerUUID != null) { + return Bukkit.getPlayer(this.playerUUID); + } + return null; + } + + /** + * Get the Boost + * @return the Boost + */ + public double getBoost(String JobName, CurrencyType type) { + return getBoost(JobName, type, false); + } + + public double getBoost(String JobName, CurrencyType type, boolean force) { + double Boost = 0D; + if (!this.isOnline()) + return Boost; + if (type == null) + return Boost; + + long time = System.currentTimeMillis(); + + if (this.boostCounter.containsKey(JobName)) { + ArrayList counterList = boostCounter.get(JobName); + for (BoostCounter counter : counterList) { + if (counter.getType() != type) + continue; + if (force || time - counter.getTime() > 1000 * 60) { + Boost = getPlayerBoostNew(JobName, type); + counter.setBoost(Boost); + counter.setTime(time); + return Boost; + } + return counter.getBoost(); + } + Boost = getPlayerBoostNew(JobName, type); + counterList.add(new BoostCounter(type, Boost, time)); + return Boost; + } + + Boost = getPlayerBoostNew(JobName, type); + + ArrayList counterList = new ArrayList<>(); + counterList.add(new BoostCounter(type, Boost, time)); + + boostCounter.put(JobName, counterList); + return Boost; + } + + private Double getPlayerBoostNew(String JobName, CurrencyType type) { + Double Boost = null; + Double v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost." + JobName + "." + type.getName().toLowerCase(), true); + Boost = v1; + v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost." + JobName + ".all"); + if (Boost == null || v1 != null && v1 > Boost) + Boost = v1; + v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost.all.all"); + if (Boost == null || v1 != null && v1 > Boost) + Boost = v1; + v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost.all." + type.getName().toLowerCase()); + if (Boost == null || v1 != null && v1 > Boost) + Boost = v1; + return Boost == null ? 0D : Boost; + } + + // New method is in use +// private Double getPlayerBoost(String JobName, CurrencyType type) { +// double Boost = 0D; +// if (Perm.hasPermission(player, "jobs.boost." + JobName + "." + type.getName().toLowerCase()) || +// Perm.hasPermission(player, "jobs.boost." + JobName + ".all") || +// Perm.hasPermission(player, "jobs.boost.all.all") || +// Perm.hasPermission(player, "jobs.boost.all." + type.getName().toLowerCase())) { +// Boost = Jobs.getGCManager().Boost.get(type); +// } +// return Boost; +// } + + /** + * Reloads max experience for this job. + */ + public void reloadMaxExperience() { + for (JobProgression prog : progression) { + prog.reloadMaxExperience(); + } + } + + /** + * Reloads limit for this player. + */ + public void reload(CurrencyType type) { + int TotalLevel = 0; + for (JobProgression prog : progression) { + TotalLevel += prog.getLevel(); + } + Parser eq = Jobs.getGCManager().currencyLimitUse.get(type).getMaxEquation(); + eq.setVariable("totallevel", TotalLevel); + limits.put(type, (int) eq.getValue()); + setSaved(false); + } + + public void reloadLimits() { + for (CurrencyType type : CurrencyType.values()) { + reload(type); + } + } + + public int getLimit(CurrencyType type) { + if (type == null) + return 0; + Integer value = this.limits.get(type); + return value == null ? 0 : value; + } + + public void resetPaymentLimit() { + if (paymentLimits == null) + getPaymentLimit(); + if (paymentLimits != null) + paymentLimits.resetLimits(); + setSaved(false); + } + + /** + * Get the list of job progressions + * @return the list of job progressions + */ + public List getJobProgression() { + return Collections.unmodifiableList(progression); + } + + /** + * Check if have permission + * @return true if have + */ + public boolean havePermission(String perm) { + Player player = Bukkit.getPlayer(this.getPlayerUUID()); + if (player != null) + return player.hasPermission(perm); + return false; + } + + /** + * Get the job progression with the certain job + * @return the job progression + */ + public JobProgression getJobProgression(Job job) { + for (JobProgression prog : progression) { + if (prog.getJob().isSame(job)) + return prog; + } + return null; + } + + /** + * get the userName + * @return the userName + */ + public String getUserName() { + Player player = Bukkit.getPlayer(this.getPlayerUUID()); + if (player != null) + userName = player.getName(); + return userName; + } + + /** + * get the playerUUID + * @return the playerUUID + */ + public UUID getPlayerUUID() { + return this.playerUUID; + } + + public void setPlayerUUID(UUID playerUUID) { + this.playerUUID = playerUUID; + } + + public String getDisplayHonorific() { + if (honorific == null) + reloadHonorific(); + return honorific; + } + + /** + * Player joins a job + * @param job - the job joined + */ + public boolean joinJob(Job job) { +// synchronized (saveLock) { + if (!isInJob(job)) { + int level = 1; + int exp = 0; + + JobProgression archived = this.getArchivedJobProgression(job); + if (archived != null) { + level = getLevelAfterRejoin(archived); + exp = getExpAfterRejoin(archived, level); + Jobs.getJobsDAO().deleteArchive(this, job); + } + + progression.add(new JobProgression(job, this, level, exp)); + reloadMaxExperience(); + reloadLimits(); + reloadHonorific(); + Jobs.getPermissionHandler().recalculatePermissions(this); + return true; + } + return false; +// } + } + + public int getLevelAfterRejoin(JobProgression jp) { + if (jp == null) + return 1; + + int level = jp.getLevel(); + + level = (int) ((level - (level * (Jobs.getGCManager().levelLossPercentage / 100.0)))); + if (level < 1) + level = 1; + + Job job = jp.getJob(); + int maxLevel = this.getMaxJobLevelAllowed(job); + if (jp.getLevel() == maxLevel) { + if (Jobs.getGCManager().fixAtMaxLevel) { + level = jp.getLevel(); + } else { + level = jp.getLevel(); + level = (int) ((level - (level * (Jobs.getGCManager().levelLossPercentageFromMax / 100.0)))); + if (level < 1) + level = 1; + } + } + + return level; + } + + public int getExpAfterRejoin(JobProgression jp, int level) { + if (jp == null) + return 1; + Integer max = jp.getMaxExperience(level); + Double exp = jp.getExperience(); + if (exp > max) + exp = max.doubleValue(); + + if (exp > 0) { + Job job = jp.getJob(); + int maxLevel = this.getMaxJobLevelAllowed(job); + if (jp.getLevel() == maxLevel) { + if (!Jobs.getGCManager().fixAtMaxLevel) + exp = (exp - (exp * (Jobs.getGCManager().levelLossPercentageFromMax / 100.0))); + } else { + exp = (exp - (exp * (Jobs.getGCManager().levelLossPercentage / 100.0))); + } + } + return exp.intValue(); + } + + /** + * Player leaves a job + * @param job - the job left + */ + public boolean leaveJob(Job job) { +// synchronized (saveLock) { + JobProgression prog = getJobProgression(job); + if (prog != null) { + progression.remove(prog); + reloadMaxExperience(); + reloadLimits(); + reloadHonorific(); + Jobs.getPermissionHandler().recalculatePermissions(this); + return true; + } + return false; +// } + } + + /** + * Leave all jobs + * @return on success + */ + public boolean leaveAllJobs() { +// synchronized (saveLock) { + progression.clear(); + reloadHonorific(); + Jobs.getPermissionHandler().recalculatePermissions(this); + return true; +// } + } + + /** + * Promotes player in job + * @param job - the job being promoted + * @param levels - number of levels to promote + */ + public void promoteJob(Job job, int levels) { +// synchronized (saveLock) { + JobProgression prog = getJobProgression(job); + if (prog == null) + return; + if (levels <= 0) + return; + int oldLevel = prog.getLevel(); + int newLevel = oldLevel + levels; + + int maxLevel = job.getMaxLevel(this); + + if (maxLevel > 0 && newLevel > maxLevel) { + newLevel = maxLevel; + } + setLevel(job, newLevel); + Jobs.getPlayerManager().performCommandOnLevelUp(this, job, newLevel - 1); +// } + } + + /** + * Demotes player in job + * @param job - the job being deomoted + * @param levels - number of levels to demote + */ + public void demoteJob(Job job, int levels) { +// synchronized (saveLock) { + JobProgression prog = getJobProgression(job); + if (prog == null) + return; + if (levels <= 0) + return; + int newLevel = prog.getLevel() - levels; + if (newLevel < 1) { + newLevel = 1; + } + setLevel(job, newLevel); +// } + } + + /** + * Sets player to a specific level + * @param job - the job + * @param level - the level + */ + private void setLevel(Job job, int level) { +// synchronized (saveLock) { + JobProgression prog = getJobProgression(job); + if (prog == null) + return; + + if (level != prog.getLevel()) { + prog.setLevel(level); + reloadHonorific(); + Jobs.getPermissionHandler().recalculatePermissions(this); + } +// } + } + + /** + * Player leaves a job + * @param oldjob - the old job + * @param newjob - the new job + */ + public boolean transferJob(Job oldjob, Job newjob) { +// synchronized (saveLock) { + if (!isInJob(newjob)) { + for (JobProgression prog : progression) { + if (!prog.getJob().isSame(oldjob)) + continue; + + prog.setJob(newjob); + + int maxLevel = getMaxJobLevelAllowed(newjob); + + if (newjob.getMaxLevel() > 0 && prog.getLevel() > maxLevel) { + prog.setLevel(maxLevel); + } + reloadMaxExperience(); + reloadLimits(); + reloadHonorific(); + Jobs.getPermissionHandler().recalculatePermissions(this); + + return true; + } + } + return false; +// } + } + + public int getMaxJobLevelAllowed(Job job) { + int maxLevel = 0; + if (this.havePermission("jobs." + job.getName() + ".vipmaxlevel")) + maxLevel = job.getVipMaxLevel() > job.getMaxLevel() ? job.getVipMaxLevel() : job.getMaxLevel(); + else + maxLevel = job.getMaxLevel(); + int tMax = Jobs.getPermissionManager().getMaxPermission(this, "jobs." + job.getName() + ".vipmaxlevel").intValue(); + if (tMax > maxLevel) + maxLevel = tMax; + return maxLevel; + } + + /** + * Checks if the player is in this job. + * @param job - the job + * @return true - they are in the job + * @return false - they are not in the job + */ + public boolean isInJob(Job job) { + if (job == null) + return false; + for (JobProgression prog : progression) { + if (prog.getJob().isSame(job)) + return true; + } + return false; + } + + /** + * Function that reloads your honorific + */ + public void reloadHonorific() { + StringBuilder builder = new StringBuilder(); + int numJobs = progression.size(); + boolean gotTitle = false; + + if (numJobs > 0) { + for (JobProgression prog : progression) { + DisplayMethod method = prog.getJob().getDisplayMethod(); + if (method.equals(DisplayMethod.NONE)) + continue; + if (gotTitle) { + builder.append(Jobs.getGCManager().getModifyChatSeparator()); + gotTitle = false; + } + Title title = Jobs.gettitleManager().getTitle(prog.getLevel(), prog.getJob().getName()); + + if (numJobs == 1) { + if (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.TITLE)) { + if (title != null) { + String honorificpart = title.getChatColor() + title.getName() + ChatColor.WHITE; + if (honorificpart.contains("{level}")) + honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel())); + builder.append(honorificpart); + gotTitle = true; + } + } + if (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.JOB)) { + if (gotTitle) { + builder.append(" "); + } + String honorificpart = prog.getJob().getChatColor() + prog.getJob().getName() + ChatColor.WHITE; + if (honorificpart.contains("{level}")) + honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel())); + builder.append(honorificpart); + gotTitle = true; + } + } + + if (numJobs > 1 && (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.TITLE)) || method.equals(DisplayMethod.SHORT_FULL) || method.equals(DisplayMethod.SHORT_TITLE)) { + // add title to honorific + if (title != null) { + String honorificpart = title.getChatColor() + title.getShortName() + ChatColor.WHITE; + if (honorificpart.contains("{level}")) + honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel())); + builder.append(honorificpart); + gotTitle = true; + } + } + + if (numJobs > 1 && (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.JOB)) || method.equals(DisplayMethod.SHORT_FULL) || method.equals( + DisplayMethod.SHORT_JOB)) { + String honorificpart = prog.getJob().getChatColor() + prog.getJob().getShortName() + ChatColor.WHITE; + if (honorificpart.contains("{level}")) + honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel())); + builder.append(honorificpart); + gotTitle = true; + } + } + } else { + Job nonejob = Jobs.getNoneJob(); + if (nonejob != null) { + DisplayMethod metod = nonejob.getDisplayMethod(); + if (metod.equals(DisplayMethod.FULL) || metod.equals(DisplayMethod.TITLE)) { + String honorificpart = Jobs.getNoneJob().getChatColor() + Jobs.getNoneJob().getName() + ChatColor.WHITE; + if (honorificpart.contains("{level}")) + honorificpart = honorificpart.replace("{level}", ""); + builder.append(honorificpart); + } + + if (metod.equals(DisplayMethod.SHORT_FULL) || metod.equals(DisplayMethod.SHORT_TITLE) || metod.equals(DisplayMethod.SHORT_JOB)) { + String honorificpart = Jobs.getNoneJob().getChatColor() + Jobs.getNoneJob().getShortName() + ChatColor.WHITE; + if (honorificpart.contains("{level}")) + honorificpart = honorificpart.replace("{level}", ""); + builder.append(honorificpart); + } + } + } + + honorific = builder.toString().trim(); + if (honorific.length() > 0) + honorific = Jobs.getGCManager().getModifyChatPrefix() + honorific + Jobs.getGCManager().getModifyChatSuffix(); + + } + + /** + * Performs player save + */ + public void save() { +// synchronized (saveLock) { + if (!isSaved()) { + JobsDAO dao = Jobs.getJobsDAO(); + dao.save(this); + dao.saveLog(this); + dao.savePoints(this); + dao.recordPlayersLimits(this); + dao.updateSeen(this); + setSaved(true); + + if (this.getPlayer() == null || !this.getPlayer().isOnline()) { + Jobs.getPlayerManager().addPlayerToCache(this); + Jobs.getPlayerManager().removePlayer(this.getPlayer()); + } + } +// } + } + + /** + * Perform connect + */ + public void onConnect() { + isOnline = true; + } + + /** + * Perform disconnect + * + */ + public void onDisconnect() { +// Jobs.getJobsDAO().savePoints(this); + clearBossMaps(); + isOnline = false; + Jobs.getPlayerManager().addPlayerToCache(this); + } + + public void clearBossMaps() { + for (BossBarInfo one : barMap) { + one.cancel(); + } + barMap.clear(); + } + + /** + * Whether or not player is online + * @return true if online, otherwise false + */ + public boolean isOnline() { + if (this.getPlayer() != null) + return this.getPlayer().isOnline(); + return isOnline; + } + + public boolean isSaved() { + return isSaved; + } + + public void setSaved(boolean isSaved) { + this.isSaved = isSaved; + } + + public Long getSeen() { + return seen; + } + + public void setSeen(Long seen) { + this.seen = seen; + } + + public HashMap getPermissionsCache() { + return permissionsCache; + } + + public void setPermissionsCache(HashMap permissionsCache) { + this.permissionsCache = permissionsCache; + } + + public void setPermissionsCache(String permission, Boolean state) { + this.permissionsCache.put(permission, state); + } + + public Long getLastPermissionUpdate() { + return lastPermissionUpdate; + } + + public void setLastPermissionUpdate(Long lastPermissionUpdate) { + this.lastPermissionUpdate = lastPermissionUpdate; + } + + public boolean canGetPaid(ActionInfo info) { + + List progression = getJobProgression(); + int numjobs = progression.size(); + + if (numjobs == 0) { + if (Jobs.getNoneJob() == null) + return false; + JobInfo jobinfo = Jobs.getNoneJob().getJobInfo(info, 1); + if (jobinfo == null) + return false; + Double income = jobinfo.getIncome(1, numjobs); + Double points = jobinfo.getPoints(1, numjobs); + if (income == 0D && points == 0D) + return false; + } + + for (JobProgression prog : progression) { + int level = prog.getLevel(); + JobInfo jobinfo = prog.getJob().getJobInfo(info, level); + if (jobinfo == null) + continue; + Double income = jobinfo.getIncome(level, numjobs); + Double pointAmount = jobinfo.getPoints(level, numjobs); + Double expAmount = jobinfo.getExperience(level, numjobs); + if (income != 0D || pointAmount != 0D || expAmount != 0D) + return true; + } + + return false; + } + + public boolean inDailyQuest(Job job, String questName) { + + HashMap qpl = this.qProgression.get(job.getName()); + if (qpl == null) + return false; + + for (Entry one : qpl.entrySet()) { + if (one.getValue().getQuest().getConfigName().equalsIgnoreCase(questName)) + return true; + } + + return false; + } + + private List getQuestNameList(Job job, ActionType type) { + List ls = new ArrayList<>(); + if (!this.isInJob(job)) + return ls; + + HashMap qpl = this.qProgression.get(job.getName()); + + if (qpl == null) + return ls; + + for (Entry one : qpl.entrySet()) { + QuestProgression prog = one.getValue(); + if (!prog.isEnded() && (type == null || type.name().equals(prog.getQuest().getAction().name()))) + ls.add(prog.getQuest().getConfigName().toLowerCase()); + } + + return ls; + } + + public void resetQuests() { + for (JobProgression one : this.getJobProgression()) { + for (QuestProgression oneQ : this.getQuestProgressions(one.getJob())) { + oneQ.setValidUntil(0L); + } + } + getQuestProgressions(); + } + + public List getQuestProgressions() { + List g = new ArrayList<>(); + for (JobProgression one : this.getJobProgression()) { + g.addAll(this.getQuestProgressions(one.getJob())); + } + return g; + } + + public List getQuestProgressions(Job job) { + return getQuestProgressions(job, null); + } + + public List getQuestProgressions(Job job, ActionType type) { + if (!this.isInJob(job)) + return new ArrayList<>(); + HashMap g = new HashMap<>(); + + if (this.qProgression.get(job.getName()) != null) + g = new HashMap<>(this.qProgression.get(job.getName())); + + HashMap tmp = new HashMap<>(); + + for (Entry one : (new HashMap(g)).entrySet()) { + QuestProgression qp = one.getValue(); + if (qp == null || !qp.isValid()) { + Quest q = job.getNextQuest(getQuestNameList(job, type), this.getJobProgression(job).getLevel()); + + if (q == null) + continue; + + qp = new QuestProgression(q); + + if (g.size() >= job.getMaxDailyQuests()) + continue; + + g.put(qp.getQuest().getConfigName(), qp); + } + + if (type == null || type.name().equals(qp.getQuest().getAction().name())) + tmp.put(qp.getQuest().getConfigName(), qp); + } + + this.qProgression.put(job.getName(), g); + + if (g.size() < job.getMaxDailyQuests()) { + for (int i = g.size(); i < job.getMaxDailyQuests(); i++) { + Quest q = job.getNextQuest(getQuestNameList(job, type), this.getJobProgression(job).getLevel()); + + if (q == null) + continue; + QuestProgression qp = new QuestProgression(q); + g.put(qp.getQuest().getConfigName(), qp); + + if (type == null || type.name().equals(qp.getQuest().getAction().name())) + tmp.put(qp.getQuest().getConfigName(), qp); + } + } + + this.qProgression.put(job.getName(), g); + + List pr = new ArrayList<>(); + for (Entry one : tmp.entrySet()) { + pr.add(one.getValue()); + } + + return pr; + } + + public int getDoneQuests() { + return doneQuests; + } + + public void setDoneQuests(int doneQuests) { + this.doneQuests = doneQuests; + } + + public void addDoneQuest() { + this.doneQuests++; + } + + public int getFurnaceCount() { + return FurnaceBrewingHandling.getTotalFurnaces(this.getPlayerUUID()); + } + + public int getBrewingStandCount() { + return FurnaceBrewingHandling.getTotalBrewingStands(this.getPlayerUUID()); + } + + public int getMaxBrewingStandsAllowed() { + Double maxV = Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxbrewingstands"); + + if (maxV == null || maxV == 0) + maxV = (double) Jobs.getGCManager().getBrewingStandsMaxDefault(); + + int max = maxV.intValue(); + return max; + } + + public int getMaxFurnacesAllowed() { + Double maxV = Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxfurnaces"); + + if (maxV == null || maxV == 0) + maxV = (double) Jobs.getGCManager().getFurnacesMaxDefault(); + + int max = maxV.intValue(); + + return max; + } +} diff --git a/src/main/java/com/gamingmesh/jobs/economy/PaymentData.java b/src/main/java/com/gamingmesh/jobs/economy/PaymentData.java index a7cc49be..f5783437 100644 --- a/src/main/java/com/gamingmesh/jobs/economy/PaymentData.java +++ b/src/main/java/com/gamingmesh/jobs/economy/PaymentData.java @@ -1,142 +1,145 @@ -package com.gamingmesh.jobs.economy; - -import java.util.HashMap; - -import com.gamingmesh.jobs.Jobs; -import com.gamingmesh.jobs.container.CurrencyType; - -public class PaymentData { - - private Long lastAnnouced = 0L; - private HashMap payments = new HashMap<>(); - private HashMap paymentsTimes = new HashMap<>(); - private boolean Informed = false; - private boolean Reseted = false; - - public PaymentData(Long time, Double Payment, Double Points, Double Exp, Long lastAnnouced, boolean Informed) { - paymentsTimes.put(CurrencyType.EXP, time); - paymentsTimes.put(CurrencyType.MONEY, time); - paymentsTimes.put(CurrencyType.POINTS, time); - payments.put(CurrencyType.EXP, Exp); - payments.put(CurrencyType.MONEY, Payment); - payments.put(CurrencyType.POINTS, Points); - this.lastAnnouced = lastAnnouced; - this.Informed = Informed; - } - - public PaymentData(CurrencyType type, Double amount) { - paymentsTimes.put(type, System.currentTimeMillis()); - payments.put(type, amount); - this.lastAnnouced = 0L; - this.Informed = false; - } - - public PaymentData() { - resetLimits(); - } - - public Long GetTime(CurrencyType type) { - return paymentsTimes.get(type); - } - - public void setReseted(boolean Reseted) { - this.Reseted = Reseted; - } - - public boolean isReseted() { - return Reseted; - } - - public Double GetAmount(CurrencyType type) { - if (!payments.containsKey(type)) - return 0D; - return payments.get(type); - } - - public Double GetAmountBylimit(CurrencyType type, int limit) { - if (GetAmount(type) > limit) - return (double) limit; - return (int) (GetAmount(type) * 100) / 100.0; - } - - public Long GetLastAnnounced() { - return lastAnnouced; - } - - public boolean IsAnnounceTime(int t) { - if (this.lastAnnouced + (t * 1000) > System.currentTimeMillis()) - return false; - SetAnnouncmentTime(); - return true; - } - - public void SetAnnouncmentTime() { - this.lastAnnouced = System.currentTimeMillis(); - } - - public void AddNewAmount(CurrencyType type, Double Payment) { - AddNewAmount( type, Payment, null); - } - - public void AddNewAmount(CurrencyType type, Double Payment, Long time) { - paymentsTimes.put(type, time == null ? System.currentTimeMillis() : time); - payments.put(type, Payment); - } - - public void setInformed() { - this.Informed = true; - } - - public void setNotInformed() { - this.Informed = false; - } - - public void AddAmount(CurrencyType type, Double Payment) { - payments.put(type, payments.get(type) + Payment); - } - - public long GetLeftTime(CurrencyType type) { - long left = 0; - if (this.GetTime(type) + (Jobs.getGCManager().getLimit(type).getTimeLimit() * 1000) > System.currentTimeMillis()) - left = (this.GetTime(type) + (Jobs.getGCManager().getLimit(type).getTimeLimit() * 1000) - System.currentTimeMillis()); - return left; - } - - public boolean IsOverLimit(CurrencyType type, int limit) { - if (this.payments.get(type) < limit) - return false; - return true; - } - - public boolean IsOverTimeLimit(CurrencyType type) { - if (this.GetTime(type) + (Jobs.getGCManager().getLimit(type).getTimeLimit() * 1000) > System.currentTimeMillis()) - return false; - if (this.Informed) - this.Informed = false; - resetLimits(); - return true; - } - - public void resetLimits() { - for (CurrencyType type : CurrencyType.values()) { - AddNewAmount(type, 0D); - } - this.Reseted = true; - } - - public boolean IsReachedLimit(CurrencyType type, int money) { - if (IsOverTimeLimit(type)) - return true; - if (IsOverLimit(type, money)) - return true; - return false; - } - - public boolean isInformed() { - return Informed; - } - - public void setInformed(boolean Informed) { - this.Informed = Informed; - } -} +package com.gamingmesh.jobs.economy; + +import java.util.HashMap; + +import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.container.CurrencyType; + +public class PaymentData { + + private Long lastAnnouced = 0L; + private HashMap payments = new HashMap<>(); + private HashMap paymentsTimes = new HashMap<>(); + private boolean Informed = false; + private boolean Reseted = false; + + public PaymentData(Long time, Double Payment, Double Points, Double Exp, Long lastAnnouced, boolean Informed) { + paymentsTimes.put(CurrencyType.EXP, time); + paymentsTimes.put(CurrencyType.MONEY, time); + paymentsTimes.put(CurrencyType.POINTS, time); + payments.put(CurrencyType.EXP, Exp); + payments.put(CurrencyType.MONEY, Payment); + payments.put(CurrencyType.POINTS, Points); + this.lastAnnouced = lastAnnouced; + this.Informed = Informed; + } + + public PaymentData(CurrencyType type, Double amount) { + paymentsTimes.put(type, System.currentTimeMillis()); + payments.put(type, amount); + this.lastAnnouced = 0L; + this.Informed = false; + } + + public PaymentData() { + resetLimits(); + } + + public Long GetTime(CurrencyType type) { + return paymentsTimes.get(type); + } + + public void setReseted(boolean Reseted) { + this.Reseted = Reseted; + } + + public boolean isReseted() { + return Reseted; + } + + public Double GetAmount(CurrencyType type) { + if (!payments.containsKey(type)) + return 0D; + return payments.get(type); + } + + public Double GetAmountBylimit(CurrencyType type, int limit) { + if (GetAmount(type) > limit) + return (double) limit; + return (int) (GetAmount(type) * 100) / 100.0; + } + + public Long GetLastAnnounced() { + return lastAnnouced; + } + + public boolean IsAnnounceTime(int t) { + if (this.lastAnnouced + (t * 1000) > System.currentTimeMillis()) + return false; + SetAnnouncmentTime(); + return true; + } + + public void SetAnnouncmentTime() { + this.lastAnnouced = System.currentTimeMillis(); + } + + public void AddNewAmount(CurrencyType type, Double Payment) { + AddNewAmount( type, Payment, null); + } + + public void AddNewAmount(CurrencyType type, Double Payment, Long time) { + paymentsTimes.put(type, time == null ? System.currentTimeMillis() : time); + payments.put(type, Payment); + } + + public void setInformed() { + this.Informed = true; + } + + public void setNotInformed() { + this.Informed = false; + } + + public void AddAmount(CurrencyType type, Double Payment) { + payments.put(type, payments.get(type) + Payment); + } + + public long GetLeftTime(CurrencyType type) { + long left = 0; + if (this.GetTime(type) + (Jobs.getGCManager().getLimit(type).getTimeLimit() * 1000) > System.currentTimeMillis()) + left = (this.GetTime(type) + (Jobs.getGCManager().getLimit(type).getTimeLimit() * 1000) - System.currentTimeMillis()); + return left; + } + + public boolean IsOverLimit(CurrencyType type, int limit) { + if (this.payments.get(type) < limit) + return false; + return true; + } + public double percentOverLimit(CurrencyType type,int limit){ + return ((this.payments.get(type) / limit)-1)*100; + } + + public boolean IsOverTimeLimit(CurrencyType type) { + if (this.GetTime(type) + (Jobs.getGCManager().getLimit(type).getTimeLimit() * 1000) > System.currentTimeMillis()) + return false; + if (this.Informed) + this.Informed = false; + resetLimits(); + return true; + } + + public void resetLimits() { + for (CurrencyType type : CurrencyType.values()) { + AddNewAmount(type, 0D); + } + this.Reseted = true; + } + + public boolean IsReachedLimit(CurrencyType type, int money) { + if (IsOverTimeLimit(type)) + return true; + if (IsOverLimit(type, money)) + return true; + return false; + } + + public boolean isInformed() { + return Informed; + } + + public void setInformed(boolean Informed) { + this.Informed = Informed; + } +}