Bug fixes.

This commit is contained in:
Mateus Moreira 2018-08-01 18:54:06 +01:00
parent dc142b4fb3
commit 2b13b4ad8a
8 changed files with 25 additions and 21 deletions

View File

@ -138,8 +138,8 @@ public final class CitizensCMD extends JavaPlugin {
waitingList = new HashMap<>(); waitingList = new HashMap<>();
if (getConfig().contains("cooldonw-time-display")) { if (getConfig().contains("cooldown-time-display")) {
switch (getConfig().getString("cooldonw-time-display").toLowerCase()) { switch (getConfig().getString("cooldown-time-display").toLowerCase()) {
case "short": case "short":
displayFormat = DisplayFormat.SHORT; displayFormat = DisplayFormat.SHORT;
break; break;

View File

@ -150,7 +150,8 @@ public class NPCListener implements Listener {
}); });
} }
if (!player.hasPermission("citizenscmd.bypass"))
if (!player.hasPermission("citizenscmd.bypass") || CitizensCMD.getPlugin().getDataHandler().getNPCCooldown(npc) != 0)
CitizensCMD.getPlugin().getCooldownHandler().addInteraction(npc, player.getUniqueId().toString(), System.nanoTime()); CitizensCMD.getPlugin().getCooldownHandler().addInteraction(npc, player.getUniqueId().toString(), System.nanoTime());
} }
@ -251,7 +252,7 @@ public class NPCListener implements Listener {
}); });
} }
if (!player.hasPermission("citizenscmd.bypass")) if (!player.hasPermission("citizenscmd.bypass") || CitizensCMD.getPlugin().getDataHandler().getNPCCooldown(npc) != 0)
CitizensCMD.getPlugin().getCooldownHandler().addInteraction(npc, player.getUniqueId().toString(), System.nanoTime()); CitizensCMD.getPlugin().getCooldownHandler().addInteraction(npc, player.getUniqueId().toString(), System.nanoTime());
} }

View File

