-
-
Notifications
You must be signed in to change notification settings - Fork 325
Refactor to remove need for ParsedDestination and add destination tests #3130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| 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
|
||
|
|
||
| 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
|
||
|
|
||
| protected final T destination; | ||
|
Check warning on line 12 in src/main/java/org/mvplugins/multiverse/core/destination/DestinationInstance.java
|
||
|
|
||
| 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
|
||
| * 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
|
||
| */ | ||
| @Override | ||
| public String toString() { | ||
| return this.destination.getIdentifier() + ":" + this.serialise(); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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 returnExactDestinationInstance, thenExactDestinationInstance.getDestination()can only returnExactDestination.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