mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 22:17:17 +00:00
Refactor player location and server name fetching, prune unused locales
This commit is contained in:
1 parent
571f35429d
commit
7e3dab918f
23 files changed
+151
-200
No files matched your search
@@ -164,8 +164,8 @@ public class EditHomeCommand extends CommandBase implements TabCompletable, Cons
|
||||
default -> Optional.of(new MineDown(""));
|
||||
}).ifPresent(editor::sendMessage));
|
||||
}
|
||||
case "relocate" -> editor.getPosition().thenAccept(position ->
|
||||
plugin.getSavedPositionManager().updateHomePosition(home, position).thenRun(() -> {
|
||||
case "relocate" ->
|
||||
plugin.getSavedPositionManager().updateHomePosition(home, editor.getPosition()).thenRun(() -> {
|
||||
if (home.owner.uuid.equals(editor.uuid)) {
|
||||
editor.sendMessage(plugin.getLocales().getLocale("edit_home_update_location",
|
||||
home.meta.name).orElse(new MineDown("")));
|
||||
@@ -181,7 +181,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable, Cons
|
||||
editor.hasPermission(Permission.COMMAND_EDIT_HOME_PRIVACY.node))
|
||||
.forEach(editor::sendMessage);
|
||||
}
|
||||
}));
|
||||
});
|
||||
case "privacy" -> {
|
||||
boolean newIsPublic = !home.isPublic;
|
||||
if (editArgs != null && !editArgs.isBlank()) {
|
||||
|
||||
@@ -114,8 +114,8 @@ public class EditWarpCommand extends CommandBase implements TabCompletable, Cons
|
||||
default -> Optional.of(new MineDown(""));
|
||||
}).ifPresent(editor::sendMessage));
|
||||
}
|
||||
case "relocate" -> editor.getPosition().thenAccept(position ->
|
||||
plugin.getSavedPositionManager().updateWarpPosition(warp, position).thenRun(() -> {
|
||||
case "relocate" ->
|
||||
plugin.getSavedPositionManager().updateWarpPosition(warp, editor.getPosition()).thenRun(() -> {
|
||||
editor.sendMessage(plugin.getLocales().getLocale("edit_warp_update_location",
|
||||
warp.meta.name).orElse(new MineDown("")));
|
||||
|
||||
@@ -124,7 +124,7 @@ public class EditWarpCommand extends CommandBase implements TabCompletable, Cons
|
||||
getWarpEditorWindow(warp, false, editor.hasPermission(Permission.COMMAND_WARP.node))
|
||||
.forEach(editor::sendMessage);
|
||||
}
|
||||
}));
|
||||
});
|
||||
default -> plugin.getLocales().getLocale("error_invalid_syntax",
|
||||
"/editwarp <name> [" + String.join("|", EDIT_WARP_COMPLETIONS) + "] [args]")
|
||||
.ifPresent(editor::sendMessage);
|
||||
|
||||
@@ -58,7 +58,12 @@ public class HomeListCommand extends CommandBase implements ConsoleExecutable {
|
||||
}
|
||||
plugin.getDatabase().getHomes(userData.user()).thenAccept(homes -> {
|
||||
if (homes.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_no_homes_set").ifPresent(onlineUser::sendMessage);
|
||||
if (!onlineUser.uuid.equals(userData.user().uuid)) {
|
||||
plugin.getLocales().getLocale("error_no_homes_set_other",
|
||||
userData.user().username).ifPresent(onlineUser::sendMessage);
|
||||
} else {
|
||||
plugin.getLocales().getLocale("error_no_homes_set").ifPresent(onlineUser::sendMessage);
|
||||
}
|
||||
return;
|
||||
}
|
||||
onlineUser.sendMessage(plugin.getCache().getHomeList(onlineUser, userData.user(),
|
||||
|
||||
@@ -39,7 +39,7 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
final Position userPosition = target.getPosition().join();
|
||||
final Position userPosition = target.getPosition();
|
||||
if (plugin.getSettings().rtpRestrictedWorlds.stream()
|
||||
.anyMatch(worldName -> worldName.equals(userPosition.world.name))) {
|
||||
plugin.getLocales().getLocale("error_rtp_restricted_world")
|
||||
|
||||
@@ -85,7 +85,7 @@ public class SetHomeCommand extends CommandBase {
|
||||
|
||||
// Set the home in the saved position manager
|
||||
final SavedPositionManager.SaveResult setResult = plugin.getSavedPositionManager()
|
||||
.setHome(new PositionMeta(homeName, ""), onlineUser, onlineUser.getPosition().join()).join();
|
||||
.setHome(new PositionMeta(homeName, ""), onlineUser, onlineUser.getPosition()).join();
|
||||
|
||||
// Display feedback of the result of the set operation
|
||||
(switch (setResult.resultType()) {
|
||||
|
||||
@@ -2,12 +2,14 @@ package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.player.OnlineUser;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.position.PositionMeta;
|
||||
import net.william278.huskhomes.position.Warp;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class SetSpawnCommand extends CommandBase {
|
||||
|
||||
@@ -23,7 +25,8 @@ public class SetSpawnCommand extends CommandBase {
|
||||
return;
|
||||
}
|
||||
|
||||
onlineUser.getPosition().thenAccept(position -> {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
final Position position = onlineUser.getPosition();
|
||||
if (plugin.getSettings().crossServer && plugin.getSettings().globalSpawn) {
|
||||
final Optional<Warp> warp = plugin.getDatabase().getWarp(plugin.getSettings().globalSpawnName).join();
|
||||
if (warp.isPresent()) {
|
||||
|
||||
@@ -26,8 +26,8 @@ public class SetWarpCommand extends CommandBase {
|
||||
}
|
||||
|
||||
private void setWarp(@NotNull OnlineUser onlineUser, @NotNull String warpName) {
|
||||
onlineUser.getPosition().thenAccept(position -> plugin.getSavedPositionManager().setWarp(
|
||||
new PositionMeta(warpName, ""), position).thenAccept(setResult ->
|
||||
plugin.getSavedPositionManager().setWarp(
|
||||
new PositionMeta(warpName, ""), onlineUser.getPosition()).thenAccept(setResult ->
|
||||
(switch (setResult.resultType()) {
|
||||
case SUCCESS -> {
|
||||
assert setResult.savedPosition().isPresent();
|
||||
@@ -38,7 +38,7 @@ public class SetWarpCommand extends CommandBase {
|
||||
case FAILED_NAME_LENGTH -> plugin.getLocales().getLocale("error_warp_name_length");
|
||||
case FAILED_NAME_CHARACTERS -> plugin.getLocales().getLocale("error_warp_name_characters");
|
||||
default -> Optional.of(new MineDown(""));
|
||||
}).ifPresent(onlineUser::sendMessage)));
|
||||
}).ifPresent(onlineUser::sendMessage));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public class SpawnCommand extends CommandBase {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
final Optional<? extends Position> position = (plugin.getSettings().crossServer && plugin.getSettings().globalSpawn
|
||||
? plugin.getDatabase().getWarp(plugin.getSettings().globalSpawnName).join()
|
||||
: plugin.getServerSpawn().flatMap(spawn -> spawn.getLocation(plugin.getServer(onlineUser).join())));
|
||||
: plugin.getServerSpawn().flatMap(spawn -> spawn.getLocation(plugin.getServer(onlineUser))));
|
||||
if (position.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_spawn_not_set").ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
|
||||
@@ -12,7 +12,6 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class TpCommand extends CommandBase implements TabCompletable, ConsoleExecutable {
|
||||
|
||||
@@ -54,11 +53,12 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
|
||||
}
|
||||
|
||||
// Parse the coordinates and set the target position
|
||||
final Position userPosition = onlineUser.getPosition().join();
|
||||
final Position userPosition = onlineUser.getPosition();
|
||||
final Optional<Position> parsedPosition = Position.parse(userPosition,
|
||||
Arrays.copyOfRange(args, coordinatesIndex, args.length));
|
||||
if (parsedPosition.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_invalid_syntax", "/tp <target> <x> <y> <z> [world] [server]")
|
||||
plugin.getLocales().getLocale("error_invalid_syntax",
|
||||
"/tp <target> <x> <y> <z> [world] [server]")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
@@ -71,12 +71,12 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
|
||||
if (targetPosition.targetType == TeleportCommandTarget.TargetType.PLAYER) {
|
||||
// Teleport players by usernames
|
||||
assert targetPosition.targetPlayer != null;
|
||||
CompletableFuture.runAsync(() -> plugin.getTeleportManager()
|
||||
plugin.getTeleportManager()
|
||||
.teleportPlayerToPlayerByName(playerToTeleportName, targetPosition.targetPlayer, onlineUser)
|
||||
.thenAccept(resultIfPlayerExists -> resultIfPlayerExists.ifPresentOrElse(
|
||||
result -> plugin.getTeleportManager().finishTeleport(onlineUser, result),
|
||||
() -> plugin.getLocales().getLocale("error_player_not_found", playerToTeleportName)
|
||||
.ifPresent(onlineUser::sendMessage))));
|
||||
.ifPresent(onlineUser::sendMessage)));
|
||||
return;
|
||||
} else if (targetPosition.targetType == TeleportCommandTarget.TargetType.POSITION) {
|
||||
// Teleport players by specified position
|
||||
|
||||
@@ -22,7 +22,7 @@ public class TpHereCommand extends CommandBase implements TabCompletable {
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
plugin.getTeleportManager().teleportPlayerByName(args[0], onlineUser.getPosition().join(), onlineUser);
|
||||
plugin.getTeleportManager().teleportPlayerByName(args[0], onlineUser.getPosition(), onlineUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user