1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 14:05:25 +01:00

Documented some of mostly used methods

Closes #1065
This commit is contained in:
montlikadani 2021-02-02 23:04:46 +01:00
parent 865bcca5c0
commit c858b53340
13 changed files with 472 additions and 200 deletions

View File

@ -14,8 +14,8 @@ import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs;
public class VersionChecker {
private Jobs plugin;
private static int resource = 4216;
public VersionChecker(Jobs plugin) {
this.plugin = plugin;
@ -69,7 +69,7 @@ public class VersionChecker {
public String getNewVersion() {
try {
URLConnection con = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + resource).openConnection();
URLConnection con = new URL("https://api.spigotmc.org/legacy/update.php?resource=4216").openConnection();
String version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
if (version.length() <= 8)
return version;

View File

@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
@ -22,15 +23,15 @@ import com.gamingmesh.jobs.container.JobItems;
public class ItemBoostManager {
private static HashMap<String, JobItems> items = new HashMap<>();
private static HashMap<String, JobItems> legacy = new HashMap<>();
private static final Map<String, JobItems> ITEMS = new HashMap<>();
private static final Map<String, JobItems> LEGACY = new HashMap<>();
@SuppressWarnings("deprecation")
public static void load() {
ConfigReader cfg = new ConfigReader("boostedItems.yml");
items.clear();
legacy.clear();
ITEMS.clear();
LEGACY.clear();
// Converting from existing records in Jobs from old format which was located in jobConfig.yml file
boolean save = false;
@ -151,10 +152,8 @@ public class ItemBoostManager {
b.add(oneC, cfg.get(one + "." + oneC.toString().toLowerCase() + "Boost", 1D) - 1);
}
List<String> jobsS = cfg.get(one + ".jobs", Arrays.asList(""));
List<Job> jobs = new ArrayList<>();
for (String oneJ : jobsS) {
for (String oneJ : cfg.get(one + ".jobs", Arrays.asList(""))) {
Job job = Jobs.getJob(oneJ);
if (job == null && !oneJ.equalsIgnoreCase("all")) {
Jobs.getPluginLogger().warning("Cant determine job by " + oneJ + " name for " + one + " boosted item!");
@ -179,58 +178,76 @@ public class ItemBoostManager {
item.setUntilLevel(cfg.get(one + ".levelUntil", 1000));
for (Job oneJ : jobs) {
if (oneJ == null)
continue;
oneJ.getItemBonus().put(one.toLowerCase(), item);
}
// Lets add into legacy map
if (one.contains("_")) {
item.setLegacyKey((one.split("_")[1]).toLowerCase());
legacy.put(item.getLegacyKey(), item);
LEGACY.put(item.getLegacyKey(), item);
}
items.put(one.toLowerCase(), item);
ITEMS.put(one.toLowerCase(), item);
}
cfg.save();
}
/**
* Returns a copy list of {@link JobItems} from the specific job.
*
* @param job {@link Job}
* @return List of {@link JobItems}
*/
public static List<JobItems> getItemsByJob(Job job) {
List<JobItems> ls = new ArrayList<>();
for (JobItems one : items.values()) {
for (JobItems one : ITEMS.values()) {
if (one.getJobs().contains(job))
ls.add(one);
}
return ls;
}
public static HashMap<String, JobItems> getItemsMapByJob(Job job) {
HashMap<String, JobItems> i = new HashMap<>();
for (Entry<String, JobItems> one : items.entrySet()) {
/** Returns a map of items from the specific job.
*
* @param job {@link Job}
* @return map of items
*/
public static Map<String, JobItems> getItemsMapByJob(Job job) {
Map<String, JobItems> i = new HashMap<>();
for (Entry<String, JobItems> one : ITEMS.entrySet()) {
if (one.getValue().getJobs().contains(job))
i.put(one.getKey(), one.getValue());
}
return i;
}
/**
* Returns {@link JobItems} from specific key.
*
* @param key items or legacy key name
* @return {@link JobItems}
*/
public static JobItems getItemByKey(String key) {
JobItems item = items.get(key.toLowerCase());
if (item != null) {
return item;
}
return legacy.get(key.toLowerCase());
key = key.toLowerCase();
JobItems item = ITEMS.get(key);
return item != null ? item : LEGACY.get(key);
}
public static HashMap<String, JobItems> getItems() {
return items;
/**
* @return the current cached map of items.
*/
public static Map<String, JobItems> getItems() {
return ITEMS;
}
public static HashMap<String, JobItems> getLegacyItems() {
return legacy;
}
public static void setItems(HashMap<String, JobItems> items) {
ItemBoostManager.items = items;
/**
* @return the current cached map of legacy items.
*/
public static Map<String, JobItems> getLegacyItems() {
return LEGACY;
}
}

View File

@ -99,7 +99,7 @@ public class Jobs extends JavaPlugin {
private static List<Job> jobs;
private static Job noneJob;
private static WeakHashMap<Job, Integer> usedSlots = new WeakHashMap<>();
private static HashMap<Integer, Job> jobsIds = new HashMap<>();
private static Map<Integer, Job> jobsIds = new HashMap<>();
private static BufferedEconomy economy;
private static PermissionHandler permissionHandler;
@ -118,10 +118,26 @@ public class Jobs extends JavaPlugin {
private static PointsData pointsDatabase;
/**
* Returns the block owner ship for specific {@link CMIMaterial} type.
*
* @param type {@link CMIMaterial}
* @see #getBlockOwnerShip(CMIMaterial, boolean)
* @return {@link BlockOwnerShip}, otherwise {@link Optional#empty()}
*/
public Optional<BlockOwnerShip> getBlockOwnerShip(CMIMaterial type) {
return getBlockOwnerShip(type, true);
}
/**
* Returns the block owner ship for specific {@link CMIMaterial} type.
* If the addNew parameter is enabled, it will cache a new owner ship for specific
* {@link CMIMaterial} type.
*
* @param type {@link CMIMaterial}
* @param addNew whenever to add a new owner ship
* @return {@link BlockOwnerShip}, otherwise {@link Optional#empty()}
*/
public Optional<BlockOwnerShip> getBlockOwnerShip(CMIMaterial type, boolean addNew) {
BlockOwnerShip b = null;
for (BlockOwnerShip ship : blockOwnerShips) {
@ -139,6 +155,12 @@ public class Jobs extends JavaPlugin {
return Optional.ofNullable(b);
}
/**
* Returns the block owner ship for specific {@link BlockTypes} type.
*
* @param type {@link BlockTypes}
* @return {@link BlockOwnerShip}, otherwise {@link Optional#empty()}
*/
public Optional<BlockOwnerShip> getBlockOwnerShip(BlockTypes type) {
for (BlockOwnerShip ship : blockOwnerShips) {
if (ship.getType() == type) {
@ -149,6 +171,9 @@ public class Jobs extends JavaPlugin {
return Optional.empty();
}
/**
* @return a set of block owner ships.
*/
public Set<BlockOwnerShip> getBlockOwnerShips() {
return blockOwnerShips;
}
@ -241,8 +266,7 @@ public class Jobs extends JavaPlugin {
}
/**
* Returns player manager
* @return the player manager
* @return {@link PlayerManager}
*/
public static PlayerManager getPlayerManager() {
if (pManager == null)
@ -266,7 +290,20 @@ public class Jobs extends JavaPlugin {
return raManager;
}
/**
* @deprecated miss named
* @see #getTitleManager()
* @return
*/
@Deprecated
public static TitleManager gettitleManager() {
return getTitleManager();
}
/**
* @return {@link TitleManager}
*/
public static TitleManager getTitleManager() {
if (titleManager == null) {
titleManager = new TitleManager();
}
@ -440,6 +477,12 @@ public class Jobs extends JavaPlugin {
return null;
}
/**
* Returns a job by identifier.
*
* @param id the id of job
* @return {@link Job}
*/
public static Job getJob(int id) {
return jobsIds.get(id);
}
@ -448,7 +491,10 @@ public class Jobs extends JavaPlugin {
return placeholderAPIEnabled;
}
public static HashMap<Integer, Job> getJobsIds() {
/**
* @return the cached job id map.
*/
public static Map<Integer, Job> getJobsIds() {
return jobsIds;
}
@ -493,9 +539,6 @@ public class Jobs extends JavaPlugin {
});
}
/**
* Executes close connections
*/
public static void convertDatabase() {
try {
List<Convert> archivelist = dao.convertDatabase();
@ -524,7 +567,8 @@ public class Jobs extends JavaPlugin {
}
/**
* Checks if player have the given {@link ActionType} in jobs.
* Checks if the given {@link JobsPlayer} have the given {@link ActionType} in one of jobs.
*
* @param jPlayer {@link JobsPlayer}
* @param type {@link ActionType}
* @return true if the player have the given action
@ -708,9 +752,6 @@ public class Jobs extends JavaPlugin {
reload(false);
}
/**
* Reloads all data
*/
public static void reload(boolean startup) {
// unregister all registered listeners by this plugin and register again
if (!startup) {
@ -839,29 +880,76 @@ public class Jobs extends JavaPlugin {
}
/**
* Performed an action
* Perform an action for the given {@link JobsPlayer} with the given action info.
*
* Give correct experience and income
* @param jPlayer - the player
* @param info - the action
* @param jPlayer {@link JobsPlayer}
* @param info {@link ActionInfo}
* @see #action(JobsPlayer, ActionInfo, Block, Entity, LivingEntity)
*/
public static void action(JobsPlayer jPlayer, ActionInfo info) {
action(jPlayer, info, null, null, null);
}
/**
* Perform an action for the given {@link JobsPlayer} with the given action info and block.
*
* @param jPlayer {@link JobsPlayer}
* @param info {@link ActionInfo}
* @param block {@link Block}
* @see #action(JobsPlayer, ActionInfo, Block, Entity, LivingEntity)
*/
public static void action(JobsPlayer jPlayer, ActionInfo info, Block block) {
action(jPlayer, info, block, null, null);
}
/**
* Perform an action for the given {@link JobsPlayer} with the given action info and entity.
*
* @param jPlayer {@link JobsPlayer}
* @param info {@link ActionInfo}
* @param ent {@link Entity}
* @see #action(JobsPlayer, ActionInfo, Block, Entity, LivingEntity)
*/
public static void action(JobsPlayer jPlayer, ActionInfo info, Entity ent) {
action(jPlayer, info, null, ent, null);
}
/**
* Perform an action for the given {@link JobsPlayer} with the given action info,
* entity and living entity.
*
* @param jPlayer {@link JobsPlayer}
* @param info {@link ActionInfo}
* @param ent {@link Entity}
* @param victim {@link LivingEntity}
* @see #action(JobsPlayer, ActionInfo, Block, Entity, LivingEntity)
*/
public static void action(JobsPlayer jPlayer, ActionInfo info, Entity ent, LivingEntity victim) {
action(jPlayer, info, null, ent, victim);
}
/**
* Perform an action for the given {@link JobsPlayer} with the parameters.
* <p>
* The process:
* <p>
* If the player does not have any job progression cached into memory, the player
* only retrieve the "noneJob" by default. This means that there will be no any
* extra income calculations and the player does no get the full income from jobs,
* but the half of it.<br>
* In other cases if player have at least 1 job cached, they will get the full income
* with the extra calculated multiplications including bonuses and limits.
* <p>
*
* <b>This usually not be called in your code, to avoid misbehaviour working ability.</b>
*
* @param jPlayer {@link JobsPlayer}
* @param info {@link ActionInfo}
* @param ent {@link Entity}
* @param victim {@link LivingEntity}
* @param block {@link Block}
* @see #action(JobsPlayer, ActionInfo, Block, Entity, LivingEntity)
*/
public static void action(JobsPlayer jPlayer, ActionInfo info, Block block, Entity ent, LivingEntity victim) {
if (jPlayer == null)
return;

View File

@ -241,9 +241,6 @@ public class PermissionHandler {
}
}
/**
* Check World permissions
*/
public boolean hasWorldPermission(Player player) {
return hasWorldPermission(player, player.getWorld().getName());
}

View File

@ -116,14 +116,42 @@ public class PermissionManager {
return mine;
}
/**
* Returns a maximum permission value for example "jobs.max.5".
*
* @param jPlayer {@link JobsPlayer}
* @param perm the permission to search
* @see #getMaxPermission(JobsPlayer, String, boolean, boolean)
* @return the max value
*/
public Double getMaxPermission(JobsPlayer jPlayer, String perm) {
return getMaxPermission(jPlayer, perm, false, false);
}
/**
* Returns a maximum permission value for example "jobs.max.5" with force condition.
*
* @param jPlayer {@link JobsPlayer}
* @param perm the permission to search
* @param force to force cache player permissions which includes jobs
* @see #getMaxPermission(JobsPlayer, String, boolean, boolean)
* @return the max value
*/
public Double getMaxPermission(JobsPlayer jPlayer, String perm, boolean force) {
return getMaxPermission(jPlayer, perm, force, false);
}
/**
* Returns a maximum permission value for example "jobs.max.5".
* If the force condition is true it will caches all the jobs
* permissions into memory and tries to find a max permission value.
*
* @param jPlayer {@link JobsPlayer}
* @param perm the permission to search
* @param force whenever to force permission cache for specific player
* @param cumulative if true it sums the maximum values of fount permissions
* @return the max value
*/
public Double getMaxPermission(JobsPlayer jPlayer, String perm, boolean force, boolean cumulative) {
if (jPlayer == null || jPlayer.getPlayer() == null)
return 0D;
@ -150,8 +178,8 @@ public class PermissionManager {
amount += temp;
else if (temp > amount)
amount = temp;
} catch (NumberFormatException ignored) {
ignored.printStackTrace();
} catch (NumberFormatException ex) {
Jobs.getPluginLogger().log(java.util.logging.Level.WARNING, ex.getLocalizedMessage());
}
}

View File

@ -553,7 +553,7 @@ public class Placeholder {
case user_title_$1:
if (j == null)
return "";
Title title = Jobs.gettitleManager().getTitle(j.getLevel(), j.getJob().getName());
Title title = Jobs.getTitleManager().getTitle(j.getLevel(), j.getJob().getName());
return title == null ? "" : title.getChatColor() + title.getName();
case user_archived_jobs_level_$1:
if (job == null) {

View File

@ -81,7 +81,7 @@ public class PlayerManager {
private final HashMap<String, PlayerInfo> PlayerNameMap = new HashMap<>();
/**
* @deprecated Use {@link Jobs#getPointsData} instead
* @deprecated Use {@link JobsPlayer#getPointsData} instead
* @return {@link com.gamingmesh.jobs.economy.PointsData}
*/
@Deprecated
@ -89,10 +89,14 @@ public class PlayerManager {
return Jobs.getPointsData();
}
/**
* @return the cached mob spawner meta name
*/
public String getMobSpawnerMetadata() {
return mobSpawnerMetadata;
}
@Deprecated
public int getMapSize() {
return PlayerUUIDMap.size();
}
@ -130,6 +134,12 @@ public class PlayerManager {
playersUUID.put(jPlayer.getUniqueId(), jPlayer);
}
/**
* Removes the given player from the memory.
*
* @param player {@link Player}
* @return {@link JobsPlayer}
*/
public JobsPlayer removePlayer(Player player) {
if (player == null)
return null;
@ -152,31 +162,69 @@ public class PlayerManager {
return PlayerUUIDMap;
}
/**
* Returns the player identifier by its name. This will returns
* -1 if the player is not cached.
*
* @param name the player name
* @return the identifier
*/
public int getPlayerId(String name) {
PlayerInfo info = getPlayerInfo(name);
return info == null ? -1 : info.getID();
}
/**
* Returns the player identifier by its uuid. This will returns
* -1 if the player is not cached.
*
* @param uuid player {@link UUID}
* @return the identifier
*/
public int getPlayerId(UUID uuid) {
PlayerInfo info = PlayerUUIDMap.get(uuid);
return info == null ? -1 : info.getID();
}
/**
* Returns the {@link PlayerInfo} for the given name. This will returns
* null if the player is not cached.
*
* @param name the player name
* @return {@link PlayerInfo}
*/
public PlayerInfo getPlayerInfo(String name) {
return PlayerNameMap.get(name.toLowerCase());
}
/**
* Returns the {@link PlayerInfo} for the given identifier. This will returns
* null if the player is not cached.
*
* @param id the player id
* @return {@link PlayerInfo}
*/
public PlayerInfo getPlayerInfo(int id) {
return PlayerIDMap.get(id);
}
/**
* Returns the {@link PlayerInfo} for the given uuid. This will returns
* null if the player is not cached.
*
* @param uuid player {@link UUID}
* @return {@link PlayerInfo}
*/
public PlayerInfo getPlayerInfo(UUID uuid) {
return PlayerUUIDMap.get(uuid);
}
/**
* Handles join of new player
* @param playername
* Handles join of new player synchronously. This can be called
* within an asynchronous operation in order to load the player
* from database if it is not cached into memory.
*
* @param player {@link Player}
*/
public void playerJoin(Player player) {
@ -204,7 +252,7 @@ public class PlayerManager {
jPlayer.setQuestProgressionFromString(info.getQuestProgression());
}
jPlayer.loadLogFromDao();
Jobs.getJobsDAO().loadLog(jPlayer);
}
addPlayer(jPlayer);
@ -216,7 +264,8 @@ public class PlayerManager {
/**
* Handles player quit
* @param playername
*
* @param player {@link Player}
*/
public void playerQuit(Player player) {
JobsPlayer jPlayer = getJobsPlayer(player);
@ -230,15 +279,18 @@ public class PlayerManager {
}
}
/**
* Removes all jobs player miscellaneous settings like boss bar.
*/
public void removePlayerAdditions() {
for (JobsPlayer jPlayer : players.values()) {
jPlayer.clearBossMaps();
jPlayer.clearUpdateBossBarFor();
jPlayer.getUpdateBossBarFor().clear();
}
}
/**
* Save all the information of all of the players in the game
* Save all the information of all of the players
*/
public void saveAll() {
/*
@ -264,7 +316,9 @@ public class PlayerManager {
}
/**
* Save all the information of all of the players
* Converts the cache of all the players into a new one.
*
* @param resetID true to not insert into database and reset the players id
*/
public void convertChacheOfPlayers(boolean resetID) {
int y = 0, i = 0, total = playersUUIDCache.size();
@ -296,25 +350,40 @@ public class PlayerManager {
}
/**
* 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
* Gets the player job info for specific player if exist.
* <p>
* This can return null sometimes if the given player
* is not cached into memory.
*
* @param player {@link Player}
* @return {@link JobsPlayer} the player job info of the player
*/
public JobsPlayer getJobsPlayer(Player player) {
return getJobsPlayer(player.getUniqueId());
}
/**
* Gets the player job info for specific player uuid if exist.
* <p>
* This can return null sometimes if the given player
* is not cached into memory.
*
* @param player the player uuid
* @return {@link JobsPlayer} the player job info of the player
*/
public JobsPlayer getJobsPlayer(UUID uuid) {
JobsPlayer jPlayer = playersUUID.get(uuid);
if (jPlayer != null)
return jPlayer;
return playersUUIDCache.get(uuid);
return jPlayer != null ? jPlayer : playersUUIDCache.get(uuid);
}
/**
* Get the player job info for specific player
* Get the player job info for specific player name if exist.
* <p>
* This can return null sometimes if the given player
* is not cached into memory.
*
* @param player name - the player name who's job you're getting
* @return the player job info of the player
* @return {@link JobsPlayer} the player job info of the player
*/
public JobsPlayer getJobsPlayer(String playerName) {
JobsPlayer jPlayer = players.get(playerName.toLowerCase());
@ -322,10 +391,15 @@ public class PlayerManager {
}
/**
* Get the player job info for specific player
* @param archivedJobs
* @param player - the player who's job you're getting
* @return the player job info of the player
* Gets the player job offline data for specific {@link PlayerInfo}
*
* @param info {@link PlayerInfo}
* @param jobs the list of jobs data from database
* @param points {@link PlayerPoints}
* @param logs the map of logs
* @param archivedJobs {@link ArchivedJobs}
* @param limits {@link PaymentData}
* @return {@link JobsPlayer}
*/
public JobsPlayer getJobsPlayerOffline(PlayerInfo info, List<JobsDAOData> jobs, PlayerPoints points,
HashMap<String, Log> logs, ArchivedJobs archivedJobs, PaymentData limits) {
@ -375,9 +449,10 @@ public class PlayerManager {
}
/**
* Causes player to join their job
* @param jPlayer
* @param job
* Causes player to join to the given job.
*
* @param jPlayer {@link JobsPlayer}
* @param job {@link Job}
*/
public void joinJob(JobsPlayer jPlayer, Job job) {
if (jPlayer.isInJob(job))
@ -406,9 +481,10 @@ public class PlayerManager {
}
/**
* Causes player to leave their job
* @param jPlayer
* @param job
* Causes player to leave the given job.
*
* @param jPlayer {@link JobsPlayer}
* @param job {@link Job}
*/
public boolean leaveJob(JobsPlayer jPlayer, Job job) {
if (!jPlayer.isInJob(job))
@ -439,7 +515,8 @@ public class PlayerManager {
/**
* Causes player to leave all their jobs
* @param jPlayer
*
* @param jPlayer {@link JobsPlayer}
*/
public void leaveAllJobs(JobsPlayer jPlayer) {
List<JobProgression> jobs = new ArrayList<>();
@ -450,8 +527,9 @@ public class PlayerManager {
}
/**
* Transfers player job
* @param jPlayer
* Transfers player job to a new one
*
* @param jPlayer {@link JobsPlayer}
* @param oldjob - the old job
* @param newjob - the new job
*/
@ -471,7 +549,8 @@ public class PlayerManager {
/**
* Promotes player in their job
* @param jPlayer
*
* @param jPlayer {@link JobsPlayer}
* @param job - the job
* @param levels - number of levels to promote
*/
@ -484,7 +563,8 @@ public class PlayerManager {
/**
* Demote player in their job
* @param jPlayer
*
* @param jPlayer {@link JobsPlayer}
* @param job - the job
* @param levels - number of levels to demote
*/
@ -497,7 +577,8 @@ public class PlayerManager {
/**
* Adds experience to the player
* @param jPlayer
*
* @param jPlayer {@link JobsPlayer}
* @param job - the job
* @param experience - experience gained
*/
@ -516,9 +597,10 @@ public class PlayerManager {
}
/**
* Removes experience to the player
* @param jPlayer
* @param job - the job
* Removes experience from the player
*
* @param jPlayer {@link JobsPlayer}
* @param job {@link Job}
* @param experience - experience gained
*/
public void removeExperience(JobsPlayer jPlayer, Job job, double experience) {
@ -534,8 +616,9 @@ public class PlayerManager {
/**
* Broadcasts level up about a player
* @param jPlayer
* @param job
*
* @param jPlayer {@link JobsPlayer}
* @param job {@link Job}
* @param oldLevel
*/
public void performLevelUp(JobsPlayer jPlayer, Job job, int oldLevel) {
@ -575,8 +658,8 @@ public class PlayerManager {
jPlayer,
job.getName(),
prog.getLevel(),
Jobs.gettitleManager().getTitle(oldLevel, prog.getJob().getName()),
Jobs.gettitleManager().getTitle(prog.getLevel(), prog.getJob().getName()),
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,
@ -651,25 +734,31 @@ public class PlayerManager {
String colorString = colorStrings.get(s);
String[] sSplit = comma.split(colorString);
if (sSplit.length < 3) {
Jobs.consoleMsg("[Jobs] &cInvalid color " + colorString + "! Colors must be 3 comma-separated numbers ranging from 0 to 255.");
continue;
}
int[] colorRGB = new int[3];
for (int i = 0; i < 3; i++) {
String colorInt = sSplit[i];
try {
colorRGB[i] = Integer.parseInt(colorInt);
colorRGB[i] = Integer.parseInt(sSplit[i]);
} catch (NumberFormatException e) {
Jobs.consoleMsg("[Jobs] &cInvalid color component " + colorInt + ", it must be an integer.");
}
}
try {
colors[s] = Color.fromRGB(colorRGB[0], colorRGB[1], colorRGB[2]);
} catch (IllegalArgumentException e) {
Jobs.consoleMsg("[Jobs] &cFailed to add color! " + e);
int r = colorRGB[0], g = colorRGB[1], b = colorRGB[2];
if (r > 255 || r < 0) {
r = 1;
}
if (g > 255 || g < 0) {
g = 5;
}
if (b > 255 || b < 0) {
b = 3;
}
colors[s] = Color.fromRGB(r, g, b);
}
fm.addEffect(FireworkEffect.builder()
@ -688,11 +777,8 @@ public class PlayerManager {
}, Jobs.getGCManager().ShootTime);
}
String message;
if (Jobs.getGCManager().isBroadcastingLevelups())
message = Jobs.getLanguage().getMessage("message.levelup.broadcast");
else
message = Jobs.getLanguage().getMessage("message.levelup.nobroadcast");
String message = Jobs.getLanguage().getMessage("message.levelup." + (Jobs.getGCManager().isBroadcastingLevelups()
? "broadcast" : "nobroadcast"));
message = message.replace("%jobname%", job.getNameWithColor());
@ -728,10 +814,8 @@ public class PlayerManager {
} catch (Exception e) {
}
// user would skill up
if (Jobs.getGCManager().isBroadcastingSkillups())
message = Jobs.getLanguage().getMessage("message.skillup.broadcast");
else
message = Jobs.getLanguage().getMessage("message.skillup.nobroadcast");
message = Jobs.getLanguage().getMessage("message.skillup." + (Jobs.getGCManager().isBroadcastingSkillups()
? "broadcast" : "nobroadcast"));
message = message.replace("%playername%", player != null ? player.getDisplayName() : jPlayer.getName());
message = message.replace("%titlename%", levelUpEvent.getNewTitle()
@ -765,8 +849,9 @@ public class PlayerManager {
/**
* Performs command on level up
* @param jPlayer
* @param job
*
* @param jPlayer {@link JobsPlayer}
* @param job {@link Job}
* @param oldLevel
*/
public void performCommandOnLevelUp(JobsPlayer jPlayer, Job job, int oldLevel) {
@ -792,6 +877,7 @@ public class PlayerManager {
/**
* Checks whenever the given jobs player is under the max allowed jobs.
*
* @param player {@link JobsPlayer}
* @param currentCount the current jobs size
* @return true if the player is under the given jobs size
@ -802,6 +888,7 @@ public class PlayerManager {
/**
* Gets the maximum jobs from player.
*
* @param jPlayer {@link JobsPlayer}
* @return the maximum allowed jobs
*/
@ -835,7 +922,7 @@ public class PlayerManager {
}
/**
* Perform reload
* Perform reload for all jobs players.
*/
public void reload() {
for (JobsPlayer jPlayer : players.values()) {
@ -881,51 +968,44 @@ public class PlayerManager {
if (player == null || prog == null)
return data;
ItemStack iih;
List<JobItems> jitems = new ArrayList<>();
ItemStack iih;
List<JobItems> jitems = new ArrayList<>();
// Check mainhand slot
if (Jobs.getGCManager().boostedItemsInMainHand) {
iih = Jobs.getNms().getItemInMainHand(player);
// Check mainhand slot
if (Jobs.getGCManager().boostedItemsInMainHand && (iih = Jobs.getNms().getItemInMainHand(player)) != null) {
jitems.add(getJobsItemByNbt(iih));
}
if (iih != null) {
jitems.add(getJobsItemByNbt(iih));
}
}
// Check offhand slot
if (Version.isCurrentEqualOrHigher(Version.v1_9_R1) && Jobs.getGCManager().boostedItemsInOffHand
&& (iih = CMIReflections.getItemInOffHand(player)) != null) {
jitems.add(getJobsItemByNbt(iih));
}
// Check offhand slot
if (Version.isCurrentEqualOrHigher(Version.v1_9_R1) && Jobs.getGCManager().boostedItemsInOffHand) {
iih = CMIReflections.getItemInOffHand(player);
// Check armor slots
if (Jobs.getGCManager().boostedArmorItems) {
for (ItemStack oneArmor : player.getInventory().getArmorContents()) {
if (oneArmor != null && oneArmor.getType() != org.bukkit.Material.AIR) {
jitems.add(getJobsItemByNbt(oneArmor));
}
}
}
if (iih != null) {
jitems.add(getJobsItemByNbt(iih));
}
}
for (JobItems jitem : jitems) {
if (jitem != null && jitem.getJobs().contains(prog)) {
data.add(jitem.getBoost(getJobsPlayer(player).getJobProgression(prog)));
}
}
// Check armor slots
if (Jobs.getGCManager().boostedArmorItems) {
for (ItemStack oneArmor : player.getInventory().getArmorContents()) {
if (oneArmor != null && oneArmor.getType() != org.bukkit.Material.AIR) {
jitems.add(getJobsItemByNbt(oneArmor));
}
}
}
for (JobItems jitem : jitems) {
if (jitem != null && jitem.getJobs().contains(prog)) {
data.add(jitem.getBoost(getJobsPlayer(player).getJobProgression(prog)));
}
}
return data;
return data;
}
private final String JobsItemBoost = "JobsItemBoost";
public boolean containsItemBoostByNBT(ItemStack item) {
return item != null && Jobs.getReflections().hasNbtString(item, JobsItemBoost);
}
private final String JobsItemBoost = "JobsItemBoost";
public JobItems getJobsItemByNbt(ItemStack item) {
if (item == null)
return null;

View File

@ -380,7 +380,7 @@ public class JobsCommands implements CommandExecutor {
String path = "command.stats.output." + (isMaxLevelReached ? "max-level"
: "message");
Title title = Jobs.gettitleManager().getTitle(jobProg.getLevel(), jobProg.getJob().getName());
Title title = Jobs.getTitleManager().getTitle(jobProg.getLevel(), jobProg.getJob().getName());
String message = Jobs.getLanguage().getMessage(path,
"%joblevel%", jobProg.getLevel(),
"%jobname%", jobProg.getJob().getNameWithColor(),

View File

@ -33,7 +33,7 @@ public class BossBarManager {
ShowJobProgression(player, oneJob, oneJob.getLastExperience());
}
}
player.clearUpdateBossBarFor();
player.getUpdateBossBarFor().clear();
}
public void ShowJobProgression(final JobsPlayer player, final JobProgression jobProg, double expGain) {

View File

@ -264,7 +264,7 @@ public class GeneralConfigManager {
// Load locale
Jobs.getLanguageManager().load();
// title settings
Jobs.gettitleManager().load();
Jobs.getTitleManager().load();
// restricted areas
Jobs.getRestrictedAreaManager().load();
// restricted blocks

View File

@ -22,18 +22,12 @@ import java.util.ArrayList;
import java.util.List;
public class JobCommands {
private String node;
private final List<String> commands = new ArrayList<>();
private int levelFrom;
private int levelUntil;
@Deprecated
public JobCommands(String node, String command, int levelFrom, int levelUntil) {
this.node = node;
this.commands.add(command);
this.levelFrom = levelFrom;
this.levelUntil = levelUntil;
}
private final List<String> commands = new ArrayList<>();
public JobCommands(String node, List<String> commands, int levelFrom, int levelUntil) {
this.node = node;
@ -46,11 +40,6 @@ public class JobCommands {
return node;
}
@Deprecated
public String getCommand() {
return commands.isEmpty() ? "" : commands.get(0);
}
public List<String> getCommands() {
return commands;
}

View File

@ -57,9 +57,8 @@ public class JobConditions {
String clean = one.toLowerCase().substring("p:".length());
if (clean.contains("-")) {
String perm = clean.split("-")[0];
boolean n = clean.split("-")[1].equalsIgnoreCase("true");
performPerm.put(perm, n);
String[] split = clean.split("-");
performPerm.put(split[0], split[1].equalsIgnoreCase("true"));
} else {
performPerm.put(clean, true);
}

View File

@ -93,38 +93,76 @@ public class JobsPlayer {
this.userName = userName == null ? "Unknown" : userName;
}
/**
* @return the cached or new instance of {@link PlayerPoints}
*/
public PlayerPoints getPointsData() {
if (pointsData == null)
pointsData = new PlayerPoints();
return pointsData;
}
public void addPoints(Double points) {
/**
* Adds points to this player.
*
* @param points the amount of points
*/
public void addPoints(double points) {
getPointsData().addPoints(points);
}
public void takePoints(Double points) {
/**
* Takes points from this player.
*
* @param points the amount of points
*/
public void takePoints(double points) {
getPointsData().takePoints(points);
}
public void setPoints(Double points) {
/**
* Sets points for this player.
*
* @param points the amount of points
*/
public void setPoints(double points) {
getPointsData().setPoints(points);
}
/**
* Sets points for this player from the given {@link PlayerPoints}
*
* @param points {@link PlayerPoints}
*/
public void setPoints(PlayerPoints points) {
getPointsData().setPoints(points.getCurrentPoints());
getPointsData().setTotalPoints(points.getTotalPoints());
getPointsData().setDbId(points.getDbId());
}
/**
* Checks whenever have enough points for the given one.
*
* @param points amount of points
* @return true if yes
*/
public boolean havePoints(double points) {
return getPointsData().getCurrentPoints() >= points;
}
/**
* @return the cached instance of {@link ArchivedJobs}
*/
public ArchivedJobs getArchivedJobs() {
return archivedJobs;
}
/**
* Returns the given archived job progression.
*
* @param job {@link Job}
* @return the given archived job progression
*/
public JobProgression getArchivedJobProgression(Job job) {
return archivedJobs.getArchivedJobProgression(job);
}
@ -133,6 +171,9 @@ public class JobsPlayer {
this.archivedJobs = archivedJob;
}
/**
* @return the total level of all jobs for this player
*/
public int getTotalLevels() {
int i = 0;
for (JobProgression job : progression) {
@ -145,6 +186,9 @@ public class JobsPlayer {
this.paymentLimits = paymentLimits;
}
/**
* @return the limit of {@link PaymentData}
*/
public PaymentData getPaymentLimit() {
if (paymentLimits == null)
paymentLimits = Jobs.getJobsDAO().getPlayersLimits(this);
@ -154,6 +198,13 @@ public class JobsPlayer {
return paymentLimits;
}
/**
* Checks whenever this player is under limit for specific {@link CurrencyType}
*
* @param type {@link CurrencyType}
* @param amount amount of points
* @return true if it is under
*/
public boolean isUnderLimit(CurrencyType type, Double amount) {
Player player = getPlayer();
if (player == null || amount == 0)
@ -192,23 +243,30 @@ public class JobsPlayer {
return getPaymentLimit().percentOverLimit(type, value == null ? 0 : value);
}
/**
* Attempt to load log for this player.
*
* @deprecated use {@link JobsDAO#loadLog(JobsPlayer)} instead
*/
@Deprecated
public void loadLogFromDao() {
Jobs.getJobsDAO().loadLog(this);
}
public synchronized List<String> getUpdateBossBarFor() {
public List<String> getUpdateBossBarFor() {
return updateBossBarFor;
}
public synchronized void clearUpdateBossBarFor() {
@Deprecated
public void clearUpdateBossBarFor() {
updateBossBarFor.clear();
}
public synchronized List<BossBarInfo> getBossBarInfo() {
public List<BossBarInfo> getBossBarInfo() {
return barMap;
}
public synchronized void hideBossBars() {
public void hideBossBars() {
for (BossBarInfo one : barMap) {
one.getBar().setVisible(false);
}
@ -231,21 +289,32 @@ public class JobsPlayer {
}
/**
* Get the player
* @return the player
* @return {@link Player} or null if not exist
*/
public Player getPlayer() {
return playerUUID != null ? Bukkit.getPlayer(playerUUID) : null;
}
/**
* Get the Boost
* @return the Boost
* Attempts to get the boost from specific job and {@link CurrencyType}
*
* @param JobName
* @param type {@link CurrencyType}
* @see #getBoost(String, CurrencyType, boolean)
* @return amount of boost
*/
public double getBoost(String JobName, CurrencyType type) {
return getBoost(JobName, type, false);
}
/**
* Attempts to get the boost from specific job and {@link CurrencyType}
*
* @param JobName
* @param type {@link CurrencyType}
* @param force whenever to retrieve as soon as possible without time
* @return amount of boost
*/
public double getBoost(String JobName, CurrencyType type, boolean force) {
double Boost = 0D;
@ -316,7 +385,7 @@ public class JobsPlayer {
}
/**
* Reloads max experience for this job.
* Reloads max experience for all jobs for this player.
*/
public void reloadMaxExperience() {
progression.forEach(JobProgression::reloadMaxExperience);
@ -353,16 +422,17 @@ public class JobsPlayer {
}
/**
* Get the list of job progressions
* @return the list of job progressions
* @return an unmodifiable list of job progressions
*/
public List<JobProgression> getJobProgression() {
return Collections.unmodifiableList(progression);
}
/**
* Get the job progression with the certain job
* @return the job progression
* Get the job progression from the certain job
*
* @param job {@link Job}
* @return the job progression or null if job not exists
*/
public JobProgression getJobProgression(Job job) {
for (JobProgression prog : progression) {
@ -382,8 +452,7 @@ public class JobsPlayer {
}
/**
* get the getName
* @return the getName
* @return the name of this player
*/
public String getName() {
Player player = Bukkit.getPlayer(getUniqueId());
@ -402,8 +471,7 @@ public class JobsPlayer {
}
/**
* get the playerUUID
* @return the playerUUID
* @return the {@link UUID} of this player
*/
public UUID getUniqueId() {
return playerUUID;
@ -424,8 +492,9 @@ public class JobsPlayer {
}
/**
* Player joins a job
* @param job - the job joined
* Attempts to join this player to the given job.
*
* @param job where to join
*/
public boolean joinJob(Job job) {
// synchronized (saveLock) {
@ -519,8 +588,8 @@ public class JobsPlayer {
}
/**
* Leave all jobs
* @return on success
* Attempts to leave all jobs from this player.
* @return true if success
*/
public boolean leaveAllJobs() {
// synchronized (saveLock) {
@ -639,10 +708,10 @@ public class JobsPlayer {
}
/**
* 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
* Checks if the player is in the given job.
*
* @param job {@link Job}
* @return true if this player is in the given job, otherwise false
*/
public boolean isInJob(Job job) {
if (job == null)
@ -655,7 +724,7 @@ public class JobsPlayer {
}
/**
* Function that reloads your honorific
* Function that reloads this player honorific
*/
public void reloadHonorific() {
StringBuilder builder = new StringBuilder();
@ -669,7 +738,7 @@ public class JobsPlayer {
if (!builder.toString().isEmpty()) {
builder.append(Jobs.getGCManager().modifyChatSeparator);
}
Title title = Jobs.gettitleManager().getTitle(prog.getLevel(), prog.getJob().getName());
Title title = Jobs.getTitleManager().getTitle(prog.getLevel(), prog.getJob().getName());
processesChat(method, builder, prog.getLevel(), title, prog.getJob());
}
} else {
@ -755,7 +824,7 @@ public class JobsPlayer {
}
/**
* Performs player save
* Performs player save into database
*/
public void save() {
// synchronized (saveLock) {
@ -784,8 +853,7 @@ public class JobsPlayer {
}
/**
* Perform disconnect
*
* Perform disconnect for this player
*/
public void onDisconnect() {
// Jobs.getJobsDAO().savePoints(this);
@ -847,6 +915,12 @@ public class JobsPlayer {
this.lastPermissionUpdate = lastPermissionUpdate;
}
/**
* Checks whenever this player can get paid for the given action.
*
* @param info {@link ActionInfo}
* @return true if yes
*/
public boolean canGetPaid(ActionInfo info) {
List<JobProgression> progression = getJobProgression();
int numjobs = progression.size();
@ -868,11 +942,11 @@ public class JobsPlayer {
JobInfo jobinfo = prog.getJob().getJobInfo(info, level);
if (jobinfo == null)
continue;
Double income = jobinfo.getIncome(level, numjobs, maxJobsEquation);
Double pointAmount = jobinfo.getPoints(level, numjobs, maxJobsEquation);
Double expAmount = jobinfo.getExperience(level, numjobs, maxJobsEquation);
if (income != 0D || pointAmount != 0D || expAmount != 0D)
return true;
return income != 0D || pointAmount != 0D || expAmount != 0D;
}
return false;
@ -1176,7 +1250,7 @@ public class JobsPlayer {
this.doneQuests = doneQuests;
}
private Integer questSignUpdateShed = null;
private Integer questSignUpdateShed;
public void addDoneQuest(final Job job) {
this.doneQuests++;