예제 #1
1
  /** Sends the current cooldown in action bar. */
  private void sendCooldownBar() {
    if (getPlayer() == null) return;

    StringBuilder stringBuilder = new StringBuilder();

    double currentCooldown = Core.getCustomPlayer(getPlayer()).canUse(type);
    double maxCooldown = type.getCountdown();

    int res = (int) (currentCooldown / maxCooldown * 10);
    ChatColor color;
    for (int i = 0; i < 10; i++) {
      color = ChatColor.RED;
      if (i < 10 - res) color = ChatColor.GREEN;
      stringBuilder.append(color + "â–�");
    }

    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.US);
    otherSymbols.setDecimalSeparator('.');
    otherSymbols.setGroupingSeparator('.');
    otherSymbols.setPatternSeparator('.');
    final DecimalFormat decimalFormat = new DecimalFormat("0.0", otherSymbols);
    String timeLeft = decimalFormat.format(currentCooldown) + "s";

    PlayerUtils.sendInActionBar(
        getPlayer(), getName() + " §f" + stringBuilder.toString() + " §f" + timeLeft);
  }
 /** @tests java.text.DecimalFormatSymbols#setPatternSeparator(char) */
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     notes = "",
     method = "setPatternSeparator",
     args = {char.class})
 public void test_setPatternSeparatorC() {
   dfs.setPatternSeparator('X');
   assertEquals("Returned incorrect PatternSeparator symbol", 'X', dfs.getPatternSeparator());
 }
예제 #3
0
  public Gadget(final UUID owner, final GadgetType type) {
    this.permission = type.permission;
    this.type = type;
    this.affectPlayers = type.affectPlayers();
    if (!type.isEnabled()) return;

    this.useTwoInteractMethods = false;
    if (owner != null) {
      this.owner = owner;
      if (Core.getCustomPlayer(getPlayer()).currentGadget != null)
        Core.getCustomPlayer(getPlayer()).removeGadget();
      if (!getPlayer().hasPermission(permission)) {
        getPlayer().sendMessage(MessageManager.getMessage("No-Permission"));
        return;
      }
      DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.US);
      otherSymbols.setDecimalSeparator('.');
      otherSymbols.setGroupingSeparator('.');
      otherSymbols.setPatternSeparator('.');
      final DecimalFormat decimalFormat = new DecimalFormat("0.0", otherSymbols);
      BukkitRunnable runnable =
          new BukkitRunnable() {
            @Override
            public void run() {
              try {
                if (Bukkit.getPlayer(owner) != null
                    && Core.getCustomPlayer(Bukkit.getPlayer(owner)).currentGadget != null
                    && Core.getCustomPlayer(Bukkit.getPlayer(owner)).currentGadget.getType()
                        == type) {
                  onUpdate();
                  if (Core.cooldownInBar) {
                    if (getPlayer().getItemInHand() != null
                        && itemStack != null
                        && getPlayer().getItemInHand().hasItemMeta()
                        && getPlayer().getItemInHand().getItemMeta().hasDisplayName()
                        && getPlayer()
                            .getItemInHand()
                            .getItemMeta()
                            .getDisplayName()
                            .contains(getType().getName())
                        && Core.getCustomPlayer(getPlayer()).canUse(type) != -1) sendCooldownBar();
                    double left = Core.getCustomPlayer(getPlayer()).canUse(type);
                    if (left > -0.1) {
                      String leftRounded = decimalFormat.format(left);
                      double decimalRoundedValue = Double.parseDouble(leftRounded);
                      if (decimalRoundedValue == 0) {
                        PlayerUtils.sendInActionBar(
                            getPlayer(),
                            MessageManager.getMessage("Gadgets.Gadget-Ready-ActionBar")
                                .replace(
                                    "%gadgetname%",
                                    (Core.placeHolderColor)
                                        ? getName()
                                        : Core.filterColor(getName())));
                        getPlayer().playSound(getPlayer().getLocation(), Sound.NOTE_STICKS, 1f, 1f);
                      }
                    }
                  }
                } else {
                  cancel();
                  unregisterListeners();
                }
              } catch (NullPointerException exc) {
                removeItem();
                onClear();
                removeListener();
                getPlayer()
                    .sendMessage(
                        MessageManager.getMessage("Gadgets.Unequip")
                            .replace(
                                "%gadgetname%",
                                (Core.placeHolderColor) ? getName() : Core.filterColor(getName())));
                cancel();
              }
            }
          };
      runnable.runTaskTimerAsynchronously(Core.getPlugin(), 0, 1);
      listener = new GadgetListener(this);
      Core.registerListener(listener);
      Core.registerListener(this);
      if (getPlayer().getInventory().getItem((int) SettingsManager.getConfig().get("Gadget-Slot"))
          != null) {
        getPlayer()
            .getWorld()
            .dropItem(
                getPlayer().getLocation(),
                getPlayer()
                    .getInventory()
                    .getItem((int) SettingsManager.getConfig().get("Gadget-Slot")));
        getPlayer().getInventory().remove((int) SettingsManager.getConfig().get("Gadget-Slot"));
      }
      String d =
          Core.isAmmoEnabled() && getType().requiresAmmo()
              ? "§f§l"
                  + Core.getCustomPlayer(getPlayer()).getAmmo(type.toString().toLowerCase())
                  + " "
              : "";
      itemStack =
          ItemFactory.create(
              type.getMaterial(),
              type.getData(),
              d + getName(),
              MessageManager.getMessage("Gadgets.Lore"));
      getPlayer()
          .getInventory()
          .setItem((int) SettingsManager.getConfig().get("Gadget-Slot"), itemStack);
      getPlayer()
          .sendMessage(
              MessageManager.getMessage("Gadgets.Equip")
                  .replace(
                      "%gadgetname%",
                      (Core.placeHolderColor) ? getName() : Core.filterColor(getName())));
      Core.getCustomPlayer(getPlayer()).currentGadget = this;
    }
  }