mirror of
https://github.com/NLthijs48/AreaShop.git
synced 2024-11-26 20:26:33 +01:00
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:
parent
46abc8f83d
commit
5568ee240b
14
config.yml
14
config.yml
@ -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)
|
## %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)
|
## %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
|
## %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
|
## Below are profiles for the signs, you can assign profiles to regions
|
||||||
## by setting 'general.signProfile' in default.yml, groups or individual regions
|
## by setting 'general.signProfile' in default.yml, groups or individual regions
|
||||||
signProfiles:
|
signProfiles:
|
||||||
@ -219,7 +225,11 @@ schematicProfiles:
|
|||||||
restore: ''
|
restore: ''
|
||||||
## Flag profiles to specify what flags should be set on the WorldGuard regions
|
## 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
|
## 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:
|
flagProfiles:
|
||||||
default:
|
default:
|
||||||
forrent:
|
forrent:
|
||||||
|
34
lang/EN.yml
34
lang/EN.yml
@ -142,7 +142,39 @@ info-playerRents: "Regions rented by %0%: &7%1%"
|
|||||||
info-playerNoRents: "%0% has not rented a region"
|
info-playerNoRents: "%0% has not rented a region"
|
||||||
info-playerBuys: "Regions bought by %0%: &7%1%"
|
info-playerBuys: "Regions bought by %0%: &7%1%"
|
||||||
info-playerNoBuys: "%0% has not bought a region"
|
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-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-regionNoRenting: "%0% is not registered for renting"
|
||||||
info-regionRenting: "&6Renting details for %0%:"
|
info-regionRenting: "&6Renting details for %0%:"
|
||||||
info-regionRentedBy: "Rented by: &7%0% until %1%"
|
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-regionNotBought: "Currently not sold"
|
||||||
info-regionBoughtBy: "Bought by: &7%0%"
|
info-regionBoughtBy: "Bought by: &7%0%"
|
||||||
info-regionSign: "Sign location(s): %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-regionNoSign: "There is no sign registered for this region"
|
||||||
info-regionPriceDuration: "Price: &7%0% for each %1%"
|
info-regionPriceDuration: "Price: &7%0% for each %1%"
|
||||||
info-regionPrice: "Price: &7%0%"
|
info-regionPrice: "Price: &7%0%"
|
||||||
|
@ -74,6 +74,12 @@ public final class AreaShop extends JavaPlugin {
|
|||||||
public static final String tagResellPrice = "%resellprice%";
|
public static final String tagResellPrice = "%resellprice%";
|
||||||
public static final String tagFriends = "%friends%";
|
public static final String tagFriends = "%friends%";
|
||||||
public static final String tagFriendsUUID = "%friendsuuid%";
|
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() {
|
public static AreaShop getInstance() {
|
||||||
return AreaShop.instance;
|
return AreaShop.instance;
|
||||||
@ -350,13 +356,7 @@ public final class AreaShop extends JavaPlugin {
|
|||||||
public String fixColors(String input) {
|
public String fixColors(String input) {
|
||||||
String result = null;
|
String result = null;
|
||||||
if(input != null) {
|
if(input != null) {
|
||||||
result = input.replaceAll("(&([a-f0-9]))", "\u00A7$2");
|
result = ChatColor.translateAlternateColorCodes('&', input);
|
||||||
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 = result.replaceAll("€", "\u20AC");
|
result = result.replaceAll("€", "\u20AC");
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -76,8 +76,6 @@ public class Utils {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package nl.evolutioncoding.areashop.commands;
|
package nl.evolutioncoding.areashop.commands;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -237,39 +236,73 @@ public class InfoCommand extends CommandAreaShop {
|
|||||||
if(rent == null && buy == null) {
|
if(rent == null && buy == null) {
|
||||||
plugin.message(sender, "info-regionNotExisting", args[2]);
|
plugin.message(sender, "info-regionNotExisting", args[2]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(rent != null) {
|
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>();
|
List<String> signLocations = new ArrayList<String>();
|
||||||
for(Location location : rent.getSignLocations()) {
|
for(Location location : rent.getSignLocations()) {
|
||||||
signLocations.add(plugin.getLanguageManager().getLang("info-regionSignLocation", location.getWorld().getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ()));
|
signLocations.add(plugin.getLanguageManager().getLang("info-regionSignLocation", location.getWorld().getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ()));
|
||||||
}
|
}
|
||||||
if(signLocations.isEmpty()) {
|
if(!signLocations.isEmpty()) {
|
||||||
plugin.message(sender, "info-regionNoSign");
|
plugin.messageNoPrefix(sender, "info-regionSigns", Utils.createCommaSeparatedList(signLocations));
|
||||||
} else {
|
}
|
||||||
plugin.message(sender, "info-regionSign", 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()) {
|
if(!rent.isRented()) {
|
||||||
plugin.message(sender, "info-regionNotRented");
|
if(rent.restrictedToRegion()) {
|
||||||
} else {
|
plugin.messageNoPrefix(sender, "info-regionRestrictedRegionRent", rent);
|
||||||
SimpleDateFormat dateFull = new SimpleDateFormat(plugin.getConfig().getString("timeFormatChat"));
|
} else if(rent.restrictedToWorld()) {
|
||||||
plugin.message(sender, "info-regionRentedBy", rent.getPlayerName(), dateFull.format(rent.getRentedUntil()));
|
plugin.messageNoPrefix(sender, "info-regionRestrictedWorldRent", rent);
|
||||||
}
|
|
||||||
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.isRestoreEnabled()) {
|
||||||
|
if(sender.hasPermission("areashop.setrestore")) {
|
||||||
if(buy != null) {
|
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());
|
plugin.message(sender, "info-regionBuying", buy.getName());
|
||||||
List<String> signLocations = new ArrayList<String>();
|
List<String> signLocations = new ArrayList<String>();
|
||||||
for(Location location : buy.getSignLocations()) {
|
for(Location location : buy.getSignLocations()) {
|
||||||
|
@ -10,7 +10,6 @@ import org.bukkit.command.Command;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
// TODO ALL
|
|
||||||
public class StopresellCommand extends CommandAreaShop {
|
public class StopresellCommand extends CommandAreaShop {
|
||||||
|
|
||||||
public StopresellCommand(AreaShop plugin) {
|
public StopresellCommand(AreaShop plugin) {
|
||||||
|
@ -170,6 +170,30 @@ public class BuyRegion extends GeneralRegion {
|
|||||||
config.set("buy.resellPrice", null);
|
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
|
@Override
|
||||||
public HashMap<String, Object> getSpecificReplacements() {
|
public HashMap<String, Object> getSpecificReplacements() {
|
||||||
// Fill the replacements map with things specific to a BuyRegion
|
// 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.tagPlayerName, getPlayerName());
|
||||||
result.put(AreaShop.tagPlayerUUID, getBuyer());
|
result.put(AreaShop.tagPlayerUUID, getBuyer());
|
||||||
result.put(AreaShop.tagResellPrice, getFormattedResellPrice());
|
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;
|
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
|
* Buy a region
|
||||||
* @param player The player that wants to buy the 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))) {
|
if(!isSold() || (isInResellingMode() && !isBuyer(player))) {
|
||||||
boolean isResell = isInResellingMode();
|
boolean isResell = isInResellingMode();
|
||||||
// Check if the players needs to be in the world or region for buying
|
// Check if the players needs to be in the world or region for buying
|
||||||
if(!player.getWorld().getName().equals(getWorldName()) && getBooleanSetting("general.restrictedToWorld")) {
|
if(restrictedToRegion() && (!player.getWorld().getName().equals(getWorldName())
|
||||||
plugin.message(player, "buy-restrictedToWorld", getWorldName(), player.getWorld().getName());
|
|| !getRegion().contains(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()))) {
|
||||||
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, "buy-restrictedToRegion", getName());
|
plugin.message(player, "buy-restrictedToRegion", getName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if(restrictedToWorld() && !player.getWorld().getName().equals(getWorldName())) {
|
||||||
|
plugin.message(player, "buy-restrictedToWorld", getWorldName(), player.getWorld().getName());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// Check region limits
|
// Check region limits
|
||||||
LimitResult limitResult = this.limitsAllowBuying(player);
|
LimitResult limitResult = this.limitsAllowBuying(player);
|
||||||
AreaShop.debug("LimitResult: " + limitResult.toString());
|
AreaShop.debug("LimitResult: " + limitResult.toString());
|
||||||
@ -314,8 +358,7 @@ public class BuyRegion extends GeneralRegion {
|
|||||||
|
|
||||||
disableReselling();
|
disableReselling();
|
||||||
/* Give part of the buying price back */
|
/* Give part of the buying price back */
|
||||||
double percentage = getDoubleSetting("buy.moneyBack") / 100.0;
|
double moneyBack = getMoneyBackAmount();
|
||||||
double moneyBack = getPrice() * percentage;
|
|
||||||
if(moneyBack > 0 && giveMoneyBack) {
|
if(moneyBack > 0 && giveMoneyBack) {
|
||||||
/* Give back the money */
|
/* Give back the money */
|
||||||
OfflinePlayer player = Bukkit.getOfflinePlayer(getBuyer());
|
OfflinePlayer player = Bukkit.getOfflinePlayer(getBuyer());
|
||||||
|
@ -347,6 +347,32 @@ public abstract class GeneralRegion {
|
|||||||
return getRegion().getMaximumPoint().getBlockY() - getRegion().getMinimumPoint().getBlockY();
|
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
|
* Get all the replacements for this region
|
||||||
* @return Map with the keys that need to be replaced with the value of the object
|
* @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;
|
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
|
* Add a friend to the region
|
||||||
* @param player The UUID of the player to add
|
* @param player The UUID of the player to add
|
||||||
@ -838,6 +880,47 @@ public abstract class GeneralRegion {
|
|||||||
return result;
|
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
|
* 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) {
|
if (flagSetting != null) {
|
||||||
try {
|
try {
|
||||||
setFlag(region, foundFlag, null, flagSetting);
|
setFlag(region, foundFlag, flagSetting);
|
||||||
AreaShop.debug(" Flag " + flagName + " set: " + flagSetting);
|
AreaShop.debug(" Flag " + flagName + " set: " + flagSetting);
|
||||||
} catch (InvalidFlagFormat e) {
|
} catch (InvalidFlagFormat e) {
|
||||||
plugin.getLogger().info("Found wrong value for flag " + flagName);
|
plugin.getLogger().info("Found wrong value for flag " + flagName);
|
||||||
|
@ -147,6 +147,17 @@ public class RentRegion extends GeneralRegion {
|
|||||||
dateString = date.format(new Date(getRentedUntil()));
|
dateString = date.format(new Date(getRentedUntil()));
|
||||||
result.put(AreaShop.tagRentedUntilShort, dateString);
|
result.put(AreaShop.tagRentedUntilShort, dateString);
|
||||||
result.put(AreaShop.tagTimeLeft, getTimeLeftString());
|
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;
|
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'
|
* @return Time left on the rent, for example '29 days', '3 months', '1 second'
|
||||||
*/
|
*/
|
||||||
public String getTimeLeftString() {
|
public String getTimeLeftString() {
|
||||||
long timeLeft = getTimeLeft() + 500;
|
return millisToHumanFormat(getTimeLeft());
|
||||||
// To seconds
|
}
|
||||||
timeLeft = timeLeft/1000;
|
|
||||||
if(timeLeft <= 0) {
|
/**
|
||||||
return plugin.getLanguageManager().getLang("timeleft-ended");
|
* Minutes until automatic unrent when player is offline
|
||||||
} else if(timeLeft == 1) {
|
* @return The number of minutes until the region is unrented while player is offline
|
||||||
return plugin.getLanguageManager().getLang("timeleft-second", timeLeft);
|
*/
|
||||||
} else if(timeLeft <= 120) {
|
public long getInactiveTimeUntilUnrent() {
|
||||||
return plugin.getLanguageManager().getLang("timeleft-seconds", timeLeft);
|
return getIntegerSetting("rent.inactiveTimeUntilUnrent");
|
||||||
}
|
}
|
||||||
// To minutes
|
|
||||||
timeLeft = timeLeft/60;
|
/**
|
||||||
if(timeLeft <= 120) {
|
* Get a human readable string indicating how long the player can be offline until automatic unrent
|
||||||
return plugin.getLanguageManager().getLang("timeleft-minutes", timeLeft);
|
* @return String indicating the inactive time until unrent
|
||||||
}
|
*/
|
||||||
// To hours
|
public String getFormattedInactiveTimeUntilUnrent() {
|
||||||
timeLeft = timeLeft/60;
|
return this.millisToHumanFormat(getInactiveTimeUntilUnrent()*60*1000);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -325,6 +320,44 @@ public class RentRegion extends GeneralRegion {
|
|||||||
setSetting("rent.duration", duration);
|
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
|
* Check if the rent should expire
|
||||||
* @return true if the rent has expired and has been unrented, false otherwise
|
* @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
|
// Check if the region is available for renting or if the player wants to extend the rent
|
||||||
if(!isRented() || extend) {
|
if(!isRented() || extend) {
|
||||||
// Check if the players needs to be in the world or region for buying
|
// Check if the players needs to be in the world or region for buying
|
||||||
if(!player.getWorld().getName().equals(getWorldName()) && getBooleanSetting("general.restrictedToWorld")) {
|
if(restrictedToRegion() && (!player.getWorld().getName().equals(getWorldName())
|
||||||
plugin.message(player, "rent-restrictedToWorld", getWorldName(), player.getWorld().getName());
|
|| !getRegion().contains(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()))) {
|
||||||
|
plugin.message(player, "rent-restrictedToRegion", getName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if((!player.getWorld().getName().equals(getWorldName())
|
if(restrictedToWorld() && !player.getWorld().getName().equals(getWorldName())) {
|
||||||
|| !getRegion().contains(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ())
|
plugin.message(player, "rent-restrictedToWorld", getWorldName(), player.getWorld().getName());
|
||||||
) && getBooleanSetting("general.restrictedToRegion")) {
|
|
||||||
plugin.message(player, "rent-restrictedToRegion", getName());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Check region limits if this is not extending
|
// 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
|
// Check if there is enough time left before hitting maxRentTime
|
||||||
long timeNow = Calendar.getInstance().getTimeInMillis();
|
long timeNow = Calendar.getInstance().getTimeInMillis();
|
||||||
long timeRented = 0;
|
long timeRented = 0;
|
||||||
long maxRentTime = this.getLongSetting("rent.maxRentTime");
|
long maxRentTime = getMaxRentTime();
|
||||||
if(isRented()) {
|
if(isRented()) {
|
||||||
timeRented = getRentedUntil() - timeNow;
|
timeRented = getRentedUntil() - timeNow;
|
||||||
}
|
}
|
||||||
@ -527,14 +559,7 @@ public class RentRegion extends GeneralRegion {
|
|||||||
public void unRent(boolean giveMoneyBack) {
|
public void unRent(boolean giveMoneyBack) {
|
||||||
// Run commands
|
// Run commands
|
||||||
this.runEventCommands(RegionEvent.UNRENTED, true);
|
this.runEventCommands(RegionEvent.UNRENTED, true);
|
||||||
/* Get the time until the region will be rented */
|
double moneyBack = getMoneyBackAmount();
|
||||||
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;
|
|
||||||
if(moneyBack > 0 && giveMoneyBack) {
|
if(moneyBack > 0 && giveMoneyBack) {
|
||||||
/* Give back the money */
|
/* Give back the money */
|
||||||
OfflinePlayer player = Bukkit.getOfflinePlayer(getRenter());
|
OfflinePlayer player = Bukkit.getOfflinePlayer(getRenter());
|
||||||
|
Loading…
Reference in New Issue
Block a user