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 @@ -105,7 +105,7 @@ private void teleportSinglePlayer(MVCommandIssuer issuer, Player player,
.teleportSingle(player)
.onSuccess(() -> issuer.sendInfo(MVCorei18n.TELEPORT_SUCCESS,
Replace.PLAYER.with(getYouOrName(issuer, player)),
Replace.DESTINATION.with(destination.toString())))
Replace.DESTINATION.with(destination.getDisplayMessage())))
.onFailureCount(reasonsCountMap -> {
for (var entry : reasonsCountMap.entrySet()) {
Logging.finer("Failed to teleport %s players to %s: %s",
Expand Down Expand Up @@ -138,7 +138,7 @@ private void teleportMultiplePlayers(MVCommandIssuer issuer, Player[] players,
.teleport(List.of(players))
.onSuccessCount(successCount -> issuer.sendInfo(MVCorei18n.TELEPORT_SUCCESS,
Replace.PLAYER.with(successCount + " players"),
Replace.DESTINATION.with(destination.toString())))
Replace.DESTINATION.with(destination.getDisplayMessage())))
.onFailureCount(reasonsCountMap -> {
for (var entry : reasonsCountMap.entrySet()) {
Logging.finer("Failed to teleport %s players to %s: %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.mvplugins.multiverse.core.utils.result.FailureReason;
import org.mvplugins.multiverse.core.locale.message.Message;

Check warning on line 9 in src/main/java/org/mvplugins/multiverse/core/destination/DestinationInstance.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 'org.mvplugins.multiverse.core.locale.message.Message' should be separated from previous imports. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/destination/DestinationInstance.java:9:1: warning: 'org.mvplugins.multiverse.core.locale.message.Message' should be separated from previous imports. (com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck)
import org.mvplugins.multiverse.core.world.location.UnloadedWorldLocation;

/**
Expand Down Expand Up @@ -79,6 +80,20 @@
*/
public abstract @NotNull Option<String> getFinerPermissionSuffix();

/**
* Gets a user-friendly display text for this destination instance. This is used when displaying the destination
* to the player. By default, this returns the same as {@link #toString()}. Override this method to provide a more
* user-friendly display text with colors, formatting and localization support.
*
* @return The display message.
* @since 5.4
*/
@ApiStatus.AvailableSince("5.4")
@NotNull
public Message getDisplayMessage() {
return Message.of(this.toString());
}

/**
* Serialises the destination instance to a savable string.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.jetbrains.annotations.NotNull;

import org.mvplugins.multiverse.core.destination.DestinationInstance;
import org.mvplugins.multiverse.core.locale.message.Message;

/**
* Destination instance implementation for the {@link AnchorDestination}.
Expand Down Expand Up @@ -63,6 +64,15 @@
return Option.of(anchorName);
}

/**
* {@inheritDoc}
*/
@Override
public @NotNull Message getDisplayMessage() {
//TODO Localize

Check warning on line 72 in src/main/java/org/mvplugins/multiverse/core/destination/core/AnchorDestinationInstance.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Comment matches to-do format 'TODO'. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/destination/core/AnchorDestinationInstance.java:72:11: info: Comment matches to-do format 'TODO'. (com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck)
return Message.of("anchor '" + anchorName + "'");
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
import org.jetbrains.annotations.Nullable;

import org.mvplugins.multiverse.core.destination.DestinationInstance;
import org.mvplugins.multiverse.core.locale.message.Message;

/**
* Destination instance implementation for the {@link BedDestination}.
*/
public final class BedDestinationInstance extends DestinationInstance<BedDestinationInstance, BedDestination> {
private final Player player;
private final @Nullable Player player;

/**
* Constructor.
Expand Down Expand Up @@ -64,6 +65,15 @@
return Option.of(player != null ? player.getName() : BedDestination.OWN_BED_STRING);
}

/**
* {@inheritDoc}
*/
@Override
public @NotNull Message getDisplayMessage() {
//TODO Localize

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

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Comment matches to-do format 'TODO'. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/destination/core/BedDestinationInstance.java:73:11: info: Comment matches to-do format 'TODO'. (com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck)
return Message.of(player == null ? "your bed/respawn point" : player.getName() + "'s bed/respawn point");
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@
import org.mvplugins.multiverse.core.locale.MVCorei18n;
import org.mvplugins.multiverse.core.utils.REPatterns;
import org.mvplugins.multiverse.core.utils.position.EntityPosition;
import org.mvplugins.multiverse.core.utils.position.PositionNumber;
import org.mvplugins.multiverse.core.utils.position.VectorPosition;
import org.mvplugins.multiverse.core.utils.result.Attempt;
import org.mvplugins.multiverse.core.utils.result.FailureReason;
import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld;
import org.mvplugins.multiverse.core.world.WorldManager;
import org.mvplugins.multiverse.core.world.entrycheck.WorldEntryCheckerProvider;
import org.mvplugins.multiverse.core.world.location.UnloadedWorldLocation;

import static org.mvplugins.multiverse.core.locale.message.MessageReplacement.*;

Expand Down Expand Up @@ -68,6 +65,7 @@ public ExactDestination(CoreConfig config, WorldManager worldManager, WorldEntry
public @NotNull ExactDestinationInstance fromLocation(@NotNull Location location) {
return new ExactDestinationInstance(
this,
worldManager,
location.getWorld().getName(),
EntityPosition.ofLocation(location)
);
Expand All @@ -88,6 +86,7 @@ public ExactDestination(CoreConfig config, WorldManager worldManager, WorldEntry
.map(location -> Attempt.<ExactDestinationInstance, InstanceFailureReason>success(
new ExactDestinationInstance(
this,
worldManager,
location.getWorld().getName(),
EntityPosition.ofLocation(location)
)
Expand All @@ -112,7 +111,7 @@ public ExactDestination(CoreConfig config, WorldManager worldManager, WorldEntry
return Attempt.failure(InstanceFailureReason.INVALID_NUMBER_FORMAT, Replace.ERROR.with(e));
}

return Attempt.success(new ExactDestinationInstance(this, worldName, position));
return Attempt.success(new ExactDestinationInstance(this, worldManager, worldName, position));
}

//TODO: Extract to a world finder class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
import org.jetbrains.annotations.NotNull;

import org.mvplugins.multiverse.core.destination.DestinationInstance;
import org.mvplugins.multiverse.core.locale.message.Message;
import org.mvplugins.multiverse.core.utils.position.EntityPosition;
import org.mvplugins.multiverse.core.utils.position.VectorPosition;
import org.mvplugins.multiverse.core.world.location.UnloadedWorldLocation;
import org.mvplugins.multiverse.core.world.MultiverseWorld;
import org.mvplugins.multiverse.core.world.WorldManager;

/**
* Destination instance implementation for the {@link ExactDestination}.
*/
public final class ExactDestinationInstance extends DestinationInstance<ExactDestinationInstance, ExactDestination> {
private final WorldManager worldManager;
private final String worldName;
private final EntityPosition position;

Expand All @@ -28,9 +30,11 @@ public final class ExactDestinationInstance extends DestinationInstance<ExactDes
* @param position The position in the world.
*/
ExactDestinationInstance(@NotNull ExactDestination destination,
@NotNull WorldManager worldManager,
@NotNull String worldName,
@NotNull EntityPosition position) {
super(destination);
this.worldManager = worldManager;
this.worldName = worldName;
this.position = position;
}
Expand Down Expand Up @@ -73,6 +77,17 @@ public boolean checkTeleportSafety() {
return Option.of(worldName);
}

/**
* {@inheritDoc}
*/
@Override
public @NotNull Message getDisplayMessage() {
String displayWorldName = worldManager.getWorld(worldName)
.map(MultiverseWorld::getAliasOrName)
.getOrElse(worldName);
return Message.of(displayWorldName + " at " + position.toString());
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.jetbrains.annotations.NotNull;

import org.mvplugins.multiverse.core.destination.DestinationInstance;
import org.mvplugins.multiverse.core.locale.message.Message;

import java.util.UUID;

Expand Down Expand Up @@ -66,6 +67,14 @@ public boolean checkTeleportSafety() {
return Option.of(playerName);
}

/**
* {@inheritDoc}
*/
@Override
public @NotNull Message getDisplayMessage() {
return Message.of(playerName);
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
import org.jetbrains.annotations.Nullable;

import org.mvplugins.multiverse.core.destination.DestinationInstance;
import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld;
import org.mvplugins.multiverse.core.locale.message.Message;
import org.mvplugins.multiverse.core.world.MultiverseWorld;

import java.lang.ref.Reference;
import java.lang.ref.WeakReference;

/**
* Destination instance implementation for the {@link WorldDestination}.
*/
Expand Down Expand Up @@ -87,6 +84,14 @@ public boolean checkTeleportSafety() {
return Option.of(world.getName());
}

/**
* {@inheritDoc}
*/
@Override
public @NotNull Message getDisplayMessage() {
return Message.of(world.getAliasOrName());
}

/**
* {@inheritDoc}
*/
Expand Down