Class CommandUtil


  • public final class CommandUtil
    extends Object
    Miscellaneous utility methods used in the AlchemicalArrows commands.
    Author:
    Parker Hawke - Choco
    • Method Detail

      • 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