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;
}
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")) {
try {
arr[1] = Integer.parseInt(time.split("m|minute")[0]);
} catch (NumberFormatException e) {
arr[1] = 0;
}
if (time.contains("h") || time.contains("hour")) {
arr[2] = Integer.parseInt(time.split("h|hour")[0]);
time = time.replaceAll(arr[1] + "+[m|minute]+", "");
}
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")) {
try {
arr[1] = Integer.parseInt(time.split("m|minute")[0]);
} catch (NumberFormatException e) {
arr[1] = 0;
}
if (time.contains("h") || time.contains("hour")) {
arr[2] = Integer.parseInt(time.split("h|hour")[0]);
time = time.replaceAll(arr[1] + "+[m|minute]+", "");
}
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")) {
try {
arr[1] = Integer.parseInt(time.split("m|minute")[0]);
} catch (NumberFormatException e) {
arr[1] = 0;
}
if (time.contains("h") || time.contains("hour")) {
arr[2] = Integer.parseInt(time.split("h|hour")[0]);
time = time.replaceAll(arr[1] + "+[m|minute]+", "");
}
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(CurrencyType type) {
boolean valid = time > System.currentTimeMillis();
if (!valid) {
map.remove(type);
time = 0L;
}
public boolean isValid() {
if (time == 0L) {
return true;
}
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,28 +34,38 @@ 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;
this.enchants = enchants;
item = mat.newItemStack();
ItemMeta meta = item.getItemMeta();
if (meta == null) {
return;
if (mat == null) {
mat = CMIMaterial.STONE;
}
this.enchants = enchants;
this.node = node;
if (boostMultiplier != null) {
this.boostMultiplier = boostMultiplier;
}
setJobs(jobs);
ItemMeta meta = (item = mat.newItemStack()).getItemMeta();
if (meta != null) {
if (name != null)
meta.setDisplayName(CMIChatColor.translate(name));
if (lore != null)
meta.setLore(lore);
@ -73,12 +83,10 @@ public class JobItems {
}
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]);