diff options
author | Luck <git@lucko.me> | 2019-02-21 13:06:10 +0000 |
---|---|---|
committer | Luck <git@lucko.me> | 2019-02-21 13:06:10 +0000 |
commit | 161d3bdfbfe331a1ea3c6da1d096e86fd7a5c525 (patch) | |
tree | 96be6a24e9bd45198e4d5620eff57bba1e0a94cb /spark-common/src/main/java/me/lucko/spark/common/command | |
parent | 77c93aeeea763c68a4fd7f5b59afcfc2f6336379 (diff) | |
download | spark-161d3bdfbfe331a1ea3c6da1d096e86fd7a5c525.tar.gz spark-161d3bdfbfe331a1ea3c6da1d096e86fd7a5c525.tar.bz2 spark-161d3bdfbfe331a1ea3c6da1d096e86fd7a5c525.zip |
Allow sampling at fractions of a millisecond intervals
Diffstat (limited to 'spark-common/src/main/java/me/lucko/spark/common/command')
-rw-r--r-- | spark-common/src/main/java/me/lucko/spark/common/command/Arguments.java | 12 | ||||
-rw-r--r-- | spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java | 2 |
2 files changed, 13 insertions, 1 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/Arguments.java b/spark-common/src/main/java/me/lucko/spark/common/command/Arguments.java index d240554..2b202af 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/Arguments.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/Arguments.java @@ -89,6 +89,18 @@ public class Arguments { return -1; // undefined } + public double doubleFlag(String key) { + Iterator<String> it = this.parsedArgs.get(key).iterator(); + if (it.hasNext()) { + try { + return Math.abs(Double.parseDouble(it.next())); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Invalid input for '" + key + "' argument. Please specify a number!"); + } + } + return -1; // undefined + } + public Set<String> stringFlag(String key) { return this.parsedArgs.get(key); } diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java index 6ebbee1..9d00a96 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java @@ -73,7 +73,7 @@ public class SamplerModule<S> implements CommandModule<S> { platform.sendPrefixedMessage(sender, "&7The accuracy of the output will significantly improve when sampling is able to run for longer periods. Consider setting a timeout value over 30 seconds."); } - int intervalMillis = arguments.intFlag("interval"); + double intervalMillis = arguments.doubleFlag("interval"); if (intervalMillis <= 0) { intervalMillis = 4; } |