@Override
  public void run() {
    if (messageIndex >= finalIndex) {
      Commons.getInstance().getThreadManager().cancelTask(taskId);
      return;
    }

    Player player = Players.getPlayer(playerId);
    if (messageCooldown.isOnCooldown(player)) {
      return;
    }
    try {
      String message = messages[messageIndex];
      Chat.message(player, message);
      Sounds.playSound(player, sound);
      messageCooldown.setOnCooldown(player);
      messageIndex++;
    } catch (IndexOutOfBoundsException e) {
      Commons.getInstance()
          .debug(
              "Uh oh! Message index["
                  + messageIndex
                  + "] doesn't exist!\n"
                  + StringUtil.joinString(messages, "\n"));
    }
  }
  public DelayedSoundMessageThread(
      Player player, Sound sound, int secondsDelay, String... messages) {
    playerId = player.getUniqueId();
    this.sound = sound;
    this.messages = messages;

    // If there's only one message in the array, attempt to split the string on newline
    // As per default behaviour ;)
    if (messages.length == 1) {
      messages = StringUtil.splitOnNewline(messages[0]);
    }

    finalIndex = messages.length - 1;
    messageCooldown = new Cooldown(secondsDelay);
  }
  public static void loadItem(File file) {
    String itemName = FilenameUtils.removeExtension(file.getName());

    XmlItemStack item = null;
    try {
      item = serializer.read(XmlItemStack.class, file);
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (item == null) {
      return;
    }

    items.put(itemName, item.getItemStack());
    Chat.debug(
        String.format(
            "Loaded item %s",
            StringUtil.joinString(Messages.itemInfo(item.getItemStack()), "\n", 0)));
  }
Esempio n. 4
0
 /**
  * Create a custom inventory.
  *
  * @param title title to give the inventory (color codes supported with & prefix)
  * @param rows rows to give the inventory
  * @return an inventory with the title, and rows.
  */
 public static Inventory makeInventory(String title, int rows) {
   return Bukkit.getServer().createInventory(null, rows * 9, StringUtil.formatColorCodes(title));
 }