Skip to content

Commit 55d1347

Browse files
authored
Merge pull request #3360 from Multiverse/feat/destination-message
Implement display message for destination instances to improve teleport command output
2 parents 4004554 + 8d06b92 commit 55d1347

8 files changed

Lines changed: 77 additions & 14 deletions

File tree

src/main/java/org/mvplugins/multiverse/core/commands/TeleportCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private void teleportSinglePlayer(MVCommandIssuer issuer, Player player,
105105
.teleportSingle(player)
106106
.onSuccess(() -> issuer.sendInfo(MVCorei18n.TELEPORT_SUCCESS,
107107
Replace.PLAYER.with(getYouOrName(issuer, player)),
108-
Replace.DESTINATION.with(destination.toString())))
108+
Replace.DESTINATION.with(destination.getDisplayMessage())))
109109
.onFailureCount(reasonsCountMap -> {
110110
for (var entry : reasonsCountMap.entrySet()) {
111111
Logging.finer("Failed to teleport %s players to %s: %s",
@@ -138,7 +138,7 @@ private void teleportMultiplePlayers(MVCommandIssuer issuer, Player[] players,
138138
.teleport(List.of(players))
139139
.onSuccessCount(successCount -> issuer.sendInfo(MVCorei18n.TELEPORT_SUCCESS,
140140
Replace.PLAYER.with(successCount + " players"),
141-
Replace.DESTINATION.with(destination.toString())))
141+
Replace.DESTINATION.with(destination.getDisplayMessage())))
142142
.onFailureCount(reasonsCountMap -> {
143143
for (var entry : reasonsCountMap.entrySet()) {
144144
Logging.finer("Failed to teleport %s players to %s: %s",

src/main/java/org/mvplugins/multiverse/core/destination/DestinationInstance.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
import org.bukkit.Location;
55
import org.bukkit.entity.Entity;
66
import org.bukkit.util.Vector;
7+
import org.jetbrains.annotations.ApiStatus;
78
import org.jetbrains.annotations.NotNull;
8-
import org.mvplugins.multiverse.core.utils.result.FailureReason;
9+
import org.mvplugins.multiverse.core.locale.message.Message;
910
import org.mvplugins.multiverse.core.world.location.UnloadedWorldLocation;
1011

1112
/**
@@ -79,6 +80,20 @@ protected DestinationInstance(@NotNull T destination) {
7980
*/
8081
public abstract @NotNull Option<String> getFinerPermissionSuffix();
8182

83+
/**
84+
* Gets a user-friendly display text for this destination instance. This is used when displaying the destination
85+
* to the player. By default, this returns the same as {@link #toString()}. Override this method to provide a more
86+
* user-friendly display text with colors, formatting and localization support.
87+
*
88+
* @return The display message.
89+
* @since 5.4
90+
*/
91+
@ApiStatus.AvailableSince("5.4")
92+
@NotNull
93+
public Message getDisplayMessage() {
94+
return Message.of(this.toString());
95+
}
96+
8297
/**
8398
* Serialises the destination instance to a savable string.
8499
*

src/main/java/org/mvplugins/multiverse/core/destination/core/AnchorDestinationInstance.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.jetbrains.annotations.NotNull;
88

99
import org.mvplugins.multiverse.core.destination.DestinationInstance;
10+
import org.mvplugins.multiverse.core.locale.message.Message;
1011

1112
/**
1213
* Destination instance implementation for the {@link AnchorDestination}.
@@ -63,6 +64,15 @@ public boolean checkTeleportSafety() {
6364
return Option.of(anchorName);
6465
}
6566

67+
/**
68+
* {@inheritDoc}
69+
*/
70+
@Override
71+
public @NotNull Message getDisplayMessage() {
72+
//TODO Localize
73+
return Message.of("anchor '" + anchorName + "'");
74+
}
75+
6676
/**
6777
* {@inheritDoc}
6878
*/

src/main/java/org/mvplugins/multiverse/core/destination/core/BedDestinationInstance.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
import org.jetbrains.annotations.Nullable;
1010

1111
import org.mvplugins.multiverse.core.destination.DestinationInstance;
12+
import org.mvplugins.multiverse.core.locale.message.Message;
1213

1314
/**
1415
* Destination instance implementation for the {@link BedDestination}.
1516
*/
1617
public final class BedDestinationInstance extends DestinationInstance<BedDestinationInstance, BedDestination> {
17-
private final Player player;
18+
private final @Nullable Player player;
1819

1920
/**
2021
* Constructor.
@@ -64,6 +65,15 @@ public boolean checkTeleportSafety() {
6465
return Option.of(player != null ? player.getName() : BedDestination.OWN_BED_STRING);
6566
}
6667

68+
/**
69+
* {@inheritDoc}
70+
*/
71+
@Override
72+
public @NotNull Message getDisplayMessage() {
73+
//TODO Localize
74+
return Message.of(player == null ? "your bed/respawn point" : player.getName() + "'s bed/respawn point");
75+
}
76+
6777
/**
6878
* {@inheritDoc}
6979
*/

src/main/java/org/mvplugins/multiverse/core/destination/core/ExactDestination.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@
2323
import org.mvplugins.multiverse.core.locale.MVCorei18n;
2424
import org.mvplugins.multiverse.core.utils.REPatterns;
2525
import org.mvplugins.multiverse.core.utils.position.EntityPosition;
26-
import org.mvplugins.multiverse.core.utils.position.PositionNumber;
27-
import org.mvplugins.multiverse.core.utils.position.VectorPosition;
2826
import org.mvplugins.multiverse.core.utils.result.Attempt;
2927
import org.mvplugins.multiverse.core.utils.result.FailureReason;
3028
import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld;
3129
import org.mvplugins.multiverse.core.world.WorldManager;
3230
import org.mvplugins.multiverse.core.world.entrycheck.WorldEntryCheckerProvider;
33-
import org.mvplugins.multiverse.core.world.location.UnloadedWorldLocation;
3431

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

@@ -68,6 +65,7 @@ public ExactDestination(CoreConfig config, WorldManager worldManager, WorldEntry
6865
public @NotNull ExactDestinationInstance fromLocation(@NotNull Location location) {
6966
return new ExactDestinationInstance(
7067
this,
68+
worldManager,
7169
location.getWorld().getName(),
7270
EntityPosition.ofLocation(location)
7371
);
@@ -88,6 +86,7 @@ public ExactDestination(CoreConfig config, WorldManager worldManager, WorldEntry
8886
.map(location -> Attempt.<ExactDestinationInstance, InstanceFailureReason>success(
8987
new ExactDestinationInstance(
9088
this,
89+
worldManager,
9190
location.getWorld().getName(),
9291
EntityPosition.ofLocation(location)
9392
)
@@ -112,7 +111,7 @@ public ExactDestination(CoreConfig config, WorldManager worldManager, WorldEntry
112111
return Attempt.failure(InstanceFailureReason.INVALID_NUMBER_FORMAT, Replace.ERROR.with(e));
113112
}
114113

115-
return Attempt.success(new ExactDestinationInstance(this, worldName, position));
114+
return Attempt.success(new ExactDestinationInstance(this, worldManager, worldName, position));
116115
}
117116

118117
//TODO: Extract to a world finder class

src/main/java/org/mvplugins/multiverse/core/destination/core/ExactDestinationInstance.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
import org.jetbrains.annotations.NotNull;
1010

1111
import org.mvplugins.multiverse.core.destination.DestinationInstance;
12+
import org.mvplugins.multiverse.core.locale.message.Message;
1213
import org.mvplugins.multiverse.core.utils.position.EntityPosition;
13-
import org.mvplugins.multiverse.core.utils.position.VectorPosition;
14-
import org.mvplugins.multiverse.core.world.location.UnloadedWorldLocation;
14+
import org.mvplugins.multiverse.core.world.MultiverseWorld;
15+
import org.mvplugins.multiverse.core.world.WorldManager;
1516

1617
/**
1718
* Destination instance implementation for the {@link ExactDestination}.
1819
*/
1920
public final class ExactDestinationInstance extends DestinationInstance<ExactDestinationInstance, ExactDestination> {
21+
private final WorldManager worldManager;
2022
private final String worldName;
2123
private final EntityPosition position;
2224

@@ -28,9 +30,11 @@ public final class ExactDestinationInstance extends DestinationInstance<ExactDes
2830
* @param position The position in the world.
2931
*/
3032
ExactDestinationInstance(@NotNull ExactDestination destination,
33+
@NotNull WorldManager worldManager,
3134
@NotNull String worldName,
3235
@NotNull EntityPosition position) {
3336
super(destination);
37+
this.worldManager = worldManager;
3438
this.worldName = worldName;
3539
this.position = position;
3640
}
@@ -73,6 +77,17 @@ public boolean checkTeleportSafety() {
7377
return Option.of(worldName);
7478
}
7579

80+
/**
81+
* {@inheritDoc}
82+
*/
83+
@Override
84+
public @NotNull Message getDisplayMessage() {
85+
String displayWorldName = worldManager.getWorld(worldName)
86+
.map(MultiverseWorld::getAliasOrName)
87+
.getOrElse(worldName);
88+
return Message.of(displayWorldName + " at " + position.toString());
89+
}
90+
7691
/**
7792
* {@inheritDoc}
7893
*/

src/main/java/org/mvplugins/multiverse/core/destination/core/PlayerDestinationInstance.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.jetbrains.annotations.NotNull;
1010

1111
import org.mvplugins.multiverse.core.destination.DestinationInstance;
12+
import org.mvplugins.multiverse.core.locale.message.Message;
1213

1314
import java.util.UUID;
1415

@@ -66,6 +67,14 @@ public boolean checkTeleportSafety() {
6667
return Option.of(playerName);
6768
}
6869

70+
/**
71+
* {@inheritDoc}
72+
*/
73+
@Override
74+
public @NotNull Message getDisplayMessage() {
75+
return Message.of(playerName);
76+
}
77+
6978
/**
7079
* {@inheritDoc}
7180
*/

src/main/java/org/mvplugins/multiverse/core/destination/core/WorldDestinationInstance.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88
import org.jetbrains.annotations.Nullable;
99

1010
import org.mvplugins.multiverse.core.destination.DestinationInstance;
11-
import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld;
11+
import org.mvplugins.multiverse.core.locale.message.Message;
1212
import org.mvplugins.multiverse.core.world.MultiverseWorld;
1313

14-
import java.lang.ref.Reference;
15-
import java.lang.ref.WeakReference;
16-
1714
/**
1815
* Destination instance implementation for the {@link WorldDestination}.
1916
*/
@@ -87,6 +84,14 @@ public boolean checkTeleportSafety() {
8784
return Option.of(world.getName());
8885
}
8986

87+
/**
88+
* {@inheritDoc}
89+
*/
90+
@Override
91+
public @NotNull Message getDisplayMessage() {
92+
return Message.of(world.getAliasOrName());
93+
}
94+
9095
/**
9196
* {@inheritDoc}
9297
*/

0 commit comments

Comments
 (0)