Changes to the PS Destination teleporter system.

This commit is contained in:
Olof Larsson 2015-05-22 14:17:30 +02:00
parent a1f2e76221
commit 9587b756c9
14 changed files with 84 additions and 24 deletions

View File

@ -95,7 +95,7 @@ public class MassiveCoreEngineDestination extends EngineAbstract
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_WORLD = new MassiveSet<String>("w", "world", "spawn", "wspawn", "worldspawn");
public static final Set<String> ALIASES_PLAYER = new MassiveSet<String>("p", "player", "here", "me", "self");
public Destination destinationArg(String arg, CommandSender sender) throws MassiveException

View File

@ -2,6 +2,9 @@ package com.massivecraft.massivecore;
import java.util.Comparator;
import com.massivecraft.massivecore.store.ComparatorEntityId;
import com.massivecraft.massivecore.store.Entity;
public class PriorityComparator implements Comparator<Prioritized>
{
// -------------------------------------------- //
@ -16,21 +19,30 @@ public class PriorityComparator implements Comparator<Prioritized>
// -------------------------------------------- //
@Override
public int compare(Prioritized one, Prioritized two)
public int compare(Prioritized p1, Prioritized p2)
{
if (one == null && two == null) return 0;
if (two == null) return 1;
if (one == null) return -1;
// Null
if (p1 == null && p2 == null) return 0;
if (p1 == null) return -1;
if (p2 == null) return +1;
int ret = Integer.valueOf(one.getPriority()).compareTo(two.getPriority());
// Equals
if (p1.equals(p2)) return 0;
// We should only return 0 if the items actually are equal.
if (ret == 0 && ! one.equals(two))
// Priority
int ret = Integer.compare(p1.getPriority(), p2.getPriority());
if (ret != 0) return ret;
// Entity Id
if (p1 instanceof Entity<?> && p2 instanceof Entity<?>)
{
ret = two.hashCode() - one.hashCode();
Entity<?> e1 = (Entity<?>)p1;
Entity<?> e2 = (Entity<?>)p2;
return ComparatorEntityId.get().compare(e1, e2);
}
return ret;
// We should only return 0 if the items actually are equal.
return p2.hashCode() - p1.hashCode();
}
}

View File

@ -33,7 +33,8 @@ public class ARDestination extends ARAbstract<Destination>
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));
// Throw exeption if ps is null.
ret.getPs(sender);
return ret;
}

View File

@ -76,7 +76,15 @@ public class TeleportMixinDefault extends TeleportMixinAbstract
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 ( ! destination.hasPs()) throw new TeleporterException(destination.getMessagePsNull(teleporteeId));
PS ps;
try
{
ps = destination.getPs(teleporteeId);
}
catch (Exception e)
{
throw new TeleporterException(e.getMessage());
}
String desc = destination.getDesc(teleporteeId);
if (delaySeconds > 0)
@ -112,11 +120,11 @@ public class TeleportMixinDefault extends TeleportMixinAbstract
Player teleportee = IdUtil.getPlayer(teleporteeId);
if (teleportee != null)
{
teleportPlayer(teleportee, destination.getPs());
teleportPlayer(teleportee, ps);
}
else
{
Mixin.setSenderPs(teleporteeId, destination.getPs());
Mixin.setSenderPs(teleporteeId, ps);
}
}
}

View File

@ -2,11 +2,12 @@ package com.massivecraft.massivecore.teleport;
import java.io.Serializable;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.ps.PS;
public interface Destination extends Serializable
{
public PS getPs();
public PS getPs(Object watcherObject) throws MassiveException;
public boolean hasPs();
public String getMessagePsNull(Object watcherObject);

View File

@ -1,5 +1,7 @@
package com.massivecraft.massivecore.teleport;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.ps.PSFormatHumanSpace;
import com.massivecraft.massivecore.util.Txt;
@ -13,14 +15,41 @@ public abstract class DestinationAbstract implements Destination
protected String desc = null;
// -------------------------------------------- //
// ABSTRACT
// -------------------------------------------- //
public PS getPsInner()
{
return null;
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public PS getPs(Object watcherObject) throws MassiveException
{
PS ret = this.getPsInner();
if (ret == null)
{
throw new MassiveException().addMessage(this.getMessagePsNull(watcherObject));
}
return ret;
}
@Override
public boolean hasPs()
{
return this.getPs() != null;
try
{
return this.getPs(null) != null;
}
catch (MassiveException e)
{
return false;
}
}
@Override
@ -34,7 +63,15 @@ public abstract class DestinationAbstract implements Destination
public String getDesc(Object watcherObject)
{
if (this.desc != null) return this.desc;
return PSFormatHumanSpace.get().format(this.getPs());
try
{
PS ps = this.getPs(watcherObject);
return PSFormatHumanSpace.get().format(ps);
}
catch (MassiveException e)
{
return "null";
}
}
@Override

View File

@ -28,7 +28,7 @@ public class DestinationJump extends DestinationPlayer
// -------------------------------------------- //
@Override
public PS getPs()
public PS getPsInner()
{
Player player = this.getPlayer();
if (player == null) return null;

View File

@ -44,7 +44,7 @@ public class DestinationPlayer extends DestinationAbstract
// -------------------------------------------- //
@Override
public PS getPs()
public PS getPsInner()
{
return Mixin.getSenderPs(this.playerId);
}

View File

@ -38,7 +38,7 @@ public class DestinationSimple extends DestinationAbstract
// -------------------------------------------- //
@Override
public PS getPs()
public PS getPsInner()
{
return this.ps;
}

View File

@ -28,7 +28,7 @@ public class DestinationThat extends DestinationPlayer
// -------------------------------------------- //
@Override
public PS getPs()
public PS getPsInner()
{
Player player = this.getPlayer();
if (player == null) return null;

View File

@ -28,7 +28,7 @@ public class DestinationThere extends DestinationPlayer
// -------------------------------------------- //
@Override
public PS getPs()
public PS getPsInner()
{
Player player = this.getPlayer();
if (player == null) return null;

View File

@ -28,7 +28,7 @@ public class DestinationTop extends DestinationPlayer
// -------------------------------------------- //
@Override
public PS getPs()
public PS getPsInner()
{
Player player = this.getPlayer();
if (player == null) return null;

View File

@ -55,7 +55,7 @@ public class DestinationWorld extends DestinationAbstract
// -------------------------------------------- //
@Override
public PS getPs()
public PS getPsInner()
{
String worldId = this.getWorldId();
if (worldId == null) return null;

View File

@ -292,6 +292,7 @@ public class InventoryUtil
public static ItemStack cloneItemStack(ItemStack itemStack)
{
if (itemStack == null) return null;
return new ItemStack(itemStack);
}