Package wtf.choco.arrows.utils
Class CommandUtil
java.lang.Object
wtf.choco.arrows.utils.CommandUtil
public final class CommandUtil extends Object
Miscellaneous utility methods used in the AlchemicalArrows commands.
- Author:
- Parker Hawke - Choco
-
Method Summary
Modifier and Type Method Description static @Nullable String
argToNamespace(@Nullable String arg, @NotNull String defaultNamespace)
Convert an argument to a namespaced key argument.static @Nullable String
argToNamespace(@Nullable String arg, @NotNull org.bukkit.plugin.Plugin plugin)
Convert an argument to a namespaced key argument.static float
clamp(float value, float min, float max)
Clamp a value between a minimum and maximum value.static int
clamp(int value, int min, int max)
Clamp a value between a minimum and maximum value.
-
Method Details
-
argToNamespace
@Nullable public static @Nullable String argToNamespace(@Nullable @Nullable String arg, @NotNull @NotNull org.bukkit.plugin.Plugin plugin)Convert an argument to a namespaced key argument. The possible outcomes of this method are as follows:- "" or null -> null
- ":arg" -> null
- "namespace:arg:erroneous_value" -> null
- "arg" -> "pluginName:arg"
- "namespace:arg" -> "namespace:arg" (unchanged)
plugin
's name (i.e.Plugin.getName()
) will be used as the default namespace if none is provided by the argument.- Parameters:
arg
- the arg to namespaceifyplugin
- the plugin whose namespace to use- Returns:
- the namespaced argument
-
argToNamespace
@Nullable public static @Nullable String argToNamespace(@Nullable @Nullable String arg, @NotNull @NotNull String defaultNamespace)Convert an argument to a namespaced key argument. The possible outcomes of this method are as follows:- "" or null -> null
- ":arg" -> null
- "namespace:arg:erroneous_value" -> null
- "arg" -> "pluginName:arg"
- "namespace:arg" -> "namespace:arg" (unchanged)
- Parameters:
arg
- the arg to namespaceifydefaultNamespace
- the default namespace to use if none is provided by the argument- Returns:
- the namespaced argument
- See Also:
argToNamespace(String, Plugin)
-
clamp
public static int clamp(int value, int min, int max)Clamp a value between a minimum and maximum value. If the value exceeds the specified bounds, it will be limited to its exceeding bound.- Parameters:
value
- the value to clampmin
- the minimum allowed valuemax
- the maximum allowed value- Returns:
- the clamped value. Itself if the boundaries were not exceeded
-
clamp
public static float clamp(float value, float min, float max)Clamp a value between a minimum and maximum value. If the value exceeds the specified bounds, it will be limited to its exceeding bound.- Parameters:
value
- the value to clampmin
- the minimum allowed valuemax
- the maximum allowed value- Returns:
- the clamped value. Itself if the boundaries were not exceeded
-