Reworked Teleportation System. ChestGUI by index.

This commit is contained in:
Olof Larsson 2015-04-09 11:55:14 +02:00
parent 5f9233bc3b
commit ed0b598ffb
31 changed files with 1210 additions and 414 deletions

View File

@ -180,6 +180,7 @@ public class MassiveCore extends MassivePlugin
EngineTeleportMixinCause.get().activate(); EngineTeleportMixinCause.get().activate();
MassiveCoreEngineWorldNameSet.get().activate(); MassiveCoreEngineWorldNameSet.get().activate();
MassiveCoreEngineCommandRegistration.get().activate(); MassiveCoreEngineCommandRegistration.get().activate();
MassiveCoreEngineDestination.get().activate();
PlayerUtil.get().activate(); PlayerUtil.get().activate();
EngineChestGui.get().activate(); EngineChestGui.get().activate();

View File

@ -0,0 +1,200 @@
package com.massivecraft.massivecore;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.plugin.Plugin;
import com.massivecraft.massivecore.cmd.arg.ARPS;
import com.massivecraft.massivecore.cmd.arg.ARSenderId;
import com.massivecraft.massivecore.cmd.arg.ARWorldId;
import com.massivecraft.massivecore.collections.MassiveSet;
import com.massivecraft.massivecore.event.EventMassiveCoreDestination;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.teleport.Destination;
import com.massivecraft.massivecore.teleport.DestinationJump;
import com.massivecraft.massivecore.teleport.DestinationPlayer;
import com.massivecraft.massivecore.teleport.DestinationSimple;
import com.massivecraft.massivecore.teleport.DestinationThat;
import com.massivecraft.massivecore.teleport.DestinationThere;
import com.massivecraft.massivecore.teleport.DestinationTop;
import com.massivecraft.massivecore.teleport.DestinationUtil;
import com.massivecraft.massivecore.teleport.DestinationWorld;
import com.massivecraft.massivecore.util.IdUtil;
public class MassiveCoreEngineDestination extends EngineAbstract
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static MassiveCoreEngineDestination i = new MassiveCoreEngineDestination();
public static MassiveCoreEngineDestination get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public Plugin getPlugin()
{
return MassiveCore.get();
}
// -------------------------------------------- //
// DESTINATION ARG
// -------------------------------------------- //
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void destinationPs(EventMassiveCoreDestination event)
{
try
{
PS ps = ARPS.get().read(event.getArg(), event.getSender());
Destination destination = new DestinationSimple(ps);
event.setDestination(destination);
}
catch (MassiveException exception)
{
event.setException(exception);
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void destinationArg(EventMassiveCoreDestination event)
{
final String arg = event.getArg().toLowerCase();
final CommandSender sender = event.getSender();
try
{
Destination destination = destinationArg(arg, sender);
if (destination == null) return;
event.setDestination(destination);
}
catch (MassiveException e)
{
event.setException(e);
}
catch (Exception e)
{
event.setException(new MassiveException().addMsg("<b>%s", e.getMessage()));
}
event.setCancelled(true);
}
public static final Set<String> ALIASES_TOP = new MassiveSet<String>("top");
public static final Set<String> ALIASES_THERE = new MassiveSet<String>("there");
public static final Set<String> ALIASES_THAT = new MassiveSet<String>("that");
public static final Set<String> ALIASES_JUMP = new MassiveSet<String>("jump");
public static final Set<String> ALIASES_WORLD = new MassiveSet<String>("w", "world", "worldspawn", "wspawn");
public static final Set<String> ALIASES_PLAYER = new MassiveSet<String>("p", "player", "here", "me", "self");
public Destination destinationArg(String arg, CommandSender sender) throws MassiveException
{
// Prepare
arg = arg.toLowerCase();
List<String> parts = Arrays.asList(arg.split("[\\s\\,\\:]+", 2));
String first = parts.get(0);
String rest = null;
if (parts.size() > 1) rest = parts.get(1);
arg = arg.replace("\\s+", "");
// TOP
if (ALIASES_TOP.contains(arg))
{
Player player = DestinationUtil.getPlayer(sender);
return new DestinationTop(player);
}
// THERE
if (ALIASES_THERE.contains(arg))
{
Player player = DestinationUtil.getPlayer(sender);
return new DestinationThere(player);
}
// THAT
if (ALIASES_THAT.contains(arg))
{
Player player = DestinationUtil.getPlayer(sender);
return new DestinationThat(player);
}
// JUMP
if (ALIASES_JUMP.contains(arg))
{
Player player = DestinationUtil.getPlayer(sender);
return new DestinationJump(player);
}
// World Explicit
if (ALIASES_WORLD.contains(first))
{
String worldId;
if (rest != null)
{
worldId = ARWorldId.get().read(rest, sender);
}
else
{
Player player = DestinationUtil.getPlayer(sender);
World world = player.getWorld();
worldId = world.getName();
}
return new DestinationWorld(worldId);
}
// World Implicit
try
{
String worldId = ARWorldId.get().read(arg, sender);
return new DestinationWorld(worldId);
}
catch (Exception e)
{
}
// Player Explicit
if (ALIASES_PLAYER.contains(first))
{
String playerId;
if (rest != null)
{
playerId = ARSenderId.get().read(rest, sender);
}
else
{
Player player = DestinationUtil.getPlayer(sender);
playerId = IdUtil.getId(player);
}
return new DestinationPlayer(playerId);
}
// Player Implicit
try
{
String playerId = ARSenderId.get().read(arg, sender);
return new DestinationPlayer(playerId);
}
catch (Exception e)
{
}
// Null
return null;
}
}

View File

@ -0,0 +1,28 @@
package com.massivecraft.massivecore.chestgui;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
public class ChestActionAbstract implements ChestAction
{
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public boolean onClick(InventoryClickEvent event)
{
HumanEntity human = event.getWhoClicked();
if ( ! (human instanceof Player)) return false;
Player player = (Player)human;
return onClick(event, player);
}
public boolean onClick(InventoryClickEvent event, Player player)
{
return false;
}
}

View File

@ -2,13 +2,12 @@ package com.massivecraft.massivecore.chestgui;
import java.security.InvalidParameterException; import java.security.InvalidParameterException;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import com.massivecraft.massivecore.mixin.Mixin; import com.massivecraft.massivecore.mixin.Mixin;
public class ChestActionCommand implements ChestAction public class ChestActionCommand extends ChestActionAbstract
{ {
// -------------------------------------------- // // -------------------------------------------- //
// FIELD // FIELD
@ -52,12 +51,8 @@ public class ChestActionCommand implements ChestAction
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public boolean onClick(InventoryClickEvent event) public boolean onClick(InventoryClickEvent event, Player player)
{ {
HumanEntity human = event.getWhoClicked();
if ( ! (human instanceof Player)) return false;
Player player = (Player)human;
String commandLine = this.getCommandLine(); String commandLine = this.getCommandLine();
if (commandLine == null) return false; if (commandLine == null) return false;

View File

@ -34,12 +34,12 @@ public class ChestGui
// FIELDS: ACTIONS // FIELDS: ACTIONS
// -------------------------------------------- // // -------------------------------------------- //
protected Map<ItemStack, ChestAction> itemToAction = new MassiveMap<ItemStack, ChestAction>(); protected Map<Integer, ChestAction> indexToAction = new MassiveMap<Integer, ChestAction>();
public Map<ItemStack, ChestAction> getItemToAction() { return this.itemToAction; } public Map<Integer, ChestAction> getIndexToAction() { return this.indexToAction; }
public ChestAction removeAction(ItemStack item) { return this.itemToAction.remove(item); } public ChestAction removeAction(ItemStack item) { return this.indexToAction.remove(item); }
public ChestAction setAction(ItemStack item, ChestAction action) { return this.itemToAction.put(item, action); } public ChestAction setAction(int index, ChestAction action) { return this.indexToAction.put(index, action); }
public ChestAction setAction(ItemStack item, String command) { return this.setAction(item, new ChestActionCommand(command)); } public ChestAction setAction(int index, String command) { return this.setAction(index, new ChestActionCommand(command)); }
public ChestAction getAction(ItemStack item) { return this.itemToAction.get(item); } public ChestAction getAction(int index) { return this.indexToAction.get(index); }
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS: SOUND // FIELDS: SOUND

View File

@ -6,11 +6,11 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.massivecraft.massivecore.EngineAbstract; import com.massivecraft.massivecore.EngineAbstract;
import com.massivecraft.massivecore.MassiveCore; import com.massivecraft.massivecore.MassiveCore;
import com.massivecraft.massivecore.mixin.Mixin;
import com.massivecraft.massivecore.util.InventoryUtil; import com.massivecraft.massivecore.util.InventoryUtil;
public class EngineChestGui extends EngineAbstract public class EngineChestGui extends EngineAbstract
@ -51,23 +51,28 @@ public class EngineChestGui extends EngineAbstract
event.setCancelled(true); event.setCancelled(true);
event.setResult(Result.DENY); event.setResult(Result.DENY);
// ... and if there is an item ... // ... warn on bottom inventory ...
ItemStack item = event.getCurrentItem(); if (InventoryUtil.isBottomInventory(event))
if (InventoryUtil.isNothing(item)) return; {
Mixin.msgOne(event.getWhoClicked(), "<b>Exit the GUI to edit your items.");
return;
}
// ... and this item has an action ... // ... and if this slot index ...
ChestAction action = gui.getAction(item); int index = event.getSlot();
// ... has an action ...
ChestAction action = gui.getAction(index);
if (action == null) return; if (action == null) return;
// ... then use that action ... // ... then play the sound ...
action.onClick(event);
// ... play the sound ...
gui.playSound(event.getWhoClicked()); gui.playSound(event.getWhoClicked());
// ... and close the GUI. // ... close the GUI ...
event.getView().close(); event.getView().close();
// ... and use that action.
action.onClick(event);
} }
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)

View File

@ -0,0 +1,45 @@
package com.massivecraft.massivecore.cmd;
import com.massivecraft.massivecore.cmd.MassiveCommand;
import com.massivecraft.massivecore.cmd.VisibilityMode;
public class DeprecatedCommand extends MassiveCommand
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
public MassiveCommand target;
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public DeprecatedCommand(MassiveCommand target, String... aliases)
{
// Fields
this.target = target;
// Aliases
this.setAliases(aliases);
// Args
this.setErrorOnToManyArgs(false);
// Visibility
this.setVisibilityMode(VisibilityMode.INVISIBLE);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform()
{
msg("<i>Use this new command instead:");
sendMessage(target.getUseageTemplate(true));
}
}

View File

@ -0,0 +1,39 @@
package com.massivecraft.massivecore.cmd.arg;
import org.bukkit.command.CommandSender;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.event.EventMassiveCoreDestination;
import com.massivecraft.massivecore.teleport.Destination;
public class ARDestination extends ArgReaderAbstract<Destination>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static ARDestination i = new ARDestination();
public static ARDestination get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public Destination read(String arg, CommandSender sender) throws MassiveException
{
EventMassiveCoreDestination event = new EventMassiveCoreDestination(arg, sender, null);
event.run();
MassiveException exception = event.getException();
if (exception != null) throw exception;
Destination ret = event.getDestination();
if (ret == null) throw new MassiveException().addMsg("<b>Unknown destination \"<h>%s<b>\".", arg);
if ( ! ret.hasPs()) throw new MassiveException().addMessage(ret.getMessagePsNull(sender));
return ret;
}
}

View File

@ -0,0 +1,216 @@
package com.massivecraft.massivecore.cmd.arg;
import java.util.Arrays;
import java.util.List;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.ps.PSBuilder;
import com.mysql.jdbc.StringUtils;
public class ARPS extends ArgReaderAbstract<PS>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static ARPS i = new ARPS();
public static ARPS get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public PS read(String arg, CommandSender sender) throws MassiveException
{
// Ellador 34 13 78.6 (standard one)
// 34 13 79 (standard one)
// pitch14.5
// worldEllador,yaw14,
// x15,y18,z8003
// x15 y32 z99 wEllador
// x:15 y:32 z:99 w:Ellador
// We get the sender ps
PS senderPs = new PSBuilder().build();
if (sender instanceof Entity) senderPs = PS.valueOf((Entity)sender);
// We remove all commas optionally followed by spaces
String argInner = arg.replaceAll("\\:\\s*", "");
// We split on comma and space to get the list of raw entries.
List<String> parts = Arrays.asList(argInner.split("[\\s,]+"));
// Then we test the standard ones
if (parts.size() == 4)
{
try
{
String world = ARWorldId.get().read(parts.get(0), sender);
double locationX = ARDouble.get().read(parts.get(1), sender);
double locationY = ARDouble.get().read(parts.get(2), sender);
double locationZ = ARDouble.get().read(parts.get(3), sender);
return new PSBuilder(senderPs).world(world).locationX(locationX).locationY(locationY).locationZ(locationZ).build();
}
catch (Exception e)
{
}
try
{
double locationX = ARDouble.get().read(parts.get(0), sender);
double locationY = ARDouble.get().read(parts.get(1), sender);
double locationZ = ARDouble.get().read(parts.get(2), sender);
String world = ARWorldId.get().read(parts.get(3), sender);
return new PSBuilder(senderPs).world(world).locationX(locationX).locationY(locationY).locationZ(locationZ).build();
}
catch (Exception e)
{
}
}
else if (parts.size() == 3)
{
try
{
double locationX = ARDouble.get().read(parts.get(0), sender);
double locationY = ARDouble.get().read(parts.get(1), sender);
double locationZ = ARDouble.get().read(parts.get(2), sender);
return new PSBuilder(senderPs).locationX(locationX).locationY(locationY).locationZ(locationZ).build();
}
catch (Exception e)
{
}
}
// Then we split each entry using known prefixes and append the ps builder.
PSBuilder ret = new PSBuilder(senderPs);
boolean something = false;
for (String part : parts)
{
String value;
value = getValue(part, PS.NAME_SERIALIZED_WORLD, PS.NAME_FULL_WORLD);
if (value != null)
{
ret.world(ARWorldId.get().read(value, sender));
something = true;
}
value = getValue(part, PS.NAME_SERIALIZED_BLOCKX, PS.NAME_FULL_BLOCKX);
if (value != null)
{
ret.blockX(ARInteger.get().read(value, sender));
something = true;
}
value = getValue(part, PS.NAME_SERIALIZED_BLOCKY, PS.NAME_FULL_BLOCKY);
if (value != null)
{
ret.blockY(ARInteger.get().read(value, sender));
something = true;
}
value = getValue(part, PS.NAME_SERIALIZED_BLOCKZ, PS.NAME_FULL_BLOCKZ);
if (value != null)
{
ret.blockZ(ARInteger.get().read(value, sender));
something = true;
}
value = getValue(part, PS.NAME_SERIALIZED_LOCATIONX, PS.NAME_FULL_LOCATIONX, "x");
if (value != null)
{
ret.locationX(ARDouble.get().read(value, sender));
something = true;
}
value = getValue(part, PS.NAME_SERIALIZED_LOCATIONY, PS.NAME_FULL_LOCATIONY, "y");
if (value != null)
{
ret.locationY(ARDouble.get().read(value, sender));
something = true;
}
value = getValue(part, PS.NAME_SERIALIZED_LOCATIONZ, PS.NAME_FULL_LOCATIONZ, "z");
if (value != null)
{
ret.locationZ(ARDouble.get().read(value, sender));
something = true;
}
value = getValue(part, PS.NAME_SERIALIZED_CHUNKX, PS.NAME_FULL_CHUNKX);
if (value != null)
{
ret.chunkX(ARInteger.get().read(value, sender));
something = true;
}
value = getValue(part, PS.NAME_SERIALIZED_CHUNKZ, PS.NAME_FULL_CHUNKZ);
if (value != null)
{
ret.chunkZ(ARInteger.get().read(value, sender));
something = true;
}
value = getValue(part, PS.NAME_SERIALIZED_PITCH, PS.NAME_FULL_PITCH);
if (value != null)
{
ret.pitch(ARFloat.get().read(value, sender));
something = true;
}
value = getValue(part, PS.NAME_SERIALIZED_YAW, PS.NAME_FULL_YAW);
if (value != null)
{
ret.yaw(ARFloat.get().read(value, sender));
something = true;
}
value = getValue(part, PS.NAME_SERIALIZED_VELOCITYX, PS.NAME_FULL_VELOCITYX);
if (value != null)
{
ret.velocityX(ARDouble.get().read(value, sender));
something = true;
}
value = getValue(part, PS.NAME_SERIALIZED_VELOCITYY, PS.NAME_FULL_VELOCITYY);
if (value != null)
{
ret.velocityY(ARDouble.get().read(value, sender));
something = true;
}
value = getValue(part, PS.NAME_SERIALIZED_VELOCITYZ, PS.NAME_FULL_VELOCITYZ);
if (value != null)
{
ret.velocityZ(ARDouble.get().read(value, sender));
something = true;
}
}
if ( ! something)
{
throw new MassiveException().addMsg("<b>Invalid physical state \"<h>%s<b>\".", arg);
}
return ret.build();
}
public static String getValue(String entry, String... prefixes)
{
for (String prefix : prefixes)
{
if ( ! StringUtils.startsWithIgnoreCase(entry, prefix)) continue;
return entry.substring(prefix.length());
}
return null;
}
}

