1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-26 04:25:15 +01:00
Jobs/com/gamingmesh/jobs/Jobs.java

952 lines
28 KiB
Java
Raw Normal View History

2015-08-21 15:10:08 +02:00
/**
* Jobs Plugin for Bukkit
* Copyright (C) 2011 Zak Ford <zak.j.ford@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.gamingmesh.jobs;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.WeakHashMap;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
2016-03-30 15:42:36 +02:00
import com.gamingmesh.jobs.Gui.GuiManager;
import com.gamingmesh.jobs.Signs.SignUtil;
2016-04-03 16:22:44 +02:00
import com.gamingmesh.jobs.api.JobsExpGainEvent;
2016-03-30 15:42:36 +02:00
import com.gamingmesh.jobs.commands.JobsCommands;
import com.gamingmesh.jobs.config.BossBarManager;
2015-08-21 15:10:08 +02:00
import com.gamingmesh.jobs.config.ConfigManager;
2016-03-30 15:42:36 +02:00
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.ScboardManager;
import com.gamingmesh.jobs.config.ScheduleManager;
import com.gamingmesh.jobs.config.ShopManager;
import com.gamingmesh.jobs.config.TitleManager;
2015-08-21 15:10:08 +02:00
import com.gamingmesh.jobs.container.ActionInfo;
2016-03-30 15:42:36 +02:00
import com.gamingmesh.jobs.container.BoostMultiplier;
2015-08-21 15:10:08 +02:00
import com.gamingmesh.jobs.container.Job;
2016-03-30 15:42:36 +02:00
import com.gamingmesh.jobs.container.JobInfo;
2015-08-21 15:10:08 +02:00
import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.dao.JobsDAO;
import com.gamingmesh.jobs.economy.BufferedEconomy;
import com.gamingmesh.jobs.economy.Economy;
import com.gamingmesh.jobs.economy.PaymentData;
import com.gamingmesh.jobs.i18n.Language;
2016-06-25 14:51:21 +02:00
import com.gamingmesh.jobs.listeners.McMMOlistener;
2016-03-30 15:42:36 +02:00
import com.gamingmesh.jobs.listeners.MythicMobsListener;
2016-06-25 14:51:21 +02:00
import com.gamingmesh.jobs.listeners.PistonProtectionListener;
2015-08-21 15:10:08 +02:00
import com.gamingmesh.jobs.stuff.ActionBar;
import com.gamingmesh.jobs.stuff.JobsClassLoader;
import com.gamingmesh.jobs.stuff.Loging;
2015-08-21 15:10:08 +02:00
import com.gamingmesh.jobs.tasks.BufferedPaymentThread;
import com.gamingmesh.jobs.tasks.DatabaseSaveThread;
public class Jobs {
2015-09-10 12:41:19 +02:00
public static Jobs instance = new Jobs();
// public static JobsPlugin plugin = new JobsPlugin();
2016-04-05 16:43:55 +02:00
private static PlayerManager pManager = null;
2016-03-30 15:42:36 +02:00
private static JobsCommands cManager = null;
private static Language lManager = null;
private static LanguageManager lmManager = null;
private static SignUtil signManager = null;
private static ScboardManager scboardManager = 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;
private static ShopManager shopManager;
2016-06-25 17:56:59 +02:00
private static Loging loging;
2016-03-30 15:42:36 +02:00
2016-06-25 14:51:21 +02:00
private static PistonProtectionListener PistonProtectionListener = null;
private static McMMOlistener McMMOlistener = null;
2016-03-30 15:42:36 +02:00
private static MythicMobsListener MythicManager;
private static ConfigManager configManager;
private static GeneralConfigManager GconfigManager;
2015-09-10 12:41:19 +02:00
private static Logger pLogger;
private static File dataFolder;
private static JobsClassLoader classLoader = new JobsClassLoader(instance);
private static JobsDAO dao = null;
private static List<Job> jobs = null;
private static Job noneJob = null;
private static WeakHashMap<Job, Integer> usedSlots = new WeakHashMap<Job, Integer>();
public static WeakHashMap<String, Boolean> actionbartoggle = new WeakHashMap<String, Boolean>();
2016-03-30 15:42:36 +02:00
public static WeakHashMap<String, Boolean> BossBartoggle = new WeakHashMap<String, Boolean>();
2015-08-21 15:10:08 +02:00
// public static WeakHashMap<String, Double> GlobalBoost = new WeakHashMap<String, Double>();
2015-09-10 12:41:19 +02:00
private static BufferedEconomy economy;
private static PermissionHandler permissionHandler;
public static BufferedPaymentThread paymentThread = null;
private static DatabaseSaveThread saveTask = null;
public final static HashMap<String, PaymentData> paymentLimit = new HashMap<String, PaymentData>();
public final static HashMap<String, PaymentData> ExpLimit = new HashMap<String, PaymentData>();
2016-03-30 15:42:36 +02:00
public final static HashMap<String, PaymentData> PointLimit = new HashMap<String, PaymentData>();
private static NMS nms;
private static ActionBar actionbar;
2016-06-25 14:51:21 +02:00
public static void setMcMMOlistener(JobsPlugin plugin) {
McMMOlistener = new McMMOlistener(plugin);
}
public static McMMOlistener getMcMMOlistener() {
return McMMOlistener;
}
2016-03-30 15:42:36 +02:00
2016-06-25 14:51:21 +02:00
public static void setPistonProtectionListener(JobsPlugin plugin) {
PistonProtectionListener = new PistonProtectionListener(plugin);
2016-03-30 15:42:36 +02:00
}
2016-06-25 14:51:21 +02:00
public static PistonProtectionListener getPistonProtectionListener() {
return PistonProtectionListener;
2016-03-30 15:42:36 +02:00
}
public static void setMythicManager(JobsPlugin plugin) {
MythicManager = new MythicMobsListener(plugin);
}
public static MythicMobsListener getMythicManager() {
return MythicManager;
}
2016-06-25 17:56:59 +02:00
public static void setLoging() {
loging = new Loging();
}
public static Loging getLoging() {
return loging;
}
2016-03-30 15:42:36 +02:00
public static void setShopManager(JobsPlugin plugin) {
shopManager = new ShopManager(plugin);
}
public static ShopManager getShopManager() {
return shopManager;
}
2015-09-10 12:41:19 +02:00
2016-03-30 15:42:36 +02:00
public static void setConfigManager(JobsPlugin plugin) {
configManager = new ConfigManager(plugin);
}
public static ConfigManager getConfigManager() {
return configManager;
}
public static void setGCManager(JobsPlugin plugin) {
GconfigManager = new GeneralConfigManager(plugin);
}
public static GeneralConfigManager getGCManager() {
return GconfigManager;
}
public static void setActionBar(ActionBar bar) {
actionbar = bar;
}
public static ActionBar getActionBar() {
return actionbar;
}
public static void setNms(NMS newNms) {
nms = newNms;
}
public static NMS getNms() {
return nms;
2015-09-10 12:41:19 +02:00
}
/**
* Returns player manager
* @return the player manager
*/
public static PlayerManager getPlayerManager() {
return pManager;
}
2016-04-05 16:43:55 +02:00
public static void setPlayerManager(JobsPlugin jobsPlugin) {
pManager = new PlayerManager(jobsPlugin);
2016-04-05 16:43:55 +02:00
}
2016-03-30 15:42:36 +02:00
public static void setRestrictedBlockManager(JobsPlugin plugin) {
RBManager = new RestrictedBlockManager(plugin);
}
public static RestrictedBlockManager getRestrictedBlockManager() {
return RBManager;
}
public static void setRestrictedAreaManager(JobsPlugin plugin) {
RAManager = new RestrictedAreaManager(plugin);
}
public static RestrictedAreaManager getRestrictedAreaManager() {
return RAManager;
}
public static void setTitleManager(JobsPlugin plugin) {
titleManager = new TitleManager(plugin);
}
public static TitleManager gettitleManager() {
return titleManager;
}
public static void setBBManager(JobsPlugin plugin) {
BBManager = new BossBarManager(plugin);
}
public static BossBarManager getBBManager() {
return BBManager;
}
public static WeakHashMap<String, Boolean> getActionbarToggleList() {
return actionbartoggle;
}
public static WeakHashMap<String, Boolean> getBossBarToggleList() {
return BossBartoggle;
}
/**
* Returns schedule manager
* @return the schedule manager
*/
2016-03-30 15:42:36 +02:00
public static ScheduleManager getScheduleManager() {
return scheduleManager;
}
2016-03-30 15:42:36 +02:00
public static void setScheduleManager(JobsPlugin plugin) {
scheduleManager = new ScheduleManager(plugin);
}
2016-03-30 15:42:36 +02:00
public static NameTranslatorManager getNameTranslatorManager() {
return NameTranslatorManager;
}
public static void setNameTranslatorManager(JobsPlugin plugin) {
NameTranslatorManager = new NameTranslatorManager(plugin);
}
public static GuiManager getGUIManager() {
return GUIManager;
}
2016-06-25 15:27:01 +02:00
public static void setGUIManager() {
2016-03-30 15:42:36 +02:00
GUIManager = new GuiManager();
}
public static JobsCommands getCommandManager() {
return cManager;
}
public static void setCommandManager(JobsPlugin plugin) {
cManager = new JobsCommands(plugin);
}
public static ExploreManager getExplore() {
2016-01-09 13:58:33 +01:00
return exploreManager;
}
public static void setExplore() {
2016-03-30 15:42:36 +02:00
exploreManager = new ExploreManager();
2016-01-09 13:58:33 +01:00
}
/**
* Returns scoreboard manager
* @return the scoreboard manager
*/
2016-03-30 15:42:36 +02:00
public static ScboardManager getScboard() {
return scboardManager;
}
public static void setScboard(JobsPlugin plugin) {
2016-03-30 15:42:36 +02:00
scboardManager = new ScboardManager(plugin);
}
/**
* Returns sign manager
* @return the sign manager
*/
public static SignUtil getSignUtil() {
return signManager;
}
public static void setSignUtil(JobsPlugin plugin) {
signManager = new SignUtil(plugin);
}
/**
* Returns language manager
* @return the language manager
*/
public static Language getLanguage() {
return lManager;
}
public static void setLanguage(JobsPlugin plugin) {
lManager = new Language(plugin);
}
2016-03-30 15:42:36 +02:00
public static LanguageManager getLanguageManager() {
return lmManager;
}
public static void setLanguageManager(JobsPlugin plugin) {
lmManager = new LanguageManager(plugin);
}
2015-09-10 12:41:19 +02:00
/**
* Sets the plugin logger
*/
public static void setPluginLogger(Logger logger) {
pLogger = logger;
}
/**
* Retrieves the plugin logger
* @return the plugin logger
*/
public static Logger getPluginLogger() {
return pLogger;
}
/**
* Sets the data folder
* @param dir - the data folder
*/
public static void setDataFolder(File dir) {
dataFolder = dir;
}
/**
* Retrieves the data folder
* @return data folder
*/
public static File getDataFolder() {
return dataFolder;
}
/**
* Sets the Data Access Object
* @param dao - the DAO
*/
public static void setDAO(JobsDAO value) {
dao = value;
}
/**
* 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<Job> list) {
jobs = list;
}
/**
* Retrieves the list of active jobs
* @return list of jobs
*/
public static List<Job> getJobs() {
return Collections.unmodifiableList(jobs);
}
/**
* Sets the none job
* @param noneJob - the none job
*/
public static void setNoneJob(Job job) {
noneJob = job;
}
/**
* 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;
2015-08-21 15:10:08 +02:00
}
2015-09-10 12:41:19 +02:00
return null;
}
/**
* Executes startup
* @throws IOException
*/
public static void startup() throws IOException {
reload();
2016-06-09 17:35:24 +02:00
// add all online players
if (!Jobs.getGCManager().MultiServerCompatability()) {
int i = 0;
long time = System.currentTimeMillis();
for (OfflinePlayer offline : Bukkit.getServer().getOfflinePlayers()) {
if (offline.isOnline())
continue;
long lastPlayed = offline.getLastPlayed();
int dif = (int) ((time - lastPlayed) / 1000 / 60 / 60 / 24);
if (dif >= 7)
continue;
JobsPlayer jPlayer = JobsPlayer.loadFromDao(Jobs.getJobsDAO(), offline);
JobsPlayer.loadLogFromDao(jPlayer);
Jobs.getPlayerManager().getPlayersCache().put(offline.getName().toLowerCase(), jPlayer);
i++;
}
Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[Jobs] Preloaded " + i + " players data from last week");
}
2015-09-10 12:41:19 +02:00
// add all online players
for (Player online : Bukkit.getServer().getOnlinePlayers()) {
Jobs.getPlayerManager().playerJoin(online);
2015-08-21 15:10:08 +02:00
}
2015-09-10 12:41:19 +02:00
}
/**
* Reloads all data
* @throws IOException
*/
public static void reload() throws IOException {
if (saveTask != null) {
saveTask.shutdown();
saveTask = null;
2015-08-21 15:10:08 +02:00
}
2015-09-10 12:41:19 +02:00
if (paymentThread != null) {
paymentThread.shutdown();
paymentThread = null;
2015-08-21 15:10:08 +02:00
}
2015-09-10 12:41:19 +02:00
if (dao != null) {
dao.closeConnections();
2015-08-21 15:10:08 +02:00
}
2016-03-30 15:42:36 +02:00
Jobs.getGCManager().reload();
2016-06-25 15:27:01 +02:00
Jobs.getLanguage().reload();
2016-03-30 15:42:36 +02:00
Jobs.getConfigManager().reload();
2015-09-10 12:41:19 +02:00
usedSlots.clear();
for (Job job : jobs) {
usedSlots.put(job, getJobsDAO().getSlotsTaken(job));
2015-08-21 15:10:08 +02:00
}
2015-09-10 12:41:19 +02:00
pManager.reload();
permissionHandler.registerPermissions();
2015-08-21 15:10:08 +02:00
2015-09-10 12:41:19 +02:00
// set the system to auto save
2016-03-30 15:42:36 +02:00
if (Jobs.getGCManager().getSavePeriod() > 0) {
saveTask = new DatabaseSaveThread(Jobs.getGCManager().getSavePeriod());
2015-09-10 12:41:19 +02:00
saveTask.start();
2015-08-21 15:10:08 +02:00
}
2015-09-10 12:41:19 +02:00
// schedule payouts to buffered payments
2016-03-30 15:42:36 +02:00
paymentThread = new BufferedPaymentThread(Jobs.getGCManager().getEconomyBatchDelay());
2015-09-10 12:41:19 +02:00
paymentThread.start();
2015-08-21 15:10:08 +02:00
2016-03-30 15:42:36 +02:00
Jobs.getJobsDAO().loadPlayerData();
2016-04-03 16:22:44 +02:00
// Schedule
Jobs.getScheduleManager().load();
if (Jobs.getGCManager().useGlobalBoostScheduler)
Jobs.getScheduleManager().scheduler();
2015-09-10 12:41:19 +02:00
}
2015-08-21 15:10:08 +02:00
2015-09-10 12:41:19 +02:00
/**
* Executes clean shutdown
*/
public static void shutdown() {
if (saveTask != null)
saveTask.shutdown();
2015-08-21 15:10:08 +02:00
2015-09-10 12:41:19 +02:00
if (paymentThread != null)
paymentThread.shutdown();
2015-08-21 15:10:08 +02:00
2015-09-10 12:41:19 +02:00
pManager.saveAll();
2015-08-21 15:10:08 +02:00
2015-09-10 12:41:19 +02:00
if (dao != null) {
dao.closeConnections();
2015-08-21 15:10:08 +02:00
}
2015-09-10 12:41:19 +02:00
}
/**
* Executes close connections
*/
public static void ChangeDatabase() {
if (dao != null) {
dao.closeConnections();
2015-08-21 15:10:08 +02:00
}
2016-03-30 15:42:36 +02:00
if (Jobs.getGCManager().storageMethod.equals("mysql"))
Jobs.getGCManager().startSqlite();
2015-09-10 12:41:19 +02:00
else
2016-03-30 15:42:36 +02:00
Jobs.getGCManager().startMysql();
2015-09-10 12:41:19 +02:00
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) {
2016-06-25 09:13:06 +02:00
if (usedSlots.containsKey(job))
return usedSlots.get(job);
2016-06-25 15:27:01 +02:00
return 0;
2015-09-10 12:41:19 +02:00
}
/**
* Function to increase the number of used slots for a job
* @param job - the job someone is taking
*/
public static void takeSlot(Job job) {
2016-06-25 09:13:06 +02:00
if (usedSlots.containsKey(job))
usedSlots.put(job, usedSlots.get(job) + 1);
2015-09-10 12:41:19 +02:00
}
/**
* Function to decrease the number of used slots for a job
* @param job - the job someone is leaving
*/
public static void leaveSlot(Job job) {
2016-06-25 09:13:06 +02:00
if (usedSlots.containsKey(job))
usedSlots.put(job, usedSlots.get(job) - 1);
2015-09-10 12:41:19 +02:00
}
/**
* Returns the jobs classloader
* @return the classloader
*/
public static JobsClassLoader getJobsClassloader() {
return classLoader;
}
/**
* Sets the permission handler
* @param h - the permission handler
*/
public static void setPermissionHandler(PermissionHandler h) {
permissionHandler = h;
}
/**
* Gets the permission handler
* @return the permission handler
*/
public static PermissionHandler getPermissionHandler() {
return permissionHandler;
}
/**
* Sets the economy handler
* @param eco - the economy handler
*/
public static void setEconomy(JobsPlugin plugin, Economy eco) {
economy = new BufferedEconomy(plugin, eco);
}
/**
* Gets the economy handler
* @return the economy handler
*/
public static BufferedEconomy getEconomy() {
return economy;
}
public static boolean isUnderMoneyLimit(OfflinePlayer player, Double amount) {
if (player == null)
return true;
2016-03-30 15:42:36 +02:00
if (amount == 0)
return true;
2015-09-10 12:41:19 +02:00
String playername = player.getName();
2016-03-30 15:42:36 +02:00
if (!Jobs.getGCManager().MoneyLimitUse)
2015-09-10 12:41:19 +02:00
return true;
if (!paymentLimit.containsKey(playername)) {
2016-03-30 15:42:36 +02:00
PaymentData data = new PaymentData(System.currentTimeMillis(), amount, 0.0, 0.0, 0L, false);
2015-09-10 12:41:19 +02:00
//data.AddNewAmount(amount);
paymentLimit.put(playername, data);
} else {
PaymentData data = paymentLimit.get(playername);
2015-12-10 14:13:57 +01:00
JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(player);
2016-03-30 15:42:36 +02:00
if (data.IsReachedMoneyLimit(Jobs.getGCManager().MoneyTimeLimit, JPlayer.getMoneyLimit())) {
2015-09-10 12:41:19 +02:00
if (player.isOnline() && !data.Informed && !data.isReseted()) {
2016-03-30 15:42:36 +02:00
((Player) player).sendMessage(Jobs.getLanguage().getMessage("command.limit.output.reachedlimit"));
((Player) player).sendMessage(Jobs.getLanguage().getMessage("command.limit.output.reachedlimit2"));
2015-09-10 12:41:19 +02:00
data.Setinformed();
2015-08-21 15:10:08 +02:00
}
2016-03-30 15:42:36 +02:00
if (data.IsAnnounceTime(Jobs.getGCManager().MoneyAnnouncmentDelay) && player.isOnline()) {
String message = Jobs.getLanguage().getMessage("command.limit.output.lefttime", "%hour%", data.GetLeftHour(Jobs
.getGCManager().MoneyTimeLimit));
message = message.replace("%min%", String.valueOf(data.GetLeftMin(Jobs.getGCManager().MoneyTimeLimit)));
message = message.replace("%sec%", String.valueOf(data.GetLeftsec(Jobs.getGCManager().MoneyTimeLimit)));
Jobs.getActionBar().send(((Player) player), ChatColor.RED + message);
2015-08-21 15:10:08 +02:00
}
2015-09-10 12:41:19 +02:00
if (data.isReseted())
data.setReseted(false);
return false;
2016-06-25 15:27:01 +02:00
}
data.AddAmount(amount);
2015-09-10 12:41:19 +02:00
paymentLimit.put(playername, data);
}
return true;
}
2015-08-21 15:10:08 +02:00
2015-09-10 12:41:19 +02:00
public static boolean isUnderExpLimit(final OfflinePlayer player, Double amount) {
if (player == null)
return false;
2015-08-21 15:10:08 +02:00
2015-09-10 12:41:19 +02:00
String playername = player.getName();
2015-08-21 15:10:08 +02:00
2016-03-30 15:42:36 +02:00
if (!Jobs.getGCManager().ExpLimitUse)
2015-09-10 12:41:19 +02:00
return true;
2015-08-21 15:10:08 +02:00
2015-09-10 12:41:19 +02:00
if (!ExpLimit.containsKey(playername)) {
2016-03-30 15:42:36 +02:00
PaymentData data = new PaymentData(System.currentTimeMillis(), 0.0, 0.0, amount, 0L, false);
2015-09-10 12:41:19 +02:00
//data.AddNewAmount(amount);
ExpLimit.put(playername, data);
} else {
PaymentData data = ExpLimit.get(playername);
2015-12-10 14:13:57 +01:00
JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(player);
2016-03-30 15:42:36 +02:00
if (data.IsReachedExpLimit(Jobs.getGCManager().ExpTimeLimit, JPlayer.getExpLimit())) {
2015-09-10 12:41:19 +02:00
if (player.isOnline() && !data.Informed && !data.isReseted()) {
2016-03-30 15:42:36 +02:00
((Player) player).sendMessage(Jobs.getLanguage().getMessage("command.limit.output.reachedExplimit"));
((Player) player).sendMessage(Jobs.getLanguage().getMessage("command.limit.output.reachedExplimit2"));
2015-09-10 12:41:19 +02:00
data.Setinformed();
2015-08-21 15:10:08 +02:00
}
2016-03-30 15:42:36 +02:00
if (data.IsAnnounceTime(Jobs.getGCManager().ExpAnnouncmentDelay) && player.isOnline()) {
String message = Jobs.getLanguage().getMessage("command.limit.output.lefttime", "%hour%", data.GetLeftHour(Jobs.getGCManager().ExpTimeLimit));
message = message.replace("%min%", String.valueOf(data.GetLeftMin(Jobs.getGCManager().ExpTimeLimit)));
message = message.replace("%sec%", String.valueOf(data.GetLeftsec(Jobs.getGCManager().ExpTimeLimit)));
Jobs.getActionBar().send(((Player) player), ChatColor.RED + message);
2015-08-21 15:10:08 +02:00
}
2015-09-10 12:41:19 +02:00
if (data.isReseted())
data.setReseted(false);
return false;
2016-06-25 15:27:01 +02:00
}
data.AddExpAmount(amount);
2015-09-10 12:41:19 +02:00
ExpLimit.put(playername, data);
2015-08-21 15:10:08 +02:00
}
2015-09-10 12:41:19 +02:00
return true;
}
2016-03-30 15:42:36 +02:00
public static boolean isUnderPointLimit(final OfflinePlayer player, Double amount) {
if (player == null)
return false;
if (amount == 0)
return true;
String playername = player.getName();
if (!Jobs.getGCManager().PointLimitUse)
return true;
if (!PointLimit.containsKey(playername)) {
PaymentData data = new PaymentData(System.currentTimeMillis(), 0.0, amount, 0.0, 0L, false);
//data.AddNewAmount(amount);
PointLimit.put(playername, data);
} else {
PaymentData data = PointLimit.get(playername);
JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(player);
if (data.IsReachedPointLimit(Jobs.getGCManager().PointTimeLimit, JPlayer.getPointLimit())) {
if (player.isOnline() && !data.Informed && !data.isReseted()) {
((Player) player).sendMessage(Jobs.getLanguage().getMessage("command.limit.output.reachedPointlimit"));
((Player) player).sendMessage(Jobs.getLanguage().getMessage("command.limit.output.reachedPointlimit2"));
data.Setinformed();
}
if (data.IsAnnounceTime(Jobs.getGCManager().PointAnnouncmentDelay) && player.isOnline()) {
String message = Jobs.getLanguage().getMessage("command.limit.output.lefttime", "%hour%", data.GetLeftHour(Jobs.getGCManager().PointTimeLimit));
message = message.replace("%min%", String.valueOf(data.GetLeftMin(Jobs.getGCManager().PointTimeLimit)));
message = message.replace("%sec%", String.valueOf(data.GetLeftsec(Jobs.getGCManager().PointTimeLimit)));
Jobs.getActionBar().send(((Player) player), ChatColor.RED + message);
}
if (data.isReseted())
data.setReseted(false);
return false;
2016-06-25 15:27:01 +02:00
}
data.AddPoints(amount);
2016-03-30 15:42:36 +02:00
PointLimit.put(playername, data);
}
return true;
}
2015-09-10 12:41:19 +02:00
/**
* Performed an action
*
* Give correct experience and income
* @param jPlayer - the player
* @param action - the action
* @param multiplier - the payment/xp multiplier
*/
2016-03-30 15:42:36 +02:00
public static void action(JobsPlayer jPlayer, ActionInfo info, double multiplier) {
2015-09-10 12:41:19 +02:00
if (jPlayer == null)
return;
List<JobProgression> progression = jPlayer.getJobProgression();
int numjobs = progression.size();
// no job
if (numjobs == 0) {
Job jobNone = Jobs.getNoneJob();
Player dude = Bukkit.getServer().getPlayer(jPlayer.getPlayerUUID());
if (jobNone != null) {
2016-03-30 15:42:36 +02:00
JobInfo jobinfo = jobNone.getJobInfo(info, 1);
if (jobinfo == null)
return;
2015-09-10 12:41:19 +02:00
2016-03-30 15:42:36 +02:00
Double income = jobinfo.getIncome(1, numjobs);
Double points = jobinfo.getPoints(1, numjobs);
2015-09-10 12:41:19 +02:00
2016-03-30 15:42:36 +02:00
if (income != 0D || points != 0D) {
// jPlayer
2016-06-25 09:13:06 +02:00
BoostMultiplier FinalBoost = Jobs.getPlayerManager().getFinalBonus(jPlayer, Jobs.getNoneJob());
2016-04-03 16:22:44 +02:00
// Calculate income
2016-03-30 15:42:36 +02:00
Double amount = 0D;
2016-04-03 16:22:44 +02:00
if (income != 0D) {
amount = income + (income * FinalBoost.getMoneyBoost() / 100);
if (Jobs.getGCManager().useMinimumOveralPayment && income > 0) {
double maxLimit = income * Jobs.getGCManager().MinimumOveralPaymentLimit;
if (amount < maxLimit) {
amount = maxLimit;
}
}
}
2016-03-30 15:42:36 +02:00
2016-04-03 16:22:44 +02:00
// Calculate points
2016-03-30 15:42:36 +02:00
2016-04-03 16:22:44 +02:00
Double pointAmount = 0D;
if (points != 0D) {
pointAmount = points + (points * FinalBoost.getPointsBoost() / 100);
if (Jobs.getGCManager().useMinimumOveralPoints && points > 0) {
double maxLimit = points * Jobs.getGCManager().MinimumOveralPaymentLimit;
if (pointAmount < maxLimit) {
pointAmount = maxLimit;
}
}
}
2016-03-30 15:42:36 +02:00
2016-04-03 16:22:44 +02:00
if (!isUnderMoneyLimit(dude, amount)) {
amount = 0D;
if (Jobs.getGCManager().MoneyStopPoint)
pointAmount = 0D;
2015-09-10 12:41:19 +02:00
}
2016-04-03 16:22:44 +02:00
if (!isUnderPointLimit(dude, pointAmount)) {
pointAmount = 0D;
if (Jobs.getGCManager().PointStopMoney)
amount = 0D;
}
if (amount == 0D && pointAmount == 0D)
2015-09-10 12:41:19 +02:00
return;
2016-04-03 19:36:39 +02:00
2016-04-05 14:42:48 +02:00
if (pointAmount != 0D)
jPlayer.setSaved(false);
2016-03-30 15:42:36 +02:00
Jobs.getEconomy().pay(jPlayer, amount, pointAmount, 0.0);
2015-08-21 15:10:08 +02:00
2016-03-30 15:42:36 +02:00
if (Jobs.getGCManager().LoggingUse)
2016-06-25 17:56:59 +02:00
Jobs.getLoging().recordToLog(jPlayer, info, amount, 0);
2015-09-10 12:41:19 +02:00
}
}
} else {
for (JobProgression prog : progression) {
int level = prog.getLevel();
2016-03-30 15:42:36 +02:00
JobInfo jobinfo = prog.getJob().getJobInfo(info, level);
if (jobinfo == null)
continue;
Double income = jobinfo.getIncome(level, numjobs);
Double points = jobinfo.getPoints(level, numjobs);
Double exp = jobinfo.getExperience(level, numjobs);
2016-03-30 15:42:36 +02:00
if (income == 0D && points == 0D && exp == 0D)
2016-03-30 15:42:36 +02:00
continue;
if (Jobs.getGCManager().addXpPlayer()) {
Player player = Bukkit.getServer().getPlayer(jPlayer.getPlayerUUID());
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 = exp.intValue();
double remainder = exp.doubleValue() - expInt;
if (Math.abs(remainder) > Math.random()) {
if (exp.doubleValue() < 0) {
expInt--;
} else {
expInt++;
2015-09-10 12:41:19 +02:00
}
}
2016-03-30 15:42:36 +02:00
player.giveExp(expInt);
2015-09-10 12:41:19 +02:00
}
2016-03-30 15:42:36 +02:00
}
2015-09-10 12:41:19 +02:00
BoostMultiplier FinalBoost = Jobs.getPlayerManager().getFinalBonus(jPlayer, prog.getJob());
2016-01-09 13:58:33 +01:00
2016-03-30 15:42:36 +02:00
if (multiplier != 0.0)
2016-04-03 16:22:44 +02:00
FinalBoost = new BoostMultiplier(FinalBoost.getMoneyBoost() + multiplier,
FinalBoost.getPointsBoost() + multiplier,
FinalBoost.getExpBoost() + multiplier);
2016-01-09 13:58:33 +01:00
2016-03-30 15:42:36 +02:00
OfflinePlayer dude = jPlayer.getPlayer();
2016-01-09 13:58:33 +01:00
2016-03-30 15:42:36 +02:00
// Calculate income
2016-01-09 13:58:33 +01:00
2016-03-30 15:42:36 +02:00
Double amount = 0D;
if (income != 0D) {
2016-04-03 16:22:44 +02:00
amount = income + (income * FinalBoost.getMoneyBoost() / 100);
2016-03-30 15:42:36 +02:00
if (Jobs.getGCManager().useMinimumOveralPayment && income > 0) {
double maxLimit = income * Jobs.getGCManager().MinimumOveralPaymentLimit;
if (amount < maxLimit) {
amount = maxLimit;
2015-09-10 12:41:19 +02:00
}
2016-01-09 13:58:33 +01:00
}
2016-03-30 15:42:36 +02:00
}
2016-01-09 13:58:33 +01:00
2016-03-30 15:42:36 +02:00
// Calculate points
2015-08-21 15:10:08 +02:00
2016-03-30 15:42:36 +02:00
Double pointAmount = 0D;
if (points != 0D) {
2016-04-03 16:22:44 +02:00
pointAmount = points + (points * FinalBoost.getPointsBoost() / 100);
2016-03-30 15:42:36 +02:00
if (Jobs.getGCManager().useMinimumOveralPoints && points > 0) {
double maxLimit = points * Jobs.getGCManager().MinimumOveralPaymentLimit;
if (pointAmount < maxLimit) {
pointAmount = maxLimit;
2015-12-21 18:31:18 +01:00
}
}
2016-03-30 15:42:36 +02:00
}
2015-12-21 18:31:18 +01:00
2016-03-30 15:42:36 +02:00
// Calculate exp
2016-04-03 16:22:44 +02:00
double expAmount = exp + (exp * FinalBoost.getExpBoost() / 100);
2015-08-21 15:10:08 +02:00
2016-03-30 15:42:36 +02:00
if (Jobs.getGCManager().useMinimumOveralPayment && exp > 0) {
double maxLimit = exp * Jobs.getGCManager().MinimumOveralPaymentLimit;
if (exp < maxLimit) {
exp = maxLimit;
2015-09-10 12:41:19 +02:00
}
2016-03-30 15:42:36 +02:00
}
2015-08-21 15:10:08 +02:00
2016-03-30 15:42:36 +02:00
if (!isUnderMoneyLimit(dude, amount)) {
amount = 0D;
if (Jobs.getGCManager().MoneyStopExp)
expAmount = 0D;
if (Jobs.getGCManager().MoneyStopPoint)
pointAmount = 0D;
}
2015-12-21 18:31:18 +01:00
2016-03-30 15:42:36 +02:00
if (!isUnderExpLimit(dude, expAmount)) {
expAmount = 0D;
if (Jobs.getGCManager().ExpStopMoney)
amount = 0D;
if (Jobs.getGCManager().ExpStopPoint)
pointAmount = 0D;
}
2015-08-21 15:10:08 +02:00
2016-03-30 15:42:36 +02:00
if (!isUnderPointLimit(dude, pointAmount)) {
pointAmount = 0D;
if (Jobs.getGCManager().PointStopMoney)
amount = 0D;
if (Jobs.getGCManager().PointStopExp)
expAmount = 0D;
}
2015-08-21 15:10:08 +02:00
if (amount == 0D && pointAmount == 0D && expAmount == 0D)
2016-03-30 15:42:36 +02:00
continue;
2015-08-21 15:10:08 +02:00
if (expAmount != 0D)
if (Jobs.getGCManager().BossBarEnabled && Jobs.getGCManager().BossBarShowOnEachAction) {
Jobs.getBBManager().ShowJobProgression(jPlayer, prog);
} else if (Jobs.getGCManager().BossBarEnabled && !Jobs.getGCManager().BossBarShowOnEachAction)
jPlayer.getUpdateBossBarFor().add(prog.getJob().getName());
2015-08-21 15:10:08 +02:00
// 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();
2016-03-30 15:42:36 +02:00
Jobs.getEconomy().pay(jPlayer, amount, pointAmount, expAmount);
int oldLevel = prog.getLevel();
2015-08-21 15:10:08 +02:00
2016-03-30 15:42:36 +02:00
if (Jobs.getGCManager().LoggingUse)
2016-06-25 17:56:59 +02:00
Jobs.getLoging().recordToLog(jPlayer, info, amount, expAmount);
2016-03-30 15:42:36 +02:00
if (prog.addExperience(expAmount))
2016-03-30 15:42:36 +02:00
Jobs.getPlayerManager().performLevelUp(jPlayer, prog.getJob(), oldLevel);
2015-09-10 12:41:19 +02:00
}
2015-08-21 15:10:08 +02:00
}
2015-09-10 12:41:19 +02:00
}
2015-08-21 15:10:08 +02:00
}