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 @@ -23,7 +23,7 @@
import org.jvnet.hk2.annotations.Service;

import org.mvplugins.multiverse.core.anchor.AnchorManager;
import org.mvplugins.multiverse.core.api.Destination;
import org.mvplugins.multiverse.core.destination.Destination;
import org.mvplugins.multiverse.core.api.MVCore;
import org.mvplugins.multiverse.core.commands.CoreCommand;
import org.mvplugins.multiverse.core.commandtools.MVCommandManager;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@

import org.mvplugins.multiverse.core.commandtools.MVCommandIssuer;
import org.mvplugins.multiverse.core.commandtools.MVCommandManager;
import org.mvplugins.multiverse.core.commandtools.MultiverseCommand;
import org.mvplugins.multiverse.core.destination.DestinationInstance;
import org.mvplugins.multiverse.core.destination.DestinationsProvider;
import org.mvplugins.multiverse.core.destination.ParsedDestination;
import org.mvplugins.multiverse.core.utils.MVCorei18n;

@Service
Expand Down Expand Up @@ -45,7 +44,7 @@ void onCheckCommand(

@Syntax("<destination>")
@Description("{@@mv-core.check.destination.description}")
ParsedDestination<?> destination) {
DestinationInstance<?, ?> destination) {
issuer.sendInfo(MVCorei18n.CHECK_CHECKING,
"{player}", player.getName(),
"{destination}", destination.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

import org.mvplugins.multiverse.core.commandtools.MVCommandIssuer;
import org.mvplugins.multiverse.core.commandtools.MVCommandManager;
import org.mvplugins.multiverse.core.commandtools.MultiverseCommand;
import org.mvplugins.multiverse.core.destination.ParsedDestination;
import org.mvplugins.multiverse.core.destination.DestinationInstance;
import org.mvplugins.multiverse.core.permissions.CorePermissionsChecker;
import org.mvplugins.multiverse.core.teleportation.AsyncSafetyTeleporter;
import org.mvplugins.multiverse.core.utils.MVCorei18n;
Expand Down Expand Up @@ -55,7 +54,7 @@ void onTeleportCommand(

@Syntax("<destination>")
@Description("{@@mv-core.teleport.destination.description}")
ParsedDestination<?> destination) {
DestinationInstance<?, ?> destination) {
// TODO: Add warning if teleporting too many players at once.

String playerName = players.length == 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

import org.mvplugins.multiverse.core.config.MVCoreConfig;
import org.mvplugins.multiverse.core.configuration.handle.PropertyModifyAction;
import org.mvplugins.multiverse.core.destination.DestinationInstance;
import org.mvplugins.multiverse.core.destination.DestinationsProvider;
import org.mvplugins.multiverse.core.destination.ParsedDestination;
import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld;
import org.mvplugins.multiverse.core.world.MultiverseWorld;
import org.mvplugins.multiverse.core.world.WorldManager;
Expand Down Expand Up @@ -68,7 +68,7 @@ class MVCommandCompletions extends PaperCommandCompletions {
registerAsyncCompletion("mvworldpropsvalue", this::suggestMVWorldPropsValue);
registerStaticCompletion("propsmodifyaction", suggestEnums(PropertyModifyAction.class));

setDefaultCompletion("destinations", ParsedDestination.class);
setDefaultCompletion("destinations", DestinationInstance.class);
setDefaultCompletion("difficulties", Difficulty.class);
setDefaultCompletion("environments", World.Environment.class);
setDefaultCompletion("flags", String[].class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import org.mvplugins.multiverse.core.commandtools.context.GameRuleValue;
import org.mvplugins.multiverse.core.config.MVCoreConfig;
import org.mvplugins.multiverse.core.destination.DestinationInstance;
import org.mvplugins.multiverse.core.destination.DestinationsProvider;
import org.mvplugins.multiverse.core.destination.ParsedDestination;
import org.mvplugins.multiverse.core.display.filters.ContentFilter;
import org.mvplugins.multiverse.core.display.filters.DefaultContentFilter;
import org.mvplugins.multiverse.core.display.filters.RegexContentFilter;
Expand Down Expand Up @@ -49,7 +49,7 @@
registerIssuerOnlyContext(BukkitCommandIssuer.class, BukkitCommandExecutionContext::getIssuer);
registerIssuerOnlyContext(MVCommandIssuer.class, this::parseMVCommandIssuer);
registerOptionalContext(ContentFilter.class, this::parseContentFilter);
registerContext(ParsedDestination.class, this::parseDestination);
registerContext(DestinationInstance.class, this::parseDestination);
registerContext(GameRule.class, this::parseGameRule);
registerContext(GameRuleValue.class, this::parseGameRuleValue);
registerIssuerAwareContext(LoadedMultiverseWorld.class, this::parseLoadedMultiverseWorld);
Expand All @@ -74,18 +74,14 @@
return RegexContentFilter.fromString(filterString);
}

private ParsedDestination<?> parseDestination(BukkitCommandExecutionContext context) {
private DestinationInstance<?, ?> parseDestination(BukkitCommandExecutionContext context) {
String destination = context.popFirstArg();
if (Strings.isNullOrEmpty(destination)) {
throw new InvalidCommandArgument("No destination specified.");
}

ParsedDestination<?> parsedDestination = destinationsProvider.parseDestination(destination);
if (parsedDestination == null) {
throw new InvalidCommandArgument("The destination " + destination + " is not valid.");
}

return parsedDestination;
return destinationsProvider.parseDestination(destination)
.getOrElseThrow(() -> new InvalidCommandArgument("The destination " + destination + " is not valid."));

Check warning on line 84 in src/main/java/org/mvplugins/multiverse/core/commandtools/MVCommandContexts.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 The String " is not valid." appears 2 times in the file. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/commandtools/MVCommandContexts.java:84:101: warning: The String " is not valid." appears 2 times in the file. (com.puppycrawl.tools.checkstyle.checks.coding.MultipleStringLiteralsCheck)
}

private GameRule<?> parseGameRule(BukkitCommandExecutionContext context) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.mvplugins.multiverse.core.api;
package org.mvplugins.multiverse.core.destination;

import java.util.Collection;

Expand All @@ -8,7 +8,7 @@
import org.jvnet.hk2.annotations.Contract;

@Contract
public interface Destination<T extends DestinationInstance> {
public interface Destination<D extends Destination<D, T>, T extends DestinationInstance<T, D>> {
Copy link
Member

@dumptruckman dumptruckman Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not crazy about the recursive generics here. Can you summarize what this is doing? Having some difficulty following.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its just each Destination maps a one DestinationInstance

Copy link
Member Author

@benwoo1110 benwoo1110 Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so that ExactDestination.parseDestination() can only return ExactDestinationInstance, then ExactDestinationInstance.getDestination() can only return ExactDestination.

Kinda like a 1 to 1 map thing, where you cant just allow ExactDestination to return any type of DestinationInstance and ExactDestinationInstance cannot be created by any type of Destination only ExactDestination

/**
* Returns the identifier or prefix that is required for this destination.
*
Expand Down Expand Up @@ -36,13 +36,4 @@ public interface Destination<T extends DestinationInstance> {
* @return A list of possible destinations.
*/
@NotNull Collection<String> suggestDestinations(@NotNull BukkitCommandIssuer issuer, @Nullable String destinationParams);

/**
* Should the Multiverse SafeTeleporter be used?
*
* <p>If not, MV will blindly take people to the location specified.</p>
*
* @return True if the SafeTeleporter will be used, false if not.
*/
boolean checkTeleportSafety();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.mvplugins.multiverse.core.destination;

import io.vavr.control.Option;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Check warning on line 8 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 🐶 Unused import - org.jetbrains.annotations.Nullable. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/destination/DestinationInstance.java:8:8: warning: Unused import - org.jetbrains.annotations.Nullable. (com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck)

public abstract class DestinationInstance<I extends DestinationInstance<I, T>, T extends Destination<T, I>> {

Check warning on line 10 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 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/destination/DestinationInstance.java:10:1: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocTypeCheck)

Check warning on line 10 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 🐶 Use a single space to separate non-whitespace characters. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/destination/DestinationInstance.java:10:54: warning: Use a single space to separate non-whitespace characters. (com.puppycrawl.tools.checkstyle.checks.whitespace.SingleSpaceSeparatorCheck)

protected final T destination;

Check warning on line 12 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 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/destination/DestinationInstance.java:12:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocVariableCheck)

protected DestinationInstance(@NotNull T destination) {
this.destination = destination;
}

/**
* Gets the destination that created this instance.
*
* @return The destination.
*/
public @NotNull T getDestination() {
return this.destination;
}

/**
* Gets the {@link Destination#getIdentifier()} for this instance.
*
* @return The identifier.
*/
public @NotNull String getIdentifier() {
return this.destination.getIdentifier();
}

/**
* Gets the exact location to teleport an entity to.
*
* @param teleportee The entity to teleport.
* @return The location to teleport to.
*/
public abstract @NotNull Option<Location> getLocation(@NotNull Entity teleportee);

/**
* Gets the velocity to apply to an entity after teleporting.
*
* @param teleportee The entity to teleport.
* @return A vector representing the speed/direction the player should travel when arriving at the destination.
*/
public abstract @NotNull Option<Vector> getVelocity(@NotNull Entity teleportee);

/**

Check warning on line 52 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 🐶 First sentence of Javadoc is missing an ending period. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/destination/DestinationInstance.java:52:0: warning: First sentence of Javadoc is missing an ending period. (com.puppycrawl.tools.checkstyle.checks.javadoc.SummaryJavadocCheck)
* Should the Multiverse SafeTeleporter be used?
*
* <p>If not, MV will blindly take people to the location specified.</p>
*
* @return True if the SafeTeleporter will be used, false if not.
*/
public abstract boolean checkTeleportSafety();

/**
* Gets the permission suffix to check for when teleporting to this destination.
* This is used for finer per world/player permissions, such as "multiverse.teleport.self.worldname".
*
* <p>For example, if the destination is "w:world", the permission suffix is "world".</p>
*
* @return The permission suffix.
*/
public abstract @NotNull Option<String> getFinerPermissionSuffix();

/**
* Serialises the destination instance to a savable string.
*
* <p>This is used when plugins save destinations to configuration,
* and when the destination is displayed to the user.</p>
*
* @return The serialised destination instance.
*/
@NotNull
protected abstract String serialise();

/**
* String representation of the destination instance that can be deserialised back into the destination instance.
* @return The string representation of the destination instance.

Check warning on line 84 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 🐶 Javadoc tag '@return' should be preceded with an empty line. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/destination/DestinationInstance.java:84:0: warning: Javadoc tag '@return' should be preceded with an empty line. (com.puppycrawl.tools.checkstyle.checks.javadoc.RequireEmptyLineBeforeBlockTagGroupCheck)
*/
@Override
public String toString() {
return this.destination.getIdentifier() + ":" + this.serialise();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
import java.util.stream.Collectors;

import co.aikar.commands.BukkitCommandIssuer;
import io.vavr.control.Option;
import jakarta.inject.Inject;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.PluginManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jvnet.hk2.annotations.Service;

import org.mvplugins.multiverse.core.api.Destination;
import org.mvplugins.multiverse.core.api.DestinationInstance;

/**
* Provides destinations for teleportation.
*/
Expand All @@ -25,7 +23,7 @@ public class DestinationsProvider {
private static final String PERMISSION_PREFIX = "multiverse.teleport.";

private final PluginManager pluginManager;
private final Map<String, Destination<?>> destinationMap;
private final Map<String, Destination<?, ?>> destinationMap;

@Inject
DestinationsProvider(@NotNull PluginManager pluginManager) {
Expand All @@ -38,12 +36,12 @@ public class DestinationsProvider {
*
* @param destination The destination.
*/
public void registerDestination(@NotNull Destination<?> destination) {
public void registerDestination(@NotNull Destination<?, ?> destination) {
this.destinationMap.put(destination.getIdentifier(), destination);
this.registerDestinationPerms(destination);
}

private void registerDestinationPerms(@NotNull Destination<?> destination) {
private void registerDestinationPerms(@NotNull Destination<?, ?> destination) {
pluginManager.addPermission(new Permission(PERMISSION_PREFIX + "self." + destination.getIdentifier()));
pluginManager.addPermission(new Permission(PERMISSION_PREFIX + "other." + destination.getIdentifier()));
}
Expand Down Expand Up @@ -74,13 +72,13 @@ private void registerDestinationPerms(@NotNull Destination<?> destination) {
* @param destinationString The destination string.
* @return The destination object, or null if invalid format.
*/
@Nullable
public ParsedDestination<?> parseDestination(@NotNull String destinationString) {
@NotNull
public Option<DestinationInstance<?, ?>> parseDestination(@NotNull String destinationString) {
String[] items = destinationString.split(SEPARATOR, 2);

String idString = items[0];
String destinationParams;
Destination<?> destination;
Destination<?, ?> destination;

if (items.length < 2) {
// Assume world destination
Expand All @@ -92,15 +90,10 @@ public ParsedDestination<?> parseDestination(@NotNull String destinationString)
}

if (destination == null) {
return null;
}

DestinationInstance destinationInstance = destination.getDestinationInstance(destinationParams);
if (destinationInstance == null) {
return null;
return Option.none();
}

return new ParsedDestination<>(destination, destinationInstance);
return Option.of(destination.getDestinationInstance(destinationParams));
}

/**
Expand All @@ -109,7 +102,7 @@ public ParsedDestination<?> parseDestination(@NotNull String destinationString)
* @param identifier The identifier.
* @return The destination, or null if not found.
*/
public @Nullable Destination<?> getDestinationById(@Nullable String identifier) {
public @Nullable Destination<?, ?> getDestinationById(@Nullable String identifier) {
return this.destinationMap.get(identifier);
}

Expand All @@ -118,7 +111,7 @@ public ParsedDestination<?> parseDestination(@NotNull String destinationString)
*
* @return A collection of destinations.
*/
public @NotNull Collection<Destination<?>> getDestinations() {
public @NotNull Collection<Destination<?, ?>> getDestinations() {
return this.destinationMap.values();
}
}
Loading
Loading