View File

@ -0,0 +1,48 @@
package com.massivecraft.massivecore.event;
import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.teleport.Destination;
public class EventMassiveCoreDestination extends EventMassiveCore
{
// -------------------------------------------- //
// REQUIRED EVENT CODE
// -------------------------------------------- //
private static final HandlerList handlers = new HandlerList();
@Override public HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; }
// -------------------------------------------- //
// FIELD
// -------------------------------------------- //
protected final String arg;
public String getArg() { return this.arg; }
protected final CommandSender sender;
public CommandSender getSender() { return this.sender; }
public Destination destination = null;
public Destination getDestination() { return this.destination; }
public void setDestination(Destination destination) { this.destination = destination; }
public MassiveException exception = null;
public MassiveException getException() { return this.exception; }
public void setException(MassiveException exception) { this.exception = exception; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public EventMassiveCoreDestination(String arg, CommandSender sender, Destination destination)
{
this.arg = arg;
this.sender = sender;
this.destination = destination;
}
}

View File

@ -1,13 +1,11 @@
package com.massivecraft.massivecore.event; package com.massivecraft.massivecore.event;
import org.bukkit.Bukkit;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.teleport.Destination;
public class EventMassiveCorePlayerPSTeleport extends Event implements Cancellable, Runnable public class EventMassiveCorePlayerPSTeleport extends EventMassiveCore
{ {
// -------------------------------------------- // // -------------------------------------------- //
// REQUIRED EVENT CODE // REQUIRED EVENT CODE
@ -21,44 +19,25 @@ public class EventMassiveCorePlayerPSTeleport extends Event implements Cancellab
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private boolean cancelled; protected final String teleporteeId;
@Override public boolean isCancelled() { return this.cancelled; }
@Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; }
private final String teleporteeId;
public String getTeleporteeId() { return this.teleporteeId; } public String getTeleporteeId() { return this.teleporteeId; }
private final PS from; protected final PS origin;
public PS getFrom() { return this.from; } public PS getOrigin() { return this.origin; }
private PS to; protected Destination destination;
public PS getTo() { return this.to; } public Destination getDestination() { return this.destination; }
public void setTo(PS to) { this.to = to; } public void setDestination(Destination destination) { this.destination = destination; }
private String desc;
public String getDesc() { return this.desc; }
public void setDesc(String desc) { this.desc = desc; }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public EventMassiveCorePlayerPSTeleport(String teleporteeId, PS from, PS to, String desc) public EventMassiveCorePlayerPSTeleport(String teleporteeId, PS origin, Destination destination)
{ {
this.teleporteeId = teleporteeId; this.teleporteeId = teleporteeId;
this.from = from; this.origin = origin;
this.to = to; this.destination = destination;
this.desc = desc;
}
// -------------------------------------------- //
// RUN
// -------------------------------------------- //
@Override
public void run()
{
Bukkit.getPluginManager().callEvent(this);
} }
} }

