mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
Fix various issues
This commit is contained in:
35 files changed
+236
-243
No files matched your search
@@ -55,15 +55,7 @@ public class Cache {
|
||||
.filter(player -> !player.isVanished())
|
||||
.map(User::getUsername)
|
||||
.toList());
|
||||
//todo
|
||||
// if (plugin.getSettings().isCrossServer()) {
|
||||
// return plugin.getMessenger()
|
||||
// .getOnlinePlayerNames(requester)
|
||||
// .thenApply(networkedPlayers -> {
|
||||
// getPlayers().addAll(Set.of(networkedPlayers));
|
||||
// return getPlayers();
|
||||
// });
|
||||
// }
|
||||
|
||||
return CompletableFuture.completedFuture(getPlayers());
|
||||
}
|
||||
|
||||
|
||||
@@ -325,7 +325,7 @@ public interface HuskHomes extends TaskRunner, EventDispatcher {
|
||||
|
||||
default <T extends Command> Optional<T> getCommand(@NotNull Class<T> type) {
|
||||
return getCommands().stream()
|
||||
.filter(command -> command.getClass().isInstance(type))
|
||||
.filter(command -> command.getClass() == type)
|
||||
.findFirst()
|
||||
.map(type::cast);
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ public class EditHomeCommand extends SavedPositionCommand<Home> {
|
||||
}
|
||||
|
||||
private void setHomeDescription(@NotNull CommandUser executor, @NotNull Home home, boolean ownerEditing, @NotNull String[] args) {
|
||||
final String oldDescription = home.getMeta().getDescription();
|
||||
final Optional<String> optionalDescription = parseGreedyString(args, 1);
|
||||
if (optionalDescription.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_invalid_syntax",
|
||||
@@ -106,11 +107,11 @@ public class EditHomeCommand extends SavedPositionCommand<Home> {
|
||||
}
|
||||
|
||||
if (ownerEditing) {
|
||||
plugin.getLocales().getLocale("edit_home_update_description", home.getName(), newDescription)
|
||||
plugin.getLocales().getLocale("edit_home_update_description", home.getName(), oldDescription, newDescription)
|
||||
.ifPresent(executor::sendMessage);
|
||||
} else {
|
||||
plugin.getLocales().getLocale("edit_home_update_description_other", home.getOwner().getUsername(),
|
||||
home.getName(), newDescription)
|
||||
home.getName(), oldDescription, newDescription)
|
||||
.ifPresent(executor::sendMessage);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -64,7 +64,7 @@ public class RtpCommand extends Command {
|
||||
.orElseThrow(() -> new IllegalStateException("No user data found for " + teleporter.getUsername()));
|
||||
final Instant currentTime = Instant.now();
|
||||
if (executor.equals(teleporter) && !currentTime.isAfter(user.getRtpCooldown()) &&
|
||||
!executor.hasPermission(getPermission("bypass_cooldown"))) {
|
||||
!executor.hasPermission(getPermission("bypass_cooldown"))) {
|
||||
plugin.getLocales().getLocale("error_rtp_cooldown",
|
||||
Long.toString(currentTime.until(user.getRtpCooldown(), ChronoUnit.MINUTES) + 1))
|
||||
.ifPresent(executor::sendMessage);
|
||||
@@ -74,7 +74,7 @@ public class RtpCommand extends Command {
|
||||
plugin.getLocales().getLocale("teleporting_random_generation")
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
final Optional<Position> position = plugin.getRandomTeleportEngine()
|
||||
.getRandomPosition(teleporter.getPosition().getWorld(), removeFirstArg(args));
|
||||
.getRandomPosition(teleporter.getPosition().getWorld(), args.length > 1 ? removeFirstArg(args) : args);
|
||||
if (position.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_rtp_randomization_timeout")
|
||||
.ifPresent(executor::sendMessage);
|
||||
|
||||
@@ -31,7 +31,10 @@ public class SetHomeCommand extends SetPositionCommand {
|
||||
plugin.getManager().homes().createHome(setter, event.getName(), event.getPosition());
|
||||
} catch (ValidationException e) {
|
||||
e.dispatchHomeError(setter, false, plugin, event.getName());
|
||||
return;
|
||||
}
|
||||
plugin.getLocales().getLocale("set_home_success", event.getName())
|
||||
.ifPresent(setter::sendMessage);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,10 @@ public class SetWarpCommand extends SetPositionCommand {
|
||||
plugin.getManager().warps().createWarp(event.getName(), event.getPosition());
|
||||
} catch (ValidationException e) {
|
||||
e.dispatchWarpError(setter, plugin, event.getName());
|
||||
return;
|
||||
}
|
||||
plugin.getLocales().getLocale("set_warp_success", event.getName())
|
||||
.ifPresent(setter::sendMessage);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public class TpaAllCommand extends InGameCommand {
|
||||
}
|
||||
|
||||
plugin.getManager().requests().sendTeleportAllRequest(executor);
|
||||
plugin.getLocales().getLocale("teleporting_all_players")
|
||||
plugin.getLocales().getLocale("tpaall_request_sent")
|
||||
.ifPresent(executor::sendMessage);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.position.Warp;
|
||||
import net.william278.huskhomes.teleport.Teleportable;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
@@ -15,6 +16,16 @@ public class WarpCommand extends SavedPositionCommand<Warp> {
|
||||
super("warp", List.of(), Warp.class, List.of(), plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(@NotNull CommandUser executor, @NotNull String[] args) {
|
||||
if (args.length == 0) {
|
||||
plugin.getCommand(WarpListCommand.class)
|
||||
.ifPresent(command -> command.showWarpList(executor, 1));
|
||||
return;
|
||||
}
|
||||
super.execute(executor, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(@NotNull CommandUser executor, @NotNull Warp warp, @NotNull String[] args) {
|
||||
if (plugin.getSettings().isPermissionRestrictWarps()) {
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.stream.Collectors;
|
||||
public class WarpListCommand extends ListCommand {
|
||||
|
||||
protected WarpListCommand(@NotNull HuskHomes plugin) {
|
||||
super("homelist", List.of("homes"), "[player] [page]", plugin);
|
||||
super("warplist", List.of("warps"), "[player] [page]", plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -41,6 +41,9 @@ public class Locales {
|
||||
* @return An {@link Optional} containing the locale corresponding to the id, if it exists
|
||||
*/
|
||||
public Optional<String> getRawLocale(@NotNull String localeId) {
|
||||
if (!rawLocales.containsKey(localeId)) { // debug
|
||||
return Optional.of(localeId + " (missing locale)"); // debug
|
||||
} // debug
|
||||
return Optional.ofNullable(rawLocales.get(localeId)).map(StringEscapeUtils::unescapeJava);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.william278.huskhomes.config;
|
||||
import net.william278.annotaml.YamlComment;
|
||||
import net.william278.annotaml.YamlFile;
|
||||
import net.william278.annotaml.YamlKey;
|
||||
import net.william278.huskhomes.command.Command;
|
||||
import net.william278.huskhomes.database.Database;
|
||||
import net.william278.huskhomes.hook.EconomyHook;
|
||||
import net.william278.huskhomes.hook.MapHook;
|
||||
@@ -490,8 +491,12 @@ public class Settings {
|
||||
return warpsOnMap;
|
||||
}
|
||||
|
||||
public List<String> getDisabledCommands() {
|
||||
return disabledCommands;
|
||||
public boolean isCommandDisabled(Command type) {
|
||||
return disabledCommands.stream().anyMatch(disabled -> {
|
||||
final String command = (disabled.startsWith("/") ? disabled.substring(1) : disabled);
|
||||
return command.equalsIgnoreCase(type.getName())
|
||||
|| type.getAliases().stream().anyMatch(alias -> alias.equalsIgnoreCase(command));
|
||||
});
|
||||
}
|
||||
|
||||
public boolean doBrigadierTabCompletion() {
|
||||
|
||||
@@ -63,28 +63,30 @@ public class EventListener {
|
||||
/**
|
||||
* Handle inbound cross-server teleports
|
||||
*
|
||||
* @param onlineUser user to handle the checks for
|
||||
* @param teleporter user to handle the checks for
|
||||
*/
|
||||
private void handleInboundTeleport(@NotNull OnlineUser onlineUser) {
|
||||
plugin.getDatabase().getCurrentTeleport(onlineUser).ifPresent(teleport -> {
|
||||
private void handleInboundTeleport(@NotNull OnlineUser teleporter) {
|
||||
plugin.getDatabase().getCurrentTeleport(teleporter).ifPresent(teleport -> {
|
||||
if (teleport.getType() == Teleport.Type.RESPAWN) {
|
||||
final Optional<Position> bedPosition = onlineUser.getBedSpawnPosition();
|
||||
final Optional<Position> bedPosition = teleporter.getBedSpawnPosition();
|
||||
if (bedPosition.isEmpty()) {
|
||||
plugin.getLocalCachedSpawn()
|
||||
.map(spawn -> spawn.getPosition(plugin.getServerName()))
|
||||
.ifPresent(position -> onlineUser.teleportLocally(position,
|
||||
.ifPresent(position -> teleporter.teleportLocally(position,
|
||||
plugin.getSettings().isAsynchronousTeleports()));
|
||||
onlineUser.sendTranslatableMessage("block.minecraft.spawn.not_valid");
|
||||
teleporter.sendTranslatableMessage("block.minecraft.spawn.not_valid");
|
||||
} else {
|
||||
onlineUser.teleportLocally(bedPosition.get(), plugin.getSettings().isAsynchronousTeleports());
|
||||
teleporter.teleportLocally(bedPosition.get(), plugin.getSettings().isAsynchronousTeleports());
|
||||
}
|
||||
plugin.getDatabase().setCurrentTeleport(onlineUser, null);
|
||||
plugin.getDatabase().setRespawnPosition(onlineUser, bedPosition.orElse(null));
|
||||
plugin.getDatabase().setCurrentTeleport(teleporter, null);
|
||||
plugin.getDatabase().setRespawnPosition(teleporter, bedPosition.orElse(null));
|
||||
return;
|
||||
}
|
||||
|
||||
onlineUser.teleportLocally((Position) teleport.getTarget(), plugin.getSettings().isAsynchronousTeleports());
|
||||
plugin.getDatabase().setCurrentTeleport(onlineUser, null);
|
||||
teleporter.teleportLocally((Position) teleport.getTarget(), plugin.getSettings().isAsynchronousTeleports());
|
||||
plugin.getDatabase().setCurrentTeleport(teleporter, null);
|
||||
plugin.getLocales().getLocale("teleporting_complete")
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -97,14 +99,6 @@ public class EventListener {
|
||||
// Remove this user's home cache
|
||||
plugin.getCache().getHomes().remove(onlineUser.getUsername());
|
||||
|
||||
// Update the cached player list using another online player if possible
|
||||
plugin.getOnlineUsers()
|
||||
.stream()
|
||||
.filter(onlinePlayer -> !onlinePlayer.equals(onlineUser))
|
||||
.findAny()
|
||||
.ifPresent(updater -> plugin.getCache().updatePlayerListCache(plugin, updater));
|
||||
|
||||
|
||||
// Set offline position
|
||||
plugin.getDatabase().setOfflinePosition(onlineUser, onlineUser.getPosition());
|
||||
}
|
||||
|
||||
@@ -163,6 +163,7 @@ public class RequestsManager {
|
||||
.payload(Payload.withTeleportRequest(request))
|
||||
.target(targetUser)
|
||||
.build().send(plugin.getMessenger(), requester);
|
||||
return;
|
||||
}
|
||||
throw new IllegalArgumentException("Player not found");
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public abstract class Broker {
|
||||
*
|
||||
* @throws RuntimeException if the broker fails to initialize
|
||||
*/
|
||||
public abstract void initialize() throws RuntimeException;
|
||||
public abstract void initialize() throws IllegalStateException;
|
||||
|
||||
/**
|
||||
* Send a message to the broker
|
||||
|
||||
@@ -32,7 +32,7 @@ public class PluginMessageBroker extends Broker {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() throws RuntimeException {
|
||||
public void initialize() throws IllegalStateException {
|
||||
plugin.initializePluginChannels();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public class RedisBroker extends PluginMessageBroker {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() throws RuntimeException {
|
||||
public void initialize() throws IllegalStateException {
|
||||
super.initialize();
|
||||
|
||||
final String password = plugin.getSettings().getRedisPassword();
|
||||
@@ -51,7 +51,7 @@ public class RedisBroker extends PluginMessageBroker {
|
||||
final Message message = plugin.getGson().fromJson(encodedMessage, Message.class);
|
||||
plugin.getOnlineUsers().stream()
|
||||
.filter(online -> message.getTarget().equals(Message.TARGET_ALL)
|
||||
|| online.getUsername().equals(message.getTarget()))
|
||||
|| online.getUsername().equals(message.getTarget()))
|
||||
.forEach(receiver -> handle(receiver, message));
|
||||
}
|
||||
}, getSubChannelId());
|
||||
|
||||
@@ -13,10 +13,8 @@ public class Home extends SavedPosition {
|
||||
private final User owner;
|
||||
private boolean isPublic;
|
||||
|
||||
public Home(double x, double y, double z, float yaw, float pitch,
|
||||
@NotNull World world, @NotNull String server,
|
||||
@NotNull PositionMeta positionMeta, @NotNull UUID uuid,
|
||||
@NotNull User owner, boolean isPublic) {
|
||||
public Home(double x, double y, double z, float yaw, float pitch, @NotNull World world, @NotNull String server,
|
||||
@NotNull PositionMeta positionMeta, @NotNull UUID uuid, @NotNull User owner, boolean isPublic) {
|
||||
super(x, y, z, yaw, pitch, world, server, positionMeta, uuid);
|
||||
this.owner = owner;
|
||||
this.setPublic(isPublic);
|
||||
|
||||
@@ -19,6 +19,7 @@ public class Server {
|
||||
/**
|
||||
* Default server identifier
|
||||
*/
|
||||
@NotNull
|
||||
public static String getDefaultServerName() {
|
||||
try {
|
||||
final Path serverDirectory = Path.of(System.getProperty("user.dir"));
|
||||
|
||||
@@ -85,6 +85,8 @@ public class Teleport {
|
||||
fireEvent((event) -> {
|
||||
executeEconomyActions();
|
||||
teleporter.teleportLocally(localTarget.get().getPosition(), async);
|
||||
plugin.getLocales().getLocale("teleporting_complete")
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -96,6 +98,8 @@ public class Teleport {
|
||||
.type(Message.Type.TELEPORT_TO_NETWORKED_POSITION)
|
||||
.target(username.name())
|
||||
.build().send(plugin.getMessenger(), executor);
|
||||
plugin.getLocales().getLocale("teleporting_complete")
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -105,10 +109,24 @@ public class Teleport {
|
||||
|
||||
fireEvent((event) -> {
|
||||
executeEconomyActions();
|
||||
teleporter.teleportLocally((Position) target, async);
|
||||
|
||||
final Position target = (Position) this.target;
|
||||
if (plugin.getSettings().isCrossServer() && target.getServer().equals(plugin.getServerName())) {
|
||||
teleporter.teleportLocally(target, async);
|
||||
plugin.getLocales().getLocale("teleporting_complete")
|
||||
.ifPresent(teleporter::sendMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getDatabase().setCurrentTeleport(teleporter, this);
|
||||
plugin.getMessenger().changeServer(teleporter, target.getServer());
|
||||
});
|
||||
}
|
||||
|
||||
private void teleport(@NotNull OnlineUser teleporter, @NotNull Position target) {
|
||||
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Optional<OnlineUser> resolveLocalTeleporter() throws TeleportationException {
|
||||
if (this.teleporter instanceof Username username) {
|
||||
|
||||
@@ -16,6 +16,8 @@ public class TeleportationException extends IllegalArgumentException {
|
||||
ALREADY_WARMING_UP,
|
||||
ECONOMY_ACTION_FAILED,
|
||||
WARMUP_ALREADY_MOVING,
|
||||
WORLD_NOT_FOUND,
|
||||
ILLEGAL_TARGET_COORDINATES,
|
||||
CANNOT_TELEPORT_TO_SELF
|
||||
}
|
||||
|
||||
@@ -33,6 +35,12 @@ public class TeleportationException extends IllegalArgumentException {
|
||||
case CANNOT_TELEPORT_TO_SELF -> plugin.getLocales()
|
||||
.getLocale("error_teleport_request_self")
|
||||
.ifPresent(user::sendMessage);
|
||||
case ILLEGAL_TARGET_COORDINATES -> plugin.getLocales()
|
||||
.getLocale("error_illegal_target_coordinates")
|
||||
.ifPresent(user::sendMessage);
|
||||
case WORLD_NOT_FOUND -> plugin.getLocales()
|
||||
.getLocale("error_invalid_world")
|
||||
.ifPresent(user::sendMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,7 +142,7 @@ public abstract class OnlineUser extends User implements Teleportable, CommandUs
|
||||
* @param location the {@link Location} to teleport the player to
|
||||
* @param asynchronous if the teleport should be asynchronous
|
||||
*/
|
||||
public abstract CompletableFuture<TeleportResult> teleportLocally(@NotNull Location location, boolean asynchronous);
|
||||
public abstract void teleportLocally(@NotNull Location location, boolean asynchronous);
|
||||
|
||||
/**
|
||||
* Send a plugin message to the user
|
||||
|
||||
Reference in new issue
Block a user