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

Trying to follow naming conventions and some cleanup

This commit is contained in:
montlikadani 2021-03-10 19:14:52 +01:00
parent ab38a64fb4
commit fc5c5bfd08
48 changed files with 441 additions and 544 deletions

View File

@ -27,7 +27,7 @@ import com.gamingmesh.jobs.container.JobsPlayer;
public class GuiManager { public class GuiManager {
public void openJobsBrowseGUI(final Player player) { public void openJobsBrowseGUI(final Player player) {
ArrayList<Job> jobsList = new ArrayList<>(); List<Job> jobsList = new ArrayList<>();
for (Job job : Jobs.getJobs()) { for (Job job : Jobs.getJobs()) {
if (Jobs.getGCManager().getHideJobsWithoutPermission()) if (Jobs.getGCManager().getHideJobsWithoutPermission())
if (!Jobs.getCommandManager().hasJobPermission(player, job)) if (!Jobs.getCommandManager().hasJobPermission(player, job))
@ -102,9 +102,7 @@ public class GuiManager {
lore.add(Jobs.getLanguage().getMessage("command.browse.output.bonus", "[amount]", (int) (job.getBonus() * 100))); lore.add(Jobs.getLanguage().getMessage("command.browse.output.bonus", "[amount]", (int) (job.getBonus() * 100)));
if (job.getDescription().isEmpty()) { if (job.getDescription().isEmpty()) {
for (String desc : job.getFullDescription()) { lore.addAll(job.getFullDescription());
lore.add(desc);
}
} else } else
lore.addAll(Arrays.asList(job.getDescription().split("/n|\\n"))); lore.addAll(Arrays.asList(job.getDescription().split("/n|\\n")));
@ -209,7 +207,7 @@ public class GuiManager {
if (info == null || info.isEmpty()) if (info == null || info.isEmpty())
continue; continue;
ArrayList<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();
lore.add(Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase() + ".info")); lore.add(Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase() + ".info"));
int y = 1; int y = 1;

View File

@ -58,8 +58,7 @@ public class HookEconomyTask implements Runnable {
if (provider == null) if (provider == null)
return false; return false;
Economy economy = provider.getProvider(); Jobs.setEconomy(new VaultEconomy(provider.getProvider()));
Jobs.setEconomy(new VaultEconomy(economy));
Jobs.consoleMsg("&e[" + plugin.getDescription().getName() + "] Successfully linked with Vault."); Jobs.consoleMsg("&e[" + plugin.getDescription().getName() + "] Successfully linked with Vault.");
return true; return true;
} }

View File

@ -251,7 +251,7 @@ public class Jobs extends JavaPlugin {
public static ShopManager getShopManager() { public static ShopManager getShopManager() {
if (shopManager == null) { if (shopManager == null) {
shopManager = new ShopManager(); shopManager = new ShopManager(instance);
} }
return shopManager; return shopManager;
} }
@ -396,7 +396,7 @@ public class Jobs extends JavaPlugin {
*/ */
public static Language getLanguage() { public static Language getLanguage() {
if (lManager == null) if (lManager == null)
lManager = new Language(instance); lManager = new Language();
return lManager; return lManager;
} }

View File

@ -65,7 +65,7 @@ public class PermissionHandler {
if (hasWorldPermission(player)) { if (hasWorldPermission(player)) {
List<JobProgression> progression = jPlayer.getJobProgression(); List<JobProgression> progression = jPlayer.getJobProgression();
// calculate new permissions // calculate new permissions
HashMap<String, Boolean> permissions = new HashMap<>(); java.util.Map<String, Boolean> permissions = new HashMap<>();
if (progression.isEmpty()) { if (progression.isEmpty()) {
Job job = Jobs.getNoneJob(); Job job = Jobs.getNoneJob();
@ -85,17 +85,17 @@ public class PermissionHandler {
} }
} }
for (JobConditions Condition : job.getConditions()) { for (JobConditions condition : job.getConditions()) {
boolean ok = true; boolean ok = true;
for (String oneReq : Condition.getRequiredPerm()) { for (String oneReq : condition.getRequiredPerm()) {
if (!player.hasPermission(oneReq)) { if (!player.hasPermission(oneReq)) {
ok = false; ok = false;
break; break;
} }
} }
for (Entry<String, Integer> oneReq : Condition.getRequiredJobs().entrySet()) { for (Entry<String, Integer> oneReq : condition.getRequiredJobs().entrySet()) {
String jobName = oneReq.getKey(); String jobName = oneReq.getKey();
int jobLevel = oneReq.getValue(); int jobLevel = oneReq.getValue();
boolean found = false; boolean found = false;
@ -116,7 +116,7 @@ public class PermissionHandler {
if (!ok) if (!ok)
continue; continue;
for (Entry<String, Boolean> one : Condition.getPerformPerm().entrySet()) { for (Entry<String, Boolean> one : condition.getPerformPerm().entrySet()) {
String perm = one.getKey(); String perm = one.getKey();
boolean node = one.getValue(); boolean node = one.getValue();
if (node) if (node)
@ -151,17 +151,17 @@ public class PermissionHandler {
} }
} }
for (JobConditions Condition : prog.getJob().getConditions()) { for (JobConditions condition : prog.getJob().getConditions()) {
boolean ok = true; boolean ok = true;
for (String oneReq : Condition.getRequiredPerm()) { for (String oneReq : condition.getRequiredPerm()) {
if (!player.hasPermission(oneReq)) { if (!player.hasPermission(oneReq)) {
ok = false; ok = false;
break; break;
} }
} }
for (Entry<String, Integer> oneReq : Condition.getRequiredJobs().entrySet()) { for (Entry<String, Integer> oneReq : condition.getRequiredJobs().entrySet()) {
String jobName = oneReq.getKey(); String jobName = oneReq.getKey();
int jobLevel = oneReq.getValue(); int jobLevel = oneReq.getValue();
boolean found = false; boolean found = false;
@ -183,7 +183,7 @@ public class PermissionHandler {
if (!ok) if (!ok)
continue; continue;
for (Entry<String, Boolean> one : Condition.getPerformPerm().entrySet()) { for (Entry<String, Boolean> one : condition.getPerformPerm().entrySet()) {
String perm = one.getKey(); String perm = one.getKey();
boolean node = one.getValue(); boolean node = one.getValue();
if (node) if (node)

View File

@ -32,7 +32,7 @@ import com.gamingmesh.jobs.container.JobsPlayer;
public class PermissionManager { public class PermissionManager {
private final HashMap<String, Integer> permDelay = new HashMap<>(); private final Map<String, Integer> permDelay = new HashMap<>();
private enum prm { private enum prm {
// jobs_join_JOBNAME(remade("jobs.join.%JOBNAME%"), 60 * 1000), // jobs_join_JOBNAME(remade("jobs.join.%JOBNAME%"), 60 * 1000),
@ -106,8 +106,8 @@ public class PermissionManager {
} }
} }
private static HashMap<String, Boolean> getAll(Player player) { private static Map<String, Boolean> getAll(Player player) {
HashMap<String, Boolean> mine = new HashMap<>(); Map<String, Boolean> mine = new HashMap<>();
for (PermissionAttachmentInfo permission : player.getEffectivePermissions()) { for (PermissionAttachmentInfo permission : player.getEffectivePermissions()) {
if (permission.getPermission().startsWith("jobs.")) if (permission.getPermission().startsWith("jobs."))
mine.put(permission.getPermission(), permission.getValue()); mine.put(permission.getPermission(), permission.getValue());
@ -160,7 +160,7 @@ public class PermissionManager {
if (!perm.endsWith(".")) if (!perm.endsWith("."))
perm += "."; perm += ".";
HashMap<String, Boolean> permissions = jPlayer.getPermissionsCache(); Map<String, Boolean> permissions = jPlayer.getPermissionsCache();
if (force || permissions == null || getDelay(perm) + jPlayer.getLastPermissionUpdate() < System.currentTimeMillis()) { if (force || permissions == null || getDelay(perm) + jPlayer.getLastPermissionUpdate() < System.currentTimeMillis()) {
permissions = getAll(jPlayer.getPlayer()); permissions = getAll(jPlayer.getPlayer());
jPlayer.setPermissionsCache(permissions); jPlayer.setPermissionsCache(permissions);
@ -190,7 +190,7 @@ public class PermissionManager {
if (jPlayer == null || jPlayer.getPlayer() == null) if (jPlayer == null || jPlayer.getPlayer() == null)
return false; return false;
HashMap<String, Boolean> permissions = jPlayer.getPermissionsCache(); Map<String, Boolean> permissions = jPlayer.getPermissionsCache();
if (permissions == null || getDelay(perm) + jPlayer.getLastPermissionUpdate() < System.currentTimeMillis()) { if (permissions == null || getDelay(perm) + jPlayer.getLastPermissionUpdate() < System.currentTimeMillis()) {
permissions = getAll(jPlayer.getPlayer()); permissions = getAll(jPlayer.getPlayer());
jPlayer.setPermissionsCache(permissions); jPlayer.setPermissionsCache(permissions);

View File

@ -20,13 +20,11 @@ public class ChatFilterRule {
return id; return id;
} }
} }
private String replaceWith;
private String replaceWith, ruleName, messageToStaff, group;
private ChatFilterBlockType blockType; private ChatFilterBlockType blockType;
private String ruleName; private final List<Pattern> pattern = new ArrayList<>();
private List<Pattern> pattern = new ArrayList<>(); private List<String> commands;
private String messageToStaff;
private List<String> commands = new ArrayList<>();
private String group;
public ChatFilterRule(String ruleName, String group, List<String> list, String replaceWith, ChatFilterBlockType blockType, String messageToStaff, List<String> commands) { public ChatFilterRule(String ruleName, String group, List<String> list, String replaceWith, ChatFilterBlockType blockType, String messageToStaff, List<String> commands) {
this.group = group; this.group = group;

View File

@ -30,7 +30,9 @@ import com.gamingmesh.jobs.stuff.TimeManage;
public class Placeholder { public class Placeholder {
private Jobs plugin; private Jobs plugin;
Pattern placeholderPatern = Pattern.compile("(%)([^\"^%]*)(%)");
private final AtomicInteger jobLevel = new AtomicInteger();
private final Pattern placeholderPatern = Pattern.compile("(%)([^\"^%]*)(%)");
public Placeholder(Jobs plugin) { public Placeholder(Jobs plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -330,8 +332,6 @@ public class Placeholder {
return message; return message;
} }
private final AtomicInteger jobLevel = new AtomicInteger();
private String translateOwnPlaceHolder(Player player, String message) { private String translateOwnPlaceHolder(Player player, String message) {
if (message == null) if (message == null)
return null; return null;
@ -342,8 +342,7 @@ public class Placeholder {
if (!message.contains("%")) if (!message.contains("%"))
break; break;
String cmd = match.group(2); JobsPlaceHolders place = JobsPlaceHolders.getByNameExact(match.group(2));
JobsPlaceHolders place = JobsPlaceHolders.getByNameExact(cmd);
if (place == null) if (place == null)
continue; continue;

View File

@ -22,8 +22,10 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -69,16 +71,16 @@ import com.gamingmesh.jobs.stuff.Util;
public class PlayerManager { public class PlayerManager {
private final ConcurrentHashMap<String, JobsPlayer> playersCache = new ConcurrentHashMap<>(); private final ConcurrentMap<String, JobsPlayer> playersCache = new ConcurrentHashMap<>();
private final ConcurrentHashMap<UUID, JobsPlayer> playersUUIDCache = new ConcurrentHashMap<>(); private final ConcurrentMap<UUID, JobsPlayer> playersUUIDCache = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, JobsPlayer> players = new ConcurrentHashMap<>(); private final ConcurrentMap<String, JobsPlayer> players = new ConcurrentHashMap<>();
private final ConcurrentHashMap<UUID, JobsPlayer> playersUUID = new ConcurrentHashMap<>(); private final ConcurrentMap<UUID, JobsPlayer> playersUUID = new ConcurrentHashMap<>();
private final String mobSpawnerMetadata = "jobsMobSpawner"; private final String mobSpawnerMetadata = "jobsMobSpawner";
private final HashMap<UUID, PlayerInfo> PlayerUUIDMap = new HashMap<>(); private final Map<UUID, PlayerInfo> playerUUIDMap = new HashMap<>();
private final HashMap<Integer, PlayerInfo> PlayerIDMap = new HashMap<>(); private final Map<Integer, PlayerInfo> playerIdMap = new HashMap<>();
private final HashMap<String, PlayerInfo> PlayerNameMap = new HashMap<>(); private final Map<String, PlayerInfo> playerNameMap = new HashMap<>();
/** /**
* @deprecated Use {@link JobsPlayer#getPointsData} instead * @deprecated Use {@link JobsPlayer#getPointsData} instead
@ -98,13 +100,13 @@ public class PlayerManager {
@Deprecated @Deprecated
public int getMapSize() { public int getMapSize() {
return PlayerUUIDMap.size(); return playerUUIDMap.size();
} }
public void clearMaps() { public void clearMaps() {
PlayerUUIDMap.clear(); playerUUIDMap.clear();
PlayerIDMap.clear(); playerIdMap.clear();
PlayerNameMap.clear(); playerNameMap.clear();
} }
public void clearCache() { public void clearCache() {
@ -115,9 +117,9 @@ public class PlayerManager {
} }
public void addPlayerToMap(PlayerInfo info) { public void addPlayerToMap(PlayerInfo info) {
PlayerUUIDMap.put(info.getUuid(), info); playerUUIDMap.put(info.getUuid(), info);
PlayerIDMap.put(info.getID(), info); playerIdMap.put(info.getID(), info);
PlayerNameMap.put(info.getName().toLowerCase(), info); playerNameMap.put(info.getName().toLowerCase(), info);
} }
public void addPlayerToCache(JobsPlayer jPlayer) { public void addPlayerToCache(JobsPlayer jPlayer) {
@ -149,16 +151,12 @@ public class PlayerManager {
return playersUUID.remove(player.getUniqueId()); return playersUUID.remove(player.getUniqueId());
} }
public ConcurrentHashMap<UUID, JobsPlayer> getPlayersCache() { public ConcurrentMap<UUID, JobsPlayer> getPlayersCache() {
return playersUUIDCache; return playersUUIDCache;
} }
// public ConcurrentHashMap<String, JobsPlayer> getPlayers() { public Map<UUID, PlayerInfo> getPlayersInfoUUIDMap() {
// return this.players; return playerUUIDMap;
// }
public HashMap<UUID, PlayerInfo> getPlayersInfoUUIDMap() {
return PlayerUUIDMap;
} }
/** /**
@ -181,7 +179,7 @@ public class PlayerManager {
* @return the identifier * @return the identifier
*/ */
public int getPlayerId(UUID uuid) { public int getPlayerId(UUID uuid) {
PlayerInfo info = PlayerUUIDMap.get(uuid); PlayerInfo info = playerUUIDMap.get(uuid);
return info == null ? -1 : info.getID(); return info == null ? -1 : info.getID();
} }
@ -193,7 +191,7 @@ public class PlayerManager {
* @return {@link PlayerInfo} * @return {@link PlayerInfo}
*/ */
public PlayerInfo getPlayerInfo(String name) { public PlayerInfo getPlayerInfo(String name) {
return PlayerNameMap.get(name.toLowerCase()); return playerNameMap.get(name.toLowerCase());
} }
/** /**
@ -204,7 +202,7 @@ public class PlayerManager {
* @return {@link PlayerInfo} * @return {@link PlayerInfo}
*/ */
public PlayerInfo getPlayerInfo(int id) { public PlayerInfo getPlayerInfo(int id) {
return PlayerIDMap.get(id); return playerIdMap.get(id);
} }
/** /**
@ -215,7 +213,7 @@ public class PlayerManager {
* @return {@link PlayerInfo} * @return {@link PlayerInfo}
*/ */
public PlayerInfo getPlayerInfo(UUID uuid) { public PlayerInfo getPlayerInfo(UUID uuid) {
return PlayerUUIDMap.get(uuid); return playerUUIDMap.get(uuid);
} }
/** /**
@ -299,9 +297,7 @@ public class PlayerManager {
* 2) Perform save on all players on copied list. * 2) Perform save on all players on copied list.
* 3) Garbage collect the real list to remove any offline players with saved data * 3) Garbage collect the real list to remove any offline players with saved data
*/ */
ArrayList<JobsPlayer> list = new ArrayList<>(players.values()); for (JobsPlayer jPlayer : new ArrayList<>(players.values()))
for (JobsPlayer jPlayer : list)
jPlayer.save(); jPlayer.save();
Iterator<JobsPlayer> iter = players.values().iterator(); Iterator<JobsPlayer> iter = players.values().iterator();

View File

@ -5,22 +5,22 @@ import java.util.List;
public class SignInfo { public class SignInfo {
private final List<jobsSign> AllSigns = new ArrayList<>(); private final List<jobsSign> allSigns = new ArrayList<>();
public void setAllSigns(List<jobsSign> AllSigns) { public void setAllSigns(List<jobsSign> AllSigns) {
this.AllSigns.clear(); this.allSigns.clear();
this.AllSigns.addAll(AllSigns == null ? new ArrayList<>() : AllSigns); this.allSigns.addAll(AllSigns == null ? new ArrayList<>() : AllSigns);
} }
public List<jobsSign> GetAllSigns() { public List<jobsSign> getAllSigns() {
return AllSigns; return allSigns;
} }
public void removeSign(jobsSign sign) { public void removeSign(jobsSign sign) {
this.AllSigns.remove(sign); this.allSigns.remove(sign);
} }
public void addSign(jobsSign sign) { public void addSign(jobsSign sign) {
this.AllSigns.add(sign); this.allSigns.add(sign);
} }
} }

View File

@ -310,7 +310,9 @@ public class SignUtil {
if (playerName == null) if (playerName == null)
return false; return false;
timelapse = timelapse < 1 ? 1 : timelapse; if (timelapse < 1) {
timelapse = 1;
}
BlockFace directionFacing = null; BlockFace directionFacing = null;
if (Version.isCurrentEqualOrLower(Version.v1_13_R2)) { if (Version.isCurrentEqualOrLower(Version.v1_13_R2)) {

View File

@ -61,8 +61,7 @@ public class jobsSign {
return loc; return loc;
if (worldName == null) if (worldName == null)
return null; return null;
world = Bukkit.getWorld(worldName); if ((world = Bukkit.getWorld(worldName)) == null)
if (world == null)
return null; return null;
return loc = new Location(world, x, y, z); return loc = new Location(world, x, y, z);
} }
@ -139,13 +138,13 @@ public class jobsSign {
} }
public String getIdentifier() { public String getIdentifier() {
if (getType() != SignTopType.toplist) if (getType() != SignTopType.toplist)
return getType().toString(); return getType().toString();
return jobName != null ? jobName + ":" + getType().toString() : getType().toString(); return jobName != null ? jobName + ":" + getType().toString() : getType().toString();
} }
public static String getIdentifier(Job job, SignTopType type) { public static String getIdentifier(Job job, SignTopType type) {
if (type != SignTopType.toplist) if (type != SignTopType.toplist)
return type.toString(); return type.toString();
return job != null ? job.getName() + ":" + type.toString() : type.toString(); return job != null ? job.getName() + ":" + type.toString() : type.toString();
} }

View File

@ -183,7 +183,7 @@ public class JobsCommands implements CommandExecutor {
private Cmd getCmdClass(String cmd) { private Cmd getCmdClass(String cmd) {
try { try {
Class<?> nmsClass = Class.forName(PACKAGEPATH + "." + cmd.toLowerCase()); Class<?> nmsClass = getClass(cmd);
if (Cmd.class.isAssignableFrom(nmsClass)) { if (Cmd.class.isAssignableFrom(nmsClass)) {
return (Cmd) nmsClass.getConstructor().newInstance(); return (Cmd) nmsClass.getConstructor().newInstance();
} }

View File

@ -1,6 +1,5 @@
package com.gamingmesh.jobs.commands.list; package com.gamingmesh.jobs.commands.list;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -114,7 +113,7 @@ public class area implements Cmd {
if (args.length == 1 && args[0].equalsIgnoreCase("list")) { if (args.length == 1 && args[0].equalsIgnoreCase("list")) {
HashMap<String, RestrictedArea> areas = Jobs.getRestrictedAreaManager().getRestrictedAres(); java.util.Map<String, RestrictedArea> areas = Jobs.getRestrictedAreaManager().getRestrictedAres();
if (areas.isEmpty()) { if (areas.isEmpty()) {
sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.noAreas")); sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.noAreas"));
return true; return true;

View File

@ -1,7 +1,5 @@
package com.gamingmesh.jobs.commands.list; package com.gamingmesh.jobs.commands.list;
import java.util.HashMap;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -20,7 +18,7 @@ public class explored implements Cmd {
Player player = (Player) sender; Player player = (Player) sender;
HashMap<String, ExploreRegion> worlds = Jobs.getExplore().getWorlds(); java.util.Map<String, ExploreRegion> worlds = Jobs.getExplore().getWorlds();
if (!worlds.containsKey(player.getWorld().getName())) { if (!worlds.containsKey(player.getWorld().getName())) {
player.sendMessage(Jobs.getLanguage().getMessage("command.explored.error.noexplore")); player.sendMessage(Jobs.getLanguage().getMessage("command.explored.error.noexplore"));

View File

@ -77,7 +77,7 @@ public class give implements Cmd {
return true; return true;
} }
GiveItem.GiveItemForPlayer(player, jItem.getItemStack(player)); GiveItem.giveItemForPlayer(player, jItem.getItemStack(player));
break; break;
case limiteditems: case limiteditems:
if (job == null) { if (job == null) {
@ -91,7 +91,7 @@ public class give implements Cmd {
return true; return true;
} }
GiveItem.GiveItemForPlayer(player, jLItem.getItemStack(player)); GiveItem.giveItemForPlayer(player, jLItem.getItemStack(player));
break; break;
default: default:
break; break;

View File

@ -46,7 +46,7 @@ public class glog implements Cmd {
if (jPlayer == null) if (jPlayer == null)
continue; continue;
HashMap<String, Log> logList = jPlayer.getLog(); Map<String, Log> logList = jPlayer.getLog();
if (logList == null || logList.isEmpty()) if (logList == null || logList.isEmpty())
continue; continue;

View File

@ -46,7 +46,7 @@ public class log implements Cmd {
return true; return true;
} }
HashMap<String, Log> logList = JPlayer.getLog(); Map<String, Log> logList = JPlayer.getLog();
if (logList == null || logList.isEmpty()) { if (logList == null || logList.isEmpty()) {
sender.sendMessage(Jobs.getLanguage().getMessage("command.log.output.bottomline")); sender.sendMessage(Jobs.getLanguage().getMessage("command.log.output.bottomline"));
sender.sendMessage(Jobs.getLanguage().getMessage("command.log.output.nodata")); sender.sendMessage(Jobs.getLanguage().getMessage("command.log.output.nodata"));
@ -73,7 +73,7 @@ public class log implements Cmd {
sender.sendMessage(Jobs.getLanguage().getMessage("command.log.output.topline", "%playername%", JPlayer.getName())); sender.sendMessage(Jobs.getLanguage().getMessage("command.log.output.topline", "%playername%", JPlayer.getName()));
for (Log one : logList.values()) { for (Log one : logList.values()) {
HashMap<String, LogAmounts> AmountList = one.getAmountList(); Map<String, LogAmounts> AmountList = one.getAmountList();
double totalMoney = 0, totalExp = 0, totalPoints = 0; double totalMoney = 0, totalExp = 0, totalPoints = 0;
for (String oneSorted : unsortMap.keySet()) { for (String oneSorted : unsortMap.keySet()) {

View File

@ -3,6 +3,7 @@ package com.gamingmesh.jobs.config;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -17,7 +18,7 @@ import com.gamingmesh.jobs.stuff.Util;
public class ExploreManager { public class ExploreManager {
private final HashMap<String, ExploreRegion> worlds = new HashMap<>(); private final Map<String, ExploreRegion> worlds = new HashMap<>();
private boolean exploreEnabled = false; private boolean exploreEnabled = false;
private int playerAmount = 1; private int playerAmount = 1;
@ -48,7 +49,7 @@ public class ExploreManager {
Jobs.consoleMsg("&e[Jobs] Loaded explorer data" + (getSize() != 0 ? " (" + getSize() + ")" : ".")); Jobs.consoleMsg("&e[Jobs] Loaded explorer data" + (getSize() != 0 ? " (" + getSize() + ")" : "."));
} }
public HashMap<String, ExploreRegion> getWorlds() { public Map<String, ExploreRegion> getWorlds() {
return worlds; return worlds;
} }
@ -69,7 +70,6 @@ public class ExploreManager {
} }
public ExploreRespond ChunkRespond(int playerId, String world, int x, int z) { public ExploreRespond ChunkRespond(int playerId, String world, int x, int z) {
ExploreRegion eRegions = worlds.get(world); ExploreRegion eRegions = worlds.get(world);
if (eRegions == null) { if (eRegions == null) {
int RegionX = (int) Math.floor(x / 32D); int RegionX = (int) Math.floor(x / 32D);

View File

@ -43,8 +43,6 @@ import com.gamingmesh.jobs.resources.jfep.Parser;
public class GeneralConfigManager { public class GeneralConfigManager {
public ArrayList<String> keys;
public List<Integer> BroadcastingLevelUpLevels = new ArrayList<>(); public List<Integer> BroadcastingLevelUpLevels = new ArrayList<>();
public List<String> FwColors = new ArrayList<>(), DisabledWorldsList = new ArrayList<>(); public List<String> FwColors = new ArrayList<>(), DisabledWorldsList = new ArrayList<>();
/** /**

View File

@ -12,6 +12,8 @@ import com.gamingmesh.jobs.stuff.Util;
public class LanguageManager { public class LanguageManager {
public final List<String> signKeys = new ArrayList<>();
private List<String> languages = new ArrayList<>(); private List<String> languages = new ArrayList<>();
public List<String> getLanguages() { public List<String> getLanguages() {
@ -676,7 +678,8 @@ public class LanguageManager {
c.get("scoreboard.gtopline", "&2Global top list"); c.get("scoreboard.gtopline", "&2Global top list");
c.get("scoreboard.line", "&2%number%. &e%playername% (&6%level%&e)"); c.get("scoreboard.line", "&2%number%. &e%playername% (&6%level%&e)");
Jobs.getGCManager().keys = new ArrayList<String>(c.getC().getConfigurationSection("signs.secondline").getKeys(false)); signKeys.clear();
signKeys.addAll(c.getC().getConfigurationSection("signs.secondline").getKeys(false));
// Write back config // Write back config
c.save(); c.save();

View File

@ -156,87 +156,88 @@ public class NameTranslatorManager {
} }
public void readFile() { public void readFile() {
YmlMaker ItemFile = new YmlMaker(Jobs.getFolder(), "TranslatableWords" + File.separator + "Words_" YmlMaker itemFile = new YmlMaker(Jobs.getFolder(), "TranslatableWords" + File.separator + "Words_"
+ Jobs.getGCManager().localeString + ".yml"); + Jobs.getGCManager().localeString + ".yml");
if (!ItemFile.getConfigFile().getName().equalsIgnoreCase("en")) { if (!itemFile.getConfigFile().getName().equalsIgnoreCase("en")) {
ItemFile.saveDefaultConfig(); itemFile.saveDefaultConfig();
} }
if (ItemFile.getConfig().isConfigurationSection("ItemList")) { if (itemFile.getConfig().isConfigurationSection("ItemList")) {
ConfigurationSection section = ItemFile.getConfig().getConfigurationSection("ItemList");
Set<String> keys = section.getKeys(false);
ListOfNames.clear(); ListOfNames.clear();
for (String one : keys) {
for (String one : itemFile.getConfig().getConfigurationSection("ItemList").getKeys(false)) {
String split = one.contains("-") ? one.split("-")[0] : one; String split = one.contains("-") ? one.split("-")[0] : one;
String id = split.contains(":") ? split.split(":")[0] : split; String id = split.contains(":") ? split.split(":")[0] : split;
String meta = split.contains(":") && split.split(":").length > 1 ? split.split(":")[1] : ""; String meta = split.contains(":") && split.split(":").length > 1 ? split.split(":")[1] : "";
String MCName = one.contains("-") && one.split("-").length > 1 ? one.split("-")[1] : one; String MCName = one.contains("-") && one.split("-").length > 1 ? one.split("-")[1] : one;
String Name = ItemFile.getConfig().getString("ItemList." + one); String Name = itemFile.getConfig().getString("ItemList." + one);
ListOfNames.put(CMIMaterial.get(one), new NameList(id, meta, Name, MCName)); ListOfNames.put(CMIMaterial.get(one), new NameList(id, meta, Name, MCName));
} }
if (ListOfNames.size() > 0) if (ListOfNames.size() > 0)
Jobs.consoleMsg("&e[Jobs] Loaded " + ListOfNames.size() + " custom item names!"); Jobs.consoleMsg("&e[Jobs] Loaded " + ListOfNames.size() + " custom item names!");
} else } else
Jobs.consoleMsg("&c[Jobs] The ItemList section not found in " + ItemFile.fileName + " file."); Jobs.consoleMsg("&c[Jobs] The ItemList section not found in " + itemFile.fileName + " file.");
if (ItemFile.getConfig().isConfigurationSection("EntityList")) { if (itemFile.getConfig().isConfigurationSection("EntityList")) {
ConfigurationSection section = ItemFile.getConfig().getConfigurationSection("EntityList");
Set<String> keys = section.getKeys(false);
ListOfEntities.clear(); ListOfEntities.clear();
for (String one : keys) {
for (String one : itemFile.getConfig().getConfigurationSection("EntityList").getKeys(false)) {
String split = one.contains("-") ? one.split("-")[0] : one; String split = one.contains("-") ? one.split("-")[0] : one;
String id = split.contains(":") ? split.split(":")[0] : split; String id = split.contains(":") ? split.split(":")[0] : split;
String meta = split.contains(":") ? split.split(":")[1] : ""; String meta = split.contains(":") ? split.split(":")[1] : "";
String MCName = one.contains("-") && one.split(":").length > 1 ? one.split("-")[1] : one; String MCName = one.contains("-") && one.split("-").length > 1 ? one.split("-")[1] : one;
String Name = ItemFile.getConfig().getString("EntityList." + one); String Name = itemFile.getConfig().getString("EntityList." + one);
ListOfEntities.add(new NameList(id, meta, Name, MCName)); ListOfEntities.add(new NameList(id, meta, Name, MCName));
} }
if (ListOfEntities.size() > 0) if (ListOfEntities.size() > 0)
Jobs.consoleMsg("&e[Jobs] Loaded " + ListOfEntities.size() + " custom entity names!"); Jobs.consoleMsg("&e[Jobs] Loaded " + ListOfEntities.size() + " custom entity names!");
} else } else
Jobs.consoleMsg("&c[Jobs] The EntityList section not found in " + ItemFile.fileName + " file."); Jobs.consoleMsg("&c[Jobs] The EntityList section not found in " + itemFile.fileName + " file.");
if (ItemFile.getConfig().isConfigurationSection("MythicEntityList")) { if (itemFile.getConfig().isConfigurationSection("MythicEntityList")) {
ConfigurationSection section = ItemFile.getConfig().getConfigurationSection("MythicEntityList");
Set<String> keys = section.getKeys(false);
ListOfMMEntities.clear(); ListOfMMEntities.clear();
for (String one : keys) {
String Name = ItemFile.getConfig().getString("MythicEntityList." + one); for (String one : itemFile.getConfig().getConfigurationSection("MythicEntityList").getKeys(false)) {
String Name = itemFile.getConfig().getString("MythicEntityList." + one);
ListOfMMEntities.put(one.toLowerCase(), new NameList(null, null, Name, Name)); ListOfMMEntities.put(one.toLowerCase(), new NameList(null, null, Name, Name));
} }
if (ListOfMMEntities.size() > 0) if (ListOfMMEntities.size() > 0)
Jobs.consoleMsg("&e[Jobs] Loaded " + ListOfMMEntities.size() + " custom MythicMobs names!"); Jobs.consoleMsg("&e[Jobs] Loaded " + ListOfMMEntities.size() + " custom MythicMobs names!");
} else } else
Jobs.consoleMsg("&c[Jobs] The MythicEntityList section not found in " + ItemFile.fileName + " file."); Jobs.consoleMsg("&c[Jobs] The MythicEntityList section not found in " + itemFile.fileName + " file.");
if (ItemFile.getConfig().isConfigurationSection("EnchantList")) { if (itemFile.getConfig().isConfigurationSection("EnchantList")) {
ConfigurationSection section = ItemFile.getConfig().getConfigurationSection("EnchantList");
Set<String> keys = section.getKeys(false);
ListOfEnchants.clear(); ListOfEnchants.clear();
for (String one : keys) {
String name = section.getString(one); ConfigurationSection section = itemFile.getConfig().getConfigurationSection("EnchantList");
ListOfEnchants.put(one.replace("_", "").toLowerCase(), new NameList(one, one, one, name)); for (String one : section.getKeys(false)) {
ListOfEnchants.put(one.replace("_", "").toLowerCase(), new NameList(one, one, one, section.getString(one)));
} }
if (ListOfEnchants.size() > 0) if (ListOfEnchants.size() > 0)
Jobs.consoleMsg("&e[Jobs] Loaded " + ListOfEnchants.size() + " custom enchant names!"); Jobs.consoleMsg("&e[Jobs] Loaded " + ListOfEnchants.size() + " custom enchant names!");
} else } else
Jobs.consoleMsg("&c[Jobs] The EnchantList section not found in " + ItemFile.fileName + " file."); Jobs.consoleMsg("&c[Jobs] The EnchantList section not found in " + itemFile.fileName + " file.");
if (ItemFile.getConfig().isConfigurationSection("ColorList")) { if (itemFile.getConfig().isConfigurationSection("ColorList")) {
ConfigurationSection section = ItemFile.getConfig().getConfigurationSection("ColorList");
Set<String> keys = section.getKeys(false);
ListOfColors.clear(); ListOfColors.clear();
for (String one : keys) {
String id = one.contains("-") ? one.split("-")[0] : one; for (String one : itemFile.getConfig().getConfigurationSection("ColorList").getKeys(false)) {
String MCName = one.split("-")[1]; String[] split = one.contains("-") ? one.split("-") : new String[0];
String Name = ItemFile.getConfig().getString("ColorList." + one); String id = split.length != 0 ? split[0] : one;
String MCName = split.length > 1 ? split[1] : "";
String Name = itemFile.getConfig().getString("ColorList." + one);
ListOfColors.add(new NameList(id, "", Name, MCName)); ListOfColors.add(new NameList(id, "", Name, MCName));
} }
if (ListOfColors.size() > 0) if (ListOfColors.size() > 0)
Jobs.consoleMsg("&e[Jobs] Loaded " + ListOfColors.size() + " custom color names!"); Jobs.consoleMsg("&e[Jobs] Loaded " + ListOfColors.size() + " custom color names!");
} else } else
Jobs.consoleMsg("&c[Jobs] The ColorList section not found in " + ItemFile.fileName + " file."); Jobs.consoleMsg("&c[Jobs] The ColorList section not found in " + itemFile.fileName + " file.");
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -359,7 +360,7 @@ public class NameTranslatorManager {
if (ent == null || !ent.isAlive()) if (ent == null || !ent.isAlive())
continue; continue;
String n = String.valueOf(ent.getId()); String n = Integer.toString(ent.getId());
String name = null; String name = null;

View File

@ -5,6 +5,7 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -21,7 +22,7 @@ import com.gamingmesh.jobs.hooks.HookManager;
public class RestrictedAreaManager { public class RestrictedAreaManager {
protected final HashMap<String, RestrictedArea> restrictedAreas = new HashMap<>(); protected final Map<String, RestrictedArea> restrictedAreas = new HashMap<>();
private boolean worldGuardArea = false; private boolean worldGuardArea = false;
@ -65,7 +66,7 @@ public class RestrictedAreaManager {
} }
} }
public HashMap<String, RestrictedArea> getRestrictedAres() { public Map<String, RestrictedArea> getRestrictedAres() {
return restrictedAreas; return restrictedAreas;
} }
@ -108,9 +109,8 @@ public class RestrictedAreaManager {
if (player == null) if (player == null)
return 0D; return 0D;
for (RestrictedArea area : getRestrictedAreasByLoc(player.getLocation())) { for (RestrictedArea area : getRestrictedAreasByLoc(player.getLocation())) {
if (area.inRestrictedArea(player.getLocation())) if (area.inRestrictedArea(player.getLocation()) || (area.getWgName() != null && HookManager.getWorldGuardManager() != null
return area.getMultiplier(); && HookManager.getWorldGuardManager().inArea(player.getLocation(), area.getWgName())))
if (area.getWgName() != null && HookManager.getWorldGuardManager() != null && HookManager.getWorldGuardManager().inArea(player.getLocation(), area.getWgName()))
return area.getMultiplier(); return area.getMultiplier();
} }
return 0D; return 0D;
@ -138,38 +138,40 @@ public class RestrictedAreaManager {
return areas; return areas;
} }
private static StringBuilder addHeader(StringBuilder header) { private StringBuilder addHeader(StringBuilder header) {
String sep = System.getProperty("line.separator");
header.append("Restricted area configuration"); header.append("Restricted area configuration");
header.append(System.getProperty("line.separator")) header.append(sep)
.append(System.getProperty("line.separator")) .append(sep)
.append("Configures restricted areas where you cannot get experience or money").append(System.getProperty("line.separator")) .append("Configures restricted areas where you cannot get experience or money").append(sep)
.append("when performing a job.").append(System.getProperty("line.separator")).append(System.getProperty("line.separator")) .append("when performing a job.").append(sep).append(sep)
.append("The multiplier changes the experience/money gains in an area.").append(System.getProperty("line.separator")) .append("The multiplier changes the experience/money gains in an area.").append(sep)
.append("A multiplier of 0.0 means no bonus, while 0.5 means you will get 50% more the normal income").append(System.getProperty("line.separator")) .append("A multiplier of 0.0 means no bonus, while 0.5 means you will get 50% more the normal income").append(sep)
.append("While -0.5 means that you will get 50% less the normal income").append(System.getProperty("line.separator")) .append("While -0.5 means that you will get 50% less the normal income").append(sep)
.append(System.getProperty("line.separator")) .append(sep)
.append("restrictedareas:").append(System.getProperty("line.separator")) .append("restrictedareas:").append(sep)
.append(" area1:").append(System.getProperty("line.separator")) .append(" area1:").append(sep)
.append(" world: 'world'").append(System.getProperty("line.separator")) .append(" world: 'world'").append(sep)
.append(" multiplier: 0.0").append(System.getProperty("line.separator")) .append(" multiplier: 0.0").append(sep)
.append(" point1:").append(System.getProperty("line.separator")) .append(" point1:").append(sep)
.append(" x: 125").append(System.getProperty("line.separator")) .append(" x: 125").append(sep)
.append(" y: 0").append(System.getProperty("line.separator")) .append(" y: 0").append(sep)
.append(" z: 125").append(System.getProperty("line.separator")) .append(" z: 125").append(sep)
.append(" point2:").append(System.getProperty("line.separator")) .append(" point2:").append(sep)
.append(" x: 150").append(System.getProperty("line.separator")) .append(" x: 150").append(sep)
.append(" y: 100").append(System.getProperty("line.separator")) .append(" y: 100").append(sep)
.append(" z: 150").append(System.getProperty("line.separator")) .append(" z: 150").append(sep)
.append(" area2:").append(System.getProperty("line.separator")) .append(" area2:").append(sep)
.append(" world: 'world_nether'").append(System.getProperty("line.separator")) .append(" world: 'world_nether'").append(sep)
.append(" multiplier: 0.0").append(System.getProperty("line.separator")) .append(" multiplier: 0.0").append(sep)
.append(" point1:").append(System.getProperty("line.separator")) .append(" point1:").append(sep)
.append(" x: -100").append(System.getProperty("line.separator")) .append(" x: -100").append(sep)
.append(" y: 0").append(System.getProperty("line.separator")) .append(" y: 0").append(sep)
.append(" z: -100").append(System.getProperty("line.separator")) .append(" z: -100").append(sep)
.append(" point2:").append(System.getProperty("line.separator")) .append(" point2:").append(sep)
.append(" x: -150").append(System.getProperty("line.separator")) .append(" x: -150").append(sep)
.append(" y: 100").append(System.getProperty("line.separator")) .append(" y: 100").append(sep)
.append(" z: -150"); .append(" z: -150");
return header; return header;
} }
@ -199,9 +201,7 @@ public class RestrictedAreaManager {
addNew(new RestrictedArea(areaKey, areaKey, multiplier)); addNew(new RestrictedArea(areaKey, areaKey, multiplier));
worldGuardArea = true; worldGuardArea = true;
} else { } else {
World world = Bukkit.getServer().getWorld(conf.getString("restrictedareas." + areaKey + ".world", ""));
String worldName = conf.getString("restrictedareas." + areaKey + ".world");
World world = Bukkit.getServer().getWorld(worldName);
if (world == null) if (world == null)
continue; continue;
Location point1 = new Location(world, conf.getDouble("restrictedareas." + areaKey + ".point1.x", 0d), conf.getDouble("restrictedareas." + areaKey Location point1 = new Location(world, conf.getDouble("restrictedareas." + areaKey + ".point1.x", 0d), conf.getDouble("restrictedareas." + areaKey

View File

@ -1,6 +1,7 @@
package com.gamingmesh.jobs.config; package com.gamingmesh.jobs.config;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
import java.util.Set; import java.util.Set;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
@ -11,7 +12,7 @@ import com.gamingmesh.jobs.CMILib.ItemManager;
public class RestrictedBlockManager { public class RestrictedBlockManager {
public final HashMap<CMIMaterial, Integer> restrictedBlocksTimer = new HashMap<>(); public final Map<CMIMaterial, Integer> restrictedBlocksTimer = new HashMap<>();
/** /**
* Method to load the restricted blocks configuration * Method to load the restricted blocks configuration

View File

@ -56,14 +56,14 @@ public class ScheduleManager {
DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
String currenttime = dateFormat.format(new Date()); String currenttime = dateFormat.format(new Date());
String CurrentDayName = getWeekDay(); String currentDayName = getWeekDay();
int Current = Integer.parseInt(currenttime.replace(":", "")); int current = Integer.parseInt(currenttime.replace(":", ""));
for (Schedule one : BOOSTSCHEDULE) { for (Schedule one : BOOSTSCHEDULE) {
int From = one.getFrom(); int from = one.getFrom();
int Until = one.getUntil(); int until = one.getUntil();
List<String> days = one.getDays(); List<String> days = one.getDays();
@ -72,8 +72,8 @@ public class ScheduleManager {
Jobs.getInstance().getComplement().broadcastMessage(one.getMessageToBroadcast()); Jobs.getInstance().getComplement().broadcastMessage(one.getMessageToBroadcast());
} }
if (((one.isNextDay() && (Current >= From && Current < Until || Current >= one.getNextFrom() && Current < one.getNextUntil()) && !one if (((one.isNextDay() && (current >= from && current < until || current >= one.getNextFrom() && current < one.getNextUntil()) && !one
.isStarted()) || !one.isNextDay() && (Current >= From && Current < Until)) && (days.contains(CurrentDayName) || days.contains("all")) && !one .isStarted()) || !one.isNextDay() && (current >= from && current < until)) && (days.contains(currentDayName) || days.contains("all")) && !one
.isStarted()) { .isStarted()) {
JobsScheduleStartEvent event = new JobsScheduleStartEvent(one); JobsScheduleStartEvent event = new JobsScheduleStartEvent(one);
@ -97,8 +97,8 @@ public class ScheduleManager {
one.setStarted(true); one.setStarted(true);
one.setStoped(false); one.setStoped(false);
break; break;
} else if (((one.isNextDay() && Current > one.getNextUntil() && Current < one.getFrom() && !one.isStoped()) || !one.isNextDay() && Current > Until } else if (((one.isNextDay() && current > one.getNextUntil() && current < one.getFrom() && !one.isStoped()) || !one.isNextDay() && current > until
&& ((days.contains(CurrentDayName)) || days.contains("all"))) && !one.isStoped()) { && ((days.contains(currentDayName)) || days.contains("all"))) && !one.isStoped()) {
JobsScheduleStopEvent event = new JobsScheduleStopEvent(one); JobsScheduleStopEvent event = new JobsScheduleStopEvent(one);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
@ -124,8 +124,7 @@ public class ScheduleManager {
} }
public static String getWeekDay() { public static String getWeekDay() {
int dayOfWeek = Calendar.getInstance().get(Calendar.DAY_OF_WEEK); switch (Calendar.getInstance().get(Calendar.DAY_OF_WEEK)) {
switch (dayOfWeek) {
case 2: case 2:
return "monday"; return "monday";
case 3: case 3:
@ -164,7 +163,7 @@ public class ScheduleManager {
if (!conf.isConfigurationSection("Boost")) if (!conf.isConfigurationSection("Boost"))
return; return;
ArrayList<String> sections = new ArrayList<>(conf.getConfigurationSection("Boost").getKeys(false)); List<String> sections = new ArrayList<>(conf.getConfigurationSection("Boost").getKeys(false));
for (String oneSection : sections) { for (String oneSection : sections) {
ConfigurationSection path = conf.getConfigurationSection("Boost." + oneSection); ConfigurationSection path = conf.getConfigurationSection("Boost." + oneSection);
@ -178,8 +177,8 @@ public class ScheduleManager {
sched.setName(oneSection); sched.setName(oneSection);
sched.setDays(path.getStringList("Days")); sched.setDays(path.getStringList("Days"));
sched.setJobs(path.getStringList("Jobs")); sched.setJobs(path.getStringList("Jobs"));
sched.setFrom(Integer.valueOf(path.getString("From").replace(":", ""))); sched.setFrom(Integer.parseInt(path.getString("From").replace(":", "")));
sched.setUntil(Integer.valueOf(path.getString("Until").replace(":", ""))); sched.setUntil(Integer.parseInt(path.getString("Until").replace(":", "")));
if (path.isList("MessageOnStart")) if (path.isList("MessageOnStart"))
sched.setMessageOnStart(path.getStringList("MessageOnStart"), path.getString("From"), path.getString("Until")); sched.setMessageOnStart(path.getStringList("MessageOnStart"), path.getString("From"), path.getString("Until"));

View File

@ -43,8 +43,14 @@ import com.gamingmesh.jobs.stuff.GiveItem;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class ShopManager { public class ShopManager {
private Jobs plugin;
private final List<ShopItem> list = new ArrayList<>(); private final List<ShopItem> list = new ArrayList<>();
public ShopManager(Jobs plugin) {
this.plugin = plugin;
}
public List<ShopItem> getShopItemList() { public List<ShopItem> getShopItemList() {
return list; return list;
} }
@ -117,7 +123,7 @@ public class ShopManager {
for (int i = 0; i < ls.size(); i++) { for (int i = 0; i < ls.size(); i++) {
ShopItem item = ls.get(i); ShopItem item = ls.get(i);
ArrayList<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();
CMIMaterial mat = CMIMaterial.get(item.getIconMaterial()); CMIMaterial mat = CMIMaterial.get(item.getIconMaterial());
if (item.isHideWithoutPerm()) { if (item.isHideWithoutPerm()) {
@ -147,7 +153,7 @@ public class ShopManager {
continue; continue;
if (item.getIconName() != null) if (item.getIconName() != null)
meta.setDisplayName(item.getIconName()); plugin.getComplement().setDisplayName(meta, item.getIconName());
lore.addAll(item.getIconLore()); lore.addAll(item.getIconLore());
@ -185,7 +191,7 @@ public class ShopManager {
? Jobs.getLanguage().getMessage("command.shop.info.reqTotalLevelColor") : "") + item.getRequiredTotalLevels())); ? Jobs.getLanguage().getMessage("command.shop.info.reqTotalLevelColor") : "") + item.getRequiredTotalLevels()));
} }
meta.setLore(lore); plugin.getComplement().setLore(meta, lore);
if (item.getCustomHead() != null) { if (item.getCustomHead() != null) {
guiItem = CMIMaterial.PLAYER_HEAD.newItemStack(); guiItem = CMIMaterial.PLAYER_HEAD.newItemStack();
@ -194,9 +200,8 @@ public class ShopManager {
if (skullMeta == null) if (skullMeta == null)
continue; continue;
// Fix skull meta plugin.getComplement().setDisplayName(skullMeta, item.getIconName());
skullMeta.setDisplayName(item.getIconName()); plugin.getComplement().setLore(skullMeta, lore);
skullMeta.setLore(lore);
if (item.isHeadOwner()) { if (item.isHeadOwner()) {
Jobs.getNms().setSkullOwner(skullMeta, jPlayer.getPlayer()); Jobs.getNms().setSkullOwner(skullMeta, jPlayer.getPlayer());
@ -253,7 +258,7 @@ public class ShopManager {
} }
for (JobItems one : item.getitems()) { for (JobItems one : item.getitems()) {
GiveItem.GiveItemForPlayer(player, one.getItemStack(player)); GiveItem.giveItemForPlayer(player, one.getItemStack(player));
} }
pointsInfo.takePoints(item.getPrice()); pointsInfo.takePoints(item.getPrice());
@ -271,7 +276,7 @@ public class ShopManager {
int prevSlot = getPrevButtonSlot(guiSize.getFields(), page); int prevSlot = getPrevButtonSlot(guiSize.getFields(), page);
if (prevSlot != -1 && page > 1) { if (prevSlot != -1 && page > 1) {
meta.setDisplayName(Jobs.getLanguage().getMessage("command.help.output.prevPage")); plugin.getComplement().setDisplayName(meta, Jobs.getLanguage().getMessage("command.help.output.prevPage"));
item.setItemMeta(meta); item.setItemMeta(meta);
gui.addButton(new CMIGuiButton(prevSlot, item) { gui.addButton(new CMIGuiButton(prevSlot, item) {
@ -284,7 +289,7 @@ public class ShopManager {
int nextSlot = getNextButtonSlot(guiSize.getFields(), page); int nextSlot = getNextButtonSlot(guiSize.getFields(), page);
if (nextSlot != -1 && !getItemsByPage(page + 1).isEmpty()) { if (nextSlot != -1 && !getItemsByPage(page + 1).isEmpty()) {
meta.setDisplayName(Jobs.getLanguage().getMessage("command.help.output.nextPage")); plugin.getComplement().setDisplayName(meta, Jobs.getLanguage().getMessage("command.help.output.nextPage"));
item.setItemMeta(meta); item.setItemMeta(meta);
gui.addButton(new CMIGuiButton(nextSlot, item) { gui.addButton(new CMIGuiButton(nextSlot, item) {
@Override @Override
@ -309,13 +314,14 @@ public class ShopManager {
return; return;
ConfigurationSection confCategory = f.getConfigurationSection("Items"); ConfigurationSection confCategory = f.getConfigurationSection("Items");
if (confCategory.getKeys(false).isEmpty()) { java.util.Set<String> categories = confCategory.getKeys(false);
if (categories.isEmpty()) {
return; return;
} }
int i = 0; int i = 0;
int y = 1; int y = 1;
for (String category : new ArrayList<>(confCategory.getKeys(false))) { for (String category : new java.util.HashSet<>(categories)) {
ConfigurationSection nameSection = confCategory.getConfigurationSection(category); ConfigurationSection nameSection = confCategory.getConfigurationSection(category);
if (nameSection == null) { if (nameSection == null) {
continue; continue;

View File

@ -19,8 +19,8 @@
package com.gamingmesh.jobs.container; package com.gamingmesh.jobs.container;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
@ -42,10 +42,10 @@ public class JobLimitedItems {
private int amount; private int amount;
private String name; private String name;
private List<String> lore; private List<String> lore;
private HashMap<Enchantment, Integer> enchants; private Map<Enchantment, Integer> enchants;
private int level; private int level;
public JobLimitedItems(String node, int id, int data, int amount, String name, List<String> lore, HashMap<Enchantment, Integer> enchants, int level) { public JobLimitedItems(String node, int id, int data, int amount, String name, List<String> lore, Map<Enchantment, Integer> enchants, int level) {
this.node = node; this.node = node;
this.id = id; this.id = id;
this.data = data; this.data = data;
@ -96,7 +96,7 @@ public class JobLimitedItems {
public int getId() { public int getId() {
return id; return id;
} }
public CMIMaterial getType(){ public CMIMaterial getType(){
return mat; return mat;
} }
@ -109,7 +109,7 @@ public class JobLimitedItems {
return lore; return lore;
} }
public HashMap<Enchantment, Integer> getenchants() { public Map<Enchantment, Integer> getEnchants() {
return enchants; return enchants;
} }

View File

@ -24,6 +24,7 @@ import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.UUID; import java.util.UUID;
@ -49,14 +50,14 @@ public class JobsPlayer {
public UUID playerUUID; public UUID playerUUID;
// progression of the player in each job // progression of the player in each job
public final ArrayList<JobProgression> progression = new ArrayList<>(); public final List<JobProgression> progression = new ArrayList<>();
public int maxJobsEquation = 0; public int maxJobsEquation = 0;
private ArchivedJobs archivedJobs = new ArchivedJobs(); private ArchivedJobs archivedJobs = new ArchivedJobs();
private PaymentData paymentLimits; private PaymentData paymentLimits;
private final HashMap<String, ArrayList<BoostCounter>> boostCounter = new HashMap<>(); private final Map<String, List<BoostCounter>> boostCounter = new HashMap<>();
// display honorific // display honorific
private String honorific; private String honorific;
@ -65,7 +66,7 @@ public class JobsPlayer {
// player online status // player online status
private volatile boolean isOnline = false; private volatile boolean isOnline = false;
private final HashMap<CurrencyType, Integer> limits = new HashMap<>(); private final Map<CurrencyType, Integer> limits = new HashMap<>();
private int userid = -1; private int userid = -1;
@ -74,18 +75,18 @@ public class JobsPlayer {
// save lock // save lock
// public final Object saveLock = new Object(); // public final Object saveLock = new Object();
private HashMap<String, Log> logList = new HashMap<>(); private Map<String, Log> logList = new HashMap<>();
private Long seen = System.currentTimeMillis(); private Long seen = System.currentTimeMillis();
private HashMap<String, Boolean> permissionsCache; private Map<String, Boolean> permissionsCache;
private Long lastPermissionUpdate = -1L; private Long lastPermissionUpdate = -1L;
private final HashMap<String, HashMap<String, QuestProgression>> qProgression = new HashMap<>(); private final Map<String, Map<String, QuestProgression>> qProgression = new HashMap<>();
private int doneQuests = 0; private int doneQuests = 0;
private int skippedQuests = 0; private int skippedQuests = 0;
private final HashMap<UUID, HashMap<Job, Long>> leftTimes = new HashMap<>(); private final Map<UUID, Map<Job, Long>> leftTimes = new HashMap<>();
private PlayerPoints pointsData; private PlayerPoints pointsData;
@ -272,7 +273,7 @@ public class JobsPlayer {
} }
} }
public HashMap<String, Log> getLog() { public Map<String, Log> getLog() {
return logList; return logList;
} }
@ -316,60 +317,60 @@ public class JobsPlayer {
* @return amount of boost * @return amount of boost
*/ */
public double getBoost(String JobName, CurrencyType type, boolean force) { public double getBoost(String JobName, CurrencyType type, boolean force) {
double Boost = 0D; double boost = 0D;
if (!isOnline() || type == null) if (!isOnline() || type == null)
return Boost; return boost;
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
if (boostCounter.containsKey(JobName)) { if (boostCounter.containsKey(JobName)) {
ArrayList<BoostCounter> counterList = boostCounter.get(JobName); List<BoostCounter> counterList = boostCounter.get(JobName);
for (BoostCounter counter : counterList) { for (BoostCounter counter : counterList) {
if (counter.getType() != type) if (counter.getType() != type)
continue; continue;
if (force || time - counter.getTime() > 1000 * 60) { if (force || time - counter.getTime() > 1000 * 60) {
Boost = getPlayerBoostNew(JobName, type); boost = getPlayerBoostNew(JobName, type);
counter.setBoost(Boost); counter.setBoost(boost);
counter.setTime(time); counter.setTime(time);
return Boost; return boost;
} }
return counter.getBoost(); return counter.getBoost();
} }
Boost = getPlayerBoostNew(JobName, type); boost = getPlayerBoostNew(JobName, type);
counterList.add(new BoostCounter(type, Boost, time)); counterList.add(new BoostCounter(type, boost, time));
return Boost; return boost;
} }
Boost = getPlayerBoostNew(JobName, type); boost = getPlayerBoostNew(JobName, type);
ArrayList<BoostCounter> counterList = new ArrayList<>(); List<BoostCounter> counterList = new ArrayList<>();
counterList.add(new BoostCounter(type, Boost, time)); counterList.add(new BoostCounter(type, boost, time));
boostCounter.put(JobName, counterList); boostCounter.put(JobName, counterList);
return Boost; return boost;
} }
private Double getPlayerBoostNew(String JobName, CurrencyType type) { private Double getPlayerBoostNew(String jobName, CurrencyType type) {
Double v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost." + JobName + "." + type.getName(), true, false); Double v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost." + jobName + "." + type.getName(), true, false);
Double Boost = v1; Double boost = v1;
v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost." + JobName + ".all", false, false); v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost." + jobName + ".all", false, false);
if (v1 != 0d && (v1 > Boost || v1 < Boost)) if (v1 != 0d && (v1 > boost || v1 < boost))
Boost = v1; boost = v1;
v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost.all.all", false, false); v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost.all.all", false, false);
if (v1 != 0d && (v1 > Boost || v1 < Boost)) if (v1 != 0d && (v1 > boost || v1 < boost))
Boost = v1; boost = v1;
v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost.all." + type.getName(), false, false); v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost.all." + type.getName(), false, false);
if (v1 != 0d && (v1 > Boost || v1 < Boost)) if (v1 != 0d && (v1 > boost || v1 < boost))
Boost = v1; boost = v1;
return Boost; return boost;
} }
public int getPlayerMaxQuest(String jobName) { public int getPlayerMaxQuest(String jobName) {
@ -395,9 +396,9 @@ public class JobsPlayer {
* Reloads limit for this player. * Reloads limit for this player.
*/ */
public void reload(CurrencyType type) { public void reload(CurrencyType type) {
int TotalLevel = getTotalLevels(); int totalLevel = getTotalLevels();
Parser eq = Jobs.getGCManager().getLimit(type).getMaxEquation(); Parser eq = Jobs.getGCManager().getLimit(type).getMaxEquation();
eq.setVariable("totallevel", TotalLevel); eq.setVariable("totallevel", totalLevel);
maxJobsEquation = Jobs.getPlayerManager().getMaxJobs(this); maxJobsEquation = Jobs.getPlayerManager().getMaxJobs(this);
limits.put(type, (int) eq.getValue()); limits.put(type, (int) eq.getValue());
setSaved(false); setSaved(false);
@ -530,13 +531,10 @@ public class JobsPlayer {
if (level < 1) if (level < 1)
level = 1; level = 1;
Job job = jp.getJob(); if (jp.getLevel() == getMaxJobLevelAllowed(jp.getJob())) {
int maxLevel = getMaxJobLevelAllowed(job); level = jp.getLevel();
if (jp.getLevel() == maxLevel) {
if (Jobs.getGCManager().fixAtMaxLevel) if (!Jobs.getGCManager().fixAtMaxLevel) {
level = jp.getLevel();
else {
level = jp.getLevel();
level = (int) (level - (level * (Jobs.getGCManager().levelLossPercentageFromMax / 100.0))); level = (int) (level - (level * (Jobs.getGCManager().levelLossPercentageFromMax / 100.0)));
if (level < 1) if (level < 1)
level = 1; level = 1;
@ -556,9 +554,7 @@ public class JobsPlayer {
exp = max.doubleValue(); exp = max.doubleValue();
if (exp > 0) { if (exp > 0) {
Job job = jp.getJob(); if (jp.getLevel() == getMaxJobLevelAllowed(jp.getJob())) {
int maxLevel = getMaxJobLevelAllowed(job);
if (jp.getLevel() == maxLevel) {
if (!Jobs.getGCManager().fixAtMaxLevel) if (!Jobs.getGCManager().fixAtMaxLevel)
exp = (exp - (exp * (Jobs.getGCManager().levelLossPercentageFromMax / 100.0))); exp = (exp - (exp * (Jobs.getGCManager().levelLossPercentageFromMax / 100.0)));
} else } else
@ -753,8 +749,7 @@ public class JobsPlayer {
} }
private static void processesChat(DisplayMethod method, StringBuilder builder, int level, Title title, Job job) { private static void processesChat(DisplayMethod method, StringBuilder builder, int level, Title title, Job job) {
String levelS = level < 0 ? "" : Integer.toString(level);
String levelS = level < 0 ? "" : String.valueOf(level);
switch (method) { switch (method) {
case FULL: case FULL:
processesTitle(builder, title, levelS); processesTitle(builder, title, levelS);
@ -893,11 +888,11 @@ public class JobsPlayer {
this.seen = seen; this.seen = seen;
} }
public HashMap<String, Boolean> getPermissionsCache() { public Map<String, Boolean> getPermissionsCache() {
return permissionsCache; return permissionsCache;
} }
public void setPermissionsCache(HashMap<String, Boolean> permissionsCache) { public void setPermissionsCache(Map<String, Boolean> permissionsCache) {
this.permissionsCache = permissionsCache; this.permissionsCache = permissionsCache;
} }
@ -952,7 +947,7 @@ public class JobsPlayer {
} }
public boolean inDailyQuest(Job job, String questName) { public boolean inDailyQuest(Job job, String questName) {
HashMap<String, QuestProgression> qpl = qProgression.get(job.getName()); Map<String, QuestProgression> qpl = qProgression.get(job.getName());
if (qpl == null) if (qpl == null)
return false; return false;
@ -969,7 +964,7 @@ public class JobsPlayer {
if (!isInJob(job)) if (!isInJob(job))
return ls; return ls;
HashMap<String, QuestProgression> qpl = qProgression.get(job.getName()); Map<String, QuestProgression> qpl = qProgression.get(job.getName());
if (qpl == null) if (qpl == null)
return ls; return ls;
@ -977,7 +972,7 @@ public class JobsPlayer {
if (prog.isEnded() || prog.getQuest() == null) if (prog.isEnded() || prog.getQuest() == null)
continue; continue;
for (HashMap<String, QuestObjective> oneAction : prog.getQuest().getObjectives().values()) { for (Map<String, QuestObjective> oneAction : prog.getQuest().getObjectives().values()) {
for (QuestObjective oneObjective : oneAction.values()) { for (QuestObjective oneObjective : oneAction.values()) {
if (type == null || type.name().equals(oneObjective.getAction().name())) { if (type == null || type.name().equals(oneObjective.getAction().name())) {
ls.add(prog.getQuest().getConfigName().toLowerCase()); ls.add(prog.getQuest().getConfigName().toLowerCase());
@ -1002,9 +997,7 @@ public class JobsPlayer {
Job job = oneQ.getQuest().getJob(); Job job = oneQ.getQuest().getJob();
getNewQuests(job); getNewQuests(job);
if (qProgression.containsKey(job.getName())) { qProgression.remove(job.getName());
qProgression.remove(job.getName());
}
} }
} }
@ -1017,11 +1010,11 @@ public class JobsPlayer {
} }
public void getNewQuests(Job job) { public void getNewQuests(Job job) {
java.util.Optional.ofNullable(qProgression.get(job.getName())).ifPresent(HashMap::clear); java.util.Optional.ofNullable(qProgression.get(job.getName())).ifPresent(Map::clear);
} }
public void replaceQuest(Quest quest) { public void replaceQuest(Quest quest) {
HashMap<String, QuestProgression> orprog = qProgression.get(quest.getJob().getName()); Map<String, QuestProgression> orProg = qProgression.get(quest.getJob().getName());
Quest q = quest.getJob().getNextQuest(getQuestNameList(quest.getJob(), null), getJobProgression(quest.getJob()).getLevel()); Quest q = quest.getJob().getNextQuest(getQuestNameList(quest.getJob(), null), getJobProgression(quest.getJob()).getLevel());
if (q == null) { if (q == null) {
@ -1037,7 +1030,7 @@ public class JobsPlayer {
if (q == null) if (q == null)
return; return;
HashMap<String, QuestProgression> prog = qProgression.get(q.getJob().getName()); Map<String, QuestProgression> prog = qProgression.get(q.getJob().getName());
if (prog == null) { if (prog == null) {
prog = new HashMap<>(); prog = new HashMap<>();
qProgression.put(q.getJob().getName(), prog); qProgression.put(q.getJob().getName(), prog);
@ -1052,9 +1045,10 @@ public class JobsPlayer {
if (q.getJob() != quest.getJob() && prog.size() >= q.getJob().getMaxDailyQuests()) if (q.getJob() != quest.getJob() && prog.size() >= q.getJob().getMaxDailyQuests())
return; return;
if (orprog != null) { if (orProg != null) {
orprog.remove(quest.getConfigName().toLowerCase()); orProg.remove(quest.getConfigName().toLowerCase());
} }
prog.put(q.getConfigName().toLowerCase(), new QuestProgression(q)); prog.put(q.getConfigName().toLowerCase(), new QuestProgression(q));
skippedQuests++; skippedQuests++;
} }
@ -1075,12 +1069,13 @@ public class JobsPlayer {
if (!isInJob(job)) if (!isInJob(job))
return new ArrayList<>(); return new ArrayList<>();
HashMap<String, QuestProgression> g = new HashMap<>(); Map<String, QuestProgression> g = new HashMap<>();
if (qProgression.get(job.getName()) != null) Map<String, QuestProgression> qProg = qProgression.get(job.getName());
g = new HashMap<>(qProgression.get(job.getName())); if (qProg != null)
g = new HashMap<>(qProg);
HashMap<String, QuestProgression> tmp = new HashMap<>(); Map<String, QuestProgression> tmp = new HashMap<>();
for (Entry<String, QuestProgression> one : (new HashMap<String, QuestProgression>(g)).entrySet()) { for (Entry<String, QuestProgression> one : (new HashMap<String, QuestProgression>(g)).entrySet()) {
QuestProgression qp = one.getValue(); QuestProgression qp = one.getValue();
@ -1134,7 +1129,7 @@ public class JobsPlayer {
continue; continue;
} }
HashMap<String, QuestObjective> old = q.getObjectives().get(type); Map<String, QuestObjective> old = q.getObjectives().get(type);
if (old != null) if (old != null)
for (QuestObjective one : old.values()) { for (QuestObjective one : old.values()) {
if (type.name().equals(one.getAction().name())) { if (type.name().equals(one.getAction().name())) {
@ -1160,7 +1155,7 @@ public class JobsPlayer {
prog += q.getJob().getName() + ":" + q.getConfigName() + ":" + one.getValidUntil() + ":"; prog += q.getJob().getName() + ":" + q.getConfigName() + ":" + one.getValidUntil() + ":";
for (HashMap<String, QuestObjective> oneA : q.getObjectives().values()) { for (Map<String, QuestObjective> oneA : q.getObjectives().values()) {
for (Entry<String, QuestObjective> oneO : oneA.entrySet()) { for (Entry<String, QuestObjective> oneO : oneA.entrySet()) {
prog += oneO.getValue().getAction().toString() + ";" + oneO.getKey() + ";" + one.getAmountDone(oneO.getValue()) + ":;:"; prog += oneO.getValue().getAction().toString() + ";" + oneO.getKey() + ";" + one.getAmountDone(oneO.getValue()) + ":;:";
} }
@ -1176,8 +1171,7 @@ public class JobsPlayer {
if (qprog == null || qprog.isEmpty()) if (qprog == null || qprog.isEmpty())
return; return;
String[] byJob = qprog.split(";:;"); for (String one : qprog.split(";:;")) {
for (String one : byJob) {
try { try {
String jname = one.split(":")[0]; String jname = one.split(":")[0];
Job job = Jobs.getJob(jname); Job job = Jobs.getJob(jname);
@ -1185,17 +1179,19 @@ public class JobsPlayer {
continue; continue;
one = one.substring(jname.length() + 1); one = one.substring(jname.length() + 1);
String qname = one.split(":")[0]; String qname = one.split(":")[0];
Quest quest = job.getQuest(qname); Quest quest = job.getQuest(qname);
if (quest == null) if (quest == null)
continue; continue;
one = one.substring(qname.length() + 1); one = one.substring(qname.length() + 1);
String longS = one.split(":")[0]; String longS = one.split(":")[0];
Long validUntil = Long.parseLong(longS); long validUntil = Long.parseLong(longS);
one = one.substring(longS.length() + 1); one = one.substring(longS.length() + 1);
HashMap<String, QuestProgression> currentProgression = qProgression.get(job.getName()); Map<String, QuestProgression> currentProgression = qProgression.get(job.getName());
if (currentProgression == null) { if (currentProgression == null) {
currentProgression = new HashMap<>(); currentProgression = new HashMap<>();
@ -1218,7 +1214,7 @@ public class JobsPlayer {
oneA = oneA.substring(prog.length() + 1); oneA = oneA.substring(prog.length() + 1);
String target = oneA.split(";")[0]; String target = oneA.split(";")[0];
HashMap<String, QuestObjective> old = quest.getObjectives().get(action); Map<String, QuestObjective> old = quest.getObjectives().get(action);
if (old == null) if (old == null)
continue; continue;
@ -1227,15 +1223,13 @@ public class JobsPlayer {
continue; continue;
oneA = oneA.substring(target.length() + 1); oneA = oneA.substring(target.length() + 1);
String doneS = oneA.split(";")[0];
int done = Integer.parseInt(doneS); qp.setAmountDone(obj, Integer.parseInt(oneA.split(";")[0]));
qp.setAmountDone(obj, done);
} }
if (qp.isCompleted()) if (qp.isCompleted())
qp.setGivenReward(true); qp.setGivenReward(true);
} catch (Exception e) {
} catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -1329,7 +1323,7 @@ public class JobsPlayer {
if (maxV == 0D && type == BlockTypes.SMOKER) if (maxV == 0D && type == BlockTypes.SMOKER)
maxV = (double) Jobs.getGCManager().SmokersMaxDefault; maxV = (double) Jobs.getGCManager().SmokersMaxDefault;
if (maxV == 0 && type == BlockTypes.BREWING_STAND) if (maxV == 0D && type == BlockTypes.BREWING_STAND)
maxV = (double) Jobs.getGCManager().getBrewingStandsMaxDefault(); maxV = (double) Jobs.getGCManager().getBrewingStandsMaxDefault();
return maxV.intValue(); return maxV.intValue();
@ -1343,7 +1337,7 @@ public class JobsPlayer {
this.skippedQuests = skippedQuests; this.skippedQuests = skippedQuests;
} }
public HashMap<UUID, HashMap<Job, Long>> getLeftTimes() { public Map<UUID, Map<Job, Long>> getLeftTimes() {
return leftTimes; return leftTimes;
} }
@ -1352,7 +1346,7 @@ public class JobsPlayer {
if (!leftTimes.containsKey(uuid)) if (!leftTimes.containsKey(uuid))
return false; return false;
HashMap<Job, Long> map = leftTimes.get(uuid); Map<Job, Long> map = leftTimes.get(uuid);
return map.containsKey(job) && map.get(job).longValue() < System.currentTimeMillis(); return map.containsKey(job) && map.get(job).longValue() < System.currentTimeMillis();
} }
@ -1371,7 +1365,7 @@ public class JobsPlayer {
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) + hour); cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) + hour);
HashMap<Job, Long> map = new HashMap<>(); Map<Job, Long> map = new HashMap<>();
map.put(job, cal.getTimeInMillis()); map.put(job, cal.getTimeInMillis());
leftTimes.put(uuid, map); leftTimes.put(uuid, map);
} }

View File

@ -1,13 +1,15 @@
package com.gamingmesh.jobs.container; package com.gamingmesh.jobs.container;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
import com.gamingmesh.jobs.stuff.TimeManage; import com.gamingmesh.jobs.stuff.TimeManage;
public final class Log { public final class Log {
private String action; private String action;
private int day; private int day;
private HashMap<String, LogAmounts> amountMap = new HashMap<>(); private Map<String, LogAmounts> amountMap = new HashMap<>();
public Log(String action) { public Log(String action) {
this.action = action; this.action = action;
@ -18,19 +20,19 @@ public final class Log {
return action; return action;
} }
public void add(String item, HashMap<CurrencyType, Double> amounts) { public void add(String item, Map<CurrencyType, Double> amounts) {
LogAmounts LAmount = amountMap.getOrDefault(item, new LogAmounts(item)); LogAmounts logAmount = amountMap.getOrDefault(item, new LogAmounts(item));
LAmount.addCount(); logAmount.addCount();
LAmount.add(amounts); logAmount.add(amounts);
this.amountMap.put(item, LAmount); this.amountMap.put(item, logAmount);
} }
public void add(String item, int count, HashMap<CurrencyType, Double> amounts) { public void add(String item, int count, Map<CurrencyType, Double> amounts) {
LogAmounts LAmount = amountMap.getOrDefault(item, new LogAmounts(item)); LogAmounts logAmount = amountMap.getOrDefault(item, new LogAmounts(item));
LAmount.setCount(count); logAmount.setCount(count);
LAmount.add(amounts); logAmount.add(amounts);
LAmount.setNewEntry(false); logAmount.setNewEntry(false);
this.amountMap.put(item, LAmount); this.amountMap.put(item, logAmount);
} }
public void setDate() { public void setDate() {
@ -41,19 +43,15 @@ public final class Log {
return day; return day;
} }
public HashMap<String, LogAmounts> getAmountList() { public Map<String, LogAmounts> getAmountList() {
return amountMap; return amountMap;
} }
public int getCount(String item) { public int getCount(String item) {
if (this.amountMap.containsKey(item)) return amountMap.containsKey(item) ? amountMap.get(item).getCount() : 0;
return this.amountMap.get(item).getCount();
return 0;
} }
public double get(String item, CurrencyType type) { public double get(String item, CurrencyType type) {
if (this.amountMap.containsKey(item)) return amountMap.containsKey(item) ? amountMap.get(item).get(type) : 0;
return this.amountMap.get(item).get(type);
return 0;
} }
} }

View File

@ -1,6 +1,7 @@
package com.gamingmesh.jobs.container; package com.gamingmesh.jobs.container;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
public final class LogAmounts { public final class LogAmounts {
@ -11,7 +12,7 @@ public final class LogAmounts {
private String item; private String item;
private int count = 0; private int count = 0;
private HashMap<CurrencyType, Double> amounts = new HashMap<>(); private Map<CurrencyType, Double> amounts = new HashMap<>();
private boolean newEntry = true; private boolean newEntry = true;
@ -31,7 +32,7 @@ public final class LogAmounts {
return item; return item;
} }
public void add(HashMap<CurrencyType, Double> amounts) { public void add(Map<CurrencyType, Double> amounts) {
for (Entry<CurrencyType, Double> one : amounts.entrySet()) { for (Entry<CurrencyType, Double> one : amounts.entrySet()) {
add(one.getKey(), one.getValue()); add(one.getKey(), one.getValue());
} }

View File

@ -1779,10 +1779,10 @@ public abstract class JobsDAO {
} }
public PlayerInfo loadPlayerData(UUID uuid) { public PlayerInfo loadPlayerData(UUID uuid) {
PlayerInfo pInfo = null;
JobsConnection conn = getConnection(); JobsConnection conn = getConnection();
if (conn == null) if (conn == null)
return pInfo; return null;
PlayerInfo pInfo = null;
PreparedStatement prest = null; PreparedStatement prest = null;
ResultSet res = null; ResultSet res = null;
try { try {

View File

@ -24,7 +24,6 @@ import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
@ -32,13 +31,10 @@ import com.gamingmesh.jobs.CMILib.CMIChatColor;
import com.gamingmesh.jobs.config.YmlMaker; import com.gamingmesh.jobs.config.YmlMaker;
public class Language { public class Language {
public FileConfiguration enlocale;
public FileConfiguration customlocale;
private Jobs plugin;
public Language(Jobs plugin) { public FileConfiguration enlocale, customlocale;
this.plugin = plugin;
} private final Pattern patern = Pattern.compile("([ ]?[\\/][n][$|\\s])");
/** /**
* Reloads the config * Reloads the config
@ -68,11 +64,10 @@ public class Language {
msg = enlocale.isString(key) ? CMIChatColor.translate(enlocale.getString(key)) : missing; msg = enlocale.isString(key) ? CMIChatColor.translate(enlocale.getString(key)) : missing;
else else
msg = customlocale.isString(key) ? CMIChatColor.translate(customlocale.getString(key)) : missing; msg = customlocale.isString(key) ? CMIChatColor.translate(customlocale.getString(key)) : missing;
} catch (Throwable e) { } catch (Exception e) {
Jobs.consoleMsg("&e[Jobs] &2Can't read language file for: " + key); Jobs.consoleMsg("&e[Jobs] &2Can't read language file for: " + key);
Bukkit.getServer().getPluginManager().disablePlugin(plugin); Jobs.consoleMsg(e.getLocalizedMessage());
e.printStackTrace(); return "";
throw e;
} }
if (msg.isEmpty() || msg.equals(missing)) { if (msg.isEmpty() || msg.equals(missing)) {
@ -81,20 +76,19 @@ public class Language {
List<String> ls = null; List<String> ls = null;
if (customlocale != null && customlocale.isList(key)) if (customlocale != null && customlocale.isList(key))
ls = ColorsArray(customlocale.getStringList(key), true); ls = colorsArray(customlocale.getStringList(key), true);
else if (enlocale.isList(key)) else if (enlocale.isList(key))
ls = !enlocale.getStringList(key).isEmpty() ? ColorsArray(enlocale.getStringList(key), true) : Arrays.asList(missing); ls = !enlocale.getStringList(key).isEmpty() ? colorsArray(enlocale.getStringList(key), true) : Arrays.asList(missing);
if (ls != null) if (ls != null)
for (String one : ls) { for (String one : ls) {
if (!msg.isEmpty()) if (!msg.isEmpty())
msg += "\n"; msg += "\n";
msg += one; msg += one;
} }
} catch (Throwable e) { } catch (Exception e) {
Jobs.consoleMsg("&e[Jobs] &2Can't read language file for: " + key); Jobs.consoleMsg("&e[Jobs] &2Can't read language file for: " + key);
Bukkit.getServer().getPluginManager().disablePlugin(plugin); Jobs.consoleMsg(e.getLocalizedMessage());
e.printStackTrace(); return "";
throw e;
} }
} }
@ -118,9 +112,9 @@ public class Language {
List<String> ls; List<String> ls;
if (customlocale.isList(key)) if (customlocale.isList(key))
ls = ColorsArray(customlocale.getStringList(key), true); ls = colorsArray(customlocale.getStringList(key), true);
else else
ls = !enlocale.getStringList(key).isEmpty() ? ColorsArray(enlocale.getStringList(key), true) : Arrays.asList(missing); ls = !enlocale.getStringList(key).isEmpty() ? colorsArray(enlocale.getStringList(key), true) : Arrays.asList(missing);
if (variables != null && variables.length > 0) if (variables != null && variables.length > 0)
for (int i = 0; i < ls.size(); i++) { for (int i = 0; i < ls.size(); i++) {
@ -128,15 +122,14 @@ public class Language {
for (int y = 0; y < variables.length; y += 2) { for (int y = 0; y < variables.length; y += 2) {
msg = msg.replace(String.valueOf(variables[y]), String.valueOf(variables[y + 1])); msg = msg.replace(String.valueOf(variables[y]), String.valueOf(variables[y + 1]));
} }
msg = filterNewLine(msg);
ls.set(i, CMIChatColor.translate(msg)); ls.set(i, CMIChatColor.translate(filterNewLine(msg)));
} }
return ls; return ls;
} }
public String filterNewLine(String msg) { public String filterNewLine(String msg) {
Pattern patern = Pattern.compile("([ ]?[\\/][n][$|\\s])");
Matcher match = patern.matcher(msg); Matcher match = patern.matcher(msg);
while (match.find()) { while (match.find()) {
msg = msg.replace(match.group(0), "\n"); msg = msg.replace(match.group(0), "\n");
@ -144,7 +137,7 @@ public class Language {
return msg; return msg;
} }
public List<String> ColorsArray(List<String> text, boolean colorize) { public List<String> colorsArray(List<String> text, boolean colorize) {
List<String> temp = new ArrayList<>(); List<String> temp = new ArrayList<>();
for (String part : text) { for (String part : text) {
if (colorize) if (colorize)

View File

@ -196,13 +196,13 @@ public class JobsListener implements Listener {
return; return;
Sign sign = (Sign) block.getState(); Sign sign = (Sign) block.getState();
String FirstLine = plugin.getComplement().getLine(sign, 0);
if (!CMIChatColor.stripColor(FirstLine).equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.topline")))) if (!CMIChatColor.stripColor(plugin.getComplement().getLine(sign, 0)).equalsIgnoreCase(
CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.topline"))))
return; return;
String command = CMIChatColor.stripColor(plugin.getComplement().getLine(sign, 1)); String command = CMIChatColor.stripColor(plugin.getComplement().getLine(sign, 1));
for (String key : Jobs.getGCManager().keys) { for (String key : Jobs.getLanguageManager().signKeys) {
if (command.equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.secondline." + key)))) { if (command.equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.secondline." + key)))) {
command = key; command = key;
break; break;
@ -224,8 +224,8 @@ public class JobsListener implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
Sign sign = (Sign) block.getState(); Sign sign = (Sign) block.getState();
String firstLine = plugin.getComplement().getLine(sign, 0); if (plugin.getComplement().getLine(sign, 0).contains(Jobs.getLanguage().getMessage("signs.topline"))
if (firstLine.contains(Jobs.getLanguage().getMessage("signs.topline")) && !player.hasPermission("jobs.command.signs")) { && !player.hasPermission("jobs.command.signs")) {
event.setCancelled(true); event.setCancelled(true);
player.sendMessage(Jobs.getLanguage().getMessage("signs.cantdestroy")); player.sendMessage(Jobs.getLanguage().getMessage("signs.cantdestroy"));
return; return;
@ -270,8 +270,7 @@ public class JobsListener implements Listener {
return; return;
} }
String jobname = CMIChatColor.stripColor(plugin.getComplement().getLine(sign, 2)).toLowerCase(); final Job job = Jobs.getJob(CMIChatColor.stripColor(plugin.getComplement().getLine(sign, 2)).toLowerCase());
final Job job = Jobs.getJob(jobname);
if (type == SignTopType.toplist && job == null) { if (type == SignTopType.toplist && job == null) {
player.sendMessage(Jobs.getLanguage().getMessage("command.top.error.nojob")); player.sendMessage(Jobs.getLanguage().getMessage("command.top.error.nojob"));
return; return;
@ -294,8 +293,7 @@ public class JobsListener implements Listener {
jobsSign signInfo = new jobsSign(); jobsSign signInfo = new jobsSign();
Location loc = sign.getLocation(); signInfo.setLoc(sign.getLocation());
signInfo.setLoc(loc);
signInfo.setNumber(number); signInfo.setNumber(number);
if (job != null) if (job != null)
signInfo.setJobName(job.getName()); signInfo.setJobName(job.getName());
@ -331,7 +329,7 @@ public class JobsListener implements Listener {
} }
String command = CMIChatColor.stripColor(plugin.getComplement().getLine(event, 1)).toLowerCase(); String command = CMIChatColor.stripColor(plugin.getComplement().getLine(event, 1)).toLowerCase();
for (String key : Jobs.getGCManager().keys) { for (String key : Jobs.getLanguageManager().signKeys) {
if (command.equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.secondline." + key)))) { if (command.equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.secondline." + key)))) {
plugin.getComplement().setLine(event, 1, convert(Jobs.getLanguage().getMessage("signs.secondline." + key))); plugin.getComplement().setLine(event, 1, convert(Jobs.getLanguage().getMessage("signs.secondline." + key)));
break; break;
@ -346,8 +344,10 @@ public class JobsListener implements Listener {
plugin.getComplement().setLine(event, 2, convert(color + job.getName())); plugin.getComplement().setLine(event, 2, convert(color + job.getName()));
} }
private final Pattern pattern = Pattern.compile("&([0-9a-fk-or])");
private String convert(String line) { private String convert(String line) {
return Pattern.compile("&([0-9a-fk-or])").matcher(CMIChatColor.translate(line)).replaceAll("\u00a7$1"); return pattern.matcher(CMIChatColor.translate(line)).replaceAll("\u00a7$1");
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@ -425,15 +425,13 @@ public class JobsListener implements Listener {
} }
} }
boolean foundEnc = false;
for (Entry<Enchantment, Integer> oneE : enchants.entrySet()) { for (Entry<Enchantment, Integer> oneE : enchants.entrySet()) {
if (oneItem.getenchants().containsKey(oneE.getKey()) && oneItem.getenchants().get(oneE.getKey()) <= oneE.getValue()) { if (oneItem.getEnchants().containsKey(oneE.getKey()) && oneItem.getEnchants().get(oneE.getKey()) <= oneE.getValue()) {
foundEnc = true; return true;
break;
} }
} }
return foundEnc; return false;
} }
@EventHandler @EventHandler

View File

@ -25,9 +25,7 @@ public class v1_10 implements NMS {
@Override @Override
public List<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) { public List<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) {
List<Block> blocks = new ArrayList<>(); return new ArrayList<>(event.getBlocks());
blocks.addAll(event.getBlocks());
return blocks;
} }
@Override @Override

View File

@ -19,9 +19,7 @@ public class v1_11 implements NMS {
@Override @Override
public List<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) { public List<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) {
List<Block> blocks = new ArrayList<>(); return new ArrayList<>(event.getBlocks());
blocks.addAll(event.getBlocks());
return blocks;
} }
@Override @Override

View File

@ -20,9 +20,7 @@ public class v1_12 implements NMS {
@Override @Override
public List<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) { public List<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) {
List<Block> blocks = new ArrayList<>(); return new ArrayList<>(event.getBlocks());
blocks.addAll(event.getBlocks());
return blocks;
} }
@Override @Override

View File

@ -20,9 +20,7 @@ public class v1_13 implements NMS {
@Override @Override
public List<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) { public List<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) {
List<Block> blocks = new ArrayList<>(); return new ArrayList<>(event.getBlocks());
blocks.addAll(event.getBlocks());
return blocks;
} }
@Override @Override

View File

@ -20,9 +20,7 @@ public class v1_14 implements NMS {
@Override @Override
public List<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) { public List<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) {
List<Block> blocks = new ArrayList<>(); return new ArrayList<>(event.getBlocks());
blocks.addAll(event.getBlocks());
return blocks;
} }
@Override @Override

View File

@ -20,9 +20,7 @@ public class v1_15 implements NMS {
@Override @Override
public List<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) { public List<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) {
List<Block> blocks = new ArrayList<>(); return new ArrayList<>(event.getBlocks());
blocks.addAll(event.getBlocks());
return blocks;
} }
@Override @Override

View File

@ -20,9 +20,7 @@ public class v1_16 implements NMS {
@Override @Override
public List<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) { public List<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) {
List<Block> blocks = new ArrayList<>(); return new ArrayList<>(event.getBlocks());
blocks.addAll(event.getBlocks());
return blocks;
} }
@Override @Override

View File

@ -25,9 +25,7 @@ public class v1_8 implements NMS {
@Override @Override
public List<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) { public List<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) {
List<Block> blocks = new ArrayList<>(); return new ArrayList<>(event.getBlocks());
blocks.addAll(event.getBlocks());
return blocks;
} }
@Override @Override

View File

@ -25,9 +25,7 @@ public class v1_9 implements NMS {
@Override @Override
public List<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) { public List<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) {
List<Block> blocks = new ArrayList<>(); return new ArrayList<>(event.getBlocks());
blocks.addAll(event.getBlocks());
return blocks;
} }
@Override @Override

View File

@ -1,8 +1,6 @@
package com.gamingmesh.jobs.stuff; package com.gamingmesh.jobs.stuff;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -13,7 +11,6 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.CMIChatColor; import com.gamingmesh.jobs.CMILib.CMIChatColor;
@ -25,20 +22,20 @@ public class CMIScoreboardManager {
private ConcurrentHashMap<UUID, ScoreboardInfo> timerMap = new ConcurrentHashMap<>(); private ConcurrentHashMap<UUID, ScoreboardInfo> timerMap = new ConcurrentHashMap<>();
private void RunScheduler() { private void runScheduler() {
Iterator<Entry<UUID, ScoreboardInfo>> MeinMapIter = timerMap.entrySet().iterator(); Iterator<Entry<UUID, ScoreboardInfo>> meinMapIter = timerMap.entrySet().iterator();
while (MeinMapIter.hasNext()) { while (meinMapIter.hasNext()) {
Entry<UUID, ScoreboardInfo> Map = MeinMapIter.next(); Entry<UUID, ScoreboardInfo> map = meinMapIter.next();
if (System.currentTimeMillis() > Map.getValue().getTime() + (Jobs.getGCManager().ToplistInScoreboardInterval * 1000)) { if (System.currentTimeMillis() > map.getValue().getTime() + (Jobs.getGCManager().ToplistInScoreboardInterval * 1000)) {
Player player = Bukkit.getPlayer(Map.getKey()); Player player = Bukkit.getPlayer(map.getKey());
if (player != null) { if (player != null) {
removeScoreBoard(player); removeScoreBoard(player);
player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
if (Map.getValue().getObj() != null) { if (map.getValue().getObj() != null) {
try { try {
Objective obj = player.getScoreboard().getObjective(Map.getValue().getObj().getName()); Objective obj = player.getScoreboard().getObjective(map.getValue().getObj().getName());
if (obj != null) if (obj != null)
obj.setDisplaySlot(DisplaySlot.SIDEBAR); obj.setDisplaySlot(DisplaySlot.SIDEBAR);
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
@ -46,47 +43,92 @@ public class CMIScoreboardManager {
} }
} }
timerMap.remove(Map.getKey()); timerMap.remove(map.getKey());
} }
} }
if (timerMap.size() > 0) if (timerMap.size() > 0)
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Jobs.getInstance(), this::RunScheduler, 20L); Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Jobs.getInstance(), this::runScheduler, 20L);
} }
public void addNew(Player player) { public void addNew(Player player) {
Scoreboard scoreBoard = player.getScoreboard(); timerMap.put(player.getUniqueId(), new ScoreboardInfo(player.getScoreboard(), DisplaySlot.SIDEBAR));
timerMap.put(player.getUniqueId(), new ScoreboardInfo(scoreBoard, DisplaySlot.SIDEBAR)); runScheduler();
RunScheduler();
} }
private final String objName = "CMIScoreboard"; private final String objName = "CMIScoreboard";
public void removeScoreBoard(Player player) { public void removeScoreBoard(Player player) {
try { try {
Class<?> boardClass = getNMSClass("Scoreboard");
Object boards = boardClass.getConstructor().newInstance();
if (Version.isCurrentEqualOrHigher(Version.v1_13_R1)) { if (Version.isCurrentEqualOrHigher(Version.v1_13_R1)) {
Class<?> p0 = getNMSClass("PacketPlayOutScoreboardObjective"); Object pp1 = getNMSClass("PacketPlayOutScoreboardObjective").getConstructor().newInstance();
Constructor<?> p00 = p0.getConstructor();
Object pp1 = p00.newInstance();
setField(pp1, "a", player.getName()); setField(pp1, "a", player.getName());
setField(pp1, "d", 1); setField(pp1, "d", 1);
sendPacket(player, pp1); sendPacket(player, pp1);
} else { } else {
Method m = boards.getClass().getMethod("registerObjective", String.class, getNMSClass("IScoreboardCriteria")); Object boards = getNMSClass("Scoreboard").getConstructor().newInstance();
Class<?> IScoreboardCriterias = getNMSClass("ScoreboardBaseCriteria"); Object obj = boards.getClass().getMethod("registerObjective", String.class,
Constructor<?> IScoreboardCriteriasConst = IScoreboardCriterias.getConstructor(String.class); getNMSClass("IScoreboardCriteria")).invoke(boards, objName,
Object IScoreboardCriteria = IScoreboardCriteriasConst.newInstance("JobsDummy"); getNMSClass("ScoreboardBaseCriteria").getConstructor(String.class).newInstance("JobsDummy"));
sendPacket(player, getNMSClass("PacketPlayOutScoreboardObjective").getConstructor(obj.getClass(), int.class).newInstance(obj, 1));
}
} catch (Exception e) {
e.printStackTrace();
}
}
Object obj = m.invoke(boards, objName, IScoreboardCriteria); public void setScoreBoard(Player player, String displayName, List<String> lines) {
Class<?> p1 = getNMSClass("PacketPlayOutScoreboardObjective"); removeScoreBoard(player);
Constructor<?> p11 = p1.getConstructor(obj.getClass(), int.class);
Object pp1 = p11.newInstance(obj, 1); try {
if (Version.isCurrentEqualOrHigher(Version.v1_13_R1)) {
Object pp1 = getNMSClass("PacketPlayOutScoreboardObjective").getConstructor().newInstance();
setField(pp1, "a", player.getName());
setField(pp1, "d", 0);
setField(pp1, "b", getNMSClass("ChatComponentText").getConstructor(String.class).newInstance(CMIChatColor.translate(displayName)));
setField(pp1, "c", getNMSClass("IScoreboardCriteria$EnumScoreboardHealthDisplay").getEnumConstants()[1]);
sendPacket(player, pp1); sendPacket(player, pp1);
Object d0 = getNMSClass("PacketPlayOutScoreboardDisplayObjective").getConstructor().newInstance();
setField(d0, "a", 1);
setField(d0, "b", player.getName());
sendPacket(player, d0);
for (int i = 0; i < 15; i++) {
if (i >= lines.size())
break;
Object PacketPlayOutScoreboardScore = getNMSClass("PacketPlayOutScoreboardScore").getConstructor().newInstance();
setField(PacketPlayOutScoreboardScore, "a", CMIChatColor.translate(lines.get(i)));
setField(PacketPlayOutScoreboardScore, "b", player.getName());
setField(PacketPlayOutScoreboardScore, "c", 15 - i);
setField(PacketPlayOutScoreboardScore, "d", getNMSClass("ScoreboardServer$Action").getEnumConstants()[0]);
sendPacket(player, PacketPlayOutScoreboardScore);
}
} else {
Object boards = getNMSClass("Scoreboard").getConstructor().newInstance();
Object obj = boards.getClass().getMethod("registerObjective", String.class, getNMSClass("IScoreboardCriteria"))
.invoke(boards, objName, getNMSClass("ScoreboardBaseCriteria").getConstructor(String.class).newInstance("JobsDummy"));
obj.getClass().getMethod("setDisplayName", String.class).invoke(obj, CMIChatColor.translate(displayName));
sendPacket(player, getNMSClass("PacketPlayOutScoreboardObjective").getConstructor(obj.getClass(), int.class).newInstance(obj, 1));
sendPacket(player, getNMSClass("PacketPlayOutScoreboardObjective").getConstructor(obj.getClass(), int.class).newInstance(obj, 0));
sendPacket(player, getNMSClass("PacketPlayOutScoreboardDisplayObjective").getConstructor(int.class,
getNMSClass("ScoreboardObjective")).newInstance(1, obj));
for (int i = 0; i < 15; i++) {
if (i >= lines.size())
break;
Object packet2 = getNMSClass("ScoreboardScore").getConstructor(getNMSClass("Scoreboard"),
getNMSClass("ScoreboardObjective"), String.class).newInstance(boards, obj, CMIChatColor.translate(lines.get(i)));
packet2.getClass().getMethod("setScore", int.class).invoke(packet2, 15 - i);
sendPacket(player, getNMSClass("PacketPlayOutScoreboardScore").getConstructor(getNMSClass("ScoreboardScore")).newInstance(packet2));
}
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -103,101 +145,9 @@ public class CMIScoreboardManager {
} }
} }
public void setScoreBoard(Player player, String displayName, List<String> lines) {
removeScoreBoard(player);
try {
Class<?> boardClass = getNMSClass("Scoreboard");
Object boards = boardClass.getConstructor().newInstance();
if (Version.isCurrentEqualOrHigher(Version.v1_13_R1)) {
Class<?> enums = getNMSClass("IScoreboardCriteria$EnumScoreboardHealthDisplay");
Class<?> p0 = getNMSClass("PacketPlayOutScoreboardObjective");
Constructor<?> p00 = p0.getConstructor();
Object pp1 = p00.newInstance();
setField(pp1, "a", player.getName());
setField(pp1, "d", 0);
Object chatComponentText = getNMSClass("ChatComponentText").getConstructor(String.class).newInstance(CMIChatColor.translate(displayName));
setField(pp1, "b", chatComponentText);
setField(pp1, "c", enums.getEnumConstants()[1]);
sendPacket(player, pp1);
Object d0 = getNMSClass("PacketPlayOutScoreboardDisplayObjective").getConstructor().newInstance();
setField(d0, "a", 1);
setField(d0, "b", player.getName());
sendPacket(player, d0);
for (int i = 0; i < 15; i++) {
if (i >= lines.size())
break;
String ln = CMIChatColor.translate(lines.get(i));
Class<?> PacketPlayOutScoreboardScoreClass = getNMSClass("PacketPlayOutScoreboardScore");
Constructor<?> PacketPlayOutScoreboardScoreConstructor = PacketPlayOutScoreboardScoreClass.getConstructor();
Object PacketPlayOutScoreboardScore = PacketPlayOutScoreboardScoreConstructor.newInstance();
Class<?> aenums = getNMSClass("ScoreboardServer$Action");
setField(PacketPlayOutScoreboardScore, "a", ln);
setField(PacketPlayOutScoreboardScore, "b", player.getName());
setField(PacketPlayOutScoreboardScore, "c", 15 - i);
setField(PacketPlayOutScoreboardScore, "d", aenums.getEnumConstants()[0]);
sendPacket(player, PacketPlayOutScoreboardScore);
}
} else {
Method m = boards.getClass().getMethod("registerObjective", String.class, getNMSClass("IScoreboardCriteria"));
Class<?> IScoreboardCriterias = getNMSClass("ScoreboardBaseCriteria");
Constructor<?> IScoreboardCriteriasConst = IScoreboardCriterias.getConstructor(String.class);
Object IScoreboardCriteria = IScoreboardCriteriasConst.newInstance("JobsDummy");
Object obj = m.invoke(boards, objName, IScoreboardCriteria);
Method mm = obj.getClass().getMethod("setDisplayName", String.class);
mm.invoke(obj, CMIChatColor.translate(displayName));
Class<?> p1 = getNMSClass("PacketPlayOutScoreboardObjective");
Constructor<?> p11 = p1.getConstructor(obj.getClass(), int.class);
Object pp1 = p11.newInstance(obj, 1);
sendPacket(player, pp1);
Class<?> p2 = getNMSClass("PacketPlayOutScoreboardObjective");
Constructor<?> p12 = p2.getConstructor(obj.getClass(), int.class);
Object pp2 = p12.newInstance(obj, 0);
sendPacket(player, pp2);
Class<?> packetClass = getNMSClass("PacketPlayOutScoreboardDisplayObjective");
Constructor<?> packetConstructor = packetClass.getConstructor(int.class, getNMSClass("ScoreboardObjective"));
Object packet = packetConstructor.newInstance(1, obj);
sendPacket(player, packet);
for (int i = 0; i < 15; i++) {
if (i >= lines.size())
break;
String ln = CMIChatColor.translate(lines.get(i));
Class<?> ScoreboardScoreClass = getNMSClass("ScoreboardScore");
Constructor<?> packetConstructor2 = ScoreboardScoreClass.getConstructor(getNMSClass("Scoreboard"), getNMSClass("ScoreboardObjective"), String.class);
Object packet2 = packetConstructor2.newInstance(boards, obj, ln);
Method mc = packet2.getClass().getMethod("setScore", int.class);
mc.invoke(packet2, 15 - i);
Class<?> PacketPlayOutScoreboardScoreClass = getNMSClass("PacketPlayOutScoreboardScore");
Constructor<?> PacketPlayOutScoreboardScoreConstructor = PacketPlayOutScoreboardScoreClass.getConstructor(getNMSClass("ScoreboardScore"));
Object PacketPlayOutScoreboardScore = PacketPlayOutScoreboardScoreConstructor.newInstance(packet2);
sendPacket(player, PacketPlayOutScoreboardScore);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static void sendPacket(Player player, Object packet) { private static void sendPacket(Player player, Object packet) {
Method sendPacket;
try { try {
sendPacket = getNMSClass("PlayerConnection").getMethod("sendPacket", getNMSClass("Packet")); getNMSClass("PlayerConnection").getMethod("sendPacket", getNMSClass("Packet")).invoke(getConnection(player), packet);
sendPacket.invoke(getConnection(player), packet);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -208,10 +158,7 @@ public class CMIScoreboardManager {
} }
private static Object getConnection(Player player) throws Exception { private static Object getConnection(Player player) throws Exception {
Method getHandle = player.getClass().getMethod("getHandle"); Object nmsPlayer = player.getClass().getMethod("getHandle").invoke(player);
Object nmsPlayer = getHandle.invoke(player); return nmsPlayer.getClass().getField("playerConnection").get(nmsPlayer);
Field conField = nmsPlayer.getClass().getField("playerConnection");
Object con = conField.get(nmsPlayer);
return con;
} }
} }

View File

@ -16,11 +16,15 @@ import com.gamingmesh.jobs.CMILib.CMIChatColor;
import com.gamingmesh.jobs.CMILib.CMIMaterial; import com.gamingmesh.jobs.CMILib.CMIMaterial;
public class GiveItem { public class GiveItem {
public static void GiveItemForPlayer(Player player, int id, int meta, int qty, String name, List<String> lore,
public static void giveItemForPlayer(Player player, int id, int meta, int qty, String name, List<String> lore,
HashMap<Enchantment, Integer> enchants) { HashMap<Enchantment, Integer> enchants) {
ItemStack itemStack = CMIMaterial.get(id, meta).newItemStack(); ItemStack itemStack = CMIMaterial.get(id, meta).newItemStack();
itemStack.setAmount(qty); itemStack.setAmount(qty);
ItemMeta itemMeta = itemStack.getItemMeta(); ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) {
return;
}
if (lore != null && !lore.isEmpty()) { if (lore != null && !lore.isEmpty()) {
List<String> translatedLore = new ArrayList<>(); List<String> translatedLore = new ArrayList<>();
@ -48,10 +52,10 @@ public class GiveItem {
Jobs.getInstance().getComplement().setDisplayName(itemMeta, CMIChatColor.translate(name)); Jobs.getInstance().getComplement().setDisplayName(itemMeta, CMIChatColor.translate(name));
itemStack.setItemMeta(itemMeta); itemStack.setItemMeta(itemMeta);
GiveItemForPlayer(player, itemStack); giveItemForPlayer(player, itemStack);
} }
public static void GiveItemForPlayer(Player player, ItemStack item) { public static void giveItemForPlayer(Player player, ItemStack item) {
player.getInventory().addItem(item); player.getInventory().addItem(item);
player.updateInventory(); player.updateInventory();
} }

View File

@ -1,6 +1,6 @@
package com.gamingmesh.jobs.stuff; package com.gamingmesh.jobs.stuff;
import java.util.HashMap; import java.util.Map;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.ActionInfo; import com.gamingmesh.jobs.container.ActionInfo;
@ -10,26 +10,25 @@ import com.gamingmesh.jobs.container.Log;
public class Loging { public class Loging {
public void recordToLog(JobsPlayer jPlayer, ActionInfo info, HashMap<CurrencyType, Double> amounts) { public void recordToLog(JobsPlayer jPlayer, ActionInfo info, Map<CurrencyType, Double> amounts) {
recordToLog(jPlayer, info.getType().getName(), info.getNameWithSub(), amounts); recordToLog(jPlayer, info.getType().getName(), info.getNameWithSub(), amounts);
} }
public void recordToLog(JobsPlayer jPlayer, String ActionName, String item, HashMap<CurrencyType, Double> amounts) { public void recordToLog(JobsPlayer jPlayer, String actionName, String item, Map<CurrencyType, Double> amounts) {
HashMap<String, Log> logList = jPlayer.getLog(); Map<String, Log> logList = jPlayer.getLog();
Log l = logList.values().stream().findFirst().orElse(null); Log l = logList.values().stream().findFirst().orElse(null);
if (l != null && TimeManage.timeInInt() != l.getDate()) { if (l != null && TimeManage.timeInInt() != l.getDate()) {
Jobs.getJobsDAO().saveLog(jPlayer); Jobs.getJobsDAO().saveLog(jPlayer);
jPlayer.getLog().clear(); jPlayer.getLog().clear();
} }
Log log = logList.getOrDefault(ActionName, new Log(ActionName)); Log log = logList.getOrDefault(actionName, new Log(actionName));
log.add(item, amounts); log.add(item, amounts);
logList.put(ActionName, log); logList.put(actionName, log);
} }
public void loadToLog(JobsPlayer jPlayer, String ActionName, String item, int count, HashMap<CurrencyType, Double> amounts) { public void loadToLog(JobsPlayer jPlayer, String actionName, String item, int count, Map<CurrencyType, Double> amounts) {
Log log = jPlayer.getLog().getOrDefault(ActionName, new Log(ActionName)); jPlayer.getLog().getOrDefault(actionName, new Log(actionName)).add(item, count, amounts);
log.add(item, count, amounts);
} }
} }

View File

@ -9,7 +9,6 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter; import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.util.StringUtil; import org.bukkit.util.StringUtil;
import com.gamingmesh.jobs.ItemBoostManager; import com.gamingmesh.jobs.ItemBoostManager;
@ -29,25 +28,24 @@ public class TabComplete implements TabCompleter {
List<String> completionList = new ArrayList<>(); List<String> completionList = new ArrayList<>();
if (args.length == 1) { if (args.length == 1) {
String PartOfCommand = args[0];
List<String> temp = new ArrayList<>(); List<String> temp = new ArrayList<>();
Jobs.getCommandManager().getCommands(sender).forEach(temp::add); temp.addAll(Jobs.getCommandManager().getCommands(sender));
StringUtil.copyPartialMatches(PartOfCommand, temp, completionList); StringUtil.copyPartialMatches(args[0], temp, completionList);
} }
if (args.length > 1) if (args.length > 1)
for (int i = 1; i <= args.length; i++) for (int i = 1; i <= args.length; i++)
if (args.length == i + 1) { if (args.length == i + 1) {
String PartOfCommand = args[i]; String partOfCommand = args[i];
if (!Jobs.getGCManager().getCommandArgs().containsKey(args[0].toLowerCase())) if (!Jobs.getGCManager().getCommandArgs().containsKey(args[0].toLowerCase()))
break; break;
List<String> ArgsList = Jobs.getGCManager().getCommandArgs().get(args[0].toLowerCase()); List<String> argsList = Jobs.getGCManager().getCommandArgs().get(args[0].toLowerCase());
if (ArgsList.size() < i) if (argsList.size() < i)
continue; continue;
String arg = ArgsList.get(i - 1); String arg = argsList.get(i - 1);
List<String> t2 = new ArrayList<>(); List<String> t2 = new ArrayList<>();
if (arg.contains("%%")) if (arg.contains("%%"))
@ -61,7 +59,7 @@ public class TabComplete implements TabCompleter {
for (String ar : t2) { for (String ar : t2) {
switch (ar) { switch (ar) {
case "[scheduleName]": case "[scheduleName]":
Jobs.getScheduleManager().getConf().getConfig().getConfigurationSection("Boost").getKeys(false).forEach(temp::add); temp.addAll(Jobs.getScheduleManager().getConf().getConfig().getConfigurationSection("Boost").getKeys(false));
break; break;
case "[time]": case "[time]":
temp.add("1hour10minute20s"); temp.add("1hour10minute20s");
@ -82,15 +80,11 @@ public class TabComplete implements TabCompleter {
} }
break; break;
case "[playername]": case "[playername]":
pl: for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
// ignore hidden players // ignore hidden players
if (Jobs.getGCManager().FilterHiddenPlayerFromTabComplete && player.hasMetadata("vanished")) { if (Jobs.getGCManager().FilterHiddenPlayerFromTabComplete && (player.hasMetadata("vanished")
// TODO add essentials & cmi support || (sender instanceof Player && ((Player) sender).canSee(player)))) {
for (MetadataValue meta : player.getMetadata("vanished")) { continue;
if (meta.asBoolean()) {
continue pl;
}
}
} }
temp.add(player.getName()); temp.add(player.getName());
@ -127,8 +121,7 @@ public class TabComplete implements TabCompleter {
break; break;
case "[oldplayerjob]": case "[oldplayerjob]":
if (sender instanceof Player) { if (sender instanceof Player) {
onePlayerJob = Jobs.getPlayerManager().getJobsPlayer((Player) sender); if ((onePlayerJob = Jobs.getPlayerManager().getJobsPlayer((Player) sender)) != null)
if (onePlayerJob != null)
for (JobProgression oneOldJob : onePlayerJob.getJobProgression()) { for (JobProgression oneOldJob : onePlayerJob.getJobProgression()) {
temp.add(oneOldJob.getJob().getName()); temp.add(oneOldJob.getJob().getName());
} }
@ -140,7 +133,7 @@ public class TabComplete implements TabCompleter {
} }
} }
StringUtil.copyPartialMatches(PartOfCommand, temp, completionList); StringUtil.copyPartialMatches(partOfCommand, temp, completionList);
} }
Collections.sort(completionList); Collections.sort(completionList);

View File

@ -1,4 +1,3 @@
package com.gamingmesh.jobs.stuff; package com.gamingmesh.jobs.stuff;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;

View File

@ -80,7 +80,8 @@ public class Util {
} }
public static String firstToUpperCase(String name) { public static String firstToUpperCase(String name) {
return name.toLowerCase().replace('_', ' ').substring(0, 1).toUpperCase() + name.toLowerCase().replace('_', ' ').substring(1); name = name.toLowerCase().replace('_', ' ');
return name.substring(0, 1).toUpperCase() + name.substring(1);
} }
public static HashMap<UUID, String> getJobsEditorMap() { public static HashMap<UUID, String> getJobsEditorMap() {
@ -109,7 +110,7 @@ public class Util {
if (distance < 1) if (distance < 1)
distance = 1; distance = 1;
ArrayList<Block> blocks = new ArrayList<>(); List<Block> blocks = new ArrayList<>();
try { try {
Block bl = player.getTargetBlock(null, distance); Block bl = player.getTargetBlock(null, distance);
@ -208,10 +209,6 @@ public class Util {
return getFilesFromPackage(pckgname, null, "class"); return getFilesFromPackage(pckgname, null, "class");
} }
public static List<String> getFilesFromPackage(String pckgname, String cleaner) throws ClassNotFoundException {
return getFilesFromPackage(pckgname, cleaner, "class");
}
public static List<String> getFilesFromPackage(String pckgname, String cleaner, String fileType) throws ClassNotFoundException { public static List<String> getFilesFromPackage(String pckgname, String cleaner, String fileType) throws ClassNotFoundException {
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
try { try {
@ -234,8 +231,7 @@ public class Util {
jarFile = new JarFile(jarPath); jarFile = new JarFile(jarPath);
Enumeration<JarEntry> en = jarFile.entries(); Enumeration<JarEntry> en = jarFile.entries();
while (en.hasMoreElements()) { while (en.hasMoreElements()) {
JarEntry entry = en.nextElement(); String entryName = en.nextElement().getName();
String entryName = entry.getName();
packageName = packageName.replace('.', '/'); packageName = packageName.replace('.', '/');

View File

@ -13,7 +13,7 @@ public class blockLoc {
private World w; private World w;
public blockLoc(String loc) { public blockLoc(String loc) {
this.fromString(loc); fromString(loc);
} }
public blockLoc(Location loc) { public blockLoc(Location loc) {
@ -77,17 +77,14 @@ public class blockLoc {
} }
public Block getBlock() { public Block getBlock() {
Location loc = this.getLocation(); Location loc = getLocation();
return loc == null ? null : loc.getBlock();
if (loc == null)
return null;
return loc.getBlock();
} }
public Location getLocation() { public Location getLocation() {
if (worldName == null && this.w == null) if (worldName == null && w == null)
return null; return null;
World w = this.w == null ? Bukkit.getWorld(worldName) : this.w; World w = this.w == null ? Bukkit.getWorld(worldName) : this.w;
if (w == null) if (w == null)
return null; return null;