View File

@ -15,8 +15,7 @@ import org.bukkit.permissions.Permissible;
import com.massivecraft.massivecore.Predictate; import com.massivecraft.massivecore.Predictate;
import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave; import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.store.SenderEntity; import com.massivecraft.massivecore.teleport.Destination;
import com.massivecraft.massivecore.teleport.PSGetter;
public class Mixin public class Mixin
{ {
@ -212,94 +211,17 @@ public class Mixin
return getTeleportMixin().isCausedByMixin(event); return getTeleportMixin().isCausedByMixin(event);
} }
// PS public static void teleport(Object teleporteeObject, Destination destination) throws TeleporterException
public static void teleport(Object teleporteeObject, PS to) throws TeleporterException
{ {
getTeleportMixin().teleport(teleporteeObject, to); getTeleportMixin().teleport(teleporteeObject, destination);
} }
public static void teleport(Object teleporteeObject, PS to, String desc) throws TeleporterException public static void teleport(Object teleporteeObject, Destination destination, Permissible delayPermissible) throws TeleporterException
{ {
getTeleportMixin().teleport(teleporteeObject, to, desc); getTeleportMixin().teleport(teleporteeObject, destination, delayPermissible);
} }
public static void teleport(Object teleporteeObject, PS to, String desc, Permissible delayPermissible) throws TeleporterException public static void teleport(Object teleporteeObject, Destination destination, int delaySeconds) throws TeleporterException
{ {
getTeleportMixin().teleport(teleporteeObject, to, desc, delayPermissible); getTeleportMixin().teleport(teleporteeObject, destination, delaySeconds);
}
public static void teleport(Object teleporteeObject, PS to, String desc, int delaySeconds) throws TeleporterException
{
getTeleportMixin().teleport(teleporteeObject, to, desc, delaySeconds);
}
// CommandSender
public static void teleport(Object teleporteeObject, CommandSender to) throws TeleporterException
{
getTeleportMixin().teleport(teleporteeObject, to);
}
public static void teleport(Object teleporteeObject, CommandSender to, String desc) throws TeleporterException
{
getTeleportMixin().teleport(teleporteeObject, to, desc);
}
public static void teleport(Object teleporteeObject, CommandSender to, String desc, Permissible delayPermissible) throws TeleporterException
{
getTeleportMixin().teleport(teleporteeObject, to, desc, delayPermissible);
}
public static void teleport(Object teleporteeObject, CommandSender to, String desc, int delaySeconds) throws TeleporterException
{
getTeleportMixin().teleport(teleporteeObject, to, desc, delaySeconds);
}
// SenderEntity
public static void teleport(Object teleporteeObject, SenderEntity<?> to) throws TeleporterException
{
getTeleportMixin().teleport(teleporteeObject, to);
}
public static void teleport(Object teleporteeObject, SenderEntity<?> to, String desc) throws TeleporterException
{
getTeleportMixin().teleport(teleporteeObject, to, desc);
}
public static void teleport(Object teleporteeObject, SenderEntity<?> to, String desc, Permissible delayPermissible) throws TeleporterException
{
getTeleportMixin().teleport(teleporteeObject, to, desc, delayPermissible);
}
public static void teleport(Object teleporteeObject, SenderEntity<?> to, String desc, int delaySeconds) throws TeleporterException
{
getTeleportMixin().teleport(teleporteeObject, to, desc, delaySeconds);
}
// String
public static void teleport(Object teleporteeObject, String to) throws TeleporterException
{
getTeleportMixin().teleport(teleporteeObject, to);
}
public static void teleport(Object teleporteeObject, String to, String desc) throws TeleporterException
{
getTeleportMixin().teleport(teleporteeObject, to, desc);
}
public static void teleport(Object teleporteeObject, String to, String desc, Permissible delayPermissible) throws TeleporterException
{
getTeleportMixin().teleport(teleporteeObject, to, desc, delayPermissible);
}
public static void teleport(Object teleporteeObject, String to, String desc, int delaySeconds) throws TeleporterException
{
getTeleportMixin().teleport(teleporteeObject, to, desc, delaySeconds);
}
// PSGetter
public static void teleport(Object teleporteeObject, PSGetter to) throws TeleporterException
{
getTeleportMixin().teleport(teleporteeObject, to);
}
public static void teleport(Object teleporteeObject, PSGetter to, String desc) throws TeleporterException
{
getTeleportMixin().teleport(teleporteeObject, to, desc);
}
public static void teleport(Object teleporteeObject, PSGetter to, String desc, Permissible delayPermissible) throws TeleporterException
{
getTeleportMixin().teleport(teleporteeObject, to, desc, delayPermissible);
}
public static void teleport(Object teleporteeObject, PSGetter to, String desc, int delaySeconds) throws TeleporterException
{
getTeleportMixin().teleport(teleporteeObject, to, desc, delaySeconds);
} }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -1,12 +1,9 @@
package com.massivecraft.massivecore.mixin; package com.massivecraft.massivecore.mixin;
import org.bukkit.command.CommandSender;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.permissions.Permissible; import org.bukkit.permissions.Permissible;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.teleport.Destination;
import com.massivecraft.massivecore.store.SenderEntity;
import com.massivecraft.massivecore.teleport.PSGetter;
public interface TeleportMixin public interface TeleportMixin
{ {
@ -28,34 +25,8 @@ public interface TeleportMixin
// COMMAND SENDER // COMMAND SENDER
// -------------------------------------------- // // -------------------------------------------- //
// PS public void teleport(Object teleporteeObject, Destination destination) throws TeleporterException;
public void teleport(Object teleporteeObject, PS to) throws TeleporterException; public void teleport(Object teleporteeObject, Destination destination, Permissible delayPermissible) throws TeleporterException;
public void teleport(Object teleporteeObject, PS to, String desc) throws TeleporterException; public void teleport(Object teleporteeObject, Destination destination, int delaySeconds) throws TeleporterException;
public void teleport(Object teleporteeObject, PS to, String desc, Permissible delayPermissible) throws TeleporterException;
public void teleport(Object teleporteeObject, PS to, String desc, int delaySeconds) throws TeleporterException;
// CommandSender
public void teleport(Object teleporteeObject, CommandSender to) throws TeleporterException;
public void teleport(Object teleporteeObject, CommandSender to, String desc) throws TeleporterException;
public void teleport(Object teleporteeObject, CommandSender to, String desc, Permissible delayPermissible) throws TeleporterException;
public void teleport(Object teleporteeObject, CommandSender to, String desc, int delaySeconds) throws TeleporterException;
// SenderEntity
public void teleport(Object teleporteeObject, SenderEntity<?> to) throws TeleporterException;
public void teleport(Object teleporteeObject, SenderEntity<?> to, String desc) throws TeleporterException;
public void teleport(Object teleporteeObject, SenderEntity<?> to, String desc, Permissible delayPermissible) throws TeleporterException;
public void teleport(Object teleporteeObject, SenderEntity<?> to, String desc, int delaySeconds) throws TeleporterException;
// String
public void teleport(Object teleporteeObject, String to) throws TeleporterException;
public void teleport(Object teleporteeObject, String to, String desc) throws TeleporterException;
public void teleport(Object teleporteeObject, String to, String desc, Permissible delayPermissible) throws TeleporterException;
public void teleport(Object teleporteeObject, String to, String desc, int delaySeconds) throws TeleporterException;
// PSGetter
public void teleport(Object teleporteeObject, PSGetter to) throws TeleporterException;
public void teleport(Object teleporteeObject, PSGetter to, String desc) throws TeleporterException;
public void teleport(Object teleporteeObject, PSGetter to, String desc, Permissible delayPermissible) throws TeleporterException;
public void teleport(Object teleporteeObject, PSGetter to, String desc, int delaySeconds) throws TeleporterException;
} }

