mirror of
https://github.com/NLthijs48/AreaShop.git
synced 2024-07-11 22:25:30 +02:00
Fix maxRentTime, inactiveTimeUntilUnrent/-Sell settings
Made a misake while converting these settings to accept human-readable durations strings instead of only minutes.
This commit is contained in:
parent
dfbc7805b5
commit
b1a56b5230
|
@ -743,7 +743,11 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
|
|||
*/
|
||||
public long getDurationFromSecondsOrString(String path) {
|
||||
if(getConfig().isLong(path) || getConfig().isInt(path)) {
|
||||
return getConfig().getLong(path)*1000;
|
||||
long setting = getConfig().getLong(path);
|
||||
if(setting != -1) {
|
||||
setting = setting*1000;
|
||||
}
|
||||
return setting;
|
||||
} else {
|
||||
return durationStringToLong(getConfig().getString(path));
|
||||
}
|
||||
|
@ -756,12 +760,52 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
|
|||
*/
|
||||
public long getDurationFromMinutesOrString(String path) {
|
||||
if(getConfig().isLong(path) || getConfig().isInt(path)) {
|
||||
return getConfig().getLong(path)*60*1000;
|
||||
long setting = getConfig().getLong(path);
|
||||
if(setting != -1) {
|
||||
setting = setting*60*1000;
|
||||
}
|
||||
return setting;
|
||||
} else {
|
||||
return durationStringToLong(getConfig().getString(path));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a time setting that could be minutes or a duration string
|
||||
* @param input The string to parse
|
||||
* @return milliseconds that the string indicates
|
||||
*/
|
||||
public long getDurationFromMinutesOrStringInput(String input) {
|
||||
long number;
|
||||
try {
|
||||
number = Long.parseLong(input);
|
||||
if(number != -1) {
|
||||
number = number*60*1000;
|
||||
}
|
||||
return number;
|
||||
} catch(NumberFormatException e) {
|
||||
return durationStringToLong(input);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a time setting that could be seconds or a duration string
|
||||
* @param input The string to parse
|
||||
* @return seconds that the string indicates
|
||||
*/
|
||||
public long getDurationFromSecondsOrStringInput(String input) {
|
||||
long number;
|
||||
try {
|
||||
number = Long.parseLong(input);
|
||||
if(number != -1) {
|
||||
number = number*1000;
|
||||
}
|
||||
return number;
|
||||
} catch(NumberFormatException e) {
|
||||
return durationStringToLong(input);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an debug message to the console
|
||||
* @param message The message that should be printed to the console
|
||||
|
|
|
@ -231,10 +231,10 @@ public class BuyRegion extends GeneralRegion {
|
|||
|
||||
/**
|
||||
* Minutes until automatic unrent when player is offline
|
||||
* @return The number of minutes until the region is unrented while player is offline
|
||||
* @return The number of milliseconds until the region is unrented while player is offline
|
||||
*/
|
||||
public long getInactiveTimeUntilSell() {
|
||||
return getLongSetting("buy.inactiveTimeUntilSell");
|
||||
return plugin.getDurationFromMinutesOrStringInput(getStringSetting("buy.inactiveTimeUntilSell"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -242,7 +242,7 @@ public class BuyRegion extends GeneralRegion {
|
|||
* @return String indicating the inactive time until unrent
|
||||
*/
|
||||
public String getFormattedInactiveTimeUntilSell() {
|
||||
return this.millisToHumanFormat(getInactiveTimeUntilSell()*60*1000);
|
||||
return this.millisToHumanFormat(getInactiveTimeUntilSell());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -446,7 +446,7 @@ public class BuyRegion extends GeneralRegion {
|
|||
return false;
|
||||
}
|
||||
//AreaShop.debug("currentTime=" + Calendar.getInstance().getTimeInMillis() + ", getLastPlayed()=" + player.getLastPlayed() + ", timeInactive=" + (Calendar.getInstance().getTimeInMillis()-player.getLastPlayed()) + ", inactiveSetting*60*1000=" + inactiveSetting * 60 * 1000);
|
||||
if(Calendar.getInstance().getTimeInMillis() > (player.getLastPlayed() + inactiveSetting * 60 * 1000)) {
|
||||
if(Calendar.getInstance().getTimeInMillis() > (player.getLastPlayed() + inactiveSetting)) {
|
||||
plugin.getLogger().info("Region " + getName() + " sold because of inactivity for player " + getPlayerName());
|
||||
AreaShop.debug("currentTime=" + Calendar.getInstance().getTimeInMillis() + ", getLastPlayed()=" + player.getLastPlayed() + ", timeInactive=" + (Calendar.getInstance().getTimeInMillis()-player.getLastPlayed()) + ", inactiveSetting*60*1000=" + inactiveSetting * 60 * 1000);
|
||||
this.sell(true);
|
||||
|
|
|
@ -157,7 +157,7 @@ public class RentRegion extends GeneralRegion {
|
|||
}
|
||||
result.put(AreaShop.tagMaxExtends, this.getMaxExtends());
|
||||
result.put(AreaShop.tagExtendsLeft, getMaxExtends() - getTimesExtended());
|
||||
result.put(AreaShop.tagMaxRentTime, this.millisToHumanFormat(getMaxRentTime()*60*1000));
|
||||
result.put(AreaShop.tagMaxRentTime, this.millisToHumanFormat(getMaxRentTime()));
|
||||
result.put(AreaShop.tagMaxInactiveTime, this.getFormattedInactiveTimeUntilUnrent());
|
||||
return result;
|
||||
}
|
||||
|
@ -259,10 +259,10 @@ public class RentRegion extends GeneralRegion {
|
|||
|
||||
/**
|
||||
* Minutes until automatic unrent when player is offline
|
||||
* @return The number of minutes until the region is unrented while player is offline
|
||||
* @return The number of milliseconds until the region is unrented while player is offline
|
||||
*/
|
||||
public long getInactiveTimeUntilUnrent() {
|
||||
return plugin.getDurationFromMinutesOrString("rent.inactiveTimeUntilUnrent");
|
||||
return plugin.getDurationFromMinutesOrStringInput(getStringSetting("rent.inactiveTimeUntilUnrent"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -270,7 +270,7 @@ public class RentRegion extends GeneralRegion {
|
|||
* @return String indicating the inactive time until unrent
|
||||
*/
|
||||
public String getFormattedInactiveTimeUntilUnrent() {
|
||||
return this.millisToHumanFormat(getInactiveTimeUntilUnrent()*60*1000);
|
||||
return this.millisToHumanFormat(getInactiveTimeUntilUnrent());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -327,11 +327,11 @@ public class RentRegion extends GeneralRegion {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the maximum time the player can rent the region in advance (minutes)
|
||||
* @return The maximum rent time in minutes
|
||||
* Get the maximum time the player can rent the region in advance (milliseconds)
|
||||
* @return The maximum rent time in milliseconds
|
||||
*/
|
||||
public long getMaxRentTime() {
|
||||
return plugin.getDurationFromMinutesOrString("rent.maxRentTime")/1000;
|
||||
return plugin.getDurationFromMinutesOrStringInput(getStringSetting("rent.maxRentTime"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -458,11 +458,11 @@ public class RentRegion extends GeneralRegion {
|
|||
if(isRented()) {
|
||||
timeRented = getRentedUntil() - timeNow;
|
||||
}
|
||||
if((timeRented + getDuration()) > (maxRentTime*60*1000)
|
||||
if((timeRented + getDuration()) > (maxRentTime)
|
||||
&& !player.hasPermission("areashop.renttimebypass")
|
||||
&& maxRentTime != -1) {
|
||||
int timeRentedMinutes = (int)(timeRented/1000.0/60.0 +1);
|
||||
plugin.message(player, "rent-maxRentTime", maxRentTime, timeRentedMinutes);
|
||||
plugin.message(player, "rent-maxRentTime", this.millisToHumanFormat(maxRentTime), this.millisToHumanFormat(timeRentedMinutes));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -602,7 +602,7 @@ public class RentRegion extends GeneralRegion {
|
|||
return false;
|
||||
}
|
||||
//AreaShop.debug("currentTime=" + Calendar.getInstance().getTimeInMillis() + ", getLastPlayed()=" + player.getLastPlayed() + ", timeInactive=" + (Calendar.getInstance().getTimeInMillis()-player.getLastPlayed()) + ", inactiveSetting*60*1000=" + inactiveSetting * 60 * 1000);
|
||||
if(Calendar.getInstance().getTimeInMillis() > (player.getLastPlayed() + inactiveSetting * 60 * 1000)) {
|
||||
if(Calendar.getInstance().getTimeInMillis() > (player.getLastPlayed() + inactiveSetting)) {
|
||||
plugin.getLogger().info("Region " + getName() + " unrented because of inactivity for player " + getPlayerName());
|
||||
AreaShop.debug("currentTime=" + Calendar.getInstance().getTimeInMillis() + ", getLastPlayed()=" + player.getLastPlayed() + ", timeInactive=" + (Calendar.getInstance().getTimeInMillis()-player.getLastPlayed()) + ", inactiveSetting*60*1000=" + inactiveSetting * 60 * 1000);
|
||||
this.unRent(true);
|
||||
|
|
Loading…
Reference in New Issue
Block a user