Fix '/as find' not getting your balance correctly

- If you search with your balance (and do not give a maxprice) it would
always use 0.0 as your balance, therefore not finding any regions.
- Also fixes the incorrect feedback, it would say it searched with a
maxprice instead of your balance and the other way around if no regions
are found.
- Fixed maxprice and balance display to use correct currency symbols and
layouts (decimals, metric prefixes, separator).

Fixes #59
This commit is contained in:
Thijs Wiefferink 2015-08-29 20:04:08 +02:00
parent bf181d69d7
commit 9ca029176d
2 changed files with 12 additions and 27 deletions

View File

@ -1,7 +1,5 @@
package nl.evolutioncoding.areashop.commands;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@ -51,7 +49,7 @@ public class FindCommand extends CommandAreaShop {
Player player = (Player)sender;
double balance = 0.0;
if(plugin.getEconomy() != null) {
plugin.getEconomy().getBalance(player);
balance = plugin.getEconomy().getBalance(player);
}
double maxPrice = 0;
boolean maxPriceSet = false;
@ -65,7 +63,8 @@ public class FindCommand extends CommandAreaShop {
plugin.message(sender, "find-wrongMaxPrice", args[2]);
return;
}
}
}
AreaShop.debug("maxPriceSet="+maxPriceSet+", balance="+balance);
// Parse optional group argument
if(args.length >= 4) {
group = plugin.getFileManager().getGroup(args[3]);
@ -87,32 +86,25 @@ public class FindCommand extends CommandAreaShop {
if(!results.isEmpty()) {
// Draw a random one
BuyRegion region = results.get(new Random().nextInt(results.size()));
BigDecimal bigDecimal = new BigDecimal(balance);
bigDecimal = bigDecimal.setScale(2, RoundingMode.HALF_UP);
balance = bigDecimal.doubleValue();
String onlyInGroup = "";
if(group != null) {
onlyInGroup = plugin.getLanguageManager().getLang("find-onlyInGroup", args[3]);
}
if(maxPriceSet) {
plugin.message(player, "find-successMax", "buy", region.getName(), maxPrice, onlyInGroup);
plugin.message(player, "find-successMax", "buy", region.getName(), plugin.formatCurrency(maxPrice), onlyInGroup);
} else {
plugin.message(player, "find-success", "buy", region.getName(), balance, onlyInGroup);
plugin.message(player, "find-success", "buy", region.getName(), plugin.formatCurrency(balance), onlyInGroup);
}
region.teleportPlayer(player, region.getBooleanSetting("general.findTeleportToSign"), false);
} else {
BigDecimal bigDecimal = new BigDecimal(balance);
bigDecimal = bigDecimal.setScale(2, RoundingMode.HALF_UP);
balance = bigDecimal.doubleValue();
String onlyInGroup = "";
if(group != null) {
onlyInGroup = plugin.getLanguageManager().getLang("find-onlyInGroup", args[3]);
}
if(maxPriceSet) {
plugin.message(player, "find-noneFound", "buy", maxPrice, onlyInGroup);
plugin.message(player, "find-noneFoundMax", "buy", plugin.formatCurrency(maxPrice), onlyInGroup);
} else {
plugin.message(player, "find-noneFoundMax", "buy", balance, onlyInGroup);
plugin.message(player, "find-noneFound", "buy", plugin.formatCurrency(balance), onlyInGroup);
}
}
} else {
@ -128,32 +120,25 @@ public class FindCommand extends CommandAreaShop {
if(!results.isEmpty()) {
// Draw a random one
RentRegion region = results.get(new Random().nextInt(results.size()));
BigDecimal bigDecimal = new BigDecimal(balance);
bigDecimal = bigDecimal.setScale(2, RoundingMode.HALF_UP);
balance = bigDecimal.doubleValue();
String onlyInGroup = "";
if(group != null) {
onlyInGroup = plugin.getLanguageManager().getLang("find-onlyInGroup", args[3]);
}
if(maxPriceSet) {
plugin.message(player, "find-successMax", "rent", region.getName(), maxPrice, onlyInGroup);
plugin.message(player, "find-successMax", "rent", region.getName(), plugin.formatCurrency(maxPrice), onlyInGroup);
} else {
plugin.message(player, "find-success", "rent", region.getName(), balance, onlyInGroup);
plugin.message(player, "find-success", "rent", region.getName(), plugin.formatCurrency(balance), onlyInGroup);
}
region.teleportPlayer(player, region.getBooleanSetting("general.findTeleportToSign"), false);
} else {
BigDecimal bigDecimal = new BigDecimal(balance);
bigDecimal = bigDecimal.setScale(2, RoundingMode.HALF_UP);
balance = bigDecimal.doubleValue();
String onlyInGroup = "";
if(group != null) {
onlyInGroup = plugin.getLanguageManager().getLang("find-onlyInGroup", args[3]);
}
if(maxPriceSet) {
plugin.message(player, "find-noneFound", "rent", maxPrice, onlyInGroup);
plugin.message(player, "find-noneFoundMax", "rent", plugin.formatCurrency(maxPrice), onlyInGroup);
} else {
plugin.message(player, "find-noneFoundMax", "rent", balance, onlyInGroup);
plugin.message(player, "find-noneFound", "rent", plugin.formatCurrency(balance), onlyInGroup);
}
}
}

View File

@ -5,7 +5,7 @@ description: "Selling and renting WorldGuard regions to your players, highly con
depend: [Vault, WorldGuard, WorldEdit]
softdepend: [Multiverse-Core]
author: NLThijs48
website: http://dev.bukkit.org/bukkit-plugins/regionbuyandrent/
website: https://github.com/NLthijs48/AreaShop
commands:
AreaShop:
description: 'For all commands use /as help.'