mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 14:38:53 +00:00
Fix economy actions being skippable in some circumstances
This commit is contained in:
1 parent
08e6569027
commit
cda665cc5a
3 files changed
+49
-10
No files matched your search
@@ -20,11 +20,11 @@ public class BackCommand extends CommandBase {
|
|||||||
if (!plugin.validateEconomyCheck(onlineUser, Settings.EconomyAction.BACK_COMMAND)) {
|
if (!plugin.validateEconomyCheck(onlineUser, Settings.EconomyAction.BACK_COMMAND)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plugin.performEconomyTransaction(onlineUser, Settings.EconomyAction.BACK_COMMAND);
|
|
||||||
|
|
||||||
// Teleport the player
|
// Teleport the player
|
||||||
plugin.getTeleportManager().timedTeleport(onlineUser, position)
|
plugin.getTeleportManager().timedTeleport(onlineUser, position, Settings.EconomyAction.RANDOM_TELEPORT)
|
||||||
.thenAccept(result -> plugin.getTeleportManager().finishTeleport(onlineUser, result));
|
.thenAccept(result -> plugin.getTeleportManager()
|
||||||
|
.finishTeleport(onlineUser, result, Settings.EconomyAction.RANDOM_TELEPORT));
|
||||||
},
|
},
|
||||||
() -> plugin.getLocales().getLocale("error_no_last_position").ifPresent(onlineUser::sendMessage)));
|
() -> plugin.getLocales().getLocale("error_no_last_position").ifPresent(onlineUser::sendMessage)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,16 @@ package net.william278.huskhomes.command;
|
|||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
import net.william278.huskhomes.config.Settings;
|
import net.william278.huskhomes.config.Settings;
|
||||||
import net.william278.huskhomes.player.OnlineUser;
|
import net.william278.huskhomes.player.OnlineUser;
|
||||||
|
import net.william278.huskhomes.player.UserData;
|
||||||
import net.william278.huskhomes.position.Position;
|
import net.william278.huskhomes.position.Position;
|
||||||
import net.william278.huskhomes.util.Permission;
|
import net.william278.huskhomes.util.Permission;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class RtpCommand extends CommandBase implements ConsoleExecutable {
|
public class RtpCommand extends CommandBase implements ConsoleExecutable {
|
||||||
|
|
||||||
protected RtpCommand(@NotNull HuskHomes implementor) {
|
protected RtpCommand(@NotNull HuskHomes implementor) {
|
||||||
@@ -28,10 +34,25 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Perform economy check if necessary
|
||||||
if (!plugin.validateEconomyCheck(onlineUser, Settings.EconomyAction.RANDOM_TELEPORT)) {
|
if (!plugin.validateEconomyCheck(onlineUser, Settings.EconomyAction.RANDOM_TELEPORT)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CompletableFuture.runAsync(() -> {
|
||||||
|
// Check the user is not still on /rtp cooldown
|
||||||
|
final Optional<UserData> userData = plugin.getDatabase().getUserData(onlineUser.uuid).join();
|
||||||
|
if (userData.isPresent()) {
|
||||||
|
final Instant currentTime = Instant.now();
|
||||||
|
if (!currentTime.isAfter(userData.get().rtpCooldown())) {
|
||||||
|
plugin.getLocales().getLocale("error_rtp_cooldown",
|
||||||
|
Long.toString(currentTime.until(userData.get().rtpCooldown(), ChronoUnit.MINUTES)))
|
||||||
|
.ifPresent(onlineUser::sendMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a random position and teleport
|
||||||
plugin.getRtpEngine().getRandomPosition(userPosition)
|
plugin.getRtpEngine().getRandomPosition(userPosition)
|
||||||
.thenAccept(position -> {
|
.thenAccept(position -> {
|
||||||
if (position.isEmpty()) {
|
if (position.isEmpty()) {
|
||||||
@@ -39,11 +60,10 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
|
|||||||
.ifPresent(onlineUser::sendMessage);
|
.ifPresent(onlineUser::sendMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plugin.getTeleportManager().timedTeleport(onlineUser, position.get())
|
plugin.getTeleportManager().timedTeleport(onlineUser, position.get(), Settings.EconomyAction.RANDOM_TELEPORT)
|
||||||
.thenAccept(result -> {
|
.thenAccept(result -> plugin.getTeleportManager()
|
||||||
plugin.getTeleportManager().finishTeleport(onlineUser, result);
|
.finishTeleport(onlineUser, result, Settings.EconomyAction.RANDOM_TELEPORT)).join();
|
||||||
plugin.performEconomyTransaction(onlineUser, Settings.EconomyAction.RANDOM_TELEPORT);
|
}).join();
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.william278.huskhomes.teleport;
|
package net.william278.huskhomes.teleport;
|
||||||
|
|
||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
|
import net.william278.huskhomes.config.Settings;
|
||||||
import net.william278.huskhomes.messenger.Message;
|
import net.william278.huskhomes.messenger.Message;
|
||||||
import net.william278.huskhomes.messenger.MessagePayload;
|
import net.william278.huskhomes.messenger.MessagePayload;
|
||||||
import net.william278.huskhomes.player.OnlineUser;
|
import net.william278.huskhomes.player.OnlineUser;
|
||||||
@@ -227,8 +228,11 @@ public class TeleportManager {
|
|||||||
*
|
*
|
||||||
* @param onlineUser the {@link OnlineUser} to teleport
|
* @param onlineUser the {@link OnlineUser} to teleport
|
||||||
* @param position the target {@link Position} to teleport to
|
* @param position the target {@link Position} to teleport to
|
||||||
|
* @param economyActions any economy actions to validate before the teleport.
|
||||||
|
* Note that this will not actually carry out the economy transactions, only validate them
|
||||||
*/
|
*/
|
||||||
public CompletableFuture<TeleportResult> timedTeleport(@NotNull OnlineUser onlineUser, @NotNull Position position) {
|
public CompletableFuture<TeleportResult> timedTeleport(@NotNull OnlineUser onlineUser, @NotNull Position position,
|
||||||
|
@NotNull Settings.EconomyAction... economyActions) {
|
||||||
// Prevent players starting multiple timed teleports
|
// Prevent players starting multiple timed teleports
|
||||||
if (currentlyOnWarmup.contains(onlineUser.uuid)) {
|
if (currentlyOnWarmup.contains(onlineUser.uuid)) {
|
||||||
return CompletableFuture.supplyAsync(() -> TeleportResult.FAILED_ALREADY_TELEPORTING);
|
return CompletableFuture.supplyAsync(() -> TeleportResult.FAILED_ALREADY_TELEPORTING);
|
||||||
@@ -239,6 +243,11 @@ public class TeleportManager {
|
|||||||
return CompletableFuture.supplyAsync(() -> processTeleportWarmup(new TimedTeleport(onlineUser, position, teleportWarmupTime))
|
return CompletableFuture.supplyAsync(() -> processTeleportWarmup(new TimedTeleport(onlineUser, position, teleportWarmupTime))
|
||||||
.thenApply(teleport -> {
|
.thenApply(teleport -> {
|
||||||
if (!teleport.cancelled) {
|
if (!teleport.cancelled) {
|
||||||
|
for (final Settings.EconomyAction action : economyActions) {
|
||||||
|
if (!plugin.validateEconomyCheck(onlineUser, action)) {
|
||||||
|
return TeleportResult.CANCELLED;
|
||||||
|
}
|
||||||
|
}
|
||||||
return teleport(onlineUser, position).join();
|
return teleport(onlineUser, position).join();
|
||||||
} else {
|
} else {
|
||||||
return TeleportResult.CANCELLED;
|
return TeleportResult.CANCELLED;
|
||||||
@@ -254,8 +263,11 @@ public class TeleportManager {
|
|||||||
*
|
*
|
||||||
* @param onlineUser the {@link OnlineUser} to send the teleport completion message to
|
* @param onlineUser the {@link OnlineUser} to send the teleport completion message to
|
||||||
* @param teleportResult the {@link TeleportResult} to handle
|
* @param teleportResult the {@link TeleportResult} to handle
|
||||||
|
* @param economyActions any economy actions to complete the transaction of
|
||||||
*/
|
*/
|
||||||
public void finishTeleport(@NotNull OnlineUser onlineUser, @NotNull TeleportResult teleportResult) {
|
public void finishTeleport(@NotNull OnlineUser onlineUser, @NotNull TeleportResult teleportResult,
|
||||||
|
@NotNull Settings.EconomyAction... economyActions) {
|
||||||
|
// Display the teleport result message
|
||||||
switch (teleportResult) {
|
switch (teleportResult) {
|
||||||
case COMPLETED_LOCALLY -> plugin.getLocales().getLocale("teleporting_complete")
|
case COMPLETED_LOCALLY -> plugin.getLocales().getLocale("teleporting_complete")
|
||||||
.ifPresent(onlineUser::sendMessage);
|
.ifPresent(onlineUser::sendMessage);
|
||||||
@@ -271,6 +283,13 @@ public class TeleportManager {
|
|||||||
case FAILED_INVALID_SERVER -> plugin.getLocales().getLocale("error_invalid_server")
|
case FAILED_INVALID_SERVER -> plugin.getLocales().getLocale("error_invalid_server")
|
||||||
.ifPresent(onlineUser::sendMessage);
|
.ifPresent(onlineUser::sendMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle economy actions
|
||||||
|
if (teleportResult.successful) {
|
||||||
|
for (final Settings.EconomyAction action : economyActions) {
|
||||||
|
plugin.performEconomyTransaction(onlineUser, action);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user