mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-15 23:26:18 +01:00
feat: Implementation of new destination API (#2833)
* feat: Basic implementation of new destination API * feat!: Move all destinations to new API * feat: Fully implement teleport and check command * chore: Improve autocomplete permission checking * chore: Fine tune tab completion * chore: Implement suggested changes * docs: Add javadocs to added api methods
This commit is contained in:
parent
747cab75fd
commit
a8590df9d4
@ -34,8 +34,8 @@ import com.onarandombox.MultiverseCore.api.MultiverseMessaging;
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.commands.CreateCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.DebugCommand;
|
||||
import com.onarandombox.MultiverseCore.commands.TeleportCommand;
|
||||
import com.onarandombox.MultiverseCore.commandsold.AnchorCommand;
|
||||
import com.onarandombox.MultiverseCore.commandsold.CheckCommand;
|
||||
import com.onarandombox.MultiverseCore.commandsold.CloneCommand;
|
||||
import com.onarandombox.MultiverseCore.commandsold.ConfigCommand;
|
||||
import com.onarandombox.MultiverseCore.commandsold.ConfirmCommand;
|
||||
@ -63,19 +63,18 @@ import com.onarandombox.MultiverseCore.commandsold.ScriptCommand;
|
||||
import com.onarandombox.MultiverseCore.commandsold.SetSpawnCommand;
|
||||
import com.onarandombox.MultiverseCore.commandsold.SilentCommand;
|
||||
import com.onarandombox.MultiverseCore.commandsold.SpawnCommand;
|
||||
import com.onarandombox.MultiverseCore.commandsold.TeleportCommand;
|
||||
import com.onarandombox.MultiverseCore.commandsold.UnloadCommand;
|
||||
import com.onarandombox.MultiverseCore.commandsold.VersionCommand;
|
||||
import com.onarandombox.MultiverseCore.commandsold.WhoCommand;
|
||||
import com.onarandombox.MultiverseCore.commandtools.MVCommandManager;
|
||||
import com.onarandombox.MultiverseCore.commandtools.queue.CommandQueueManager;
|
||||
import com.onarandombox.MultiverseCore.destination.AnchorDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.BedDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.CannonDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.DestinationFactory;
|
||||
import com.onarandombox.MultiverseCore.destination.ExactDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.PlayerDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.WorldDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.core.AnchorDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.core.BedDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.core.CannonDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.core.ExactDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.core.PlayerDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.DestinationsProvider;
|
||||
import com.onarandombox.MultiverseCore.destination.core.WorldDestination;
|
||||
import com.onarandombox.MultiverseCore.event.MVDebugModeEvent;
|
||||
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVChatListener;
|
||||
@ -227,7 +226,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
private MVEconomist economist;
|
||||
private Buscript buscript;
|
||||
private int pluginCount;
|
||||
private DestinationFactory destFactory;
|
||||
private DestinationsProvider destinationsProvider;
|
||||
private MultiverseMessaging messaging;
|
||||
private BlockSafety blockSafety;
|
||||
private LocationManipulation locationManipulation;
|
||||
@ -362,14 +361,13 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
}
|
||||
|
||||
private void initializeDestinationFactory() {
|
||||
this.destFactory = new DestinationFactory(this);
|
||||
this.destFactory.registerDestinationType(WorldDestination.class, "");
|
||||
this.destFactory.registerDestinationType(WorldDestination.class, "w");
|
||||
this.destFactory.registerDestinationType(ExactDestination.class, "e");
|
||||
this.destFactory.registerDestinationType(PlayerDestination.class, "pl");
|
||||
this.destFactory.registerDestinationType(CannonDestination.class, "ca");
|
||||
this.destFactory.registerDestinationType(BedDestination.class, "b");
|
||||
this.destFactory.registerDestinationType(AnchorDestination.class, "a");
|
||||
this.destinationsProvider = new DestinationsProvider(this);
|
||||
this.destinationsProvider.registerDestination(new AnchorDestination(this));
|
||||
this.destinationsProvider.registerDestination(new BedDestination());
|
||||
this.destinationsProvider.registerDestination(new CannonDestination(this));
|
||||
this.destinationsProvider.registerDestination(new ExactDestination(this));
|
||||
this.destinationsProvider.registerDestination(new PlayerDestination());
|
||||
this.destinationsProvider.registerDestination(new WorldDestination(this));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -748,7 +746,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
this.commandHandler.registerCommand(new ReloadCommand(this));
|
||||
this.commandHandler.registerCommand(new SetSpawnCommand(this));
|
||||
this.commandHandler.registerCommand(new CoordCommand(this));
|
||||
this.commandHandler.registerCommand(new TeleportCommand(this));
|
||||
this.commandHandler.registerCommand(new WhoCommand(this));
|
||||
this.commandHandler.registerCommand(new SpawnCommand(this));
|
||||
// Dangerous Commands
|
||||
@ -771,12 +768,12 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
this.commandHandler.registerCommand(new EnvironmentCommand(this));
|
||||
this.commandHandler.registerCommand(new SilentCommand(this));
|
||||
this.commandHandler.registerCommand(new GeneratorCommand(this));
|
||||
this.commandHandler.registerCommand(new CheckCommand(this));
|
||||
this.commandHandler.registerCommand(new ScriptCommand(this));
|
||||
this.commandHandler.registerCommand(new GameruleCommand(this));
|
||||
this.commandHandler.registerCommand(new GamerulesCommand(this));
|
||||
|
||||
//**NEW ACF COMMAND HANDLER**
|
||||
this.commandManager.registerCommand(new TeleportCommand(this));
|
||||
this.commandManager.registerCommand(new DebugCommand(this));
|
||||
this.commandManager.registerCommand(new CreateCommand(this));
|
||||
}
|
||||
@ -935,8 +932,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public DestinationFactory getDestFactory() {
|
||||
return this.destFactory;
|
||||
public DestinationsProvider getDestinationsProvider() {
|
||||
return this.destinationsProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,7 +10,7 @@ package com.onarandombox.MultiverseCore.api;
|
||||
import buscript.Buscript;
|
||||
import com.onarandombox.MultiverseCore.commandtools.MVCommandManager;
|
||||
import com.onarandombox.MultiverseCore.commandtools.queue.CommandQueueManager;
|
||||
import com.onarandombox.MultiverseCore.destination.DestinationFactory;
|
||||
import com.onarandombox.MultiverseCore.destination.DestinationsProvider;
|
||||
import com.onarandombox.MultiverseCore.utils.AnchorManager;
|
||||
import com.onarandombox.MultiverseCore.utils.MVEconomist;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPermissions;
|
||||
@ -106,12 +106,12 @@ public interface Core {
|
||||
CommandQueueManager getCommandQueueManager();
|
||||
|
||||
/**
|
||||
* Gets the factory class responsible for loading many different destinations
|
||||
* Gets the class responsible for loading many different destinations
|
||||
* on demand.
|
||||
*
|
||||
* @return A valid {@link DestinationFactory}.
|
||||
* @return A valid {@link DestinationsProvider}.
|
||||
*/
|
||||
DestinationFactory getDestFactory();
|
||||
DestinationsProvider getDestinationsProvider();
|
||||
|
||||
/**
|
||||
* Gets the primary class responsible for managing Multiverse Worlds.
|
||||
|
@ -0,0 +1,56 @@
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import co.aikar.commands.BukkitCommandIssuer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface Destination<T extends DestinationInstance> {
|
||||
/**
|
||||
* Returns the identifier or prefix that is 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.
|
||||
* Please check the wiki when adding a custom destination!</p>
|
||||
*
|
||||
* @return The identifier or prefix that is required for this destination.
|
||||
*/
|
||||
@NotNull String getIdentifier();
|
||||
|
||||
/**
|
||||
* Returns the destination instance for the given destination parameters.
|
||||
*
|
||||
* @param destinationParams The destination parameters. ex: p:MyPortal:nw
|
||||
* @return The destination instance, or null if the destination parameters are invalid.
|
||||
*/
|
||||
@Nullable T getDestinationInstance(@Nullable String destinationParams);
|
||||
|
||||
/**
|
||||
* Returns a list of possible destinations for the given destination parameters.
|
||||
*
|
||||
* @param issuer The command issuer.
|
||||
* @param destinationParams The destination parameters. ex: p:MyPortal:nw
|
||||
* @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();
|
||||
|
||||
/**
|
||||
* Returns the teleporter to use for this destination.
|
||||
*
|
||||
* <p>By default, Multiverse will automatically use SafeTeleporter. If you want to use a different teleporter, you can
|
||||
* override this method.</p>
|
||||
*
|
||||
* @return The custom teleporter to use for this destination. Return null to use the default teleporter.
|
||||
*/
|
||||
@Nullable Teleporter getTeleporter();
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface DestinationInstance {
|
||||
/**
|
||||
* Gets the exact location to teleport an entity to.
|
||||
*
|
||||
* @param teleportee The entity to teleport.
|
||||
* @return The location to teleport to.
|
||||
*/
|
||||
@Nullable 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.
|
||||
*/
|
||||
@Nullable Vector getVelocity(@NotNull Entity teleportee);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@Nullable 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 String serialise();
|
||||
}
|
@ -16,6 +16,7 @@ import org.bukkit.util.Vector;
|
||||
* A destination API for Multiverse
|
||||
* Any plugin can add these to MV and when they are, any action that uses them (portals, MVTP, etc.) can use them!
|
||||
*/
|
||||
@Deprecated
|
||||
public interface MVDestination {
|
||||
/**
|
||||
* Returns the identifier or prefix that is required for this destination.
|
||||
|
@ -1,11 +1,12 @@
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import co.aikar.commands.BukkitCommandIssuer;
|
||||
import com.onarandombox.MultiverseCore.destination.ParsedDestination;
|
||||
import com.onarandombox.MultiverseCore.enums.TeleportResult;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import com.onarandombox.MultiverseCore.enums.TeleportResult;
|
||||
|
||||
/**
|
||||
* Used to safely teleport people.
|
||||
*/
|
||||
@ -31,12 +32,12 @@ public interface SafeTTeleporter extends Teleporter {
|
||||
* Safely teleport the entity to the MVDestination. This will perform checks to see if the place is safe, and if
|
||||
* it's not, will adjust the final destination accordingly.
|
||||
*
|
||||
* @param teleporter Person who performed the teleport command.
|
||||
* @param teleportee Entity to teleport
|
||||
* @param d Destination to teleport them to
|
||||
* @param teleporter Person who performed the teleport command.
|
||||
* @param teleportee Entity to teleport
|
||||
* @param destination Destination to teleport them to
|
||||
* @return true for success, false for failure
|
||||
*/
|
||||
TeleportResult safelyTeleport(CommandSender teleporter, Entity teleportee, MVDestination d);
|
||||
TeleportResult safelyTeleport(BukkitCommandIssuer teleporter, Entity teleportee, ParsedDestination<?> destination);
|
||||
|
||||
/**
|
||||
* Safely teleport the entity to the Location. This may perform checks to
|
||||
@ -55,11 +56,11 @@ public interface SafeTTeleporter extends Teleporter {
|
||||
/**
|
||||
* Returns a safe location for the entity to spawn at.
|
||||
*
|
||||
* @param e The entity to spawn
|
||||
* @param d The MVDestination to take the entity to.
|
||||
* @param entity The entity to spawn
|
||||
* @param destination The MVDestination to take the entity to.
|
||||
* @return A new location to spawn the entity at.
|
||||
*/
|
||||
Location getSafeLocation(Entity e, MVDestination d);
|
||||
Location getSafeLocation(Entity entity, DestinationInstance destination);
|
||||
|
||||
/**
|
||||
* Finds a portal-block next to the specified {@link Location}.
|
||||
|
@ -1,10 +1,18 @@
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import co.aikar.commands.BukkitCommandIssuer;
|
||||
import com.onarandombox.MultiverseCore.destination.ParsedDestination;
|
||||
import com.onarandombox.MultiverseCore.enums.TeleportResult;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
public interface Teleporter {
|
||||
TeleportResult teleport(CommandSender teleporter, Player teleportee, MVDestination destination);
|
||||
/**
|
||||
* Teleport the entity to the Multiverse Destination.
|
||||
*
|
||||
* @param teleporter Person who performed the teleport command.
|
||||
* @param teleportee Entity to teleport
|
||||
* @param destination Destination to teleport them to
|
||||
* @return true for success, false for failure
|
||||
*/
|
||||
TeleportResult teleport(BukkitCommandIssuer teleporter, Entity teleportee, ParsedDestination<?> destination);
|
||||
}
|
||||
|
@ -0,0 +1,40 @@
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.CommandIssuer;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.destination.ParsedDestination;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@CommandAlias("mv")
|
||||
public class CheckCommand extends MultiverseCommand {
|
||||
protected CheckCommand(@NotNull MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Subcommand("check")
|
||||
@CommandPermission("multiverse.core.check")
|
||||
@CommandCompletion("@players @destinations|@mvworlds")
|
||||
@Syntax("<player> <destination>")
|
||||
@Description("Checks if a player can teleport to a destination.")
|
||||
public void onCheckCommand(CommandIssuer issuer,
|
||||
|
||||
@Syntax("<player>")
|
||||
@Description("Player to check destination on.")
|
||||
Player player,
|
||||
|
||||
@Syntax("<destination>")
|
||||
@Description("A destination location, e.g. a world name.")
|
||||
ParsedDestination<?> destination
|
||||
) {
|
||||
issuer.sendMessage("Checking " + player + " to " + destination + "...");
|
||||
//TODO More detailed output on permissions required.
|
||||
this.plugin.getDestinationsProvider().checkTeleportPermissions(issuer, player, destination);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.BukkitCommandIssuer;
|
||||
import co.aikar.commands.CommandIssuer;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Flags;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.destination.ParsedDestination;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@CommandAlias("mv")
|
||||
public class TeleportCommand extends MultiverseCommand {
|
||||
public TeleportCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Subcommand("teleport|tp")
|
||||
@Syntax("[player] <destination>")
|
||||
@CommandCompletion("@players|@mvworlds:playeronly|@destinations:playeronly @mvworlds|@destinations")
|
||||
@Description("Allows you to the teleport to a location on your server!")
|
||||
public void onTeleportCommand(@NotNull CommandIssuer issuer,
|
||||
|
||||
@Flags("resolve=issueraware")
|
||||
@Syntax("[player]")
|
||||
@Description("Target player to teleport.")
|
||||
Player player,
|
||||
|
||||
@Syntax("<destination>")
|
||||
@Description("Location, can be a world name.")
|
||||
ParsedDestination<?> destination
|
||||
) {
|
||||
issuer.sendMessage("Teleporting "
|
||||
+ (((BukkitCommandIssuer) issuer).getPlayer() == player ? "you" : player.getName())
|
||||
+ " to " + destination + "...");
|
||||
this.plugin.getDestinationsProvider().playerTeleport((BukkitCommandIssuer) issuer, player, destination);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandIssuer issuer) {
|
||||
return this.plugin.getDestinationsProvider().hasAnyTeleportPermission(issuer);
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commandsold;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.InvalidDestination;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPermissions;
|
||||
import com.onarandombox.MultiverseCore.utils.PlayerFinder;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
/**
|
||||
* Checks to see if a player can go to a destination.
|
||||
*/
|
||||
public class CheckCommand extends MultiverseCommand {
|
||||
|
||||
public CheckCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.setName("Help you validate your multiverse settings");
|
||||
this.setCommandUsage("/mv check " + ChatColor.GREEN + "{PLAYER} {DESTINATION}");
|
||||
this.setArgRange(2, 2);
|
||||
this.addKey("mv check");
|
||||
this.addKey("mvcheck");
|
||||
this.addCommandExample("/mv check " + ChatColor.GREEN + "fernferret " + ChatColor.LIGHT_PURPLE + "w:MyWorld");
|
||||
this.addCommandExample("/mv check " + ChatColor.GREEN + "Rigby90 " + ChatColor.LIGHT_PURPLE + "p:MyPortal");
|
||||
this.addCommandExample("/mv check " + ChatColor.GREEN + "lithium3141 " + ChatColor.LIGHT_PURPLE + "ow:WarpName");
|
||||
this.setPermission("multiverse.core.debug", "Checks to see if a player can go to a destination. Prints debug if false.", PermissionDefault.OP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
Player p = PlayerFinder.get(args.get(0), sender);
|
||||
if (p == null) {
|
||||
sender.sendMessage("Could not find player " + ChatColor.GREEN + args.get(0));
|
||||
sender.sendMessage("Are they online?");
|
||||
return;
|
||||
}
|
||||
MVDestination dest = this.plugin.getDestFactory().getDestination(args.get(1));
|
||||
if (dest instanceof InvalidDestination) {
|
||||
sender.sendMessage(String.format("You asked if '%s' could go to %s%s%s,",
|
||||
args.get(0), ChatColor.GREEN, args.get(0), ChatColor.WHITE));
|
||||
sender.sendMessage("but I couldn't find a Destination of that name? Did you type it correctly?");
|
||||
return;
|
||||
}
|
||||
|
||||
MVPermissions perms = this.plugin.getMVPerms();
|
||||
perms.tellMeWhyICantDoThis(sender, p, dest);
|
||||
}
|
||||
}
|
@ -1,198 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.commandsold;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.Teleporter;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.commandtools.queue.QueuedCommand;
|
||||
import com.onarandombox.MultiverseCore.destination.CustomTeleporterDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.DestinationFactory;
|
||||
import com.onarandombox.MultiverseCore.destination.InvalidDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.WorldDestination;
|
||||
import com.onarandombox.MultiverseCore.enums.TeleportResult;
|
||||
import com.onarandombox.MultiverseCore.event.MVTeleportEvent;
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.utils.PlayerFinder;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Used to teleport players.
|
||||
*/
|
||||
public class TeleportCommand extends MultiverseCommand {
|
||||
private SafeTTeleporter playerTeleporter;
|
||||
|
||||
public TeleportCommand(MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
Permission menu = new Permission("multiverse.teleport.*", "Allows you to display the teleport menu.", PermissionDefault.OP);
|
||||
|
||||
this.setName("Teleport");
|
||||
this.setCommandUsage("/mv tp " + ChatColor.GOLD + "[PLAYER]" + ChatColor.GREEN + " {DESTINATION}");
|
||||
this.setArgRange(1, 2);
|
||||
this.addKey("mvtp");
|
||||
this.addKey("mv tp");
|
||||
this.playerTeleporter = this.plugin.getSafeTTeleporter();
|
||||
this.setPermission(menu);
|
||||
}
|
||||
|
||||
private static final int UNSAFE_TELEPORT_EXPIRE_DELAY = 15;
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
CommandSender teleporter = sender;
|
||||
Player teleportee = null;
|
||||
|
||||
String destinationName;
|
||||
|
||||
if (args.size() == 2) {
|
||||
teleportee = PlayerFinder.get(args.get(0), sender);
|
||||
if (teleportee == null) {
|
||||
this.messaging.sendMessage(sender, String.format("Sorry, I couldn't find player: %s%s",
|
||||
ChatColor.GOLD, args.get(0)), false);
|
||||
return;
|
||||
}
|
||||
destinationName = args.get(1);
|
||||
|
||||
} else {
|
||||
destinationName = args.get(0);
|
||||
if (!(sender instanceof Player)) {
|
||||
this.messaging.sendMessage(sender, String.format("From the console, you must specify a player to teleport"), false);
|
||||
return;
|
||||
}
|
||||
teleportee = (Player) sender;
|
||||
}
|
||||
|
||||
DestinationFactory df = this.plugin.getDestFactory();
|
||||
MVDestination d = df.getPlayerAwareDestination(teleportee, destinationName);
|
||||
|
||||
MVTeleportEvent teleportEvent = new MVTeleportEvent(d, teleportee, teleporter, true);
|
||||
this.plugin.getServer().getPluginManager().callEvent(teleportEvent);
|
||||
if (teleportEvent.isCancelled()) {
|
||||
Logging.fine("Someone else cancelled the MVTeleport Event!!!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (d != null && d instanceof InvalidDestination) {
|
||||
this.messaging.sendMessage(sender, String.format("Multiverse does not know how to take you to %s%s",
|
||||
ChatColor.RED, destinationName), false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.checkSendPermissions(teleporter, teleportee, d)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.getMVConfig().getEnforceAccess() && teleporter != null && !this.plugin.getMVPerms().canEnterDestination(teleporter, d)) {
|
||||
if (teleportee.equals(teleporter)) {
|
||||
teleporter.sendMessage("Doesn't look like you're allowed to go " + ChatColor.RED + "there...");
|
||||
} else {
|
||||
teleporter.sendMessage("Doesn't look like you're allowed to send " + ChatColor.GOLD
|
||||
+ teleportee.getName() + ChatColor.WHITE + " to " + ChatColor.RED + "there...");
|
||||
}
|
||||
return;
|
||||
} else if (teleporter != null && !this.plugin.getMVPerms().canTravelFromLocation(teleporter, d.getLocation(teleportee))) {
|
||||
if (teleportee.equals(teleporter)) {
|
||||
this.messaging.sendMessage(teleporter, String.format("DOH! Doesn't look like you can get to %s%s %sfrom where you are...",
|
||||
ChatColor.GREEN, d.toString(), ChatColor.WHITE), false);
|
||||
} else {
|
||||
this.messaging.sendMessage(teleporter, String.format("DOH! Doesn't look like %s%s %scan get to %sTHERE from where they are...",
|
||||
ChatColor.GREEN, ((Player) teleporter).getWorld().getName(), ChatColor.WHITE, ChatColor.RED), false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Special check to verify if players are tryint to teleport to the same
|
||||
// WORLDDestination as the world they're in, that they ALSO have multiverse.core.spawn.self
|
||||
|
||||
if (d instanceof WorldDestination) {
|
||||
World w = d.getLocation(teleportee).getWorld();
|
||||
if (teleportee.getWorld().equals(w)) {
|
||||
if (teleporter.equals(teleportee)) {
|
||||
if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.core.spawn.self", true)) {
|
||||
this.messaging.sendMessages(teleporter, new String[]{
|
||||
String.format("Sorry you don't have permission to go to the world spawn!"),
|
||||
String.format("%s (multiverse.core.spawn.self)",
|
||||
ChatColor.RED) }, false);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.core.spawn.other", true)) {
|
||||
this.messaging.sendMessages(teleporter, new String[]{
|
||||
String.format("Sorry you don't have permission to send %s to the world spawn!",
|
||||
teleportee.getDisplayName()),
|
||||
String.format("%s (multiverse.core.spawn.other)",
|
||||
ChatColor.RED) }, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (d.getLocation(teleportee) == null) {
|
||||
this.messaging.sendMessage(teleporter, "Sorry Boss, I tried everything, but just couldn't teleport ya there!", false);
|
||||
return;
|
||||
}
|
||||
Teleporter teleportObject = (d instanceof CustomTeleporterDestination) ?
|
||||
((CustomTeleporterDestination)d).getTeleporter() : this.playerTeleporter;
|
||||
TeleportResult result = teleportObject.teleport(teleporter, teleportee, d);
|
||||
if (result == TeleportResult.FAIL_UNSAFE) {
|
||||
Logging.fine("Could not teleport " + teleportee.getName()
|
||||
+ " to " + plugin.getLocationManipulation().strCoordsRaw(d.getLocation(teleportee)));
|
||||
|
||||
String player = "you";
|
||||
if (!teleportee.equals(teleporter)) {
|
||||
player = teleportee.getName();
|
||||
}
|
||||
|
||||
this.plugin.getCommandQueueManager().addToQueue(new QueuedCommand(
|
||||
sender,
|
||||
doUnsafeTeleport(teleporter, teleportee, d.getLocation(teleportee)),
|
||||
String.format("%sMultiverse %sdid not teleport %s%s %sto %s%s %sbecause it was unsafe. Would you like to try anyway?",
|
||||
ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, player, ChatColor.WHITE, ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE),
|
||||
UNSAFE_TELEPORT_EXPIRE_DELAY
|
||||
));
|
||||
}
|
||||
// else: Player was teleported successfully (or the tp event was fired I should say)
|
||||
}
|
||||
|
||||
private Runnable doUnsafeTeleport(CommandSender teleporter, Player player, Location location) {
|
||||
return () -> this.plugin.getSafeTTeleporter().safelyTeleport(teleporter, player, location, false);
|
||||
}
|
||||
|
||||
private boolean checkSendPermissions(CommandSender teleporter, Player teleportee, MVDestination destination) {
|
||||
if (teleporter.equals(teleportee)) {
|
||||
if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.teleport.self." + destination.getIdentifier(), true)) {
|
||||
this.messaging.sendMessages(teleporter, new String[]{
|
||||
String.format("%sYou don't have permission to teleport %syourself %sto a %s%s %sDestination",
|
||||
ChatColor.WHITE, ChatColor.AQUA, ChatColor.WHITE, ChatColor.RED, destination.getType(), ChatColor.WHITE),
|
||||
String.format("%s (multiverse.teleport.self.%s)",
|
||||
ChatColor.RED, destination.getIdentifier()) }, false);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.teleport.other." + destination.getIdentifier(), true)) {
|
||||
this.messaging.sendMessages(teleporter, new String[]{
|
||||
String.format("You don't have permission to teleport another player to a %s%s Destination.",
|
||||
ChatColor.GREEN, destination.getType()),
|
||||
String.format("%s(multiverse.teleport.other.%s)",
|
||||
ChatColor.RED, destination.getIdentifier()) }, false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,24 +1,52 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import co.aikar.commands.BukkitCommandCompletionContext;
|
||||
import co.aikar.commands.BukkitCommandIssuer;
|
||||
import co.aikar.commands.PaperCommandCompletions;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MVCommandCompletions extends PaperCommandCompletions {
|
||||
protected final MVCommandManager commandManager;
|
||||
private final MultiverseCore plugin;
|
||||
|
||||
public MVCommandCompletions(MVCommandManager mvCommandManager) {
|
||||
public MVCommandCompletions(MVCommandManager mvCommandManager, MultiverseCore plugin) {
|
||||
super(mvCommandManager);
|
||||
this.commandManager = mvCommandManager;
|
||||
this.plugin = plugin;
|
||||
|
||||
registerAsyncCompletion("destinations", this::suggestDestinations);
|
||||
registerAsyncCompletion("flags", this::suggestFlags);
|
||||
registerAsyncCompletion("mvworlds", this::suggestMVWorlds);
|
||||
}
|
||||
|
||||
private Collection<String> suggestDestinations(BukkitCommandCompletionContext context) {
|
||||
if (context.hasConfig("playeronly") && !context.getIssuer().isPlayer()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return this.plugin.getDestinationsProvider()
|
||||
.suggestDestinations((BukkitCommandIssuer)context.getIssuer(), context.getInput());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<String> suggestFlags(@NotNull BukkitCommandCompletionContext context) {
|
||||
return this.commandManager.getFlagsManager().suggest(
|
||||
context.getConfig("groupName", ""), context.getContextValue(String[].class));
|
||||
}
|
||||
|
||||
private Collection<String> suggestMVWorlds(BukkitCommandCompletionContext context) {
|
||||
if (context.hasConfig("playeronly") && !context.getIssuer().isPlayer()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return this.plugin.getMVWorldManager().getMVWorlds()
|
||||
.stream()
|
||||
.map(MultiverseWorld::getName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,80 @@
|
||||
package com.onarandombox.MultiverseCore.commandtools;
|
||||
|
||||
import co.aikar.commands.BukkitCommandExecutionContext;
|
||||
import co.aikar.commands.InvalidCommandArgument;
|
||||
import co.aikar.commands.PaperCommandContexts;
|
||||
import com.google.common.base.Strings;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.destination.ParsedDestination;
|
||||
import com.onarandombox.MultiverseCore.utils.PlayerFinder;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class MVCommandContexts extends PaperCommandContexts {
|
||||
public MVCommandContexts(MVCommandManager mvCommandManager) {
|
||||
private final MultiverseCore plugin;
|
||||
|
||||
public MVCommandContexts(MVCommandManager mvCommandManager, MultiverseCore plugin) {
|
||||
super(mvCommandManager);
|
||||
this.plugin = plugin;
|
||||
|
||||
registerContext(ParsedDestination.class, this::parseDestination);
|
||||
registerIssuerAwareContext(Player.class, this::parsePlayer);
|
||||
}
|
||||
|
||||
private ParsedDestination<?> parseDestination(BukkitCommandExecutionContext context) {
|
||||
String destination = context.popFirstArg();
|
||||
if (Strings.isNullOrEmpty(destination)) {
|
||||
throw new InvalidCommandArgument("No destination specified.");
|
||||
}
|
||||
|
||||
ParsedDestination<?> parsedDestination = plugin.getDestinationsProvider().parseDestination(destination);
|
||||
if (parsedDestination == null) {
|
||||
throw new InvalidCommandArgument("The destination " + destination + " is not valid.");
|
||||
}
|
||||
|
||||
return parsedDestination;
|
||||
}
|
||||
|
||||
private Player parsePlayer(BukkitCommandExecutionContext context) {
|
||||
String resolve = context.getFlagValue("resolve", "");
|
||||
|
||||
// Get player based on sender only
|
||||
if (resolve.equals("issueronly")) {
|
||||
if (context.getIssuer().isPlayer()) {
|
||||
return context.getIssuer().getPlayer();
|
||||
}
|
||||
if (context.isOptional()) {
|
||||
return null;
|
||||
}
|
||||
throw new InvalidCommandArgument("This command can only be used by a player.");
|
||||
}
|
||||
|
||||
String playerIdentifier = context.getFirstArg();
|
||||
Player player = PlayerFinder.get(playerIdentifier, context.getSender());
|
||||
|
||||
// Get player based on input, fallback to sender if input is not a player
|
||||
if (resolve.equals("issueraware")) {
|
||||
if (player != null) {
|
||||
context.popFirstArg();
|
||||
return player;
|
||||
}
|
||||
if (context.getIssuer().isPlayer()) {
|
||||
return context.getIssuer().getPlayer();
|
||||
}
|
||||
if (context.isOptional()) {
|
||||
return null;
|
||||
}
|
||||
throw new InvalidCommandArgument("Invalid player: " + playerIdentifier
|
||||
+ ". Either specify an online player or use this command as a player.");
|
||||
}
|
||||
|
||||
// Get player based on input only
|
||||
if (player != null) {
|
||||
context.popFirstArg();
|
||||
return player;
|
||||
}
|
||||
if (!context.isOptional()) {
|
||||
return null;
|
||||
}
|
||||
throw new InvalidCommandArgument("Player " + playerIdentifier + " not found.");
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public class MVCommandManager extends PaperCommandManager {
|
||||
@Override
|
||||
public synchronized @NotNull CommandContexts<BukkitCommandExecutionContext> getCommandContexts() {
|
||||
if (this.contexts == null) {
|
||||
this.contexts = new MVCommandContexts(this);
|
||||
this.contexts = new MVCommandContexts(this, plugin);
|
||||
}
|
||||
return this.contexts;
|
||||
}
|
||||
@ -62,7 +62,7 @@ public class MVCommandManager extends PaperCommandManager {
|
||||
@Override
|
||||
public synchronized @NotNull CommandCompletions<BukkitCommandCompletionContext> getCommandCompletions() {
|
||||
if (this.completions == null) {
|
||||
this.completions = new MVCommandCompletions(this);
|
||||
this.completions = new MVCommandCompletions(this, plugin);
|
||||
}
|
||||
return this.completions;
|
||||
}
|
||||
|
@ -1,148 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An anchor-{@link MVDestination}.
|
||||
*/
|
||||
public class AnchorDestination implements MVDestination {
|
||||
private boolean isValid;
|
||||
private Location location;
|
||||
private MultiverseCore plugin;
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "a";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Vector getVelocity() {
|
||||
return new Vector(0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isThisType(JavaPlugin plugin, String destination) {
|
||||
if (!(plugin instanceof MultiverseCore)) {
|
||||
return false;
|
||||
}
|
||||
this.plugin = (MultiverseCore) plugin;
|
||||
List<String> parsed = Arrays.asList(destination.split(":"));
|
||||
// Need at least: a:name
|
||||
if (!(parsed.size() == 2)) {
|
||||
return false;
|
||||
}
|
||||
// If it's not an Anchor type
|
||||
return parsed.get(0).equalsIgnoreCase("a");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation(Entity e) {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return this.isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setDestination(JavaPlugin plugin, String destination) {
|
||||
if (!(plugin instanceof MultiverseCore)) {
|
||||
return;
|
||||
}
|
||||
this.plugin = (MultiverseCore) plugin;
|
||||
List<String> parsed = Arrays.asList(destination.split(":"));
|
||||
// Need at least: e:world:x,y,z
|
||||
// OR e:world:x,y,z:pitch:yaw
|
||||
// so basically 3 or 5
|
||||
if (!(parsed.size() == 2)) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
this.name = parsed.get(1);
|
||||
this.location = this.plugin.getAnchorManager().getAnchorLocation(parsed.get(1));
|
||||
if (this.location == null) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
if (!parsed.get(0).equalsIgnoreCase(this.getIdentifier())) {
|
||||
this.isValid = false;
|
||||
}
|
||||
this.isValid = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getType() {
|
||||
return "Anchor";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Anchor: " + this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (isValid) {
|
||||
return "a:" + this.name;
|
||||
}
|
||||
return "i:Invalid Destination";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getRequiredPermission() {
|
||||
return "multiverse.access." + this.location.getWorld().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean useSafeTeleporter() {
|
||||
// This is an ANCHOR destination, don't safely teleport here.
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,141 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
/**
|
||||
* A bed-{@link MVDestination}.
|
||||
*/
|
||||
public class BedDestination implements MVDestination {
|
||||
public static final String OWN_BED_STRING = "playerbed";
|
||||
private String playername = "";
|
||||
private boolean isValid;
|
||||
private Location knownBedLoc;
|
||||
private MultiverseCore plugin;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "b";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isThisType(JavaPlugin plugin, String destination) {
|
||||
String[] split = destination.split(":");
|
||||
boolean validFormat = split.length >= 1 && split.length <= 2 && split[0].equals(this.getIdentifier());
|
||||
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(split[1]);
|
||||
boolean validPlayer = p.getName() != null && !p.getName().equals(OWN_BED_STRING);
|
||||
|
||||
if (validFormat && validPlayer) this.playername = p.getName();
|
||||
|
||||
this.isValid = destination.equals("b:" + OWN_BED_STRING) || (validFormat && validPlayer);
|
||||
|
||||
return this.isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation(Entity entity) {
|
||||
if (entity instanceof Player) {
|
||||
if (this.playername.isEmpty())
|
||||
this.knownBedLoc = this.plugin.getBlockSafety().getSafeBedSpawn(((Player) entity).getBedSpawnLocation());
|
||||
else
|
||||
this.knownBedLoc = this.plugin.getBlockSafety().getSafeBedSpawn(Bukkit.getOfflinePlayer(this.playername).getBedSpawnLocation());
|
||||
|
||||
if (this.knownBedLoc == null) {
|
||||
((Player) entity).sendMessage("The bed was " + ChatColor.RED + "invalid or blocked" + ChatColor.RESET + ". Sorry.");
|
||||
}
|
||||
return this.knownBedLoc;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Vector getVelocity() {
|
||||
return new Vector();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setDestination(JavaPlugin plugin, String destination) {
|
||||
this.plugin = (MultiverseCore) plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return this.isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getType() {
|
||||
return "Bed";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Bed";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getRequiredPermission() {
|
||||
if (knownBedLoc != null) {
|
||||
return "multiverse.access." + knownBedLoc.getWorld().getName();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean useSafeTeleporter() {
|
||||
// Bukkit should have already checked this.
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "b:" + (playername.isEmpty() ? OWN_BED_STRING : playername);
|
||||
}
|
||||
}
|
@ -1,227 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A cannon-{@link MVDestination}.
|
||||
*/
|
||||
public class CannonDestination implements MVDestination {
|
||||
private final String coordRegex = "(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*)";
|
||||
private boolean isValid;
|
||||
private Location location;
|
||||
private double speed;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Vector getVelocity() {
|
||||
double pitchRadians = Math.toRadians(location.getPitch());
|
||||
double yawRadians = Math.toRadians(location.getYaw());
|
||||
double x = Math.sin(yawRadians) * speed * -1;
|
||||
double y = Math.sin(pitchRadians) * speed * -1;
|
||||
double z = Math.cos(yawRadians) * speed;
|
||||
// Account for the angle they were pointed, and take away velocity
|
||||
x = Math.cos(pitchRadians) * x;
|
||||
z = Math.cos(pitchRadians) * z;
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "ca";
|
||||
}
|
||||
|
||||
// NEED ca:world:x,y,z:pitch:yaw:speed
|
||||
// so basically 6
|
||||
private static final int SPLIT_SIZE = 6;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isThisType(JavaPlugin plugin, String destination) {
|
||||
if (!(plugin instanceof MultiverseCore)) {
|
||||
return false;
|
||||
}
|
||||
List<String> parsed = Arrays.asList(destination.split(":"));
|
||||
if (parsed.size() != SPLIT_SIZE) {
|
||||
return false;
|
||||
}
|
||||
// If it's not an Cannon type
|
||||
if (!parsed.get(0).equalsIgnoreCase("ca")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If it's not a MV world
|
||||
if (!((MultiverseCore) plugin).getMVWorldManager().isMVWorld(parsed.get(1))) {
|
||||
return false;
|
||||
}
|
||||
// Verify X,Y,Z are numbers
|
||||
if (!parsed.get(2).matches(coordRegex)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
Float.parseFloat(parsed.get(3));
|
||||
Float.parseFloat(parsed.get(4));
|
||||
Float.parseFloat(parsed.get(5));
|
||||
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation(Entity e) {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return this.isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setDestination(JavaPlugin plugin, String destination) {
|
||||
if (!(plugin instanceof MultiverseCore)) {
|
||||
return;
|
||||
}
|
||||
List<String> parsed = Arrays.asList(destination.split(":"));
|
||||
|
||||
if (parsed.size() != SPLIT_SIZE) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
if (!parsed.get(0).equalsIgnoreCase(this.getIdentifier())) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!((MultiverseCore) plugin).getMVWorldManager().isMVWorld(parsed.get(1))) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this.location = new Location(((MultiverseCore) plugin).getMVWorldManager().getMVWorld(parsed.get(1)).getCBWorld(), 0, 0, 0);
|
||||
|
||||
if (!parsed.get(2).matches(this.coordRegex)) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
double[] coords = new double[3];
|
||||
String[] coordString = parsed.get(2).split(",");
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
coords[i] = Double.parseDouble(coordString[i]);
|
||||
} catch (NumberFormatException e) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.location.setX(coords[0]);
|
||||
this.location.setY(coords[1]);
|
||||
this.location.setZ(coords[2]);
|
||||
|
||||
try {
|
||||
// BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
this.location.setPitch(Float.parseFloat(parsed.get(3)));
|
||||
this.location.setYaw(Float.parseFloat(parsed.get(4)));
|
||||
this.speed = Math.abs(Float.parseFloat(parsed.get(5)));
|
||||
// END CHECKSTYLE-SUPPRESSION: MagicNumberCheck
|
||||
} catch (NumberFormatException e) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this.isValid = true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getType() {
|
||||
return "Cannon!";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Cannon (" + this.location.getX() + ", " + this.location.getY() + ", " + this.location.getZ() + ":"
|
||||
+ this.location.getPitch() + ":" + this.location.getYaw() + ":" + this.speed + ")";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this {@link CannonDestination}.
|
||||
*
|
||||
* @param location The {@link Location}.
|
||||
* @param speed The speed.
|
||||
*/
|
||||
public void setDestination(Location location, double speed) {
|
||||
if (location != null) {
|
||||
this.location = location;
|
||||
this.speed = Math.abs(speed);
|
||||
this.isValid = true;
|
||||
}
|
||||
this.isValid = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getRequiredPermission() {
|
||||
return "multiverse.access." + this.location.getWorld().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean useSafeTeleporter() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (isValid) {
|
||||
return "ca:" + location.getWorld().getName() + ":" + location.getX() + "," + location.getY()
|
||||
+ "," + location.getZ() + ":" + location.getPitch() + ":" + location.getYaw() + ":" + this.speed;
|
||||
}
|
||||
return "i:Invalid Destination";
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.Teleporter;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public abstract class CustomTeleporterDestination implements MVDestination {
|
||||
@Override
|
||||
public final Location getLocation(final Entity entity) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Vector getVelocity() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean useSafeTeleporter() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract String toString();
|
||||
|
||||
public abstract Teleporter getTeleporter();
|
||||
}
|
@ -1,177 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.commandsold.TeleportCommand;
|
||||
import com.onarandombox.MultiverseCore.utils.PermissionTools;
|
||||
import com.onarandombox.MultiverseCore.utils.PlayerFinder;
|
||||
import com.pneumaticraft.commandhandler.Command;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* A factory class that will create destinations from specific strings.
|
||||
*/
|
||||
public class DestinationFactory {
|
||||
|
||||
private static final Pattern CANNON_PATTERN = Pattern.compile("(?i)cannon-[\\d]+(\\.[\\d]+)?");
|
||||
|
||||
private MultiverseCore plugin;
|
||||
private Map<String, Class<? extends MVDestination>> destList;
|
||||
private Command teleportCommand;
|
||||
|
||||
public DestinationFactory(MultiverseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
this.destList = new HashMap<String, Class<? extends MVDestination>>();
|
||||
List<Command> cmds = this.plugin.getCommandHandler().getAllCommands();
|
||||
for (Command c : cmds) {
|
||||
if (c instanceof TeleportCommand) {
|
||||
this.teleportCommand = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a destination that has relation to sender, such as a cannon or player destination.
|
||||
*
|
||||
* @param teleportee The player that is going to be teleported.
|
||||
* @param destinationName The destination to parse.
|
||||
* @return A non-null MVDestination
|
||||
*/
|
||||
@NotNull
|
||||
public MVDestination getPlayerAwareDestination(@NotNull Player teleportee,
|
||||
@NotNull String destinationName) {
|
||||
|
||||
// Prioritise world, in the event that a world is named after a player online.
|
||||
if (Bukkit.getWorld(destinationName) != null) {
|
||||
return getDestination(destinationName);
|
||||
}
|
||||
|
||||
Player targetPlayer = PlayerFinder.get(destinationName, teleportee);
|
||||
if (targetPlayer != null) {
|
||||
return getDestination("pl:" + targetPlayer.getName());
|
||||
}
|
||||
|
||||
if (CANNON_PATTERN.matcher(destinationName).matches()) {
|
||||
return getDestination(parseCannonDest(teleportee, destinationName));
|
||||
}
|
||||
|
||||
return getDestination(destinationName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a cannon destination.
|
||||
*
|
||||
* @param teleportee The player that is going to be teleported.
|
||||
* @param destinationName The destination to parse.
|
||||
* @return A destination string.
|
||||
*/
|
||||
@NotNull
|
||||
private String parseCannonDest(@NotNull Player teleportee,
|
||||
@NotNull String destinationName) {
|
||||
|
||||
String[] cannonSpeed = destinationName.split("-");
|
||||
try {
|
||||
double speed = Double.parseDouble(cannonSpeed[1]);
|
||||
destinationName = "ca:" + teleportee.getWorld().getName() + ":" + teleportee.getLocation().getX()
|
||||
+ "," + teleportee.getLocation().getY() + "," + teleportee.getLocation().getZ() + ":"
|
||||
+ teleportee.getLocation().getPitch() + ":" + teleportee.getLocation().getYaw() + ":" + speed;
|
||||
}
|
||||
catch (Exception e) {
|
||||
destinationName = "i:invalid";
|
||||
}
|
||||
|
||||
return destinationName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a new destination from a string.
|
||||
* Returns a new InvalidDestination if the string could not be parsed.
|
||||
*
|
||||
* @param destination The destination in string format.
|
||||
*
|
||||
* @return A non-null MVDestination
|
||||
*/
|
||||
public MVDestination getDestination(String destination) {
|
||||
String idenChar = "";
|
||||
if (destination.split(":").length > 1) {
|
||||
idenChar = destination.split(":")[0];
|
||||
}
|
||||
|
||||
if (this.destList.containsKey(idenChar)) {
|
||||
Class<? extends MVDestination> myClass = this.destList.get(idenChar);
|
||||
try {
|
||||
MVDestination mydest = myClass.newInstance();
|
||||
if (!mydest.isThisType(this.plugin, destination)) {
|
||||
return new InvalidDestination();
|
||||
}
|
||||
mydest.setDestination(this.plugin, destination);
|
||||
return mydest;
|
||||
} catch (InstantiationException e) {
|
||||
} catch (IllegalAccessException e) {
|
||||
}
|
||||
}
|
||||
return new InvalidDestination();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a {@link MVDestination}.
|
||||
*
|
||||
* @param c The {@link Class} of the {@link MVDestination} to register.
|
||||
* @param identifier The {@link String}-identifier.
|
||||
* @return True if the class was successfully registered.
|
||||
*/
|
||||
public boolean registerDestinationType(Class<? extends MVDestination> c, String identifier) {
|
||||
if (this.destList.containsKey(identifier)) {
|
||||
return false;
|
||||
}
|
||||
this.destList.put(identifier, c);
|
||||
// Special case for world defaults:
|
||||
if (identifier.equals("")) {
|
||||
identifier = "w";
|
||||
}
|
||||
Permission self = this.plugin.getServer().getPluginManager().getPermission("multiverse.teleport.self." + identifier);
|
||||
Permission other = this.plugin.getServer().getPluginManager().getPermission("multiverse.teleport.other." + identifier);
|
||||
PermissionTools pt = new PermissionTools(this.plugin);
|
||||
if (self == null) {
|
||||
self = new Permission("multiverse.teleport.self." + identifier,
|
||||
"Permission to teleport yourself for the " + identifier + " destination.", PermissionDefault.OP);
|
||||
this.plugin.getServer().getPluginManager().addPermission(self);
|
||||
pt.addToParentPerms("multiverse.teleport.self." + identifier);
|
||||
}
|
||||
if (other == null) {
|
||||
other = new Permission("multiverse.teleport.other." + identifier,
|
||||
"Permission to teleport others for the " + identifier + " destination.", PermissionDefault.OP);
|
||||
this.plugin.getServer().getPluginManager().addPermission(other);
|
||||
pt.addToParentPerms("multiverse.teleport.other." + identifier);
|
||||
}
|
||||
this.teleportCommand.addAdditonalPermission(self);
|
||||
this.teleportCommand.addAdditonalPermission(other);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the {@link MVDestination} identifiers registered.
|
||||
*
|
||||
* @return A collection of destination identifiers.
|
||||
*/
|
||||
public Collection<String> getRegisteredIdentifiers() {
|
||||
return this.destList.keySet();
|
||||
}
|
||||
}
|
@ -0,0 +1,208 @@
|
||||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import co.aikar.commands.BukkitCommandIssuer;
|
||||
import co.aikar.commands.CommandIssuer;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.Destination;
|
||||
import com.onarandombox.MultiverseCore.api.DestinationInstance;
|
||||
import com.onarandombox.MultiverseCore.api.Teleporter;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Provides destinations for teleportation.
|
||||
*/
|
||||
public class DestinationsProvider {
|
||||
private static final String SEPARATOR = ":";
|
||||
private static final String PERMISSION_PREFIX = "multiverse.teleport.";
|
||||
|
||||
private final MultiverseCore plugin;
|
||||
private final Map<String, Destination<?>> destinationMap;
|
||||
|
||||
/**
|
||||
* Creates a new destinations provider.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
public DestinationsProvider(@NotNull MultiverseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
this.destinationMap = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a destination to the provider.
|
||||
*
|
||||
* @param destination The destination.
|
||||
*/
|
||||
public void registerDestination(@NotNull Destination<?> destination) {
|
||||
this.destinationMap.put(destination.getIdentifier(), destination);
|
||||
this.registerDestinationPerms(destination);
|
||||
}
|
||||
|
||||
private void registerDestinationPerms(@NotNull Destination<?> destination) {
|
||||
PluginManager pluginManager = this.plugin.getServer().getPluginManager();
|
||||
pluginManager.addPermission(new Permission(PERMISSION_PREFIX + "self." + destination.getIdentifier()));
|
||||
pluginManager.addPermission(new Permission(PERMISSION_PREFIX + "other." + destination.getIdentifier()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Suggest tab completions for a destination string.
|
||||
*
|
||||
* @param issuer The command issuer.
|
||||
* @param deststring The current destination string.
|
||||
* @return A collection of tab completions.
|
||||
*/
|
||||
public @NotNull Collection<String> suggestDestinations(@NotNull BukkitCommandIssuer issuer,
|
||||
@Nullable String deststring
|
||||
) {
|
||||
return destinationMap.values().stream()
|
||||
.filter(destination -> issuer.hasPermission(PERMISSION_PREFIX + "self." + destination.getIdentifier())
|
||||
|| issuer.hasPermission(PERMISSION_PREFIX + "other." + destination.getIdentifier()))
|
||||
.map(destination -> destination.suggestDestinations(issuer, deststring).stream()
|
||||
.map(s -> destination.getIdentifier() + SEPARATOR + s)
|
||||
.collect(Collectors.toList()))
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a destination string to a destination object.
|
||||
*
|
||||
* @param destinationString The destination string.
|
||||
* @return The destination object, or null if invalid format.
|
||||
*/
|
||||
public ParsedDestination<?> parseDestination(String destinationString) {
|
||||
String[] items = destinationString.split(SEPARATOR, 2);
|
||||
|
||||
String idString = items[0];
|
||||
String destinationParams;
|
||||
Destination<?> destination;
|
||||
|
||||
if (items.length < 2) {
|
||||
// Assume world destination
|
||||
destination = this.getDestinationById("w");
|
||||
destinationParams = items[0];
|
||||
} else {
|
||||
destination = this.getDestinationById(idString);
|
||||
destinationParams = items[1];
|
||||
}
|
||||
|
||||
if (destination == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
DestinationInstance destinationInstance = destination.getDestinationInstance(destinationParams);
|
||||
if (destinationInstance == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ParsedDestination<>(destination, destinationInstance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a destination by its identifier.
|
||||
*
|
||||
* @param identifier The identifier.
|
||||
* @return The destination, or null if not found.
|
||||
*/
|
||||
public @Nullable Destination<?> getDestinationById(@Nullable String identifier) {
|
||||
return this.destinationMap.get(identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports the teleportee to the destination.
|
||||
*
|
||||
* @param teleporter The teleporter.
|
||||
* @param teleportee The teleportee.
|
||||
* @param destination The destination.
|
||||
*/
|
||||
public void playerTeleport(@NotNull BukkitCommandIssuer teleporter,
|
||||
@NotNull Player teleportee,
|
||||
@NotNull ParsedDestination<?> destination
|
||||
) {
|
||||
if (!checkTeleportPermissions(teleporter, teleportee, destination)) {
|
||||
return;
|
||||
}
|
||||
teleport(teleporter, teleportee, destination);
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports the teleportee to the destination.
|
||||
*
|
||||
* @param teleporter The teleporter.
|
||||
* @param teleportee The teleportee.
|
||||
* @param destination The destination.
|
||||
*/
|
||||
public void teleport(@NotNull BukkitCommandIssuer teleporter,
|
||||
@NotNull Entity teleportee,
|
||||
@NotNull ParsedDestination<?> destination
|
||||
) {
|
||||
Teleporter teleportHandler = destination.getDestination().getTeleporter();
|
||||
if (teleportHandler == null) {
|
||||
teleportHandler = this.plugin.getSafeTTeleporter();
|
||||
}
|
||||
teleportHandler.teleport(teleporter, teleportee, destination);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the teleporter has permission to teleport the teleportee to the destination.
|
||||
*
|
||||
* @param teleporter The teleporter.
|
||||
* @param teleportee The teleportee.
|
||||
* @param destination The destination.
|
||||
* @return True if the teleporter has permission, false otherwise.
|
||||
*/
|
||||
public boolean checkTeleportPermissions(CommandIssuer teleporter, Entity teleportee, ParsedDestination<?> destination) {
|
||||
//TODO Move permission checking to a separate class
|
||||
String permission = PERMISSION_PREFIX
|
||||
+ (teleportee.equals(teleporter.getIssuer()) ? "self" : "other") + "."
|
||||
+ destination.getDestination().getIdentifier();
|
||||
if (!teleporter.hasPermission(permission)) {
|
||||
teleporter.sendMessage("You don't have permission to teleport to this destination.");
|
||||
return false;
|
||||
}
|
||||
|
||||
//TODO Config whether to use finer permission
|
||||
String finerPermissionSuffix = destination.getDestinationInstance().getFinerPermissionSuffix();
|
||||
if (finerPermissionSuffix == null || finerPermissionSuffix.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String finerPermission = permission + "." + finerPermissionSuffix;
|
||||
if (!teleporter.hasPermission(finerPermission)) {
|
||||
teleporter.sendMessage("You don't have permission to teleport to this destination.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the issuer has permission to teleport to at least one destination.
|
||||
*
|
||||
* @param issuer The issuer.
|
||||
* @return True if the issuer has permission, false otherwise.
|
||||
*/
|
||||
public boolean hasAnyTeleportPermission(CommandIssuer issuer) {
|
||||
for (Destination<?> destination : this.destinationMap.values()) {
|
||||
String permission = PERMISSION_PREFIX + "self." + destination.getIdentifier();
|
||||
if (issuer.hasPermission(permission)) {
|
||||
return true;
|
||||
}
|
||||
permission = PERMISSION_PREFIX + "other." + destination.getIdentifier();
|
||||
if (issuer.hasPermission(permission)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,263 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An exact {@link MVDestination}.
|
||||
*/
|
||||
public class ExactDestination implements MVDestination {
|
||||
private final String coordRegex = "(-?[\\d]+\\.?[\\d]*|~-?[\\d]+\\.?[\\d]*|~),(-?[\\d]+\\.?[\\d]*|~-?[\\d]+\\.?[\\d]*|~),(-?[\\d]+\\.?[\\d]*|~-?[\\d]+\\.?[\\d]*|~)";
|
||||
private boolean isValid;
|
||||
private Location location;
|
||||
private boolean relativeX, relativeY, relativeZ;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "e";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Vector getVelocity() {
|
||||
return new Vector(0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isThisType(JavaPlugin plugin, String destination) {
|
||||
if (!(plugin instanceof MultiverseCore)) {
|
||||
return false;
|
||||
}
|
||||
List<String> parsed = Arrays.asList(destination.split(":"));
|
||||
// Need at least: e:world:x,y,z
|
||||
// OR e:world:x,y,z:pitch:yaw
|
||||
// so basically 3 or 5
|
||||
if (!(parsed.size() == 3 || parsed.size() == 5)) { // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
return false;
|
||||
}
|
||||
// If it's not an Exact type
|
||||
if (!parsed.get(0).equalsIgnoreCase("e")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If it's not a MV world
|
||||
if (!((MultiverseCore) plugin).getMVWorldManager().isMVWorld(parsed.get(1))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parsed.get(2).matches(coordRegex)) {
|
||||
return false;
|
||||
}
|
||||
// This is 1 now, because we've removed 2
|
||||
if (parsed.size() == 3) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
Float.parseFloat(parsed.get(3));
|
||||
Float.parseFloat(parsed.get(4)); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation(Entity e) {
|
||||
Location loc = this.location.clone();
|
||||
if (relativeX || relativeY || relativeZ) {
|
||||
Location eLoc = e.getLocation();
|
||||
loc.add(relativeX ? eLoc.getX() : 0, relativeY ? eLoc.getY() : 0, relativeZ ? eLoc.getZ() : 0);
|
||||
// Since the location is relative, it makes sense to use the entity's pitch and yaw unless those were
|
||||
// specified in the destination.
|
||||
if (loc.getPitch() == 0) {
|
||||
loc.setPitch(eLoc.getPitch());
|
||||
}
|
||||
if (loc.getYaw() == 0) {
|
||||
loc.setYaw(eLoc.getYaw());
|
||||
}
|
||||
}
|
||||
return loc;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return this.isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setDestination(JavaPlugin plugin, String destination) {
|
||||
if (!(plugin instanceof MultiverseCore)) {
|
||||
return;
|
||||
}
|
||||
List<String> parsed = Arrays.asList(destination.split(":"));
|
||||
// Need at least: e:world:x,y,z
|
||||
// OR e:world:x,y,z:pitch:yaw
|
||||
// so basically 3 or 5
|
||||
if (!(parsed.size() == 3 || parsed.size() == 5)) { // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!parsed.get(0).equalsIgnoreCase(this.getIdentifier())) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!((MultiverseCore) plugin).getMVWorldManager().isMVWorld(parsed.get(1))) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
this.location = new Location(((MultiverseCore) plugin).getMVWorldManager().getMVWorld(parsed.get(1)).getCBWorld(), 0, 0, 0);
|
||||
|
||||
if (!parsed.get(2).matches(this.coordRegex)) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
double[] coords = new double[3];
|
||||
String[] coordString = parsed.get(2).split(",");
|
||||
for (int i = 0; i < 3; i++) {
|
||||
String[] relSplit = coordString[i].split("~");
|
||||
boolean relative = false;
|
||||
if (relSplit.length == 0) {
|
||||
// coord is "~" form
|
||||
relative = true;
|
||||
coords[i] = 0;
|
||||
} else if (relSplit.length == 1) {
|
||||
// coord is "123" form
|
||||
try {
|
||||
coords[i] = Double.parseDouble(relSplit[0]);
|
||||
} catch (NumberFormatException e) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// coord is "~123" form
|
||||
relative = true;
|
||||
try {
|
||||
coords[i] = Double.parseDouble(relSplit[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (relative) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
relativeX = true;
|
||||
break;
|
||||
case 1:
|
||||
relativeY = true;
|
||||
break;
|
||||
case 2:
|
||||
relativeZ = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.location.setX(coords[0]);
|
||||
this.location.setY(coords[1]);
|
||||
this.location.setZ(coords[2]);
|
||||
|
||||
if (parsed.size() == 3) {
|
||||
this.isValid = true;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.location.setPitch(Float.parseFloat(parsed.get(3)));
|
||||
this.location.setYaw(Float.parseFloat(parsed.get(4))); // SUPPRESS CHECKSTYLE: MagicNumberCheck
|
||||
} catch (NumberFormatException e) {
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
this.isValid = true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getType() {
|
||||
return "Exact";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Exact (" + this.location.getX() + ", " + this.location.getY() + ", " + this.location.getZ()
|
||||
+ ":" + location.getPitch() + ":" + location.getYaw() + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this {@link ExactDestination}.
|
||||
*
|
||||
* @param location The {@link Location}.
|
||||
*/
|
||||
public void setDestination(Location location) {
|
||||
this.isValid = (this.location = location) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
if (isValid) {
|
||||
return "e:" + location.getWorld().getName() + ":" + location.getX() + "," + location.getY()
|
||||
+ "," + location.getZ() + ":" + location.getPitch() + ":" + location.getYaw();
|
||||
}
|
||||
return "i:Invalid Destination";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getRequiredPermission() {
|
||||
return "multiverse.access." + this.location.getWorld().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean useSafeTeleporter() {
|
||||
// This is an EXACT destination, don't safely teleport here.
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,107 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
/**
|
||||
* An invalid {@link MVDestination}.
|
||||
*/
|
||||
public class InvalidDestination implements MVDestination {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "i";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isThisType(JavaPlugin plugin, String destination) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation(Entity e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setDestination(JavaPlugin plugin, String destination) {
|
||||
// Nothing needed, it's invalid.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getType() {
|
||||
return ChatColor.RED + "Invalid Destination";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return ChatColor.RED + "Invalid Destination";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "i:Invalid Destination";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getRequiredPermission() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Vector getVelocity() {
|
||||
return new Vector(0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean useSafeTeleporter() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.Destination;
|
||||
import com.onarandombox.MultiverseCore.api.DestinationInstance;
|
||||
|
||||
/**
|
||||
* A parsed destination.
|
||||
*
|
||||
* @param <S> The destination instance type.
|
||||
*/
|
||||
public class ParsedDestination<S extends DestinationInstance> {
|
||||
private final Destination<S> destination;
|
||||
private final DestinationInstance destinationInstance;
|
||||
|
||||
/**
|
||||
* Creates a new parsed destination.
|
||||
*
|
||||
* @param destination The destination.
|
||||
* @param destinationInstance The destination instance.
|
||||
*/
|
||||
public ParsedDestination(Destination<S> destination, DestinationInstance destinationInstance) {
|
||||
this.destination = destination;
|
||||
this.destinationInstance = destinationInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the destination.
|
||||
*
|
||||
* @return The destination.
|
||||
*/
|
||||
public Destination<S> getDestination() {
|
||||
return destination;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the destination instance.
|
||||
*
|
||||
* @return The destination instance.
|
||||
*/
|
||||
public DestinationInstance getDestinationInstance() {
|
||||
return destinationInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts to saveable string representation of this destination.
|
||||
*
|
||||
* @return Serialized string.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return destination.getIdentifier() + ":" + destinationInstance.serialise();
|
||||
}
|
||||
}
|
@ -1,137 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
/**
|
||||
* A player-{@link MVDestination}.
|
||||
*/
|
||||
public class PlayerDestination implements MVDestination {
|
||||
private String player;
|
||||
private boolean isValid;
|
||||
private JavaPlugin plugin;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "pl";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isThisType(JavaPlugin plugin, String destination) {
|
||||
String[] items = destination.split(":");
|
||||
if (items.length != 2) {
|
||||
return false;
|
||||
}
|
||||
if (!items[0].equalsIgnoreCase("pl")) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation(Entity e) {
|
||||
Player p = plugin.getServer().getPlayerExact(this.player);
|
||||
Player plLoc = null;
|
||||
if (e instanceof Player) {
|
||||
plLoc = (Player) e;
|
||||
} else if (e.getPassenger() instanceof Player) {
|
||||
plLoc = (Player) e.getPassenger();
|
||||
}
|
||||
|
||||
if (p != null && plLoc != null) {
|
||||
return p.getLocation();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return this.isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setDestination(JavaPlugin plugin, String destination) {
|
||||
String[] items = destination.split(":");
|
||||
if (items.length != 2) {
|
||||
this.isValid = false;
|
||||
}
|
||||
if (!items[0].equalsIgnoreCase("pl")) {
|
||||
this.isValid = false;
|
||||
}
|
||||
this.isValid = true;
|
||||
this.player = items[1];
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getType() {
|
||||
return "Player";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "pl:" + this.player;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getRequiredPermission() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Vector getVelocity() {
|
||||
return new Vector(0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean useSafeTeleporter() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,173 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
|
||||
* Multiverse 2 is licensed under the BSD License. *
|
||||
* For more information please check the README.md file included *
|
||||
* with this project. *
|
||||
******************************************************************************/
|
||||
|
||||
package com.onarandombox.MultiverseCore.destination;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.Core;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
/**
|
||||
* A world-{@link MVDestination}.
|
||||
*/
|
||||
public class WorldDestination implements MVDestination {
|
||||
private boolean isValid;
|
||||
private MultiverseWorld world;
|
||||
private float yaw = -1;
|
||||
private String direction = "";
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "w";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isThisType(JavaPlugin plugin, String destination) {
|
||||
String[] items = destination.split(":");
|
||||
if (items.length > 3) {
|
||||
return false;
|
||||
}
|
||||
if (items.length == 1 && ((MultiverseCore) plugin).getMVWorldManager().isMVWorld(items[0])) {
|
||||
// This case is: world
|
||||
return true;
|
||||
}
|
||||
if (items.length == 2 && ((MultiverseCore) plugin).getMVWorldManager().isMVWorld(items[0])) {
|
||||
// This case is: world:n
|
||||
return true;
|
||||
} else if (items[0].equalsIgnoreCase("w") && ((MultiverseCore) plugin).getMVWorldManager().isMVWorld(items[1])) {
|
||||
// This case is: w:world
|
||||
// and w:world:ne
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation(Entity e) {
|
||||
Location spawnLoc = getAcurateSpawnLocation(e, this.world);
|
||||
if (this.yaw >= 0) {
|
||||
// Only modify the yaw if its set.
|
||||
spawnLoc.setYaw(this.yaw);
|
||||
}
|
||||
return spawnLoc;
|
||||
}
|
||||
|
||||
private static Location getAcurateSpawnLocation(Entity e, MultiverseWorld world) {
|
||||
if (world != null) {
|
||||
return world.getSpawnLocation();
|
||||
} else {
|
||||
// add 0.5 to x and z to center people
|
||||
// (spawn location is stored as int meaning that you would spawn in the corner of a block)
|
||||
return e.getWorld().getSpawnLocation().add(.5, 0, .5);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return this.isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setDestination(JavaPlugin plugin, String destination) {
|
||||
// TODO Taking a JavaPlugin here is rather useless, if we keep casting it up to MultiverseCore.
|
||||
// We should change that.
|
||||
Core core = (Core) plugin;
|
||||
String[] items = destination.split(":");
|
||||
if (items.length > 3) {
|
||||
isValid = false;
|
||||
return;
|
||||
}
|
||||
if (items.length == 1 && ((MultiverseCore) plugin).getMVWorldManager().isMVWorld(items[0])) {
|
||||
isValid = true;
|
||||
this.world = core.getMVWorldManager().getMVWorld(items[0]);
|
||||
return;
|
||||
}
|
||||
if (items.length == 2 && ((MultiverseCore) plugin).getMVWorldManager().isMVWorld(items[0])) {
|
||||
this.world = core.getMVWorldManager().getMVWorld(items[0]);
|
||||
this.yaw = core.getLocationManipulation().getYaw(items[1]);
|
||||
return;
|
||||
}
|
||||
if (items[0].equalsIgnoreCase("w") && ((MultiverseCore) plugin).getMVWorldManager().isMVWorld(items[1])) {
|
||||
this.world = ((MultiverseCore) plugin).getMVWorldManager().getMVWorld(items[1]);
|
||||
isValid = true;
|
||||
if (items.length == 3) {
|
||||
this.yaw = core.getLocationManipulation().getYaw(items[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getType() {
|
||||
return "World";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.world.getColoredWorldString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (direction.length() > 0 && yaw >= 0) {
|
||||
return this.world.getCBWorld().getName() + ":" + this.direction;
|
||||
}
|
||||
return this.world.getCBWorld().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String getRequiredPermission() {
|
||||
// TODO: Potenitally replace spaces wiht tabs for friendlier yaml.
|
||||
// this.world.getName().replace(" ","_");
|
||||
return "multiverse.access." + this.world.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Vector getVelocity() {
|
||||
return new Vector(0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean useSafeTeleporter() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package com.onarandombox.MultiverseCore.destination.core;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import co.aikar.commands.BukkitCommandIssuer;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.Destination;
|
||||
import com.onarandombox.MultiverseCore.api.Teleporter;
|
||||
import org.bukkit.Location;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class AnchorDestination implements Destination<AnchorDestinationInstance> {
|
||||
private final MultiverseCore plugin;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param plugin The MultiverseCore plugin.
|
||||
*/
|
||||
public AnchorDestination(MultiverseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return "a";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable AnchorDestinationInstance getDestinationInstance(@Nullable String destinationParams) {
|
||||
Location anchorLocation = this.plugin.getAnchorManager().getAnchorLocation(destinationParams);
|
||||
if (anchorLocation == null) {
|
||||
return null;
|
||||
}
|
||||
return new AnchorDestinationInstance(destinationParams, anchorLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @NotNull Collection<String> suggestDestinations(@NotNull BukkitCommandIssuer issuer, @Nullable String destinationParams) {
|
||||
return this.plugin.getAnchorManager().getAnchors(issuer.getPlayer());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean checkTeleportSafety() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable Teleporter getTeleporter() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.onarandombox.MultiverseCore.destination.core;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.DestinationInstance;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class AnchorDestinationInstance implements DestinationInstance {
|
||||
private final String anchorName;
|
||||
private final Location anchorLocation;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param anchorName The name of the anchor.
|
||||
* @param anchorLocation The location of the anchor.
|
||||
*/
|
||||
public AnchorDestinationInstance(@NotNull String anchorName, @NotNull Location anchorLocation) {
|
||||
this.anchorName = anchorName;
|
||||
this.anchorLocation = anchorLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable Location getLocation(@NotNull Entity teleportee) {
|
||||
return anchorLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable Vector getVelocity(@NotNull Entity teleportee) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable String getFinerPermissionSuffix() {
|
||||
return anchorName;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @NotNull String serialise() {
|
||||
return anchorName;
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package com.onarandombox.MultiverseCore.destination.core;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import co.aikar.commands.BukkitCommandIssuer;
|
||||
import com.onarandombox.MultiverseCore.api.Destination;
|
||||
import com.onarandombox.MultiverseCore.api.Teleporter;
|
||||
import com.onarandombox.MultiverseCore.utils.PlayerFinder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class BedDestination implements Destination<BedDestinationInstance> {
|
||||
public static final String OWN_BED_STRING = "playerbed";
|
||||
|
||||
public BedDestination() {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return "b";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable BedDestinationInstance getDestinationInstance(@Nullable String destinationParams) {
|
||||
Player player = PlayerFinder.get(destinationParams);
|
||||
if (player == null && !destinationParams.equals(OWN_BED_STRING)) {
|
||||
return null;
|
||||
}
|
||||
return new BedDestinationInstance(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @NotNull Collection<String> suggestDestinations(@NotNull BukkitCommandIssuer issuer, @Nullable String destinationParams) {
|
||||
List<String> collect = Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||
collect.add(OWN_BED_STRING);
|
||||
return collect;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean checkTeleportSafety() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable Teleporter getTeleporter() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.onarandombox.MultiverseCore.destination.core;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.DestinationInstance;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class BedDestinationInstance implements DestinationInstance {
|
||||
private final Player player;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param player The player whose bed to use.
|
||||
*/
|
||||
public BedDestinationInstance(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable Location getLocation(@NotNull Entity teleportee) {
|
||||
if (player != null) {
|
||||
return player.getBedSpawnLocation();
|
||||
}
|
||||
if (teleportee instanceof Player) {
|
||||
return ((Player) teleportee).getBedSpawnLocation();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable Vector getVelocity(@NotNull Entity teleportee) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable String getFinerPermissionSuffix() {
|
||||
return player != null ? player.getName() : BedDestination.OWN_BED_STRING;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @NotNull String serialise() {
|
||||
return player != null ? player.getName() : BedDestination.OWN_BED_STRING;
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
package com.onarandombox.MultiverseCore.destination.core;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import co.aikar.commands.BukkitCommandIssuer;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.Destination;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.api.Teleporter;
|
||||
import org.bukkit.Location;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CannonDestination implements Destination<CannonDestinationInstance> {
|
||||
private final MultiverseCore plugin;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param plugin The MultiverseCore plugin.
|
||||
*/
|
||||
public CannonDestination(MultiverseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return "ca";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable CannonDestinationInstance getDestinationInstance(@Nullable String destinationParams) {
|
||||
String[] params = destinationParams.split(":");
|
||||
if (params.length != 5) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String worldName = params[0];
|
||||
String coordinates = params[1];
|
||||
String pitch = params[2];
|
||||
String yaw = params[3];
|
||||
String speed = params[4];
|
||||
|
||||
String[] coordinatesParams = coordinates.split(",");
|
||||
if (coordinatesParams.length != 3) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(worldName);
|
||||
if (world == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Location location;
|
||||
double dSpeed;
|
||||
try {
|
||||
location = new Location(
|
||||
world.getCBWorld(),
|
||||
Double.parseDouble(coordinatesParams[0]),
|
||||
Double.parseDouble(coordinatesParams[1]),
|
||||
Double.parseDouble(coordinatesParams[2]),
|
||||
Float.parseFloat(yaw),
|
||||
Float.parseFloat(pitch)
|
||||
);
|
||||
dSpeed = Double.parseDouble(speed);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CannonDestinationInstance(location, dSpeed);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @NotNull Collection<String> suggestDestinations(@NotNull BukkitCommandIssuer issuer, @Nullable String destinationParams) {
|
||||
return Collections.singleton("");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean checkTeleportSafety() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable Teleporter getTeleporter() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.onarandombox.MultiverseCore.destination.core;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.DestinationInstance;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CannonDestinationInstance implements DestinationInstance {
|
||||
private final Location location;
|
||||
private final double speed;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param location The location to teleport to.
|
||||
* @param speed The speed to fire the player at.
|
||||
*/
|
||||
public CannonDestinationInstance(@NotNull Location location, double speed) {
|
||||
this.location = location;
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable Location getLocation(@NotNull Entity teleportee) {
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable Vector getVelocity(@NotNull Entity teleportee) {
|
||||
double pitchRadians = Math.toRadians(location.getPitch());
|
||||
double yawRadians = Math.toRadians(location.getYaw());
|
||||
double x = Math.sin(yawRadians) * speed * -1;
|
||||
double y = Math.sin(pitchRadians) * speed * -1;
|
||||
double z = Math.cos(yawRadians) * speed;
|
||||
// Account for the angle they were pointed, and take away velocity
|
||||
x = Math.cos(pitchRadians) * x;
|
||||
z = Math.cos(pitchRadians) * z;
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable String getFinerPermissionSuffix() {
|
||||
return location.getWorld().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @NotNull String serialise() {
|
||||
return location.getWorld().getName() + ":" + location.getX() + "," + location.getY()
|
||||
+ "," + location.getZ() + ":" + location.getPitch() + ":" + location.getYaw() + ":" + this.speed;
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
package com.onarandombox.MultiverseCore.destination.core;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import co.aikar.commands.BukkitCommandIssuer;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.Destination;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.api.Teleporter;
|
||||
import org.bukkit.Location;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ExactDestination implements Destination<ExactDestinationInstance> {
|
||||
private final MultiverseCore plugin;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param plugin The MultiverseCore plugin.
|
||||
*/
|
||||
public ExactDestination(MultiverseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return "e";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable ExactDestinationInstance getDestinationInstance(@Nullable String destinationParams) {
|
||||
String[] items = destinationParams.split(":");
|
||||
if (items.length < 2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String worldName = items[0];
|
||||
String coordinates = items[1];
|
||||
String[] coordinatesParams = coordinates.split(",");
|
||||
if (coordinatesParams.length != 3) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(worldName);
|
||||
if (world == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Location location;
|
||||
try {
|
||||
location = new Location(
|
||||
world.getCBWorld(),
|
||||
Double.parseDouble(coordinatesParams[0]),
|
||||
Double.parseDouble(coordinatesParams[1]),
|
||||
Double.parseDouble(coordinatesParams[2])
|
||||
);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (items.length == 4) {
|
||||
String pitch = items[2];
|
||||
String yaw = items[3];
|
||||
try {
|
||||
location.setPitch(Float.parseFloat(pitch));
|
||||
location.setYaw(Float.parseFloat(yaw));
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return new ExactDestinationInstance(location);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @NotNull Collection<String> suggestDestinations(@NotNull BukkitCommandIssuer issuer, @Nullable String destinationParams) {
|
||||
return Collections.singleton("");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean checkTeleportSafety() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable Teleporter getTeleporter() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.onarandombox.MultiverseCore.destination.core;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.DestinationInstance;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ExactDestinationInstance implements DestinationInstance {
|
||||
private final Location location;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param location The location to teleport to.
|
||||
*/
|
||||
public ExactDestinationInstance(Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable Location getLocation(@NotNull Entity teleportee) {
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable Vector getVelocity(@NotNull Entity teleportee) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable String getFinerPermissionSuffix() {
|
||||
return location.getWorld().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @NotNull String serialise() {
|
||||
return location.getWorld().getName() + ":" + location.getX() + "," + location.getY()
|
||||
+ "," + location.getZ() + ":" + location.getPitch() + ":" + location.getYaw();
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.onarandombox.MultiverseCore.destination.core;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import co.aikar.commands.BukkitCommandIssuer;
|
||||
import com.onarandombox.MultiverseCore.api.Destination;
|
||||
import com.onarandombox.MultiverseCore.api.Teleporter;
|
||||
import com.onarandombox.MultiverseCore.utils.PlayerFinder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PlayerDestination implements Destination<PlayerDestinationInstance> {
|
||||
/**
|
||||
* Creates a new instance of the PlayerDestination.
|
||||
*/
|
||||
public PlayerDestination() {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return "pl";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable PlayerDestinationInstance getDestinationInstance(@Nullable String destinationParams) {
|
||||
Player player = PlayerFinder.get(destinationParams);
|
||||
if (player == null) {
|
||||
return null;
|
||||
}
|
||||
return new PlayerDestinationInstance(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @NotNull Collection<String> suggestDestinations(@NotNull BukkitCommandIssuer issuer, @Nullable String destinationParams) {
|
||||
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean checkTeleportSafety() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable Teleporter getTeleporter() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.onarandombox.MultiverseCore.destination.core;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.DestinationInstance;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PlayerDestinationInstance implements DestinationInstance {
|
||||
private final Player player;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param player The player whose location to go to.
|
||||
*/
|
||||
public PlayerDestinationInstance(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable Location getLocation(@NotNull Entity teleportee) {
|
||||
return player.getLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable Vector getVelocity(@NotNull Entity teleportee) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable String getFinerPermissionSuffix() {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @NotNull String serialise() {
|
||||
return player.getName();
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package com.onarandombox.MultiverseCore.destination.core;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import co.aikar.commands.BukkitCommandIssuer;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.Destination;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.api.Teleporter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class WorldDestination implements Destination<WorldDestinationInstance> {
|
||||
|
||||
private final MultiverseCore plugin;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param plugin The MultiverseCore plugin.
|
||||
*/
|
||||
public WorldDestination(MultiverseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return "w";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable WorldDestinationInstance getDestinationInstance(@Nullable String destinationParams) {
|
||||
String[] items = destinationParams.split(":");
|
||||
if (items.length > 3) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String worldName = items[0];
|
||||
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(worldName);
|
||||
if (world == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String direction = (items.length == 2) ? items[1] : null;
|
||||
float yaw = direction != null ? this.plugin.getLocationManipulation().getYaw(direction) : -1;
|
||||
|
||||
return new WorldDestinationInstance(world, direction, yaw);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @NotNull Collection<String> suggestDestinations(@NotNull BukkitCommandIssuer issuer, @Nullable String destinationParams) {
|
||||
// Autocomplete of worlds is done by MVCommandCompletion without prefix
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean checkTeleportSafety() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable Teleporter getTeleporter() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.onarandombox.MultiverseCore.destination.core;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.DestinationInstance;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class WorldDestinationInstance implements DestinationInstance {
|
||||
private final MultiverseWorld world;
|
||||
private final String direction;
|
||||
private final float yaw;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param world The world to teleport to.
|
||||
*/
|
||||
public WorldDestinationInstance(@NotNull MultiverseWorld world, @Nullable String direction, float yaw) {
|
||||
this.world = world;
|
||||
this.direction = direction;
|
||||
this.yaw = yaw;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable Location getLocation(@NotNull Entity teleportee) {
|
||||
Location worldLoc = world.getSpawnLocation();
|
||||
if (this.yaw >= 0) {
|
||||
// Only modify the yaw if its set.
|
||||
worldLoc.setYaw(this.yaw);
|
||||
}
|
||||
return worldLoc;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable Vector getVelocity(@NotNull Entity teleportee) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @Nullable String getFinerPermissionSuffix() {
|
||||
return world.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @NotNull String serialise() {
|
||||
if (this.direction != null) {
|
||||
return this.world.getCBWorld().getName() + ":" + this.direction;
|
||||
}
|
||||
return this.world.getCBWorld().getName();
|
||||
}
|
||||
}
|
@ -9,7 +9,6 @@ package com.onarandombox.MultiverseCore.event;
|
||||
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -1,5 +1,11 @@
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -7,12 +13,6 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Helper class to get {@link Player} from name, UUID or Selectors.
|
||||
*/
|
||||
@ -21,6 +21,16 @@ public class PlayerFinder {
|
||||
private static final Pattern UUID_REGEX = Pattern.compile("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}");
|
||||
private static final Pattern COMMA_SPLIT = Pattern.compile(",");
|
||||
|
||||
/**
|
||||
* Get a {@link Player} based on an identifier of name UUID or selector.
|
||||
*
|
||||
* @param playerIdentifier An identifier of name UUID or selector.
|
||||
* @return The player if found, else null.
|
||||
*/
|
||||
public static Player get(@NotNull String playerIdentifier) {
|
||||
return get(playerIdentifier, Bukkit.getConsoleSender());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a {@link Player} based on an identifier of name UUID or selector.
|
||||
*
|
||||
@ -29,17 +39,21 @@ public class PlayerFinder {
|
||||
* @return The player if found, else null.
|
||||
*/
|
||||
@Nullable
|
||||
public static Player get(@NotNull String playerIdentifier,
|
||||
@NotNull CommandSender sender) {
|
||||
public static Player get(@Nullable String playerIdentifier, @NotNull CommandSender sender) {
|
||||
if (playerIdentifier == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Player targetPlayer = getByName(playerIdentifier);
|
||||
if (targetPlayer != null) {
|
||||
return targetPlayer;
|
||||
}
|
||||
|
||||
targetPlayer = getByUuid(playerIdentifier);
|
||||
if (targetPlayer != null) {
|
||||
return targetPlayer;
|
||||
}
|
||||
|
||||
return getBySelector(playerIdentifier, sender);
|
||||
}
|
||||
|
||||
|
@ -7,11 +7,12 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import co.aikar.commands.BukkitCommandIssuer;
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.api.DestinationInstance;
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.destination.InvalidDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.ParsedDestination;
|
||||
import com.onarandombox.MultiverseCore.enums.TeleportResult;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -189,11 +190,12 @@ public class SimpleSafeTTeleporter implements SafeTTeleporter {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public TeleportResult safelyTeleport(CommandSender teleporter, Entity teleportee, MVDestination d) {
|
||||
if (d instanceof InvalidDestination) {
|
||||
public TeleportResult safelyTeleport(BukkitCommandIssuer teleporter, Entity teleportee, ParsedDestination<?> destination) {
|
||||
if (destination == null) {
|
||||
Logging.finer("Entity tried to teleport to an invalid destination");
|
||||
return TeleportResult.FAIL_INVALID;
|
||||
}
|
||||
|
||||
Player teleporteePlayer = null;
|
||||
if (teleportee instanceof Player) {
|
||||
teleporteePlayer = ((Player) teleportee);
|
||||
@ -204,26 +206,29 @@ public class SimpleSafeTTeleporter implements SafeTTeleporter {
|
||||
if (teleporteePlayer == null) {
|
||||
return TeleportResult.FAIL_INVALID;
|
||||
}
|
||||
MultiverseCore.addPlayerToTeleportQueue(teleporter.getName(), teleporteePlayer.getName());
|
||||
|
||||
Location safeLoc = d.getLocation(teleportee);
|
||||
if (d.useSafeTeleporter()) {
|
||||
safeLoc = this.getSafeLocation(teleportee, d);
|
||||
MultiverseCore.addPlayerToTeleportQueue(teleporter.getIssuer().getName(), teleporteePlayer.getName());
|
||||
|
||||
Location safeLoc = destination.getDestinationInstance().getLocation(teleportee);
|
||||
if (destination.getDestination().checkTeleportSafety()) {
|
||||
safeLoc = this.getSafeLocation(teleportee, destination.getDestinationInstance());
|
||||
}
|
||||
|
||||
if (safeLoc != null) {
|
||||
if (teleportee.teleport(safeLoc)) {
|
||||
Vector v = d.getVelocity();
|
||||
if (v != null && !DEFAULT_VECTOR.equals(v)) {
|
||||
Bukkit.getScheduler().runTaskLater(this.plugin, () -> {
|
||||
teleportee.setVelocity(d.getVelocity());
|
||||
}, 1);
|
||||
}
|
||||
return TeleportResult.SUCCESS;
|
||||
}
|
||||
if (safeLoc == null) {
|
||||
return TeleportResult.FAIL_UNSAFE;
|
||||
}
|
||||
|
||||
if (!teleportee.teleport(safeLoc)) {
|
||||
return TeleportResult.FAIL_OTHER;
|
||||
}
|
||||
return TeleportResult.FAIL_UNSAFE;
|
||||
|
||||
Vector v = destination.getDestinationInstance().getVelocity(teleportee);
|
||||
if (v != null && !DEFAULT_VECTOR.equals(v)) {
|
||||
Bukkit.getScheduler().runTaskLater(this.plugin, () -> {
|
||||
teleportee.setVelocity(v);
|
||||
}, 1);
|
||||
}
|
||||
return TeleportResult.SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -244,23 +249,20 @@ public class SimpleSafeTTeleporter implements SafeTTeleporter {
|
||||
return TeleportResult.FAIL_UNSAFE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Location getSafeLocation(Entity e, MVDestination d) {
|
||||
Location l = d.getLocation(e);
|
||||
public Location getSafeLocation(Entity entity, DestinationInstance destination) {
|
||||
Location l = destination.getLocation(entity);
|
||||
if (plugin.getBlockSafety().playerCanSpawnHereSafely(l)) {
|
||||
Logging.fine("The first location you gave me was safe.");
|
||||
return l;
|
||||
}
|
||||
if (e instanceof Minecart) {
|
||||
Minecart m = (Minecart) e;
|
||||
if (entity instanceof Minecart) {
|
||||
Minecart m = (Minecart) entity;
|
||||
if (!plugin.getBlockSafety().canSpawnCartSafely(m)) {
|
||||
return null;
|
||||
}
|
||||
} else if (e instanceof Vehicle) {
|
||||
Vehicle v = (Vehicle) e;
|
||||
} else if (entity instanceof Vehicle) {
|
||||
Vehicle v = (Vehicle) entity;
|
||||
if (!plugin.getBlockSafety().canSpawnVehicleSafely(v)) {
|
||||
return null;
|
||||
}
|
||||
@ -268,19 +270,19 @@ public class SimpleSafeTTeleporter implements SafeTTeleporter {
|
||||
Location safeLocation = this.getSafeLocation(l);
|
||||
if (safeLocation != null) {
|
||||
// Add offset to account for a vehicle on dry land!
|
||||
if (e instanceof Minecart && !plugin.getBlockSafety().isEntitiyOnTrack(safeLocation)) {
|
||||
if (entity instanceof Minecart && !plugin.getBlockSafety().isEntitiyOnTrack(safeLocation)) {
|
||||
safeLocation.setY(safeLocation.getBlockY() + .5);
|
||||
Logging.finer("Player was inside a minecart. Offsetting Y location.");
|
||||
}
|
||||
Logging.finer("Had to look for a bit, but I found a safe place for ya!");
|
||||
return safeLocation;
|
||||
}
|
||||
if (e instanceof Player) {
|
||||
Player p = (Player) e;
|
||||
if (entity instanceof Player) {
|
||||
Player p = (Player) entity;
|
||||
this.plugin.getMessaging().sendMessage(p, "No safe locations found!", false);
|
||||
Logging.finer("No safe location found for " + p.getName());
|
||||
} else if (e.getPassenger() instanceof Player) {
|
||||
Player p = (Player) e.getPassenger();
|
||||
} else if (entity.getPassenger() instanceof Player) {
|
||||
Player p = (Player) entity.getPassenger();
|
||||
this.plugin.getMessaging().sendMessage(p, "No safe locations found!", false);
|
||||
Logging.finer("No safe location found for " + p.getName());
|
||||
}
|
||||
@ -334,7 +336,7 @@ public class SimpleSafeTTeleporter implements SafeTTeleporter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TeleportResult teleport(final CommandSender teleporter, final Player teleportee, final MVDestination destination) {
|
||||
public TeleportResult teleport(BukkitCommandIssuer teleporter, Entity teleportee, ParsedDestination<?> destination) {
|
||||
return this.safelyTeleport(teleporter, teleportee, destination);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user