DisplayName per beholder

This commit is contained in:
Olof Larsson 2014-06-21 19:05:20 +02:00
parent 944aaf6853
commit 1fb0fd9abe
9 changed files with 65 additions and 18 deletions

View File

@ -47,9 +47,23 @@ public class AREnum<T> extends ARAbstractSelect<T>
arg = getComparable(arg);
// Algorithmic General Detection
int startswithCount = 0;
T startswith = null;
for (T value : getEnumValues(this.clazz))
{
if (getComparable(value.toString()).equals(arg)) return value;
String comparable = getComparable(value.toString());
if (comparable.equals(arg)) return value;
if (comparable.startsWith(arg))
{
startswith = value;
startswithCount++;
}
}
if (startswithCount == 1)
{
return startswith;
}
// Nothing found

View File

@ -38,7 +38,7 @@ public class ReqIsntCertainSender extends ReqAbstract
@Override
public String createErrorMessage(CommandSender sender, MassiveCommand command)
{
return Txt.parse("<b>Player can't be <h>%s<b>.", Mixin.getDisplayName(this.getSenderId()));
return Txt.parse("<b>Player can't be <h>%s<b>.", Mixin.getDisplayName(this.getSenderId(), sender));
}
}

View File

@ -2,6 +2,5 @@ package com.massivecraft.massivecore.mixin;
public interface DisplayNameMixin
{
public String getDisplayName(Object senderObject);
public String getDisplayName(Object senderObject, Object watcherObject);
}

View File

@ -2,14 +2,5 @@ package com.massivecraft.massivecore.mixin;
public abstract class DisplayNameMixinAbstract implements DisplayNameMixin
{
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public String getDisplayName(Object senderObject)
{
return this.getDisplayName(senderObject, null);
}
}

View File

@ -119,9 +119,10 @@ public class Mixin
// STATIC EXPOSE: DISPLAY NAME
// -------------------------------------------- //
@Deprecated
public static String getDisplayName(Object senderObject)
{
return getDisplayNameMixin().getDisplayName(senderObject);
return getDisplayNameMixin().getDisplayName(senderObject, null);
}
public static String getDisplayName(Object senderObject, Object watcherObject)

View File

@ -74,7 +74,7 @@ public class TeleportMixinDefault extends TeleportMixinAbstract
public void teleport(Object teleporteeObject, PSGetter toGetter, String desc, int delaySeconds) throws TeleporterException
{
String teleporteeId = IdUtil.getId(teleporteeObject);
if (!IdUtil.isPlayerId(teleporteeId)) throw new TeleporterException(Txt.parse("<white>%s <b>is not a player.", Mixin.getDisplayName(teleporteeId)));
if (!IdUtil.isPlayerId(teleporteeId)) throw new TeleporterException(Txt.parse("<white>%s <b>is not a player.", Mixin.getDisplayName(teleporteeId, IdUtil.getConsole())));
if (delaySeconds > 0)
{

View File

@ -95,6 +95,7 @@ public abstract class SenderEntity<E extends SenderEntity<E>> extends Entity<E>
// DISPLAY NAME
@Deprecated
public String getDisplayName()
{
return Mixin.getDisplayName(this.getId());

View File

@ -732,11 +732,25 @@ public class IdUtil implements Listener, Runnable
return MUtil.isValidPlayerName(string) || MUtil.isValidUUID(string);
}
public static boolean isPlayer(Object senderObject)
{
String id = IdUtil.getId(senderObject);
if (id == null) return false;
return isPlayerId(id);
}
public static boolean isConsoleId(String string)
{
return CONSOLE_ID.equals(string);
}
public static boolean isConsole(Object senderObject)
{
String id = IdUtil.getId(senderObject);
if (id == null) return false;
return isConsoleId(id);
}
// -------------------------------------------- //
// GET AS
// -------------------------------------------- //

View File

@ -25,8 +25,10 @@ import org.bukkit.event.vehicle.VehicleEnterEvent;
import org.bukkit.event.vehicle.VehicleEvent;
import org.bukkit.event.vehicle.VehicleExitEvent;
import com.massivecraft.massivecore.mixin.Mixin;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.IdUtil;
import com.massivecraft.massivecore.util.MUtil;
public class ExtractorLogic
{
@ -156,7 +158,6 @@ public class ExtractorLogic
public static World worldFromObject(Object o)
{
if (o instanceof World) return (World)o;
if (o instanceof Block) return world((Block)o);
if (o instanceof Location) return world((Location)o);
if (o instanceof Entity) return world((Entity)o);
@ -172,11 +173,37 @@ public class ExtractorLogic
public static String worldNameFromObject(Object o)
{
if (o instanceof String) return (String)o;
if (o instanceof String)
{
String string = (String)o;
if (MUtil.isValidUUID(string))
{
String ret = worldNameViaPsMixin(string);
if (ret != null) return ret;
}
return string;
}
if (o instanceof PS) return ((PS)o).getWorld();
World world = worldFromObject(o);
if (world == null) return null;
return world.getName();
if (world != null) return world.getName();
String ret = worldNameViaPsMixin(o);
if (ret != null) return ret;
return null;
}
public static String worldNameViaPsMixin(Object senderObject)
{
if (senderObject == null) return null;
PS ps = Mixin.getSenderPs(senderObject);
if (ps == null) return null;
return ps.getWorld();
}
}