Changes the '/as info' command for rent regions to show more info

Some lines will not show up when based on config options (extending, in
advance renting, restoring), some don't show up if empty (friends,
signs) and some don't show up based on permissions (groups, teleport
location, restoring). Also adds a couple of tags to be used in language
files and the config.
This commit is contained in:
Thijs Wiefferink 2014-12-03 00:38:55 +01:00
parent 46abc8f83d
commit 5568ee240b
9 changed files with 331 additions and 101 deletions

View File

@ -97,7 +97,13 @@ limitGroups:
## %timeleft% The time left on the rent (uses the unit of time that fits best, minutes used from 121 seconds till 120 minutes)
## %clicker% The name of the player that clicked the sign (only to be used in the signProfiles section)
## %resellprice% The price of a region when it is in resell mode
## %moneyback% The amount of money the player will get back when unrenting/selling the region (formatted with currency characters)
## %moneybackpercent% The percentage of the price the player will get back when unrenting (only the number between 0-100)
## %maxextends% The maximum number of extends a player can do on the region
## %extendsleft% The number of extends that are left (maxextends - timesextended)
## %maxrenttime% The maximum time you can rent a region in advance (human readble)
## %inactivetime% The maximum time a player may be inactive before unrent/sell (human readble)
## Below are profiles for the signs, you can assign profiles to regions
## by setting 'general.signProfile' in default.yml, groups or individual regions
signProfiles:
@ -219,7 +225,11 @@ schematicProfiles:
restore: ''
## Flag profiles to specify what flags should be set on the WorldGuard regions
## All normal region flags as present in WorldGuard can be used, and also members, owners, priority and parent
## Use '' for members or owners to clear it. Use '' for a flag to reset it.
## For the members and owners flags you can add groups by using 'g:<groupname>', so for example: '%player%, %friends%, g:vip'
## For flags like 'entry' and 'exit' you can add group setting by using 'g:<scope>' behind it, <scope> is one of the following:
## members, non_members, owners, non_owners, all. Example, only owners can enter the region:
## entry: 'deny g:non_owners'
## Use '' for a flag to reset it.
flagProfiles:
default:
forrent:

View File

@ -142,7 +142,39 @@ info-playerRents: "Regions rented by %0%: &7%1%"
info-playerNoRents: "%0% has not rented a region"
info-playerBuys: "Regions bought by %0%: &7%1%"
info-playerNoBuys: "%0% has not bought a region"
info-regionHelp: "/as info region [name], the region you stand in will be used if not specified"
info-regionHeader: "&2Information about %region%:"
info-regionRented: "&2&l►&r Rented by %player% until: &7%until%"
info-regionExtending: "&2&l►&r Price to extend: &7%price% per %duration%"
info-regionCanBeRented: "&2&l►&r Price to rent: &7%price% per %duration%"
info-regionFriends: "&2&l►&r Added friends: &7%friends%"
info-regionMoneyBackBuy: "&2&l►&r Selling payback: &7%moneyback% (%moneybackpercent%% of the price)"
info-regionMoneyBackRent: "&2&l►&r Unrenting payback &7%moneyback% (%moneybackpercent%% of the remaining time)"
info-regionMaxExtends: "&2&l►&r Maximum times extending: &7%maxextends% time(s)"
info-regionNoExtending: "&2&l►&r Rent cannot be extended"
info-regionExtendsLeft: "&2&l►&r Extending left: &7%extendsleft% time(s) out of %maxextends%"
info-regionMaxRentTime: "&2&l►&r In advance renting: &7%maxrenttime% at maximum"
info-regionNoTeleport: "&2&l►&r Teleport location not set%0%"
info-regionTeleportHint: " &7(use '/as settp' for a better spot)"
info-regionTeleportAt: "&2&l►&r Teleport set at: &7(%0%, %1%, %2%, %3%), pitch: %4%, yaw: %5%"
info-regionSigns: "&2&l►&r Connected signs: &7%0%"
info-regionSignLocation: "&7(%0%, %1%, %2%, %3%)&r"
info-regionGroups: "&2&l►&r Assigned groups: &7%0%"
info-regionInactiveUnrent: "&2&l►&r Auto unrent after: &7%inactivetime% of inactivity by the player"
info-regionRestrictedRegionRent: "&2&l►&r To rent it you need to be inside the region"
info-regionRestrictedWorldRent: "&2&l►&r To rent it you need to be inside world '%world%'"
info-regionRestoringRent: "&2&l►&r Restoring is enabled &7(region will reset at unrent)%0%"
info-regionRestoringProfile: " (profile: %0%)"
info-regionFooter: ""
info-regionNoRenting: "%0% is not registered for renting"
info-regionRenting: "&6Renting details for %0%:"
info-regionRentedBy: "Rented by: &7%0% until %1%"
@ -152,7 +184,7 @@ info-regionNoBuying: "%0% is not registered for buying"
info-regionNotBought: "Currently not sold"
info-regionBoughtBy: "Bought by: &7%0%"
info-regionSign: "Sign location(s): %0%"
info-regionSignLocation: "&7(%0%, %1%, %2%, %3%)&r"
info-regionNoSign: "There is no sign registered for this region"
info-regionPriceDuration: "Price: &7%0% for each %1%"
info-regionPrice: "Price: &7%0%"