View File

@ -1,15 +1,10 @@
package com.massivecraft.massivecore.mixin; package com.massivecraft.massivecore.mixin;
import org.bukkit.command.CommandSender;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.permissions.Permissible; import org.bukkit.permissions.Permissible;
import com.massivecraft.massivecore.MassiveCoreMConf; import com.massivecraft.massivecore.MassiveCoreMConf;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.teleport.Destination;
import com.massivecraft.massivecore.store.SenderEntity;
import com.massivecraft.massivecore.teleport.PSGetter;
import com.massivecraft.massivecore.teleport.PSGetterPS;
import com.massivecraft.massivecore.teleport.PSGetterPlayer;
public abstract class TeleportMixinAbstract implements TeleportMixin public abstract class TeleportMixinAbstract implements TeleportMixin
{ {
@ -23,7 +18,7 @@ public abstract class TeleportMixinAbstract implements TeleportMixin
} }
// -------------------------------------------- // // -------------------------------------------- //
// CHECK // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
@ -31,134 +26,25 @@ public abstract class TeleportMixinAbstract implements TeleportMixin
{ {
return EngineTeleportMixinCause.get().isCausedByTeleportMixin(event); return EngineTeleportMixinCause.get().isCausedByTeleportMixin(event);
} }
// -------------------------------------------- //
// SENDER OBJECT
// -------------------------------------------- //
// PS
@Override @Override
public void teleport(Object teleportee, PS to) throws TeleporterException public void teleport(Object teleportee, Destination destination) throws TeleporterException
{ {
this.teleport(teleportee, to, null); this.teleport(teleportee, destination, 0);
} }
@Override @Override
public void teleport(Object teleportee, PS to, String desc) throws TeleporterException public void teleport(Object teleportee, Destination destination, Permissible delayPermissible) throws TeleporterException
{ {
this.teleport(teleportee, to, desc, 0); this.teleport(teleportee, destination, getTpdelay(delayPermissible));
} }
// TO OVERRIDE
/*
@Override @Override
public void teleport(Object teleportee, PS to, String desc, Permissible delayPermissible) throws TeleporterException public void teleport(Object teleporteeObject, Destination destination, int delaySeconds) throws TeleporterException
{ {
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible)); // TODO Auto-generated method stub
} }
*/
@Override
public void teleport(Object teleportee, PS to, String desc, int delaySeconds) throws TeleporterException
{
this.teleport(teleportee, PSGetterPS.valueOf(to), desc, delaySeconds);
}
// CommandSender
@Override
public void teleport(Object teleportee, CommandSender to) throws TeleporterException
{
this.teleport(teleportee, to, null);
}
@Override
public void teleport(Object teleportee, CommandSender to, String desc) throws TeleporterException
{
this.teleport(teleportee, to, desc, 0);
}
@Override
public void teleport(Object teleportee, CommandSender to, String desc, Permissible delayPermissible) throws TeleporterException
{
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
}
@Override
public void teleport(Object teleportee, CommandSender to, String desc, int delaySeconds) throws TeleporterException
{
this.teleport(teleportee, PSGetterPlayer.valueOf(to), desc, delaySeconds);
}
// SenderEntity
@Override
public void teleport(Object teleportee, SenderEntity<?> to) throws TeleporterException
{
this.teleport(teleportee, to, null);
}
@Override
public void teleport(Object teleportee, SenderEntity<?> to, String desc) throws TeleporterException
{
this.teleport(teleportee, to, desc, 0);
}
@Override
public void teleport(Object teleportee, SenderEntity<?> to, String desc, Permissible delayPermissible) throws TeleporterException
{
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
}
@Override
public void teleport(Object teleportee, SenderEntity<?> to, String desc, int delaySeconds) throws TeleporterException
{
this.teleport(teleportee, PSGetterPlayer.valueOf(to), desc, delaySeconds);
}
// String
@Override
public void teleport(Object teleportee, String to) throws TeleporterException
{
this.teleport(teleportee, to, null);
}
@Override
public void teleport(Object teleportee, String to, String desc) throws TeleporterException
{
this.teleport(teleportee, to, desc, 0);
}
@Override
public void teleport(Object teleportee, String to, String desc, Permissible delayPermissible) throws TeleporterException
{
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
}
@Override
public void teleport(Object teleportee, String to, String desc, int delaySeconds) throws TeleporterException
{
this.teleport(teleportee, PSGetterPlayer.valueOf(to), desc, delaySeconds);
}
// PSGetter
@Override
public void teleport(Object teleportee, PSGetter to) throws TeleporterException
{
this.teleport(teleportee, to, null);
}
@Override
public void teleport(Object teleportee, PSGetter to, String desc) throws TeleporterException
{
this.teleport(teleportee, to, desc, 0);
}
@Override
public void teleport(Object teleportee, PSGetter to, String desc, Permissible delayPermissible) throws TeleporterException
{
this.teleport(teleportee, to, desc, getTpdelay(delayPermissible));
}
// To implement!
/*@Override
public void teleport(Object teleportee, PSGetter to, String desc, int delaySeconds) throws TeleporterException
{
//this.teleport(teleportee, to, desc, delaySeconds);
}*/
} }

