Fixing with argument handlers.

This commit is contained in:
Olof Larsson 2011-12-12 18:43:52 +01:00
parent 9519d46a42
commit d823098f44
11 changed files with 71 additions and 13 deletions

View File

@ -9,6 +9,13 @@ import java.util.Set;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.massivecraft.mcore1.cmd.arg.AHBoolean;
import com.massivecraft.mcore1.cmd.arg.AHDouble;
import com.massivecraft.mcore1.cmd.arg.AHFloat;
import com.massivecraft.mcore1.cmd.arg.AHInteger;
import com.massivecraft.mcore1.cmd.arg.AHPlayer;
import com.massivecraft.mcore1.cmd.arg.IArgHandler;
public class Cmd
{
protected Map<Class<?>, IArgHandler<?>> argHandlers = new HashMap<Class<?>, IArgHandler<?>>();

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
import com.massivecraft.mcore1.Lang;
import com.massivecraft.mcore1.MCore;
import com.massivecraft.mcore1.cmd.arg.IArgHandler;
import com.massivecraft.mcore1.persist.IClassManager;
import com.massivecraft.mcore1.persist.Persist;
import com.massivecraft.mcore1.plugin.MPlugin;

View File

@ -1,4 +1,4 @@
package com.massivecraft.mcore1.cmd;
package com.massivecraft.mcore1.cmd.arg;
import org.bukkit.command.CommandSender;

View File

@ -1,4 +1,4 @@
package com.massivecraft.mcore1.cmd;
package com.massivecraft.mcore1.cmd.arg;
public class AHBoolean extends AHPrimitive<Boolean>
{

View File

@ -1,4 +1,4 @@
package com.massivecraft.mcore1.cmd;
package com.massivecraft.mcore1.cmd.arg;
public class AHDouble extends AHPrimitive<Double>
{

View File

@ -1,4 +1,4 @@
package com.massivecraft.mcore1.cmd;
package com.massivecraft.mcore1.cmd.arg;
public class AHFloat extends AHPrimitive<Float>
{

View File

@ -1,4 +1,4 @@
package com.massivecraft.mcore1.cmd;
package com.massivecraft.mcore1.cmd.arg;
public class AHInteger extends AHPrimitive<Integer>
{

View File

@ -1,4 +1,4 @@
package com.massivecraft.mcore1.cmd;
package com.massivecraft.mcore1.cmd.arg;
import java.util.List;
@ -23,14 +23,17 @@ public class AHPlayer extends AHBase<Player>
{
return players.get(0);
}
this.error = "<b>\"<p>"+str+"<b>\" did not match any online player.";
this.error = "<b>No online player's name begins with \"<p>"+str+"<b>\".";
}
Player player = Bukkit.getServer().getPlayer(str);
if (player == null)
else
{
Player player = Bukkit.getServer().getPlayer(str);
if (player != null)
{
this.error = "<b>No player online with the exact name \"<p>"+str+"<b>\".";
}
return player;
}
this.error = "<b>No player online with the exact name \"<p>"+str+"<b>\".";
}
return null;
}
}

View File

@ -0,0 +1,47 @@
package com.massivecraft.mcore1.cmd.arg;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore1.persist.IClassManager;
import com.massivecraft.mcore1.plugin.MPlugin;
public abstract class AHPlayerWrapper<T> extends AHBase<T>
{
public abstract Class<T> getClazz();
public IClassManager<T> getManager(MPlugin p)
{
return p.persist.getManager(getClazz());
}
@Override
public T parse(String str, String style, CommandSender sender, MPlugin p)
{
this.error = null;
if (str == null) return null;
IClassManager<T> manager = this.getManager(p);
T ret;
if (style.equals("match"))
{
ret = manager.getBestMatch(str);
if (ret != null)
{
return ret;
}
this.error = "<b>No player name begins with \"<p>"+str+"<b>\".";
}
else
{
ret = manager.get(str);
if (ret != null)
{
return ret;
}
this.error = "<b>No player with the exact name \"<p>"+str+"<b>\".";
}
return null;
}
}

View File

@ -1,4 +1,4 @@
package com.massivecraft.mcore1.cmd;
package com.massivecraft.mcore1.cmd.arg;
import org.bukkit.command.CommandSender;

View File

@ -1,4 +1,4 @@
package com.massivecraft.mcore1.cmd;
package com.massivecraft.mcore1.cmd.arg;
import org.bukkit.command.CommandSender;