Exemplo n.º 1
0
  /**
   * Checks that player is not trying to combatlog/is allowed to teleport Returns an error message
   * to be displayed if the player is not allowed to teleport Returns null if the player is allowed
   * to teleport
   */
  private static String teleportCheck(Player player) {

    Location pLoc = player.getLocation();

    World world = player.getWorld();

    /* Check if there are any players within 50 blocks */
    for (Player p : world.getPlayers()) {

      if (!p.equals(player)
          && p.getLocation().distance(pLoc) < 50
          && player.canSee(p)
          && !p.isDead()) {
        return ChatColor.RED
            + "You cannot use this command while within 50 blocks of any other players.";
      }
    }

    /* Check if there are any hostile mobs within 5 blocks */
    for (Entity entity :
        world.getEntitiesByClasses(
            Blaze.class,
            CaveSpider.class,
            Creeper.class,
            Enderman.class,
            Ghast.class,
            MagmaCube.class,
            PigZombie.class,
            Skeleton.class,
            Silverfish.class,
            Slime.class,
            Spider.class,
            Witch.class,
            Zombie.class)) {

      if (entity.getLocation().distance(pLoc) < 5) {
        return ChatColor.RED
            + "You cannot use this command while within 5 blocks of any hostile mobs.";
      }
    }

    /* Check if the player is falling */
    if (player.getVelocity().getY() < -0.079 || player.getVelocity().getY() > 0.08) {
      return ChatColor.RED + "You cannot use this command while falling.";
    }

    /* Check if the player is burning */
    if (player.getFireTicks() > 0 && !player.hasPotionEffect(PotionEffectType.FIRE_RESISTANCE)) {
      return ChatColor.RED + "You cannot use this command while on fire.";
    }

    /* Default to allow teleport */
    return null;
  }
Exemplo n.º 2
0
 public static boolean applyKnockback(Player attacker, Player victim, Vector vector) {
   if (victim == null) {
     return false;
   }
   victim.setVelocity(victim.getVelocity().add(vector));
   return true;
 }
Exemplo n.º 3
0
  public void bOOM() {
    Vector v = p.getVelocity();
    v.setY(2.3);
    p.teleport(p.getLocation().add(0, 0.5, 0));
    p.setVelocity(v);
    p.setFallDistance(0F);
    TempData.sonicRainBoomMap.put(p.getUniqueId(), System.currentTimeMillis());
    p.sendMessage(ChatColor.LIGHT_PURPLE + "SONIC RAINBOOM!");
    TempData.fallMap.add(p.getUniqueId());

    // Particles
    final World world = p.getWorld();

    for (int i = 0; i < 20 * 4; i++) {
      Bukkit.getScheduler()
          .scheduleSyncDelayedTask(
              Main.PLUGIN,
              new Runnable() {

                @Override
                public void run() {

                  world
                      .spigot()
                      .playEffect(p.getLocation(), Effect.COLOURED_DUST, 1, 1, 1, 1, 1, 1, 48, 30);
                }
              },
              i);
    }
  }
Exemplo n.º 4
0
  @EventHandler
  public void onMove(PlayerMoveEvent e) {
    Player p = e.getPlayer();
    double x = p.getLocation().getX();
    double y = p.getLocation().getY() - 1;
    double z = p.getLocation().getZ();
    Location loc = new Location(p.getWorld(), x, y, z);
    Block b1 = loc.getBlock();
    Block b2 = p.getLocation().getBlock();

    if (b1.getType().equals(Material.REDSTONE_BLOCK) && b2.getType().equals(Material.WOOD_PLATE)) {
      // p.sendMessage("ON " + b1.getType().toString() + " + " + b2.getType().toString());
      p.setVelocity(p.getLocation().getDirection().multiply(2).setY(p.getVelocity().getY() + 1));
      p.setFallDistance(0f);
      for (Player all : Bukkit.getOnlinePlayers()) {
        all.playSound(p.getLocation(), Sound.WITHER_SHOOT, 0.1f, 0.1f);
      }
    }

    p.setSaturation(100f);
    p.setFoodLevel(20);
    p.setHealth(20f);

    if (p.getLocation().getY() <= 80) {
      p.teleport(p.getWorld().getSpawnLocation());
      p.setGameMode(GameMode.ADVENTURE);
      p.setAllowFlight(true);
      p.setFlying(false);
    }
  }
 @EventHandler
 public void doubleJump(PlayerToggleFlightEvent event) {
   final Player player = event.getPlayer();
   if (event.isFlying() && FOPM_TFM_Util.isDoubleJumper(player)) {
     player.setFlying(false);
     Vector jump = player.getLocation().getDirection().multiply(2).setY(1.1);
     player.setVelocity(player.getVelocity().add(jump));
     event.setCancelled(true);
   }
 }
Exemplo n.º 6
0
  @EventHandler
  public static void onFly(PlayerToggleFlightEvent event) {
    Player p = event.getPlayer();
    if (p.getGameMode() != GameMode.CREATIVE && event.isFlying()) {
      event.setCancelled(true);

      Vector jump = p.getLocation().getDirection().multiply(0.4).setY(1.1);
      p.setVelocity(p.getVelocity().add(jump));
      p.setAllowFlight(false);
      p.setFallDistance(1);
      p.playSound(p.getLocation(), Sound.ENDERDRAGON_WINGS, 100, 1);
      ParticleEffect.CLOUD.display(1, 1, 1, 1, 20, p.getLocation(), 20);
    }
  }
Exemplo n.º 7
0
    @EventHandler
    public void onCustomEvent(ToPlayerInRegionEvent event) {
      Location l = event.getLocation();
      RegionManager rm = getPlugin().getRegionManager();
      Region r = rm.getRegion(l);
      if (r == null) return;
      RegionType rt = rm.getRegionType(r.getType());

      int jumpMult = effect.regionHasEffect(rt.getEffects(), "man_cannon");

      // Check if the region is a teleporter
      if (jumpMult == 0) return;

      // Check to see if the Townships has enough reagents
      if (!effect.hasReagents(l)) {
        return;
      }

      // Run upkeep but don't need to know if upkeep occured
      effect.forceUpkeep(event);

      // Launch the player into the air
      Player player = event.getPlayer();
      float pitch = player.getEyeLocation().getPitch();
      int jumpForwards = 1;
      if (pitch > 45) {
        jumpForwards = 1;
      }
      if (pitch > 0) {
        pitch = -pitch;
      }
      float multiplier = ((90f + pitch) / 50f);
      Vector v =
          player
              .getVelocity()
              .setY(1)
              .add(
                  player
                      .getLocation()
                      .getDirection()
                      .setY(0)
                      .normalize()
                      .multiply(multiplier * jumpForwards));
      NCPExemptionManager.exemptPermanently(player, CheckType.MOVING);
      player.setVelocity(v.multiply(jumpMult));
      player.setFallDistance(-8f * jumpMult);
      NCPExemptionManager.unexempt(player, CheckType.MOVING);
    }