View File

@ -7,7 +7,7 @@ import org.bukkit.util.Vector;
import com.massivecraft.massivecore.event.EventMassiveCorePlayerPSTeleport; import com.massivecraft.massivecore.event.EventMassiveCorePlayerPSTeleport;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.teleport.PSGetter; import com.massivecraft.massivecore.teleport.Destination;
import com.massivecraft.massivecore.teleport.ScheduledTeleport; import com.massivecraft.massivecore.teleport.ScheduledTeleport;
import com.massivecraft.massivecore.util.IdUtil; import com.massivecraft.massivecore.util.IdUtil;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
@ -71,11 +71,14 @@ public class TeleportMixinDefault extends TeleportMixinAbstract
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public void teleport(Object teleporteeObject, PSGetter toGetter, String desc, int delaySeconds) throws TeleporterException public void teleport(Object teleporteeObject, Destination destination, int delaySeconds) throws TeleporterException
{ {
String teleporteeId = IdUtil.getId(teleporteeObject); String teleporteeId = IdUtil.getId(teleporteeObject);
if (!IdUtil.isPlayerId(teleporteeId)) throw new TeleporterException(Txt.parse("<white>%s <b>is not a player.", Mixin.getDisplayName(teleporteeId, IdUtil.getConsole()))); if (!IdUtil.isPlayerId(teleporteeId)) throw new TeleporterException(Txt.parse("<white>%s <b>is not a player.", Mixin.getDisplayName(teleporteeId, IdUtil.getConsole())));
if ( ! destination.hasPs()) throw new TeleporterException(destination.getMessagePsNull(teleporteeId));
String desc = destination.getDesc(teleporteeId);
if (delaySeconds > 0) if (delaySeconds > 0)
{ {
// With delay // With delay
@ -88,22 +91,18 @@ public class TeleportMixinDefault extends TeleportMixinAbstract
Mixin.msgOne(teleporteeId, "<i>Teleporting in <h>"+delaySeconds+"s <i>unless you move."); Mixin.msgOne(teleporteeId, "<i>Teleporting in <h>"+delaySeconds+"s <i>unless you move.");
} }
new ScheduledTeleport(teleporteeId, toGetter, desc, delaySeconds).schedule(); new ScheduledTeleport(teleporteeId, destination, delaySeconds).schedule();
} }
else else
{ {
// Without delay AKA "now"/"at once" // Without delay AKA "now"/"at once"
// Resolve the getter
PS to = toGetter.getPS();
// Run event // Run event
EventMassiveCorePlayerPSTeleport event = new EventMassiveCorePlayerPSTeleport(teleporteeId, Mixin.getSenderPs(teleporteeId), to, desc); EventMassiveCorePlayerPSTeleport event = new EventMassiveCorePlayerPSTeleport(teleporteeId, Mixin.getSenderPs(teleporteeId), destination);
event.run(); event.run();
if (event.isCancelled()) return; if (event.isCancelled()) return;
if (event.getTo() == null) return; destination = event.getDestination();
to = event.getTo(); desc = destination.getDesc(teleporteeId);
desc = event.getDesc();
if (desc != null) if (desc != null)
{ {
@ -113,13 +112,13 @@ public class TeleportMixinDefault extends TeleportMixinAbstract
Player teleportee = IdUtil.getPlayer(teleporteeId); Player teleportee = IdUtil.getPlayer(teleporteeId);
if (teleportee != null) if (teleportee != null)
{ {
teleportPlayer(teleportee, to); teleportPlayer(teleportee, destination.getPs());
} }
else else
{ {
Mixin.setSenderPs(teleporteeId, to); Mixin.setSenderPs(teleporteeId, destination.getPs());
} }
} }
} }
} }

