Remove that old stuff and add in some new herp.

This commit is contained in:
Olof Larsson 2013-01-30 12:48:18 +01:00
parent 9068618e8c
commit dba940f337
47 changed files with 631 additions and 680 deletions

View File

@ -21,7 +21,6 @@ import com.massivecraft.mcore5.event.MCoreAfterPlayerRespawnEvent;
import com.massivecraft.mcore5.event.MCoreAfterPlayerTeleportEvent;
import com.massivecraft.mcore5.event.MCorePlayerLeaveEvent;
import com.massivecraft.mcore5.store.Coll;
import com.massivecraft.mcore5.store.PlayerColl;
import com.massivecraft.mcore5.store.SenderColl;
import com.massivecraft.mcore5.util.SmokeUtil;
@ -81,7 +80,6 @@ public class InternalListener implements Listener
String id = event.getPlayer().getName();
Player player = event.getPlayer();
PlayerColl.setPlayerRefferences(id, player);
SenderColl.setSenderRefferences(id, player);
}
@ -93,7 +91,6 @@ public class InternalListener implements Listener
String id = event.getPlayer().getName();
Player player = null;
PlayerColl.setPlayerRefferences(id, player);
SenderColl.setSenderRefferences(id, player);
}
@ -103,7 +100,6 @@ public class InternalListener implements Listener
String id = event.getPlayer().getName();
Player player = null;
PlayerColl.setPlayerRefferences(id, player);
SenderColl.setSenderRefferences(id, player);
}
@ -205,8 +201,8 @@ public class InternalListener implements Listener
String playerName = player.getName();
for (Coll<?, ?> coll : Coll.instances)
{
if (!(coll instanceof PlayerColl)) continue;
PlayerColl<?> pcoll = (PlayerColl<?>)coll;
if (!(coll instanceof SenderColl)) continue;
SenderColl<?> pcoll = (SenderColl<?>)coll;
pcoll.syncId(playerName);
}
}

View File