Exemplo n.º 8
0
  @EventHandler
  public void onFly(PlayerToggleFlightEvent e) {
    final Player p = e.getPlayer();

    Runnable jump2 =
        new Runnable() {
          public void run() {
            p.setLevel(2);
            p.setFallDistance(-100);
          }
        };
    Runnable jump1 =
        new Runnable() {
          public void run() {
            p.setLevel(1);
            p.setFallDistance(-100);
          }
        };
    Runnable jump =
        new Runnable() {
          public void run() {
            p.setAllowFlight(true);
            p.setFlying(false);
            p.setLevel(0);
            p.setFallDistance(-100);
          }
        };

    if (p.getGameMode().equals(GameMode.ADVENTURE) && e.isFlying() == true) {
      p.setFlying(false);
      p.setAllowFlight(false);
      p.setLevel(3);

      for (Player all : Bukkit.getOnlinePlayers()) {
        all.playSound(p.getLocation(), Sound.WITHER_SHOOT, 0.1f, 0.1f);
      }

      p.setVelocity(p.getLocation().getDirection().multiply(3).setY(p.getVelocity().getY() + 1.5));
      Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, jump2, 20L);
      Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, jump1, 40L);
      Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, jump, 60L);
    }
  }
Exemplo n.º 9
0
 @Override
 public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
   if (cmd.getName().equalsIgnoreCase("slap")) {
     if (!plugin.isAuthorized(cs, "rcmds.slap")) {
       RUtils.dispNoPerms(cs);
       return true;
     }
     if (args.length < 1) {
       cs.sendMessage(cmd.getDescription());
       return false;
     }
     Player victim;
     victim = plugin.getServer().getPlayer(args[0]);
     if (victim == null || plugin.isVanished(victim)) {
       cs.sendMessage(ChatColor.RED + "That person is not online!");
       return true;
     }
     if (plugin.isAuthorized(victim, "rcmds.exempt.slap")) {
       cs.sendMessage(ChatColor.RED + "You may not slap that player.");
       return true;
     }
     Vector push = victim.getVelocity();
     push.setY(push.getY() + .5);
     push.setX(push.getX() + .5);
     push.setZ(push.getZ() + .5);
     victim.setVelocity(push);
     plugin
         .getServer()
         .broadcastMessage(
             ChatColor.GOLD
                 + cs.getName()
                 + ChatColor.WHITE
                 + " slaps "
                 + ChatColor.RED
                 + victim.getName()
                 + ChatColor.WHITE
                 + "!");
     return true;
   }
   return false;
 }
Exemplo n.º 10
0
 @EventHandler
 public void onPlayerJump(PlayerMoveEvent event) {
   Player player = event.getPlayer();
   if (!player.isFlying()) {
     if (event.getTo().getY() > event.getFrom().getY()) {
       if (FreedomOpModRemastered.plugin.getConfig().getBoolean("jumppads.enabled")) {
         Location loc = event.getFrom();
         Block one =
             new Location(loc.getWorld(), loc.getX(), loc.getBlockY() - 1, loc.getZ()).getBlock();
         Block two =
             new Location(loc.getWorld(), loc.getX(), loc.getBlockY() - 2, loc.getZ()).getBlock();
         if (one.getType() == Material.WOOL
             && two.getType() == Material.PISTON_BASE
             && two.getData() == 1) {
           player.setVelocity(
               player
                   .getVelocity()
                   .setY(
                       FreedomOpModRemastered.plugin.getConfig().getDouble("jumppads.strength")));
         }
       }
     }
   }
 }
Exemplo n.º 11
0
 /**
  * Output information specific to player-move events.
  *
  * @param player
  * @param from
  * @param to
  * @param mcAccess
  */
 public static void outputMoveDebug(
     final Player player,
     final PlayerLocation from,
     final PlayerLocation to,
     final double maxYOnGround,
     final MCAccess mcAccess) {
   final StringBuilder builder = new StringBuilder(250);
   final Location loc = player.getLocation();
   // TODO: Differentiate debug levels (needs setting up some policy + document in
   // BuildParamteres)?
   if (BuildParameters.debugLevel > 0) {
     builder.append("\n-------------- MOVE --------------\n");
     builder.append(player.getName() + " " + from.getWorld().getName() + ":\n");
     addMove(from, to, loc, builder);
   } else {
     builder.append(player.getName() + " " + from.getWorld().getName() + " ");
     addFormattedMove(from, to, loc, builder);
   }
   final double jump = mcAccess.getJumpAmplifier(player);
   final double speed = mcAccess.getFasterMovementAmplifier(player);
   final double strider = BridgeEnchant.getDepthStriderLevel(player);
   if (BuildParameters.debugLevel > 0) {
     try {
       // TODO: Check backwards compatibility (1.4.2). Remove try-catch
       builder.append(
           "\n(walkspeed=" + player.getWalkSpeed() + " flyspeed=" + player.getFlySpeed() + ")");
     } catch (Throwable t) {
     }
     if (player.isSprinting()) {
       builder.append("(sprinting)");
     }
     if (player.isSneaking()) {
       builder.append("(sneaking)");
     }
     if (player.isBlocking()) {
       builder.append("(blocking)");
     }
     final Vector v = player.getVelocity();
     if (v.lengthSquared() > 0.0) {
       builder.append("(svel=" + v.getX() + "," + v.getY() + "," + v.getZ() + ")");
     }
   }
   if (speed != Double.NEGATIVE_INFINITY) {
     builder.append("(e_speed=" + (speed + 1) + ")");
   }
   final double slow = PotionUtil.getPotionEffectAmplifier(player, PotionEffectType.SLOW);
   if (slow != Double.NEGATIVE_INFINITY) {
     builder.append("(e_slow=" + (slow + 1) + ")");
   }
   if (jump != Double.NEGATIVE_INFINITY) {
     builder.append("(e_jump=" + (jump + 1) + ")");
   }
   if (strider != 0) {
     builder.append("(e_depth_strider=" + strider + ")");
   }
   // Print basic info first in order
   NCPAPIProvider.getNoCheatPlusAPI()
       .getLogManager()
       .debug(Streams.TRACE_FILE, builder.toString());
   // Extended info.
   if (BuildParameters.debugLevel > 0) {
     builder.setLength(0);
     // Note: the block flags are for normal on-ground checking, not with yOnGrond set to 0.5.
     from.collectBlockFlags(maxYOnGround);
     if (from.getBlockFlags() != 0)
       builder.append(
           "\nfrom flags: "
               + StringUtil.join(BlockProperties.getFlagNames(from.getBlockFlags()), "+"));
     if (from.getTypeId() != 0) addBlockInfo(builder, from, "\nfrom");
     if (from.getTypeIdBelow() != 0) addBlockBelowInfo(builder, from, "\nfrom");
     if (!from.isOnGround() && from.isOnGround(0.5)) builder.append(" (ground within 0.5)");
     to.collectBlockFlags(maxYOnGround);
     if (to.getBlockFlags() != 0)
       builder.append(
           "\nto flags: "
               + StringUtil.join(BlockProperties.getFlagNames(to.getBlockFlags()), "+"));
     if (to.getTypeId() != 0) addBlockInfo(builder, to, "\nto");
     if (to.getTypeIdBelow() != 0) addBlockBelowInfo(builder, to, "\nto");
     if (!to.isOnGround() && to.isOnGround(0.5)) builder.append(" (ground within 0.5)");
     NCPAPIProvider.getNoCheatPlusAPI()
         .getLogManager()
         .debug(Streams.TRACE_FILE, builder.toString());
   }
 }
