mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 22:17:17 +00:00
Close #18 - Added option to charge per use of /back command
This commit is contained in:
1 parent
4f7b4a7e18
commit
da30aa9076
11 files changed
+62
-9
No files matched your search
@@ -1,7 +1,9 @@
|
||||
package me.william278.huskhomes2.commands;
|
||||
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
import me.william278.huskhomes2.MessageManager;
|
||||
import me.william278.huskhomes2.data.DataManager;
|
||||
import me.william278.huskhomes2.integrations.VaultIntegration;
|
||||
import me.william278.huskhomes2.teleport.TeleportManager;
|
||||
import me.william278.huskhomes2.teleport.points.TeleportationPoint;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -11,11 +13,6 @@ public class BackCommand extends CommandBase {
|
||||
|
||||
@Override
|
||||
protected void onCommand(Player p, Command command, String label, String[] args) {
|
||||
TeleportationPoint lastPosition = DataManager.getPlayerLastPosition(p);
|
||||
if (lastPosition != null) {
|
||||
TeleportManager.queueTimedTeleport(p, lastPosition);
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_no_last_position");
|
||||
}
|
||||
TeleportManager.queueBackTeleport(p);
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,7 @@ public class Settings {
|
||||
private double setHomeCost;
|
||||
private double publicHomeCost;
|
||||
private double rtpCost;
|
||||
private double backCost;
|
||||
|
||||
// Vanished player checks
|
||||
private boolean checkVanishedPlayers;
|
||||
@@ -154,6 +155,7 @@ public class Settings {
|
||||
this.setHomeCost = config.getDouble("economy_integration.costs.additional_home_slot");
|
||||
this.publicHomeCost = config.getDouble("economy_integration.costs.make_home_public");
|
||||
this.rtpCost = config.getDouble("economy_integration.costs.random_teleport");
|
||||
this.backCost = config.getDouble("economy_integration.costs.back");
|
||||
|
||||
// Retrieve sounds used in plugin; if invalid, use defaults.
|
||||
try {
|
||||
@@ -321,6 +323,10 @@ public class Settings {
|
||||
return setHomeCost;
|
||||
}
|
||||
|
||||
public double getBackCost() {
|
||||
return backCost;
|
||||
}
|
||||
|
||||
public double getPublicHomeCost() {
|
||||
return publicHomeCost;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,37 @@ public class TeleportManager {
|
||||
return;
|
||||
}
|
||||
|
||||
getQueuedTeleports().add(new TimedTeleport(player, point));
|
||||
getQueuedTeleports().add(new TimedTeleport(player, point, "point"));
|
||||
}
|
||||
|
||||
public static void queueBackTeleport(Player player) {
|
||||
TeleportationPoint lastPosition = DataManager.getPlayerLastPosition(player);
|
||||
if (lastPosition != null) {
|
||||
if (HuskHomes.getSettings().doEconomy()) {
|
||||
double backCost = HuskHomes.getSettings().getBackCost();
|
||||
if (backCost > 0) {
|
||||
if (!VaultIntegration.hasMoney(player, backCost)) {
|
||||
MessageManager.sendMessage(player, "error_insufficient_funds", VaultIntegration.format(backCost));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (player.hasPermission("huskhomes.bypass_timer")) {
|
||||
if (HuskHomes.getSettings().doEconomy()) {
|
||||
double backCost = HuskHomes.getSettings().getRtpCost();
|
||||
if (backCost > 0) {
|
||||
VaultIntegration.takeMoney(player, backCost);
|
||||
MessageManager.sendMessage(player, "rtp_spent_money", VaultIntegration.format(backCost));
|
||||
}
|
||||
}
|
||||
teleportPlayer(player, lastPosition);
|
||||
return;
|
||||
}
|
||||
|
||||
getQueuedTeleports().add(new TimedTeleport(player, lastPosition, "back"));
|
||||
} else {
|
||||
MessageManager.sendMessage(player, "error_no_last_position");
|
||||
}
|
||||
}
|
||||
|
||||
public static void queueRandomTeleport(Player player) {
|
||||
|
||||
@@ -201,6 +201,20 @@ public class TeleportRequestHandler {
|
||||
case "point":
|
||||
TeleportManager.teleportPlayer(teleporter, timedTeleport.getTargetPoint());
|
||||
break;
|
||||
case "back":
|
||||
if (HuskHomes.getSettings().doEconomy()) {
|
||||
double backCost = HuskHomes.getSettings().getBackCost();
|
||||
if (backCost > 0) {
|
||||
if (!VaultIntegration.takeMoney(teleporter, backCost)) {
|
||||
MessageManager.sendMessage(teleporter, "error_insufficient_funds", VaultIntegration.format(backCost));
|
||||
break;
|
||||
} else {
|
||||
MessageManager.sendMessage(teleporter, "back_spent_money", VaultIntegration.format(backCost));
|
||||
}
|
||||
}
|
||||
}
|
||||
TeleportManager.teleportPlayer(teleporter, timedTeleport.getTargetPoint());
|
||||
break;
|
||||
case "player":
|
||||
TeleportManager.teleportPlayer(teleporter, timedTeleport.getTargetPlayerName());
|
||||
break;
|
||||
|
||||
@@ -20,11 +20,11 @@ public class TimedTeleport {
|
||||
private int timeRemaining;
|
||||
private final int warmupTime = HuskHomes.getSettings().getTeleportWarmupTime();
|
||||
|
||||
public TimedTeleport(Player teleporter, TeleportationPoint targetPoint) {
|
||||
public TimedTeleport(Player teleporter, TeleportationPoint targetPoint, String targetType) {
|
||||
this.teleporter = teleporter;
|
||||
this.initialTeleporterLocation = teleporter.getLocation();
|
||||
this.initialTeleporterHealth = teleporter.getHealth();
|
||||
this.targetType = "point";
|
||||
this.targetType = targetType;
|
||||
this.targetPoint = targetPoint;
|
||||
this.timeRemaining = warmupTime;
|
||||
|
||||
|
||||
Reference in new issue
Block a user