@ -28,7 +28,7 @@ import static me.mattmoreira.citizenscmd.utility.Util.*;
public class CMDPrice extends CommandBase { public class CMDPrice extends CommandBase {
public CMDPrice() { public CMDPrice() {
super("price", "citizenscmd.price", false, new String[]{"cd"}, 1, 1); super("price", "citizenscmd.price", false, new String[]{"p"}, 1, 1);
} }
@Override @Override

View File

@ -135,7 +135,7 @@ public class CooldownHandler {
* @param uuid The player uuid * @param uuid The player uuid
* @return returns in seconds the time left * @return returns in seconds the time left
*/ */
public int getTimeLeft(int npc, String uuid) { public long getTimeLeft(int npc, String uuid) {
return CitizensCMD.getPlugin().getDataHandler().getNPCCooldown(npc) - getSecondsDifference(cooldownData.get("cooldown-data.npc-" + npc + "." + uuid)); return CitizensCMD.getPlugin().getDataHandler().getNPCCooldown(npc) - getSecondsDifference(cooldownData.get("cooldown-data.npc-" + npc + "." + uuid));
} }
@ -150,9 +150,12 @@ public class CooldownHandler {
if (cooldownData.containsKey("cooldown-data.npc-" + npc + "." + uuid)) { if (cooldownData.containsKey("cooldown-data.npc-" + npc + "." + uuid)) {
if (CitizensCMD.getPlugin().getDataHandler().getNPCCooldown(npc) == -1) if (CitizensCMD.getPlugin().getDataHandler().getNPCCooldown(npc) == -1)
return true; return true;
else else {
System.out.println("seconds left: " + getSecondsDifference(cooldownData.get("cooldown-data.npc-" + npc + "." + uuid)));
System.out.println("CD: " +CitizensCMD.getPlugin().getDataHandler().getNPCCooldown(npc));
return getSecondsDifference(cooldownData.get("cooldown-data.npc-" + npc + "." + uuid)) < CitizensCMD.getPlugin().getDataHandler().getNPCCooldown(npc); return getSecondsDifference(cooldownData.get("cooldown-data.npc-" + npc + "." + uuid)) < CitizensCMD.getPlugin().getDataHandler().getNPCCooldown(npc);
} }
}
return false; return false;
} }

View File

@ -283,7 +283,7 @@ public class DataHandler {
* @return Returns the NPC price * @return Returns the NPC price
*/ */
public double getPrice(int npc) { public double getPrice(int npc) {
return data.containsKey("npc-data.npc-" + npc + ".price") ? (double) data.get("npc-data.npc-" + npc + ".price") : 0.0; return data.containsKey("npc-data.npc-" + npc + ".price") ? Double.parseDouble(data.get("npc-data.npc-" + npc + ".price").toString()) : 0.0;
} }
/** /**

View File

@ -41,7 +41,7 @@ public class TimeUtil {
* @param seconds The time in seconds to be converted * @param seconds The time in seconds to be converted
* @return String with the time like "2d 2h 2m 2s" * @return String with the time like "2d 2h 2m 2s"
*/ */
public static String getFormattedTime(int seconds, DisplayFormat format) { public static String getFormattedTime(long seconds, DisplayFormat format) {
String messagesString[] = new String[4]; String messagesString[] = new String[4];
messagesString[0] = CitizensCMD.getPlugin().getLang().getMessage(Path.SECONDS); messagesString[0] = CitizensCMD.getPlugin().getLang().getMessage(Path.SECONDS);
@ -90,8 +90,8 @@ public class TimeUtil {
return seconds + secondFormat; return seconds + secondFormat;
} }
int minutes = (int) TimeUnit.SECONDS.toMinutes(seconds); long minutes = TimeUnit.SECONDS.toMinutes(seconds);
int secondsLeft = seconds - (int) TimeUnit.MINUTES.toSeconds(minutes); long secondsLeft = seconds - TimeUnit.MINUTES.toSeconds(minutes);
if (minutes < 60) { if (minutes < 60) {
if (minutes == 1 && !format.equals(DisplayFormat.SHORT)) { if (minutes == 1 && !format.equals(DisplayFormat.SHORT)) {
@ -112,13 +112,13 @@ public class TimeUtil {
} }
if (minutes < 1440) { if (minutes < 1440) {
int hours = (int) TimeUnit.MINUTES.toHours(minutes); long hours = TimeUnit.MINUTES.toHours(minutes);
String time; String time;
if (hours == 1 && !format.equals(DisplayFormat.SHORT)) if (hours == 1 && !format.equals(DisplayFormat.SHORT))
time = hours + hourFormat.substring(0, hourFormat.length() - 1); time = hours + hourFormat.substring(0, hourFormat.length() - 1);
else else
time = hours + hourFormat; time = hours + hourFormat;
int leftOver = minutes - (int) TimeUnit.HOURS.toMinutes(hours); long leftOver = minutes - TimeUnit.HOURS.toMinutes(hours);
if (leftOver >= 1) { if (leftOver >= 1) {
if (leftOver == 1 && !format.equals(DisplayFormat.SHORT)) if (leftOver == 1 && !format.equals(DisplayFormat.SHORT))
@ -136,13 +136,13 @@ public class TimeUtil {
return time; return time;
} }
int days = (int) TimeUnit.MINUTES.toDays(minutes); long days = TimeUnit.MINUTES.toDays(minutes);
String time; String time;
if (days == 1 && !format.equals(DisplayFormat.SHORT)) if (days == 1 && !format.equals(DisplayFormat.SHORT))
time = days + dayFormat.substring(0, dayFormat.length() - 1); time = days + dayFormat.substring(0, dayFormat.length() - 1);
else else
time = days + dayFormat; time = days + dayFormat;
int leftOver = minutes - (int) TimeUnit.DAYS.toMinutes(days); long leftOver = minutes - TimeUnit.DAYS.toMinutes(days);
if (leftOver >= 1) { if (leftOver >= 1) {
if (leftOver < 60) { if (leftOver < 60) {
@ -151,12 +151,12 @@ public class TimeUtil {
else else
time += " " + leftOver + minuteFormat; time += " " + leftOver + minuteFormat;
} else { } else {
int hours = (int) TimeUnit.MINUTES.toHours(leftOver); long hours = TimeUnit.MINUTES.toHours(leftOver);
if (hours == 1 && !format.equals(DisplayFormat.SHORT)) if (hours == 1 && !format.equals(DisplayFormat.SHORT))
time += " " + hours + hourFormat.substring(0, hourFormat.length() - 1); time += " " + hours + hourFormat.substring(0, hourFormat.length() - 1);
else else
time += " " + hours + hourFormat; time += " " + hours + hourFormat;
int minsLeft = leftOver - (int) TimeUnit.HOURS.toMinutes(hours); long minsLeft = leftOver - TimeUnit.HOURS.toMinutes(hours);
if (minsLeft == 1 && !format.equals(DisplayFormat.SHORT)) if (minsLeft == 1 && !format.equals(DisplayFormat.SHORT))
time += " " + minsLeft + minuteFormat.substring(0, minuteFormat.length() - 1); time += " " + minsLeft + minuteFormat.substring(0, minuteFormat.length() - 1);
else else

View File

@ -164,8 +164,8 @@ public class Util {
* @param storedTime the stored time to compare * @param storedTime the stored time to compare
* @return returns the difference in seconds * @return returns the difference in seconds
*/ */
public static int getSecondsDifference(long storedTime) { public static long getSecondsDifference(long storedTime) {
return (int) TimeUnit.SECONDS.convert((System.nanoTime() - storedTime), TimeUnit.NANOSECONDS); return TimeUnit.SECONDS.convert((System.nanoTime() - storedTime), TimeUnit.NANOSECONDS);
} }
} }

View File

@ -5,7 +5,7 @@
# Enables Checking for update. # Enables Checking for update.
check-updates: true check-updates: true
# #
# Available languages EN, PT # Available languages EN, PT, BG, RO, NO
lang: en lang: en
# #
# The default npc cooldown in seconds # The default npc cooldown in seconds
@ -15,4 +15,4 @@ default-cooldown: 0
shift-confirm: true shift-confirm: true
# #
# Select cooldown display format, SHORT = 3m 3s | MEDIUM = 3 min 3 sec | FULL - 3 minutes 3 seconds # Select cooldown display format, SHORT = 3m 3s | MEDIUM = 3 min 3 sec | FULL - 3 minutes 3 seconds
cooldonw-time-display: MEDIUM cooldown-time-display: MEDIUM