Custom teleporters.

This commit is contained in:
main() 2012-12-26 20:09:09 +01:00
parent fa9191dd8f
commit dba21cadaf
5 changed files with 49 additions and 3 deletions

View File

@ -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.

View File

@ -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);
}

View File

@ -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)));

View File

@ -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();
}

View File

@ -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);
}
}