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.util.ArrayList;
|
2016-03-30 15:42:36 +02:00
|
|
|
import java.util.HashMap;
|
2015-08-21 15:10:08 +02:00
|
|
|
import java.util.Iterator;
|
2016-03-30 15:42:36 +02:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.Map.Entry;
|
2015-11-25 16:14:48 +01:00
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
2015-08-21 15:10:08 +02:00
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
2017-01-09 14:09:02 +01:00
|
|
|
import org.bukkit.Material;
|
2015-08-21 15:10:08 +02:00
|
|
|
import org.bukkit.Sound;
|
2016-03-30 15:42:36 +02:00
|
|
|
import org.bukkit.enchantments.Enchantment;
|
2016-11-19 09:27:43 +01:00
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
2015-08-21 15:10:08 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2016-11-19 09:27:43 +01:00
|
|
|
import org.bukkit.entity.Tameable;
|
2016-03-30 15:42:36 +02:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
2015-08-21 15:10:08 +02:00
|
|
|
import com.gamingmesh.jobs.api.JobsJoinEvent;
|
|
|
|
import com.gamingmesh.jobs.api.JobsLeaveEvent;
|
|
|
|
import com.gamingmesh.jobs.api.JobsLevelUpEvent;
|
2016-11-19 09:27:43 +01:00
|
|
|
import com.gamingmesh.jobs.container.Boost;
|
2016-03-30 15:42:36 +02:00
|
|
|
import com.gamingmesh.jobs.container.BoostMultiplier;
|
2017-01-10 12:48:40 +01:00
|
|
|
import com.gamingmesh.jobs.container.CurrencyType;
|
2015-08-21 15:10:08 +02:00
|
|
|
import com.gamingmesh.jobs.container.Job;
|
|
|
|
import com.gamingmesh.jobs.container.JobCommands;
|
2016-03-30 15:42:36 +02:00
|
|
|
import com.gamingmesh.jobs.container.JobItems;
|
2015-08-21 15:10:08 +02:00
|
|
|
import com.gamingmesh.jobs.container.JobProgression;
|
|
|
|
import com.gamingmesh.jobs.container.JobsPlayer;
|
2016-03-30 15:42:36 +02:00
|
|
|
import com.gamingmesh.jobs.container.PlayerInfo;
|
2015-08-21 15:10:08 +02:00
|
|
|
import com.gamingmesh.jobs.dao.JobsDAO;
|
2016-03-30 15:42:36 +02:00
|
|
|
import com.gamingmesh.jobs.dao.JobsDAOData;
|
|
|
|
import com.gamingmesh.jobs.economy.PointsData;
|
2015-08-21 15:10:08 +02:00
|
|
|
import com.gamingmesh.jobs.stuff.ChatColor;
|
2016-11-19 09:27:43 +01:00
|
|
|
import com.gamingmesh.jobs.stuff.Debug;
|
2015-08-21 15:10:08 +02:00
|
|
|
import com.gamingmesh.jobs.stuff.PerformCommands;
|
2016-06-09 17:35:24 +02:00
|
|
|
import com.gamingmesh.jobs.stuff.Perm;
|
2015-08-21 15:10:08 +02:00
|
|
|
|
|
|
|
public class PlayerManager {
|
2015-11-25 16:14:48 +01:00
|
|
|
// private Map<String, JobsPlayer> players = Collections.synchronizedMap(new HashMap<String, JobsPlayer>());
|
2016-06-09 17:35:24 +02:00
|
|
|
private ConcurrentHashMap<String, JobsPlayer> playersCache = new ConcurrentHashMap<String, JobsPlayer>();
|
2015-11-25 16:14:48 +01:00
|
|
|
private ConcurrentHashMap<String, JobsPlayer> players = new ConcurrentHashMap<String, JobsPlayer>();
|
2016-03-30 15:42:36 +02:00
|
|
|
private PointsData PointsDatabase = new PointsData();
|
2016-11-19 09:27:43 +01:00
|
|
|
private final String mobSpawnerMetadata = "jobsMobSpawner";
|
2016-03-30 15:42:36 +02:00
|
|
|
|
|
|
|
private HashMap<String, PlayerInfo> PlayerMap = new HashMap<String, PlayerInfo>();
|
2016-08-08 16:36:56 +02:00
|
|
|
Jobs plugin;
|
2016-04-05 16:43:55 +02:00
|
|
|
|
2016-08-08 16:36:56 +02:00
|
|
|
public PlayerManager(Jobs plugin) {
|
2016-04-05 16:43:55 +02:00
|
|
|
this.plugin = plugin;
|
|
|
|
}
|
2016-03-30 15:42:36 +02:00
|
|
|
|
|
|
|
public PointsData getPointsData() {
|
2016-06-25 14:51:21 +02:00
|
|
|
return this.PointsDatabase;
|
2016-03-30 15:42:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public HashMap<String, PlayerInfo> getPlayerMap() {
|
2016-06-25 14:51:21 +02:00
|
|
|
return this.PlayerMap;
|
2016-03-30 15:42:36 +02:00
|
|
|
}
|
|
|
|
|
2016-06-09 17:35:24 +02:00
|
|
|
public ConcurrentHashMap<String, JobsPlayer> getPlayersCache() {
|
2016-06-25 14:51:21 +02:00
|
|
|
return this.playersCache;
|
2016-06-09 17:35:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public ConcurrentHashMap<String, JobsPlayer> getPlayers() {
|
2016-06-25 14:51:21 +02:00
|
|
|
return this.players;
|
2016-06-09 17:35:24 +02:00
|
|
|
}
|
|
|
|
|
2016-03-30 15:42:36 +02:00
|
|
|
public int getPlayerIdByName(String name) {
|
2016-06-25 14:51:21 +02:00
|
|
|
for (Entry<String, PlayerInfo> one : this.PlayerMap.entrySet()) {
|
2016-03-30 15:42:36 +02:00
|
|
|
if (one.getValue().getName() == null)
|
|
|
|
continue;
|
|
|
|
if (one.getValue().getName().equalsIgnoreCase(name))
|
|
|
|
return one.getValue().getID();
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Entry<String, PlayerInfo> getPlayerInfoByName(String name) {
|
2016-06-25 14:51:21 +02:00
|
|
|
for (Entry<String, PlayerInfo> one : this.PlayerMap.entrySet()) {
|
2016-03-30 15:42:36 +02:00
|
|
|
if (one.getValue().getName() == null)
|
|
|
|
continue;
|
|
|
|
if (one.getValue().getName().equalsIgnoreCase(name))
|
|
|
|
return one;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Entry<String, PlayerInfo> getPlayerInfoById(int id) {
|
2016-06-25 14:51:21 +02:00
|
|
|
for (Entry<String, PlayerInfo> one : this.PlayerMap.entrySet()) {
|
2016-03-30 15:42:36 +02:00
|
|
|
if (one.getValue().getName() == null)
|
|
|
|
continue;
|
|
|
|
if (one.getValue().getID() == id)
|
|
|
|
return one;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2015-09-04 16:37:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles join of new player
|
|
|
|
* @param playername
|
|
|
|
*/
|
2015-09-10 12:41:19 +02:00
|
|
|
public void playerJoin(Player player) {
|
2016-06-25 14:51:21 +02:00
|
|
|
JobsPlayer jPlayer = this.playersCache.get(player.getName().toLowerCase());
|
2016-09-23 15:05:31 +02:00
|
|
|
if (jPlayer == null || Jobs.getGCManager().MultiServerCompatability()) {
|
2016-08-05 12:28:31 +02:00
|
|
|
jPlayer = Jobs.getJobsDAO().loadFromDao(player);
|
|
|
|
jPlayer.loadLogFromDao();
|
2016-06-25 14:51:21 +02:00
|
|
|
this.playersCache.put(player.getName().toLowerCase(), jPlayer);
|
2016-09-23 15:05:31 +02:00
|
|
|
}
|
2016-06-09 17:35:24 +02:00
|
|
|
|
2016-06-25 14:51:21 +02:00
|
|
|
this.players.put(player.getName().toLowerCase(), jPlayer);
|
2016-06-26 15:12:44 +02:00
|
|
|
jPlayer.setPlayer(player);
|
2016-04-05 16:43:55 +02:00
|
|
|
AutoJoinJobs(player);
|
2015-11-25 16:14:48 +01:00
|
|
|
jPlayer.onConnect();
|
|
|
|
jPlayer.reloadHonorific();
|
|
|
|
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
|
|
|
|
return;
|
2015-09-04 16:37:36 +02:00
|
|
|
}
|
2015-09-17 09:48:10 +02:00
|
|
|
|
2015-09-04 16:37:36 +02:00
|
|
|
/**
|
|
|
|
* Handles player quit
|
|
|
|
* @param playername
|
|
|
|
*/
|
|
|
|
public void playerQuit(Player player) {
|
2016-09-21 16:18:08 +02:00
|
|
|
JobsPlayer jPlayer = this.players.remove(player.getName().toLowerCase());
|
2017-01-10 14:01:44 +01:00
|
|
|
if (jPlayer == null)
|
|
|
|
jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
|
|
|
|
if (jPlayer == null)
|
|
|
|
return;
|
2016-09-21 16:18:08 +02:00
|
|
|
playersCache.put(player.getName().toLowerCase(), jPlayer);
|
2016-03-30 15:42:36 +02:00
|
|
|
if (Jobs.getGCManager().saveOnDisconnect()) {
|
2017-01-10 14:01:44 +01:00
|
|
|
jPlayer.save();
|
|
|
|
jPlayer.onDisconnect();
|
2015-11-25 16:14:48 +01:00
|
|
|
} else {
|
2017-01-10 14:01:44 +01:00
|
|
|
jPlayer.onDisconnect();
|
2015-08-21 15:10:08 +02:00
|
|
|
}
|
2015-09-04 16:37:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save all the information of all of the players in the game
|
|
|
|
*/
|
|
|
|
public void saveAll() {
|
|
|
|
/*
|
|
|
|
* Saving is a three step process to minimize synchronization locks when called asynchronously.
|
|
|
|
*
|
|
|
|
* 1) Safely copy list for saving.
|
|
|
|
* 2) Perform save on all players on copied list.
|
|
|
|
* 3) Garbage collect the real list to remove any offline players with saved data
|
2015-08-21 15:10:08 +02:00
|
|
|
*/
|
2016-08-08 16:36:56 +02:00
|
|
|
ArrayList<JobsPlayer> list = new ArrayList<JobsPlayer>(this.players.values());
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2015-09-04 16:37:36 +02:00
|
|
|
for (JobsPlayer jPlayer : list) {
|
2016-08-05 12:28:31 +02:00
|
|
|
jPlayer.save();
|
2015-08-21 15:10:08 +02:00
|
|
|
}
|
|
|
|
|
2016-06-25 14:51:21 +02:00
|
|
|
Iterator<JobsPlayer> iter = this.players.values().iterator();
|
2015-11-25 16:14:48 +01:00
|
|
|
while (iter.hasNext()) {
|
|
|
|
JobsPlayer jPlayer = iter.next();
|
|
|
|
if (!jPlayer.isOnline() && jPlayer.isSaved()) {
|
|
|
|
iter.remove();
|
2015-09-04 16:37:36 +02:00
|
|
|
}
|
2015-08-21 15:10:08 +02:00
|
|
|
}
|
2015-09-04 16:37:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the player job info for specific player
|
|
|
|
* @param player - the player who's job you're getting
|
|
|
|
* @return the player job info of the player
|
|
|
|
*/
|
|
|
|
public JobsPlayer getJobsPlayer(Player player) {
|
2016-06-26 15:12:44 +02:00
|
|
|
return getJobsPlayer(player.getName().toLowerCase());
|
2015-09-04 16:37:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the player job info for specific player
|
|
|
|
* @param player name - the player name who's job you're getting
|
|
|
|
* @return the player job info of the player
|
|
|
|
*/
|
|
|
|
public JobsPlayer getJobsPlayer(String playerName) {
|
2016-09-21 16:18:08 +02:00
|
|
|
JobsPlayer jPlayer = this.players.get(playerName.toLowerCase());
|
2015-09-04 16:37:36 +02:00
|
|
|
if (jPlayer != null)
|
|
|
|
return jPlayer;
|
2016-09-21 16:18:08 +02:00
|
|
|
return this.playersCache.get(playerName.toLowerCase());
|
2015-09-04 16:37:36 +02:00
|
|
|
}
|
2016-08-05 13:08:08 +02:00
|
|
|
|
2016-08-05 12:28:31 +02:00
|
|
|
/**
|
|
|
|
* Get the player job info for specific player
|
|
|
|
* @param player - the player who's job you're getting
|
|
|
|
* @return the player job info of the player
|
|
|
|
*/
|
|
|
|
public JobsPlayer getJobsPlayerOffline(Entry<String, PlayerInfo> info) {
|
2016-08-05 13:08:08 +02:00
|
|
|
|
2016-08-05 12:28:31 +02:00
|
|
|
if (info == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
if (info.getValue().getName() == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
JobsPlayer jPlayer = new JobsPlayer(info.getValue().getName(), null);
|
|
|
|
jPlayer.setPlayerUUID(UUID.fromString(info.getKey()));
|
|
|
|
jPlayer.setUserId(info.getValue().getID());
|
2015-09-04 16:37:36 +02:00
|
|
|
|
2016-08-08 16:36:56 +02:00
|
|
|
List<JobsDAOData> list = Jobs.getJobsDAO().getAllJobs(info.getValue());
|
2016-08-05 12:28:31 +02:00
|
|
|
for (JobsDAOData jobdata : list) {
|
|
|
|
if (Jobs.getJob(jobdata.getJobName()) == null)
|
|
|
|
continue;
|
|
|
|
Job job = Jobs.getJob(jobdata.getJobName());
|
|
|
|
if (job == null)
|
|
|
|
continue;
|
|
|
|
JobProgression jobProgression = new JobProgression(job, jPlayer, jobdata.getLevel(), jobdata.getExperience());
|
|
|
|
jPlayer.progression.add(jobProgression);
|
|
|
|
jPlayer.reloadMaxExperience();
|
|
|
|
jPlayer.reloadLimits();
|
|
|
|
}
|
|
|
|
|
|
|
|
Jobs.getJobsDAO().loadPoints(jPlayer);
|
|
|
|
|
|
|
|
jPlayer.loadLogFromDao();
|
|
|
|
|
|
|
|
return jPlayer;
|
|
|
|
}
|
2016-08-05 13:08:08 +02:00
|
|
|
|
2015-09-04 16:37:36 +02:00
|
|
|
/**
|
|
|
|
* Causes player to join their job
|
|
|
|
* @param jPlayer
|
|
|
|
* @param job
|
|
|
|
*/
|
|
|
|
public void joinJob(JobsPlayer jPlayer, Job job) {
|
2015-11-25 16:14:48 +01:00
|
|
|
// synchronized (jPlayer.saveLock) {
|
|
|
|
if (jPlayer.isInJob(job))
|
|
|
|
return;
|
|
|
|
// let the user join the job
|
2016-08-05 12:28:31 +02:00
|
|
|
if (!jPlayer.joinJob(job))
|
2015-11-25 16:14:48 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
// JobsJoin event
|
|
|
|
JobsJoinEvent jobsjoinevent = new JobsJoinEvent(jPlayer, job);
|
|
|
|
Bukkit.getServer().getPluginManager().callEvent(jobsjoinevent);
|
|
|
|
// If event is canceled, dont do anything
|
|
|
|
if (jobsjoinevent.isCancelled())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Jobs.getJobsDAO().joinJob(jPlayer, job);
|
|
|
|
PerformCommands.PerformCommandsOnJoin(jPlayer, job);
|
|
|
|
Jobs.takeSlot(job);
|
2016-01-06 14:40:27 +01:00
|
|
|
Jobs.getSignUtil().SignUpdate(job.getName());
|
|
|
|
Jobs.getSignUtil().SignUpdate("gtoplist");
|
2015-11-25 16:14:48 +01:00
|
|
|
job.updateTotalPlayers();
|
|
|
|
// }
|
2015-09-04 16:37:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Causes player to leave their job
|
|
|
|
* @param jPlayer
|
|
|
|
* @param job
|
|
|
|
*/
|
2016-08-05 13:08:08 +02:00
|
|
|
public boolean leaveJob(JobsPlayer jPlayer, Job job) {
|
2015-11-25 16:14:48 +01:00
|
|
|
// synchronized (jPlayer.saveLock) {
|
|
|
|
if (!jPlayer.isInJob(job))
|
2016-08-05 13:08:08 +02:00
|
|
|
return false;
|
2015-11-25 16:14:48 +01:00
|
|
|
|
|
|
|
// JobsJoin event
|
|
|
|
JobsLeaveEvent jobsleaveevent = new JobsLeaveEvent(jPlayer, job);
|
|
|
|
Bukkit.getServer().getPluginManager().callEvent(jobsleaveevent);
|
|
|
|
// If event is canceled, dont do anything
|
|
|
|
if (jobsleaveevent.isCancelled())
|
2016-08-05 13:08:08 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
Jobs.getJobsDAO().recordToArchive(jPlayer, job);
|
|
|
|
// let the user leave the job
|
|
|
|
if (!jPlayer.leaveJob(job))
|
|
|
|
return false;
|
2015-11-25 16:14:48 +01:00
|
|
|
|
2016-09-23 14:07:35 +02:00
|
|
|
if (!Jobs.getJobsDAO().quitJob(jPlayer, job))
|
|
|
|
return false;
|
2015-11-25 16:14:48 +01:00
|
|
|
PerformCommands.PerformCommandsOnLeave(jPlayer, job);
|
|
|
|
Jobs.leaveSlot(job);
|
|
|
|
|
2016-01-06 14:40:27 +01:00
|
|
|
Jobs.getSignUtil().SignUpdate(job.getName());
|
|
|
|
Jobs.getSignUtil().SignUpdate("gtoplist");
|
2015-11-25 16:14:48 +01:00
|
|
|
job.updateTotalPlayers();
|
2016-08-05 13:08:08 +02:00
|
|
|
return true;
|
2015-11-25 16:14:48 +01:00
|
|
|
// }
|
2015-09-04 16:37:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Causes player to leave all their jobs
|
|
|
|
* @param jPlayer
|
|
|
|
*/
|
|
|
|
public void leaveAllJobs(JobsPlayer jPlayer) {
|
2016-06-28 11:33:28 +02:00
|
|
|
List<JobProgression> jobs = new ArrayList<JobProgression>();
|
|
|
|
jobs.addAll(jPlayer.getJobProgression());
|
|
|
|
for (JobProgression job : jobs) {
|
2016-06-27 13:52:46 +02:00
|
|
|
leaveJob(jPlayer, job.getJob());
|
2015-08-21 15:10:08 +02:00
|
|
|
}
|
2015-11-25 16:14:48 +01:00
|
|
|
jPlayer.leaveAllJobs();
|
2015-09-04 16:37:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transfers player job
|
|
|
|
* @param jPlayer
|
|
|
|
* @param oldjob - the old job
|
|
|
|
* @param newjob - the new job
|
|
|
|
*/
|
2016-09-23 14:07:35 +02:00
|
|
|
public boolean transferJob(JobsPlayer jPlayer, Job oldjob, Job newjob) {
|
2015-11-25 16:14:48 +01:00
|
|
|
// synchronized (jPlayer.saveLock) {
|
2016-08-05 12:28:31 +02:00
|
|
|
if (!jPlayer.transferJob(oldjob, newjob))
|
2016-09-23 14:07:35 +02:00
|
|
|
return false;
|
2015-11-25 16:14:48 +01:00
|
|
|
|
|
|
|
JobsDAO dao = Jobs.getJobsDAO();
|
2016-09-23 14:07:35 +02:00
|
|
|
if (!dao.quitJob(jPlayer, oldjob))
|
|
|
|
return false;
|
2015-11-25 16:14:48 +01:00
|
|
|
oldjob.updateTotalPlayers();
|
|
|
|
dao.joinJob(jPlayer, newjob);
|
|
|
|
newjob.updateTotalPlayers();
|
2016-08-05 12:28:31 +02:00
|
|
|
jPlayer.save();
|
2015-11-25 16:14:48 +01:00
|
|
|
// }
|
2016-09-23 14:07:35 +02:00
|
|
|
return true;
|
2015-09-04 16:37:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Promotes player in their job
|
|
|
|
* @param jPlayer
|
|
|
|
* @param job - the job
|
|
|
|
* @param levels - number of levels to promote
|
|
|
|
*/
|
|
|
|
public void promoteJob(JobsPlayer jPlayer, Job job, int levels) {
|
2015-11-25 16:14:48 +01:00
|
|
|
// synchronized (jPlayer.saveLock) {
|
2016-08-05 12:28:31 +02:00
|
|
|
jPlayer.promoteJob(job, levels);
|
|
|
|
jPlayer.save();
|
2015-09-04 16:37:36 +02:00
|
|
|
|
2016-01-06 14:40:27 +01:00
|
|
|
Jobs.getSignUtil().SignUpdate(job.getName());
|
|
|
|
Jobs.getSignUtil().SignUpdate("gtoplist");
|
2015-11-25 16:14:48 +01:00
|
|
|
// }
|
2015-09-04 16:37:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Demote player in their job
|
|
|
|
* @param jPlayer
|
|
|
|
* @param job - the job
|
|
|
|
* @param levels - number of levels to demote
|
|
|
|
*/
|
|
|
|
public void demoteJob(JobsPlayer jPlayer, Job job, int levels) {
|
2015-11-25 16:14:48 +01:00
|
|
|
// synchronized (jPlayer.saveLock) {
|
|
|
|
jPlayer.demoteJob(job, levels);
|
2016-08-05 12:28:31 +02:00
|
|
|
jPlayer.save();
|
2016-01-06 14:40:27 +01:00
|
|
|
Jobs.getSignUtil().SignUpdate(job.getName());
|
|
|
|
Jobs.getSignUtil().SignUpdate("gtoplist");
|
2015-11-25 16:14:48 +01:00
|
|
|
// }
|
2015-09-04 16:37:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds experience to the player
|
|
|
|
* @param jPlayer
|
|
|
|
* @param job - the job
|
|
|
|
* @param experience - experience gained
|
|
|
|
*/
|
|
|
|
public void addExperience(JobsPlayer jPlayer, Job job, double experience) {
|
2015-11-25 16:14:48 +01:00
|
|
|
// synchronized (jPlayer.saveLock) {
|
|
|
|
JobProgression prog = jPlayer.getJobProgression(job);
|
|
|
|
if (prog == null)
|
|
|
|
return;
|
|
|
|
int oldLevel = prog.getLevel();
|
|
|
|
if (prog.addExperience(experience))
|
|
|
|
performLevelUp(jPlayer, job, oldLevel);
|
|
|
|
|
2016-08-05 12:28:31 +02:00
|
|
|
jPlayer.save();
|
2016-01-06 14:40:27 +01:00
|
|
|
Jobs.getSignUtil().SignUpdate(job.getName());
|
|
|
|
Jobs.getSignUtil().SignUpdate("gtoplist");
|
2015-11-25 16:14:48 +01:00
|
|
|
// }
|
2015-09-04 16:37:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes experience to the player
|
|
|
|
* @param jPlayer
|
|
|
|
* @param job - the job
|
|
|
|
* @param experience - experience gained
|
|
|
|
*/
|
|
|
|
public void removeExperience(JobsPlayer jPlayer, Job job, double experience) {
|
2015-11-25 16:14:48 +01:00
|
|
|
// synchronized (jPlayer.saveLock) {
|
|
|
|
JobProgression prog = jPlayer.getJobProgression(job);
|
|
|
|
if (prog == null)
|
|
|
|
return;
|
|
|
|
prog.addExperience(-experience);
|
|
|
|
|
2016-08-05 12:28:31 +02:00
|
|
|
jPlayer.save();
|
2016-01-06 14:40:27 +01:00
|
|
|
Jobs.getSignUtil().SignUpdate(job.getName());
|
|
|
|
Jobs.getSignUtil().SignUpdate("gtoplist");
|
2015-11-25 16:14:48 +01:00
|
|
|
// }
|
2015-09-04 16:37:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Broadcasts level up about a player
|
|
|
|
* @param jPlayer
|
|
|
|
* @param job
|
|
|
|
* @param oldLevel
|
|
|
|
*/
|
|
|
|
public void performLevelUp(JobsPlayer jPlayer, Job job, int oldLevel) {
|
|
|
|
|
2016-06-09 17:35:24 +02:00
|
|
|
Player player = jPlayer.getPlayer();
|
2015-09-04 16:37:36 +02:00
|
|
|
JobProgression prog = jPlayer.getJobProgression(job);
|
|
|
|
if (prog == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// LevelUp event
|
2016-10-01 12:23:30 +02:00
|
|
|
JobsLevelUpEvent levelUpEvent = new JobsLevelUpEvent(
|
|
|
|
jPlayer,
|
|
|
|
job.getName(),
|
|
|
|
prog.getLevel(),
|
|
|
|
Jobs.gettitleManager().getTitle(oldLevel, prog.getJob().getName()),
|
|
|
|
Jobs.gettitleManager().getTitle(prog.getLevel(), prog.getJob().getName()),
|
|
|
|
Jobs.getGCManager().SoundLevelupSound.toUpperCase(),
|
|
|
|
Jobs.getGCManager().SoundLevelupVolume,
|
|
|
|
Jobs.getGCManager().SoundLevelupPitch,
|
|
|
|
Jobs.getGCManager().SoundTitleChangeSound.toUpperCase(),
|
2016-11-19 09:27:43 +01:00
|
|
|
Jobs.getGCManager().SoundTitleChangeVolume,
|
2016-10-01 12:23:30 +02:00
|
|
|
Jobs.getGCManager().SoundTitleChangePitch);
|
2015-09-04 16:37:36 +02:00
|
|
|
Bukkit.getServer().getPluginManager().callEvent(levelUpEvent);
|
|
|
|
// If event is canceled, dont do anything
|
|
|
|
if (levelUpEvent.isCancelled())
|
|
|
|
return;
|
|
|
|
|
2016-03-30 15:42:36 +02:00
|
|
|
if (Jobs.getGCManager().SoundLevelupUse) {
|
2016-09-30 12:19:57 +02:00
|
|
|
Sound sound = levelUpEvent.getSound();
|
|
|
|
if (sound != null && player != null && player.getLocation() != null)
|
2016-03-02 15:14:44 +01:00
|
|
|
player.getWorld().playSound(player.getLocation(), sound, levelUpEvent.getSoundVolume(), levelUpEvent.getSoundPitch());
|
|
|
|
else
|
2017-01-10 16:28:35 +01:00
|
|
|
Bukkit.getConsoleSender().sendMessage("[Jobs] Cant find sound by name: " + levelUpEvent.getTitleChangeSound().name() + ". Please update it");
|
2016-03-02 15:14:44 +01:00
|
|
|
}
|
2015-09-04 16:37:36 +02:00
|
|
|
|
|
|
|
String message;
|
2016-03-30 15:42:36 +02:00
|
|
|
if (Jobs.getGCManager().isBroadcastingLevelups()) {
|
|
|
|
message = Jobs.getLanguage().getMessage("message.levelup.broadcast");
|
2015-09-04 16:37:36 +02:00
|
|
|
} else {
|
2016-03-30 15:42:36 +02:00
|
|
|
message = Jobs.getLanguage().getMessage("message.levelup.nobroadcast");
|
2015-08-21 15:10:08 +02:00
|
|
|
}
|
|
|
|
|
2015-09-04 16:37:36 +02:00
|
|
|
message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE);
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2015-09-04 16:37:36 +02:00
|
|
|
if (levelUpEvent.getOldTitle() != null) {
|
|
|
|
message = message.replace("%titlename%", levelUpEvent.getOldTitleColor() + levelUpEvent.getOldTitleName() + ChatColor.WHITE);
|
|
|
|
}
|
|
|
|
if (player != null) {
|
|
|
|
message = message.replace("%playername%", player.getDisplayName());
|
|
|
|
} else {
|
|
|
|
message = message.replace("%playername%", jPlayer.getUserName());
|
|
|
|
}
|
|
|
|
message = message.replace("%joblevel%", "" + prog.getLevel());
|
|
|
|
for (String line : message.split("\n")) {
|
2016-03-30 15:42:36 +02:00
|
|
|
if (Jobs.getGCManager().isBroadcastingLevelups()) {
|
|
|
|
if (Jobs.getGCManager().BroadcastingLevelUpLevels.contains(oldLevel + 1) || Jobs.getGCManager().BroadcastingLevelUpLevels.contains(0))
|
2015-09-04 16:37:36 +02:00
|
|
|
Bukkit.getServer().broadcastMessage(line);
|
|
|
|
} else if (player != null) {
|
2016-03-30 15:42:36 +02:00
|
|
|
if (Jobs.getGCManager().LevelChangeActionBar)
|
|
|
|
Jobs.getActionBar().send(player, line);
|
|
|
|
if (Jobs.getGCManager().LevelChangeChat)
|
2015-09-04 16:37:36 +02:00
|
|
|
player.sendMessage(line);
|
|
|
|
}
|
|
|
|
}
|
2015-08-21 15:10:08 +02:00
|
|
|
|
2015-09-04 16:37:36 +02:00
|
|
|
if (levelUpEvent.getNewTitle() != null && !levelUpEvent.getNewTitle().equals(levelUpEvent.getOldTitle())) {
|
|
|
|
|
2016-03-30 15:42:36 +02:00
|
|
|
if (Jobs.getGCManager().SoundTitleChangeUse) {
|
2016-09-30 12:19:57 +02:00
|
|
|
Sound sound = levelUpEvent.getTitleChangeSound();
|
2016-10-01 12:23:30 +02:00
|
|
|
if (sound != null && player != null && player.getLocation() != null)
|
2016-03-02 15:14:44 +01:00
|
|
|
player.getWorld().playSound(player.getLocation(), sound, levelUpEvent.getTitleChangeVolume(),
|
|
|
|
levelUpEvent.getTitleChangePitch());
|
|
|
|
else
|
2017-01-10 16:28:35 +01:00
|
|
|
Bukkit.getConsoleSender().sendMessage("[Jobs] Cant find sound by name: " + levelUpEvent.getTitleChangeSound().name() + ". Please update it");
|
2016-03-02 15:14:44 +01:00
|
|
|
}
|
2015-09-04 16:37:36 +02:00
|
|
|
// user would skill up
|
2016-03-30 15:42:36 +02:00
|
|
|
if (Jobs.getGCManager().isBroadcastingSkillups()) {
|
|
|
|
message = Jobs.getLanguage().getMessage("message.skillup.broadcast");
|
2015-09-04 16:37:36 +02:00
|
|
|
} else {
|
2016-03-30 15:42:36 +02:00
|
|
|
message = Jobs.getLanguage().getMessage("message.skillup.nobroadcast");
|
2015-09-04 16:37:36 +02:00
|
|
|
}
|
|
|
|
if (player != null) {
|
|
|
|
message = message.replace("%playername%", player.getDisplayName());
|
|
|
|
} else {
|
|
|
|
message = message.replace("%playername%", jPlayer.getUserName());
|
|
|
|
}
|
|
|
|
message = message.replace("%titlename%", levelUpEvent.getNewTitleColor() + levelUpEvent.getNewTitleName() + ChatColor.WHITE);
|
|
|
|
message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE);
|
|
|
|
for (String line : message.split("\n")) {
|
2016-03-30 15:42:36 +02:00
|
|
|
if (Jobs.getGCManager().isBroadcastingLevelups()) {
|
2015-09-04 16:37:36 +02:00
|
|
|
Bukkit.getServer().broadcastMessage(line);
|
|
|
|
} else if (player != null) {
|
2016-03-30 15:42:36 +02:00
|
|
|
if (Jobs.getGCManager().TitleChangeActionBar)
|
|
|
|
Jobs.getActionBar().send(player, line);
|
|
|
|
if (Jobs.getGCManager().TitleChangeChat)
|
2015-09-04 16:37:36 +02:00
|
|
|
player.sendMessage(line);
|
2015-08-21 15:10:08 +02:00
|
|
|
}
|
2015-09-04 16:37:36 +02:00
|
|
|
}
|
2015-08-21 15:10:08 +02:00
|
|
|
}
|
2015-09-04 16:37:36 +02:00
|
|
|
jPlayer.reloadHonorific();
|
|
|
|
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
|
|
|
|
performCommandOnLevelUp(jPlayer, prog.getJob(), oldLevel);
|
2016-01-06 14:40:27 +01:00
|
|
|
Jobs.getSignUtil().SignUpdate(job.getName());
|
|
|
|
Jobs.getSignUtil().SignUpdate("gtoplist");
|
2015-09-17 09:48:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Performs command on level up
|
|
|
|
* @param jPlayer
|
|
|
|
* @param job
|
|
|
|
* @param oldLevel
|
2015-09-04 16:37:36 +02:00
|
|
|
*/
|
|
|
|
public void performCommandOnLevelUp(JobsPlayer jPlayer, Job job, int oldLevel) {
|
|
|
|
int newLevel = oldLevel + 1;
|
|
|
|
Player player = Bukkit.getServer().getPlayer(jPlayer.getPlayerUUID());
|
|
|
|
JobProgression prog = jPlayer.getJobProgression(job);
|
|
|
|
if (prog == null)
|
|
|
|
return;
|
|
|
|
for (JobCommands command : job.getCommands()) {
|
|
|
|
if (newLevel >= command.getLevelFrom() && newLevel <= command.getLevelUntil()) {
|
|
|
|
String commandString = command.getCommand();
|
|
|
|
commandString = commandString.replace("[player]", player.getName());
|
|
|
|
commandString = commandString.replace("[oldlevel]", String.valueOf(oldLevel));
|
|
|
|
commandString = commandString.replace("[newlevel]", String.valueOf(newLevel));
|
|
|
|
commandString = commandString.replace("[jobname]", job.getName());
|
|
|
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), commandString);
|
|
|
|
}
|
2015-08-21 15:10:08 +02:00
|
|
|
}
|
2015-09-04 16:37:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get max jobs
|
|
|
|
* @param player
|
|
|
|
* @return True if he have permission
|
|
|
|
*/
|
2017-01-13 14:10:55 +01:00
|
|
|
public boolean getJobsLimit(JobsPlayer jPlayer, Short currentCount) {
|
2015-09-04 16:37:36 +02:00
|
|
|
|
2017-01-13 14:10:55 +01:00
|
|
|
Double max = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.max");
|
2015-09-04 16:37:36 +02:00
|
|
|
|
2017-01-13 14:10:55 +01:00
|
|
|
max = max == null ? Jobs.getGCManager().getMaxJobs() : max;
|
2016-01-10 14:25:14 +01:00
|
|
|
|
2017-01-13 14:10:55 +01:00
|
|
|
if (max > currentCount)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Using new system to get max value from permission
|
|
|
|
|
|
|
|
// if (Perm.hasPermission(player, "jobs.max.*"))
|
|
|
|
// return true;
|
|
|
|
//
|
|
|
|
// int totalJobs = Jobs.getJobs().size() + 1;
|
|
|
|
//
|
|
|
|
// short count = (short) Jobs.getGCManager().getMaxJobs();
|
|
|
|
// for (short ctr = 0; ctr < totalJobs; ctr++) {
|
|
|
|
// if (Perm.hasPermission(player, "jobs.max." + ctr))
|
|
|
|
// count = ctr;
|
|
|
|
// if (count > currentCount)
|
|
|
|
// return true;
|
|
|
|
// }
|
2015-09-04 16:37:36 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-19 09:27:43 +01:00
|
|
|
public BoostMultiplier getBoost(JobsPlayer player, Job job) {
|
2017-01-10 16:28:35 +01:00
|
|
|
return getBoost(player, job, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public BoostMultiplier getBoost(JobsPlayer player, Job job, boolean force) {
|
2016-11-19 09:27:43 +01:00
|
|
|
BoostMultiplier b = new BoostMultiplier();
|
2017-01-10 12:48:40 +01:00
|
|
|
for (CurrencyType one : CurrencyType.values()) {
|
2017-01-10 16:28:35 +01:00
|
|
|
b.add(one, getBoost(player, job, one, force));
|
2016-11-19 09:27:43 +01:00
|
|
|
}
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2017-01-10 12:48:40 +01:00
|
|
|
public double getBoost(JobsPlayer player, Job job, CurrencyType type) {
|
2016-11-19 09:27:43 +01:00
|
|
|
return getBoost(player, job, type, false);
|
2016-06-15 12:27:43 +02:00
|
|
|
}
|
|
|
|
|
2017-01-10 12:48:40 +01:00
|
|
|
public double getBoost(JobsPlayer player, Job job, CurrencyType type, boolean force) {
|
2016-11-19 09:27:43 +01:00
|
|
|
return player.getBoost(job.getName(), type, force);
|
2015-09-04 16:37:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform reload
|
|
|
|
*/
|
|
|
|
public void reload() {
|
2016-06-25 14:51:21 +02:00
|
|
|
for (JobsPlayer jPlayer : this.players.values()) {
|
2015-11-25 16:14:48 +01:00
|
|
|
for (JobProgression progression : jPlayer.getJobProgression()) {
|
|
|
|
String jobName = progression.getJob().getName();
|
|
|
|
Job job = Jobs.getJob(jobName);
|
|
|
|
if (job != null) {
|
|
|
|
progression.setJob(job);
|
2015-08-21 15:10:08 +02:00
|
|
|
}
|
2015-09-04 16:37:36 +02:00
|
|
|
}
|
2015-11-25 16:14:48 +01:00
|
|
|
if (jPlayer.isOnline()) {
|
|
|
|
jPlayer.reloadHonorific();
|
2016-03-30 15:42:36 +02:00
|
|
|
jPlayer.reloadLimits();
|
2015-11-25 16:14:48 +01:00
|
|
|
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
|
|
|
|
}
|
2015-08-21 15:10:08 +02:00
|
|
|
}
|
2016-03-30 15:42:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public BoostMultiplier getItemBoost(Player player, Job prog) {
|
2016-11-19 09:27:43 +01:00
|
|
|
BoostMultiplier data = new BoostMultiplier();
|
2016-03-30 15:42:36 +02:00
|
|
|
if (player == null)
|
|
|
|
return data;
|
2017-01-09 14:09:02 +01:00
|
|
|
if (prog == null)
|
2016-08-05 12:36:30 +02:00
|
|
|
return data;
|
2017-01-09 14:09:02 +01:00
|
|
|
ItemStack iih = Jobs.getNms().getItemInMainHand(player);
|
|
|
|
data = Jobs.getPlayerManager().getItemBoost(prog, iih);
|
2016-03-30 15:42:36 +02:00
|
|
|
for (ItemStack OneArmor : player.getInventory().getArmorContents()) {
|
2017-01-09 14:09:02 +01:00
|
|
|
if (OneArmor == null || OneArmor.getType() == Material.AIR)
|
|
|
|
continue;
|
|
|
|
BoostMultiplier armorboost = Jobs.getPlayerManager().getItemBoost(prog, OneArmor);
|
2016-11-19 09:27:43 +01:00
|
|
|
data.add(armorboost);
|
2016-03-30 15:42:36 +02:00
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
public BoostMultiplier getItemBoost(Job prog, ItemStack item) {
|
2016-11-19 09:27:43 +01:00
|
|
|
BoostMultiplier bonus = new BoostMultiplier();
|
2017-01-09 14:09:02 +01:00
|
|
|
if (prog.getItems().isEmpty())
|
|
|
|
return bonus;
|
2016-03-30 15:42:36 +02:00
|
|
|
if (item == null)
|
2016-11-19 09:27:43 +01:00
|
|
|
return bonus;
|
2016-03-30 15:42:36 +02:00
|
|
|
|
|
|
|
ItemMeta meta = item.getItemMeta();
|
|
|
|
String name = null;
|
|
|
|
List<String> lore = new ArrayList<String>();
|
|
|
|
|
|
|
|
if (item.hasItemMeta()) {
|
|
|
|
if (meta.hasDisplayName())
|
|
|
|
name = meta.getDisplayName();
|
|
|
|
if (meta.hasLore())
|
|
|
|
lore = meta.getLore();
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<Enchantment, Integer> enchants = item.getEnchantments();
|
|
|
|
|
|
|
|
main: for (JobItems oneItem : prog.getItems()) {
|
|
|
|
if (oneItem.getId() != item.getTypeId())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (oneItem.getName() != null && name != null)
|
|
|
|
if (!org.bukkit.ChatColor.translateAlternateColorCodes('&', oneItem.getName()).equalsIgnoreCase(name))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (String onelore : oneItem.getLore()) {
|
|
|
|
if (lore.size() == 0 || !lore.contains(onelore))
|
|
|
|
continue main;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Entry<Enchantment, Integer> oneE : enchants.entrySet()) {
|
2016-08-08 16:36:56 +02:00
|
|
|
if (oneItem.getEnchants().containsKey(oneE.getKey())) {
|
|
|
|
if (oneItem.getEnchants().get(oneE.getKey()) < oneE.getValue()) {
|
2016-03-30 15:42:36 +02:00
|
|
|
continue main;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
continue main;
|
|
|
|
}
|
|
|
|
|
2017-01-10 15:25:02 +01:00
|
|
|
return oneItem.getBoost();
|
2016-03-30 15:42:36 +02:00
|
|
|
}
|
|
|
|
|
2016-11-19 09:27:43 +01:00
|
|
|
return bonus;
|
2016-03-30 15:42:36 +02:00
|
|
|
}
|
|
|
|
|
2016-11-19 09:27:43 +01:00
|
|
|
public enum BoostOf {
|
|
|
|
McMMO, PetPay, NearSpawner, Permission, Global, Dynamic, Item, Area
|
|
|
|
}
|
2016-03-30 15:42:36 +02:00
|
|
|
|
2017-01-10 16:28:35 +01:00
|
|
|
public Boost getFinalBonus(JobsPlayer player, Job prog, boolean force) {
|
|
|
|
return getFinalBonus(player, prog, null, null, force);
|
|
|
|
}
|
|
|
|
|
2016-11-19 09:27:43 +01:00
|
|
|
public Boost getFinalBonus(JobsPlayer player, Job prog) {
|
2017-01-10 16:28:35 +01:00
|
|
|
return getFinalBonus(player, prog, null, null, false);
|
2016-11-19 09:27:43 +01:00
|
|
|
}
|
2016-03-30 15:42:36 +02:00
|
|
|
|
2017-01-10 16:28:35 +01:00
|
|
|
public Boost getFinalBonus(JobsPlayer player, Job prog, Entity ent, LivingEntity victim, boolean force) {
|
2016-11-19 09:27:43 +01:00
|
|
|
Boost boost = new Boost();
|
2016-03-30 15:42:36 +02:00
|
|
|
|
2016-11-19 09:27:43 +01:00
|
|
|
if (player == null || prog == null)
|
|
|
|
return boost;
|
|
|
|
|
|
|
|
if (Jobs.getMcMMOlistener().mcMMOPresent)
|
|
|
|
boost.add(BoostOf.McMMO, new BoostMultiplier().add(Jobs.getMcMMOlistener().getMultiplier(player.getPlayer())));
|
|
|
|
|
|
|
|
if (ent != null && ent instanceof Tameable) {
|
|
|
|
Tameable t = (Tameable) ent;
|
|
|
|
if (t.isTamed() && t.getOwner() instanceof Player) {
|
|
|
|
Player pDamager = (Player) t.getOwner();
|
|
|
|
double PetPayMultiplier = 0D;
|
|
|
|
if (Perm.hasPermission(pDamager, "jobs.petpay") || Perm.hasPermission(pDamager, "jobs.vippetpay"))
|
|
|
|
PetPayMultiplier = Jobs.getGCManager().VipPetPay;
|
|
|
|
else
|
|
|
|
PetPayMultiplier = Jobs.getGCManager().PetPay;
|
|
|
|
boost.add(BoostOf.PetPay, new BoostMultiplier().add(PetPayMultiplier));
|
|
|
|
}
|
|
|
|
}
|
2016-03-30 15:42:36 +02:00
|
|
|
|
2016-11-19 09:27:43 +01:00
|
|
|
if (victim != null && victim.hasMetadata(this.getMobSpawnerMetadata()))
|
|
|
|
boost.add(BoostOf.NearSpawner, new BoostMultiplier().add(player.getVipSpawnerMultiplier()));
|
2017-01-10 16:28:35 +01:00
|
|
|
boost.add(BoostOf.Permission, Jobs.getPlayerManager().getBoost(player, prog, force));
|
2016-11-19 09:27:43 +01:00
|
|
|
boost.add(BoostOf.Global, prog.getBoost());
|
|
|
|
if (Jobs.getGCManager().useDynamicPayment)
|
|
|
|
boost.add(BoostOf.Dynamic, new BoostMultiplier().add(prog.getBonus()));
|
|
|
|
boost.add(BoostOf.Item, Jobs.getPlayerManager().getItemBoost(player.getPlayer(), prog));
|
|
|
|
boost.add(BoostOf.Area, new BoostMultiplier().add(Jobs.getRestrictedAreaManager().getRestrictedMultiplier(player.getPlayer())));
|
|
|
|
return boost;
|
2015-09-04 16:37:36 +02:00
|
|
|
}
|
2016-04-05 16:43:55 +02:00
|
|
|
|
|
|
|
public void AutoJoinJobs(final Player player) {
|
|
|
|
if (player == null)
|
|
|
|
return;
|
|
|
|
if (player.isOp())
|
|
|
|
return;
|
2016-06-15 12:27:43 +02:00
|
|
|
if (!Jobs.getGCManager().AutoJobJoinUse)
|
|
|
|
return;
|
2016-06-25 14:51:21 +02:00
|
|
|
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new Runnable() {
|
2016-06-25 17:56:59 +02:00
|
|
|
@Override
|
2016-04-05 16:43:55 +02:00
|
|
|
public void run() {
|
|
|
|
if (!player.isOnline())
|
|
|
|
return;
|
|
|
|
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
|
|
|
|
if (jPlayer == null)
|
|
|
|
return;
|
2016-06-15 12:27:43 +02:00
|
|
|
if (player.hasPermission("jobs.*"))
|
|
|
|
return;
|
2016-06-09 17:35:24 +02:00
|
|
|
int confMaxJobs = Jobs.getGCManager().getMaxJobs();
|
2016-04-05 16:43:55 +02:00
|
|
|
for (Job one : Jobs.getJobs()) {
|
2016-06-09 17:35:24 +02:00
|
|
|
if (one.getMaxSlots() != null && Jobs.getUsedSlots(one) >= one.getMaxSlots())
|
|
|
|
continue;
|
|
|
|
short PlayerMaxJobs = (short) jPlayer.getJobProgression().size();
|
2017-01-13 14:10:55 +01:00
|
|
|
if (confMaxJobs > 0 && PlayerMaxJobs >= confMaxJobs && !Jobs.getPlayerManager().getJobsLimit(jPlayer, PlayerMaxJobs))
|
2016-06-09 17:35:24 +02:00
|
|
|
break;
|
|
|
|
if (jPlayer.isInJob(one))
|
|
|
|
continue;
|
2016-06-15 12:27:43 +02:00
|
|
|
if (player.hasPermission("jobs.autojoin." + one.getName().toLowerCase()))
|
2016-04-05 16:43:55 +02:00
|
|
|
Jobs.getPlayerManager().joinJob(jPlayer, one);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}, Jobs.getGCManager().AutoJobJoinDelay * 20L);
|
|
|
|
}
|
2016-11-19 09:27:43 +01:00
|
|
|
|
|
|
|
public String getMobSpawnerMetadata() {
|
|
|
|
return mobSpawnerMetadata;
|
|
|
|
}
|
2015-08-21 15:10:08 +02:00
|
|
|
}
|