Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private ContentFilter parseContentFilter(BukkitCommandExecutionContext context)
throw new InvalidCommandArgument("No destination specified.");
}

return destinationsProvider.parseDestination(destination)
return destinationsProvider.parseDestination(context.getSender(), destination)
.getOrThrow(failure -> MVInvalidCommandArgument.of(failure.getFailureMessage()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ private void showConfigValue(MVCommandIssuer issuer, String name) {
}

private void updateConfigValue(MVCommandIssuer issuer, String name, String value) {
config.getStringPropertyHandle().setPropertyString(name, value)
var stringPropertyHandle = config.getStringPropertyHandle();
stringPropertyHandle.setPropertyString(issuer.getIssuer(), name, value)
.onSuccess(ignore -> {
config.save();
issuer.sendMessage(MVCorei18n.CONFIG_SET_SUCCESS,
Replace.NAME.with(name),
Replace.VALUE.with(value));
Replace.VALUE.with(stringPropertyHandle.getProperty(name).getOrNull()));
})
.onFailure(e -> issuer.sendMessage(MVCorei18n.CONFIG_SET_ERROR,
Replace.NAME.with(name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
}

StringPropertyHandle worldPropertyHandle = world.getStringPropertyHandle();
worldPropertyHandle.modifyPropertyString(propertyName, propertyValue, action).onSuccess(ignore -> {
worldPropertyHandle.modifyPropertyString(issuer.getIssuer(), propertyName, propertyValue, action).onSuccess(ignore -> {

Check warning on line 83 in src/main/java/org/mvplugins/multiverse/core/commands/ModifyCommand.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Line is longer than 120 characters (found 127). Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/commands/ModifyCommand.java:83:0: warning: Line is longer than 120 characters (found 127). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
issuer.sendMessage(MVCorei18n.MODIFY_SUCCESS,
replace("{action}").with(action.name().toLowerCase()),
replace("{property}").with(propertyName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.mvplugins.multiverse.core.config.node.NodeGroup;
import org.mvplugins.multiverse.core.config.node.functions.NodeStringParser;
import org.mvplugins.multiverse.core.config.node.serializer.NodeSerializer;
import org.mvplugins.multiverse.core.destination.DestinationInstance;
import org.mvplugins.multiverse.core.destination.DestinationsProvider;
import org.mvplugins.multiverse.core.dynamiclistener.EventPriorityMapper;
import org.mvplugins.multiverse.core.event.MVDebugModeEvent;
Expand Down Expand Up @@ -251,6 +252,7 @@ private <N extends Node> N node(N node) {
.defaultValue("")
.name("first-spawn-location")
.suggester(this::suggestDestinations)
.stringParser(this::parseDestinationString)
.build());

final ConfigNode<Boolean> enableJoinDestination = node(ConfigNode.builder("spawn.enable-join-destination", Boolean.class)
Expand All @@ -268,6 +270,7 @@ private <N extends Node> N node(N node) {
.defaultValue("")
.name("join-destination")
.suggester(this::suggestDestinations)
.stringParser(this::parseDestinationString)
.build());

final ConfigNode<Boolean> defaultRespawnInOverworld = node(ConfigNode.builder("spawn.default-respawn-in-overworld", Boolean.class)
Expand Down Expand Up @@ -550,6 +553,12 @@ private Collection<String> suggestDestinations(CommandSender sender, String inpu
return destinationsProvider.get().suggestDestinationStrings(sender, input);
}

private Try<String> parseDestinationString(CommandSender sender, String input, Class<String> type) {
return destinationsProvider.get().parseDestination(sender, input)
.map(DestinationInstance::toString)
.toTry();
}

private static final class DimensionFormatNodeSerializer implements NodeSerializer<DimensionFormat> {

private static final DimensionFormatNodeSerializer INSTANCE = new DimensionFormatNodeSerializer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.util.Collection;

import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jvnet.hk2.annotations.Contract;
Expand All @@ -11,20 +13,23 @@

/**
* A destination is a location that can be teleported to.
* <br />
* Please ensure you implement at least one of {@link #getDestinationInstance(CommandSender, String)} or
* {@link #getDestinationInstance(String)} to prevent a stack overflow.
*
* @param <D> The type of the destination
* @param <T> The type of the destination instance
*/
@Contract
public interface Destination<D extends Destination<D, T, F>, T extends DestinationInstance<T, D>, F extends FailureReason> {
/**
* Returns the identifier or prefix that is required for this destination.
* Returns the identifier or prefix required for this destination.
*
* <p>Portals have a prefix of "p" for example and OpenWarp (third party plugin) uses "ow". This is derived from a
* hash and cannot have duplicate values. Read that as your plugin cannot use 'p' because it's already used.
* hash and cannot have duplicate values. Means that your plugin cannot use 'p' because it's already used.
* Please check the wiki when adding a custom destination!</p>
*
* @return The identifier or prefix that is required for this destination.
* @return The identifier or prefix required for this destination.
*/
@NotNull String getIdentifier();

Expand All @@ -33,8 +38,36 @@
*
* @param destinationParams The destination parameters. ex: p:MyPortal:nw
* @return The destination instance, or null if the destination parameters are invalid.
*
* @deprecated Use {@link #getDestinationInstance(CommandSender, String)} instead. This method will no longer be
* called by {@link DestinationsProvider}.
*/
@Deprecated(forRemoval = true, since = "5.1")
@ApiStatus.ScheduledForRemoval(inVersion = "6.0")
default @NotNull Attempt<T, F> getDestinationInstance(@NotNull String destinationParams) {
return getDestinationInstance(Bukkit.getConsoleSender(), destinationParams);
}

/**
* Returns the destination instance for the given destination parameters with sender context. This allows
* for shorthands such as getting location or name from sender. If no sender context is available, use
* {@link Bukkit#getConsoleSender()} will be defaulted by {@link DestinationsProvider}.
* <br />
* Note that the resulting {@link DestinationInstance} should be (de)serializable without the original sender context.

Check warning on line 56 in src/main/java/org/mvplugins/multiverse/core/destination/Destination.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Line is longer than 120 characters (found 122). Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/destination/Destination.java:56:0: warning: Line is longer than 120 characters (found 122). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
* <br />
* For example, the parsable string with sender context `e:@here` should return a {@link DestinationInstance} that
* is serialized to `e:world:x,y,z:p:y`, which can be deserialized without the original sender context.
*
* @param sender The sender context.
* @param destinationParams The destination parameters. ex: p:MyPortal:nw
* @return The destination instance, or null if the destination parameters are invalid.
*
* @since 5.1
*/
@NotNull Attempt<T, F> getDestinationInstance(@NotNull String destinationParams);
@ApiStatus.AvailableSince("5.1")
default Attempt<T, F> getDestinationInstance(@NotNull CommandSender sender, @NotNull String destinationParams) {
return getDestinationInstance(destinationParams);
}

/**
* Returns a list of possible destinations for the given destination parameters. This packet's destination
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import co.aikar.locales.MessageKey;
import co.aikar.locales.MessageKeyProvider;
import jakarta.inject.Inject;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -51,8 +52,25 @@
* @param destinationString The destination string.
* @return The destination object, or null if invalid format.
*/
@SuppressWarnings("unchecked,rawtypes")
public @NotNull Attempt<DestinationInstance<?, ?>, FailureReason> parseDestination(@NotNull String destinationString) {
return this.parseDestination(Bukkit.getConsoleSender(), destinationString);
}

/**
* Converts a destination string to a destination object with sender context.
*
* @param sender The target sender context.
* @param destinationString The destination string.
* @return The destination object, or null if invalid format.
*
* @since 5.1
*/
@ApiStatus.AvailableSince("5.1")
@SuppressWarnings("unchecked,rawtypes")
public @NotNull Attempt<DestinationInstance<?, ?>, FailureReason> parseDestination(
@NotNull CommandSender sender,
@NotNull String destinationString
) {

Check warning on line 73 in src/main/java/org/mvplugins/multiverse/core/destination/DestinationsProvider.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 ')' should be on the previous line. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/destination/DestinationsProvider.java:73:5: warning: ')' should be on the previous line. (SeparatorWrapEol)
String[] items = destinationString.split(SEPARATOR, 2);

String idString = items[0];
Expand All @@ -74,7 +92,7 @@
replace("{ids}").with(String.join(", ", this.destinationMap.keySet())));
}

return destination.getDestinationInstance(destinationParams);
return destination.getDestinationInstance(sender, destinationParams);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
* {@inheritDoc}
*/
@Override
public @NotNull Attempt<AnchorDestinationInstance, InstanceFailureReason> getDestinationInstance(@NotNull String destinationParams) {
public @NotNull Attempt<AnchorDestinationInstance, InstanceFailureReason> getDestinationInstance(
@NotNull CommandSender sender,
@NotNull String destinationParams
) {

Check warning on line 51 in src/main/java/org/mvplugins/multiverse/core/destination/core/AnchorDestination.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 ')' should be on the previous line. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/destination/core/AnchorDestination.java:51:5: warning: ')' should be on the previous line. (SeparatorWrapEol)
return this.anchorManager.getAnchor(destinationParams)
.fold(
() -> Attempt.failure(InstanceFailureReason.ANCHOR_NOT_FOUND, replace("{anchor}").with(destinationParams)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
* {@inheritDoc}
*/
@Override
public @NotNull Attempt<BedDestinationInstance, InstanceFailureReason> getDestinationInstance(@NotNull String destinationParams) {
public @NotNull Attempt<BedDestinationInstance, InstanceFailureReason> getDestinationInstance(
@NotNull CommandSender sender,
@NotNull String destinationParams
) {

Check warning on line 51 in src/main/java/org/mvplugins/multiverse/core/destination/core/BedDestination.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 ')' should be on the previous line. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/destination/core/BedDestination.java:51:5: warning: ')' should be on the previous line. (SeparatorWrapEol)
Player player = PlayerFinder.get(destinationParams);
if (player == null && !OWN_BED_STRING.equals(destinationParams)) {
return Attempt.failure(InstanceFailureReason.PLAYER_NOT_FOUND, Replace.PLAYER.with(destinationParams));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ public final class CannonDestination implements Destination<CannonDestination, C
* {@inheritDoc}
*/
@Override
public @NotNull Attempt<CannonDestinationInstance, InstanceFailureReason> getDestinationInstance(@NotNull String destinationParams) {
public @NotNull Attempt<CannonDestinationInstance, InstanceFailureReason> getDestinationInstance(
@NotNull CommandSender sender,
@NotNull String destinationParams
) {
String[] params = REPatterns.COLON.split(destinationParams);
if (params.length != 5) {
return Attempt.failure(InstanceFailureReason.INVALID_FORMAT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

import co.aikar.locales.MessageKey;
import co.aikar.locales.MessageKeyProvider;
import com.dumptruckman.minecraft.util.Logging;
import io.vavr.control.Option;
import jakarta.inject.Inject;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jvnet.hk2.annotations.Service;
Expand Down Expand Up @@ -69,9 +69,19 @@
* {@inheritDoc}
*/
@Override
public @NotNull Attempt<ExactDestinationInstance, InstanceFailureReason> getDestinationInstance(@NotNull String destinationParams) {
public @NotNull Attempt<ExactDestinationInstance, InstanceFailureReason> getDestinationInstance(
@NotNull CommandSender sender,
@NotNull String destinationParams
) {

Check warning on line 75 in src/main/java/org/mvplugins/multiverse/core/destination/core/ExactDestination.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 ')' should be on the previous line. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/destination/core/ExactDestination.java:75:5: warning: ')' should be on the previous line. (SeparatorWrapEol)
String[] items = REPatterns.COLON.split(destinationParams);
if (items.length < 2) {
if (items[0].equals("@here")) {

Check warning on line 78 in src/main/java/org/mvplugins/multiverse/core/destination/core/ExactDestination.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 The String "@here" appears 2 times in the file. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/destination/core/ExactDestination.java:78:33: warning: The String "@here" appears 2 times in the file. (com.puppycrawl.tools.checkstyle.checks.coding.MultipleStringLiteralsCheck)
return getLocationFromSender(sender)
.map(location -> Attempt.<ExactDestinationInstance, InstanceFailureReason>success(
new ExactDestinationInstance(this, new UnloadedWorldLocation(location))
))

Check warning on line 82 in src/main/java/org/mvplugins/multiverse/core/destination/core/ExactDestination.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 ')' should be on the previous line. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/destination/core/ExactDestination.java:82:25: warning: ')' should be on the previous line. (SeparatorWrapEol)
.getOrElse(() -> Attempt.failure(InstanceFailureReason.INVALID_COORDINATES_FORMAT)); // todo: specific failure reason for this case

Check warning on line 83 in src/main/java/org/mvplugins/multiverse/core/destination/core/ExactDestination.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Line is longer than 120 characters (found 155). Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/destination/core/ExactDestination.java:83:0: warning: Line is longer than 120 characters (found 155). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
}
return Attempt.failure(InstanceFailureReason.INVALID_FORMAT);
}

Expand Down Expand Up @@ -120,6 +130,16 @@
: worldManager.getLoadedWorld(worldName);
}

private Option<Location> getLocationFromSender(CommandSender sender) {
if (sender instanceof Entity entity) {
return Option.of(entity.getLocation());
}
if (sender instanceof BlockCommandSender blockSender) {
return Option.of(blockSender.getBlock().getLocation());
}
return Option.none();
}

/**
* {@inheritDoc}
*/
Expand All @@ -132,30 +152,37 @@
.isSuccess())
.map(world ->
new DestinationSuggestionPacket(this, world.getTabCompleteName() + ":", world.getName()));
if (sender instanceof Player player) {
var playerLocation = new DestinationSuggestionPacket(

Location location = getLocationFromSender(sender).getOrNull();
if (location != null) {
var herePacket = new DestinationSuggestionPacket(
this,
"@here",
location.getWorld().getName()
);
var locationPacket = new DestinationSuggestionPacket(
this,
"%s:%.2f,%.2f,%.2f".formatted(
player.getWorld().getName(),
player.getLocation().getX(),
player.getLocation().getY(),
player.getLocation().getZ()
location.getWorld().getName(),
location.getX(),
location.getY(),
location.getZ()
),
player.getWorld().getName()
location.getWorld().getName()
);
var playerLocationPW = new DestinationSuggestionPacket(
var locationPacketPW = new DestinationSuggestionPacket(
this,
"%s:%.2f,%.2f,%.2f:%.2f:%.2f".formatted(
player.getWorld().getName(),
player.getLocation().getX(),
player.getLocation().getY(),
player.getLocation().getZ(),
player.getLocation().getPitch(),
player.getLocation().getYaw()
location.getWorld().getName(),
location.getX(),
location.getY(),
location.getZ(),
location.getPitch(),
location.getYaw()
),
player.getWorld().getName()
location.getWorld().getName()
);
stream = Stream.concat(stream, Stream.of(playerLocation, playerLocationPW));
stream = Stream.concat(stream, Stream.of(herePacket, locationPacket, locationPacketPW));
}
return stream.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public final class PlayerDestination implements Destination<PlayerDestination, P
* {@inheritDoc}
*/
@Override
public @NotNull Attempt<PlayerDestinationInstance, InstanceFailureReason> getDestinationInstance(@NotNull String destinationParams) {
public @NotNull Attempt<PlayerDestinationInstance, InstanceFailureReason> getDestinationInstance(
@NotNull CommandSender sender,
@NotNull String destinationParams
) {
Player player = PlayerFinder.get(destinationParams);
if (player == null) {
return Attempt.failure(InstanceFailureReason.PLAYER_NOT_FOUND, Replace.PLAYER.with(destinationParams));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ public final class WorldDestination implements Destination<WorldDestination, Wor
* {@inheritDoc}
*/
@Override
public @NotNull Attempt<WorldDestinationInstance, InstanceFailureReason> getDestinationInstance(@NotNull String destinationParams) {
public @NotNull Attempt<WorldDestinationInstance, InstanceFailureReason> getDestinationInstance(
@NotNull CommandSender sender,
@NotNull String destinationParams
) {
String[] items = REPatterns.COLON.split(destinationParams, 3);
String worldName = items[0];
MultiverseWorld world = getMultiverseWorld(worldName);
Expand Down
Loading
Loading