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

Fix some boost time parsing issues

This commit is contained in:
montlikadani 2021-01-27 18:28:30 +01:00
parent 1170086166
commit 865bcca5c0
8 changed files with 123 additions and 58 deletions

View File

@ -87,16 +87,34 @@ public class expboost implements Cmd {
return arr; return arr;
} }
if (time.contains("s") || time.contains("second")) { if (time.contains("h") || time.contains("hour")) {
arr[0] = Integer.parseInt(time.split("s|second")[0]); try {
arr[2] = Integer.parseInt(time.split("h|hour")[0]);
} catch (NumberFormatException e) {
arr[2] = 0;
}
time = time.replaceAll(arr[2] + "+[h|hour]+", "");
} }
if (time.contains("m") || time.contains("minute")) { if (time.contains("m") || time.contains("minute")) {
arr[1] = Integer.parseInt(time.split("m|minute")[0]); try {
arr[1] = Integer.parseInt(time.split("m|minute")[0]);
} catch (NumberFormatException e) {
arr[1] = 0;
}
time = time.replaceAll(arr[1] + "+[m|minute]+", "");
} }
if (time.contains("h") || time.contains("hour")) { if (time.contains("s") || time.contains("second")) {
arr[2] = Integer.parseInt(time.split("h|hour")[0]); try {
arr[0] = Integer.parseInt(time.split("s|second")[0]);
} catch (NumberFormatException e) {
arr[0] = 0;
}
time = time.replaceAll(arr[0] + "+[s|second]+", "");
} }
if (arr[0] == 0 && arr[1] == 0 && arr[2] == 0) { if (arr[0] == 0 && arr[1] == 0 && arr[2] == 0) {

View File

@ -87,16 +87,34 @@ public class moneyboost implements Cmd {
return arr; return arr;
} }
if (time.contains("s") || time.contains("second")) { if (time.contains("h") || time.contains("hour")) {
arr[0] = Integer.parseInt(time.split("s|second")[0]); try {
arr[2] = Integer.parseInt(time.split("h|hour")[0]);
} catch (NumberFormatException e) {
arr[2] = 0;
}
time = time.replaceAll(arr[2] + "+[h|hour]+", "");
} }
if (time.contains("m") || time.contains("minute")) { if (time.contains("m") || time.contains("minute")) {
arr[1] = Integer.parseInt(time.split("m|minute")[0]); try {
arr[1] = Integer.parseInt(time.split("m|minute")[0]);
} catch (NumberFormatException e) {
arr[1] = 0;
}
time = time.replaceAll(arr[1] + "+[m|minute]+", "");
} }
if (time.contains("h") || time.contains("hour")) { if (time.contains("s") || time.contains("second")) {
arr[2] = Integer.parseInt(time.split("h|hour")[0]); try {
arr[0] = Integer.parseInt(time.split("s|second")[0]);
} catch (NumberFormatException e) {
arr[0] = 0;
}
time = time.replaceAll(arr[0] + "+[s|second]+", "");
} }
if (arr[0] == 0 && arr[1] == 0 && arr[2] == 0) { if (arr[0] == 0 && arr[1] == 0 && arr[2] == 0) {

View File

@ -87,16 +87,34 @@ public class pointboost implements Cmd {
return arr; return arr;
} }
if (time.contains("s") || time.contains("second")) { if (time.contains("h") || time.contains("hour")) {
arr[0] = Integer.parseInt(time.split("s|second")[0]); try {
arr[2] = Integer.parseInt(time.split("h|hour")[0]);
} catch (NumberFormatException e) {
arr[2] = 0;
}
time = time.replaceAll(arr[2] + "+[h|hour]+", "");
} }
if (time.contains("m") || time.contains("minute")) { if (time.contains("m") || time.contains("minute")) {
arr[1] = Integer.parseInt(time.split("m|minute")[0]); try {
arr[1] = Integer.parseInt(time.split("m|minute")[0]);
} catch (NumberFormatException e) {
arr[1] = 0;
}
time = time.replaceAll(arr[1] + "+[m|minute]+", "");
} }
if (time.contains("h") || time.contains("hour")) { if (time.contains("s") || time.contains("second")) {
arr[2] = Integer.parseInt(time.split("h|hour")[0]); try {
arr[0] = Integer.parseInt(time.split("s|second")[0]);
} catch (NumberFormatException e) {
arr[0] = 0;
}
time = time.replaceAll(arr[0] + "+[s|second]+", "");
} }
if (arr[0] == 0 && arr[1] == 0 && arr[2] == 0) { if (arr[0] == 0 && arr[1] == 0 && arr[2] == 0) {

View File

@ -64,7 +64,7 @@ public class Boost {
if (excludeExtra && (one == BoostOf.NearSpawner || one == BoostOf.PetPay)) if (excludeExtra && (one == BoostOf.NearSpawner || one == BoostOf.PetPay))
continue; continue;
if (!map.get(one).isValid()) if (!map.get(one).isValid(BT))
continue; continue;
r += map.get(one).get(BT); r += map.get(one).get(BT);

View File

@ -42,6 +42,7 @@ public class BoostMultiplier {
} }
public double get(CurrencyType type) { public double get(CurrencyType type) {
isValid(type); // Call without check to make sure map cache is removed
return map.getOrDefault(type, 0D); return map.getOrDefault(type, 0D);
} }
@ -49,22 +50,19 @@ public class BoostMultiplier {
return time; return time;
} }
public void setTime(Long time) { public boolean isValid(CurrencyType type) {
this.time = time; boolean valid = time > System.currentTimeMillis();
} if (!valid) {
map.remove(type);
public boolean isValid() { time = 0L;
if (time == 0L) {
return true;
} }
return time > System.currentTimeMillis(); return time == 0L || valid;
} }
public void add(BoostMultiplier armorboost) { public void add(BoostMultiplier armorboost) {
for (CurrencyType one : CurrencyType.values()) { for (CurrencyType one : CurrencyType.values()) {
double r = armorboost.get(one); map.put(one, get(one) + armorboost.get(one));
map.put(one, get(one) + r);
} }
} }
} }

View File

@ -121,15 +121,13 @@ public class Job {
} }
} }
public void addBoost(CurrencyType type, double Point) { public void addBoost(CurrencyType type, double point) {
boost.add(type, Point); boost.add(type, point);
} }
public void addBoost(CurrencyType type, double point, int[] times) { public void addBoost(CurrencyType type, double point, int[] times) {
final int h = times[2], final int h = times[2], m = times[1], s = times[0];
m = times[1], if (h == 0 && m == 0 && s == 0) {
s = times[0];
if (times.length < 3 || (h == 0 && m == 0 && s == 0)) {
addBoost(type, point); addBoost(type, point);
return; return;
} }
@ -144,8 +142,8 @@ public class Job {
boost.add(type, point, cal.getTimeInMillis()); boost.add(type, point, cal.getTimeInMillis());
} }
public void setBoost(BoostMultiplier BM) { public void setBoost(BoostMultiplier boost) {
this.boost = BM; this.boost = boost;
} }
public BoostMultiplier getBoost() { public BoostMultiplier getBoost() {

View File

@ -34,51 +34,59 @@ import com.gamingmesh.jobs.CMILib.CMIMaterial;
import com.gamingmesh.jobs.CMILib.CMIReflections; import com.gamingmesh.jobs.CMILib.CMIReflections;
public class JobItems { public class JobItems {
private String node; private String node;
private String legacyKey = null; private String legacyKey;
private ItemStack item; private ItemStack item;
private HashMap<Enchantment, Integer> enchants; private HashMap<Enchantment, Integer> enchants;
private BoostMultiplier boostMultiplier = new BoostMultiplier(); private BoostMultiplier boostMultiplier = new BoostMultiplier();
private List<Job> jobs = new ArrayList<>(); private List<Job> jobs = new ArrayList<>();
private int fromLevel = 0; private int fromLevel = 0;
private int untilLevel = Integer.MAX_VALUE; private int untilLevel = Integer.MAX_VALUE;
public JobItems(String node, CMIMaterial mat, int amount, String name, List<String> lore, HashMap<Enchantment, Integer> enchants, BoostMultiplier boostMultiplier, List<Job> jobs) { public JobItems(String node, CMIMaterial mat, int amount, String name, List<String> lore, HashMap<Enchantment, Integer> enchants, BoostMultiplier boostMultiplier, List<Job> jobs) {
mat = mat == null ? CMIMaterial.STONE : mat; if (mat == null) {
mat = CMIMaterial.STONE;
}
this.enchants = enchants; this.enchants = enchants;
item = mat.newItemStack(); this.node = node;
ItemMeta meta = item.getItemMeta(); if (boostMultiplier != null) {
if (meta == null) { this.boostMultiplier = boostMultiplier;
return;
} }
if (name != null) setJobs(jobs);
meta.setDisplayName(CMIChatColor.translate(name));
if (lore != null)
meta.setLore(lore);
if (enchants != null) { ItemMeta meta = (item = mat.newItemStack()).getItemMeta();
if (mat == CMIMaterial.ENCHANTED_BOOK) { if (meta != null) {
EnchantmentStorageMeta bookMeta = (EnchantmentStorageMeta) meta; if (name != null)
for (Entry<Enchantment, Integer> oneEnch : enchants.entrySet()) { meta.setDisplayName(CMIChatColor.translate(name));
bookMeta.addStoredEnchant(oneEnch.getKey(), oneEnch.getValue(), true);
} if (lore != null)
} else { meta.setLore(lore);
for (Entry<Enchantment, Integer> oneEnchant : enchants.entrySet()) {
meta.addEnchant(oneEnchant.getKey(), oneEnchant.getValue(), true); if (enchants != null) {
if (mat == CMIMaterial.ENCHANTED_BOOK) {
EnchantmentStorageMeta bookMeta = (EnchantmentStorageMeta) meta;
for (Entry<Enchantment, Integer> oneEnch : enchants.entrySet()) {
bookMeta.addStoredEnchant(oneEnch.getKey(), oneEnch.getValue(), true);
}
} else {
for (Entry<Enchantment, Integer> oneEnchant : enchants.entrySet()) {
meta.addEnchant(oneEnchant.getKey(), oneEnchant.getValue(), true);
}
} }
} }
item.setItemMeta(meta);
} }
item.setItemMeta(meta);
item.setAmount(amount); item.setAmount(amount);
item = CMIReflections.setNbt(item, "JobsItemBoost", node); item = CMIReflections.setNbt(item, "JobsItemBoost", node);
this.node = node;
this.boostMultiplier = boostMultiplier;
setJobs(jobs);
} }
public String getNode() { public String getNode() {

View File

@ -53,12 +53,19 @@ public class blockLoc {
if (!loc.contains(":")) if (!loc.contains(":"))
return false; return false;
String[] split = loc.split(":"); String[] split = loc.split(":");
if (split.length == 0) {
return false;
}
World w = Bukkit.getWorld(split[0]); World w = Bukkit.getWorld(split[0]);
if (w == null) if (w == null)
return false; return false;
this.w = w; this.w = w;
if (split.length < 4) {
return false;
}
try { try {
x = Integer.parseInt(split[1]); x = Integer.parseInt(split[1]);
y = Integer.parseInt(split[2]); y = Integer.parseInt(split[2]);