@ -5,20 +5,20 @@ import org.bukkit.command.CommandSender;
public abstract class ARAbstractPrimitive<T> implements ArgReader<T>
{
public abstract String typename();
public abstract T convert(String str) throws Exception;
public abstract T convert(String arg) throws Exception;
@Override
public ArgResult<T> read(String str, CommandSender sender)
public ArgResult<T> read(String arg, CommandSender sender)
{
ArgResult<T> result = new ArgResult<T>();
try
{
result.setResult(this.convert(str));
result.setResult(this.convert(arg));
}
catch (Exception e)
{
result.getErrors().add("<b>Invalid "+this.typename()+" \"<h>"+str+"\"<b>.");
result.getErrors().add("<b>Invalid "+this.typename()+" \"<h>"+arg+"\"<b>.");
}
return result;

View File

@ -14,13 +14,13 @@ public abstract class ARAbstractSelect<T> implements ArgReader<T>
public boolean canList(CommandSender sender) { return true; }
@Override
public ArgResult<T> read(String str, CommandSender sender)
public ArgResult<T> read(String arg, CommandSender sender)
{
ArgResult<T> result = new ArgResult<T>(this.select(str, sender));
ArgResult<T> result = new ArgResult<T>(this.select(arg, sender));
if (!result.hasResult())
{
result.getErrors().add("<b>No "+this.typename()+" matches \"<h>"+str+"<b>\".");
result.getErrors().add("<b>No "+this.typename()+" matches \"<h>"+arg+"<b>\".");
if (this.canList(sender))
{
Collection<String> names = this.altNames(sender);

View File

@ -1,95 +0,0 @@
package com.massivecraft.mcore5.cmd.arg;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore5.util.Txt;
public abstract class ARAbstractStringMatch implements ArgReader<String>
{
// -------------------------------------------- //
// IMPLEMENTATION
// -------------------------------------------- //
@Override
public ArgResult<String> read(String str, CommandSender sender)
{
ArgResult<String> result = new ArgResult<String>();
// Find all matches
Set<String> matches = new HashSet<String>();
String perfectMatch = null;
outerloop:
for (Collection<String> altColl : this.altColls())
{
for (String alt : altColl)
{
Integer matchDistance = this.matches(str, alt);
if (matchDistance == null) continue;
if (matchDistance == 0)
{
perfectMatch = alt;
break outerloop;
}
else
{
matches.add(alt);
}
}
}
// Set result and errors
if (perfectMatch != null)
{
result.setResult(perfectMatch);
}
else if (matches.size() == 1)
{
result.setResult(matches.iterator().next());
}
else if (matches.size() > 1)
{
result.getErrors().add("<b>"+Txt.upperCaseFirst(this.typename())+" matching \"<h>"+str+"<b>\" is ambigious.");
result.getErrors().add("<b>Did you mean "+Txt.implodeCommaAndDot(matches, "<h>%s", "<b>, ", " <b>or ", "<b>?"));
}
else if (matches.size() == 0)
{
result.getErrors().add("<b>No "+this.typename()+" matching \"<h>"+str+"<b>\".");
}
return result;
}
// -------------------------------------------- //
// ABSTRACT
// -------------------------------------------- //
// return null if no match
// return 0 if perfect match
// return >0 to declare distance from perfect match
public abstract Integer matches(String arg, String alt);
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
protected String typename;
public String typename() { return this.typename; }
protected Collection<Collection<String>> altColls;
public Collection<Collection<String>> altColls() { return this.altColls; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public ARAbstractStringMatch(String typename, Collection<Collection<String>> altColls)
{
this.typename = typename;
this.altColls = altColls;
}
}

View File

@ -17,9 +17,9 @@ public class ARAspect extends ARAbstractSelect<Aspect>
}
@Override
public Aspect select(String str, CommandSender sender)
public Aspect select(String arg, CommandSender sender)
{
return AspectColl.i.get(str);
return AspectColl.i.get(arg);
}
@Override

View File

@ -9,10 +9,10 @@ public class ARBoolean extends ARAbstractPrimitive<Boolean>
}
@Override
public Boolean convert(String str) throws Exception
public Boolean convert(String arg) throws Exception
{
str = str.toLowerCase();
if (str.startsWith("y") || str.startsWith("t") || str.startsWith("on") || str.startsWith("+") || str.startsWith("1"))
arg = arg.toLowerCase();
if (arg.startsWith("y") || arg.startsWith("t") || arg.startsWith("on") || arg.startsWith("+") || arg.startsWith("1"))
{
return true;
}

View File

@ -9,9 +9,9 @@ public class ARByte extends ARAbstractPrimitive<Byte>
}
@Override
public Byte convert(String str) throws Exception
public Byte convert(String arg) throws Exception
{
return Byte.parseByte(str);
return Byte.parseByte(arg);
}
// -------------------------------------------- //

View File

@ -16,18 +16,18 @@ public class ARChatColor extends ARAbstractSelect<ChatColor>
}
@Override
public ChatColor select(String str, CommandSender sender)
public ChatColor select(String arg, CommandSender sender)
{
ChatColor ret = null;
str = getToCompare(str);
arg = getToCompare(arg);
for (ChatColor cc : ChatColor.values())
{
String ccstr = getToCompare(cc.name());
if ( ! ccstr.equals(str)) continue;
if ( ! ccstr.equals(arg)) continue;
ret = cc;
break;
}

View File

@ -15,9 +15,9 @@ public class ARDate extends ARAbstractPrimitive<Date>
}
@Override
public Date convert(String str) throws Exception
public Date convert(String arg) throws Exception
{
return df.parse(str);
return df.parse(arg);
}
// -------------------------------------------- //

View File

@ -16,25 +16,25 @@ public class ARDifficulty extends ARAbstractSelect<Difficulty>
}
@Override
public Difficulty select(String str, CommandSender sender)
public Difficulty select(String arg, CommandSender sender)
{
Difficulty ret = null;
str = str.toLowerCase();
arg = arg.toLowerCase();
if (str.startsWith("p"))
if (arg.startsWith("p"))
{
ret = Difficulty.PEACEFUL;
}
else if (str.startsWith("e"))
else if (arg.startsWith("e"))
{
ret = Difficulty.EASY;
}
else if (str.startsWith("n"))
else if (arg.startsWith("n"))
{
ret = Difficulty.NORMAL;
}
else if (str.startsWith("h"))
else if (arg.startsWith("h"))
{
ret = Difficulty.HARD;
}

View File

@ -9,9 +9,9 @@ public class ARDouble extends ARAbstractPrimitive<Double>
}
@Override
public Double convert(String str) throws Exception
public Double convert(String arg) throws Exception
{
return Double.parseDouble(str);
return Double.parseDouble(arg);
}
// -------------------------------------------- //

View File

@ -16,26 +16,26 @@ public class AREnvironment extends ARAbstractSelect<Environment>
}
@Override
public Environment select(String str, CommandSender sender)
public Environment select(String arg, CommandSender sender)
{
Environment ret = null;
// "THE_END" --> "end"
str = str.toLowerCase();
str = str.replace("_", "");
str = str.replace("the", "");
arg = arg.toLowerCase();
arg = arg.replace("_", "");
arg = arg.replace("the", "");
if (str.startsWith("no") || str.startsWith("d"))
if (arg.startsWith("no") || arg.startsWith("d"))
{
// "normal" or "default"
ret = Environment.NORMAL;
}
else if (str.startsWith("ne"))
else if (arg.startsWith("ne"))
{
// "nether"
ret = Environment.NETHER;
}
else if (str.startsWith("e"))
else if (arg.startsWith("e"))
{
// "end"
ret = Environment.THE_END;

View File

@ -9,9 +9,9 @@ public class ARFloat extends ARAbstractPrimitive<Float>
}
@Override
public Float convert(String str) throws Exception
public Float convert(String arg) throws Exception
{
return Float.parseFloat(str);
return Float.parseFloat(arg);
}
// -------------------------------------------- //

View File

@ -16,21 +16,21 @@ public class ARGameMode extends ARAbstractSelect<GameMode>
}
@Override
public GameMode select(String str, CommandSender sender)
public GameMode select(String arg, CommandSender sender)
{
GameMode ret = null;
str = str.toLowerCase();
arg = arg.toLowerCase();
if (str.startsWith("s"))
if (arg.startsWith("s"))
{
ret = GameMode.SURVIVAL;
}
else if (str.startsWith("c"))
else if (arg.startsWith("c"))
{
ret = GameMode.CREATIVE;
}
else if (str.startsWith("a"))
else if (arg.startsWith("a"))
{
ret = GameMode.ADVENTURE;
}

View File

@ -9,9 +9,9 @@ public class ARInteger extends ARAbstractPrimitive<Integer>
}
@Override
public Integer convert(String str) throws Exception
public Integer convert(String arg) throws Exception
{
return Integer.parseInt(str);
return Integer.parseInt(arg);
}
// -------------------------------------------- //

View File

@ -9,9 +9,9 @@ public class ARLong extends ARAbstractPrimitive<Long>
}
@Override
public Long convert(String str) throws Exception
public Long convert(String arg) throws Exception
{
return Long.parseLong(str);
return Long.parseLong(arg);
}
// -------------------------------------------- //

