Fixing with argument handlers.
This commit is contained in:
parent
9519d46a42
commit
d823098f44
@ -9,6 +9,13 @@ import java.util.Set;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
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
|
public class Cmd
|
||||||
{
|
{
|
||||||
protected Map<Class<?>, IArgHandler<?>> argHandlers = new HashMap<Class<?>, IArgHandler<?>>();
|
protected Map<Class<?>, IArgHandler<?>> argHandlers = new HashMap<Class<?>, IArgHandler<?>>();
|
||||||
|
@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import com.massivecraft.mcore1.Lang;
|
import com.massivecraft.mcore1.Lang;
|
||||||
import com.massivecraft.mcore1.MCore;
|
import com.massivecraft.mcore1.MCore;
|
||||||
|
import com.massivecraft.mcore1.cmd.arg.IArgHandler;
|
||||||
import com.massivecraft.mcore1.persist.IClassManager;
|
import com.massivecraft.mcore1.persist.IClassManager;
|
||||||
import com.massivecraft.mcore1.persist.Persist;
|
import com.massivecraft.mcore1.persist.Persist;
|
||||||
import com.massivecraft.mcore1.plugin.MPlugin;
|
import com.massivecraft.mcore1.plugin.MPlugin;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.massivecraft.mcore1.cmd;
|
package com.massivecraft.mcore1.cmd.arg;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.massivecraft.mcore1.cmd;
|
package com.massivecraft.mcore1.cmd.arg;
|
||||||
|
|
||||||
public class AHBoolean extends AHPrimitive<Boolean>
|
public class AHBoolean extends AHPrimitive<Boolean>
|
||||||
{
|
{
|
@ -1,4 +1,4 @@
|
|||||||
package com.massivecraft.mcore1.cmd;
|
package com.massivecraft.mcore1.cmd.arg;
|
||||||
|
|
||||||
public class AHDouble extends AHPrimitive<Double>
|
public class AHDouble extends AHPrimitive<Double>
|
||||||
{
|
{
|
@ -1,4 +1,4 @@
|
|||||||
package com.massivecraft.mcore1.cmd;
|
package com.massivecraft.mcore1.cmd.arg;
|
||||||
|
|
||||||
public class AHFloat extends AHPrimitive<Float>
|
public class AHFloat extends AHPrimitive<Float>
|
||||||
{
|
{
|
@ -1,4 +1,4 @@
|
|||||||
package com.massivecraft.mcore1.cmd;
|
package com.massivecraft.mcore1.cmd.arg;
|
||||||
|
|
||||||
public class AHInteger extends AHPrimitive<Integer>
|
public class AHInteger extends AHPrimitive<Integer>
|
||||||
{
|
{
|
@ -1,4 +1,4 @@
|
|||||||
package com.massivecraft.mcore1.cmd;
|
package com.massivecraft.mcore1.cmd.arg;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -23,14 +23,17 @@ public class AHPlayer extends AHBase<Player>
|
|||||||
{
|
{
|
||||||
return players.get(0);
|
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>\".";
|
||||||
}
|
}
|
||||||
|
else
|
||||||
Player player = Bukkit.getServer().getPlayer(str);
|
{
|
||||||
if (player == null)
|
Player player = Bukkit.getServer().getPlayer(str);
|
||||||
|
if (player != null)
|
||||||
{
|
{
|
||||||
this.error = "<b>No player online with the exact name \"<p>"+str+"<b>\".";
|
|
||||||
}
|
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
this.error = "<b>No player online with the exact name \"<p>"+str+"<b>\".";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
47
src/com/massivecraft/mcore1/cmd/arg/AHPlayerWrapper.java
Normal file
47
src/com/massivecraft/mcore1/cmd/arg/AHPlayerWrapper.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.massivecraft.mcore1.cmd;
|
package com.massivecraft.mcore1.cmd.arg;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.massivecraft.mcore1.cmd;
|
package com.massivecraft.mcore1.cmd.arg;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user