1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-02-18 05:11:32 +01:00

Remove redundant fields from heap

This commit is contained in:
montlikadani 2020-12-17 16:21:51 +01:00
parent 7544eea2ac
commit 03dee3da8e
10 changed files with 87 additions and 110 deletions

View File

@ -29,7 +29,6 @@ import org.bukkit.permissions.PermissionAttachmentInfo;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.Debug;
public class PermissionManager {
@ -128,7 +127,7 @@ public class PermissionManager {
public Double getMaxPermission(JobsPlayer jPlayer, String perm, boolean force, boolean cumulative) {
if (jPlayer == null || jPlayer.getPlayer() == null)
return 0D;
perm = perm.toLowerCase();
if (!perm.endsWith("."))
perm += ".";
@ -157,7 +156,7 @@ public class PermissionManager {
}
}
return amount == Double.NEGATIVE_INFINITY ? 0D : amount;
return amount == Double.NEGATIVE_INFINITY ? 0D : amount;
}
public boolean hasPermission(JobsPlayer jPlayer, String perm) {

View File

@ -544,9 +544,19 @@ public class Placeholder {
Title title = Jobs.gettitleManager().getTitle(j.getLevel(), j.getJob().getName());
return title == null ? "" : title.getChatColor() + title.getName();
case user_archived_jobs_level:
return j == null ? "" : Integer.toString(user.getArchivedJobProgression(j.getJob()).getLevel());
if (j == null) {
return "";
}
JobProgression archivedJobProg = user.getArchivedJobProgression(j.getJob());
return archivedJobProg == null ? "" : Integer.toString(archivedJobProg.getLevel());
case user_archived_jobs_exp:
return j == null ? "" : Double.toString(user.getArchivedJobProgression(j.getJob()).getExperience());
if (j == null) {
return "";
}
JobProgression archivedJobProgression = user.getArchivedJobProgression(j.getJob());
return archivedJobProgression == null ? "" : Double.toString(archivedJobProgression.getExperience());
default:
break;
}

View File

@ -56,12 +56,9 @@ public class bp implements Cmd {
changedBlocks.add(l.getBlock());
if (Version.isCurrentEqualOrHigher(Version.v1_15_R1)) {
if (bp.getAction() == DBAction.DELETE)
player.sendBlockChange(l, CMIMaterial.RED_STAINED_GLASS.getMaterial().createBlockData());
else if (time == -1)
player.sendBlockChange(l, CMIMaterial.BLACK_STAINED_GLASS.getMaterial().createBlockData());
else
player.sendBlockChange(l, CMIMaterial.WHITE_STAINED_GLASS.getMaterial().createBlockData());
player.sendBlockChange(l, (bp.getAction() == DBAction.DELETE ?
CMIMaterial.RED_STAINED_GLASS :
time == -1 ? CMIMaterial.BLACK_STAINED_GLASS : CMIMaterial.WHITE_STAINED_GLASS).getMaterial().createBlockData());
} else {
if (bp.getAction() == DBAction.DELETE)
player.sendBlockChange(l, CMIMaterial.RED_STAINED_GLASS.getMaterial(), (byte) 14);

View File

@ -19,7 +19,6 @@ public class browse implements Cmd {
@Override
@JobCommand(200)
public boolean perform(Jobs plugin, CommandSender sender, final String[] args) {
if (Jobs.getGCManager().BrowseUseNewLook) {
List<Job> jobList = new ArrayList<>(Jobs.getJobs());
if (jobList.isEmpty()) {
@ -32,25 +31,24 @@ public class browse implements Cmd {
Jobs.getGUIManager().openJobsBrowseGUI((Player) sender);
} catch (Throwable e) {
((Player) sender).closeInventory();
return true;
}
return true;
}
Job j = null;
int page = 1;
if (sender instanceof Player) {
for (String one : args) {
if (one.startsWith("-p:")) {
try {
page = Integer.parseInt(one.substring("-p:".length()));
continue;
} catch (Exception e) {
}
}
}
}
Job j = null;
for (String one : args) {
if (one.startsWith("-j:")) {
j = Jobs.getJob(one.substring("-j:".length()));
@ -228,7 +226,6 @@ public class browse implements Cmd {
Jobs.getGUIManager().openJobsBrowseGUI((Player) sender);
} catch (Throwable e) {
((Player) sender).closeInventory();
return true;
}
return true;

View File

@ -1,8 +1,6 @@
package com.gamingmesh.jobs.commands.list;
import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -32,10 +30,10 @@ public class fireall implements Cmd {
Jobs.getDBManager().getDB().truncate(DBTables.JobsTable.getTableName());
for (Entry<UUID, JobsPlayer> one : Jobs.getPlayerManager().getPlayersCache().entrySet()) {
one.getValue().leaveAllJobs();
for (JobsPlayer one : Jobs.getPlayerManager().getPlayersCache().values()) {
one.leaveAllJobs();
// No need to save as we are clearing database with more efficient method
one.getValue().setSaved(true);
one.setSaved(true);
}
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success"));

View File

@ -4,7 +4,6 @@ import java.text.NumberFormat;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@ -36,8 +35,8 @@ public class glog implements Cmd {
Map<LogAmounts, Double> unsortMap = new HashMap<>();
int time = TimeManage.timeInInt();
for (Integer OneP : Jobs.getJobsDAO().getLognameList(time, time)) {
PlayerInfo info = Jobs.getPlayerManager().getPlayerInfo(OneP);
for (Integer oneP : Jobs.getJobsDAO().getLognameList(time, time)) {
PlayerInfo info = Jobs.getPlayerManager().getPlayerInfo(oneP);
if (info == null)
continue;
@ -45,21 +44,19 @@ public class glog implements Cmd {
if (name == null)
continue;
JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(info.getUuid());
if (JPlayer == null)
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(info.getUuid());
if (jPlayer == null)
continue;
HashMap<String, Log> logList = JPlayer.getLog();
HashMap<String, Log> logList = jPlayer.getLog();
if (logList == null || logList.isEmpty())
continue;
for (Entry<String, Log> l : logList.entrySet()) {
Log one = l.getValue();
HashMap<String, LogAmounts> AmountList = one.getAmountList();
for (Entry<String, LogAmounts> oneMap : AmountList.entrySet()) {
oneMap.getValue().setUsername(name);
oneMap.getValue().setAction(one.getActionType());
unsortMap.put(oneMap.getValue(), oneMap.getValue().get(CurrencyType.MONEY));
for (Log l : logList.values()) {
for (LogAmounts amounts : l.getAmountList().values()) {
amounts.setUsername(name);
amounts.setAction(l.getActionType());
unsortMap.put(amounts, amounts.get(CurrencyType.MONEY));
}
}
}
@ -77,25 +74,23 @@ public class glog implements Cmd {
totalPoints = 0;
sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.topline"));
for (Entry<LogAmounts, Double> one : unsortMap.entrySet()) {
LogAmounts info = one.getKey();
for (LogAmounts info : unsortMap.keySet()) {
double money = info.get(CurrencyType.MONEY);
totalMoney = totalMoney + money;
totalMoney += money;
String moneyS = "";
if (money != 0D)
moneyS = Jobs.getLanguage().getMessage("command.glog.output.money", "%amount%", money);
double exp = info.get(CurrencyType.EXP);
totalExp = totalExp + exp;
totalExp += exp;
String expS = "";
if (exp != 0D)
expS = Jobs.getLanguage().getMessage("command.glog.output.exp", "%amount%", exp);
double points = info.get(CurrencyType.POINTS);
totalPoints = totalPoints + points;
totalPoints += points;
String pointsS = "";
if (points != 0D)
@ -104,7 +99,7 @@ public class glog implements Cmd {
sender.sendMessage(Jobs.getLanguage().getMessage("command.glog.output.ls",
"%number%", count,
"%action%", info.getAction(),
"%item%", info.getItemName().replace(":0", "").replace("_", " ").toLowerCase(),
"%item%", info.getItemName().replace(":0", "").replace('_', ' ').toLowerCase(),
"%qty%", info.getCount(),
"%money%", moneyS,
"%exp%", expS,

View File

@ -19,7 +19,6 @@
package com.gamingmesh.jobs.config;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@ -29,7 +28,6 @@ import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringEscapeUtils;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@ -70,8 +68,8 @@ public class ConfigManager {
private final Set<YmlMaker> jobFiles = new HashSet<>();
public static final String exampleJobName = "_EXAMPLE";
public static final String exampleJobInternalName = "exampleJob";
public static final String EXAMPLEJOBNAME = "_EXAMPLE";
public static final String EXAMPLEJOBINTERNALNAME = "exampleJob";
public ConfigManager() {
this.jobFile = new File(Jobs.getFolder(), "jobConfig.yml");
@ -81,7 +79,7 @@ public class ConfigManager {
}
private void updateExampleFile() {
ConfigReader cfg = new ConfigReader(new File(Jobs.getFolder(), "jobs" + File.separator + exampleJobName.toUpperCase() + ".yml"));
ConfigReader cfg = new ConfigReader(new File(Jobs.getFolder(), "jobs" + File.separator + EXAMPLEJOBNAME.toUpperCase() + ".yml"));
if (!cfg.getFile().isFile())
return;
cfg.load();
@ -311,7 +309,7 @@ public class ConfigManager {
}
public void changeJobsSettings(String jobName, String path, Object value) {
path = path.replace("/", ".");
path = path.replace('/', '.');
for (YmlMaker yml : jobFiles) {
if (yml.getConfigFile().getName().contains(jobName.toLowerCase())) {
yml.getConfig().set(path, value);
@ -323,9 +321,7 @@ public class ConfigManager {
public class KeyValues {
private String type;
private String subType = "";
private String meta = "";
private String type, subType = "", meta = "";
private int id = 0;
public String getType() {
@ -628,12 +624,12 @@ public class ConfigManager {
}
private boolean migrateJobs() {
YamlConfiguration oldConf = getJobConfig();
if (oldConf == null) {
if (!jobsPathFolder.exists()) {
jobsPathFolder.mkdirs();
}
if (jobsPathFolder.isDirectory() && jobsPathFolder.listFiles().length == 0)
try {
for (String f : Util.getFilesFromPackage("jobs", "", "yml")) {
@ -641,6 +637,7 @@ public class ConfigManager {
}
} catch (Exception c) {
}
return false;
}
@ -659,7 +656,7 @@ public class ConfigManager {
for (String jobKey : jobsSection.getKeys(false)) {
String fileName = jobKey.equalsIgnoreCase(exampleJobName) ? jobKey.toUpperCase() : jobKey.toLowerCase();
String fileName = jobKey.equalsIgnoreCase(EXAMPLEJOBNAME) ? jobKey.toUpperCase() : jobKey.toLowerCase();
YmlMaker newJobFile = new YmlMaker(jobsPathFolder, fileName + ".yml");
if (!newJobFile.exists()) {
@ -677,7 +674,7 @@ public class ConfigManager {
newJobFile.saveConfig();
if (!fileName.equalsIgnoreCase(exampleJobName)) {
if (!fileName.equalsIgnoreCase(EXAMPLEJOBNAME)) {
jobFiles.add(newJobFile);
}
}
@ -705,7 +702,7 @@ public class ConfigManager {
if (jobFiles.isEmpty()) {
File[] files = jobsPathFolder.listFiles((dir, name) -> name.toLowerCase().endsWith(".yml")
&& !name.toLowerCase().equalsIgnoreCase(exampleJobName + ".yml"));
&& !name.toLowerCase().equalsIgnoreCase(EXAMPLEJOBNAME + ".yml"));
if (files != null) {
for (File file : files) {
jobFiles.add(new YmlMaker(jobsPathFolder, file));
@ -739,7 +736,7 @@ public class ConfigManager {
for (String jobKey : jobsSection.getKeys(false)) {
// Ignore example job
if (jobKey.equalsIgnoreCase(exampleJobInternalName)) {
if (jobKey.equalsIgnoreCase(EXAMPLEJOBINTERNALNAME)) {
continue;
}
@ -747,7 +744,7 @@ public class ConfigManager {
jobKey = StringEscapeUtils.unescapeJava(jobKey);
ConfigurationSection jobSection = jobsSection.getConfigurationSection(jobKey);
String jobFullName = jobSection.getString("fullname", null);
String jobFullName = jobSection.getString("fullname");
if (jobFullName == null) {
log.warning("Job " + jobKey + " has an invalid fullname property. Skipping job!");
continue;
@ -775,7 +772,7 @@ public class ConfigManager {
rejoinCd *= 1000L;
}
String jobShortName = jobSection.getString("shortname", null);
String jobShortName = jobSection.getString("shortname");
if (jobShortName == null) {
log.warning("Job " + jobKey + " is missing the shortname property. Skipping job!");
continue;
@ -884,7 +881,7 @@ public class ConfigManager {
// Gui item
int guiSlot = -1;
ItemStack GUIitem = CMIMaterial.GREEN_WOOL.newItemStack();
ItemStack guiItem = CMIMaterial.GREEN_WOOL.newItemStack();
if (jobSection.contains("Gui")) {
ConfigurationSection guiSection = jobSection.getConfigurationSection("Gui");
if (guiSection.isString("Item")) {
@ -921,24 +918,24 @@ public class ConfigManager {
}
if (material != null)
GUIitem = material.newItemStack();
guiItem = material.newItemStack();
} else if (guiSection.isInt("Id") && guiSection.isInt("Data")) {
GUIitem = CMIMaterial.get(guiSection.getInt("Id"), guiSection.getInt("Data")).newItemStack();
guiItem = CMIMaterial.get(guiSection.getInt("Id"), guiSection.getInt("Data")).newItemStack();
} else
log.warning("Job " + jobKey + " has an invalid Gui property. Please fix this if you want to use it!");
for (String str4 : guiSection.getStringList("Enchantments")) {
String[] id = str4.split(":");
if (GUIitem.getItemMeta() instanceof EnchantmentStorageMeta) {
EnchantmentStorageMeta enchantMeta = (EnchantmentStorageMeta) GUIitem.getItemMeta();
if (guiItem.getItemMeta() instanceof EnchantmentStorageMeta) {
EnchantmentStorageMeta enchantMeta = (EnchantmentStorageMeta) guiItem.getItemMeta();
enchantMeta.addStoredEnchant(CMIEnchantment.getEnchantment(id[0]), Integer.parseInt(id[1]), true);
GUIitem.setItemMeta(enchantMeta);
guiItem.setItemMeta(enchantMeta);
} else
GUIitem.addUnsafeEnchantment(CMIEnchantment.getEnchantment(id[0]), Integer.parseInt(id[1]));
guiItem.addUnsafeEnchantment(CMIEnchantment.getEnchantment(id[0]), Integer.parseInt(id[1]));
}
if (guiSection.isString("CustomSkull")) {
GUIitem = Util.getSkull(guiSection.getString("CustomSkull"));
guiItem = Util.getSkull(guiSection.getString("CustomSkull"));
}
if (guiSection.getInt("slot", -1) >= 0)
@ -985,16 +982,6 @@ public class ConfigManager {
}
}
// Command on leave
List<String> JobsCommandOnLeave = new ArrayList<>();
if (jobSection.isList("cmd-on-leave"))
JobsCommandOnLeave = jobSection.getStringList("cmd-on-leave");
// Command on join
List<String> JobsCommandOnJoin = new ArrayList<>();
if (jobSection.isList("cmd-on-join"))
JobsCommandOnJoin = jobSection.getStringList("cmd-on-join");
// Commands
ArrayList<JobCommands> jobCommand = new ArrayList<>();
ConfigurationSection commandsSection = jobSection.getConfigurationSection("commands");
@ -1003,7 +990,7 @@ public class ConfigManager {
ConfigurationSection commandSection = commandsSection.getConfigurationSection(commandKey);
if (commandSection == null) {
log.warning("Job " + jobKey + " has an invalid command key" + commandKey + "!");
log.warning("Job " + jobKey + " has an invalid command key " + commandKey + "!");
continue;
}
@ -1019,12 +1006,6 @@ public class ConfigManager {
}
}
// Commands
List<String> worldBlacklist = new ArrayList<>();
if (jobSection.isList("world-blacklist")) {
worldBlacklist = jobSection.getStringList("world-blacklist");
}
// Items **OUTDATED** Moved to ItemBoostManager!!
HashMap<String, JobItems> jobItems = new HashMap<>();
ConfigurationSection itemsSection = jobSection.getConfigurationSection("items");
@ -1084,10 +1065,10 @@ public class ConfigManager {
// Limited Items
HashMap<String, JobLimitedItems> jobLimitedItems = new HashMap<>();
ConfigurationSection LimitedItemsSection = jobSection.getConfigurationSection("limitedItems");
if (LimitedItemsSection != null) {
for (String itemKey : LimitedItemsSection.getKeys(false)) {
ConfigurationSection itemSection = LimitedItemsSection.getConfigurationSection(itemKey);
ConfigurationSection limitedItemsSection = jobSection.getConfigurationSection("limitedItems");
if (limitedItemsSection != null) {
for (String itemKey : limitedItemsSection.getKeys(false)) {
ConfigurationSection itemSection = limitedItemsSection.getConfigurationSection(itemKey);
if (itemSection == null) {
log.warning("Job " + jobKey + " has an invalid item key " + itemKey + "!");
continue;
@ -1095,9 +1076,7 @@ public class ConfigManager {
int id = itemSection.getInt("id");
String name = null;
if (itemSection.isString("name"))
name = itemSection.getString("name");
String name = itemSection.getString("name");
List<String> lore = new ArrayList<>();
if (itemSection.isList("lore"))
@ -1128,7 +1107,9 @@ public class ConfigManager {
}
Job job = new Job(jobKey, jobFullName, jobShortName, description, color, maxExpEquation, displayMethod, maxLevel, vipmaxLevel, maxSlots, jobPermissions, jobCommand,
jobConditions, jobItems, jobLimitedItems, JobsCommandOnJoin, JobsCommandOnLeave, GUIitem, guiSlot, bossbar, rejoinCd, worldBlacklist);
jobConditions, jobItems, jobLimitedItems, jobSection.getStringList("cmd-on-join"),
jobSection.getStringList("cmd-on-leave"), guiItem, guiSlot, bossbar, rejoinCd,
jobSection.getStringList("world-blacklist"));
job.setFullDescription(fDescription);
job.setMoneyEquation(incomeEquation);

View File

@ -69,15 +69,15 @@ public class Job {
// max number of people allowed with this job on the server.
private Integer maxSlots;
private List<String> CmdOnJoin = new ArrayList<>(), CmdOnLeave = new ArrayList<>();
private List<String> cmdOnJoin = new ArrayList<>(), cmdOnLeave = new ArrayList<>();
private ItemStack GUIitem;
private ItemStack guiItem;
private int guiSlot = 0;
private Long rejoinCd = 0L;
private int totalPlayers = -1;
private Double bonus = null;
private Double bonus;
private BoostMultiplier boost = new BoostMultiplier();
private String bossbar;
@ -89,12 +89,11 @@ public class Job {
private final List<Quest> quests = new ArrayList<>();
private int maxDailyQuests = 1;
private int id = 0;
public Job(String jobName, String fullName, String jobShortName, String description, CMIChatColor jobColour, Parser maxExpEquation, DisplayMethod displayMethod, int maxLevel,
int vipmaxLevel, Integer maxSlots, List<JobPermission> jobPermissions, List<JobCommands> jobCommands, List<JobConditions> jobConditions, HashMap<String, JobItems> jobItems,
HashMap<String, JobLimitedItems> jobLimitedItems, List<String> CmdOnJoin, List<String> CmdOnLeave, ItemStack GUIitem, int guiSlot, String bossbar, Long rejoinCD, List<String> worldBlacklist) {
HashMap<String, JobLimitedItems> jobLimitedItems, List<String> cmdOnJoin, List<String> cmdOnLeave, ItemStack guiItem, int guiSlot, String bossbar, Long rejoinCD, List<String> worldBlacklist) {
this.jobName = jobName == null ? "" : jobName;
this.fullName = fullName == null ? "" : fullName;
this.jobShortName = jobShortName;
@ -110,13 +109,16 @@ public class Job {
this.jobConditions = jobConditions;
this.jobItems = jobItems;
this.jobLimitedItems = jobLimitedItems;
this.CmdOnJoin = CmdOnJoin;
this.CmdOnLeave = CmdOnLeave;
this.GUIitem = GUIitem;
this.cmdOnJoin = cmdOnJoin;
this.cmdOnLeave = cmdOnLeave;
this.guiItem = guiItem;
this.guiSlot = guiSlot;
this.bossbar = bossbar;
this.rejoinCd = rejoinCD;
this.worldBlacklist = worldBlacklist;
if (worldBlacklist != null) {
this.worldBlacklist = worldBlacklist;
}
}
public void addBoost(CurrencyType type, double Point) {
@ -197,15 +199,15 @@ public class Job {
}
public List<String> getCmdOnJoin() {
return CmdOnJoin;
return cmdOnJoin;
}
public List<String> getCmdOnLeave() {
return CmdOnLeave;
return cmdOnLeave;
}
public ItemStack getGuiItem() {
return GUIitem;
return guiItem;
}
public int getGuiSlot() {
@ -519,8 +521,7 @@ public class Job {
while (true) {
i++;
final Random rand = new Random(System.nanoTime());
int target = rand.nextInt(100);
int target = new Random(System.nanoTime()).nextInt(100);
for (Quest one : ls) {
if (one.getChance() >= target && (excludeQuests == null || !excludeQuests.contains(one.getConfigName().toLowerCase()))
&& one.isInLevelRange(level)) {

View File

@ -27,7 +27,6 @@ import com.gamingmesh.jobs.container.blockOwnerShip.BlockOwnerShip;
import com.gamingmesh.jobs.container.blockOwnerShip.BlockOwnerShip.ownershipFeedback;
import com.gamingmesh.jobs.hooks.HookManager;
import com.gamingmesh.jobs.hooks.JobsHook;
import com.gamingmesh.jobs.stuff.Debug;
import com.google.common.base.Objects;
import org.bukkit.Bukkit;
@ -418,7 +417,7 @@ public class JobsPaymentListener implements Listener {
|| brokenBlock == CMIMaterial.CACTUS.getMaterial() || brokenBlock == CMIMaterial.BAMBOO.getMaterial())) {
return;
}
Jobs.action(Jobs.getPlayerManager().getJobsPlayer(player), bInfo, block);
}

View File

@ -2,11 +2,11 @@
#
# Edited by roracle to include 1.13 items and item names, preparing for 1.14 as well.
# ATTENTION!
# This is just an example job and will not be included into job list. Recomended to keep
# it around just for reference. Can be removed if needed.
# Must be one word. This job will be ignored as this is just example of all possible actions.
# ATTENTION!
# This is just an example job and will not be included into job list. Recomended to keep it around just for reference. Can be removed if needed.
exampleJob:
# full name of the job (displayed when browsing a job, used when joining and leaving)
# also can be used as a prefix for the user's name if the option is enabled.