View File

@ -6,12 +6,12 @@ import org.bukkit.command.CommandSender;
public class ARMaterial implements ArgReader<Material>
{
@Override
public ArgResult<Material> read(String str, CommandSender sender)
public ArgResult<Material> read(String arg, CommandSender sender)
{
ArgResult<Material> result = new ArgResult<Material>(Material.matchMaterial(str));
ArgResult<Material> result = new ArgResult<Material>(Material.matchMaterial(arg));
if (!result.hasResult())
{
result.getErrors().add("<b>No material matches <h>"+str+"<b>.");
result.getErrors().add("<b>No material matches <h>"+arg+"<b>.");
result.getErrors().add("<i>Suggestion: <aqua>http://www.minecraftwiki.net/wiki/Data_values");
}
return result;

View File

@ -17,9 +17,9 @@ public class ARMultiverse extends ARAbstractSelect<Multiverse>
}
@Override
public Multiverse select(String str, CommandSender sender)
public Multiverse select(String arg, CommandSender sender)
{
return MultiverseColl.i.get(str);
return MultiverseColl.i.get(arg);
}
@Override

View File

@ -1,31 +0,0 @@
package com.massivecraft.mcore5.cmd.arg;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class AROnlinePlayerExact implements ArgReader<Player>
{
@Override
public ArgResult<Player> read(String str, CommandSender sender)
{
ArgResult<Player> result = new ArgResult<Player>();
Player player = Bukkit.getServer().getPlayerExact(str);
result.setResult(player);
if (!result.hasResult())
{
result.getErrors().add("<b>No online player with exact name \"<h>"+str+"<b>\".");
}
return result;
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static AROnlinePlayerExact i = new AROnlinePlayerExact();
public static AROnlinePlayerExact get() { return i; }
}

View File

@ -1,49 +0,0 @@
package com.massivecraft.mcore5.cmd.arg;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.massivecraft.mcore5.util.Txt;
public class AROnlinePlayerMatch implements ArgReader<Player>
{
@Override
public ArgResult<Player> read(String str, CommandSender sender)
{
ArgResult<Player> result = new ArgResult<Player>();
List<Player> players = Bukkit.getServer().matchPlayer(str);
if (players.size() == 1)
{
result.setResult(players.get(0));
}
else if (players.size() > 1)
{
List<String> names = new ArrayList<String>();
for (Player player : players)
{
names.add(player.getName());
}
result.getErrors().add("<b>Online player matching \"<h>"+str+"<b>\" is ambigious.");
result.getErrors().add("<b>Did you mean "+Txt.implodeCommaAndDot(names, "<h>%s", "<b>, ", " <b>or ", "<b>?"));
}
else if (players.size() == 0)
{
result.getErrors().add("<b>No online player matching \"<h>"+str+"<b>\".");
}
return result;
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static AROnlinePlayerMatch i = new AROnlinePlayerMatch();
public static AROnlinePlayerMatch get() { return i; }
}

View File

@ -0,0 +1,46 @@
package com.massivecraft.mcore5.cmd.arg;
import org.bukkit.entity.Player;
import com.massivecraft.mcore5.store.MixinSenderIdSource;
import com.massivecraft.mcore5.store.SenderIdSource;
import com.massivecraft.mcore5.util.SenderUtil;
public class ARPlayer extends ARSenderIdAbstractPredsource<Player>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static final ARPlayer full = getFull(MixinSenderIdSource.get());
public static ARPlayer getFull() { return full; }
private static final ARPlayer start = getStart(MixinSenderIdSource.get());
public static ARPlayer getStart() { return start; }
public static ARPlayer getFull(SenderIdSource source)
{
return new ARPlayer(source, "player", ArgPredictateStringEqualsLC.get());
}
public static ARPlayer getStart(SenderIdSource source)
{
return new ARPlayer(source, "player", ArgPredictateStringStartsLC.get());
}
private ARPlayer(SenderIdSource source, String typename, ArgPredictate<String> argPredictate)
{
super(source, typename, argPredictate);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public Player getResultForSenderId(String senderId)
{
return SenderUtil.getPlayer(senderId);
}
}

View File

@ -0,0 +1,46 @@
package com.massivecraft.mcore5.cmd.arg;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore5.store.MixinSenderIdSource;
import com.massivecraft.mcore5.store.SenderIdSource;
import com.massivecraft.mcore5.util.SenderUtil;
public class ARSender extends ARSenderIdAbstractPredsource<CommandSender>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static final ARSender full = getFull(MixinSenderIdSource.get());
public static ARSender getFull() { return full; }
private static final ARSender start = getStart(MixinSenderIdSource.get());
public static ARSender getStart() { return start; }
public static ARSender getFull(SenderIdSource source)
{
return new ARSender(source, "sender", ArgPredictateStringEqualsLC.get());
}
public static ARSender getStart(SenderIdSource source)
{
return new ARSender(source, "sender", ArgPredictateStringStartsLC.get());
}
private ARSender(SenderIdSource source, String typename, ArgPredictate<String> argPredictate)
{
super(source, typename, argPredictate);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public CommandSender getResultForSenderId(String senderId)
{
return SenderUtil.getSender(senderId);
}
}

View File

@ -0,0 +1,63 @@
package com.massivecraft.mcore5.cmd.arg;
import com.massivecraft.mcore5.store.SenderIdSource;
import com.massivecraft.mcore5.store.SenderColl;
import com.massivecraft.mcore5.store.SenderEntity;
public class ARSenderEntity<T extends SenderEntity<T>> extends ARSenderIdAbstractPredsource<T>
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private final SenderColl<T> coll;
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
public static <T extends SenderEntity<T>> ARSenderEntity<T> getFullAny(SenderColl<T> coll) { return getFullAny(coll, coll.isCreative() ? coll.getMixinedIdSource() : coll); }
public static <T extends SenderEntity<T>> ARSenderEntity<T> getStartAny(SenderColl<T> coll) { return getStartAny(coll, coll.isCreative() ? coll.getMixinedIdSource() : coll); }
public static <T extends SenderEntity<T>> ARSenderEntity<T> getFullOnline(SenderColl<T> coll) { return getFullOnline(coll, coll.isCreative() ? coll.getMixinedIdSource() : coll); }
public static <T extends SenderEntity<T>> ARSenderEntity<T> getStartOnline(SenderColl<T> coll) { return getStartOnline(coll, coll.isCreative() ? coll.getMixinedIdSource() : coll); }
public static <T extends SenderEntity<T>> ARSenderEntity<T> getFullOnline(SenderColl<T> coll, SenderIdSource source)
{
return new ARSenderEntity<T>(coll, source, "player", new ArgPredictateAnd<String>(ArgPredictateStringEqualsLC.get(), ArgPredictateStringIsOnlineSenderId.get()));
}
public static <T extends SenderEntity<T>> ARSenderEntity<T> getStartOnline(SenderColl<T> coll, SenderIdSource source)
{
return new ARSenderEntity<T>(coll, source, "player", new ArgPredictateAnd<String>(ArgPredictateStringStartsLC.get(), ArgPredictateStringIsOnlineSenderId.get()));
}
public static <T extends SenderEntity<T>> ARSenderEntity<T> getFullAny(SenderColl<T> coll, SenderIdSource source)
{
return new ARSenderEntity<T>(coll, source, "player", ArgPredictateStringEqualsLC.get());
}
public static <T extends SenderEntity<T>> ARSenderEntity<T> getStartAny(SenderColl<T> coll, SenderIdSource source)
{
return new ARSenderEntity<T>(coll, source, "player", ArgPredictateStringStartsLC.get());
}
private ARSenderEntity(SenderColl<T> coll, SenderIdSource source, String typename, ArgPredictate<String> argPredictate)
{
super(source, typename, argPredictate);
this.coll = coll;
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public T getResultForSenderId(String senderId)
{
return this.coll.get(senderId);
}
}

View File

@ -0,0 +1,43 @@
package com.massivecraft.mcore5.cmd.arg;
import com.massivecraft.mcore5.store.MixinSenderIdSource;
import com.massivecraft.mcore5.store.SenderIdSource;
public class ARSenderId extends ARSenderIdAbstractPredsource<String>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static final ARSenderId full = getFull(MixinSenderIdSource.get());
public static ARSenderId getFull() { return full; }
private static final ARSenderId start = getStart(MixinSenderIdSource.get());
public static ARSenderId getStart() { return start; }
public static ARSenderId getFull(SenderIdSource source)
{
return new ARSenderId(source, "player", ArgPredictateStringEqualsLC.get());
}
public static ARSenderId getStart(SenderIdSource source)
{
return new ARSenderId(source, "player", ArgPredictateStringStartsLC.get());
}
private ARSenderId(SenderIdSource source, String typename, ArgPredictate<String> argPredictate)
{
super(source, typename, argPredictate);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public String getResultForSenderId(String senderId)
{
return senderId;
}
}

View File

@ -0,0 +1,69 @@
package com.massivecraft.mcore5.cmd.arg;
import java.util.Collection;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore5.mixin.Mixin;
import com.massivecraft.mcore5.util.Txt;
public abstract class ARSenderIdAbstract<T> implements ArgReader<T>
{
// -------------------------------------------- //
// ABSTRACT
// -------------------------------------------- //
public abstract String getTypename();
public abstract T getResultForSenderId(String senderId);
public abstract Collection<String> getSenderIdsFor(String arg, CommandSender sender);
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public ArgResult<T> read(String arg, CommandSender sender)
{
ArgResult<T> ret = new ArgResult<T>();
Collection<String> senderIds = this.getSenderIdsFor(arg, sender);
if (senderIds.size() == 0)
{
// No alternatives found
ret.setErrors("<b>No "+this.getTypename()+" matches \"<h>"+arg+"<b>\".");
}
else if (senderIds.size() == 1)
{
// Only one alternative found
String senderId = senderIds.iterator().next();
ret.setResult(this.getResultForSenderId(senderId));
}
else if (senderIds.contains(arg))
{
// Exact match
String senderId = Mixin.tryFix(arg);
ret.setResult(this.getResultForSenderId(senderId));
}
else
{
// Ambigious!
ret.getErrors().add("<b>Online "+this.getTypename()+" matching \"<h>"+arg+"<b>\" is ambigious.");
if (senderIds.size() > 10)
{
// To many to list
ret.getErrors().add("<b>Could be any of <h>"+senderIds.size()+" <b>possible alternatives.");
}
else
{
// List the alternatives
ret.getErrors().add("<b>Did you mean "+Txt.implodeCommaAndDot(senderIds, "<h>%s", "<b>, ", " <b>or ", "<b>?"));
}
}
return ret;
}
}

View File

@ -0,0 +1,72 @@
package com.massivecraft.mcore5.cmd.arg;
import java.util.Collection;
import java.util.Iterator;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore5.store.SenderIdSource;
public abstract class ARSenderIdAbstractPredsource<T> extends ARSenderIdAbstract<T>
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private final SenderIdSource source;
private final String typename;
private final ArgPredictate<String> argPredictate;
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public ARSenderIdAbstractPredsource(SenderIdSource source, String typename, ArgPredictate<String> argPredictate)
{
this.source = source;
this.typename = typename;
this.argPredictate = argPredictate;
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public String getTypename()
{
return this.typename;
}
@Override
public Collection<String> getSenderIdsFor(String arg, CommandSender sender)
{
Collection<String> senderIds = this.source.getSenderIds();
arg = arg.toLowerCase();
Iterator<String> iter = senderIds.iterator();
while(iter.hasNext())
{
String senderId = iter.next();
if (this.isSenderIdOk(senderId, arg, sender)) continue;
iter.remove();
}
return senderIds;
}
protected boolean isSenderIdOk(String senderId, String arg, CommandSender sender)
{
// If the predictate applies ...
if (!this.argPredictate.apply(senderId, arg, sender)) return false;
// ... and the result is non null ...
T result = this.getResultForSenderId(senderId);
if (result == null) return false;
// ... then the senderId is ok.
return true;
}
}

View File

@ -9,9 +9,9 @@ public class ARString extends ARAbstractPrimitive<String>
}
@Override
public String convert(String str) throws Exception
public String convert(String arg) throws Exception
{
return str;
return arg;
}
// -------------------------------------------- //

View File

@ -1,54 +0,0 @@
package com.massivecraft.mcore5.cmd.arg;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore5.store.Coll;
import com.massivecraft.mcore5.store.Entity;
public class ARStringEntity<E extends Entity<E, String>> implements ArgReader<E>
{
// -------------------------------------------- //
// IMPLEMENTATION
// -------------------------------------------- //
@Override
public ArgResult<E> read(String str, CommandSender sender)
{
ArgResult<E> result = new ArgResult<E>();
ArgResult<String> innerResult = this.stringReader().read(str, sender);
if (innerResult.hasResult())
{
String playerName = innerResult.getResult();
E entity = this.coll().get(playerName);
result.setResult(entity);
}
else
{
result.setErrors(innerResult.getErrors());
}
return result;
}
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
protected ArgReader<String> stringReader;
public ArgReader<String> stringReader() { return this.stringReader; }
protected Coll<E, String> coll;
public Coll<E, String> coll() { return this.coll; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public ARStringEntity(ArgReader<String> stringReader, Coll<E, String> coll)
{
this.stringReader = stringReader;
this.coll = coll;
}
}

View File

@ -1,25 +0,0 @@
package com.massivecraft.mcore5.cmd.arg;
import java.util.Collection;
public class ARStringMatchFull extends ARAbstractStringMatch
{
// -------------------------------------------- //
// IMPLEMENTATION
// -------------------------------------------- //
@Override
public Integer matches(String arg, String alt)
{
return alt.equalsIgnoreCase(arg) ? 0 : null;
}
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public ARStringMatchFull(String typename, Collection<Collection<String>> altColls)
{
super(typename, altColls);
}
}

View File

@ -1,34 +0,0 @@
package com.massivecraft.mcore5.cmd.arg;
import java.util.Collection;
public class ARStringMatchStart extends ARAbstractStringMatch
{
// -------------------------------------------- //
// IMPLEMENTATION
// -------------------------------------------- //
@Override
public Integer matches(String arg, String alt)
{
arg = arg.toLowerCase();
alt = alt.toLowerCase();
if (alt.startsWith(arg))
{
return alt.length() - arg.length();
}
else
{
return null;
}
}
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public ARStringMatchStart(String typename, Collection<Collection<String>> altColls)
{
super(typename, altColls);
}
}

View File

@ -15,17 +15,17 @@ public class ARUniverse implements ArgReader<String>
// -------------------------------------------- //
@Override
public ArgResult<String> read(String str, CommandSender sender)
public ArgResult<String> read(String arg, CommandSender sender)
{
ArgResult<String> result = new ArgResult<String>();
if (multiverse.containsUniverse(str))
if (multiverse.containsUniverse(arg))
{
result.setResult(str);
result.setResult(arg);
}
else
{
result.getErrors().add("<b>No universe \"<h>"+str+"<b>\" exists in multiverse <h>"+this.multiverse.getId()+"<b>.");
result.getErrors().add("<b>No universe \"<h>"+arg+"<b>\" exists in multiverse <h>"+this.multiverse.getId()+"<b>.");
Collection<String> names = new ArrayList<String>(multiverse.getUniverses());
result.getErrors().add("<i>Use "+Txt.implodeCommaAndDot(names, "<h>%s", "<i>, ", " <i>or ", "<i>."));

View File

@ -16,9 +16,9 @@ public class ARWorld extends ARAbstractSelect<World>
}
@Override
public World select(String str, CommandSender sender)
public World select(String arg, CommandSender sender)
{
return Bukkit.getWorld(str);
return Bukkit.getWorld(arg);
}
@Override

View File

@ -16,36 +16,36 @@ public class ARWorldType extends ARAbstractSelect<WorldType>
}
@Override
public WorldType select(String str, CommandSender sender)
public WorldType select(String arg, CommandSender sender)
{
WorldType ret = null;
// "DEFAULT_1_1" --> "11"
// "LARGE_BIOMES" --> "large"
// "Default" --> ""
str = str.toLowerCase();
str = str.replace("_", "");
str = str.replace(".", "");
str = str.replace("normal", "");
str = str.replace("default", "");
str = str.replace("large", "");
arg = arg.toLowerCase();
arg = arg.replace("_", "");
arg = arg.replace(".", "");
arg = arg.replace("normal", "");
arg = arg.replace("default", "");
arg = arg.replace("large", "");
if (str.equals(""))
if (arg.equals(""))
{
// "normal" or "default"
ret = WorldType.NORMAL;
}
else if (str.startsWith("flat"))
else if (arg.startsWith("flat"))
{
// "flat"
ret = WorldType.FLAT;
}
else if (str.contains("11"))
else if (arg.contains("11"))
{
// "VERSION_1_1"
ret = WorldType.VERSION_1_1;
}
else if (str.contains("large"))
else if (arg.contains("large"))
{
// "LARGE_BIOMES"
ret = WorldType.LARGE_BIOMES;

View File

@ -0,0 +1,8 @@
package com.massivecraft.mcore5.cmd.arg;
import org.bukkit.command.CommandSender;
public interface ArgPredictate<T>
{
public boolean apply(T type, String arg, CommandSender sender);
}

View File

@ -0,0 +1,31 @@
package com.massivecraft.mcore5.cmd.arg;
import org.bukkit.command.CommandSender;
public class ArgPredictateAnd<T> implements ArgPredictate<T>
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private final ArgPredictate<T> one;
private final ArgPredictate<T> two;
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public ArgPredictateAnd(ArgPredictate<T> one, ArgPredictate<T>two)
{
this.one = one;
this.two = two;
}
@Override
public boolean apply(T type, String arg, CommandSender sender)
{
if (!this.one.apply(type, arg, sender)) return false;
return this.two.apply(type, arg, sender);
}
}

View File

@ -0,0 +1,24 @@
package com.massivecraft.mcore5.cmd.arg;
import org.bukkit.command.CommandSender;
public class ArgPredictateStringEqualsLC implements ArgPredictate<String>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static ArgPredictateStringEqualsLC i = new ArgPredictateStringEqualsLC();
public static ArgPredictateStringEqualsLC get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public boolean apply(String string, String arg, CommandSender sender)
{
return string.toLowerCase().equals(arg);
}
}

View File

@ -0,0 +1,26 @@
package com.massivecraft.mcore5.cmd.arg;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore5.mixin.Mixin;
public class ArgPredictateStringIsOnlineSenderId implements ArgPredictate<String>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static ArgPredictateStringIsOnlineSenderId i = new ArgPredictateStringIsOnlineSenderId();
public static ArgPredictateStringIsOnlineSenderId get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public boolean apply(String string, String arg, CommandSender sender)
{
return Mixin.isOnline(string);
}
}

View File

@ -0,0 +1,24 @@
package com.massivecraft.mcore5.cmd.arg;
import org.bukkit.command.CommandSender;
public class ArgPredictateStringStartsLC implements ArgPredictate<String>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static ArgPredictateStringStartsLC i = new ArgPredictateStringStartsLC();
public static ArgPredictateStringStartsLC get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public boolean apply(String string, String arg, CommandSender sender)
{
return string.toLowerCase().startsWith(arg);
}
}

View File

@ -4,5 +4,5 @@ import org.bukkit.command.CommandSender;
public interface ArgReader<T>
{
public ArgResult<T> read(String str, CommandSender sender);
public ArgResult<T> read(String arg, CommandSender sender);
}

View File

@ -0,0 +1,26 @@
package com.massivecraft.mcore5.store;
import java.util.Collection;
import com.massivecraft.mcore5.mixin.Mixin;
public class MixinSenderIdSource implements SenderIdSource
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static MixinSenderIdSource i = new MixinSenderIdSource();
public static MixinSenderIdSource get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public Collection<String> getSenderIds()
{
return Mixin.getAllSenderIds();
}
}

