From dba21cadafece256692802629e1d4f42c662535c Mon Sep 17 00:00:00 2001 From: "main()" Date: Wed, 26 Dec 2012 20:09:09 +0100 Subject: [PATCH] Custom teleporters. --- .../MultiverseCore/api/SafeTTeleporter.java | 2 +- .../MultiverseCore/api/Teleporter.java | 10 +++++++ .../commands/TeleportCommand.java | 6 +++- .../CustomTeleporterDestination.java | 29 +++++++++++++++++++ .../utils/SimpleSafeTTeleporter.java | 5 +++- 5 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/onarandombox/MultiverseCore/api/Teleporter.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/CustomTeleporterDestination.java diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/SafeTTeleporter.java b/src/main/java/com/onarandombox/MultiverseCore/api/SafeTTeleporter.java index a38140e1..c6e7e76b 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/SafeTTeleporter.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/SafeTTeleporter.java @@ -9,7 +9,7 @@ import com.onarandombox.MultiverseCore.enums.TeleportResult; /** * Used to safely teleport people. */ -public interface SafeTTeleporter { +public interface SafeTTeleporter extends Teleporter { /** * Gets the next safe location around the given location. diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/Teleporter.java b/src/main/java/com/onarandombox/MultiverseCore/api/Teleporter.java new file mode 100644 index 00000000..aead219c --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/api/Teleporter.java @@ -0,0 +1,10 @@ +package com.onarandombox.MultiverseCore.api; + +import com.onarandombox.MultiverseCore.api.MVDestination; +import com.onarandombox.MultiverseCore.enums.TeleportResult; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public interface Teleporter { + TeleportResult teleport(CommandSender teleporter, Player teleportee, MVDestination destination); +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java index 7b0d9a92..2df71c0b 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java @@ -8,7 +8,9 @@ package com.onarandombox.MultiverseCore.commands; import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.api.Teleporter; import com.onarandombox.MultiverseCore.api.MVDestination; +import com.onarandombox.MultiverseCore.destination.CustomTeleporterDestination; import com.onarandombox.MultiverseCore.destination.DestinationFactory; import com.onarandombox.MultiverseCore.destination.InvalidDestination; import com.onarandombox.MultiverseCore.destination.WorldDestination; @@ -156,7 +158,9 @@ public class TeleportCommand extends MultiverseCommand { this.messaging.sendMessage(teleporter, "Sorry Boss, I tried everything, but just couldn't teleport ya there!", false); return; } - TeleportResult result = this.playerTeleporter.safelyTeleport(teleporter, teleportee, d); + Teleporter teleportObject = (d instanceof CustomTeleporterDestination) ? + ((CustomTeleporterDestination)d).getTeleporter() : this.playerTeleporter; + TeleportResult result = teleportObject.teleport(teleporter, teleportee, d); if (result == TeleportResult.FAIL_UNSAFE) { this.plugin.log(Level.FINE, "Could not teleport " + teleportee.getName() + " to " + plugin.getLocationManipulation().strCoordsRaw(d.getLocation(teleportee))); diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/CustomTeleporterDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/CustomTeleporterDestination.java new file mode 100644 index 00000000..858c3e34 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/CustomTeleporterDestination.java @@ -0,0 +1,29 @@ +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(); +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/SimpleSafeTTeleporter.java b/src/main/java/com/onarandombox/MultiverseCore/utils/SimpleSafeTTeleporter.java index f68b39fe..0608dc15 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/SimpleSafeTTeleporter.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/SimpleSafeTTeleporter.java @@ -30,7 +30,6 @@ import java.util.logging.Level; * The default-implementation of {@link SafeTTeleporter}. */ public class SimpleSafeTTeleporter implements SafeTTeleporter { - private MultiverseCore plugin; public SimpleSafeTTeleporter(MultiverseCore plugin) { @@ -331,4 +330,8 @@ public class SimpleSafeTTeleporter implements SafeTTeleporter { return blockB; } + @Override + public TeleportResult teleport(final CommandSender teleporter, final Player teleportee, final MVDestination destination) { + return this.safelyTeleport(teleporter, teleportee, destination); + } }