Now using a sender fixer method to set vars instead of functions with consolecommands. And added commaAndDot.
This commit is contained in:
parent
c18a57f17a
commit
155344a7ad
@ -1,8 +1,8 @@
|
||||
name: mcore1
|
||||
version: 1
|
||||
depend: [Spout]
|
||||
main: com.massivecraft.mcore1.MCore
|
||||
authors: [Olof Larsson]
|
||||
softdepend: [Spout]
|
||||
commands:
|
||||
mcoresilenteater:
|
||||
description: ignore me.
|
@ -12,8 +12,6 @@ import com.massivecraft.mcore1.MCore;
|
||||
import com.massivecraft.mcore1.MPlugin;
|
||||
import com.massivecraft.mcore1.cmd.arg.IArgHandler;
|
||||
import com.massivecraft.mcore1.cmd.req.IReq;
|
||||
import com.massivecraft.mcore1.persist.IClassManager;
|
||||
import com.massivecraft.mcore1.persist.Persist;
|
||||
import com.massivecraft.mcore1.util.Perm;
|
||||
import com.massivecraft.mcore1.util.Txt;
|
||||
|
||||
@ -125,9 +123,12 @@ public abstract class MCommand
|
||||
public List<MCommand> getCommandChain() { return this.commandChain; }
|
||||
public void setCommandChain(List<MCommand> val) { this.commandChain = val; }
|
||||
|
||||
// FIELD: sender
|
||||
protected CommandSender sender;
|
||||
public CommandSender getSender() { return this.sender; }
|
||||
// FIELDS: sender, me, senderIsConsole
|
||||
public CommandSender sender;
|
||||
public Player me;
|
||||
public boolean senderIsConsole;
|
||||
|
||||
/*
|
||||
public boolean getSenderIsConsole() { return ! (this.sender instanceof Player); }
|
||||
public Player me()
|
||||
{
|
||||
@ -137,6 +138,9 @@ public abstract class MCommand
|
||||
}
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getSenderAs(Class<T> clazz)
|
||||
{
|
||||
@ -152,7 +156,7 @@ public abstract class MCommand
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}*/
|
||||
|
||||
public MCommand()
|
||||
{
|
||||
@ -178,6 +182,16 @@ public abstract class MCommand
|
||||
{
|
||||
// Set the execution-time specific variables
|
||||
this.sender = sender;
|
||||
this.senderIsConsole = true;
|
||||
this.me = null;
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
this.me = (Player) sender;
|
||||
this.senderIsConsole = false;
|
||||
}
|
||||
|
||||
this.fixSenderVars();
|
||||
|
||||
this.args = args;
|
||||
this.commandChain = commandChain;
|
||||
|
||||
@ -201,6 +215,8 @@ public abstract class MCommand
|
||||
perform();
|
||||
}
|
||||
|
||||
public void fixSenderVars() {};
|
||||
|
||||
public void execute(CommandSender sender, List<String> args)
|
||||
{
|
||||
execute(sender, args, new ArrayList<MCommand>());
|
||||
@ -443,4 +459,13 @@ public abstract class MCommand
|
||||
{
|
||||
return this.argAs(idx, clazz, null, null);
|
||||
}
|
||||
|
||||
public String argConcatFrom(int idx)
|
||||
{
|
||||
if ( ! this.argIsSet(idx)) return null;
|
||||
int from = idx;
|
||||
int to = args.size();
|
||||
if (to <= from) return "";
|
||||
return Txt.implode(args.subList(from, to), " ");
|
||||
}
|
||||
}
|
||||
|
@ -210,7 +210,7 @@ public class Txt
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
public static String implodeCommaAnd(List<String> list, String comma, String and)
|
||||
public static String implodeCommaAndDot(List<String> list, String comma, String and, String dot)
|
||||
{
|
||||
if (list.size() == 0) return "";
|
||||
if (list.size() == 1) return list.get(0);
|
||||
@ -221,14 +221,24 @@ public class Txt
|
||||
list.set(list.size()-2, merge);
|
||||
list.remove(list.size()-1);
|
||||
|
||||
return implode(list, comma);
|
||||
return implode(list, comma)+dot;
|
||||
}
|
||||
public static String implodeCommaAnd(List<String> list, String comma, String and)
|
||||
{
|
||||
return implodeCommaAndDot(list, comma, and, "");
|
||||
}
|
||||
public static String implodeCommaAndDot(List<String> list, String color)
|
||||
{
|
||||
return implodeCommaAndDot(list, color+", ", color+" and ", color+".");
|
||||
}
|
||||
|
||||
public static String implodeCommaAnd(List<String> list, String color)
|
||||
{
|
||||
return implodeCommaAnd(list, color+", ", color+" and ");
|
||||
return implodeCommaAndDot(list, color+", ", color+" and ", "");
|
||||
}
|
||||
public static String implodeCommaAndDot(List<String> list)
|
||||
{
|
||||
return implodeCommaAndDot(list, "");
|
||||
}
|
||||
|
||||
public static String implodeCommaAnd(List<String> list)
|
||||
{
|
||||
return implodeCommaAnd(list, "");
|
||||
@ -324,7 +334,7 @@ public class Txt
|
||||
|
||||
if (unitCountParts.size() == 0) return "just now";
|
||||
|
||||
ret += implodeCommaAnd(unitCountParts);
|
||||
ret += implodeCommaAndDot(unitCountParts);
|
||||
ret += " ";
|
||||
if (millis <= 0)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user