Fix a bug with inactive player unrent/sell settings

If the 'inactiveTimeUntilUnrent' or 'inactiveTimeUntilSell' settings
would be set to a value above 35000 it would cause an integer overflow,
resulting in a 50% chance that all regions will be unrentend/sold (and
if that does not happen it will still sell/unrent them too early). This
is caused by an integer overflow, switching to long fixed this problem.
This commit is contained in:
Thijs Wiefferink 2014-12-18 16:21:07 +01:00
parent 40338b66df
commit 00d3256716
2 changed files with 6 additions and 6 deletions

View File

@ -218,7 +218,7 @@ public class BuyRegion extends GeneralRegion {
* @return The number of minutes until the region is unrented while player is offline
*/
public long getInactiveTimeUntilSell() {
return getIntegerSetting("buy.inactiveTimeUntilSell");
return getLongSetting("buy.inactiveTimeUntilSell");
}
/**
@ -402,11 +402,11 @@ public class BuyRegion extends GeneralRegion {
return false;
}
OfflinePlayer player = Bukkit.getOfflinePlayer(getBuyer());
//AreaShop.debug("inactive checking for " + getName() + ", player=" + player.getName() + ", currenttime=" + Calendar.getInstance().getTimeInMillis() + ", lastPlayed=" + player.getLastPlayed() + ", diff=" + (Calendar.getInstance().getTimeInMillis() - player.getLastPlayed()));
int inactiveSetting = getIntegerSetting("buy.inactiveTimeUntilSell");
long inactiveSetting = getInactiveTimeUntilSell();
if(inactiveSetting <= 0 || player.isOp()) {
return false;
}
AreaShop.debug("inactivetimemillis: " + inactiveSetting * 60 * 1000);
if(Calendar.getInstance().getTimeInMillis() > (player.getLastPlayed() + inactiveSetting * 60 * 1000)) {
plugin.getLogger().info("Region " + getName() + " sold because of inactivity for player " + getPlayerName());
this.sell(true);

View File

@ -293,7 +293,7 @@ public class RentRegion extends GeneralRegion {
* @return The number of minutes until the region is unrented while player is offline
*/
public long getInactiveTimeUntilUnrent() {
return getIntegerSetting("rent.inactiveTimeUntilUnrent");
return getLongSetting("rent.inactiveTimeUntilUnrent");
}
/**
@ -603,11 +603,11 @@ public class RentRegion extends GeneralRegion {
return false;
}
OfflinePlayer player = Bukkit.getOfflinePlayer(getRenter());
//AreaShop.debug("inactive checking for " + getName() + ", player=" + player.getName() + ", currenttime=" + Calendar.getInstance().getTimeInMillis() + ", lastPlayed=" + player.getLastPlayed() + ", diff=" + (Calendar.getInstance().getTimeInMillis() - player.getLastPlayed()));
int inactiveSetting = getIntegerSetting("rent.inactiveTimeUntilUnrent");
long inactiveSetting = getInactiveTimeUntilUnrent();
if(inactiveSetting <= 0 || player.isOp()) {
return false;
}
AreaShop.debug("inactivetimemillis: " + inactiveSetting * 60 * 1000);
if(Calendar.getInstance().getTimeInMillis() > (player.getLastPlayed() + inactiveSetting * 60 * 1000)) {
plugin.getLogger().info("Region " + getName() + " unrented because of inactivity for player " + getPlayerName());
this.unRent(true);