View File

@ -74,6 +74,12 @@ public final class AreaShop extends JavaPlugin {
public static final String tagResellPrice = "%resellprice%";
public static final String tagFriends = "%friends%";
public static final String tagFriendsUUID = "%friendsuuid%";
public static final String tagMoneyBackPercentage = "%moneybackpercent%";
public static final String tagMoneyBackAmount = "%moneyback%";
public static final String tagMaxExtends = "%maxextends%";
public static final String tagExtendsLeft = "%extendsleft%";
public static final String tagMaxRentTime = "%maxrenttime%";
public static final String tagMaxInactiveTime = "%inactivetime%";
public static AreaShop getInstance() {
return AreaShop.instance;
@ -350,13 +356,7 @@ public final class AreaShop extends JavaPlugin {
public String fixColors(String input) {
String result = null;
if(input != null) {
result = input.replaceAll("(&([a-f0-9]))", "\u00A7$2");
result = result.replaceAll("&k", ChatColor.MAGIC.toString());
result = result.replaceAll("&l", ChatColor.BOLD.toString());
result = result.replaceAll("&m", ChatColor.STRIKETHROUGH.toString());
result = result.replaceAll("&n", ChatColor.UNDERLINE.toString());
result = result.replaceAll("&o", ChatColor.ITALIC.toString());
result = result.replaceAll("&r", ChatColor.RESET.toString());
result = ChatColor.translateAlternateColorCodes('&', input);
result = result.replaceAll("", "\u20AC");
}
return result;

View File

@ -76,8 +76,6 @@ public class Utils {
return result;
}
}

View File

@ -1,6 +1,5 @@
package nl.evolutioncoding.areashop.commands;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -237,39 +236,73 @@ public class InfoCommand extends CommandAreaShop {
if(rent == null && buy == null) {
plugin.message(sender, "info-regionNotExisting", args[2]);
return;
}
}
if(rent != null) {
plugin.message(sender, "info-regionRenting", rent.getName());
plugin.message(sender, "info-regionHeader", rent);
if(rent.isRented()) {
plugin.messageNoPrefix(sender, "info-regionRented", rent);
plugin.messageNoPrefix(sender, "info-regionExtending", rent);
plugin.messageNoPrefix(sender, "info-regionMoneyBackRent", rent);
if(!rent.getFriendNames().isEmpty()) {
plugin.messageNoPrefix(sender, "info-regionFriends", rent);
}
} else {
plugin.messageNoPrefix(sender, "info-regionCanBeRented", rent);
}
if(rent.getMaxExtends() != -1) {
if(rent.getMaxExtends() == 0) {
plugin.messageNoPrefix(sender, "info-regionNoExtending", rent);
} else if(rent.isRented()) {
plugin.messageNoPrefix(sender, "info-regionExtendsLeft", rent);
} else {
plugin.messageNoPrefix(sender, "info-regionMaxExtends", rent);
}
}
if(rent.getMaxRentTime() != -1) {
plugin.messageNoPrefix(sender, "info-regionMaxRentTime", rent);
}
if(rent.getInactiveTimeUntilUnrent() != -1) {
plugin.messageNoPrefix(sender, "info-regionInactiveUnrent", rent);
}
if(sender.hasPermission("areashop.teleport") || sender.hasPermission("areashop.teleportall")) {
Location teleport = rent.getTeleportLocation();
if(teleport == null) {
if(rent.isRented()) {
plugin.messageNoPrefix(sender, "info-regionNoTeleport", rent, plugin.getLanguageManager().getLang("info-regionTeleportHint", rent));
} else {
plugin.messageNoPrefix(sender, "info-regionNoTeleport", rent, "");
}
} else {
plugin.messageNoPrefix(sender, "info-regionTeleportAt", rent, teleport.getWorld().getName(), teleport.getBlockX(), teleport.getBlockY(), teleport.getBlockZ(), (int)teleport.getPitch(), (int)teleport.getYaw());
}
}
List<String> signLocations = new ArrayList<String>();
for(Location location : rent.getSignLocations()) {
signLocations.add(plugin.getLanguageManager().getLang("info-regionSignLocation", location.getWorld().getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ()));
}
if(signLocations.isEmpty()) {
plugin.message(sender, "info-regionNoSign");
} else {
plugin.message(sender, "info-regionSign", Utils.createCommaSeparatedList(signLocations));
if(!signLocations.isEmpty()) {
plugin.messageNoPrefix(sender, "info-regionSigns", Utils.createCommaSeparatedList(signLocations));
}
if(sender.hasPermission("areashop.groupinfo") && !rent.getGroupNames().isEmpty()) {
plugin.messageNoPrefix(sender, "info-regionGroups", Utils.createCommaSeparatedList(rent.getGroupNames()));
}
plugin.message(sender, "info-regionPriceDuration", rent.getFormattedPrice(), rent.getDurationString());
if(!rent.isRented()) {
plugin.message(sender, "info-regionNotRented");
} else {
SimpleDateFormat dateFull = new SimpleDateFormat(plugin.getConfig().getString("timeFormatChat"));
plugin.message(sender, "info-regionRentedBy", rent.getPlayerName(), dateFull.format(rent.getRentedUntil()));
}
if(sender.hasPermission("areashop.rentrestore")) {
plugin.message(sender, "info-regionRestore", rent.isRestoreEnabled());
plugin.message(sender, "info-regionRestoreProfile", rent.getRestoreProfile());
}
if(sender.hasPermission("areashop.teleport")) {
if(rent.getTeleportLocation() == null) {
plugin.message(sender, "info-regionNoTP");
} else {
plugin.message(sender, "info-regionTPLocation", rent.getTeleportLocation().getWorld().getName(), rent.getTeleportLocation().getBlockX(), rent.getTeleportLocation().getBlockY(), rent.getTeleportLocation().getBlockZ(), rent.getTeleportLocation().getPitch(), rent.getTeleportLocation().getYaw());
if(rent.restrictedToRegion()) {
plugin.messageNoPrefix(sender, "info-regionRestrictedRegionRent", rent);
} else if(rent.restrictedToWorld()) {
plugin.messageNoPrefix(sender, "info-regionRestrictedWorldRent", rent);
}
}
}
if(buy != null) {
if(rent.isRestoreEnabled()) {
if(sender.hasPermission("areashop.setrestore")) {
plugin.messageNoPrefix(sender, "info-regionRestoringRent", rent, plugin.getLanguageManager().getLang("info-regionRestoringProfile", rent.getRestoreProfile()));
} else {
plugin.messageNoPrefix(sender, "info-regionRestoringRent", rent, "");
}
}
plugin.messageNoPrefix(sender, "info-regionFooter", rent);
} else if(buy != null) {
plugin.message(sender, "info-regionBuying", buy.getName());
List<String> signLocations = new ArrayList<String>();
for(Location location : buy.getSignLocations()) {

View File

@ -10,7 +10,6 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
// TODO ALL
public class StopresellCommand extends CommandAreaShop {
public StopresellCommand(AreaShop plugin) {

View File

@ -170,6 +170,30 @@ public class BuyRegion extends GeneralRegion {
config.set("buy.resellPrice", null);
}
/**
* Get the moneyBack percentage
* @return The % of money the player will get back when selling
*/
public double getMoneyBackPercentage() {
return getDoubleSetting("buy.moneyBack");
}
/**
* Get the amount of money that should be paid to the player when selling the region
* @return The amount of money the player should get back
*/
public double getMoneyBackAmount() {
return getPrice() * (getMoneyBackPercentage() / 100.0);
}
/**
* Get the formatted string of the amount of the moneyBack amount
* @return String with currency symbols and proper fractional part
*/
public String getFormattedMoneyBackAmount() {
return plugin.formatCurrency(getMoneyBackAmount());
}
@Override
public HashMap<String, Object> getSpecificReplacements() {
// Fill the replacements map with things specific to a BuyRegion
@ -178,11 +202,32 @@ public class BuyRegion extends GeneralRegion {
result.put(AreaShop.tagPlayerName, getPlayerName());
result.put(AreaShop.tagPlayerUUID, getBuyer());
result.put(AreaShop.tagResellPrice, getFormattedResellPrice());
// TODO: Add more?
double moneyBackPercent = getMoneyBackPercentage();
if((moneyBackPercent%1.0) == 0.0) {
result.put(AreaShop.tagMoneyBackPercentage, (int)moneyBackPercent);
} else {
result.put(AreaShop.tagMoneyBackPercentage, moneyBackPercent);
}
result.put(AreaShop.tagMaxInactiveTime, this.getFormattedInactiveTimeUntilSell());
return result;
}
/**
* Minutes until automatic unrent when player is offline
* @return The number of minutes until the region is unrented while player is offline
*/
public long getInactiveTimeUntilSell() {
return getIntegerSetting("buy.inactiveTimeUntilSell");
}
/**
* Get a human readable string indicating how long the player can be offline until automatic unrent
* @return String indicating the inactive time until unrent
*/
public String getFormattedInactiveTimeUntilSell() {
return this.millisToHumanFormat(getInactiveTimeUntilSell()*60*1000);
}
/**
* Buy a region
* @param player The player that wants to buy the region
@ -194,16 +239,15 @@ public class BuyRegion extends GeneralRegion {
if(!isSold() || (isInResellingMode() && !isBuyer(player))) {
boolean isResell = isInResellingMode();
// Check if the players needs to be in the world or region for buying
if(!player.getWorld().getName().equals(getWorldName()) && getBooleanSetting("general.restrictedToWorld")) {
plugin.message(player, "buy-restrictedToWorld", getWorldName(), player.getWorld().getName());
return false;
}
if((!player.getWorld().getName().equals(getWorldName())
|| !getRegion().contains(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ())
) && getBooleanSetting("general.restrictedToRegion")) {
if(restrictedToRegion() && (!player.getWorld().getName().equals(getWorldName())
|| !getRegion().contains(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()))) {
plugin.message(player, "buy-restrictedToRegion", getName());
return false;
}
}
if(restrictedToWorld() && !player.getWorld().getName().equals(getWorldName())) {
plugin.message(player, "buy-restrictedToWorld", getWorldName(), player.getWorld().getName());
return false;
}
// Check region limits
LimitResult limitResult = this.limitsAllowBuying(player);
AreaShop.debug("LimitResult: " + limitResult.toString());
@ -314,8 +358,7 @@ public class BuyRegion extends GeneralRegion {
disableReselling();
/* Give part of the buying price back */
double percentage = getDoubleSetting("buy.moneyBack") / 100.0;
double moneyBack = getPrice() * percentage;
double moneyBack = getMoneyBackAmount();
if(moneyBack > 0 && giveMoneyBack) {
/* Give back the money */
OfflinePlayer player = Bukkit.getOfflinePlayer(getBuyer());

View File

@ -347,6 +347,32 @@ public abstract class GeneralRegion {
return getRegion().getMaximumPoint().getBlockY() - getRegion().getMinimumPoint().getBlockY();
}
/**
* Get the groups that this region is added to
* @return A Set with all groups of this region
*/
public Set<RegionGroup> getGroups() {
Set<RegionGroup> result = new HashSet<RegionGroup>();
for(RegionGroup group : plugin.getFileManager().getGroups()) {
if(group.isMember(this)) {
result.add(group);
}
}
return result;
}
/**
* Get a list of names from groups this region is in
* @return A list of groups this region is part of
*/
public List<String> getGroupNames() {
List<String> result = new ArrayList<String>();
for(RegionGroup group : getGroups()) {
result.add(group.getName());
}
return result;
}
/**
* Get all the replacements for this region
* @return Map with the keys that need to be replaced with the value of the object
@ -429,6 +455,22 @@ public abstract class GeneralRegion {
return getType() == RegionType.BUY;
}
/**
* Check if for renting this region you should be inside of it
* @return true if you need to be inside, otherwise false
*/
public boolean restrictedToRegion() {
return getBooleanSetting("general.restrictedToRegion");
}
/**
* Check if for renting you need to be in the correct world
* @return true if you need to be in the same world as the region, otherwise false
*/
public boolean restrictedToWorld() {
return getBooleanSetting("general.restrictedToWorld") || restrictedToRegion();
}
/**
* Add a friend to the region
* @param player The UUID of the player to add
@ -838,6 +880,47 @@ public abstract class GeneralRegion {
return result;
}
/**
* Convert milliseconds to a human readable format
* @param milliseconds The amount of milliseconds to convert
* @return A formatted string based on the language file
*/
public String millisToHumanFormat(long milliseconds) {
long timeLeft = milliseconds + 500;
// To seconds
timeLeft = timeLeft/1000;
if(timeLeft <= 0) {
return plugin.getLanguageManager().getLang("timeleft-ended");
} else if(timeLeft == 1) {
return plugin.getLanguageManager().getLang("timeleft-second", timeLeft);
} else if(timeLeft <= 120) {
return plugin.getLanguageManager().getLang("timeleft-seconds", timeLeft);
}
// To minutes
timeLeft = timeLeft/60;
if(timeLeft <= 120) {
return plugin.getLanguageManager().getLang("timeleft-minutes", timeLeft);
}
// To hours
timeLeft = timeLeft/60;
if(timeLeft <= 48) {
return plugin.getLanguageManager().getLang("timeleft-hours", timeLeft);
}
// To days
timeLeft = timeLeft/24;
if(timeLeft <= 60) {
return plugin.getLanguageManager().getLang("timeleft-days", timeLeft);
}
// To months
timeLeft = timeLeft/30;
if(timeLeft <= 24) {
return plugin.getLanguageManager().getLang("timeleft-months", timeLeft);
}
// To years
timeLeft = timeLeft/12;
return plugin.getLanguageManager().getLang("timeleft-years", timeLeft);
}
/**
* Reset all flags of the region
*/
@ -850,8 +933,15 @@ public abstract class GeneralRegion {
}
}
protected static <V> void setFlag(ProtectedRegion region, Flag<V> flag, CommandSender sender, String value) throws InvalidFlagFormat {
region.setFlag(flag, flag.parseInput(WorldGuardPlugin.inst(), sender, value));
/**
* Set a WorldGuard regin flag
* @param region The WorldGuard region to set
* @param flag The flag to set
* @param value The value to set the flag to
* @throws InvalidFlagFormat When the value of the flag is wrong
*/
protected static <V> void setFlag(ProtectedRegion region, Flag<V> flag, String value) throws InvalidFlagFormat {
region.setFlag(flag, flag.parseInput(WorldGuardPlugin.inst(), null, value));
}
@ -985,7 +1075,7 @@ public abstract class GeneralRegion {
}
if (flagSetting != null) {
try {
setFlag(region, foundFlag, null, flagSetting);
setFlag(region, foundFlag, flagSetting);
AreaShop.debug(" Flag " + flagName + " set: " + flagSetting);
} catch (InvalidFlagFormat e) {
plugin.getLogger().info("Found wrong value for flag " + flagName);

View File

@ -147,6 +147,17 @@ public class RentRegion extends GeneralRegion {
dateString = date.format(new Date(getRentedUntil()));
result.put(AreaShop.tagRentedUntilShort, dateString);
result.put(AreaShop.tagTimeLeft, getTimeLeftString());
result.put(AreaShop.tagMoneyBackAmount, getFormattedMoneyBackAmount());
double moneyBackPercent = getMoneyBackPercentage();
if((moneyBackPercent%1.0) == 0.0) {
result.put(AreaShop.tagMoneyBackPercentage, (int)moneyBackPercent);
} else {
result.put(AreaShop.tagMoneyBackPercentage, moneyBackPercent);
}
result.put(AreaShop.tagMaxExtends, this.getMaxExtends());
result.put(AreaShop.tagExtendsLeft, getMaxExtends() - getTimesExtended());
result.put(AreaShop.tagMaxRentTime, this.millisToHumanFormat(getMaxRentTime()*60*1000));
result.put(AreaShop.tagMaxInactiveTime, this.getFormattedInactiveTimeUntilUnrent());
return result;
}
@ -274,39 +285,23 @@ public class RentRegion extends GeneralRegion {
* @return Time left on the rent, for example '29 days', '3 months', '1 second'
*/
public String getTimeLeftString() {
long timeLeft = getTimeLeft() + 500;
// To seconds
timeLeft = timeLeft/1000;
if(timeLeft <= 0) {
return plugin.getLanguageManager().getLang("timeleft-ended");
} else if(timeLeft == 1) {
return plugin.getLanguageManager().getLang("timeleft-second", timeLeft);
} else if(timeLeft <= 120) {
return plugin.getLanguageManager().getLang("timeleft-seconds", timeLeft);
}
// To minutes
timeLeft = timeLeft/60;
if(timeLeft <= 120) {
return plugin.getLanguageManager().getLang("timeleft-minutes", timeLeft);
}
// To hours
timeLeft = timeLeft/60;
if(timeLeft <= 48) {
return plugin.getLanguageManager().getLang("timeleft-hours", timeLeft);
}
// To days
timeLeft = timeLeft/24;
if(timeLeft <= 60) {
return plugin.getLanguageManager().getLang("timeleft-days", timeLeft);
}
// To months
timeLeft = timeLeft/30;
if(timeLeft <= 24) {
return plugin.getLanguageManager().getLang("timeleft-months", timeLeft);
}
// To years
timeLeft = timeLeft/12;
return plugin.getLanguageManager().getLang("timeleft-years", timeLeft);
return millisToHumanFormat(getTimeLeft());
}
/**
* Minutes until automatic unrent when player is offline
* @return The number of minutes until the region is unrented while player is offline
*/
public long getInactiveTimeUntilUnrent() {
return getIntegerSetting("rent.inactiveTimeUntilUnrent");
}
/**
* Get a human readable string indicating how long the player can be offline until automatic unrent
* @return String indicating the inactive time until unrent
*/
public String getFormattedInactiveTimeUntilUnrent() {
return this.millisToHumanFormat(getInactiveTimeUntilUnrent()*60*1000);
}
/**
@ -325,6 +320,44 @@ public class RentRegion extends GeneralRegion {
setSetting("rent.duration", duration);
}
/**
* Get the moneyBack percentage
* @return The % of money the player will get back when unrenting
*/
public double getMoneyBackPercentage() {
return getDoubleSetting("rent.moneyBack");
}
/**
* Get the amount of money that should be paid to the player when unrenting the region
* @return The amount of money the player should get back
*/
public double getMoneyBackAmount() {
Long currentTime = Calendar.getInstance().getTimeInMillis();
Double timeLeft = (double) ((getRentedUntil() - currentTime));
double percentage = (getMoneyBackPercentage()) / 100.0;
Double timePeriod = (double) (getDuration());
double periods = timeLeft / timePeriod;
double moneyBack = periods * getPrice() * percentage;
return moneyBack;
}
/**
* Get the formatted string of the amount of the moneyBack amount
* @return String with currency symbols and proper fractional part
*/
public String getFormattedMoneyBackAmount() {
return plugin.formatCurrency(getMoneyBackAmount());
}
/**
* Get the maximum time the player can rent the region in advance (minutes)
* @return The maximum rent time in minutes
*/
public long getMaxRentTime() {
return this.getLongSetting("rent.maxRentTime");
}
/**
* Check if the rent should expire
* @return true if the rent has expired and has been unrented, false otherwise
@ -395,14 +428,13 @@ public class RentRegion extends GeneralRegion {
// Check if the region is available for renting or if the player wants to extend the rent
if(!isRented() || extend) {
// Check if the players needs to be in the world or region for buying
if(!player.getWorld().getName().equals(getWorldName()) && getBooleanSetting("general.restrictedToWorld")) {
plugin.message(player, "rent-restrictedToWorld", getWorldName(), player.getWorld().getName());
if(restrictedToRegion() && (!player.getWorld().getName().equals(getWorldName())
|| !getRegion().contains(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()))) {
plugin.message(player, "rent-restrictedToRegion", getName());
return false;
}
if((!player.getWorld().getName().equals(getWorldName())
|| !getRegion().contains(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ())
) && getBooleanSetting("general.restrictedToRegion")) {
plugin.message(player, "rent-restrictedToRegion", getName());
if(restrictedToWorld() && !player.getWorld().getName().equals(getWorldName())) {
plugin.message(player, "rent-restrictedToWorld", getWorldName(), player.getWorld().getName());
return false;
}
// Check region limits if this is not extending
@ -434,7 +466,7 @@ public class RentRegion extends GeneralRegion {
// Check if there is enough time left before hitting maxRentTime
long timeNow = Calendar.getInstance().getTimeInMillis();
long timeRented = 0;
long maxRentTime = this.getLongSetting("rent.maxRentTime");
long maxRentTime = getMaxRentTime();
if(isRented()) {
timeRented = getRentedUntil() - timeNow;
}
@ -527,14 +559,7 @@ public class RentRegion extends GeneralRegion {
public void unRent(boolean giveMoneyBack) {
// Run commands
this.runEventCommands(RegionEvent.UNRENTED, true);
/* Get the time until the region will be rented */
Long currentTime = Calendar.getInstance().getTimeInMillis();
Double timeLeft = (double) ((getRentedUntil() - currentTime));
double percentage = (getDoubleSetting("rent.moneyBack")) / 100.0;
Double timePeriod = (double) (getDuration());
double periods = timeLeft / timePeriod;
double moneyBack = periods * getPrice() * percentage;
double moneyBack = getMoneyBackAmount();
if(moneyBack > 0 && giveMoneyBack) {
/* Give back the money */
OfflinePlayer player = Bukkit.getOfflinePlayer(getRenter());