mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
Update locales, add tpall check for no online players
This commit is contained in:
1 parent
33fdab44f2
commit
e8e9b1ffb9
15 files changed
+36
-143
No files matched your search
@@ -20,6 +20,12 @@ public class TpAllCommand extends InGameCommand {
|
||||
|
||||
@Override
|
||||
public void execute(@NotNull OnlineUser executor, @NotNull String[] args) {
|
||||
if (plugin.getGlobalPlayerList().size() <= 1) {
|
||||
plugin.getLocales().getLocale("error_no_players_online")
|
||||
.ifPresent(executor::sendMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
final Position targetPosition = executor.getPosition();
|
||||
try {
|
||||
for (OnlineUser user : plugin.getOnlineUsers()) {
|
||||
|
||||
@@ -65,6 +65,7 @@ public class TpCommand extends Command implements TabProvider {
|
||||
// Execute a teleport
|
||||
private void execute(@NotNull CommandUser executor, @NotNull Teleportable teleportable, @NotNull Target target,
|
||||
@NotNull String[] args) {
|
||||
// Build and execute the teleport
|
||||
final TeleportBuilder builder = Teleport.builder(plugin)
|
||||
.teleporter(teleportable)
|
||||
.target(target);
|
||||
@@ -75,6 +76,20 @@ public class TpCommand extends Command implements TabProvider {
|
||||
builder.toTeleport().execute();
|
||||
} catch (TeleportationException e) {
|
||||
e.displayMessage(executor, plugin, args);
|
||||
return;
|
||||
}
|
||||
|
||||
// Display teleport completion message
|
||||
final String teleporterName = teleportable instanceof OnlineUser user
|
||||
? user.getUsername() : ((Username) teleportable).name();
|
||||
if (target instanceof Position position) {
|
||||
plugin.getLocales().getLocale("teleporting_other_complete_position", teleporterName,
|
||||
Integer.toString((int) position.getX()), Integer.toString((int) position.getY()),
|
||||
Integer.toString((int) position.getZ()))
|
||||
.ifPresent(executor::sendMessage);
|
||||
} else {
|
||||
plugin.getLocales().getLocale("teleporting_other_complete", teleporterName, ((Username) target).name())
|
||||
.ifPresent(executor::sendMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,9 @@ public class TpHereCommand extends InGameCommand implements UserListTabProvider
|
||||
.teleporter(optionalTarget.get())
|
||||
.target(executor.getPosition())
|
||||
.toTeleport().execute();
|
||||
|
||||
plugin.getLocales().getLocale("teleporting_other_complete",
|
||||
optionalTarget.get(), executor.getUsername());
|
||||
} catch (TeleportationException e) {
|
||||
e.displayMessage(executor, plugin, args);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,12 @@ public class TpaAllCommand extends InGameCommand {
|
||||
|
||||
@Override
|
||||
public void execute(@NotNull OnlineUser executor, @NotNull String[] args) {
|
||||
if (plugin.getGlobalPlayerList().size() <= 1) {
|
||||
plugin.getLocales().getLocale("error_no_players_online")
|
||||
.ifPresent(executor::sendMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.getManager().requests().isIgnoringRequests(executor)) {
|
||||
plugin.getLocales().getLocale("error_ignoring_teleport_requests")
|
||||
.ifPresent(executor::sendMessage);
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
package net.william278.huskhomes.teleport;
|
||||
|
||||
import net.william278.huskhomes.config.Locales;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.position.World;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Represents the state of a {@link Teleport} after it has finished executing
|
||||
*/
|
||||
public enum TeleportResult {
|
||||
|
||||
/**
|
||||
* Returns if the {@link Teleport} was completed locally, successfully
|
||||
*/
|
||||
COMPLETED_LOCALLY(true, "teleporting_complete"),
|
||||
|
||||
/**
|
||||
* Returns if the {@link Teleport} was completed cross-server
|
||||
*/
|
||||
COMPLETED_CROSS_SERVER(true),
|
||||
|
||||
/**
|
||||
* Returns if the {@link Teleport} failed because the user is already teleporting
|
||||
*/
|
||||
FAILED_ALREADY_TELEPORTING(false, "error_already_teleporting"),
|
||||
|
||||
/**
|
||||
* Returns if the {@link TimedTeleport} warmup could not be started because they were moving
|
||||
*/
|
||||
FAILED_MOVING(false, "error_teleport_warmup_stand_still"),
|
||||
|
||||
/**
|
||||
* Returns if the {@link Teleport} failed because the {@link World} of the
|
||||
* target {@link Position} could not be found
|
||||
*/
|
||||
FAILED_INVALID_WORLD(false, "error_invalid_world"),
|
||||
|
||||
/**
|
||||
* Returns if the {@link Teleport} failed because the server of the target
|
||||
* {@link Position} was invalid or not online
|
||||
*/
|
||||
FAILED_INVALID_SERVER(false, "error_invalid_server"),
|
||||
|
||||
/**
|
||||
* Returns if the {@link Teleport} failed because the coordinates of the
|
||||
* target {@link Position} were outside the world border limits
|
||||
*/
|
||||
FAILED_ILLEGAL_COORDINATES(false, "error_illegal_target_coordinates"),
|
||||
|
||||
/**
|
||||
* Returns if the {@link Teleport} failed because the teleporter could not be resolved or was offline
|
||||
*/
|
||||
FAILED_TELEPORTER_NOT_RESOLVED(false, "error_teleport_target_not_resolved"),
|
||||
|
||||
/**
|
||||
* Returns if the {@link Teleport} failed because the target {@link Position} could not be resolved
|
||||
*/
|
||||
FAILED_TARGET_NOT_RESOLVED(false, "error_teleport_teleporter_not_resolved"),
|
||||
|
||||
/**
|
||||
* Returns if the teleport was cancelled, for example if a {@link TimedTeleport} in progress is cancelled
|
||||
*/
|
||||
CANCELLED(false),
|
||||
|
||||
/**
|
||||
* Returns if the {@link Teleport} was cancelled due to failing economy checks
|
||||
*/
|
||||
CANCELLED_ECONOMY(false);
|
||||
|
||||
/**
|
||||
* Is {@code true} if the teleport was a success
|
||||
*/
|
||||
public final boolean successful;
|
||||
|
||||
/**
|
||||
* The {@link Locales} key to use when sending a message to the teleporter
|
||||
*/
|
||||
@Nullable
|
||||
private final String messageId;
|
||||
|
||||
TeleportResult(boolean successful, @NotNull String messageId) {
|
||||
this.successful = successful;
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
TeleportResult(boolean successful) {
|
||||
this.successful = successful;
|
||||
this.messageId = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an {@link OnlineUser} the corresponding message for this {@link TeleportResult}, if there is one
|
||||
*
|
||||
* @param locales the {@link Locales} instance to use
|
||||
* @param user the {@link OnlineUser} to send the message to
|
||||
* @since 3.1
|
||||
*/
|
||||
public void sendResultMessage(@NotNull Locales locales, @NotNull OnlineUser user) {
|
||||
Optional.ofNullable(messageId).flatMap(locales::getLocale).ifPresent(user::sendMessage);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user