@Override
 public void run() {
   for (CustomPlayer customPlayer : Core.getCustomPlayers()) {
     Player p = customPlayer.getPlayer();
     try {
       if (!((List<String>) SettingsManager.getConfig().get("Enabled-Worlds"))
           .contains(p.getWorld().getName())) {
         customPlayer.clear();
         customPlayer.removeMenuItem();
       }
     } catch (Exception exc) {
     }
   }
 }
Exemplo n.º 2
0
 @EventHandler
 protected void onItemDrop(PlayerDropItemEvent event) {
   if (event.getItemDrop().getItemStack().getType() == type.getMaterial()) {
     if (event.getItemDrop().getItemStack().getData().getData() == type.getData()) {
       if (event.getItemDrop().getItemStack().getItemMeta().hasDisplayName()) {
         if (event
             .getItemDrop()
             .getItemStack()
             .getItemMeta()
             .getDisplayName()
             .endsWith(getName())) {
           if (SettingsManager.getConfig().getBoolean("Remove-Gadget-With-Drop")) {
             Core.getCustomPlayer(getPlayer()).removeGadget();
             event.getItemDrop().remove();
             return;
           }
           event.setCancelled(true);
         }
       }
     }
   }
 }
Exemplo n.º 3
0
  GadgetType(
      Material material,
      byte data,
      double defaultCountdown,
      String permission,
      String configName,
      String defaultDesc,
      Class<? extends Gadget> clazz) {
    this.permission = permission;
    this.configName = configName;
    this.clazz = clazz;
    this.material = material;
    this.data = data;
    this.affectPlayers =
        SettingsManager.getConfig().getBoolean("Gadgets." + configName + ".Affect-Players");

    if (SettingsManager.getConfig().get("Gadgets." + configName + ".Cooldown") == null) {
      this.countdown = defaultCountdown;
      SettingsManager.getConfig().set("Gadgets." + configName + ".Cooldown", defaultCountdown);
    } else
      this.countdown =
          Double.valueOf(
              String.valueOf(
                  SettingsManager.getConfig().get("Gadgets." + configName + ".Cooldown")));
    if (SettingsManager.getConfig().get("Gadgets." + configName + ".Description") == null) {
      this.description = defaultDesc;
      Core.config.addDefault(
          "Gadgets." + configName + ".Description",
          getDescriptionWithColor(),
          "Description of this gadget.");
    } else
      this.description =
          fromList(
              ((List<String>)
                  SettingsManager.getConfig().get("Gadgets." + configName + ".Description")));
  }
Exemplo n.º 4
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;
    }
  }
Exemplo n.º 5
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();
        }
      }
    }
Exemplo n.º 6
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");
 }
Exemplo n.º 7
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");
 }
Exemplo n.º 8
0
 /** Removes the item. */
 public void removeItem() {
   itemStack = null;
   getPlayer().getInventory().setItem((int) SettingsManager.getConfig().get("Gadget-Slot"), null);
 }
Exemplo n.º 9
0
 public boolean isEnabled() {
   return SettingsManager.getConfig().getBoolean("Gadgets." + configName + ".Enabled");
 }
Exemplo n.º 10
0
 public boolean canBeFound() {
   return SettingsManager.getConfig()
       .getBoolean("Gadgets." + configName + ".Can-Be-Found-In-Treasure-Chests");
 }
Exemplo n.º 11
0
 public boolean showsDescription() {
   return SettingsManager.getConfig().getBoolean("Gadgets." + configName + ".Show-Description");
 }
Exemplo n.º 12
0
 public boolean requiresAmmo() {
   return SettingsManager.getConfig().getBoolean("Gadgets." + configName + ".Ammo.Enabled");
 }