Exemplo n.º 1
0
  @Override
  public boolean deposit(String player, double amount) {
    if (amount > 0) {
      Account account = eco.getBank().getAccount(player);
      if (account == null) {
        eco.getBank().addAccount(player);
        account = eco.getBank().getAccount(player);
      }

      account.add(amount);
      return true;
    }
    return false;
  }
  /* (non-Javadoc)
   * @see org.bukkit.event.player.PlayerListener#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)
   */
  @Override
  public void onPlayerMove(PlayerMoveEvent event) {
    Player p = event.getPlayer();
    Location l = event.getTo();
    Block ch = l.getWorld().getBlockAt(l.getBlockX(), l.getBlockY(), l.getBlockZ());
    Stargate st = StargateManager.getGateFromBlock(ch);

    if (st != null && st.Active && st.Target != null) {
      String gatenetwork;
      if (st.Network != null) {
        gatenetwork = st.Network.netName;
      } else {
        gatenetwork = "Public";
      }
      wxt.prettyLog(
          Level.FINE,
          false,
          "Player in gate:"
              + st.Name
              + " gate Active: "
              + st.Active
              + " Target Gate: "
              + st.Target.Name
              + " Network: "
              + gatenetwork);

      if (ConfigManager.getWormholeUseIsTeleport()
          && ((st.IsSignPowered && !WXPermissions.checkWXPermissions(p, st, PermissionType.SIGN))
              || (!st.IsSignPowered
                  && !WXPermissions.checkWXPermissions(p, st, PermissionType.DIALER)))) {
        p.sendMessage(ConfigManager.output_strings.get(StringTypes.PERMISSION_NO));
        return;
      }
      if (st.Target.IrisActive) {
        p.sendMessage(ConfigManager.errorheader + "Remote Iris is locked!");
        p.setNoDamageTicks(2);
        event.setFrom(st.TeleportLocation);
        event.setTo(st.TeleportLocation);
        p.teleport(st.TeleportLocation);
        if (p.getFireTicks() > 0) {
          p.setFireTicks(0);
        }
        return;
      }

      Location target = st.Target.TeleportLocation;
      if (WormholeXTreme.iconomy != null) {
        double cost = ConfigManager.getIconomyWormholeUseCost();
        if (!ConfigManager.getIconomyOpsExcempt()
            && !p.isOp()
            && cost != 0.0
            && st.Owner != null
            && !st.Owner.equals(p.getName())) {
          Account player_account = iConomy.getBank().getAccount(p.getName());
          double balance = player_account.getBalance();
          String currency = iConomy.getBank().getCurrency();
          if (balance >= cost) {
            player_account.subtract(cost);
            // player_account.save();
            p.sendMessage(
                ConfigManager.normalheader
                    + "Wormhole Use \u00A7F- \u00A72"
                    + cost
                    + " \u00A77"
                    + currency);
            // p.sendMessage("You were charged " + cost + " " + iConomy.getBank().getCurrency() + "
            // to use wormhole." );
            double owner_percent = ConfigManager.getIconomyWormholeOwnerPercent();

            if (owner_percent != 0.0 && st.Owner != null) {
              if (st.Owner != null && iConomy.getBank().hasAccount(st.Owner)) {
                Account own_acc = iConomy.getBank().getAccount(st.Owner);
                own_acc.add(cost * owner_percent);
                // own_acc.save();
              }
            }
          } else {
            p.sendMessage(
                ConfigManager.errorheader
                    + "Not enough "
                    + currency
                    + "! - Requires: \u00A72"
                    + cost
                    + " \u00A77- Available: \u00A74"
                    + player_account.getBalance()
                    + " \u00A77"
                    + currency);
            // p.sendMessage("Not enough " + iConomy.getBank().getCurrency() + " to use - requires:
            // " + cost);
            target = st.TeleportLocation;
          }
        }
      }

      Block target_block =
          target.getWorld().getBlockAt(target.getBlockX(), target.getBlockY(), target.getBlockZ());
      while (target_block.getType() != Material.AIR
          && target_block.getType() != Material.WATER
          && target_block.getType() != Material.LAVA) {
        target_block = target_block.getFace(BlockFace.UP);
        target.setY(target.getY() + 1.0);
      }
      event.setFrom(target);
      event.setTo(target);
      p.setNoDamageTicks(2);
      p.teleport(target);
      event.setCancelled(true);
      if (target == st.Target.TeleportLocation)
        wxt.prettyLog(
            Level.INFO,
            false,
            p.getDisplayName() + " used wormhole: " + st.Name + " to go to: " + st.Target.Name);

      if (ConfigManager.getTimeoutShutdown() == 0) {
        st.ShutdownStargate();
      }
    } else if (st != null) {
      wxt.prettyLog(
          Level.FINE, false, "Player entered gate but wasn't active or didn't have a target.");
    }
  }