View File

@ -28,4 +28,5 @@ public class TeleporterException extends Exception
{ {
super(message, cause, enableSuppression, writableStackTrace); super(message, cause, enableSuppression, writableStackTrace);
} }
} }

View File

@ -0,0 +1,15 @@
package com.massivecraft.massivecore.teleport;
import java.io.Serializable;
import com.massivecraft.massivecore.ps.PS;
public interface Destination extends Serializable
{
public PS getPs();
public boolean hasPs();
public String getMessagePsNull(Object watcherObject);
public String getDesc(Object watcherObject);
public void setDesc(String desc);
}

View File

@ -0,0 +1,46 @@
package com.massivecraft.massivecore.teleport;
import com.massivecraft.massivecore.ps.PSFormatHumanSpace;
import com.massivecraft.massivecore.util.Txt;
public abstract class DestinationAbstract implements Destination
{
private static final long serialVersionUID = 1L;
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
protected String desc = null;
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public boolean hasPs()
{
return this.getPs() != null;
}
@Override
public String getMessagePsNull(Object watcherObject)
{
String desc = this.getDesc(watcherObject);
return Txt.parse("<b>Location for <h>%s<b> could not be found.", desc);
}
@Override
public String getDesc(Object watcherObject)
{
if (this.desc != null) return this.desc;
return PSFormatHumanSpace.get().format(this.getPs());
}
@Override
public void setDesc(String desc)
{
this.desc = desc;
}
}

View File