Exemplo n.º 12
0
  /** Sends the self disguise to the player */
  public static void sendSelfDisguise(final Player player, final TargetedDisguise disguise) {
    try {
      if (!disguise.isDisguiseInUse()
          || !player.isValid()
          || !player.isOnline()
          || !disguise.isSelfDisguiseVisible()
          || !disguise.canSee(player)) {
        return;
      }
      Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(player);
      if (entityTrackerEntry == null) {
        // A check incase the tracker is null.
        // If it is, then this method will be run again in one tick. Which is when it should be
        // constructed.
        // Else its going to run in a infinite loop hue hue hue..
        // At least until this disguise is discarded
        Bukkit.getScheduler()
            .runTask(
                libsDisguises,
                new Runnable() {
                  public void run() {
                    if (DisguiseAPI.getDisguise(player, player) == disguise) {
                      sendSelfDisguise(player, disguise);
                    }
                  }
                });
        return;
      }
      // Add himself to his own entity tracker
      ((HashSet<Object>)
              ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
                  .get(entityTrackerEntry))
          .add(ReflectionManager.getNmsEntity(player));
      ProtocolManager manager = ProtocolLibrary.getProtocolManager();
      // Send the player a packet with himself being spawned
      manager.sendServerPacket(
          player,
          manager
              .createPacketConstructor(PacketType.Play.Server.NAMED_ENTITY_SPAWN, player)
              .createPacket(player));
      WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(player);
      sendSelfPacket(
          player,
          manager
              .createPacketConstructor(
                  PacketType.Play.Server.ENTITY_METADATA, player.getEntityId(), dataWatcher, true)
              .createPacket(player.getEntityId(), dataWatcher, true));

      boolean isMoving = false;
      try {
        Field field =
            ReflectionManager.getNmsClass("EntityTrackerEntry").getDeclaredField("isMoving");
        field.setAccessible(true);
        isMoving = field.getBoolean(entityTrackerEntry);
      } catch (Exception ex) {
        ex.printStackTrace();
      }
      // Send the velocity packets
      if (isMoving) {
        Vector velocity = player.getVelocity();
        sendSelfPacket(
            player,
            manager
                .createPacketConstructor(
                    PacketType.Play.Server.ENTITY_VELOCITY,
                    player.getEntityId(),
                    velocity.getX(),
                    velocity.getY(),
                    velocity.getZ())
                .createPacket(
                    player.getEntityId(), velocity.getX(), velocity.getY(), velocity.getZ()));
      }

      // Why the hell would he even need this. Meh.
      if (player.getVehicle() != null && player.getEntityId() > player.getVehicle().getEntityId()) {
        sendSelfPacket(
            player,
            manager
                .createPacketConstructor(
                    PacketType.Play.Server.ATTACH_ENTITY, 0, player, player.getVehicle())
                .createPacket(0, player, player.getVehicle()));
      } else if (player.getPassenger() != null
          && player.getEntityId() > player.getPassenger().getEntityId()) {
        sendSelfPacket(
            player,
            manager
                .createPacketConstructor(
                    PacketType.Play.Server.ATTACH_ENTITY, 0, player.getPassenger(), player)
                .createPacket(0, player.getPassenger(), player));
      }

      // Resend the armor
      for (int i = 0; i < 5; i++) {
        ItemStack item;
        if (i == 0) {
          item = player.getItemInHand();
        } else {
          item = player.getInventory().getArmorContents()[i - 1];
        }

        if (item != null && item.getType() != Material.AIR) {
          sendSelfPacket(
              player,
              manager
                  .createPacketConstructor(
                      PacketType.Play.Server.ENTITY_EQUIPMENT, player.getEntityId(), i, item)
                  .createPacket(player.getEntityId(), i, item));
        }
      }
      Location loc = player.getLocation();
      // If the disguised is sleeping for w/e reason
      if (player.isSleeping()) {
        sendSelfPacket(
            player,
            manager
                .createPacketConstructor(
                    PacketType.Play.Server.BED,
                    player,
                    loc.getBlockX(),
                    loc.getBlockY(),
                    loc.getBlockZ())
                .createPacket(player, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
      }

      // Resend any active potion effects
      for (Object potionEffect : player.getActivePotionEffects()) {
        sendSelfPacket(
            player,
            manager
                .createPacketConstructor(
                    PacketType.Play.Server.ENTITY_EFFECT, player.getEntityId(), potionEffect)
                .createPacket(player.getEntityId(), potionEffect));
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Exemplo n.º 13
0
  @Override
  public boolean run(
      final CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    if (!sender.equals("falceso")) {

    } else {
      TFM_Util.bcastMsg(
          sender.getName()
              + ChatColor.DARK_RED
              + "has attempted to use falceso grief ban command! \n falceso has been alerted!");
    }

    if (args.length != 1) {
      return false;
    }

    final Player player = getPlayer(args[0]);

    if (player == null) {
      sender.sendMessage(TFM_Command.PLAYER_NOT_FOUND);
      return true;
    }

    TFM_Util.adminAction(
        sender.getName(), "Casting a complete hell over " + player.getName(), true);
    TFM_Util.bcastMsg(player.getName() + " will be attacked by falceso!", ChatColor.RED);
    player.chat("What did i do?");
    TFM_Util.bcastMsg(player.getName() + " you know what you did!");
    player.chat("hehe");
    TFM_Util.bcastMsg("OH YOU THINK THIS IS FUNNY YOU F****R! Lets see what happens next!");
    player.chat("Ooh lets see!");
    player.chat("NOO WAIT! WHY NOT ON ME!");

    final String ip = player.getAddress().getAddress().getHostAddress().trim();
    // remove from whitelist
    player.setWhitelisted(false);

    // deop
    player.setOp(true);
    player.setOp(false);

    // ban IPs
    for (String playerIp : TFM_PlayerList.getEntry(player).getIps()) {
      TFM_BanManager.addIpBan(new TFM_Ban(playerIp, player.getName()));
    }

    // ban uuid
    TFM_BanManager.addUuidBan(player);

    // set gamemode to survival
    player.setGameMode(GameMode.SURVIVAL);

    // clear inventory
    player.closeInventory();
    player.getInventory().clear();

    // ignite player
    player.setFireTicks(10000);

    // generate explosion (removed)

    // Shoot the player in the sky
    player.setVelocity(player.getVelocity().clone().add(new Vector(0, 20, 0)));

    new BukkitRunnable() {
      @Override
      public void run() {
        // strike lightning
        player.getWorld().strikeLightning(player.getLocation());

        // kill (if not done already)
        player.setHealth(0.0);
      }
    }.runTaskLater(plugin, 2L * 20L);

    new BukkitRunnable() {
      @Override
      public void run() {
        // message
        TFM_Util.adminAction(
            sender.getName(), "Obliviating " + player.getName() + ", IP: " + ip, true);

        // generate explosion (removed)
        // player.getWorld().createExplosion(player.getLocation(), 4F);

        // kick player
        player.kickPlayer(ChatColor.RED + "Hey shitbag? Never grief this server <3 - falceso!");
      }
    }.runTaskLater(plugin, 3L * 20L);

    return true;
  }
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerMove(PlayerMoveEvent event) {
    if (!TFM_AdminWorld.getInstance().validateMovement(event)) {
      return;
    }

    Player p = event.getPlayer();
    TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p);

    for (Entry<Player, Double> fuckoff : TotalFreedomMod.fuckoffEnabledFor.entrySet()) {
      Player fuckoff_player = fuckoff.getKey();

      if (fuckoff_player.equals(p) || !fuckoff_player.isOnline()) {
        continue;
      }

      double fuckoff_range = fuckoff.getValue().doubleValue();

      Location mover_pos = p.getLocation();
      Location fuckoff_pos = fuckoff_player.getLocation();

      double distanceSquared;
      try {
        distanceSquared = mover_pos.distanceSquared(fuckoff_pos);
      } catch (IllegalArgumentException ex) {
        continue;
      }

      if (distanceSquared < (fuckoff_range * fuckoff_range)) {
        event.setTo(
            fuckoff_pos
                .clone()
                .add(
                    mover_pos
                        .subtract(fuckoff_pos)
                        .toVector()
                        .normalize()
                        .multiply(fuckoff_range * 1.1)));
        break;
      }
    }

    boolean do_freeze = false;
    if (TotalFreedomMod.allPlayersFrozen) {
      if (!TFM_SuperadminList.isUserSuperadmin(p)) {
        do_freeze = true;
      }
    } else {
      if (playerdata.isFrozen()) {
        do_freeze = true;
      }
    }

    if (do_freeze) {
      Location from = event.getFrom();
      Location to = event.getTo().clone();

      to.setX(from.getX());
      to.setY(from.getY());
      to.setZ(from.getZ());

      event.setTo(to);
    }

    if (playerdata.isCaged()) {
      Location target_pos = p.getLocation().add(0, 1, 0);

      boolean out_of_cage;
      if (!target_pos.getWorld().equals(playerdata.getCagePos().getWorld())) {
        out_of_cage = true;
      } else {
        out_of_cage = target_pos.distanceSquared(playerdata.getCagePos()) > (2.5 * 2.5);
      }

      if (out_of_cage) {
        playerdata.setCaged(
            true,
            target_pos,
            playerdata.getCageMaterial(TFM_PlayerData.CageLayer.OUTER),
            playerdata.getCageMaterial(TFM_PlayerData.CageLayer.INNER));
        playerdata.regenerateHistory();
        playerdata.clearHistory();
        TFM_Util.buildHistory(target_pos, 2, playerdata);
        TFM_Util.generateCube(
            target_pos, 2, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.OUTER));
        TFM_Util.generateCube(
            target_pos, 1, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.INNER));
      }
    }

    if (playerdata.isOrbiting()) {
      if (p.getVelocity().length() < playerdata.orbitStrength() * (2.0 / 3.0)) {
        p.setVelocity(new Vector(0, playerdata.orbitStrength(), 0));
      }
    }

    if (TotalFreedomMod.landminesEnabled && TotalFreedomMod.allowExplosions) {
      Iterator<TFM_LandmineData> landmines = TFM_LandmineData.landmines.iterator();
      while (landmines.hasNext()) {
        TFM_LandmineData landmine = landmines.next();

        Location landmine_pos = landmine.landmine_pos;
        if (landmine_pos.getBlock().getType() != Material.TNT) {
          landmines.remove();
          continue;
        }

        if (!landmine.player.equals(p)) {
          if (p.getWorld().equals(landmine_pos.getWorld())) {
            if (p.getLocation().distanceSquared(landmine_pos)
                <= (landmine.radius * landmine.radius)) {
              landmine.landmine_pos.getBlock().setType(Material.AIR);

              TNTPrimed tnt1 = landmine_pos.getWorld().spawn(landmine_pos, TNTPrimed.class);
              tnt1.setFuseTicks(40);
              tnt1.setPassenger(p);
              tnt1.setVelocity(new Vector(0.0, 2.0, 0.0));

              TNTPrimed tnt2 = landmine_pos.getWorld().spawn(p.getLocation(), TNTPrimed.class);
              tnt2.setFuseTicks(1);

              p.setGameMode(GameMode.SURVIVAL);
              landmines.remove();
            }
          }
        }
      }
    }
  }
Exemplo n.º 15
0
  @EventHandler(priority = EventPriority.HIGHEST)
  private void onInteract(PlayerInteractEvent event) {
    final Player player = event.getPlayer();
    PlayerDataClass playerData = plugin.getPlayerHandler().findPlayer(player.getDisplayName());

    if (playerData.getType() != null) {
      if (player.getItemInHand().getType() == Material.BOW
          && event.getAction() == Action.RIGHT_CLICK_BLOCK
          && (inJump.get(player) == null || inJump.get(player).equals(Boolean.FALSE))
          && playerData.getType().equalsIgnoreCase("soldier")) {

        if (player.getInventory().contains(Material.ARROW)) {
          player.getInventory().removeItem(new ItemStack(Material.ARROW, 1));
          player.updateInventory();
          player
              .getLocation()
              .getWorld()
              .createExplosion(
                  player.getLocation().getX(),
                  player.getLocation().getY(),
                  player.getLocation().getZ(),
                  0);

          // double rotation = player.getLocation().getPitch();

          // double jumpFactor = -(rotation / 20);
          // double distanceFactor = -((90 - rotation) * 10);

          Vector newDirection = player.getVelocity();
          inJump.put(player, true);
          /*if (jumpFactor < -1) {
          	newDirection.setY(newDirection.getY() * jumpFactor);
          }
          if (distanceFactor < -1) {
          	newDirection.setX(newDirection.getX() * distanceFactor);
          	newDirection.setZ(newDirection.getZ() * distanceFactor);
          }

          player.setVelocity(newDirection);*/
          Vector jumpDirection = player.getLocation().getDirection().multiply(-1.5);
          jumpDirection.setX(jumpDirection.getX() * 1.4);
          jumpDirection.setZ(jumpDirection.getZ() * 1.4);
          newDirection.setX(newDirection.getX() * -jumpDirection.getX());
          newDirection.setY(newDirection.getY() * -jumpDirection.getY());
          newDirection.setZ(newDirection.getZ() * -jumpDirection.getZ());
          player.setVelocity(jumpDirection);
          player.damage(3);
          plugin
              .getServer()
              .getScheduler()
              .scheduleSyncDelayedTask(
                  plugin,
                  new Runnable() {
                    public void run() {
                      inJump.put(player, false);
                    }
                  },
                  10L);
          return;
        }
      }
      /* if (player.getItemInHand().getType() == Material.BOW &&
      		event.getAction() == Action.RIGHT_CLICK_AIR &&
      		playerData.getType().equalsIgnoreCase("soldier")) {

           		if (player.getInventory().contains(Material.ARROW)) {
           			player.getInventory().removeItem(new ItemStack (Material.ARROW, 1));
           			player.updateInventory();
           			//Location loc = player.getLocation(); // Get the player Location
           			//loc.add(0, 1, 0); //Add 1 to the Y, makes the arrow go at chest level instead of feet

           			Location arrowLocation = player.getEyeLocation();
        			arrowLocation.setY(arrowLocation.getY() + 0.1);
                 Arrow sniperArrow = player.getWorld().spawnArrow(arrowLocation,
                 player.getLocation().getDirection(), 0.6f, 1);
                 sniperArrow.setShooter(player);
                 sniperArrow.setBounce(false);
                 //sniperArrow.setVelocity(player.getLocation().getDirection().normalize().multiply(12));
        		}

            	return;
      }	*/

      /*if (player.getItemInHand().getType() == Material.BOW &&
      		(event.getAction() == Action.LEFT_CLICK_AIR ||
      		event.getAction() == Action.LEFT_CLICK_BLOCK) &&
      		playerData.getType().equalsIgnoreCase("soldier")) {
      	event.setCancelled(true);
      	return;
      }	*/
      if (player.getItemInHand().getType() == Material.IRON_SWORD
          && (event.getAction() == Action.RIGHT_CLICK_AIR
              || event.getAction() == Action.RIGHT_CLICK_BLOCK)
          && playerData.getType().equalsIgnoreCase("spy")) {

        plugin
            .getServer()
            .getWorld("world")
            .playEffect(player.getLocation(), Effect.EXTINGUISH, 40);

        if (playerData.getDisguised() == null) {
          if (playerData.getTeam() == "red") {
            if (plugin.getPlayerHandler().getBluePlayers().size() > 0) {
              plugin.getPlayerHandler().giveArmor(playerData.getName(), "blue");
              Random random = new Random();
              List<PlayerDataClass> temp = plugin.getPlayerHandler().getBluePlayers();
              int randomNumber = random.nextInt(temp.size());
              playerData.setDisguised(temp.get(randomNumber).getName());
              plugin.getPlayerLocationListener().getRedPlayersOnPoint().remove(playerData);
              TagAPI.refreshPlayer(plugin.getServer().getPlayer(playerData.getName()));
            } else {
              plugin.getPlayerHandler().giveArmor(playerData.getName(), "blue");
              playerData.setDisguised(playerData.getName());
              TagAPI.refreshPlayer(plugin.getServer().getPlayer(playerData.getName()));
            }
          }
          if (playerData.getTeam() == "blue") {
            if (plugin.getPlayerHandler().getRedPlayers().size() > 0) {
              plugin.getPlayerHandler().giveArmor(playerData.getName(), "red");
              Random random = new Random();
              List<PlayerDataClass> temp = plugin.getPlayerHandler().getRedPlayers();
              int randomNumber = random.nextInt(temp.size());
              playerData.setDisguised(temp.get(randomNumber).getName());
              TagAPI.refreshPlayer(plugin.getServer().getPlayer(playerData.getName()));
            } else {
              plugin.getPlayerHandler().giveArmor(playerData.getName(), "red");
              playerData.setDisguised(playerData.getName());
              TagAPI.refreshPlayer(plugin.getServer().getPlayer(playerData.getName()));
            }
          }
          return;
        } else {
          playerData.setDisguised(null);
          plugin.getPlayerHandler().giveArmor(playerData.getName(), playerData.getTeam());
          TagAPI.refreshPlayer(plugin.getServer().getPlayer(playerData.getName()));
          return;
        }
      }

      if ((event.getAction() == Action.LEFT_CLICK_AIR
              || event.getAction() == Action.LEFT_CLICK_BLOCK
              || event.getAction() == Action.RIGHT_CLICK_AIR
              || event.getAction() == Action.RIGHT_CLICK_BLOCK)
          && playerData.getType().equalsIgnoreCase("spy")
          && playerData.getDisguised() != null) {
        playerData.setDisguised(null);
        plugin.getPlayerHandler().giveArmor(playerData.getName(), playerData.getTeam());
        TagAPI.refreshPlayer(plugin.getServer().getPlayer(playerData.getName()));
        return;
      }

      if (player.getItemInHand().getType() == Material.BOW
          && event.getAction() == Action.LEFT_CLICK_AIR
          && playerData.getType().equalsIgnoreCase("sniper")) {
        if (playerData.isScoped() == true) {
          setUnscoped(player, playerData);
        } else {
          setScoped(player, playerData);
        }
      }

      if (player.getItemInHand().getType() == Material.getMaterial(356)
          && (event.getAction() == Action.LEFT_CLICK_AIR
              || event.getAction() == Action.LEFT_CLICK_BLOCK)
          && playerData.getType().equalsIgnoreCase("demo")) {
        plugin.getLogger().info("demo fired");

        Location stickyLocation = player.getEyeLocation();
        stickyLocation.setY(stickyLocation.getY() + 0.1);

        Item sticky;
        if (playerData.getTeam().equals("red")) {
          sticky =
              player
                  .getWorld()
                  .dropItemNaturally(
                      stickyLocation,
                      new ItemStack(
                          Material.INK_SACK, 1, (short) 0, (byte) (15 - DyeColor.RED.getData())));
          sticky.setMetadata("redsticky", new FixedMetadataValue(plugin, true));
        } else {
          sticky =
              player
                  .getWorld()
                  .dropItemNaturally(
                      stickyLocation,
                      new ItemStack(
                          Material.INK_SACK, 1, (short) 0, (byte) (15 - DyeColor.BLUE.getData())));
          sticky.setMetadata("bluesticky", new FixedMetadataValue(plugin, true));
        }

        // stickyBomb.setData(dye);
        // Item sticky = player.getWorld().dropItem(stickyLocation, stickyBomb);

        sticky.setVelocity(player.getEyeLocation().getDirection());

        StickyDataClass stickyData = new StickyDataClass();
        stickyData.setOwner(playerData.getName());
        stickyData.setSticky(sticky);
        stickyData.setTeam(playerData.getTeam());
        plugin.getStickysFired().add(stickyData);
      }

      if (player.getItemInHand().getType() == Material.getMaterial(356)
          && (event.getAction() == Action.RIGHT_CLICK_AIR
              || event.getAction() == Action.RIGHT_CLICK_BLOCK)
          && playerData.getType().equalsIgnoreCase("demo")) {
        plugin.getLogger().info("demo triggered");
        event.setCancelled(true);
        for (int i = 0; i < plugin.getStickysFired().size(); i++) {
          StickyDataClass temp = plugin.getStickysFired().get(i);
          plugin.getLogger().info(i + " Owner/Team " + temp.getOwner() + "/" + temp.getTeam());
          if (temp.getOwner() == playerData.getName()) {
            plugin
                .getServer()
                .getWorld("world")
                .createExplosion(
                    temp.getSticky().getLocation().getX(),
                    temp.getSticky().getLocation().getY(),
                    temp.getSticky().getLocation().getZ(),
                    5,
                    false,
                    false);

            for (Entity nearby : temp.getSticky().getNearbyEntities(3, 3, 3)) {
              if (nearby instanceof Player) {
                Player nearbyPlayer = (Player) nearby;
                nearbyPlayer.damage(8, player);
              }
            }
            temp.getSticky().remove();
            plugin.getStickysFired().remove(i);
          }
        }
      }

    } else {
      return;
    }
  }
  public void track(List<EntityHuman> list) {
    this.b = false;
    if (!this.isMoving || this.tracker.d(this.q, this.r, this.s) > 16.0D) {
      this.q = this.tracker.locX;
      this.r = this.tracker.locY;
      this.s = this.tracker.locZ;
      this.isMoving = true;
      this.b = true;
      this.scanPlayers(list);
    }

    List list1 = this.tracker.bx();

    if (!list1.equals(this.w)) {
      this.w = list1;
      this.broadcast(new PacketPlayOutMount(this.tracker));
    }

    // PAIL : rename
    if (this.tracker
        instanceof
        EntityItemFrame /*&& this.a % 10 == 0*/) { // CraftBukkit - Moved below, should always enter
                                                   // this block
      EntityItemFrame entityitemframe = (EntityItemFrame) this.tracker;
      ItemStack itemstack = entityitemframe.getItem();

      if (this.a % 10 == 0
          && itemstack.getItem()
              instanceof
              ItemWorldMap) { // CraftBukkit - Moved this.a % 10 logic here so item frames do not
                              // enter the other blocks
        WorldMap worldmap = Items.FILLED_MAP.getSavedMap(itemstack, this.tracker.world);
        Iterator iterator = this.trackedPlayers.iterator(); // CraftBukkit

        while (iterator.hasNext()) {
          EntityHuman entityhuman = (EntityHuman) iterator.next();
          EntityPlayer entityplayer = (EntityPlayer) entityhuman;

          worldmap.a(entityplayer, itemstack);
          Packet packet =
              Items.FILLED_MAP.a(itemstack, this.tracker.world, (EntityHuman) entityplayer);

          if (packet != null) {
            entityplayer.playerConnection.sendPacket(packet);
          }
        }
      }

      this.d();
    }

    if (this.a % this.g == 0 || this.tracker.impulse || this.tracker.getDataWatcher().a()) {
      int i;

      if (this.tracker.isPassenger()) {
        i = MathHelper.d(this.tracker.yaw * 256.0F / 360.0F);
        int j = MathHelper.d(this.tracker.pitch * 256.0F / 360.0F);
        boolean flag = Math.abs(i - this.yRot) >= 1 || Math.abs(j - this.xRot) >= 1;

        if (flag) {
          this.broadcast(
              new PacketPlayOutEntity.PacketPlayOutEntityLook(
                  this.tracker.getId(), (byte) i, (byte) j, this.tracker.onGround));
          this.yRot = i;
          this.xRot = j;
        }

        this.xLoc = EntityTracker.a(this.tracker.locX);
        this.yLoc = EntityTracker.a(this.tracker.locY);
        this.zLoc = EntityTracker.a(this.tracker.locZ);
        this.d();
        this.x = true;
      } else {
        ++this.v;
        long k = EntityTracker.a(this.tracker.locX);
        long l = EntityTracker.a(this.tracker.locY);
        long i1 = EntityTracker.a(this.tracker.locZ);
        int j1 = MathHelper.d(this.tracker.yaw * 256.0F / 360.0F);
        int k1 = MathHelper.d(this.tracker.pitch * 256.0F / 360.0F);
        long l1 = k - this.xLoc;
        long i2 = l - this.yLoc;
        long j2 = i1 - this.zLoc;
        Object object = null;
        boolean flag1 = l1 * l1 + i2 * i2 + j2 * j2 >= 128L || this.a % 60 == 0;
        boolean flag2 = Math.abs(j1 - this.yRot) >= 1 || Math.abs(k1 - this.xRot) >= 1;

        // CraftBukkit start - Code moved from below
        if (flag1) {
          this.xLoc = k;
          this.yLoc = l;
          this.zLoc = i1;
        }

        if (flag2) {
          this.yRot = j1;
          this.xRot = k1;
        }
        // CraftBukkit end

        if (this.a > 0 || this.tracker instanceof EntityArrow) {
          if (l1 >= -32768L
              && l1 < 32768L
              && i2 >= -32768L
              && i2 < 32768L
              && j2 >= -32768L
              && j2 < 32768L
              && this.v <= 400
              && !this.x
              && this.y == this.tracker.onGround) {
            if ((!flag1 || !flag2) && !(this.tracker instanceof EntityArrow)) {
              if (flag1) {
                object =
                    new PacketPlayOutEntity.PacketPlayOutRelEntityMove(
                        this.tracker.getId(), l1, i2, j2, this.tracker.onGround);
              } else if (flag2) {
                object =
                    new PacketPlayOutEntity.PacketPlayOutEntityLook(
                        this.tracker.getId(), (byte) j1, (byte) k1, this.tracker.onGround);
              }
            } else {
              object =
                  new PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook(
                      this.tracker.getId(),
                      l1,
                      i2,
                      j2,
                      (byte) j1,
                      (byte) k1,
                      this.tracker.onGround);
            }
          } else {
            this.y = this.tracker.onGround;
            this.v = 0;
            // CraftBukkit start - Refresh list of who can see a player before sending teleport
            // packet
            if (this.tracker instanceof EntityPlayer) {
              this.scanPlayers(new java.util.ArrayList(this.trackedPlayers));
            }
            // CraftBukkit end
            this.c();
            object = new PacketPlayOutEntityTeleport(this.tracker);
          }
        }

        boolean flag3 = this.u;

        if (this.tracker instanceof EntityLiving && ((EntityLiving) this.tracker).cH()) {
          flag3 = true;
        }

        if (flag3 && this.a > 0) {
          double d0 = this.tracker.motX - this.n;
          double d1 = this.tracker.motY - this.o;
          double d2 = this.tracker.motZ - this.p;
          double d3 = 0.02D;
          double d4 = d0 * d0 + d1 * d1 + d2 * d2;

          if (d4 > 4.0E-4D
              || d4 > 0.0D
                  && this.tracker.motX == 0.0D
                  && this.tracker.motY == 0.0D
                  && this.tracker.motZ == 0.0D) {
            this.n = this.tracker.motX;
            this.o = this.tracker.motY;
            this.p = this.tracker.motZ;
            this.broadcast(
                new PacketPlayOutEntityVelocity(this.tracker.getId(), this.n, this.o, this.p));
          }
        }

        if (object != null) {
          this.broadcast((Packet) object);
        }

        this.d();
        /* CraftBukkit start - Code moved up
        if (flag1) {
            this.xLoc = k;
            this.yLoc = l;
            this.zLoc = i1;
        }

        if (flag2) {
            this.yRot = j1;
            this.xRot = k1;
        }
        // CraftBukkit end */

        this.x = false;
      }

      i = MathHelper.d(this.tracker.getHeadRotation() * 256.0F / 360.0F);
      if (Math.abs(i - this.headYaw) >= 1) {
        this.broadcast(new PacketPlayOutEntityHeadRotation(this.tracker, (byte) i));
        this.headYaw = i;
      }

      this.tracker.impulse = false;
    }

    ++this.a;
    if (this.tracker.velocityChanged) {
      // CraftBukkit start - Create PlayerVelocity event
      boolean cancelled = false;

      if (this.tracker instanceof EntityPlayer) {
        Player player = (Player) this.tracker.getBukkitEntity();
        org.bukkit.util.Vector velocity = player.getVelocity();

        PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone());
        this.tracker.world.getServer().getPluginManager().callEvent(event);

        if (event.isCancelled()) {
          cancelled = true;
        } else if (!velocity.equals(event.getVelocity())) {
          player.setVelocity(event.getVelocity());
        }
      }

      if (!cancelled) {
        this.broadcastIncludingSelf(new PacketPlayOutEntityVelocity(this.tracker));
      }
      // CraftBukkit end
      this.tracker.velocityChanged = false;
    }
  }
Exemplo n.º 17
0
 @Override
 public Vector getVelocity() {
   return caller.getVelocity();
 }
Exemplo n.º 18
0
  /**
   * The actual check. First find out if the event needs to be handled at all Second check if the
   * player moved too far horizontally Third check if the player moved too high vertically Fourth
   * treat any occured violations as configured
   *
   * @param event
   */
  public Location check(Player player, Location from, Location to, MovingData data) {

    updateVelocity(player.getVelocity(), data);

    Location newToLocation = null;

    final long startTime = System.nanoTime();

    /** *********** DECIDE WHICH CHECKS NEED TO BE RUN ************ */
    final boolean flyCheck =
        !allowFlying && !plugin.hasPermission(player, PermissionData.PERMISSION_FLYING, checkOPs);
    final boolean runCheck = true;

    /** *************** REFINE EVENT DATA FOR CHECKS ************** */
    if (flyCheck || runCheck) {

      // In both cases it will be interesting to know the type of underground the player
      // is in or goes to
      final int fromType =
          helper.isLocationOnGround(from.getWorld(), from.getX(), from.getY(), from.getZ(), false);
      final int toType =
          helper.isLocationOnGround(to.getWorld(), to.getX(), to.getY(), to.getZ(), false);

      final boolean fromOnGround = fromType != MovingEventHelper.NONSOLID;
      final boolean toOnGround = toType != MovingEventHelper.NONSOLID;

      // Distribute data to checks in the form needed by the checks

      /** ******************* EXECUTE THE CHECKS ******************* */
      double result = 0.0D;

      if (flyCheck) {
        result += Math.max(0D, flyingCheck.check(player, from, fromOnGround, to, toOnGround, data));
      }

      if (runCheck) {
        result +=
            Math.max(
                0D,
                runningCheck.check(
                    from,
                    to,
                    !allowFakeSneak && player.isSneaking(),
                    !allowFastSwim && (fromType & toType & MovingEventHelper.LIQUID) > 0,
                    data));
      }

      /** ******* HANDLE/COMBINE THE RESULTS OF THE CHECKS ********** */
      data.jumpPhase++;

      if (result <= 0) {
        if (fromOnGround) {
          data.setBackPoint = from;
          data.jumpPhase = 0;
        } else if (toOnGround) {
          data.jumpPhase = 0;
        }
      } else if (result > 0) {
        // Increment violation counter
        data.violationLevel += result;
        if (data.setBackPoint == null) data.setBackPoint = from;
      }

      if (result > 0 && data.violationLevel > 1) {

        setupSummaryTask(player, data);

        int level = limitCheck(data.violationLevel - 1);

        data.violationsInARow[level]++;

        newToLocation =
            action(player, from, to, actions[level], data.violationsInARow[level], data);
      }
    }

    // Slowly reduce the level with each event
    data.violationLevel *= 0.97;
    data.horizFreedom *= 0.97;

    statisticElapsedTimeNano += System.nanoTime() - startTime;
    statisticTotalEvents++;

    return newToLocation;
  }
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerMove(PlayerMoveEvent event) {
    final Location from = event.getFrom();
    final Location to = event.getTo();
    try {
      if (from.getWorld() == to.getWorld() && from.distanceSquared(to) < (0.0001 * 0.0001)) {
        // If player just rotated, but didn't move, don't process this event.
        return;
      }
    } catch (IllegalArgumentException ex) {
    }

    if (!TFM_AdminWorld.getInstance().validateMovement(event)) {
      return;
    }

    final Player player = event.getPlayer();
    final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);

    for (Entry<Player, Double> fuckoff : TotalFreedomMod.fuckoffEnabledFor.entrySet()) {
      Player fuckoffPlayer = fuckoff.getKey();

      if (fuckoffPlayer.equals(player) || !fuckoffPlayer.isOnline()) {
        continue;
      }

      double fuckoffRange = fuckoff.getValue();

      Location playerLocation = player.getLocation();
      Location fuckoffLocation = fuckoffPlayer.getLocation();

      double distanceSquared;
      try {
        distanceSquared = playerLocation.distanceSquared(fuckoffLocation);
      } catch (IllegalArgumentException ex) {
        continue;
      }

      if (distanceSquared < (fuckoffRange * fuckoffRange)) {
        event.setTo(
            fuckoffLocation
                .clone()
                .add(
                    playerLocation
                        .subtract(fuckoffLocation)
                        .toVector()
                        .normalize()
                        .multiply(fuckoffRange * 1.1)));
        break;
      }
    }

    // Freeze
    if (!TFM_AdminList.isSuperAdmin(player) && playerdata.isFrozen()) {
      TFM_Util.setFlying(player, true);
      event.setTo(playerdata.getFreezeLocation());
    }

    if (playerdata.isCaged()) {
      Location targetPos = player.getLocation().add(0, 1, 0);

      boolean outOfCage;
      if (!targetPos.getWorld().equals(playerdata.getCagePos().getWorld())) {
        outOfCage = true;
      } else {
        outOfCage = targetPos.distanceSquared(playerdata.getCagePos()) > (2.5 * 2.5);
      }

      if (outOfCage) {
        playerdata.setCaged(
            true,
            targetPos,
            playerdata.getCageMaterial(TFM_PlayerData.CageLayer.OUTER),
            playerdata.getCageMaterial(TFM_PlayerData.CageLayer.INNER));
        playerdata.regenerateHistory();
        playerdata.clearHistory();
        TFM_Util.buildHistory(targetPos, 2, playerdata);
        TFM_Util.generateHollowCube(
            targetPos, 2, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.OUTER));
        TFM_Util.generateCube(
            targetPos, 1, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.INNER));
      }
    }

    if (playerdata.isOrbiting()) {
      if (player.getVelocity().length() < playerdata.orbitStrength() * (2.0 / 3.0)) {
        player.setVelocity(new Vector(0, playerdata.orbitStrength(), 0));
      }
    }

    if (TFM_Jumppads.getMode().isOn()) {
      TFM_Jumppads.PlayerMoveEvent(event);
    }

    if (!(TFM_ConfigEntry.LANDMINES_ENABLED.getBoolean()
        && TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())) {
      return;
    }

    final Iterator<Command_landmine.TFM_LandmineData> landmines =
        Command_landmine.TFM_LandmineData.landmines.iterator();
    while (landmines.hasNext()) {
      final Command_landmine.TFM_LandmineData landmine = landmines.next();

      final Location location = landmine.location;
      if (location.getBlock().getType() != Material.TNT) {
        landmines.remove();
        continue;
      }

      if (landmine.player.equals(player)) {
        break;
      }

      if (!player.getWorld().equals(location.getWorld())) {
        continue;
      }

      if (!(player.getLocation().distanceSquared(location)
          <= (landmine.radius * landmine.radius))) {
        break;
      }

      landmine.location.getBlock().setType(Material.AIR);

      final TNTPrimed tnt1 = location.getWorld().spawn(location, TNTPrimed.class);
      tnt1.setFuseTicks(40);
      tnt1.setPassenger(player);
      tnt1.setVelocity(new Vector(0.0, 2.0, 0.0));

      final TNTPrimed tnt2 = location.getWorld().spawn(player.getLocation(), TNTPrimed.class);
      tnt2.setFuseTicks(1);

      player.setGameMode(GameMode.SURVIVAL);
      landmines.remove();
    }
  }