View File

@ -1,155 +0,0 @@
package com.massivecraft.mcore5.store;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.massivecraft.mcore5.MCore;
import com.massivecraft.mcore5.MPlugin;
import com.massivecraft.mcore5.Predictate;
import com.massivecraft.mcore5.cmd.arg.ARStringEntity;
import com.massivecraft.mcore5.cmd.arg.ARStringMatchFull;
import com.massivecraft.mcore5.cmd.arg.ARStringMatchStart;
import com.massivecraft.mcore5.cmd.arg.ArgReader;
import com.massivecraft.mcore5.util.MUtil;
import com.massivecraft.mcore5.util.PlayerUtil;
public class PlayerColl<E extends PlayerEntity<E>> extends Coll<E, String>
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
// Note that the lowercasing should be kept at either true or false.
protected boolean lowercasing = false;
public boolean isLowercasing() { return this.lowercasing; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public PlayerColl(Db<?> db, MPlugin mplugin, String name, Class<E> entityClass, boolean creative, boolean lowercasing)
{
super(db, mplugin, "ai", name, entityClass, String.class, creative);
this.lowercasing = lowercasing;
}
public PlayerColl(Db<?> db, MPlugin mplugin, String name, Class<E> entityClass, boolean creative)
{
this(db, mplugin, name, entityClass, creative, false);
}
public PlayerColl(Db<?> db, MPlugin mplugin, String name, Class<E> entityClass)
{
this(db, mplugin, name, entityClass, true);
}
public PlayerColl(MPlugin mplugin, String name, Class<E> entityClass, boolean creative, boolean lowercasing)
{
this(MCore.getDb(), mplugin, name, entityClass, creative, lowercasing);
}
public PlayerColl(MPlugin mplugin, String name, Class<E> entityClass, boolean creative)
{
this(MCore.getDb(), mplugin, name, entityClass, creative);
}
public PlayerColl(MPlugin mplugin, String name, Class<E> entityClass)
{
this(MCore.getDb(), mplugin, name, entityClass);
}
// -------------------------------------------- //
// EXTRAS
// -------------------------------------------- //
@Override
public String fixId(Object oid)
{
if (oid == null) return null;
String ret = MUtil.extract(String.class, "playerName", oid);
if (ret == null) return ret;
return this.lowercasing ? ret.toLowerCase() : ret;
}
public Collection<E> getAllOnline()
{
List<E> ret = new ArrayList<E>();
for(Player player : Bukkit.getOnlinePlayers())
{
E entity = this.get(player.getName());
if (entity == null) continue;
ret.add(entity);
}
return ret;
}
public Collection<E> getAllOffline()
{
return this.getAll(new Predictate<E>()
{
public boolean apply(E entity)
{
return entity.isOffline();
}
});
}
// -------------------------------------------- //
// PLAYER REFFERENCE MANAGEMENT
// -------------------------------------------- //
protected void setPlayerRefference(String playerName, Player player)
{
E pentity = this.get(playerName, false);
if (pentity == null) return;
pentity.player = player;
pentity.playerInitiated = true;
}
public static void setPlayerRefferences(String playerName, Player player)
{
for (Coll<?, ?> coll : Coll.instances)
{
if (!(coll instanceof PlayerColl)) continue;
PlayerColl<?> pcoll = (PlayerColl<?>)coll;
pcoll.setPlayerRefference(playerName, player);
}
}
// -------------------------------------------- //
// ARGUMENT READERS
// -------------------------------------------- //
protected Collection<Collection<String>> forgeAltColls()
{
Collection<Collection<String>> ret = new ArrayList<Collection<String>>();
ret.add(this.getIds());
if (this.isCreative()) ret.add(PlayerUtil.getAllVisitorNames());
return ret;
}
public ArgReader<String> argReaderPlayerNameFull()
{
return new ARStringMatchFull("player", this.forgeAltColls());
}
public ArgReader<String> argReaderPlayerNameStart()
{
return new ARStringMatchStart("player", this.forgeAltColls());
}
public ArgReader<E> argReaderPlayerFull()
{
return new ARStringEntity<E>(this.argReaderPlayerNameFull(), this);
}
public ArgReader<E> argReaderPlayerStart()
{
return new ARStringEntity<E>(this.argReaderPlayerNameStart(), this);
}
}

