Fix a couple of bugs

This commit is contained in:
Thijs Wiefferink 2015-06-11 00:51:44 +02:00
parent 8f2c95f5c4
commit dfbc7805b5
4 changed files with 114 additions and 100 deletions

View File

@ -581,47 +581,54 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
String after = this.getConfig().getString("moneyCharacterAfter");
after = after.replace(currencyEuro, "\u20ac");
String result;
// Add metric
double metricAbove = getConfig().getDouble("metricSuffixesAbove");
if(metricAbove != -1 && amount >= metricAbove) {
if(amount >= 1000000000000000000000000.0) {
amount = amount/1000000000000000000000000.0;
after = "Y" + after;
} else if(amount >= 1000000000000000000000.0) {
amount = amount/1000000000000000000000.0;
after = "Z" + after;
} else if(amount >= 1000000000000000000.0) {
amount = amount/1000000000000000000.0;
after = "E" + after;
} else if(amount >= 1000000000000000.0) {
amount = amount/1000000000000000.0;
after = "P" + after;
} else if(amount >= 1000000000000.0) {
amount = amount/1000000000000.0;
after = "T" + after;
} else if(amount >= 1000000000.0) {
amount = amount/1000000000.0;
after = "G" + after;
} else if(amount >= 1000000.0) {
amount = amount/1000000.0;
after = "M" + after;
} else if(amount >= 1000.0) {
amount = amount/1000.0;
after = "k" + after;
}
BigDecimal bigDecimal = new BigDecimal(amount);
if(bigDecimal.toString().contains(".")) {
int frontLength = bigDecimal.toString().substring(0, bigDecimal.toString().indexOf('.')).length();
bigDecimal = bigDecimal.setScale(getConfig().getInt("fractionalNumbers") + (3-frontLength), RoundingMode.HALF_UP);
}
result = bigDecimal.toString();
} else {
BigDecimal bigDecimal = new BigDecimal(amount);
bigDecimal = bigDecimal.setScale(getConfig().getInt("fractionalNumbers"), RoundingMode.HALF_UP);
amount = bigDecimal.doubleValue();
result = bigDecimal.toString();
if(getConfig().getBoolean("hideEmptyFractionalPart") && (amount%1.0) == 0.0 && result.contains(".")) {
result = result.substring(0, result.indexOf('.'));
// Check for infinite and NaN
if(Double.isInfinite(amount)) {
result = "\u221E"; // Infinite symbol
} else if(Double.isNaN(amount)) {
result = "NaN";
} else {
// Add metric
double metricAbove = getConfig().getDouble("metricSuffixesAbove");
if(metricAbove != -1 && amount >= metricAbove) {
if(amount >= 1000000000000000000000000.0) {
amount = amount/1000000000000000000000000.0;
after = "Y" + after;
} else if(amount >= 1000000000000000000000.0) {
amount = amount/1000000000000000000000.0;
after = "Z" + after;
} else if(amount >= 1000000000000000000.0) {
amount = amount/1000000000000000000.0;
after = "E" + after;
} else if(amount >= 1000000000000000.0) {
amount = amount/1000000000000000.0;
after = "P" + after;
} else if(amount >= 1000000000000.0) {
amount = amount/1000000000000.0;
after = "T" + after;
} else if(amount >= 1000000000.0) {
amount = amount/1000000000.0;
after = "G" + after;
} else if(amount >= 1000000.0) {
amount = amount/1000000.0;
after = "M" + after;
} else if(amount >= 1000.0) {
amount = amount/1000.0;
after = "k" + after;
}
BigDecimal bigDecimal = new BigDecimal(amount);
if(bigDecimal.toString().contains(".")) {
int frontLength = bigDecimal.toString().substring(0, bigDecimal.toString().indexOf('.')).length();
bigDecimal = bigDecimal.setScale(getConfig().getInt("fractionalNumbers") + (3-frontLength), RoundingMode.HALF_UP);
}
result = bigDecimal.toString();
} else {
BigDecimal bigDecimal = new BigDecimal(amount);
bigDecimal = bigDecimal.setScale(getConfig().getInt("fractionalNumbers"), RoundingMode.HALF_UP);
amount = bigDecimal.doubleValue();
result = bigDecimal.toString();
if(getConfig().getBoolean("hideEmptyFractionalPart") && (amount%1.0) == 0.0 && result.contains(".")) {
result = result.substring(0, result.indexOf('.'));
}
}
}
result = result.replace(".", getConfig().getString("decimalMark"));

View File

@ -55,7 +55,7 @@ public class SetrestoreCommand extends CommandAreaShop {
valueString = value+"";
}
if(args.length > 3) {
region.setRestoreProfile(args[3]);
region.setSchematicProfile(args[3]);
plugin.message(sender, "setrestore-successProfile", region.getName(), valueString, args[3]);
} else {
plugin.message(sender, "setrestore-success", region.getName(), valueString);

View File

@ -222,12 +222,15 @@ public class FileManager {
* @param regionName Name of the region that can be rented
* @param rent Map containing all the info for a rent
*/
public void addRent(RentRegion rent) {
public void addRentNoSave(RentRegion rent) {
if(rent == null) {
AreaShop.debug("Tried adding a null rent!");
return;
}
regions.put(rent.getName().toLowerCase(), rent);
}
public void addRent(RentRegion rent) {
addRentNoSave(rent);
rent.saveRequired();
}
@ -236,12 +239,15 @@ public class FileManager {
* @param regionName Name of the region that can be buyed
* @param buy Map containing all the info for a buy
*/
public void addBuy(BuyRegion buy) {
public void addBuyNoSave(BuyRegion buy) {
if(buy == null) {
AreaShop.debug("Tried adding a null buy!");
return;
}
regions.put(buy.getName().toLowerCase(), buy);
}
public void addBuy(BuyRegion buy) {
addBuyNoSave(buy);
buy.saveRequired();
}
@ -992,10 +998,10 @@ public class FileManager {
// Construct the correct type of region
if(RegionType.RENT.getValue().equals(config.getString("general.type"))) {
RentRegion rent = new RentRegion(plugin, config);
addRent(rent);
addRentNoSave(rent);
} else if(RegionType.BUY.getValue().equals(config.getString("general.type"))) {
BuyRegion buy = new BuyRegion(plugin, config);
addBuy(buy);
addBuyNoSave(buy);
}
}
}

View File

@ -842,8 +842,8 @@ public abstract class GeneralRegion implements GeneralRegionInterface {
* Change the restore profile
* @param profile default or the name of the profile as set in the config
*/
public void setRestoreProfile(String profile) {
setSetting("general.restoreProfile", profile);
public void setSchematicProfile(String profile) {
setSetting("general.schematicProfile", profile);
}
/**
@ -1125,6 +1125,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface {
* Indicate this region needs to be saved, saving will happen by a repeating task
*/
public void saveRequired() {
AreaShop.debug("saveRequired()");
saveRequired = true;
}
@ -1276,14 +1277,14 @@ public abstract class GeneralRegion implements GeneralRegionInterface {
// Check locations starting from startLocation and then a cube that increases
// radius around that (until no block in the region is found at all cube sides)
Location saveLocation = startLocation;
Location safeLocation = startLocation;
int radius = 1;
boolean blocksInRegion = region.contains(startLocation.getBlockX(), startLocation.getBlockY(), startLocation.getBlockZ());
if(!blocksInRegion && insideRegion) {
plugin.message(player, "teleport-blocked", getName());
return false;
}
boolean done = isSave(saveLocation) && ((blocksInRegion && insideRegion) || (!insideRegion));
boolean done = isSafe(safeLocation) && ((blocksInRegion && insideRegion) || (!insideRegion));
boolean north=false, east=false, south=false, west=false, top=false, bottom=false;
boolean track;
while(((blocksInRegion && insideRegion) || (!insideRegion)) && !done) {
@ -1292,13 +1293,13 @@ public abstract class GeneralRegion implements GeneralRegionInterface {
track = false;
for(int x=-radius+1; x<=radius && !done && !north; x++) {
for(int y=-radius+1; y<radius && !done; y++) {
saveLocation = startLocation.clone().add(x, y, -radius);
if(saveLocation.getBlockY()>256 || saveLocation.getBlockY()<0) {
safeLocation = startLocation.clone().add(x, y, -radius);
if(safeLocation.getBlockY()>256 || safeLocation.getBlockY()<0) {
continue;
}
if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
if((insideRegion && region.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ())) || !insideRegion) {
checked++;
done = isSave(saveLocation) || checked > maxTries;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
@ -1310,13 +1311,13 @@ public abstract class GeneralRegion implements GeneralRegionInterface {
track = false;
for(int z=-radius+1; z<=radius && !done && !east; z++) {
for(int y=-radius+1; y<radius && !done; y++) {
saveLocation = startLocation.clone().add(radius, y, z);
if(saveLocation.getBlockY()>256 || saveLocation.getBlockY()<0) {
safeLocation = startLocation.clone().add(radius, y, z);
if(safeLocation.getBlockY()>256 || safeLocation.getBlockY()<0) {
continue;
}
if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
if((insideRegion && region.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ())) || !insideRegion) {
checked++;
done = isSave(saveLocation) || checked > maxTries;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
@ -1328,13 +1329,13 @@ public abstract class GeneralRegion implements GeneralRegionInterface {
track = false;
for(int x=radius-1; x>=-radius && !done && !south; x--) {
for(int y=-radius+1; y<radius && !done; y++) {
saveLocation = startLocation.clone().add(x, y, radius);
if(saveLocation.getBlockY()>256 || saveLocation.getBlockY()<0) {
safeLocation = startLocation.clone().add(x, y, radius);
if(safeLocation.getBlockY()>256 || safeLocation.getBlockY()<0) {
continue;
}
if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
if((insideRegion && region.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ())) || !insideRegion) {
checked++;
done = isSave(saveLocation) || checked > maxTries;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
@ -1346,13 +1347,13 @@ public abstract class GeneralRegion implements GeneralRegionInterface {
track = false;
for(int z=radius-1; z>=-radius && !done && !west; z--) {
for(int y=-radius+1; y<radius && !done; y++) {
saveLocation = startLocation.clone().add(-radius, y, z);
if(saveLocation.getBlockY()>256 || saveLocation.getBlockY()<0) {
safeLocation = startLocation.clone().add(-radius, y, z);
if(safeLocation.getBlockY()>256 || safeLocation.getBlockY()<0) {
continue;
}
if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
if((insideRegion && region.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ())) || !insideRegion) {
checked++;
done = isSave(saveLocation) || checked > maxTries;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
@ -1367,10 +1368,10 @@ public abstract class GeneralRegion implements GeneralRegionInterface {
top = true;
}
if(!done && !top) {
saveLocation = startLocation.clone().add(0, radius, 0);
if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
safeLocation = startLocation.clone().add(0, radius, 0);
if((insideRegion && region.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ())) || !insideRegion) {
checked++;
done = isSave(saveLocation) || checked > maxTries;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
@ -1378,40 +1379,40 @@ public abstract class GeneralRegion implements GeneralRegionInterface {
for(int r=1; r<=radius && !done && !top; r++) {
// North
for(int x=-r+1; x<=r && !done; x++) {
saveLocation = startLocation.clone().add(x, radius, -r);
if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
safeLocation = startLocation.clone().add(x, radius, -r);
if((insideRegion && region.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ())) || !insideRegion) {
checked++;
done = isSave(saveLocation) || checked > maxTries;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
}
// East
for(int z=-r+1; z<=r && !done; z++) {
saveLocation = startLocation.clone().add(r, radius, z);
if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
safeLocation = startLocation.clone().add(r, radius, z);
if((insideRegion && region.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ())) || !insideRegion) {
checked++;
done = isSave(saveLocation) || checked > maxTries;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
}
// South side
for(int x=r-1; x>=-r && !done; x--) {
saveLocation = startLocation.clone().add(x, radius, r);
if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
safeLocation = startLocation.clone().add(x, radius, r);
if((insideRegion && region.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ())) || !insideRegion) {
checked++;
done = isSave(saveLocation) || checked > maxTries;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
}
// West side
for(int z=r-1; z>=-r && !done; z--) {
saveLocation = startLocation.clone().add(-r, radius, z);
if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
safeLocation = startLocation.clone().add(-r, radius, z);
if((insideRegion && region.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ())) || !insideRegion) {
checked++;
done = isSave(saveLocation) || checked > maxTries;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
@ -1426,10 +1427,10 @@ public abstract class GeneralRegion implements GeneralRegionInterface {
bottom = true;
}
if(!done && !bottom) {
saveLocation = startLocation.clone().add(0, -radius, 0);
if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
safeLocation = startLocation.clone().add(0, -radius, 0);
if((insideRegion && region.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ())) || !insideRegion) {
checked++;
done = isSave(saveLocation) || checked > maxTries;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
@ -1437,40 +1438,40 @@ public abstract class GeneralRegion implements GeneralRegionInterface {
for(int r=1; r<=radius && !done && !bottom; r++) {
// North
for(int x=-r+1; x<=r && !done; x++) {
saveLocation = startLocation.clone().add(x, -radius, -r);
if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
safeLocation = startLocation.clone().add(x, -radius, -r);
if((insideRegion && region.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ())) || !insideRegion) {
checked++;
done = isSave(saveLocation) || checked > maxTries;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
}
// East
for(int z=-r+1; z<=r && !done; z++) {
saveLocation = startLocation.clone().add(r, -radius, z);
if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
safeLocation = startLocation.clone().add(r, -radius, z);
if((insideRegion && region.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ())) || !insideRegion) {
checked++;
done = isSave(saveLocation) || checked > maxTries;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
}
// South side
for(int x=r-1; x>=-r && !done; x--) {
saveLocation = startLocation.clone().add(x, -radius, r);
if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
safeLocation = startLocation.clone().add(x, -radius, r);
if((insideRegion && region.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ())) || !insideRegion) {
checked++;
done = isSave(saveLocation) || checked > maxTries;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
}
// West side
for(int z=r-1; z>=-r && !done; z--) {
saveLocation = startLocation.clone().add(-r, -radius, z);
if((insideRegion && region.contains(saveLocation.getBlockX(), saveLocation.getBlockY(), saveLocation.getBlockZ())) || !insideRegion) {
safeLocation = startLocation.clone().add(-r, -radius, z);
if((insideRegion && region.contains(safeLocation.getBlockX(), safeLocation.getBlockY(), safeLocation.getBlockZ())) || !insideRegion) {
checked++;
done = isSave(saveLocation) || checked > maxTries;
done = isSafe(safeLocation) || checked > maxTries;
blocksInRegion = true;
track = true;
}
@ -1481,14 +1482,14 @@ public abstract class GeneralRegion implements GeneralRegionInterface {
// Increase cube radius
radius++;
}
if(done && isSave(saveLocation)) {
if(done && isSafe(safeLocation)) {
if(toSign) {
plugin.message(player, "teleport-successSign", getName());
} else {
plugin.message(player, "teleport-success", getName());
}
player.teleport(saveLocation);
AreaShop.debug("Found location: " + saveLocation.toString() + " Tries: " + (checked-1));
player.teleport(safeLocation);
AreaShop.debug("Found location: " + safeLocation.toString() + " Tries: " + (checked-1));
return true;
} else {
plugin.message(player, "teleport-noSafe", getName(), checked-1, maxTries);
@ -1508,7 +1509,7 @@ public abstract class GeneralRegion implements GeneralRegionInterface {
* @param location The location to check
* @return true if it is safe, otherwise false
*/
protected boolean isSave(Location location) {
protected boolean isSafe(Location location) {
Block feet = location.getBlock();
Block head = feet.getRelative(BlockFace.UP);
Block below = feet.getRelative(BlockFace.DOWN);