Esempio n. 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);
  }
Esempio n. 2
0
  /** Opens Ammo Purchase Menu. */
  public void openAmmoPurchaseMenu() {

    Inventory inventory =
        Bukkit.createInventory(null, 54, MessageManager.getMessage("Menus.Buy-Ammo"));

    inventory.setItem(
        13,
        ItemFactory.create(
            type.getMaterial(),
            type.getData(),
            MessageManager.getMessage("Buy-Ammo-Description")
                .replace("%amount%", "" + getResultAmmoAmount())
                .replace("%price%", "" + getPrice())
                .replaceAll("%gadgetname%", getName())));

    for (int i = 27; i < 30; i++) {
      inventory.setItem(
          i,
          ItemFactory.create(
              Material.EMERALD_BLOCK, (byte) 0x0, MessageManager.getMessage("Purchase")));
      inventory.setItem(
          i + 9,
          ItemFactory.create(
              Material.EMERALD_BLOCK, (byte) 0x0, MessageManager.getMessage("Purchase")));
      inventory.setItem(
          i + 18,
          ItemFactory.create(
              Material.EMERALD_BLOCK, (byte) 0x0, MessageManager.getMessage("Purchase")));
      inventory.setItem(
          i + 6,
          ItemFactory.create(
              Material.REDSTONE_BLOCK, (byte) 0x0, MessageManager.getMessage("Cancel")));
      inventory.setItem(
          i + 9 + 6,
          ItemFactory.create(
              Material.REDSTONE_BLOCK, (byte) 0x0, MessageManager.getMessage("Cancel")));
      inventory.setItem(
          i + 18 + 6,
          ItemFactory.create(
              Material.REDSTONE_BLOCK, (byte) 0x0, MessageManager.getMessage("Cancel")));
    }
    ItemFactory.fillInventory(inventory);

    getPlayer().openInventory(inventory);

    this.inv = inventory;
  }
Esempio n. 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;
    }
  }
Esempio n. 4
0
 /**
  * Gets the ammo it should give after a purchase.
  *
  * @return the ammo it should give after a purchase.
  */
 public int getResultAmmoAmount() {
   return (int)
       SettingsManager.getConfig().get("Gadgets." + type.getConfigName() + ".Ammo.Result-Amount");
 }
Esempio n. 5
0
 /**
  * Gets the price for each ammo purchase.
  *
  * @return the price for each ammo purchase.
  */
 public int getPrice() {
   return (int) SettingsManager.getConfig().get("Gadgets." + type.getConfigName() + ".Ammo.Price");
 }
Esempio n. 6
0
 public Byte getData() {
   return type.getData();
 }
Esempio n. 7
0
 public Material getMaterial() {
   return type.getMaterial();
 }
Esempio n. 8
0
 public String getName() {
   return type.getName();
 }