View File

@ -1,122 +0,0 @@
package com.massivecraft.mcore5.store;
import java.util.Collection;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import com.massivecraft.mcore5.util.Txt;
public abstract class PlayerEntity<E extends PlayerEntity<E>> extends Entity<E, String>
{
// The Bukkit player reference is initiated here
// It's kept updated using the InternalListener
protected transient Player player = null;
protected transient boolean playerInitiated = false;
public Player getPlayer()
{
if ( ! this.playerInitiated)
{
this.player = Bukkit.getPlayerExact(this.getId());
this.playerInitiated = true;
}
return this.player;
}
@Override
public PlayerColl<E> getColl()
{
return (PlayerColl<E>) super.getColl();
}
public boolean isOnline()
{
return this.getPlayer() != null;
}
public boolean isOffline()
{
return ! isOnline();
}
/*public String getCurrentUniverse()
{
Player player = this.getPlayer();
if (player == null) return null;
String aspectId = this.getColl().nameAspect();
Aspect aspect = Aspect.get(aspectId);
aspect.
return USelColl.i.get(aspect).select(player.getWorld().getName());
vi ska returna ett universeId
}
public boolean isInThisUniverse()
{
String universe = this.getUniverse();
if (universe == null) return false;
String currentUniverse = this.getCurrentUniverse();
if (currentUniverse == null) return false;
return universe.equals(currentUniverse);
}*/
// -------------------------------------------- //
// CHECKER UTILS
// -------------------------------------------- //
public boolean isGameMode(GameMode gm, boolean defaultIfOffline)
{
Player player = this.getPlayer();
if (player == null || ! player.isOnline()) return defaultIfOffline;
return player.getGameMode() == gm;
}
// -------------------------------------------- //
// Message Sending Helpers
// -------------------------------------------- //
public void sendMessage(String msg)
{
Player player = this.getPlayer();
if (player == null) return;
player.sendMessage(msg);
}
public void sendMessage(Collection<String> msgs)
{
Player player = this.getPlayer();
if (player == null) return;
for(String msg : msgs)
{
player.sendMessage(msg);
}
}
public void msg(String msg)
{
this.sendMessage(Txt.parse(msg));
}
public void msg(String msg, Object... args)
{
this.sendMessage(Txt.parse(msg, args));
}
public void msg(Collection<String> msgs)
{
Player player = this.getPlayer();
if (player == null) return;
for(String msg : msgs)
{
player.sendMessage(Txt.parse(msg));
}
}
}

