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

Some fixes

- Fixed when crafting tipped arrows, it didn't work
- Fix when PayForEachCraft option not works
- Some null checks to prevent exceptions
- Trying to fix issue with editpoints
This commit is contained in:
montlikadani 2020-06-24 09:27:17 +02:00
parent 4d0e4be8dd
commit 1e4b7aa002
13 changed files with 84 additions and 121 deletions

View File

@ -205,7 +205,6 @@ public class PlayerManager {
jPlayer.onConnect();
jPlayer.reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
return;
}
@ -776,10 +775,11 @@ public class PlayerManager {
*/
public void performCommandOnLevelUp(JobsPlayer jPlayer, Job job, int oldLevel) {
int newLevel = oldLevel + 1;
Player player = Bukkit.getServer().getPlayer(jPlayer.getUniqueId());
Player player = Bukkit.getPlayer(jPlayer.getUniqueId());
JobProgression prog = jPlayer.getJobProgression(job);
if (prog == null)
return;
for (JobCommands command : job.getCommands()) {
if (newLevel >= command.getLevelFrom() && newLevel <= command.getLevelUntil()) {
for (String commandString : new ArrayList<String>(command.getCommands())) {
@ -860,7 +860,7 @@ public class PlayerManager {
}
}
private HashMap<UUID, HashMap<Job, ItemBonusCache>> cache = new HashMap<>();
private final HashMap<UUID, HashMap<Job, ItemBonusCache>> cache = new HashMap<>();
public void resetiItemBonusCache(UUID uuid) {
cache.remove(uuid);
@ -875,20 +875,20 @@ public class PlayerManager {
ItemBonusCache c = cj.get(prog);
if (c == null) {
c = new ItemBonusCache(player, prog);
c.recheck();
c = new ItemBonusCache();
c.setBoostMultiplier(getInventoryBoost(player, prog));
cj.put(prog, c);
return c.getBoostMultiplier();
}
return c.getBoostMultiplier();
}
public BoostMultiplier getInventoryBoost(Player player, Job prog) {
BoostMultiplier data = new BoostMultiplier();
if (player == null)
return data;
if (prog == null)
if (player == null || prog == null)
return data;
ItemStack iih = Jobs.getNms().getItemInMainHand(player);
JobItems jitem = getJobsItemByNbt(iih);
if (jitem != null && jitem.getJobs().contains(prog))
@ -919,9 +919,7 @@ public class PlayerManager {
}
public boolean containsItemBoostByNBT(ItemStack item) {
if (item == null)
return false;
return Jobs.getReflections().hasNbtString(item, JobsItemBoost);
return item == null ? false : Jobs.getReflections().hasNbtString(item, JobsItemBoost);
}
private final String JobsItemBoost = "JobsItemBoost";

View File

@ -5,10 +5,11 @@ import java.util.List;
public class SignInfo {
private List<jobsSign> AllSigns = new ArrayList<>();
private final List<jobsSign> AllSigns = new ArrayList<>();
public void setAllSigns(List<jobsSign> AllSigns) {
this.AllSigns = AllSigns;
this.AllSigns.clear();
this.AllSigns.addAll(AllSigns == null ? new ArrayList<>() : AllSigns);
}
public List<jobsSign> GetAllSigns() {

View File

@ -11,9 +11,7 @@ public class jobsSign {
private String worldName;
private Integer x;
private Integer y;
private Integer z;
private Integer x, y, z;
private World world;
private Location loc;
@ -105,9 +103,7 @@ public class jobsSign {
String[] split = string.replace(",", ".").split(";");
Integer x = 0;
Integer y = 0;
Integer z = 0;
int x = 0, y = 0, z = 0;
if (split.length > 0)
try {

View File

@ -32,11 +32,6 @@ public class editpoints implements Cmd {
}
PlayerPoints pointInfo = jPlayer.getPointsData();
if (pointInfo == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", jPlayer.getName()));
return true;
}
switch (args[0].toLowerCase()) {
case "take":
pointInfo.takePoints(amount);
@ -63,6 +58,7 @@ public class editpoints implements Cmd {
}
Jobs.getJobsDAO().savePoints(jPlayer);
Jobs.getJobsDAO().loadPoints(jPlayer);
return true;
}
}

View File

@ -363,7 +363,7 @@ public class ShopManager {
if (NameSection.isBoolean("Icon.HideWithoutPermission"))
Sitem.setHideWithoutPerm(NameSection.getBoolean("Icon.HideWithoutPermission"));
if (NameSection.isList("RequiredPermission") && !NameSection.getStringList("RequiredPermission").isEmpty()) {
if (NameSection.isList("RequiredPermission")) {
Sitem.setRequiredPerm(NameSection.getStringList("RequiredPermission"));
}

View File

@ -1,43 +1,14 @@
package com.gamingmesh.jobs.container;
import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs;
public class ItemBonusCache {
private Player player;
private Long lastCheck = null;
private BoostMultiplier bm = new BoostMultiplier();
private Job job;
public ItemBonusCache(Player player, Job job) {
this.player = player;
this.job = job;
}
public Long getLastCheck() {
return lastCheck;
}
public void setLastCheck(Long lastCheck) {
this.lastCheck = lastCheck;
}
public BoostMultiplier getBoostMultiplier() {
if (lastCheck == null || System.currentTimeMillis() - lastCheck > 1000 * 60)
recheck();
return bm;
}
public void setBoostMultiplier(BoostMultiplier bm) {
this.bm = bm;
}
public ItemBonusCache recheck() {
bm = Jobs.getPlayerManager().getInventoryBoost(player, job);
lastCheck = System.currentTimeMillis();
return this;
}
}

View File

@ -20,6 +20,7 @@ package com.gamingmesh.jobs.container;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.CMIMaterial;
import com.gamingmesh.jobs.actions.PotionItemActionInfo;
import com.gamingmesh.jobs.resources.jfep.Parser;
import com.gamingmesh.jobs.stuff.ChatColor;
@ -145,9 +146,7 @@ public class Job {
}
public boolean isSame(Job job) {
if (job == null)
return false;
return this.getName().equalsIgnoreCase(job.getName());
return job == null ? false : getName().equalsIgnoreCase(job.getName());
}
public int getTotalPlayers() {
@ -166,22 +165,26 @@ public class Job {
public void updateBonus() {
if (!Jobs.getGCManager().useDynamicPayment)
return;
Parser eq = Jobs.getGCManager().DynamicPaymentEquation;
eq.setVariable("totalworkers", Jobs.getJobsDAO().getTotalPlayers());
eq.setVariable("totaljobs", Jobs.getJobs().size());
eq.setVariable("jobstotalplayers", getTotalPlayers());
double now = eq.getValue();
if (now > Jobs.getGCManager().DynamicPaymentMaxBonus)
now = Jobs.getGCManager().DynamicPaymentMaxBonus;
if (now < Jobs.getGCManager().DynamicPaymentMaxPenalty * -1)
now = Jobs.getGCManager().DynamicPaymentMaxPenalty * -1;
this.bonus = (now / 100D);
}
public double getBonus() {
if (this.bonus == null)
if (bonus == null)
updateBonus();
return this.bonus == null ? 0D : this.bonus;
return bonus == null ? 0D : bonus;
}
public List<String> getCmdOnJoin() {
@ -226,6 +229,11 @@ public class Job {
public JobInfo getJobInfo(ActionInfo action, int level) {
BiPredicate<JobInfo, ActionInfo> condition = (jobInfo, actionInfo) -> {
if (actionInfo instanceof PotionItemActionInfo) {
return jobInfo.getName().equalsIgnoreCase(((PotionItemActionInfo) action).getNameWithSub()) ||
(jobInfo.getName() + ":" + jobInfo.getMeta()).equalsIgnoreCase(((PotionItemActionInfo) action).getNameWithSub());
}
return jobInfo.getName().equalsIgnoreCase(action.getNameWithSub()) ||
(jobInfo.getName() + ":" + jobInfo.getMeta()).equalsIgnoreCase(action.getNameWithSub()) ||
jobInfo.getName().equalsIgnoreCase(action.getName());
@ -327,19 +335,19 @@ public class Job {
}
public int getMaxLevel(JobsPlayer player) {
if (player == null)
return getMaxLevel();
return player.getMaxJobLevelAllowed(this);
return player == null ? getMaxLevel() : player.getMaxJobLevelAllowed(this);
}
public int getMaxLevel(CommandSender sender) {
if (sender == null)
return getMaxLevel();
if (sender instanceof Player) {
JobsPlayer player = Jobs.getPlayerManager().getJobsPlayer((Player) sender);
if (player != null)
return player.getMaxJobLevelAllowed(this);
}
return getMaxLevel() > getVipMaxLevel() ? getMaxLevel() : getVipMaxLevel();
}
@ -458,7 +466,8 @@ public class Job {
}
public void setFullDescription(List<String> fDescription) {
this.fDescription = fDescription;
this.fDescription.clear();
this.fDescription.addAll(fDescription == null ? new ArrayList<>() : fDescription);
}
public List<Quest> getQuests() {
@ -480,7 +489,7 @@ public class Job {
public void setQuests(List<Quest> quests) {
this.quests.clear();
this.quests = quests;
this.quests.addAll(quests == null ? new ArrayList<>() : quests);
}
// public Quest getNextQuest() {
@ -499,7 +508,6 @@ public class Job {
for (Quest one : ls) {
if (one.getChance() >= target)
if (excludeQuests == null || !excludeQuests.contains(one.getConfigName().toLowerCase())) {
if (!one.isInLevelRange(level))
continue;

View File

@ -77,7 +77,7 @@ public class JobItems {
this.node = node;
this.boostMultiplier = boostMultiplier;
this.jobs = jobs;
setJobs(jobs);
}
public String getNode() {
@ -135,7 +135,8 @@ public class JobItems {
}
public void setJobs(List<Job> jobs) {
this.jobs = jobs;
this.jobs.clear();
this.jobs.addAll(jobs == null ? new ArrayList<>() : jobs);
}
public HashMap<Enchantment, Integer> getEnchants() {

View File

@ -539,14 +539,12 @@ public class JobsPlayer {
public void promoteJob(Job job, int levels) {
// synchronized (saveLock) {
JobProgression prog = getJobProgression(job);
if (prog == null)
if (prog == null || levels <= 0)
return;
if (levels <= 0)
return;
int oldLevel = prog.getLevel();
int newLevel = oldLevel + levels;
int maxLevel = job.getMaxLevel(this);
int oldLevel = prog.getLevel(),
newLevel = oldLevel + levels,
maxLevel = job.getMaxLevel(this);
if (maxLevel > 0 && newLevel > maxLevel)
newLevel = maxLevel;
@ -563,10 +561,9 @@ public class JobsPlayer {
public void demoteJob(Job job, int levels) {
// synchronized (saveLock) {
JobProgression prog = getJobProgression(job);
if (prog == null)
return;
if (levels <= 0)
if (prog == null || levels <= 0)
return;
int newLevel = prog.getLevel() - levels;
if (newLevel < 1)
newLevel = 1;
@ -618,7 +615,6 @@ public class JobsPlayer {
reloadLimits();
reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(this);
return true;
}
}

View File

@ -48,7 +48,8 @@ public class Quest {
}
public void setRewardCmds(List<String> rewardCmds) {
this.rewardCmds = rewardCmds;
this.rewardCmds.clear();
this.rewardCmds.addAll(rewardCmds == null ? new ArrayList<>() : rewardCmds);
}
public List<String> getDescription() {
@ -56,7 +57,8 @@ public class Quest {
}
public void setDescription(List<String> rewards) {
this.rewards = rewards;
this.rewards.clear();
this.rewards.addAll(rewards == null ? new ArrayList<>() : rewards);
}
public List<String> getRestrictedAreas() {
@ -64,7 +66,8 @@ public class Quest {
}
public void setRestrictedArea(List<String> area) {
this.area = area;
this.area.clear();
this.area.addAll(area == null ? new ArrayList<>() : area);
}
public Long getValidUntil() {
@ -95,7 +98,7 @@ public class Quest {
}
public Job getJob() {
return Jobs.getJob(this.job.getName());
return Jobs.getJob(job.getName());
}
public void setJob(Job job) {
@ -146,10 +149,10 @@ public class Quest {
if (level == null)
return true;
if (this.getMinLvl() != null && level < this.getMinLvl())
if (getMinLvl() != null && level < getMinLvl())
return false;
if (this.getMaxLvl() != null && level > this.getMaxLvl())
if (getMaxLvl() != null && level > getMaxLvl())
return false;
return true;
@ -184,7 +187,7 @@ public class Quest {
public void addObjective(QuestObjective objective) {
HashMap<String, QuestObjective> old = objectives.get(objective.getAction());
if (old == null) {
old = new HashMap<String, QuestObjective>();
old = new HashMap<>();
old.put(objective.getTargetName(), objective);
objectives.put(objective.getAction(), old);
}

View File

@ -61,7 +61,7 @@ public class QuestProgression {
}
public Long getValidUntil() {
return this.validUntil;
return validUntil;
}
public void setValidUntil(Long validUntil) {
@ -79,7 +79,7 @@ public class QuestProgression {
public boolean isCompleted() {
for (Entry<ActionType, HashMap<String, QuestObjective>> oneA : quest.getObjectives().entrySet()) {
for (Entry<String, QuestObjective> one : oneA.getValue().entrySet()) {
Integer amountDone = this.done.get(one.getValue());
Integer amountDone = done.get(one.getValue());
if (amountDone == null || amountDone < one.getValue().getAmount())
return false;
}
@ -154,9 +154,6 @@ public class QuestProgression {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), ev.getCommand().startsWith("/") ? ev.getCommand().substring(1) : ev.getCommand());
}
}
return;
}
public boolean isGivenReward() {

View File

@ -16,19 +16,18 @@ public class ShopItem {
private String IconMaterial = null;
private int IconAmount = 1;
private String IconName = null;
private List<String> IconLore = new ArrayList<>();
private final List<String> IconLore = new ArrayList<>();
private boolean HideWithoutPerm = false;
private boolean hideNoEnoughPoint = false;
private int RequiredTotalLevels = -1;
private List<String> RequiredPerm = new ArrayList<>();
private HashMap<String, Integer> RequiredJobs = new HashMap<>();
private List<String> Commands = new ArrayList<>();
private List<JobItems> items = new ArrayList<>();
private final List<String> RequiredPerm = new ArrayList<>();
private final List<String> Commands = new ArrayList<>();
private final List<JobItems> items = new ArrayList<>();
private String PlayerName;
private boolean useCurrentPlayer = false;
@ -55,7 +54,8 @@ public class ShopItem {
}
public void setitems(List<JobItems> items) {
this.items = items;
this.items.clear();
this.items.addAll(items == null ? new ArrayList<>() : items);
}
public List<JobItems> getitems() {
@ -63,7 +63,8 @@ public class ShopItem {
}
public void setCommands(List<String> Commands) {
this.Commands = Commands;
this.Commands.clear();
this.Commands.addAll(Commands == null ? new ArrayList<>() : Commands);
}
public List<String> getCommands() {
@ -79,7 +80,8 @@ public class ShopItem {
}
public void setRequiredPerm(List<String> RequiredPerm) {
this.RequiredPerm = RequiredPerm;
this.RequiredPerm.clear();
this.RequiredPerm.addAll(RequiredPerm == null ? new ArrayList<>() : RequiredPerm);
}
public List<String> getRequiredPerm() {
@ -103,7 +105,8 @@ public class ShopItem {
}
public void setIconLore(List<String> IconLore) {
this.IconLore = IconLore;
this.IconLore.clear();
this.IconLore.addAll(IconLore == null ? new ArrayList<>() : IconLore);
}
public List<String> getIconLore() {

View File

@ -89,13 +89,13 @@ import java.util.*;
import java.util.Map.Entry;
public class JobsPaymentListener implements Listener {
private Jobs plugin;
public static final String furnaceOwnerMetadata = "jobsFurnaceOwner";
public static final String brewingOwnerMetadata = "jobsBrewingOwner";
private final String BlockMetadata = "BlockOwner";
public static final String VegyMetadata = "VegyTimer";
private final String CowMetadata = "CowTimer";
private final String entityDamageByPlayer = "JobsEntityDamagePlayer";
public static final String furnaceOwnerMetadata = "jobsFurnaceOwner",
brewingOwnerMetadata = "jobsBrewingOwner", VegyMetadata = "VegyTimer";
private final String BlockMetadata = "BlockOwner", CowMetadata = "CowTimer", entityDamageByPlayer = "JobsEntityDamagePlayer";
public JobsPaymentListener(Jobs plugin) {
this.plugin = plugin;
@ -618,9 +618,7 @@ public class JobsPaymentListener implements Listener {
int y = -1;
CMIMaterial first = null;
CMIMaterial second = null;
CMIMaterial third = null;
CMIMaterial first = null, second = null, third = null;
boolean leather = false;
boolean shulker = false;
@ -700,24 +698,19 @@ public class JobsPaymentListener implements Listener {
}
}
// when we trying to craft tipped arrow effects
ItemStack currentItem = event.getCurrentItem();
if (currentItem != null) {
if (currentItem.hasItemMeta() && currentItem.getItemMeta() instanceof PotionMeta) {
PotionMeta potion = (PotionMeta) currentItem.getItemMeta();
Jobs.action(jPlayer, new PotionItemActionInfo(currentItem, ActionType.CRAFT, potion.getBasePotionData().getType()));
} else {
Jobs.action(jPlayer, new ItemActionInfo(currentItem, ActionType.CRAFT));
}
return;
}
// If we need to pay only by each craft action we will skip calculation how much was crafted
if (!Jobs.getGCManager().PayForEachCraft) {
if (resultStack.hasItemMeta() && resultStack.getItemMeta().hasDisplayName()) {
ItemStack currentItem = event.getCurrentItem();
// when we trying to craft tipped arrow effects
if (currentItem != null && currentItem.hasItemMeta() && currentItem.getItemMeta() instanceof PotionMeta) {
PotionMeta potion = (PotionMeta) currentItem.getItemMeta();
Jobs.action(jPlayer, new PotionItemActionInfo(currentItem, ActionType.CRAFT, potion.getBasePotionData().getType()));
} else if (resultStack.hasItemMeta() && resultStack.getItemMeta().hasDisplayName()) {
Jobs.action(jPlayer, new ItemNameActionInfo(ChatColor.stripColor(resultStack.getItemMeta()
.getDisplayName()), ActionType.CRAFT));
} else if (currentItem != null) {
Jobs.action(jPlayer, new ItemActionInfo(currentItem, ActionType.CRAFT));
}
return;