1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 14:05:25 +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;
}
if (time.contains("s") || time.contains("second")) {
arr[0] = Integer.parseInt(time.split("s|second")[0]);
if (time.contains("h") || time.contains("hour")) {
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")) {
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")) {
arr[2] = Integer.parseInt(time.split("h|hour")[0]);
if (time.contains("s") || time.contains("second")) {
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) {

View File

@ -87,16 +87,34 @@ public class moneyboost implements Cmd {
return arr;
}
if (time.contains("s") || time.contains("second")) {
arr[0] = Integer.parseInt(time.split("s|second")[0]);
if (time.contains("h") || time.contains("hour")) {
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")) {
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")) {
arr[2] = Integer.parseInt(time.split("h|hour")[0]);
if (time.contains("s") || time.contains("second")) {
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) {

View File

@ -87,16 +87,34 @@ public class pointboost implements Cmd {
return arr;
}
if (time.contains("s") || time.contains("second")) {
arr[0] = Integer.parseInt(time.split("s|second")[0]);
if (time.contains("h") || time.contains("hour")) {
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")) {
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")) {
arr[2] = Integer.parseInt(time.split("h|hour")[0]);
if (time.contains("s") || time.contains("second")) {
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) {

View File

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

View File

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

View File

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

View File

@ -34,51 +34,59 @@ import com.gamingmesh.jobs.CMILib.CMIMaterial;
import com.gamingmesh.jobs.CMILib.CMIReflections;
public class JobItems {
private String node;
private String legacyKey = null;
private String legacyKey;
private ItemStack item;
private HashMap<Enchantment, Integer> enchants;
private BoostMultiplier boostMultiplier = new BoostMultiplier();
private List<Job> jobs = new ArrayList<>();
private int fromLevel = 0;
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) {
mat = mat == null ? CMIMaterial.STONE : mat;
if (mat == null) {
mat = CMIMaterial.STONE;
}
this.enchants = enchants;
item = mat.newItemStack();
this.node = node;
ItemMeta meta = item.getItemMeta();
if (meta == null) {
return;
if (boostMultiplier != null) {
this.boostMultiplier = boostMultiplier;
}
if (name != null)
meta.setDisplayName(CMIChatColor.translate(name));
if (lore != null)
meta.setLore(lore);
setJobs(jobs);
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);
ItemMeta meta = (item = mat.newItemStack()).getItemMeta();
if (meta != null) {
if (name != null)
meta.setDisplayName(CMIChatColor.translate(name));
if (lore != null)
meta.setLore(lore);
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 = CMIReflections.setNbt(item, "JobsItemBoost", node);
this.node = node;
this.boostMultiplier = boostMultiplier;
setJobs(jobs);
}
public String getNode() {

View File

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