View File

@ -1,6 +1,5 @@
package com.massivecraft.mcore5.store;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.TreeSet;
@ -9,16 +8,10 @@ import org.bukkit.command.CommandSender;
import com.massivecraft.mcore5.MPlugin;
import com.massivecraft.mcore5.Predictate;
import com.massivecraft.mcore5.cmd.arg.ARStringEntity;
import com.massivecraft.mcore5.cmd.arg.ARStringMatchFull;
import com.massivecraft.mcore5.cmd.arg.ARStringMatchStart;
import com.massivecraft.mcore5.cmd.arg.ArgReader;
import com.massivecraft.mcore5.mixin.Mixin;
import com.massivecraft.mcore5.util.MUtil;
import com.massivecraft.mcore5.util.PlayerUtil;
import com.massivecraft.mcore5.util.SenderUtil;
public class SenderColl<E extends SenderEntity<E>> extends Coll<E, String>
public class SenderColl<E extends SenderEntity<E>> extends Coll<E, String> implements SenderIdSource
{
// -------------------------------------------- //
// CONSTANTS
@ -38,6 +31,9 @@ public class SenderColl<E extends SenderEntity<E>> extends Coll<E, String>
protected boolean lowercasing;
public boolean isLowercasing() { return this.lowercasing; }
protected final SenderIdSource mixinedIdSource = new SenderIdSourceCombined(this, MixinSenderIdSource.get());
public SenderIdSource getMixinedIdSource() { return this.mixinedIdSource; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
@ -77,6 +73,12 @@ public class SenderColl<E extends SenderEntity<E>> extends Coll<E, String>
return ret;
}
@Override
public Collection<String> getSenderIds()
{
return this.getFixedIds();
}
@Override
public String fixId(Object oid)
{
@ -134,36 +136,14 @@ public class SenderColl<E extends SenderEntity<E>> extends Coll<E, String>
// ARGUMENT READERS
// -------------------------------------------- //
protected Collection<Collection<String>> forgeAltColls()
/*public ArgReader<E> getARFullAny()
{
Collection<Collection<String>> ret = new ArrayList<Collection<String>>();
ret.add(this.getIds());
if (this.isCreative())
{
ret.add(PlayerUtil.getAllVisitorNames());
ret.add(SenderUtil.getIdToSender().keySet());
}
return ret;
return ARSenderEntity.getFullAny(this);
}
public ArgReader<String> argReaderSenderIdFull()
public ArgReader<E> getARStartAny()
{
return new ARStringMatchFull("player", this.forgeAltColls());
}
public ArgReader<String> argReaderSenderIdStart()
{
return new ARStringMatchStart("player", this.forgeAltColls());
}
public ArgReader<E> argReaderEntityFull()
{
return new ARStringEntity<E>(this.argReaderSenderIdFull(), this);
}
public ArgReader<E> argReaderEntityStart()
{
return new ARStringEntity<E>(this.argReaderSenderIdStart(), this);
}
return ARSenderEntity.getStartAny(this);
}*/
}

View File

@ -32,6 +32,15 @@ public abstract class SenderEntity<E extends SenderEntity<E>> extends Entity<E,
return this.sender;
}
// -------------------------------------------- //
// FIXED ID
// -------------------------------------------- //
public String getFixedId()
{
return Mixin.tryFix(this.getId());
}
// -------------------------------------------- //
// OVERRIDES
// -------------------------------------------- //
@ -116,12 +125,12 @@ public abstract class SenderEntity<E extends SenderEntity<E>> extends Entity<E,
public boolean isOnline()
{
return this.getSender() != null;
return Mixin.isOnline(this.getId());
}
public boolean isOffline()
{
return ! isOnline();
return Mixin.isOffline(this.getId());
}
// DISPLAY NAME

