Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Commit

Permalink
optimize rounding, may fix #45
Browse files Browse the repository at this point in the history
  • Loading branch information
Librazy committed Mar 31, 2018
1 parent 9dc9144 commit e7fb8c5
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/main/java/cat/nyaa/nyaautils/commandwarpper/Teleport.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import org.bukkit.event.player.PlayerTeleportEvent;
import org.librazy.nyaautils_lang_checker.LangKey;

import java.text.DecimalFormat;
import java.math.BigDecimal;
import java.util.List;

public class Teleport implements Listener {
public static boolean hasOurTown = false;
private static boolean hasOurTown = false;
private IEssentials ess;
private NyaaUtils plugin;

Expand Down Expand Up @@ -156,7 +156,7 @@ private void doSetHome(Player p, User iu, Location curLoc, String name) {
fee -= curLoc.distance(PlayerSpawn(p, defaultWorld)) * (double) plugin.cfg.setHomeDecrement / plugin.cfg.setHomeDistance;
}
if (fee < plugin.cfg.setHomeMin) fee = plugin.cfg.setHomeMin;
fee = Double.parseDouble(new DecimalFormat("#.00").format(fee));
fee = new BigDecimal(fee).setScale(2, BigDecimal.ROUND_HALF_DOWN).doubleValue();
if (!VaultUtils.withdraw(p, fee)) {
msg(p, "user.teleport.money_insufficient", fee);
return;
Expand All @@ -182,7 +182,7 @@ private void doBack(Player p, User iu, Location curLoc, Location lastLoc) {
fee += lastLoc.distance(curLoc) * (double) plugin.cfg.backIncrement / plugin.cfg.backDistance;
}
if (fee > plugin.cfg.backMax) fee = plugin.cfg.backMax;
fee = Double.parseDouble(new DecimalFormat("#.00").format(fee));
fee = new BigDecimal(fee).setScale(2, BigDecimal.ROUND_HALF_DOWN).doubleValue();
if (!VaultUtils.withdraw(p, fee)) {
msg(p, "user.teleport.money_insufficient", fee);
return;
Expand Down Expand Up @@ -213,7 +213,7 @@ private void doHome(Player p, User iu, Location homeLoc, Location curLoc) {
fee += homeLoc.distance(curLoc) * (double) plugin.cfg.homeIncrement / plugin.cfg.homeDistance;
}
if (fee > plugin.cfg.homeMax) fee = plugin.cfg.homeMax;
fee = Double.parseDouble(new DecimalFormat("#.00").format(fee));
fee = new BigDecimal(fee).setScale(2, BigDecimal.ROUND_HALF_DOWN).doubleValue();
if (!VaultUtils.withdraw(p, fee)) {
msg(p, "user.teleport.money_insufficient", fee);
return;
Expand Down

0 comments on commit e7fb8c5

Please sign in to comment.