From 4e2928460ef4a71d82456d370b92d344a6e8d872 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Tue, 16 Mar 2021 11:17:29 +0100 Subject: [PATCH] A bit more improvements --- src/main/java/com/gamingmesh/jobs/Jobs.java | 3 +- .../jobs/commands/list/editquests.java | 12 +- .../gamingmesh/jobs/commands/list/quests.java | 3 +- .../jobs/container/ArchivedJobs.java | 7 +- .../com/gamingmesh/jobs/container/Boost.java | 43 +- .../jobs/container/BoostMultiplier.java | 2 +- .../jobs/container/ExploreChunk.java | 15 +- .../jobs/container/ExploreRegion.java | 5 +- .../jobs/container/JobConditions.java | 9 +- .../jobs/container/JobProgression.java | 28 +- .../gamingmesh/jobs/container/JobsPlayer.java | 22 +- .../com/gamingmesh/jobs/container/Log.java | 4 +- .../gamingmesh/jobs/container/LogAmounts.java | 8 +- .../com/gamingmesh/jobs/container/Quest.java | 11 +- .../jobs/container/QuestProgression.java | 9 +- .../gamingmesh/jobs/container/ShopItem.java | 7 +- .../blockOwnerShip/BlockOwnerShip.java | 8 +- .../jobs/listeners/JobsPaymentListener.java | 32 +- .../jobs/stuff/FurnaceBrewingHandling.java | 373 ------------------ .../jobs/stuff/complement/Complement2.java | 2 +- 20 files changed, 111 insertions(+), 492 deletions(-) delete mode 100644 src/main/java/com/gamingmesh/jobs/stuff/FurnaceBrewingHandling.java diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index d7642322..ef8259f1 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -155,8 +155,7 @@ public class Jobs extends JavaPlugin { } if (addNew && b == null) { - b = new BlockOwnerShip(type); - blockOwnerShips.add(b); + blockOwnerShips.add(b = new BlockOwnerShip(type)); } return Optional.ofNullable(b); diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/editquests.java b/src/main/java/com/gamingmesh/jobs/commands/list/editquests.java index 5ed360c7..ac6be20f 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/editquests.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/editquests.java @@ -1,8 +1,8 @@ package com.gamingmesh.jobs.commands.list; import java.io.File; -import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Map.Entry; import org.bukkit.block.Block; @@ -111,7 +111,7 @@ public class editquests implements Cmd { return false; } - HashMap obj = quest.getObjectives().get(actionT); + Map obj = quest.getObjectives().get(actionT); if (obj == null || obj.isEmpty()) return false; @@ -179,7 +179,7 @@ public class editquests implements Cmd { return false; } - HashMap obj = quest.getObjectives().get(actionT); + Map obj = quest.getObjectives().get(actionT); if (obj == null || obj.isEmpty()) return false; @@ -207,7 +207,7 @@ public class editquests implements Cmd { return false; } - HashMap obj = q.getObjectives().get(actionT); + Map obj = q.getObjectives().get(actionT); if (obj == null || obj.isEmpty()) return false; @@ -610,11 +610,9 @@ public class editquests implements Cmd { if (action != null && job != null && jInfo != null && q != null) { rm = new RawMessage(); - String materialName = jInfo.getRealisticName(); - rm.addText(Jobs.getLanguage().getMessage("command.editquests.help.list.quests", "%questname%", q.getConfigName())) .addHover(jInfo.getName()).addCommand("jobs editquests list " + job.getName() + " " + action.getName() + " " + q.getConfigName() - + " " + materialName); + + " " + jInfo.getRealisticName()); rm.show(player); } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/quests.java b/src/main/java/com/gamingmesh/jobs/commands/list/quests.java index 03f70e45..a12b7616 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/quests.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/quests.java @@ -1,7 +1,6 @@ package com.gamingmesh.jobs.commands.list; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map.Entry; @@ -104,7 +103,7 @@ public class quests implements Cmd { } } - for (HashMap oneAction : q.getQuest().getObjectives().values()) { + for (java.util.Map oneAction : q.getQuest().getObjectives().values()) { for (Entry oneObjective : oneAction.entrySet()) { hoverList.add(Jobs.getLanguage().getMessage("command.info.output." + oneObjective.getValue().getAction().toString().toLowerCase() + ".info") + " " + Jobs.getNameTranslatorManager().Translate(oneObjective.getKey(), oneObjective.getValue().getAction(), oneObjective.getValue().getTargetId(), oneObjective.getValue() diff --git a/src/main/java/com/gamingmesh/jobs/container/ArchivedJobs.java b/src/main/java/com/gamingmesh/jobs/container/ArchivedJobs.java index e1dc0d62..d093dbb8 100644 --- a/src/main/java/com/gamingmesh/jobs/container/ArchivedJobs.java +++ b/src/main/java/com/gamingmesh/jobs/container/ArchivedJobs.java @@ -28,11 +28,6 @@ public class ArchivedJobs { } public void removeArchivedJob(Job job) { - for (JobProgression one : jobs) { - if (one.getJob().isSame(job)) { - jobs.remove(one); - break; - } - } + jobs.remove(getArchivedJobProgression(job)); } } diff --git a/src/main/java/com/gamingmesh/jobs/container/Boost.java b/src/main/java/com/gamingmesh/jobs/container/Boost.java index af098a30..14e397e5 100644 --- a/src/main/java/com/gamingmesh/jobs/container/Boost.java +++ b/src/main/java/com/gamingmesh/jobs/container/Boost.java @@ -7,7 +7,7 @@ import com.gamingmesh.jobs.PlayerManager.BoostOf; public class Boost { - private HashMap map = new HashMap<>(); + private java.util.Map map = new HashMap<>(); public Boost() { for (BoostOf one : BoostOf.values()) { @@ -15,38 +15,38 @@ public class Boost { } } - public void add(BoostOf boostoff, BoostMultiplier BM) { - map.put(boostoff, BM); + public void add(BoostOf boostoff, BoostMultiplier multiplier) { + map.put(boostoff, multiplier); } - public BoostMultiplier get(BoostOf boostoff) { - return map.getOrDefault(boostoff, new BoostMultiplier()); + public BoostMultiplier get(BoostOf boostOf) { + return map.getOrDefault(boostOf, new BoostMultiplier()); } - public double get(BoostOf boostoff, CurrencyType BT) { - return get(boostoff, BT, false); + public double get(BoostOf boostOf, CurrencyType type) { + return get(boostOf, type, false); } - public double get(BoostOf boostoff, CurrencyType BT, boolean percent) { - if (!map.containsKey(boostoff)) + public double get(BoostOf boostOf, CurrencyType type, boolean percent) { + if (!map.containsKey(boostOf)) return 0D; - double r = map.get(boostoff).get(BT); + + double r = map.get(boostOf).get(type); if (r < -1) r = -1; - if (percent) - return (int) (r * 100); - return r; + + return percent ? (int) (r * 100) : r; } - public double getFinal(CurrencyType BT) { - return getFinal(BT, false, false); + public double getFinal(CurrencyType type) { + return getFinal(type, false, false); } - public double getFinalAmount(CurrencyType BT, double income) { + public double getFinalAmount(CurrencyType type, double income) { double f = income; if (income > 0 || income < 0 && Jobs.getGCManager().applyToNegativeIncome) - f = income + income * getFinal(BT, false, false); + f = income + income * getFinal(type, false, false); if (income > 0 && f < 0 || income < 0 && f > 0) f = 0; @@ -54,7 +54,7 @@ public class Boost { return f; } - public double getFinal(CurrencyType BT, boolean percent, boolean excludeExtra) { + public double getFinal(CurrencyType type, boolean percent, boolean excludeExtra) { double r = 0D; for (BoostOf one : BoostOf.values()) { @@ -64,10 +64,9 @@ public class Boost { if (excludeExtra && (one == BoostOf.NearSpawner || one == BoostOf.PetPay)) continue; - if (!map.get(one).isValid(BT)) - continue; - - r += map.get(one).get(BT); + BoostMultiplier bm = map.get(one); + if (bm.isValid(type)) + r += bm.get(type); } if (r < -1) diff --git a/src/main/java/com/gamingmesh/jobs/container/BoostMultiplier.java b/src/main/java/com/gamingmesh/jobs/container/BoostMultiplier.java index 96a04182..a5cb6b93 100644 --- a/src/main/java/com/gamingmesh/jobs/container/BoostMultiplier.java +++ b/src/main/java/com/gamingmesh/jobs/container/BoostMultiplier.java @@ -4,7 +4,7 @@ import java.util.HashMap; public class BoostMultiplier implements Cloneable { - private final HashMap map = new HashMap<>(); + private final java.util.Map map = new HashMap<>(); private Long time = 0L; diff --git a/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java b/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java index f9b091e0..f7561242 100644 --- a/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java +++ b/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java @@ -1,14 +1,13 @@ package com.gamingmesh.jobs.container; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import com.gamingmesh.jobs.Jobs; public class ExploreChunk { - private ArrayList playerIds = new ArrayList<>(); + private List playerIds = new ArrayList<>(); private int dbId = -1; private boolean updated = false; @@ -16,12 +15,14 @@ public class ExploreChunk { if (isFullyExplored()) { return new ExploreRespond(Jobs.getExplore().getPlayerAmount() + 1, false); } + boolean newChunkForPlayer = false; if (!playerIds.contains(playerId)) { if (playerIds.size() < Jobs.getExplore().getPlayerAmount()) { playerIds.add(playerId); updated = true; } + newChunkForPlayer = true; } @@ -29,7 +30,8 @@ public class ExploreChunk { playerIds = null; } - return new ExploreRespond(newChunkForPlayer ? getPlayers().size() : getPlayers().size() + 1, newChunkForPlayer); + List players = getPlayers(); + return new ExploreRespond(newChunkForPlayer ? players.size() : players.size() + 1, newChunkForPlayer); } public boolean isAlreadyVisited(int playerId) { @@ -40,7 +42,7 @@ public class ExploreChunk { return isFullyExplored() ? Jobs.getExplore().getPlayerAmount() : playerIds.size(); } - public ArrayList getPlayers() { + public List getPlayers() { return playerIds == null ? new ArrayList<>() : playerIds; } @@ -67,14 +69,13 @@ public class ExploreChunk { playerIds = new ArrayList<>(); } - List split = Arrays.asList(names.split(";")); - for (String one : split) { + for (String one : names.split(";")) { try { int id = Integer.parseInt(one); PlayerInfo info = Jobs.getPlayerManager().getPlayerInfo(id); if (info != null) playerIds.add(id); - } catch (Throwable e) { + } catch (Exception e) { updated = true; JobsPlayer jp = Jobs.getPlayerManager().getJobsPlayer(one); if (jp != null) diff --git a/src/main/java/com/gamingmesh/jobs/container/ExploreRegion.java b/src/main/java/com/gamingmesh/jobs/container/ExploreRegion.java index d5ef04fc..2e179229 100644 --- a/src/main/java/com/gamingmesh/jobs/container/ExploreRegion.java +++ b/src/main/java/com/gamingmesh/jobs/container/ExploreRegion.java @@ -1,6 +1,7 @@ package com.gamingmesh.jobs.container; import java.util.HashMap; +import java.util.Map; import org.bukkit.Chunk; @@ -9,7 +10,7 @@ public class ExploreRegion { int x; int z; - private final HashMap chunks = new HashMap<>(); + private final Map chunks = new HashMap<>(); public ExploreRegion(int x, int z) { this.x = x; @@ -20,7 +21,7 @@ public class ExploreRegion { chunks.put(getPlace(x, z), chunk); } - public HashMap getChunks() { + public Map getChunks() { return chunks; } diff --git a/src/main/java/com/gamingmesh/jobs/container/JobConditions.java b/src/main/java/com/gamingmesh/jobs/container/JobConditions.java index d3131580..338b28d4 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobConditions.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobConditions.java @@ -21,14 +21,15 @@ package com.gamingmesh.jobs.container; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; public class JobConditions { private String node; private final List requiresPerm = new ArrayList<>(); - private final HashMap requiresJobs = new HashMap<>(); - private final HashMap performPerm = new HashMap<>(); + private final Map requiresJobs = new HashMap<>(); + private final Map performPerm = new HashMap<>(); public JobConditions(String node, List requires, List perform) { this.node = node; @@ -73,11 +74,11 @@ public class JobConditions { return requiresPerm; } - public HashMap getRequiredJobs() { + public Map getRequiredJobs() { return requiresJobs; } - public HashMap getPerformPerm() { + public Map getPerformPerm() { return performPerm; } } diff --git a/src/main/java/com/gamingmesh/jobs/container/JobProgression.java b/src/main/java/com/gamingmesh/jobs/container/JobProgression.java index 43ebda2a..11addb01 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobProgression.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobProgression.java @@ -19,6 +19,7 @@ package com.gamingmesh.jobs.container; import java.util.HashMap; +import java.util.Map; import com.gamingmesh.jobs.stuff.TimeManage; @@ -92,7 +93,7 @@ public class JobProgression { public boolean addExperience(double experience) { jPlayer.setSaved(false); this.experience += experience; - this.lastExperience = getLastExperience() + experience; + lastExperience = getLastExperience() + experience; return checkLevelUp(); } @@ -115,7 +116,7 @@ public class JobProgression { public boolean takeExperience(double experience) { jPlayer.setSaved(false); this.experience -= experience; - this.lastExperience = getLastExperience() + experience; + lastExperience = getLastExperience() + experience; return checkLevelUp(); } @@ -151,14 +152,14 @@ public class JobProgression { * Reloads max experience */ public void reloadMaxExperience() { - HashMap param = new HashMap<>(); + Map param = new HashMap<>(); param.put("joblevel", (double) level); param.put("numjobs", (double) jPlayer.getJobProgression().size()); - this.maxExperience = (int) job.getMaxExp(param); + maxExperience = (int) job.getMaxExp(param); } public int getMaxExperience(int level) { - HashMap param = new HashMap<>(); + Map param = new HashMap<>(); param.put("joblevel", (double) level); param.put("numjobs", (double) jPlayer.getJobProgression().size()); return (int) job.getMaxExp(param); @@ -171,18 +172,19 @@ public class JobProgression { private boolean checkLevelUp() { if (level == 1 && experience < 0) experience = 0; + if (experience < 0) return checkLevelDown(); boolean ret = false; while (canLevelUp()) { - int maxLevel = jPlayer.getMaxJobLevelAllowed(job); // Don't level up at max level - if (job.getMaxLevel() > 0 && level >= maxLevel) + if (job.getMaxLevel() > 0 && level >= jPlayer.getMaxJobLevelAllowed(job)) break; level++; experience -= maxExperience; + ret = true; reloadMaxExperience(); jPlayer.reloadLimits(); @@ -205,12 +207,13 @@ public class JobProgression { // Don't level down at 1 if (level <= 1) break; + level--; - int exp = getMaxExperience(level); - experience += exp; + experience += getMaxExperience(level); + ret = true; reloadMaxExperience(); - this.jPlayer.reloadLimits(); + jPlayer.reloadLimits(); } return ret; } @@ -220,7 +223,6 @@ public class JobProgression { * Do this whenever job or level changes * @return if leveled up */ - private boolean reloadMaxExperienceAndCheckLevelUp() { reloadMaxExperience(); return checkLevelUp(); @@ -238,7 +240,9 @@ public class JobProgression { public boolean canRejoin() { if (leftOn == null || leftOn + job.getRejoinCd() < System.currentTimeMillis()) return true; - return jPlayer != null && jPlayer.getPlayer() != null && jPlayer.getPlayer().hasPermission("jobs.rejoinbypass"); + + org.bukkit.entity.Player player = jPlayer != null ? jPlayer.getPlayer() : null; + return player != null && player.hasPermission("jobs.rejoinbypass"); } public String getRejoinTimeMessage() { diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index 493a9280..c2ea3f4a 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -210,12 +210,14 @@ public class JobsPlayer { Player player = getPlayer(); if (player == null || amount == 0) return true; + CurrencyLimit limit = Jobs.getGCManager().getLimit(type); if (!limit.isEnabled()) return true; + PaymentData data = getPaymentLimit(); - Integer value = limits.getOrDefault(type, 0); - if (data.isReachedLimit(type, value)) { + + if (data.isReachedLimit(type, limits.getOrDefault(type, 0))) { String name = type.getName().toLowerCase(); if (player.isOnline() && !data.isInformed() && !data.isReseted(type)) { @@ -311,12 +313,12 @@ public class JobsPlayer { /** * Attempts to get the boost from specific job and {@link CurrencyType} * - * @param JobName + * @param jobName * @param type {@link CurrencyType} * @param force whenever to retrieve as soon as possible without time * @return amount of boost */ - public double getBoost(String JobName, CurrencyType type, boolean force) { + public double getBoost(String jobName, CurrencyType type, boolean force) { double boost = 0D; if (!isOnline() || type == null) @@ -324,14 +326,14 @@ public class JobsPlayer { long time = System.currentTimeMillis(); - if (boostCounter.containsKey(JobName)) { - List counterList = boostCounter.get(JobName); + if (boostCounter.containsKey(jobName)) { + List counterList = boostCounter.get(jobName); for (BoostCounter counter : counterList) { if (counter.getType() != type) continue; if (force || time - counter.getTime() > 1000 * 60) { - boost = getPlayerBoostNew(JobName, type); + boost = getPlayerBoostNew(jobName, type); counter.setBoost(boost); counter.setTime(time); return boost; @@ -340,17 +342,17 @@ public class JobsPlayer { return counter.getBoost(); } - boost = getPlayerBoostNew(JobName, type); + boost = getPlayerBoostNew(jobName, type); counterList.add(new BoostCounter(type, boost, time)); return boost; } - boost = getPlayerBoostNew(JobName, type); + boost = getPlayerBoostNew(jobName, type); List counterList = new ArrayList<>(); counterList.add(new BoostCounter(type, boost, time)); - boostCounter.put(JobName, counterList); + boostCounter.put(jobName, counterList); return boost; } diff --git a/src/main/java/com/gamingmesh/jobs/container/Log.java b/src/main/java/com/gamingmesh/jobs/container/Log.java index ff119cef..1cf3f7ea 100644 --- a/src/main/java/com/gamingmesh/jobs/container/Log.java +++ b/src/main/java/com/gamingmesh/jobs/container/Log.java @@ -24,7 +24,7 @@ public final class Log { LogAmounts logAmount = amountMap.getOrDefault(item, new LogAmounts(item)); logAmount.addCount(); logAmount.add(amounts); - this.amountMap.put(item, logAmount); + amountMap.put(item, logAmount); } public void add(String item, int count, Map amounts) { @@ -32,7 +32,7 @@ public final class Log { logAmount.setCount(count); logAmount.add(amounts); logAmount.setNewEntry(false); - this.amountMap.put(item, logAmount); + amountMap.put(item, logAmount); } public void setDate() { diff --git a/src/main/java/com/gamingmesh/jobs/container/LogAmounts.java b/src/main/java/com/gamingmesh/jobs/container/LogAmounts.java index 6c801a7f..4871c223 100644 --- a/src/main/java/com/gamingmesh/jobs/container/LogAmounts.java +++ b/src/main/java/com/gamingmesh/jobs/container/LogAmounts.java @@ -42,13 +42,11 @@ public final class LogAmounts { if (amount == null) return; - Double a = amounts.getOrDefault(type, 0D); - amounts.put(type, a + amount); + amounts.put(type, amounts.getOrDefault(type, 0D) + amount); } - public Double get(CurrencyType type) { - Double a = amounts.getOrDefault(type, 0D); - return ((int) (a * 100D)) / 100D; + public double get(CurrencyType type) { + return ((int) (amounts.getOrDefault(type, 0D) * 100D)) / 100D; } public void addCount() { diff --git a/src/main/java/com/gamingmesh/jobs/container/Quest.java b/src/main/java/com/gamingmesh/jobs/container/Quest.java index c6427008..e9ab6be0 100644 --- a/src/main/java/com/gamingmesh/jobs/container/Quest.java +++ b/src/main/java/com/gamingmesh/jobs/container/Quest.java @@ -5,6 +5,7 @@ import java.util.Calendar; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import com.gamingmesh.jobs.Jobs; @@ -23,7 +24,7 @@ public class Quest { private boolean stopped = false; - private HashMap> objectives = new HashMap<>(); + private Map> objectives = new HashMap<>(); private final Set actions = new HashSet<>(); public Quest(String questName, Job job) { @@ -154,12 +155,12 @@ public class Quest { return true; } - public HashMap> getObjectives() { + public Map> getObjectives() { return objectives; } public boolean hasObjective(QuestObjective objective) { - HashMap old = objectives.get(objective.getAction()); + Map old = objectives.get(objective.getAction()); if (old == null) return false; @@ -172,7 +173,7 @@ public class Quest { return false; } - public void setObjectives(HashMap> objectives) { + public void setObjectives(Map> objectives) { if (objectives == null) { objectives = new HashMap<>(); } @@ -182,7 +183,7 @@ public class Quest { } public void addObjective(QuestObjective objective) { - HashMap old = objectives.get(objective.getAction()); + Map old = objectives.get(objective.getAction()); if (old == null) { old = new HashMap<>(); old.put(objective.getTargetName(), objective); diff --git a/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java b/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java index 42d8daf8..4e425c9d 100644 --- a/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java +++ b/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java @@ -1,6 +1,7 @@ package com.gamingmesh.jobs.container; import java.util.HashMap; +import java.util.Map; import java.util.Map.Entry; import org.bukkit.Bukkit; @@ -15,7 +16,7 @@ public class QuestProgression { private long validUntil; private boolean givenReward = false; - private final HashMap done = new HashMap<>(); + private final Map done = new HashMap<>(); public QuestProgression(Quest quest) { this.quest = quest; @@ -33,7 +34,7 @@ public class QuestProgression { public int getTotalAmountNeeded() { int amountNeeded = 0; - for (HashMap oneA : quest.getObjectives().values()) { + for (Map oneA : quest.getObjectives().values()) { for (QuestObjective one : oneA.values()) { amountNeeded += one.getAmount(); } @@ -77,7 +78,7 @@ public class QuestProgression { } public boolean isCompleted() { - for (HashMap oneA : quest.getObjectives().values()) { + for (Map oneA : quest.getObjectives().values()) { for (QuestObjective one : oneA.values()) { Integer amountDone = done.get(one); if (amountDone == null || amountDone < one.getAmount()) @@ -112,7 +113,7 @@ public class QuestProgression { } if (!isCompleted()) { - HashMap byAction = quest.getObjectives().get(action.getType()); + Map byAction = quest.getObjectives().get(action.getType()); QuestObjective objective = null; if (byAction != null) { diff --git a/src/main/java/com/gamingmesh/jobs/container/ShopItem.java b/src/main/java/com/gamingmesh/jobs/container/ShopItem.java index 198a8c2f..e9bf4b59 100644 --- a/src/main/java/com/gamingmesh/jobs/container/ShopItem.java +++ b/src/main/java/com/gamingmesh/jobs/container/ShopItem.java @@ -3,6 +3,7 @@ package com.gamingmesh.jobs.container; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; public class ShopItem { @@ -17,7 +18,7 @@ public class ShopItem { private int requiredTotalLevels = -1; - private HashMap requiredJobs = new HashMap<>(); + private Map requiredJobs = new HashMap<>(); private final List iconLore = new ArrayList<>(), requiredPerm = new ArrayList<>(), commands = new ArrayList<>(); private final List items = new ArrayList<>(); @@ -64,11 +65,11 @@ public class ShopItem { return commands; } - public void setRequiredJobs(HashMap requiredJobs) { + public void setRequiredJobs(Map requiredJobs) { this.requiredJobs = requiredJobs; } - public HashMap getRequiredJobs() { + public Map getRequiredJobs() { return requiredJobs; } diff --git a/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java b/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java index 2868ff5b..7b40babd 100644 --- a/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java +++ b/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java @@ -5,8 +5,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.UUID; -import java.util.Map.Entry; import org.bukkit.block.Block; import org.bukkit.configuration.ConfigurationSection; @@ -26,7 +26,7 @@ public class BlockOwnerShip { private BlockTypes type; private String metadataName = ""; - private final HashMap> blockOwnerShips = new HashMap<>(); + private final Map> blockOwnerShips = new HashMap<>(); public BlockOwnerShip(CMIMaterial type) { // Type should be any type of furnace, smoker or brewing stand @@ -69,7 +69,7 @@ public class BlockOwnerShip { return metadataName; } - public HashMap> getBlockOwnerShips() { + public Map> getBlockOwnerShips() { return blockOwnerShips; } @@ -253,7 +253,7 @@ public class BlockOwnerShip { : type == BlockTypes.BREWING_STAND ? "Brewing" : type == BlockTypes.SMOKER ? "Smoker" : ""); f.getConfig().set(path, null); - for (Entry> one : blockOwnerShips.entrySet()) { + for (Map.Entry> one : blockOwnerShips.entrySet()) { String full = ""; for (blockLoc oneL : one.getValue()) { if (!full.isEmpty()) diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index a720bf98..f4176c7b 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -103,15 +103,7 @@ public class JobsPaymentListener implements Listener { private Jobs plugin; - /** - * @deprecated Use {@link Jobs#getBlockOwnerShip(CMIMaterial)} - */ - @Deprecated - public static final String furnaceOwnerMetadata = "jobsFurnaceOwner", blastFurnaceOwnerMetadata = "jobsBlastFurnaceOwner", - brewingOwnerMetadata = "jobsBrewingOwner", smokerOwnerMetadata = "jobsSmokerOwner"; - public static final String VegyMetadata = "VegyTimer"; - - private final String BlockMetadata = "BlockOwner", CowMetadata = "CowTimer", entityDamageByPlayer = "JobsEntityDamagePlayer"; + private final String blockMetadata = "BlockOwner", cowMetadata = "CowTimer", entityDamageByPlayer = "JobsEntityDamagePlayer"; public JobsPaymentListener(Jobs plugin) { this.plugin = plugin; @@ -175,7 +167,7 @@ public class JobsPaymentListener implements Listener { ItemStack currentItem = event.getCurrentItem(); if (resultStack.hasItemMeta() && resultStack.getItemMeta().hasDisplayName()) { - Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(Jobs.getInstance() + Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(plugin .getComplement().getDisplayName(resultStack.getItemMeta())), ActionType.VTRADE)); } else if (currentItem != null) { Jobs.action(jPlayer, new ItemActionInfo(currentItem, ActionType.VTRADE)); @@ -198,7 +190,7 @@ public class JobsPaymentListener implements Listener { while (newItemsCount >= 1) { newItemsCount--; if (resultStack.hasItemMeta() && resultStack.getItemMeta().hasDisplayName()) - Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(Jobs.getInstance() + Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(plugin .getComplement().getDisplayName(resultStack.getItemMeta())), ActionType.VTRADE)); else Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.VTRADE)); @@ -247,8 +239,8 @@ public class JobsPaymentListener implements Listener { } if (Jobs.getGCManager().CowMilkingTimer > 0) { - if (cow.hasMetadata(CowMetadata)) { - long time = cow.getMetadata(CowMetadata).get(0).asLong(); + if (cow.hasMetadata(cowMetadata)) { + long time = cow.getMetadata(cowMetadata).get(0).asLong(); if (System.currentTimeMillis() < time + Jobs.getGCManager().CowMilkingTimer) { long timer = ((Jobs.getGCManager().CowMilkingTimer - (System.currentTimeMillis() - time)) / 1000); jPlayer.getPlayer().sendMessage(Jobs.getLanguage().getMessage("message.cowtimer", "%time%", timer)); @@ -263,7 +255,7 @@ public class JobsPaymentListener implements Listener { Jobs.action(jPlayer, new EntityActionInfo(cow, ActionType.MILK)); Long timer = System.currentTimeMillis(); - cow.setMetadata(CowMetadata, new FixedMetadataValue(plugin, timer)); + cow.setMetadata(cowMetadata, new FixedMetadataValue(plugin, timer)); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @@ -320,7 +312,7 @@ public class JobsPaymentListener implements Listener { if (!Jobs.getGCManager().canPerformActionInWorld(block.getWorld())) return; - BlockOwnerShip ownerShip = Jobs.getInstance().getBlockOwnerShip(CMIMaterial.get(block), false).orElse(null); + BlockOwnerShip ownerShip = plugin.getBlockOwnerShip(CMIMaterial.get(block), false).orElse(null); if (ownerShip == null || !block.hasMetadata(ownerShip.getMetadataName())) return; @@ -690,7 +682,7 @@ public class JobsPaymentListener implements Listener { 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(CMIChatColor.stripColor(Jobs.getInstance() + Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(plugin .getComplement().getDisplayName(resultStack.getItemMeta())), ActionType.CRAFT)); } else if (currentItem != null) { Jobs.action(jPlayer, new ItemActionInfo(currentItem, ActionType.CRAFT)); @@ -713,7 +705,7 @@ public class JobsPaymentListener implements Listener { while (newItemsCount >= 1) { newItemsCount--; if (resultStack.hasItemMeta() && resultStack.getItemMeta().hasDisplayName()) - Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(Jobs.getInstance() + Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(plugin .getComplement().getDisplayName(resultStack.getItemMeta())), ActionType.CRAFT)); else Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.CRAFT)); @@ -841,10 +833,10 @@ public class JobsPaymentListener implements Listener { String originalName = null; String newName = null; if (firstSlot.hasItemMeta()) - originalName = Jobs.getInstance().getComplement().getDisplayName(firstSlot.getItemMeta()); + originalName = plugin.getComplement().getDisplayName(firstSlot.getItemMeta()); if (resultStack.hasItemMeta()) - newName = Jobs.getInstance().getComplement().getDisplayName(resultStack.getItemMeta()); + newName = plugin.getComplement().getDisplayName(resultStack.getItemMeta()); if (originalName != null && !originalName.equals(newName) && inv.getItem(1) == null && !Jobs.getGCManager().PayForRenaming) return; @@ -1533,7 +1525,7 @@ public class JobsPaymentListener implements Listener { plugin.getBlockOwnerShips().forEach(b -> b.remove(block)); - if (Jobs.getGCManager().useBlockProtection && block.getState().hasMetadata(BlockMetadata)) + if (Jobs.getGCManager().useBlockProtection && block.getState().hasMetadata(blockMetadata)) return; Jobs.action(jPlayer, new BlockActionInfo(block, ActionType.TNTBREAK), block); diff --git a/src/main/java/com/gamingmesh/jobs/stuff/FurnaceBrewingHandling.java b/src/main/java/com/gamingmesh/jobs/stuff/FurnaceBrewingHandling.java deleted file mode 100644 index 873d67fe..00000000 --- a/src/main/java/com/gamingmesh/jobs/stuff/FurnaceBrewingHandling.java +++ /dev/null @@ -1,373 +0,0 @@ -package com.gamingmesh.jobs.stuff; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map.Entry; -import java.util.UUID; - -import org.bukkit.block.Block; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.metadata.FixedMetadataValue; -import org.bukkit.metadata.MetadataValue; - -import com.gamingmesh.jobs.Jobs; -import com.gamingmesh.jobs.CMILib.CMIMaterial; -import com.gamingmesh.jobs.config.YmlMaker; -import com.gamingmesh.jobs.container.JobsPlayer; -import com.gamingmesh.jobs.listeners.JobsPaymentListener; - -/** - * @deprecated As of new blocks (smoker, blast furnace) this has been deprecated and - * marked as "removeable". In the future this class will get removed - * and not used anymore by anyone. Instead use {@link Jobs#getBlockOwnerShips()} - */ -@Deprecated -public class FurnaceBrewingHandling { - - static HashMap> furnaceMap = new HashMap<>(); - static HashMap> brewingMap = new HashMap<>(); - - public static void load() { - YmlMaker f = new YmlMaker(Jobs.getFolder(), "furnaceBrewingStands.yml"); - if (!f.exists()) - return; - - int totalf = 0; - int totalb = 0; - - FileConfiguration config = f.getConfig(); - - if (Jobs.getGCManager().isFurnacesReassign()) { - ConfigurationSection section = config.getConfigurationSection("Furnace"); - if (section == null) - return; - - for (String one : section.getKeys(false)) { - String value = section.getString(one); - List ls = new ArrayList<>(); - if (value.contains(";")) - ls.addAll(Arrays.asList(value.split(";"))); - else - ls.add(value); - - UUID uuid = UUID.fromString(one); - if (uuid == null) - continue; - - List blist = new ArrayList<>(); - for (String oneL : ls) { - blockLoc bl = new blockLoc(oneL); - Block block = bl.getBlock(); - if (block == null) - continue; - - block.removeMetadata(JobsPaymentListener.furnaceOwnerMetadata, Jobs.getInstance()); - block.setMetadata(JobsPaymentListener.furnaceOwnerMetadata, new FixedMetadataValue(Jobs.getInstance(), one)); - - blist.add(bl); - } - - if (!blist.isEmpty()) { - furnaceMap.put(uuid, blist); - totalf++; - } - } - } - - if (Jobs.getGCManager().isBrewingStandsReassign()) { - ConfigurationSection section = config.getConfigurationSection("Brewing"); - if (section == null) - return; - - for (String one : section.getKeys(false)) { - String value = section.getString(one); - List ls = new ArrayList<>(); - if (value.contains(";")) - ls.addAll(Arrays.asList(value.split(";"))); - else - ls.add(value); - - UUID uuid = UUID.fromString(one); - if (uuid == null) - continue; - - List blist = new ArrayList<>(); - for (String oneL : ls) { - blockLoc bl = new blockLoc(oneL); - Block block = bl.getBlock(); - if (block == null) - continue; - - block.removeMetadata(JobsPaymentListener.brewingOwnerMetadata, Jobs.getInstance()); - block.setMetadata(JobsPaymentListener.brewingOwnerMetadata, new FixedMetadataValue(Jobs.getInstance(), one)); - - blist.add(bl); - } - - if (!blist.isEmpty()) { - brewingMap.put(uuid, blist); - totalb++; - } - } - } - - if (totalf > 0 || totalb > 0) - Jobs.consoleMsg("&e[Jobs] Loaded " + totalf + " furnaces and " + totalb + " brewing stands for reassigning."); - } - - public static void save() { - YmlMaker f = new YmlMaker(Jobs.getFolder(), "furnaceBrewingStands.yml"); - if (!f.exists()) - f.createNewFile(); - - f.saveDefaultConfig(); - - FileConfiguration config = f.getConfig(); - - if (Jobs.getGCManager().isFurnacesReassign()) { - config.set("Furnace", null); - for (Entry> one : furnaceMap.entrySet()) { - String full = ""; - for (blockLoc oneL : one.getValue()) { - if (!full.isEmpty()) - full += ";"; - - full += oneL.toString(); - } - if (!full.isEmpty()) - config.set("Furnace." + one.getKey().toString(), full); - } - } - - if (Jobs.getGCManager().isBrewingStandsReassign()) { - config.set("Brewing", null); - for (Entry> one : brewingMap.entrySet()) { - String full = ""; - - for (blockLoc oneL : one.getValue()) { - if (!full.isEmpty()) - full += ";"; - - full += oneL.toString(); - } - if (!full.isEmpty()) - config.set("Brewing." + one.getKey().toString(), full); - } - } - - f.saveConfig(); - - } - - public static int getTotalFurnaces(UUID uuid) { - List ls = furnaceMap.get(uuid); - return ls == null ? 0 : ls.size(); - } - - public static int getTotalBrewingStands(UUID uuid) { - List ls = brewingMap.get(uuid); - return ls == null ? 0 : ls.size(); - } - - public static boolean removeFurnace(Block block) { - UUID uuid = null; - if (block.hasMetadata(JobsPaymentListener.furnaceOwnerMetadata)) { - List data = block.getMetadata(JobsPaymentListener.furnaceOwnerMetadata); - if (!data.isEmpty()) { - // only care about first - MetadataValue value = data.get(0); - String uuidS = value.asString(); - uuid = UUID.fromString(uuidS); - } - } - - if (uuid == null) { - return false; - } - - List ls = furnaceMap.get(uuid); - if (ls == null) - return false; - - for (blockLoc one : ls) { - if (!one.getLocation().equals(block.getLocation())) - continue; - - block.removeMetadata(JobsPaymentListener.furnaceOwnerMetadata, Jobs.getInstance()); - ls.remove(one); - return true; - } - return false; - } - - public static boolean removeBrewing(Block block) { - UUID uuid = null; - if (block.hasMetadata(JobsPaymentListener.brewingOwnerMetadata)) { - List data = block.getMetadata(JobsPaymentListener.brewingOwnerMetadata); - if (!data.isEmpty()) { - // only care about first - MetadataValue value = data.get(0); - String uuidS = value.asString(); - uuid = UUID.fromString(uuidS); - } - } - - if (uuid == null) { - return false; - } - - List ls = brewingMap.get(uuid); - if (ls == null) - return false; - - for (blockLoc one : ls) { - if (!one.getLocation().equals(block.getLocation())) - continue; - - block.removeMetadata(JobsPaymentListener.brewingOwnerMetadata, Jobs.getInstance()); - ls.remove(one); - return true; - } - return false; - } - - public enum ownershipFeedback { - invalid, tooMany, newReg, old, notOwn - } - - public static ownershipFeedback registerFurnaces(Player player, Block block) { - CMIMaterial cmat = CMIMaterial.get(block); - if (cmat != CMIMaterial.FURNACE && cmat != CMIMaterial.LEGACY_BURNING_FURNACE && cmat != CMIMaterial.SMOKER && cmat != CMIMaterial.BLAST_FURNACE) - return ownershipFeedback.invalid; - - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); - int max = jPlayer.getMaxFurnacesAllowed(); - int have = jPlayer.getFurnaceCount(); - - boolean owner = false; - if (block.hasMetadata(JobsPaymentListener.furnaceOwnerMetadata)) { - List data = block.getMetadata(JobsPaymentListener.furnaceOwnerMetadata); - if (!data.isEmpty()) { - // only care about first - MetadataValue value = data.get(0); - String uuid = value.asString(); - - if (uuid.equals(player.getUniqueId().toString())) { - if (have > max && max > 0) - removeFurnace(block); - owner = true; - } else - return ownershipFeedback.notOwn; - } - } - - if (owner) - return ownershipFeedback.old; - - if (have >= max && max > 0) - return ownershipFeedback.tooMany; - - block.setMetadata(JobsPaymentListener.furnaceOwnerMetadata, new FixedMetadataValue(Jobs.getInstance(), player.getUniqueId().toString())); - - if (!Jobs.getGCManager().isFurnacesReassign() && !Jobs.getGCManager().BlastFurnacesReassign && !Jobs.getGCManager().SmokerReassign) { - return ownershipFeedback.newReg; - } - - List ls = furnaceMap.get(player.getUniqueId()); - if (ls == null) - ls = new ArrayList<>(); - - ls.add(new blockLoc(block.getLocation())); - furnaceMap.put(player.getUniqueId(), ls); - return ownershipFeedback.newReg; - } - - public static ownershipFeedback registerBrewingStand(Player player, Block block) { - if (CMIMaterial.get(block) != CMIMaterial.BREWING_STAND && CMIMaterial.get(block) != CMIMaterial.LEGACY_BREWING_STAND) - return ownershipFeedback.invalid; - - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); - int max = jPlayer.getMaxBrewingStandsAllowed(); - int have = jPlayer.getBrewingStandCount(); - - boolean owner = false; - if (block.hasMetadata(JobsPaymentListener.brewingOwnerMetadata)) { - List data = block.getMetadata(JobsPaymentListener.brewingOwnerMetadata); - if (!data.isEmpty()) { - // only care about first - MetadataValue value = data.get(0); - String uuid = value.asString(); - - if (uuid.equals(player.getUniqueId().toString())) { - if (have > max && max > 0) - removeBrewing(block); - owner = true; - } else - return ownershipFeedback.notOwn; - } - } - - if (owner) - return ownershipFeedback.old; - - if (have >= max && max > 0) - return ownershipFeedback.tooMany; - - block.setMetadata(JobsPaymentListener.brewingOwnerMetadata, new FixedMetadataValue(Jobs.getInstance(), player.getUniqueId().toString())); - - if (!Jobs.getGCManager().isBrewingStandsReassign()) { - return ownershipFeedback.newReg; - } - - List ls = brewingMap.get(player.getUniqueId()); - if (ls == null) - ls = new ArrayList<>(); - - ls.add(new blockLoc(block.getLocation())); - brewingMap.put(player.getUniqueId(), ls); - return ownershipFeedback.newReg; - } - - public static int clearFurnaces(UUID uuid) { - List ls = furnaceMap.remove(uuid); - if (ls == null) - return 0; - - for (blockLoc one : ls) { - Block block = one.getBlock(); - CMIMaterial cmat = CMIMaterial.get(block); - if (cmat != CMIMaterial.FURNACE && cmat != CMIMaterial.LEGACY_BURNING_FURNACE && cmat != CMIMaterial.SMOKER && cmat != CMIMaterial.BLAST_FURNACE) - continue; - - block.removeMetadata(JobsPaymentListener.furnaceOwnerMetadata, Jobs.getInstance()); - } - - return ls.size(); - } - - public static int clearBrewingStands(UUID uuid) { - List ls = brewingMap.remove(uuid); - if (ls == null) - return 0; - - for (blockLoc one : ls) { - Block block = one.getBlock(); - if (CMIMaterial.get(block) == CMIMaterial.BREWING_STAND) - block.removeMetadata(JobsPaymentListener.brewingOwnerMetadata, Jobs.getInstance()); - } - - return ls.size(); - } - - public static HashMap> getBrewingMap() { - return brewingMap; - } - - public static HashMap> getFurnaceMap() { - return furnaceMap; - } -} diff --git a/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement2.java b/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement2.java index 0f839d06..e870ef65 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement2.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement2.java @@ -21,7 +21,7 @@ public class Complement2 implements Complement { } protected Component deserialize(String t) { - return PlainComponentSerializer.plain().deserialize(t); + return Component.text(t); } @Override