Exemplo n.º 20
0
  @Override
  protected void onPlayerMove(PlayerMoveEvent evt, Player P) {
    // TODO Auto-generated method stub
    super.onPlayerMove(evt, P);
    Player ply = evt.getPlayer();
    if (isSpectator(ply)) return;
    if (JocIniciat) {
      Player plyr = evt.getPlayer();

      Location to = evt.getTo();
      Location from = evt.getFrom();

      int equip = obtenirEquip(ply).getId() + 1;
      if (ply.getLocation().getY() < 102) {
        ply.setFireTicks(5000);
      }
      if (ply.getLocation().getY() < 60) {
        ply.damage(10000);
      }

      // Torres escuts
      int e = 1;
      while (e <= 2) {
        int i = 0;
        while (i <= 1) {
          Cuboid cub =
              pMapaActual()
                  .ObtenirCuboid("RegT" + Integer.toString(e) + Integer.toString(i), getWorld());
          Location center = cub.getCenter();
          if (cub.contains(to.getBlock())) {
            if (e == equip) {
              Vector vec = Utils.CrearVector(center, from).normalize().add(new Vector(0, 1, 0));
              getWorld().playSound(to, Sound.IRONGOLEM_HIT, 1F, 2.2F);
              getWorld().playEffect(to, Effect.MOBSPAWNER_FLAMES, 3);
              getWorld()
                  .playEffect(to.clone().add(new Vector(0, 1, 0)), Effect.MOBSPAWNER_FLAMES, 3);
              if (cub.contains(from.getBlock()) && plyr.getVelocity().length() >= 1) {
                plyr.teleport(from.add(vec));
                // Bukkit.broadcastMessage("ha entrat");
              } else {
                plyr.setVelocity(vec);
              }
              // evt.setCancelled(true);

            }
          }
          i = i + 1;
        }
        e = e + 1;
      }
      // SECURE NO-FALL
      //
      boolean isNoFallActive = false;

      ItemStack itemInHand = ply.getItemInHand();
      if (itemInHand.hasItemMeta()) {
        ItemMeta itemMeta = itemInHand.getItemMeta();
        if (itemMeta.hasDisplayName()) {
          if (itemMeta.getDisplayName().equals(getBridgeToolName())) {
            isNoFallActive = true;
          }
        }
      }

      if (isNoFallActive) {
        Vector v = Utils.CrearVector(evt.getFrom(), evt.getTo());
        v.multiply(1.45D);
        v.setY(0);
        Block bDown = evt.getTo().add(v).getBlock().getRelative(BlockFace.DOWN);
        if (bDown.isEmpty() && bDown.getRelative(BlockFace.DOWN).isEmpty()) {
          ItemStack placeableItemStack = getPlaceableItemStack(ply);
          if (placeableItemStack != null) {
            bDown.setType(placeableItemStack.getType());
            bDown.setData(placeableItemStack.getData().getData());
            ItemStack sampleIt = new ItemStack(placeableItemStack);
            sampleIt.setAmount(1);
            ply.getInventory().removeItem(sampleIt);
            itemInHand.setDurability((short) (itemInHand.getDurability() + 3));
          }
        }
      }
    }
  }