Skip to content

Utilities and Helpers

Griffin Kubesa edited this page Nov 27, 2019 · 4 revisions

Will move to a javadoc soon:tm:

BNCore

  • void log(message) - Log a message
  • void warn(message) - Log a warning
  • void severe(message) - Log an error
  • void registerListener(listener) - Registers an EventListener with the server

Utils

Strings

  • String colorize(text) - Turn color codes into real colors
  • String right(string, number) - Get the rightmost x characters of a string
  • String left(string, number) - Get the leftmost x characters of a string

Lists

Borrowed from the language ColdFusion, lists are just strings separated by something.

  • String listFirst(string, delimiter) - Get the first value in a list
  • String listLast(string, delimiter) - Get the last value in a list
  • String listGetAt(string, index, delimiter) - Get the value at an index in a list (starts at 1)

Tasks

  • void wait(delay, runnable) - Wait x milliseconds, then execute a task
  • int repeat(startDelay, interval, runnable) - Repeat a task. Returns taskId
  • int async(runnable) - Run a task asynchronously. Returns taskId
  • void cancelTask(taskId) - Cancel a task

Players

  • boolean isVanished(player)
  • boolean isAfk(player)
  • boolean isAfk(nerd)
  • List<String> getOnlineUuids()
  • OfflinePlayer getPlayer(uuid)
  • OfflinePlayer getPlayer(partialName)
  • void giveItem(player, item) - Gives an item to a player, dropping excess on the floor
  • void giveItems(player, items) - Gives items to a player, dropping excess on the floor
  • String getRankDisplay(player)

Formatting and conversions

  • String getPrefix(text) - Get a formatted prefix
  • String camelCase(text) - Turn a space or underscore delimited string into camel case
  • LocalDateTime timestamp(timestamp)
  • String timespanFormat(seconds)

Other

  • void callEvent(event) - Call a Bukkit event
  • void dump(object) - Dump an object to console

ItemStackBuilder

Follows the Builder Pattern.

ItemStack item = new ItemStackBuilder(Material.APPLE)
    .amount(20)
    .name("Chomp")
    .enchantment(Enchantment.MENDING)
    .build();
  • amount(amount)
  • name(displayName)
  • lore(lore)
  • enchant(enchantment)
  • enchant(enchantment, level)
  • enchant(enchantment, level, ignoreLevelRestriction)
  • effect(potionEffectType)
  • effect(potionEffectType, seconds)
  • effect(potionEffectType, seconds, amplifier)
  • itemFlags(flags)
Clone this wiki locally