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.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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)
      null will only be returned if the argument is invalid. The 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 namespaceify
      plugin - 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)
      null will only be returned if the argument is invalid.
      Parameters:
      arg - the arg to namespaceify
      defaultNamespace - 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 clamp
      min - the minimum allowed value
      max - 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 clamp
      min - the minimum allowed value
      max - the maximum allowed value
      Returns:
      the clamped value. Itself if the boundaries were not exceeded