View File

@ -0,0 +1,8 @@
package com.massivecraft.mcore5.store;
import java.util.Collection;
public interface SenderIdSource
{
public Collection<String> getSenderIds();
}

View File

@ -0,0 +1,46 @@
package com.massivecraft.mcore5.store;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.TreeSet;
public class SenderIdSourceCombined implements SenderIdSource
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private final List<SenderIdSource> sources;
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public SenderIdSourceCombined(SenderIdSource... sources)
{
this.sources = new ArrayList<SenderIdSource>(Arrays.asList(sources));
}
public SenderIdSourceCombined(Collection<SenderIdSource> sources)
{
this.sources = new ArrayList<SenderIdSource>(sources);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public Collection<String> getSenderIds()
{
TreeSet<String> ret = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
for (SenderIdSource source : this.sources)
{
ret.addAll(source.getSenderIds());
}
return ret;
}
}

View File

@ -26,7 +26,6 @@ import org.bukkit.event.vehicle.VehicleEvent;
import org.bukkit.event.vehicle.VehicleExitEvent;
import com.massivecraft.mcore5.PS;
import com.massivecraft.mcore5.store.PlayerEntity;
import com.massivecraft.mcore5.store.SenderEntity;
import com.massivecraft.mcore5.util.SenderUtil;
@ -97,7 +96,7 @@ public class ExtractorLogic
if (o == null) return null;
if (o instanceof String) return (String)o;
if (o instanceof SenderEntity) return ((SenderEntity<?>)o).getId();
if (o instanceof PlayerEntity) return ((PlayerEntity<?>)o).getId();
if (o instanceof SenderEntity) return ((SenderEntity<?>)o).getId();
CommandSender sender = senderFromObject(o);
if (sender == null) return null;
return SenderUtil.getSenderId(sender);