Ejemplo n.º 1
0
 @Override
 void onUpdate() {
   final Item ITEM =
       ent.getWorld()
           .dropItem(
               ((Sheep) ent).getEyeLocation(),
               ItemFactory.create(
                   Material.WOOL, (byte) r.nextInt(017), UUID.randomUUID().toString()));
   ITEM.setPickupDelay(30000);
   ITEM.setVelocity(
       new Vector(r.nextDouble() - 0.5, r.nextDouble() / 2.0 + 0.3, r.nextDouble() - 0.5)
           .multiply(0.4));
   items.add(ITEM);
   Bukkit.getScheduler()
       .runTaskLater(
           Core.getPlugin(),
           new Runnable() {
             @Override
             public void run() {
               ITEM.remove();
               items.remove(ITEM);
             }
           },
           5);
 }
Ejemplo 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;
  }
Ejemplo 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;
    }
  }
Ejemplo n.º 4
0
    @EventHandler
    protected void onPlayerInteract(final PlayerInteractEvent EVENT) {
      Player player = EVENT.getPlayer();
      UUID uuid = player.getUniqueId();
      CustomPlayer cp = Core.getCustomPlayer(getPlayer());
      if (!uuid.equals(gadget.owner)) return;
      ItemStack itemStack = player.getItemInHand();
      if (itemStack.getType() != gadget.getMaterial()) return;
      if (itemStack.getData().getData() != gadget.getData()) return;
      if (player.getInventory().getHeldItemSlot()
          != (int) SettingsManager.getConfig().get("Gadget-Slot")) return;
      if (Core.getCustomPlayer(getPlayer()).currentGadget != gadget) return;
      if (EVENT.getAction() == Action.PHYSICAL) return;
      EVENT.setCancelled(true);
      player.updateInventory();
      if (!Core.getCustomPlayer(getPlayer()).hasGadgetsEnabled()) {
        getPlayer().sendMessage(MessageManager.getMessage("Gadgets-Enabled-Needed"));
        return;
      }
      if (Core.getCustomPlayer(getPlayer()).currentTreasureChest != null) return;

      if (Core.isAmmoEnabled() && getType().requiresAmmo()) {
        if (Core.getCustomPlayer(getPlayer()).getAmmo(getType().toString().toLowerCase()) < 1) {
          openAmmoPurchaseMenu();
          return;
        }
      }
      if (type == GadgetType.PORTALGUN) {
        if (getPlayer().getTargetBlock((Set<Material>) null, 20).getType() == Material.AIR) {
          getPlayer().sendMessage(MessageManager.getMessage("Gadgets.PortalGun.No-Block-Range"));
          return;
        }
      }
      if (type == GadgetType.ROCKET) {
        boolean pathClear = true;
        Cuboid c =
            new Cuboid(
                getPlayer().getLocation().add(-1, 0, -1), getPlayer().getLocation().add(1, 75, 1));
        if (!c.isEmpty()) {
          getPlayer().sendMessage(MessageManager.getMessage("Gadgets.Rocket.Not-Enough-Space"));
          return;
        }
        if (!getPlayer().isOnGround()) {
          getPlayer().sendMessage(MessageManager.getMessage("Gadgets.Rocket.Not-On-Ground"));
          return;
        }
      }
      if (type == GadgetType.DISCOBALL) {
        if (Core.discoBalls.size() > 0) {
          getPlayer().sendMessage(MessageManager.getMessage("Gadgets.DiscoBall.Already-Active"));
          return;
        }
        if (getPlayer().getLocation().add(0, 4, 0).getBlock() != null
            && getPlayer().getLocation().add(0, 4, 0).getBlock().getType() != Material.AIR) {
          getPlayer().sendMessage(MessageManager.getMessage("Gadgets.DiscoBall.Not-Space-Above"));
          return;
        }
      }
      if (type == GadgetType.CHRISTMASTREE) {
        if (EVENT.getClickedBlock() == null || EVENT.getClickedBlock().getType() == Material.AIR) {
          getPlayer()
              .sendMessage(MessageManager.getMessage("Gadgets.ChristmasTree.Click-On-Block"));
          return;
        }
      }
      if (type == GadgetType.TRAMPOLINE) {
        // Check blocks above.
        Location loc1 = getPlayer().getLocation().add(2, 15, 2);
        Location loc2 = getPlayer().getLocation().clone().add(-2, 0, -2);
        Block block = loc1.getBlock().getRelative(3, 0, 0);
        Block block2 = loc1.getBlock().getRelative(3, 1, 0);
        Cuboid checkCuboid = new Cuboid(loc1, loc2);

        if (!checkCuboid.isEmpty()
            || block.getType() != Material.AIR
            || block2.getType() != Material.AIR) {
          getPlayer().sendMessage(MessageManager.getMessage("Gadgets.Rocket.Not-Enough-Space"));
          return;
        }
      }
      // Check for the parachute if there is space 30-40 blocks above the player to avoid problems.
      if (type == GadgetType.PARACHUTE) {
        // Check blocks above.
        Location loc1 = getPlayer().getLocation().add(2, 28, 2);
        Location loc2 = getPlayer().getLocation().clone().add(-2, 40, -2);
        Cuboid checkCuboid = new Cuboid(loc1, loc2);

        if (!checkCuboid.isEmpty()) {
          getPlayer().sendMessage(MessageManager.getMessage("Gadgets.Rocket.Not-Enough-Space"));
          return;
        }
      }
      if (type == GadgetType.EXPLOSIVESHEEP) {
        if (Core.explosiveSheep.size() > 0) {
          getPlayer()
              .sendMessage(MessageManager.getMessage("Gadgets.ExplosiveSheep.Already-Active"));
          return;
        }
      }
      double coolDown = cp.canUse(getType());
      if (coolDown != -1) {
        String timeLeft = new DecimalFormat("#.#").format(coolDown);
        if (type.getCountdown() > 1)
          getPlayer()
              .sendMessage(
                  MessageManager.getMessage("Gadgets.Countdown-Message")
                      .replace(
                          "%gadgetname%",
                          (Core.placeHolderColor) ? getName() : Core.filterColor(getName()))
                      .replace("%time%", timeLeft));
        return;
      } else cp.setCoolDown(getType(), type.getCountdown());
      if (Core.isAmmoEnabled() && getType().requiresAmmo()) {
        Core.getCustomPlayer(getPlayer()).removeAmmo(getType().toString().toLowerCase());
        itemStack =
            ItemFactory.create(
                type.getMaterial(),
                type.getData(),
                "§f§l"
                    + Core.getCustomPlayer(getPlayer()).getAmmo(type.toString().toLowerCase())
                    + " "
                    + getName(),
                MessageManager.getMessage("Gadgets.Lore"));
        getPlayer()
            .getInventory()
            .setItem((int) SettingsManager.getConfig().get("Gadget-Slot"), itemStack);
      }
      if (EVENT.getClickedBlock() != null && EVENT.getClickedBlock().getType() != Material.AIR)
        lastClickedBlock = EVENT.getClickedBlock();
      if (asyncAction) {
        Bukkit.getScheduler()
            .runTaskAsynchronously(
                Core.getPlugin(),
                new BukkitRunnable() {
                  @Override
                  public void run() {
                    if (useTwoInteractMethods) {
                      if (EVENT.getAction() == Action.RIGHT_CLICK_AIR
                          || EVENT.getAction() == Action.RIGHT_CLICK_BLOCK) onRightClick();
                      else if (EVENT.getAction() == Action.LEFT_CLICK_BLOCK
                          || EVENT.getAction() == Action.LEFT_CLICK_AIR) onLeftClick();
                    } else {
                      onRightClick();
                    }
                  }
                });
      } else {
        if (useTwoInteractMethods) {
          if (EVENT.getAction() == Action.RIGHT_CLICK_AIR
              || EVENT.getAction() == Action.RIGHT_CLICK_BLOCK) onRightClick();
          else if (EVENT.getAction() == Action.LEFT_CLICK_BLOCK
              || EVENT.getAction() == Action.LEFT_CLICK_AIR) onLeftClick();
        } else {
          onRightClick();
        }
      }
    }