Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/main/java/org/minecast/bedhome/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ private void noBedCheck(Player p, World w, boolean isOtherWorld) {
switch (getConfig().getString("nobedmode")) {
case "a":
if (bedInConfig(p, w)) {
if (chargePlayerAccount(p, bedTpCost)) {
if (playerHasEnoughMoney(p, bedTpCost)) {
startBedTeleport(p, w, getConfig().getInt("teleportDelay"));
}
if (getConfig().getBoolean("console_messages")) {
Expand Down Expand Up @@ -587,16 +587,22 @@ private void doDebugChecking(CommandSender sender) {
}

public boolean chargePlayerAccount(Player p, double cost){
if (!useEconomy) return true;
if (econ.getBalance(p) >= cost){
if (playerHasEnoughMoney(p ,cost)){
econ.withdrawPlayer(p, cost);
return true;
} else {
}
else {
sendUTF8Message(getLocaleString("ERR_NO_MONEY").replace("$amount", String.valueOf(cost)), p);
}
return false;
}

//ideally we want to be able to check if someone has enough during the teleport windup, without actually charging them.
public boolean playerHasEnoughMoney(Player p, double cost){
if (!useEconomy) return true;
return econ.getBalance(p) >= cost;
}

@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if (commandLabel.equalsIgnoreCase("bed")) {
Expand All @@ -607,7 +613,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
if (Bukkit.getWorld(args[0]) != null) {
World w = Bukkit.getWorld(args[0]);
if (bedInConfig(p, w) && bedAtPos(p, w)) {
if (chargePlayerAccount(p, bedTpCost)) {
if (playerHasEnoughMoney(p, bedTpCost)) {
startBedTeleport(p, w, getConfig().getInt("teleportDelay"));
}
} else {
Expand All @@ -623,7 +629,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
if (isPlayerAuthorized(sender, "bedhome.bed")) {
if (p.getBedSpawnLocation() != null && p.getBedSpawnLocation().getWorld() == p.getWorld()) {
if (bedInConfig(p, p.getWorld())) {
if (chargePlayerAccount(p, bedTpCost)) {
if (playerHasEnoughMoney(p, bedTpCost)) {
startBedTeleport(p, p.getWorld(), getConfig().getInt("teleportDelay"));
}
if (getConfig().getBoolean("console_messages")) {
Expand Down Expand Up @@ -654,7 +660,9 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,

public void startBedTeleport(Player player, World world, int teleportDelay){
if (teleportDelay == 0) {
teleToBed(player, world);
if (chargePlayerAccount(player, bedTpCost)){
teleToBed(player, world);
}
}

player.sendMessage(getLocaleString("BH_DELAYED"));
Expand All @@ -665,7 +673,9 @@ public void startBedTeleport(Player player, World world, int teleportDelay){
player.sendMessage(getLocaleString("BH_MOVED_DELAY"));
}
else {
teleToBed(player, world);
if (chargePlayerAccount(player, bedTpCost)){
teleToBed(player, world);
}
}
}, teleportDelay * 20L);
};
Expand Down