@ -0,0 +1,47 @@
package com.massivecraft.massivecore.teleport;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.massivecraft.massivecore.ps.PS;
public class DestinationJump extends DestinationPlayer
{
private static final long serialVersionUID = 1L;
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public DestinationJump(String playerId)
{
super(playerId);
}
public DestinationJump(Object playerObject)
{
super(playerObject);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public PS getPs()
{
Player player = this.getPlayer();
if (player == null) return null;
Location location = DestinationUtil.getJumpLocation(player);
return PS.valueOf(location);
}
@Override
public String getDesc(Object watcherObject)
{
return "Jump for " + super.getDesc(watcherObject, false);
}
}

View File

@ -0,0 +1,80 @@
package com.massivecraft.massivecore.teleport;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.massivecraft.massivecore.mixin.Mixin;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.IdUtil;
import com.massivecraft.massivecore.util.Txt;
public class DestinationPlayer extends DestinationAbstract
{
private static final long serialVersionUID = 1L;
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
protected String playerId;
public String getPlayerId() { return this.playerId; }
public void setPlayerId(String playerId) { this.playerId = playerId; }
public void setPlayer(Object playerObject) { this.playerId = IdUtil.getId(playerObject); }
public CommandSender getSender() { return IdUtil.getSender(this.playerId); }
public Player getPlayer() { return IdUtil.getPlayer(this.playerId); }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public DestinationPlayer(String playerId)
{
this.setPlayerId(playerId);
}
public DestinationPlayer(Object playerObject)
{
this.setPlayer(playerObject);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public PS getPs()
{
return Mixin.getSenderPs(this.playerId);
}
@Override
public String getDesc(Object watcherObject)
{
return this.getDesc(watcherObject, true);
}
public String getDesc(Object watcherObject, boolean prefix)
{
String ret = "";
// Player Prefix
if (prefix)
{
ret += "Player ";
}
// Display Name
ret += Mixin.getDisplayName(this.getPlayerId(), watcherObject);
// Offline Suffix
if (Mixin.isOffline(this.getPlayerId()))
{
ret += Txt.parse(" <b>[Offline]");
}
return ret;
}
}

View File

@ -2,7 +2,7 @@ package com.massivecraft.massivecore.teleport;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PS;
public final class PSGetterPS extends PSGetterAbstract public class DestinationSimple extends DestinationAbstract
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -10,24 +10,27 @@ public final class PSGetterPS extends PSGetterAbstract
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private final PS ps; protected PS ps = null;
public void setPs(PS ps) { this.ps = ps; }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private PSGetterPS(PS ps) public DestinationSimple()
{ {
this.ps = ps; this(null, null);
} }
// -------------------------------------------- // public DestinationSimple(PS ps)
// VALUE OF
// -------------------------------------------- //
public static PSGetterPS valueOf(PS ps)
{ {
return new PSGetterPS(ps); this(ps, null);
}
public DestinationSimple(PS ps, String desc)
{
this.ps = ps;
this.desc = desc;
} }
// -------------------------------------------- // // -------------------------------------------- //
@ -35,7 +38,7 @@ public final class PSGetterPS extends PSGetterAbstract
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public PS getPS() public PS getPs()
{ {
return this.ps; return this.ps;
} }

View File

@ -0,0 +1,47 @@
package com.massivecraft.massivecore.teleport;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.massivecraft.massivecore.ps.PS;
public class DestinationThat extends DestinationPlayer
{
private static final long serialVersionUID = 1L;
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public DestinationThat(String playerId)
{
super(playerId);
}
public DestinationThat(Object playerObject)
{
super(playerObject);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public PS getPs()
{
Player player = this.getPlayer();
if (player == null) return null;
Location location = DestinationUtil.getThatLocation(player);
return PS.valueOf(location);
}
@Override
public String getDesc(Object watcherObject)
{
return "That for " + super.getDesc(watcherObject, false);
}
}

View File

@ -0,0 +1,47 @@
package com.massivecraft.massivecore.teleport;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.massivecraft.massivecore.ps.PS;
public class DestinationThere extends DestinationPlayer
{
private static final long serialVersionUID = 1L;
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public DestinationThere(String playerId)
{
super(playerId);
}
public DestinationThere(Object playerObject)
{
super(playerObject);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public PS getPs()
{
Player player = this.getPlayer();
if (player == null) return null;
Location location = DestinationUtil.getThereLocation(player);
return PS.valueOf(location);
}
@Override
public String getDesc(Object watcherObject)
{
return "There for " + super.getDesc(watcherObject, false);
}
}

View File

@ -0,0 +1,48 @@
package com.massivecraft.massivecore.teleport;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.massivecraft.massivecore.ps.PS;
public class DestinationTop extends DestinationPlayer
{
private static final long serialVersionUID = 1L;
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public DestinationTop(String playerId)
{
super(playerId);
}
public DestinationTop(Object playerObject)
{
super(playerObject);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public PS getPs()
{
Player player = this.getPlayer();
if (player == null) return null;
Location location = player.getLocation();
location.setY(location.getWorld().getHighestBlockYAt(location) + 1);
return PS.valueOf(location);
}
@Override
public String getDesc(Object watcherObject)
{
return "Top for " + super.getDesc(watcherObject, false);
}
}

View File

@ -0,0 +1,140 @@
package com.massivecraft.massivecore.teleport;
import java.util.Iterator;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.util.BlockIterator;
import com.massivecraft.massivecore.MassiveException;
public class DestinationUtil
{
public static Player getPlayer(CommandSender sender) throws MassiveException
{
if ( ! (sender instanceof Player)) throw new MassiveException().addMsg("<b>You must be a player to use this destination.");
return (Player)sender;
}
// We strictly avoid blocks since they have a tendency to not accept outside world coordinates.
public static Location getThatLocation(LivingEntity livingEntity)
{
BlockIterator iter = createHeadlessIterator(livingEntity);
Block block = nextSolid(iter);
// Nothing solid in sight
if (block == null) return null;
Location oldLocation = livingEntity.getLocation();
Location targetLocation = moveLocationToBlock(oldLocation, block);
return targetLocation;
}
public static Location getThereLocation(LivingEntity livingEntity)
{
BlockIterator iter = createHeadlessIterator(livingEntity);
Block block = nextBeforeSolid(iter);
// Nothing solid in sight
if (block == null) return null;
Location oldLocation = livingEntity.getLocation();
Location targetLocation = moveLocationToBlock(oldLocation, block);
return targetLocation;
}
public static Location getJumpLocation(LivingEntity livingEntity)
{
BlockIterator iter = createHeadlessIterator(livingEntity);
Block block = nextSolid(iter);
// Nothing solid in sight
if (block == null) return null;
Location oldLocation = livingEntity.getLocation();
Location targetLocation = moveUp(moveLocationToBlock(oldLocation, block));
return targetLocation;
}
public static BlockIterator createHeadlessIterator(LivingEntity livingEntity)
{
BlockIterator ret = new BlockIterator(livingEntity, 300);
ret.next();
return ret;
}
public static Block nextSolid(Iterator<Block> iter)
{
if (iter == null) return null;
while (iter.hasNext())
{
Block block = iter.next();
if (block.getType().isSolid()) return block;
}
return null;
}
public static Block nextBeforeSolid(Iterator<Block> iter)
{
if (iter == null) return null;
Block ret = null;
while (iter.hasNext())
{
Block block = iter.next();
if (block.getType().isSolid()) break;
ret = block;
}
return ret;
}
public static Location moveUp(Location location)
{
Location ret = location.clone();
while (!canStandIn(ret))
{
ret.add(0, 1, 0);
}
return ret;
}
public static boolean canStandIn(Location location)
{
return canStandIn(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
public static boolean canStandIn(World world, int x, int y, int z)
{
if (isSolid(world, x, y, z)) return false;
if (isSolid(world, x, y+1, z)) return false;
if (!isSolid(world, x, y-1, z)) return false;
return true;
}
public static boolean isSolid(World world, int x, int y, int z)
{
if (y > world.getMaxHeight()) return false;
if (y < 0) return false;
return world.getBlockAt(x, y, z).getType().isSolid();
}
public static Location moveLocationToBlock(Location location, Block block)
{
return moveLocationToBlockCoords(location, block.getX(), block.getY(), block.getZ());
}
public static Location moveLocationToBlockCoords(Location location, int x, int y, int z)
{
Location ret = location.clone();
ret.setX(x + location.getX() - location.getBlockX());
ret.setY(y + location.getY() - location.getBlockY());
ret.setZ(z + location.getZ() - location.getBlockZ());
return ret;
}
}

View File

@ -0,0 +1,72 @@
package com.massivecraft.massivecore.teleport;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.massivecraft.massivecore.mixin.Mixin;
import com.massivecraft.massivecore.ps.PS;
public class DestinationWorld extends DestinationAbstract
{
private static final long serialVersionUID = 1L;
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
protected String worldId;
public String getWorldId() { return this.worldId; }
public void setWorldId(String worldId) { this.worldId = worldId; }
public void setWorld(World world) { this.worldId = (world == null ? null : world.getName()); }
public World getWorld() { return Bukkit.getWorld(this.worldId); }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public DestinationWorld()
{
}
public DestinationWorld(CommandSender sender)
{
if ( ! (sender instanceof Player)) return;
Player player = (Player)sender;
this.setWorld(player.getWorld());
}
public DestinationWorld(World world)
{
this.setWorld(world);
}
public DestinationWorld(String worldId)
{
this.setWorldId(worldId);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public PS getPs()
{
String worldId = this.getWorldId();
if (worldId == null) return null;
return Mixin.getWorldSpawnPs(worldId);
}
@Override
public String getDesc(Object watcherObject)
{
return "World " + Mixin.getWorldDisplayName(this.getWorldId());
}
}

View File

@ -102,7 +102,7 @@ public class EngineScheduledTeleport extends EngineAbstract
scheduledTeleport.unschedule(); scheduledTeleport.unschedule();
// ... and inform the teleportee. // ... and inform the teleportee.
Mixin.msgOne(scheduledTeleport.getTeleporteeId(), "<rose>Cancelled <i>teleport to <h>"+scheduledTeleport.getDestinationDesc()+"<i>."); Mixin.msgOne(scheduledTeleport.getTeleporteeId(), "<rose>Cancelled <i>teleport to <h>"+scheduledTeleport.getDestination().getDesc(scheduledTeleport.getTeleporteeId())+"<i>.");
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)

View File

@ -1,10 +0,0 @@
package com.massivecraft.massivecore.teleport;
import java.io.Serializable;
import com.massivecraft.massivecore.ps.PS;
public interface PSGetter extends Serializable
{
public PS getPS();
}

View File

@ -1,11 +0,0 @@
package com.massivecraft.massivecore.teleport;
public abstract class PSGetterAbstract implements PSGetter
{
private static final long serialVersionUID = 1L;
public boolean hasPS()
{
return this.getPS() != null;
}
}

View File

@ -1,59 +0,0 @@
package com.massivecraft.massivecore.teleport;
import org.bukkit.command.CommandSender;
import com.massivecraft.massivecore.mixin.Mixin;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.store.SenderEntity;
import com.massivecraft.massivecore.util.IdUtil;
public final class PSGetterPlayer extends PSGetterAbstract
{
private static final long serialVersionUID = 1L;
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private final String senderId;
public String getSenderId() { return this.senderId; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
private PSGetterPlayer(String senderId)
{
this.senderId = senderId;
}
// -------------------------------------------- //
// VALUE OF
// -------------------------------------------- //
public static PSGetterPlayer valueOf(CommandSender player)
{
return new PSGetterPlayer(IdUtil.getId(player));
}
public static PSGetterPlayer valueOf(SenderEntity<?> playerEntity)
{
return new PSGetterPlayer(playerEntity.getId());
}
public static PSGetterPlayer valueOf(String playerId)
{
return new PSGetterPlayer(playerId);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public PS getPS()
{
return Mixin.getSenderPs(this.senderId);
}
}

View File

@ -12,11 +12,8 @@ public class ScheduledTeleport implements Runnable
private final String teleporteeId; private final String teleporteeId;
public String getTeleporteeId() { return this.teleporteeId; } public String getTeleporteeId() { return this.teleporteeId; }
private final PSGetter destinationGetter; private final Destination destination;
public PSGetter getDestinationGetter() { return this.destinationGetter; } public Destination getDestination() { return this.destination; }
private final String destinationDesc;
public String getDestinationDesc() { return this.destinationDesc; }
private final int delaySeconds; private final int delaySeconds;
public int getDelaySeconds() { return this.delaySeconds; } public int getDelaySeconds() { return this.delaySeconds; }
@ -30,11 +27,10 @@ public class ScheduledTeleport implements Runnable
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public ScheduledTeleport(String teleporteeId, PSGetter destinationGetter, String destinationDesc, int delaySeconds) public ScheduledTeleport(String teleporteeId, Destination destination, int delaySeconds)
{ {
this.teleporteeId = teleporteeId; this.teleporteeId = teleporteeId;
this.destinationGetter = destinationGetter; this.destination = destination;
this.destinationDesc = destinationDesc;
this.delaySeconds = delaySeconds; this.delaySeconds = delaySeconds;
this.dueMillis = 0; this.dueMillis = 0;
} }
@ -69,7 +65,7 @@ public class ScheduledTeleport implements Runnable
try try
{ {
Mixin.teleport(this.getTeleporteeId(), this.getDestinationGetter(), this.getDestinationDesc()); Mixin.teleport(this.getTeleporteeId(), this.getDestination(), 0);
} }
catch (TeleporterException e) catch (TeleporterException e)
{ {