diff --git a/src/com/massivecraft/massivecore/PotionEffectWrap.java b/src/com/massivecraft/massivecore/PotionEffectWrap.java index 4f7a5bbd..bb1b6b9a 100644 --- a/src/com/massivecraft/massivecore/PotionEffectWrap.java +++ b/src/com/massivecraft/massivecore/PotionEffectWrap.java @@ -25,6 +25,11 @@ public class PotionEffectWrap public int getId() { return this.id; } public void setId(int id) { this.id = id; } + @SuppressWarnings("deprecation") + public void setPotionEffectType(PotionEffectType potionEffectType) { this.setId(potionEffectType.getId());} + @SuppressWarnings("deprecation") + public PotionEffectType getPotionEffectType() { return PotionEffectType.getById(this.getId()); } + protected int amplifier; public int getAmplifier() { return this.amplifier; } public void setAmplifier(int amplifier) { this.amplifier = amplifier; } @@ -139,4 +144,36 @@ public class PotionEffectWrap addEffects(entity, potionEffectWraps); } + // -------------------------------------------- // + // TO STRING + // -------------------------------------------- // + + public String getListLine() + { + // Create Ret + StringBuilder ret = new StringBuilder(); + + // Type Name (ID) + ret.append(this.getPotionEffectType().getName()); + ret.append(' '); + + // Amplifier + ret.append(this.amplifier); + ret.append(' '); + + // Duration + ret.append(this.duration); + ret.append(' '); + + // Ambient + ret.append(this.ambient); + ret.append(' '); + + // Particles + ret.append(this.particles); + + // Return Ret + return ret.toString(); + } + } diff --git a/src/com/massivecraft/massivecore/cmd/MassiveCommand.java b/src/com/massivecraft/massivecore/cmd/MassiveCommand.java index 51ccc174..5a95ff76 100644 --- a/src/com/massivecraft/massivecore/cmd/MassiveCommand.java +++ b/src/com/massivecraft/massivecore/cmd/MassiveCommand.java @@ -21,6 +21,7 @@ import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.cmd.arg.ArgReader; import com.massivecraft.massivecore.cmd.req.Req; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; +import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.mixin.Mixin; import com.massivecraft.massivecore.util.PermUtil; import com.massivecraft.massivecore.util.Txt; @@ -165,10 +166,12 @@ public class MassiveCommand // The different names this commands will react to protected List aliases; public List getAliases() { return this.aliases; } - public void setAliases(List aliases) { this.aliases = aliases; } - public void addAliases(String... aliases) { this.aliases.addAll(Arrays.asList(aliases)); } + public void setAliases(Collection aliases) { this.aliases = new MassiveList(aliases); } + public void setAliases(String... aliases) { this.setAliases(Arrays.asList(aliases)); } + public void addAliases(Collection aliases) { this.aliases.addAll(aliases); } + public void addAliases(String... aliases) { this.addAliases(Arrays.asList(aliases)); } // FIELD: requiredArgs // These args must always be sent diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARCombined.java b/src/com/massivecraft/massivecore/cmd/arg/ARCombined.java new file mode 100644 index 00000000..c1ed2fef --- /dev/null +++ b/src/com/massivecraft/massivecore/cmd/arg/ARCombined.java @@ -0,0 +1,68 @@ +package com.massivecraft.massivecore.cmd.arg; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import org.bukkit.command.CommandSender; + +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.collections.MassiveList; + +public class ARCombined extends ArgReaderAbstract> +{ + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + protected List> inners; + public List> getInners() { return this.inners; } + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + public static ARCombined get(Collection> inners) { return new ARCombined(inners); } + public static ARCombined get(ArgReader... inners) { return new ARCombined(inners); } + + public ARCombined(Collection> inners) + { + this.inners = new MassiveList>(inners); + } + public ARCombined(ArgReader... inners) + { + this(Arrays.asList(inners)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public List read(String arg, CommandSender sender) throws MassiveException + { + // Create Ret + List ret = new MassiveList(); + + // Fill Ret + List parts = Arrays.asList(arg.split(",")); + if (parts.size() > this.getInners().size()) + { + throw new MassiveException().addMsg("Too many parts!"); + } + + for (int i = 0; i < parts.size(); i++) + { + String part = parts.get(i); + ArgReader argReader = this.getInners().get(i); + + Object asdf = argReader.read(part, sender); + + ret.add(asdf); + } + + // Return Ret + return ret; + } + +} diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARPotionEffectType.java b/src/com/massivecraft/massivecore/cmd/arg/ARPotionEffectType.java new file mode 100644 index 00000000..64df95b6 --- /dev/null +++ b/src/com/massivecraft/massivecore/cmd/arg/ARPotionEffectType.java @@ -0,0 +1,80 @@ +package com.massivecraft.massivecore.cmd.arg; + +import java.util.Collection; +import java.util.List; + +import org.bukkit.command.CommandSender; +import org.bukkit.potion.PotionEffectType; + +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.collections.MassiveList; + +public class ARPotionEffectType extends ARAbstractSelect +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARPotionEffectType i = new ARPotionEffectType(); + public static ARPotionEffectType get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String typename() + { + return "potion effect type"; + } + + @Override + public PotionEffectType select(String str, CommandSender sender) throws MassiveException + { + // Prepare + str = getComparable(str); + + // Match Name + for (PotionEffectType potionEffectType : PotionEffectType.values()) + { + String name = getComparable(potionEffectType); + if (str.equals(name)) return potionEffectType; + } + + // :( + return null; + } + + @Override + public Collection altNames(CommandSender sender) + { + // Create Ret + List ret = new MassiveList(); + + // Match Name + for (PotionEffectType potionEffectType : PotionEffectType.values()) + { + if (potionEffectType == null) continue; + String name = potionEffectType.getName(); + if (name == null) continue; + + ret.add(name); + } + + // Return Ret + return ret; + } + + public static String getComparable(PotionEffectType potionEffectType) + { + if (potionEffectType == null) return null; + return getComparable(potionEffectType.getName()); + } + + public static String getComparable(String string) + { + if (string == null) return null; + return string.toLowerCase(); + } + +} diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARPotionEffectWrap.java b/src/com/massivecraft/massivecore/cmd/arg/ARPotionEffectWrap.java new file mode 100644 index 00000000..6a2404cd --- /dev/null +++ b/src/com/massivecraft/massivecore/cmd/arg/ARPotionEffectWrap.java @@ -0,0 +1,80 @@ +package com.massivecraft.massivecore.cmd.arg; + +import java.util.List; + +import org.bukkit.command.CommandSender; +import org.bukkit.potion.PotionEffectType; + +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.PotionEffectWrap; + +public class ARPotionEffectWrap extends ArgReaderAbstract +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARPotionEffectWrap i = new ARPotionEffectWrap(); + public static ARPotionEffectWrap get() { return i; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + protected final ARCombined combined = new ARCombined( + ARPotionEffectType.get(), + ARInteger.get(), + ARInteger.get(), + ARBoolean.get(), + ARBoolean.get() + ); + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public PotionEffectWrap read(String arg, CommandSender sender) throws MassiveException + { + // Create Ret + PotionEffectWrap ret = new PotionEffectWrap(); + + // Fill Ret + List parts = combined.read(arg, sender); + + for (int i = 0 ; i < parts.size() ; i++) + { + Object part = parts.get(i); + + if (i == 0) + { + PotionEffectType potionEffectType = (PotionEffectType)part; + ret.setPotionEffectType(potionEffectType); + } + else if (i == 1) + { + Integer amplifier = (Integer)part; + ret.setAmplifier(amplifier); + } + else if (i == 2) + { + Integer duration = (Integer)part; + ret.setDuration(duration); + } + else if (i == 3) + { + Boolean ambient = (Boolean)part; + ret.setAmbient(ambient); + } + else if (i == 4) + { + Boolean particles = (Boolean)part; + ret.setParticles(particles); + } + } + + // Return Ret + return ret; + } + +} diff --git a/src/com/massivecraft/massivecore/cmd/req/ReqAbstract.java b/src/com/massivecraft/massivecore/cmd/req/ReqAbstract.java index a16716a0..52045179 100644 --- a/src/com/massivecraft/massivecore/cmd/req/ReqAbstract.java +++ b/src/com/massivecraft/massivecore/cmd/req/ReqAbstract.java @@ -4,6 +4,8 @@ import java.io.Serializable; import org.bukkit.command.CommandSender; +import com.massivecraft.massivecore.cmd.MassiveCommand; + public abstract class ReqAbstract implements Req, Serializable { private static final long serialVersionUID = 1L; @@ -20,4 +22,10 @@ public abstract class ReqAbstract implements Req, Serializable return this.createErrorMessage(sender, null); } + public static String getDesc(MassiveCommand command) + { + if (command == null) return "do that"; + return command.getDesc(); + } + }