From ad06dd854cb5a69f2676c6e67bfac1a9e6681d62 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Thu, 14 Mar 2013 12:35:42 +0100 Subject: [PATCH] Making argument index optional and heavy OCD --- src/com/massivecraft/mcore/cmd/MCommand.java | 11 ++++-- .../mcore/cmd/arg/ARAbstractPrimitive.java | 10 +++++- .../mcore/cmd/arg/ARAbstractSelect.java | 10 +++++- .../massivecraft/mcore/cmd/arg/ARAspect.java | 18 ++++++---- .../massivecraft/mcore/cmd/arg/ARBoolean.java | 18 ++++++---- .../massivecraft/mcore/cmd/arg/ARByte.java | 20 ++++++----- .../mcore/cmd/arg/ARChatColor.java | 18 ++++++---- .../massivecraft/mcore/cmd/arg/ARDate.java | 22 +++++++----- .../mcore/cmd/arg/ARDifficulty.java | 18 ++++++---- .../massivecraft/mcore/cmd/arg/ARDouble.java | 20 ++++++----- .../mcore/cmd/arg/AREnvironment.java | 18 ++++++---- .../massivecraft/mcore/cmd/arg/ARFloat.java | 20 ++++++----- .../mcore/cmd/arg/ARGameMode.java | 18 ++++++---- .../massivecraft/mcore/cmd/arg/ARInteger.java | 20 ++++++----- .../massivecraft/mcore/cmd/arg/ARLong.java | 20 ++++++----- .../mcore/cmd/arg/ARMaterial.java | 20 ++++++----- .../mcore/cmd/arg/ARMillisDiff.java | 16 ++++----- .../mcore/cmd/arg/ARMultiverse.java | 18 ++++++---- .../mcore/cmd/arg/ARSenderIdAbstract.java | 4 +-- .../massivecraft/mcore/cmd/arg/ARString.java | 18 ++++++---- .../mcore/cmd/arg/ARUniverse.java | 35 ++++++++++--------- .../massivecraft/mcore/cmd/arg/ARWorld.java | 21 ++++++----- .../massivecraft/mcore/cmd/arg/ARWorldId.java | 18 ++++++---- .../mcore/cmd/arg/ARWorldType.java | 18 ++++++---- .../mcore/cmd/arg/ArgPredictateAnd.java | 4 +++ .../massivecraft/mcore/cmd/arg/ArgReader.java | 3 ++ .../mcore/cmd/arg/ArgReaderAbstract.java | 29 +++++++++++++++ .../massivecraft/mcore/cmd/arg/ArgResult.java | 5 +-- src/com/massivecraft/mcore/util/MUtil.java | 1 + .../mcore/xlib/gson/internal/Streams.java | 1 + .../gson/internal/bind/ObjectTypeAdapter.java | 1 + 31 files changed, 302 insertions(+), 171 deletions(-) create mode 100644 src/com/massivecraft/mcore/cmd/arg/ArgReaderAbstract.java diff --git a/src/com/massivecraft/mcore/cmd/MCommand.java b/src/com/massivecraft/mcore/cmd/MCommand.java index 38fc74e7..5e776fd6 100644 --- a/src/com/massivecraft/mcore/cmd/MCommand.java +++ b/src/com/massivecraft/mcore/cmd/MCommand.java @@ -491,9 +491,9 @@ public abstract class MCommand return this.args.get(idx); } - public T arg(int idx, ArgReader ar) + public T arg(int idx, ArgReader argReader) { - return this.arg(idx, ar, null); + return this.arg(idx, argReader, null); } public T arg(int idx, ArgReader argReader, T defaultNotSet) @@ -504,4 +504,11 @@ public abstract class MCommand if (result.hasErrors()) this.msg(result.getErrors()); return result.getResult(); } + + public T arg(ArgReader argReader) + { + ArgResult result = argReader.read(this.sender); + if (result.hasErrors()) this.msg(result.getErrors()); + return result.getResult(); + } } diff --git a/src/com/massivecraft/mcore/cmd/arg/ARAbstractPrimitive.java b/src/com/massivecraft/mcore/cmd/arg/ARAbstractPrimitive.java index e5998100..5c3df1c9 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ARAbstractPrimitive.java +++ b/src/com/massivecraft/mcore/cmd/arg/ARAbstractPrimitive.java @@ -2,11 +2,19 @@ package com.massivecraft.mcore.cmd.arg; import org.bukkit.command.CommandSender; -public abstract class ARAbstractPrimitive implements ArgReader +public abstract class ARAbstractPrimitive extends ArgReaderAbstract { + // -------------------------------------------- // + // ABSTRACT + // -------------------------------------------- // + public abstract String typename(); public abstract T convert(String arg) throws Exception; + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + @Override public ArgResult read(String arg, CommandSender sender) { diff --git a/src/com/massivecraft/mcore/cmd/arg/ARAbstractSelect.java b/src/com/massivecraft/mcore/cmd/arg/ARAbstractSelect.java index 729e3f16..232b8f28 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ARAbstractSelect.java +++ b/src/com/massivecraft/mcore/cmd/arg/ARAbstractSelect.java @@ -6,13 +6,21 @@ import org.bukkit.command.CommandSender; import com.massivecraft.mcore.util.Txt; -public abstract class ARAbstractSelect implements ArgReader +public abstract class ARAbstractSelect extends ArgReaderAbstract { + // -------------------------------------------- // + // ABSTRACT + // -------------------------------------------- // + public abstract String typename(); public abstract T select(String str, CommandSender sender); public abstract Collection altNames(CommandSender sender); public boolean canList(CommandSender sender) { return true; } + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + @Override public ArgResult read(String arg, CommandSender sender) { diff --git a/src/com/massivecraft/mcore/cmd/arg/ARAspect.java b/src/com/massivecraft/mcore/cmd/arg/ARAspect.java index 9a7ccdfb..7a87e1fd 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ARAspect.java +++ b/src/com/massivecraft/mcore/cmd/arg/ARAspect.java @@ -10,6 +10,17 @@ import com.massivecraft.mcore.usys.AspectColl; public class ARAspect extends ARAbstractSelect { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARAspect i = new ARAspect(); + public static ARAspect get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + @Override public String typename() { @@ -34,11 +45,4 @@ public class ARAspect extends ARAbstractSelect return AspectColl.i.getIds(); } - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static ARAspect i = new ARAspect(); - public static ARAspect get() { return i; } - } diff --git a/src/com/massivecraft/mcore/cmd/arg/ARBoolean.java b/src/com/massivecraft/mcore/cmd/arg/ARBoolean.java index 3966a3bd..16752e8e 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ARBoolean.java +++ b/src/com/massivecraft/mcore/cmd/arg/ARBoolean.java @@ -2,6 +2,17 @@ package com.massivecraft.mcore.cmd.arg; public class ARBoolean extends ARAbstractPrimitive { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARBoolean i = new ARBoolean(); + public static ARBoolean get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + @Override public String typename() { @@ -19,11 +30,4 @@ public class ARBoolean extends ARAbstractPrimitive return false; } - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static ARBoolean i = new ARBoolean(); - public static ARBoolean get() { return i; } - } diff --git a/src/com/massivecraft/mcore/cmd/arg/ARByte.java b/src/com/massivecraft/mcore/cmd/arg/ARByte.java index d68b26bf..d81a35e0 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ARByte.java +++ b/src/com/massivecraft/mcore/cmd/arg/ARByte.java @@ -1,7 +1,18 @@ package com.massivecraft.mcore.cmd.arg; public class ARByte extends ARAbstractPrimitive -{ +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARByte i = new ARByte(); + public static ARByte get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + @Override public String typename() { @@ -14,11 +25,4 @@ public class ARByte extends ARAbstractPrimitive return Byte.parseByte(arg); } - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static ARByte i = new ARByte(); - public static ARByte get() { return i; } - } diff --git a/src/com/massivecraft/mcore/cmd/arg/ARChatColor.java b/src/com/massivecraft/mcore/cmd/arg/ARChatColor.java index 3a1fc622..1c7ef194 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ARChatColor.java +++ b/src/com/massivecraft/mcore/cmd/arg/ARChatColor.java @@ -9,6 +9,17 @@ import org.bukkit.command.CommandSender; public class ARChatColor extends ARAbstractSelect { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARChatColor i = new ARChatColor(); + public static ARChatColor get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + @Override public String typename() { @@ -62,11 +73,4 @@ public class ARChatColor extends ARAbstractSelect return str; } - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static ARChatColor i = new ARChatColor(); - public static ARChatColor get() { return i; } - } diff --git a/src/com/massivecraft/mcore/cmd/arg/ARDate.java b/src/com/massivecraft/mcore/cmd/arg/ARDate.java index a047f492..eb9dc1da 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ARDate.java +++ b/src/com/massivecraft/mcore/cmd/arg/ARDate.java @@ -5,9 +5,20 @@ import java.text.SimpleDateFormat; import java.util.Date; public class ARDate extends ARAbstractPrimitive -{ - protected static DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); +{ + protected final static DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARDate i = new ARDate(); + public static ARDate get() { return i; } + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + @Override public String typename() { @@ -20,11 +31,4 @@ public class ARDate extends ARAbstractPrimitive return df.parse(arg); } - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static ARDate i = new ARDate(); - public static ARDate get() { return i; } - } \ No newline at end of file diff --git a/src/com/massivecraft/mcore/cmd/arg/ARDifficulty.java b/src/com/massivecraft/mcore/cmd/arg/ARDifficulty.java index efb4eda0..ec65e425 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ARDifficulty.java +++ b/src/com/massivecraft/mcore/cmd/arg/ARDifficulty.java @@ -9,6 +9,17 @@ import com.massivecraft.mcore.util.MUtil; public class ARDifficulty extends ARAbstractSelect { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARDifficulty i = new ARDifficulty(); + public static ARDifficulty get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + @Override public String typename() { @@ -48,11 +59,4 @@ public class ARDifficulty extends ARAbstractSelect return MUtil.list("peaceful", "easy", "normal", "hard"); } - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static ARDifficulty i = new ARDifficulty(); - public static ARDifficulty get() { return i; } - } diff --git a/src/com/massivecraft/mcore/cmd/arg/ARDouble.java b/src/com/massivecraft/mcore/cmd/arg/ARDouble.java index 3143f8eb..7f9f523a 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ARDouble.java +++ b/src/com/massivecraft/mcore/cmd/arg/ARDouble.java @@ -1,7 +1,18 @@ package com.massivecraft.mcore.cmd.arg; public class ARDouble extends ARAbstractPrimitive -{ +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARDouble i = new ARDouble(); + public static ARDouble get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + @Override public String typename() { @@ -14,11 +25,4 @@ public class ARDouble extends ARAbstractPrimitive return Double.parseDouble(arg); } - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static ARDouble i = new ARDouble(); - public static ARDouble get() { return i; } - } diff --git a/src/com/massivecraft/mcore/cmd/arg/AREnvironment.java b/src/com/massivecraft/mcore/cmd/arg/AREnvironment.java index 92c8c68e..b5e527a6 100644 --- a/src/com/massivecraft/mcore/cmd/arg/AREnvironment.java +++ b/src/com/massivecraft/mcore/cmd/arg/AREnvironment.java @@ -9,6 +9,17 @@ import com.massivecraft.mcore.util.MUtil; public class AREnvironment extends ARAbstractSelect { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static AREnvironment i = new AREnvironment(); + public static AREnvironment get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + @Override public String typename() { @@ -50,11 +61,4 @@ public class AREnvironment extends ARAbstractSelect return MUtil.list("normal", "end", "nether"); } - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static AREnvironment i = new AREnvironment(); - public static AREnvironment get() { return i; } - } diff --git a/src/com/massivecraft/mcore/cmd/arg/ARFloat.java b/src/com/massivecraft/mcore/cmd/arg/ARFloat.java index b466bd1f..86ed0aaf 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ARFloat.java +++ b/src/com/massivecraft/mcore/cmd/arg/ARFloat.java @@ -1,7 +1,18 @@ package com.massivecraft.mcore.cmd.arg; public class ARFloat extends ARAbstractPrimitive -{ +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARFloat i = new ARFloat(); + public static ARFloat get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + @Override public String typename() { @@ -14,11 +25,4 @@ public class ARFloat extends ARAbstractPrimitive return Float.parseFloat(arg); } - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static ARFloat i = new ARFloat(); - public static ARFloat get() { return i; } - } diff --git a/src/com/massivecraft/mcore/cmd/arg/ARGameMode.java b/src/com/massivecraft/mcore/cmd/arg/ARGameMode.java index aed76df7..35f7d7e7 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ARGameMode.java +++ b/src/com/massivecraft/mcore/cmd/arg/ARGameMode.java @@ -9,6 +9,17 @@ import com.massivecraft.mcore.util.MUtil; public class ARGameMode extends ARAbstractSelect { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARGameMode i = new ARGameMode(); + public static ARGameMode get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + @Override public String typename() { @@ -44,11 +55,4 @@ public class ARGameMode extends ARAbstractSelect return MUtil.list("survival", "creative", "adventure"); } - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static ARGameMode i = new ARGameMode(); - public static ARGameMode get() { return i; } - } diff --git a/src/com/massivecraft/mcore/cmd/arg/ARInteger.java b/src/com/massivecraft/mcore/cmd/arg/ARInteger.java index 0500695d..06b061d2 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ARInteger.java +++ b/src/com/massivecraft/mcore/cmd/arg/ARInteger.java @@ -2,6 +2,17 @@ package com.massivecraft.mcore.cmd.arg; public class ARInteger extends ARAbstractPrimitive { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARInteger i = new ARInteger(); + public static ARInteger get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + @Override public String typename() { @@ -13,12 +24,5 @@ public class ARInteger extends ARAbstractPrimitive { return Integer.parseInt(arg); } - - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static ARInteger i = new ARInteger(); - public static ARInteger get() { return i; } - + } \ No newline at end of file diff --git a/src/com/massivecraft/mcore/cmd/arg/ARLong.java b/src/com/massivecraft/mcore/cmd/arg/ARLong.java index 2a163edf..9610587f 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ARLong.java +++ b/src/com/massivecraft/mcore/cmd/arg/ARLong.java @@ -1,7 +1,18 @@ package com.massivecraft.mcore.cmd.arg; public class ARLong extends ARAbstractPrimitive -{ +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARLong i = new ARLong(); + public static ARLong get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + @Override public String typename() { @@ -14,11 +25,4 @@ public class ARLong extends ARAbstractPrimitive return Long.parseLong(arg); } - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static ARLong i = new ARLong(); - public static ARLong get() { return i; } - } diff --git a/src/com/massivecraft/mcore/cmd/arg/ARMaterial.java b/src/com/massivecraft/mcore/cmd/arg/ARMaterial.java index 750aff67..c2f66743 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ARMaterial.java +++ b/src/com/massivecraft/mcore/cmd/arg/ARMaterial.java @@ -3,8 +3,19 @@ package com.massivecraft.mcore.cmd.arg; import org.bukkit.Material; import org.bukkit.command.CommandSender; -public class ARMaterial implements ArgReader +public class ARMaterial extends ArgReaderAbstract { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARMaterial i = new ARMaterial(); + public static ARMaterial get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + @Override public ArgResult read(String arg, CommandSender sender) { @@ -17,11 +28,4 @@ public class ARMaterial implements ArgReader return result; } - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static ARMaterial i = new ARMaterial(); - public static ARMaterial get() { return i; } - } diff --git a/src/com/massivecraft/mcore/cmd/arg/ARMillisDiff.java b/src/com/massivecraft/mcore/cmd/arg/ARMillisDiff.java index 99d35c39..ecabec7c 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ARMillisDiff.java +++ b/src/com/massivecraft/mcore/cmd/arg/ARMillisDiff.java @@ -5,8 +5,15 @@ import org.bukkit.command.CommandSender; import com.massivecraft.mcore.util.TimeDiffUtil; import com.massivecraft.mcore.util.Txt; -public class ARMillisDiff implements ArgReader +public class ARMillisDiff extends ArgReaderAbstract { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARMillisDiff i = new ARMillisDiff(); + public static ARMillisDiff get() { return i; } + // -------------------------------------------- // // OVERRIDE // -------------------------------------------- // @@ -26,11 +33,4 @@ public class ARMillisDiff implements ArgReader return ret; } - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static ARMillisDiff i = new ARMillisDiff(); - public static ARMillisDiff get() { return i; } - } diff --git a/src/com/massivecraft/mcore/cmd/arg/ARMultiverse.java b/src/com/massivecraft/mcore/cmd/arg/ARMultiverse.java index 1ec5cb99..dc621985 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ARMultiverse.java +++ b/src/com/massivecraft/mcore/cmd/arg/ARMultiverse.java @@ -10,6 +10,17 @@ import com.massivecraft.mcore.usys.MultiverseColl; public class ARMultiverse extends ARAbstractSelect { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARMultiverse i = new ARMultiverse(); + public static ARMultiverse get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + @Override public String typename() { @@ -34,11 +45,4 @@ public class ARMultiverse extends ARAbstractSelect return MultiverseColl.i.getIds(); } - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static ARMultiverse i = new ARMultiverse(); - public static ARMultiverse get() { return i; } - } diff --git a/src/com/massivecraft/mcore/cmd/arg/ARSenderIdAbstract.java b/src/com/massivecraft/mcore/cmd/arg/ARSenderIdAbstract.java index ef771f99..cc57c3ed 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ARSenderIdAbstract.java +++ b/src/com/massivecraft/mcore/cmd/arg/ARSenderIdAbstract.java @@ -7,10 +7,10 @@ import org.bukkit.command.CommandSender; import com.massivecraft.mcore.mixin.Mixin; import com.massivecraft.mcore.util.Txt; -public abstract class ARSenderIdAbstract implements ArgReader +public abstract class ARSenderIdAbstract extends ArgReaderAbstract { // -------------------------------------------- // - // ABSTRACT + // CONSTANTS // -------------------------------------------- // public final static int MAX_COUNT = 10; diff --git a/src/com/massivecraft/mcore/cmd/arg/ARString.java b/src/com/massivecraft/mcore/cmd/arg/ARString.java index 98f29356..493cf174 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ARString.java +++ b/src/com/massivecraft/mcore/cmd/arg/ARString.java @@ -2,6 +2,17 @@ package com.massivecraft.mcore.cmd.arg; public class ARString extends ARAbstractPrimitive { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARString i = new ARString(); + public static ARString get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + @Override public String typename() { @@ -14,11 +25,4 @@ public class ARString extends ARAbstractPrimitive return arg; } - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static ARString i = new ARString(); - public static ARString get() { return i; } - } diff --git a/src/com/massivecraft/mcore/cmd/arg/ARUniverse.java b/src/com/massivecraft/mcore/cmd/arg/ARUniverse.java index 31f077be..b2120226 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ARUniverse.java +++ b/src/com/massivecraft/mcore/cmd/arg/ARUniverse.java @@ -8,10 +8,26 @@ import org.bukkit.command.CommandSender; import com.massivecraft.mcore.usys.Multiverse; import com.massivecraft.mcore.util.Txt; -public class ARUniverse implements ArgReader +public class ARUniverse extends ArgReaderAbstract { // -------------------------------------------- // - // IMPLEMENTATION + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + public ARUniverse(Multiverse multiverse) + { + this.multiverse = multiverse; + } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + protected Multiverse multiverse; + public Multiverse multiverse() { return this.multiverse; } + + // -------------------------------------------- // + // OVERRIDE // -------------------------------------------- // @Override @@ -34,19 +50,4 @@ public class ARUniverse implements ArgReader return result; } - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - protected Multiverse multiverse; - public Multiverse multiverse() { return this.multiverse; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public ARUniverse(Multiverse multiverse) - { - this.multiverse = multiverse; - } } diff --git a/src/com/massivecraft/mcore/cmd/arg/ARWorld.java b/src/com/massivecraft/mcore/cmd/arg/ARWorld.java index 13a98b69..77052d0d 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ARWorld.java +++ b/src/com/massivecraft/mcore/cmd/arg/ARWorld.java @@ -4,8 +4,19 @@ import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.command.CommandSender; -public class ARWorld implements ArgReader +public class ARWorld extends ArgReaderAbstract { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARWorld i = new ARWorld(); + public static ARWorld get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + @Override public ArgResult read(String arg, CommandSender sender) { @@ -33,12 +44,4 @@ public class ARWorld implements ArgReader return ret; } - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static ARWorld i = new ARWorld(); - public static ARWorld get() { return i; } - - } diff --git a/src/com/massivecraft/mcore/cmd/arg/ARWorldId.java b/src/com/massivecraft/mcore/cmd/arg/ARWorldId.java index 2642f5e8..ac818d17 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ARWorldId.java +++ b/src/com/massivecraft/mcore/cmd/arg/ARWorldId.java @@ -9,6 +9,17 @@ import com.massivecraft.mcore.mixin.Mixin; public class ARWorldId extends ARAbstractSelect { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARWorldId i = new ARWorldId(); + public static ARWorldId get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + @Override public String typename() { @@ -50,11 +61,4 @@ public class ARWorldId extends ARAbstractSelect return ret; } - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static ARWorldId i = new ARWorldId(); - public static ARWorldId get() { return i; } - } diff --git a/src/com/massivecraft/mcore/cmd/arg/ARWorldType.java b/src/com/massivecraft/mcore/cmd/arg/ARWorldType.java index 23e81d25..ace9b239 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ARWorldType.java +++ b/src/com/massivecraft/mcore/cmd/arg/ARWorldType.java @@ -9,6 +9,17 @@ import com.massivecraft.mcore.util.MUtil; public class ARWorldType extends ARAbstractSelect { + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARWorldType i = new ARWorldType(); + public static ARWorldType get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + @Override public String typename() { @@ -60,11 +71,4 @@ public class ARWorldType extends ARAbstractSelect return MUtil.list("normal", "flat", "1.1", "largebiomes"); } - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static ARWorldType i = new ARWorldType(); - public static ARWorldType get() { return i; } - } diff --git a/src/com/massivecraft/mcore/cmd/arg/ArgPredictateAnd.java b/src/com/massivecraft/mcore/cmd/arg/ArgPredictateAnd.java index 8b3f2142..3c100f40 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ArgPredictateAnd.java +++ b/src/com/massivecraft/mcore/cmd/arg/ArgPredictateAnd.java @@ -21,6 +21,10 @@ public class ArgPredictateAnd implements ArgPredictate this.two = two; } + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + @Override public boolean apply(T type, String arg, CommandSender sender) { diff --git a/src/com/massivecraft/mcore/cmd/arg/ArgReader.java b/src/com/massivecraft/mcore/cmd/arg/ArgReader.java index 1cbb1f0c..56e9d251 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ArgReader.java +++ b/src/com/massivecraft/mcore/cmd/arg/ArgReader.java @@ -5,4 +5,7 @@ import org.bukkit.command.CommandSender; public interface ArgReader { public ArgResult read(String arg, CommandSender sender); + public ArgResult read(CommandSender sender); + public ArgResult read(String arg); + public ArgResult read(); } \ No newline at end of file diff --git a/src/com/massivecraft/mcore/cmd/arg/ArgReaderAbstract.java b/src/com/massivecraft/mcore/cmd/arg/ArgReaderAbstract.java new file mode 100644 index 00000000..451084e9 --- /dev/null +++ b/src/com/massivecraft/mcore/cmd/arg/ArgReaderAbstract.java @@ -0,0 +1,29 @@ +package com.massivecraft.mcore.cmd.arg; + +import org.bukkit.command.CommandSender; + +public abstract class ArgReaderAbstract implements ArgReader +{ + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public ArgResult read(CommandSender sender) + { + return this.read(null, sender); + } + + @Override + public ArgResult read(String arg) + { + return this.read(arg, null); + } + + @Override + public ArgResult read() + { + return this.read(null, null); + } + +} diff --git a/src/com/massivecraft/mcore/cmd/arg/ArgResult.java b/src/com/massivecraft/mcore/cmd/arg/ArgResult.java index c065b074..95e68171 100644 --- a/src/com/massivecraft/mcore/cmd/arg/ArgResult.java +++ b/src/com/massivecraft/mcore/cmd/arg/ArgResult.java @@ -13,10 +13,7 @@ public class ArgResult protected T result = null; public T getResult() { return this.result; } public void setResult(T result) { this.result = result; } - public boolean hasResult() - { - return this.getResult() != null; - } + public boolean hasResult() { return this.getResult() != null; } // -------------------------------------------- // // FIELD: ERRORS diff --git a/src/com/massivecraft/mcore/util/MUtil.java b/src/com/massivecraft/mcore/util/MUtil.java index 4b007911..3294099f 100644 --- a/src/com/massivecraft/mcore/util/MUtil.java +++ b/src/com/massivecraft/mcore/util/MUtil.java @@ -314,6 +314,7 @@ public class MUtil // SIMPLE CONSTRUCTORS // -------------------------------------------- // + @SafeVarargs public static List list(T... items) { diff --git a/src/com/massivecraft/mcore/xlib/gson/internal/Streams.java b/src/com/massivecraft/mcore/xlib/gson/internal/Streams.java index 840bc082..cc2e3c33 100644 --- a/src/com/massivecraft/mcore/xlib/gson/internal/Streams.java +++ b/src/com/massivecraft/mcore/xlib/gson/internal/Streams.java @@ -68,6 +68,7 @@ public final class Streams { TypeAdapters.JSON_ELEMENT.write(writer, element); } + @SuppressWarnings("resource") public static Writer writerForAppendable(Appendable appendable) { return appendable instanceof Writer ? (Writer) appendable : new AppendableWriter(appendable); } diff --git a/src/com/massivecraft/mcore/xlib/gson/internal/bind/ObjectTypeAdapter.java b/src/com/massivecraft/mcore/xlib/gson/internal/bind/ObjectTypeAdapter.java index 8b01fc77..42b73aaa 100644 --- a/src/com/massivecraft/mcore/xlib/gson/internal/bind/ObjectTypeAdapter.java +++ b/src/com/massivecraft/mcore/xlib/gson/internal/bind/ObjectTypeAdapter.java @@ -52,6 +52,7 @@ public final class ObjectTypeAdapter extends TypeAdapter { this.gson = gson; } + @SuppressWarnings("incomplete-switch") @Override public Object read(JsonReader in) throws IOException { JsonToken token = in.peek(); switch (token) {