예제 #1
0
  private static void resetPlayer(PlayerMoveEvent event, NoCheatData data) {

    Location l = data.speedhackSetBackPoint;

    data.reset = true;
    // If we have stored a location for the player, we put him back there
    if (l != null) {
      event.setFrom(l);
      event.setTo(l);
      event.setCancelled(true);
      event.getPlayer().teleportTo(l);
    } else {
      event.setFrom(event.getFrom());
      event.setTo(event.getFrom().clone());
      event.setCancelled(true);
      event.getPlayer().teleportTo(event.getFrom());
    }
  }
  /* (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.");
    }
  }
  @Override
  public void onPlayerMove(final PlayerMoveEvent event) {
    if (event.isCancelled()) {
      return;
    }
    final User user = ess.getUser(event.getPlayer());

    if (user.isAfk() && ess.getSettings().getFreezeAfkPlayers()) {
      final Location from = event.getFrom();
      final Location to = event.getTo().clone();
      to.setX(from.getX());
      to.setY(from.getBlock().getTypeId() == 0 ? from.getY() - 1 : from.getY());
      to.setZ(from.getZ());
      event.setTo(to);
      return;
    }

    Location afk = user.getAfkPosition();
    if (afk == null
        || !event.getTo().getWorld().equals(afk.getWorld())
        || afk.distanceSquared(event.getTo()) > 9) {
      user.updateActivity(true);
    }

    if (!ess.getSettings().getNetherPortalsEnabled()) {
      return;
    }

    final Block block =
        event
            .getPlayer()
            .getWorld()
            .getBlockAt(
                event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ());
    final List<World> worlds = server.getWorlds();

    if (block.getType() == Material.PORTAL
        && worlds.size() > 1
        && user.isAuthorized("essentials.portal")) {
      if (user.getJustPortaled()) {
        return;
      }

      World nether = server.getWorld(ess.getSettings().getNetherName());
      if (nether == null) {
        for (World world : worlds) {
          if (world.getEnvironment() == World.Environment.NETHER) {
            nether = world;
            break;
          }
        }
        if (nether == null) {
          return;
        }
      }
      final World world = user.getWorld() == nether ? worlds.get(0) : nether;

      double factor;
      if (user.getWorld().getEnvironment() == World.Environment.NETHER
          && world.getEnvironment() == World.Environment.NORMAL) {
        factor = ess.getSettings().getNetherRatio();
      } else if (user.getWorld().getEnvironment() == World.Environment.NORMAL
          && world.getEnvironment() == World.Environment.NETHER) {
        factor = 1.0 / ess.getSettings().getNetherRatio();
      } else {
        factor = 1.0;
      }

      Location loc = event.getTo();
      int x = loc.getBlockX();
      int y = loc.getBlockY();
      int z = loc.getBlockZ();

      if (user.getWorld().getBlockAt(x, y, z - 1).getType() == Material.PORTAL) {
        z--;
      }
      if (user.getWorld().getBlockAt(x - 1, y, z).getType() == Material.PORTAL) {
        x--;
      }

      x = (int) (x * factor);
      z = (int) (z * factor);
      loc = new Location(world, x + .5, y, z + .5);

      Block dest = world.getBlockAt(x, y, z);
      NetherPortal portal = NetherPortal.findPortal(dest);
      if (portal == null) {
        if (world.getEnvironment() == World.Environment.NETHER
            || ess.getSettings().getGenerateExitPortals()) {
          portal = NetherPortal.createPortal(dest);
          LOGGER.info(Util.format("userCreatedPortal", event.getPlayer().getName()));
          user.sendMessage(Util.i18n("generatingPortal"));
          loc = portal.getSpawn();
        }
      } else {
        LOGGER.info(Util.format("userUsedPortal", event.getPlayer().getName()));
        user.sendMessage(Util.i18n("usingPortal"));
        loc = portal.getSpawn();
      }

      event.setFrom(loc);
      event.setTo(loc);
      try {
        user.getTeleport().now(loc, new Trade("portal", ess));
      } catch (Exception ex) {
        user.sendMessage(ex.getMessage());
      }
      user.setJustPortaled(true);
      user.sendMessage(Util.i18n("teleportingPortal"));

      event.setCancelled(true);
      return;
    }

    user.setJustPortaled(false);
  }