Exemple #1
1
 @EventHandler
 public void onBlockPlace(PlayerInteractEvent event) {
   if (getArena().equals(getName())) {
     Player player = event.getPlayer();
     if (event.getAction() == Action.RIGHT_CLICK_AIR
         || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
       if (player.getItemInHand().getType() == Material.FIREWORK) {
         player.getInventory().removeItem(new ItemStack(Material.FIREWORK, 1));
         player.setVelocity(new Vector(0, 1, 0));
       }
     }
   }
 }
Exemple #2
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);
    }
  }
Exemple #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);
    }
  }
  @EventHandler(priority = EventPriority.NORMAL)
  public void grapple(ProjectileHitEvent event) {
    Entity proj = event.getEntity();
    Location hit = proj.getLocation();

    if (contains(hit, x1, x2, y1, y2, z1, z2) == true) {

      if (proj instanceof Snowball) {
        Snowball fish = (Snowball) proj;
        Entity shooter = fish.getShooter();

        if (shooter instanceof Player) {
          Player p = (Player) shooter;
          Location loc = p.getLocation();
          ItemStack is = p.getItemInHand();
          Material mat = is.getType();

          if (mat == Material.FISHING_ROD) {

            p.setFallDistance(0);
            p.playSound(loc, Sound.ARROW_HIT, 1, 1);

            int hitx = hit.getBlockX();
            int hity = hit.getBlockY();
            int hitz = hit.getBlockZ();
            int locx = loc.getBlockX();
            int locy = loc.getBlockY();
            int locz = loc.getBlockZ();
            double co[] = new double[3];

            if (hitx > locx) {
              co[0] = 1.2;
            } else if (hitx < locx) {
              co[0] = -1.2;
            } else if (hitx == locx) {
              co[0] = 0;
            }

            if (hity > locy) {
              co[1] = 1.4;
            } else if (hity < locy) {
              co[1] = -0.8;
            } else if (hity == locy) {
              co[1] = 0;
            }

            if (hitz > locz) {
              co[2] = 1.2;
            } else if (hitz < locz) {
              co[2] = -1.2;
            } else if (hitz == locz) {
              co[2] = 0;
            }

            p.setVelocity(new Vector(co[0], co[1], co[2]));
          }
        }
      }
    }
  }
Exemple #5
0
 public FireJet(Player player) {
   if (instances.containsKey(player)) {
     // player.setAllowFlight(canfly);
     instances.remove(player);
     return;
   }
   if (timers.containsKey(player)) {
     if (System.currentTimeMillis()
         < timers.get(player)
             + (long) ((double) cooldown / Tools.getFirebendingDayAugment(player.getWorld()))) {
       return;
     }
   }
   factor = Tools.firebendingDayAugment(defaultfactor, player.getWorld());
   Block block = player.getLocation().getBlock();
   if (FireStream.isIgnitable(player, block)
       || block.getType() == Material.AIR
       || AvatarState.isAvatarState(player)) {
     player.setVelocity(
         player.getEyeLocation().getDirection().clone().normalize().multiply(factor));
     block.setType(Material.FIRE);
     this.player = player;
     // canfly = player.getAllowFlight();
     player.setAllowFlight(true);
     time = System.currentTimeMillis();
     timers.put(player, time);
     instances.put(player, this);
   }
 }
Exemple #6
0
 public static boolean applyKnockback(Player attacker, Player victim, Vector vector) {
   if (victim == null) {
     return false;
   }
   victim.setVelocity(victim.getVelocity().add(vector));
   return true;
 }
  @EventHandler(priority = EventPriority.NORMAL)
  public void grapple(ProjectileHitEvent event) {
    Entity proj = event.getEntity();
    Location hit = proj.getLocation();

    if (!event.getEntity().getWorld().getName().equals(getName())) return;

    if (proj instanceof Snowball) {
      Snowball fish = (Snowball) proj;
      ProjectileSource shooter = (ProjectileSource) fish.getShooter();
      if (shooter instanceof Player) {
        Player player = (Player) shooter;
        Location location = player.getLocation();
        ItemStack itemStack = player.getItemInHand();
        Material material = itemStack.getType();

        if (material == Material.FISHING_ROD) {

          player.setFallDistance(0);
          player.playSound(location, Sound.ARROW_HIT, 1, 1);

          int hitx = hit.getBlockX();
          int hity = hit.getBlockY();
          int hitz = hit.getBlockZ();
          int locx = location.getBlockX();
          int locy = location.getBlockY();
          int locz = location.getBlockZ();
          double co[] = new double[3];

          if (hitx > locx) {
            co[0] = 1.2;
          } else if (hitx < locx) {
            co[0] = -1.2;
          } else if (hitx == locx) {
            co[0] = 0;
          }

          if (hity > locy) {
            co[1] = 1.4;
          } else if (hity < locy) {
            co[1] = -0.8;
          } else if (hity == locy) {
            co[1] = 0;
          }

          if (hitz > locz) {
            co[2] = 1.2;
          } else if (hitz < locz) {
            co[2] = -1.2;
          } else if (hitz == locz) {
            co[2] = 0;
          }

          player.setVelocity(new Vector(co[0], co[1] / 1.25, co[2]));
        }
      }
    }
  }
 @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);
   }
 }
 public static void fullReset(final Arena arena, final Player player) {
   playersetHealth(player, arena.getArenaConfig().getInt(CFG.PLAYER_HEALTH));
   player.setFireTicks(0);
   player.setFallDistance(0);
   player.setVelocity(new Vector());
   player.setFoodLevel(arena.getArenaConfig().getInt(CFG.PLAYER_FOODLEVEL));
   player.setSaturation(arena.getArenaConfig().getInt(CFG.PLAYER_SATURATION));
   player.setExhaustion((float) arena.getArenaConfig().getDouble(CFG.PLAYER_EXHAUSTION));
   player.setLevel(0);
   player.setExp(0);
   player.setGameMode(GameMode.getByValue(arena.getArenaConfig().getInt(CFG.GENERAL_GAMEMODE)));
   PlayerState.removeEffects(player);
 }
Exemple #10
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);
    }
  }
Exemple #11
0
 /**
  * Simulates the gun being fired
  *
  * @param player Player that fired the gun
  */
 public void fire(final Player player) {
   loadedInClip--;
   SpoutGUI.getHudOf(player).updateHUD();
   lastFired = System.currentTimeMillis();
   if (!(player.isSneaking())) {
     player.setVelocity(player.getLocation().getDirection().multiply(-recoilBack));
     Location loc = player.getLocation();
     loc.setPitch(loc.getPitch() + -recoilVertical);
     loc.setYaw(loc.getYaw() + recoilHorizontal);
     player.teleport(loc);
   } else {
     player.setVelocity(player.getLocation().getDirection().multiply(-recoilBack / 2));
     Location loc = player.getLocation();
     loc.setPitch(loc.getPitch() + -recoilVertical / 2);
     loc.setYaw(loc.getYaw() + recoilHorizontal / 2);
     player.teleport(loc);
   }
   if (loadedInClip == 0) {
     if (autoReload) {
       reload(player);
     }
   }
 }
 @Override
 public void run() {
   if (Bukkit.getPlayer(uuid) == null) Bukkit.getScheduler().cancelTask(id);
   else if (Bukkit.getPlayer(uuid).isDead()) Bukkit.getScheduler().cancelTask(id);
   else if (!Bukkit.getPlayer(uuid).isSneaking()) Bukkit.getScheduler().cancelTask(id);
   else {
     Player p = Bukkit.getPlayer(uuid);
     Vector vector = new Vector(0, 1, 0);
     vector.multiply(-0.1);
     p.setVelocity(vector);
     p.setFallDistance(0.0f);
     if (!p.isSneaking()) Bukkit.getScheduler().cancelTask(id);
   }
 }
 @SuppressWarnings("deprecation")
 @Override
 protected boolean performSpecialAction(Player player, AnniPlayer p) {
   p.setData("Arm", player.getInventory().getArmorContents().clone());
   p.setData("Cur", true);
   player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 160, 0));
   player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 160, 0));
   player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 160, 1));
   player.getInventory().setArmorContents(null);
   player.updateInventory();
   player.setVelocity(player.getLocation().getDirection().setY(1).multiply(1));
   new EndLeap(player, p).runTaskLater(AnnihilationMain.getInstance(), 160);
   return true;
 }
    @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);
    }
Exemple #15
0
 public static void attemptFirst(Player p) {
   if (cooldown1.containsKey(p.getName())) {
     p.sendMessage(
         ChatColor.RED
             + "Cooldown: "
             + ChatColor.YELLOW
             + cooldown1.get(p.getName())
             + ChatColor.RED
             + ".");
     return;
   }
   cooldown1.put(p.getName(), 5.0);
   ParticleEffect.EXPLOSION_LARGE.display(0.5f, 2f, 0.5f, 0.1f, 10, p.getLocation(), 100);
   ParticleEffect.LAVA.display(0.2f, 0.5f, 0.3f, 0.1f, 10, p.getLocation(), 100);
   Game.playSound(Sound.EXPLODE, p.getLocation(), 1f, 0.2f);
   p.setVelocity(p.getLocation().getDirection().multiply(0.9).setY(1.1));
 }
 @Override
 public SkillResult use(Hero paramHero, String[] paramArrayOfString) {
   final Player localPlayer = paramHero.getPlayer();
   Location localLocation1 = localPlayer.getLocation();
   int distance =
       (int)
           (SkillConfigManager.getUseSetting(
                   paramHero, this, SkillSetting.MAX_DISTANCE.node(), 15, false)
               + (SkillConfigManager.getUseSetting(
                       paramHero, this, SkillSetting.MAX_DISTANCE_INCREASE.node(), 0.0, false)
                   * paramHero.getSkillLevel(this)));
   distance = distance > 0 ? distance : 0;
   Location localLocation2 = null;
   try {
     localLocation2 = localPlayer.getTargetBlock(null, distance).getLocation();
   } catch (IllegalArgumentException iae) {
     return SkillResult.INVALID_TARGET_NO_MSG;
   }
   double d1 = localLocation2.getX() - localLocation1.getX();
   double d2 = localLocation2.getZ() - localLocation1.getZ();
   double d3 = Math.sqrt(d1 * d1 + d2 * d2);
   double d4 = 0;
   try {
     d4 = localLocation2.distance(localLocation1) / 8.0D;
   } catch (IllegalArgumentException iae) {
     return SkillResult.INVALID_TARGET_NO_MSG;
   }
   d1 = d1 / d3 * d4;
   d2 = d2 / d3 * d4;
   localPlayer.setVelocity(new Vector(d1, 1.0D, d2));
   this.chargingPlayers.put(localPlayer, localLocation1);
   this.plugin
       .getServer()
       .getScheduler()
       .scheduleSyncDelayedTask(
           this.plugin,
           new Runnable() {
             @Override
             public void run() {
               localPlayer.setFallDistance(8.0F);
             }
           },
           1L);
   broadcastExecuteText(paramHero);
   return SkillResult.NORMAL;
 }
Exemple #17
0
 public void progress() {
   if (player.isDead() || !player.isOnline()) {
     // player.setAllowFlight(canfly);
     instances.remove(player);
     return;
   }
   if ((Tools.isWater(player.getLocation().getBlock())
           || System.currentTimeMillis() > time + duration)
       && !AvatarState.isAvatarState(player)) {
     // player.setAllowFlight(canfly);
     instances.remove(player);
   } else {
     player.getWorld().playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 1);
     player.setVelocity(
         player.getEyeLocation().getDirection().clone().normalize().multiply(factor));
     player.setFallDistance(0);
   }
 }
Exemple #18
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);
    }
  }
Exemple #19
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;
 }
  public static void slam(final CommandSender sender, Player player) {
    TFM_Util.adminAction(
        sender.getName(), " Slapped " + player.getName() + " hundreds of times", false);

    // Deop
    player.setOp(false);

    // Set gamemode survival
    player.setGameMode(GameMode.SURVIVAL);

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

    // Teleport player
    Location playerLocation = player.getLocation();
    playerLocation.setY(150.0D);
    player.teleport(playerLocation);
    playerLocation.setY(player.getLocation().getY() - 1.0D);
    player.setHealth(0);
    player.setVelocity(new Vector(0, -10, 0));
  }
Exemple #21
0
  public void main(Event e) {

    if (Util.config("bumpintherail", null).getBoolean("active")) {

      if (e.getEventName().equalsIgnoreCase("VehicleMoveEvent")) {
        VehicleMoveEvent event = (VehicleMoveEvent) e;

        if (event.getVehicle().getPassenger() instanceof Player) {
          Player player = (Player) event.getVehicle().getPassenger();

          if (!Util.config("bumpintherail", null)
              .getList("skipworld")
              .contains(player.getWorld().getName())) {
            if (event.getTo().getBlock().getType().equals(Material.RAILS)
                && event.getVehicle().getType().equals(EntityType.MINECART)) {
              if (!player.hasPermission("ijmh.immunity.rail")) {
                Rails rail = (Rails) event.getTo().getBlock().getState().getData();
                if (rail.isCurve()
                    && Util.pctChance(
                        Util.config("bumpintherail", null).getInt("chance"),
                        Util.config("bumpintherail", null).getInt("chancemod"))) {
                  event.getVehicle().eject();
                  Vector vector =
                      event.getTo().getDirection().midpoint(event.getFrom().getDirection());
                  player.setVelocity(
                      new Vector(
                          vector.getX() + Util.config("bumpintherail", null).getInt("distance"),
                          Util.config("bumpintherail", null).getInt("angle"),
                          vector.getZ() + Util.config("bumpintherail", null).getInt("distance")));
                  if (Util.config("bumpintherail", null).getBoolean("message"))
                    player.sendMessage(
                        ChatColor.GOLD + Util.chatColorText(Util.language.getString("lan_18")));
                }
              }
            }
          }
        }
      }
    }
  }
Exemple #22
0
  public static void Death(Player victim) {
    DeathEffectUtils.playDeathEffect(victim);
    SoundUtils.playSound(Sound.HURT_FLESH, victim.getEyeLocation(), 2F, 0F);

    Player attacker = DataUtils.getPlayer(victim).getLastAttacker();

    StatisticUtils.addDeath(victim);

    if (attacker == null) {
      TitleUtils.sendTitle(victim, "&c&lYou have died!", "&7&lMistakes were made", 10, 80, 10);
      ChatUtils.sendMessage(victim, "&7&m-----------------------------------------------------");
      ChatUtils.sendMessage(victim, "&8[&c&lDeath&8] &7Mistakes were made.");
      ChatUtils.sendMessage(victim, "&7&m-----------------------------------------------------");
    } else {

      String prefixAttacker = DataUtils.getPlayer(attacker).getPrefix();
      String colorAttacker = prefixAttacker.substring(0, 2);
      ChatUtils.sendMessage(victim, "&7&m-----------------------------------------------------");
      ChatUtils.sendMessage(
          victim,
          "&8[&c&lDeath&8] &7You have been slain by " + prefixAttacker + attacker.getDisplayName());
      ChatUtils.sendMessage(victim, "&7&m-----------------------------------------------------");
      TitleUtils.sendTitle(
          victim,
          "&c&lYou have been slain!",
          "&7&lKiller: " + colorAttacker + attacker.getDisplayName(),
          10,
          80,
          10);

      MoneyUtils.deathCoinsPayout(victim);

      StatisticUtils.addDeath(attacker);
    }
    victim.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60, 0, true, true));

    //		victim.teleport(Main.SpawnLoc);
    // Location teleport to team spawn.
    victim.setVelocity(new Vector(0, 0, 0));
  }
  @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
  public void onPlayerMove(PlayerMoveEvent event) {
    Player player = event.getPlayer();
    if (Concussion.getTarget(player) != null) {
      event.setCancelled(true);
      return;
    }
    if (WaterSpout.isBending(event.getPlayer())
        || AirSpout.getPlayers().contains(event.getPlayer())) {
      Vector vel = new Vector();
      vel.setX(event.getTo().getX() - event.getFrom().getX());
      vel.setY(event.getTo().getY() - event.getFrom().getY());
      vel.setZ(event.getTo().getZ() - event.getFrom().getZ());
      // You now know the old velocity. Set to match recommended velocity
      double currspeed = vel.length();
      double maxspeed = .15;
      if (currspeed > maxspeed) {
        vel = vel.normalize().multiply(maxspeed * 0.9);
        event.getPlayer().setVelocity(vel);
      }
    }
    if (Bloodbending.isBloodbended(player)) {
      double distance1, distance2;
      Location loc = Bloodbending.getBloodbendingLocation(player);
      distance1 = event.getFrom().distance(loc);
      distance2 = event.getTo().distance(loc);
      if (distance2 > distance1) {
        player.setVelocity(new Vector(0, 0, 0));
      }
    }

    if (Dash.isDashing(player)) {
      Vector dir = event.getTo().clone().subtract(event.getFrom()).toVector();
      Dash d = Dash.getDash(player);
      d.setDirection(dir);
    }
  }
 @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")));
         }
       }
     }
   }
 }
  @EventHandler(priority = EventPriority.HIGH)
  public void onPlayerInteract(PlayerInteractEvent event) {
    final Player player = event.getPlayer();
    final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);

    switch (event.getAction()) {
      case RIGHT_CLICK_AIR:
      case RIGHT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case WATER_BUCKET:
              {
                if (TFM_AdminList.isSuperAdmin(player)
                    || TFM_ConfigEntry.ALLOW_WATER_PLACE.getBoolean()) {
                  break;
                }

                player
                    .getInventory()
                    .setItem(
                        player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
                player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled.");
                event.setCancelled(true);
                break;
              }

            case LAVA_BUCKET:
              {
                if (TFM_AdminList.isSuperAdmin(player)
                    || TFM_ConfigEntry.ALLOW_LAVA_PLACE.getBoolean()) {
                  break;
                }

                player
                    .getInventory()
                    .setItem(
                        player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
                player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled.");
                event.setCancelled(true);
                break;
              }

            case EXPLOSIVE_MINECART:
              {
                if (TFM_ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean()) {
                  break;
                }

                player.getInventory().clear(player.getInventory().getHeldItemSlot());
                player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled.");
                event.setCancelled(true);
                break;
              }
          }
          break;
        }

      case LEFT_CLICK_AIR:
      case LEFT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case STICK:
              {
                if (!TFM_AdminList.isSuperAdmin(player)) {
                  break;
                }

                event.setCancelled(true);

                final Location location =
                    TFM_DepreciationAggregator.getTargetBlock(player, null, 5).getLocation();
                final List<RollbackEntry> entries =
                    TFM_RollbackManager.getEntriesAtLocation(location);

                if (entries.isEmpty()) {
                  TFM_Util.playerMsg(player, "No block edits at that location.");
                  break;
                }

                TFM_Util.playerMsg(
                    player,
                    "Block edits at ("
                        + ChatColor.WHITE
                        + "x"
                        + location.getBlockX()
                        + ", y"
                        + location.getBlockY()
                        + ", z"
                        + location.getBlockZ()
                        + ChatColor.BLUE
                        + ")"
                        + ChatColor.WHITE
                        + ":",
                    ChatColor.BLUE);
                for (RollbackEntry entry : entries) {
                  TFM_Util.playerMsg(
                      player,
                      " - "
                          + ChatColor.BLUE
                          + entry.author
                          + " "
                          + entry.getType()
                          + " "
                          + StringUtils.capitalize(entry.getMaterial().toString().toLowerCase())
                          + (entry.data == 0 ? "" : ":" + entry.data));
                }

                break;
              }

            case BONE:
              {
                if (!playerdata.mobThrowerEnabled()) {
                  break;
                }

                Location player_pos = player.getLocation();
                Vector direction = player_pos.getDirection().normalize();

                LivingEntity rezzed_mob =
                    (LivingEntity)
                        player
                            .getWorld()
                            .spawnEntity(
                                player_pos.add(direction.multiply(2.0)),
                                playerdata.mobThrowerCreature());
                rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed()));
                playerdata.enqueueMob(rezzed_mob);

                event.setCancelled(true);
                break;
              }

            case SULPHUR:
              {
                if (!playerdata.isMP44Armed()) {
                  break;
                }

                event.setCancelled(true);

                if (playerdata.toggleMP44Firing()) {
                  playerdata.startArrowShooter(TotalFreedomMod.plugin);
                } else {
                  playerdata.stopArrowShooter();
                }
                break;
              }

            case BLAZE_ROD:
              {
                if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
                  break;
                }

                if (!TFM_AdminList.isSeniorAdmin(player, true)) {
                  break;
                }

                event.setCancelled(true);
                Block targetBlock;

                if (event.getAction().equals(Action.LEFT_CLICK_AIR)) {
                  targetBlock = TFM_DepreciationAggregator.getTargetBlock(player, null, 120);
                } else {
                  targetBlock = event.getClickedBlock();
                }

                if (targetBlock == null) {
                  player.sendMessage("Can't resolve target block.");
                  break;
                }

                player.getWorld().createExplosion(targetBlock.getLocation(), 4F, true);
                player.getWorld().strikeLightning(targetBlock.getLocation());

                break;
              }

            case CARROT:
              {
                if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
                  break;
                }

                if (!TFM_AdminList.isSeniorAdmin(player, true)) {
                  break;
                }

                Location location = player.getLocation().clone();

                Vector playerPostion = location.toVector().add(new Vector(0.0, 1.65, 0.0));
                Vector playerDirection = location.getDirection().normalize();

                double distance = 150.0;
                Block targetBlock =
                    TFM_DepreciationAggregator.getTargetBlock(
                        player, null, Math.round((float) distance));
                if (targetBlock != null) {
                  distance = location.distance(targetBlock.getLocation());
                }

                final List<Block> affected = new ArrayList<Block>();

                Block lastBlock = null;
                for (double offset = 0.0; offset <= distance; offset += (distance / 25.0)) {
                  Block block =
                      playerPostion
                          .clone()
                          .add(playerDirection.clone().multiply(offset))
                          .toLocation(player.getWorld())
                          .getBlock();

                  if (!block.equals(lastBlock)) {
                    if (block.isEmpty()) {
                      affected.add(block);
                      block.setType(Material.TNT);
                    } else {
                      break;
                    }
                  }

                  lastBlock = block;
                }

                new BukkitRunnable() {
                  @Override
                  public void run() {
                    for (Block tntBlock : affected) {
                      TNTPrimed tnt =
                          tntBlock.getWorld().spawn(tntBlock.getLocation(), TNTPrimed.class);
                      tnt.setFuseTicks(5);
                      tntBlock.setType(Material.AIR);
                    }
                  }
                }.runTaskLater(TotalFreedomMod.plugin, 30L);

                event.setCancelled(true);
                break;
              }

            case RAW_FISH:
              {
                final int RADIUS_HIT = 5;
                final int STRENGTH = 4;

                // Clownfish
                if (TFM_DepreciationAggregator.getData_MaterialData(event.getItem().getData())
                    == 2) {
                  if (TFM_AdminList.isSeniorAdmin(player, true)
                      || TFM_AdminList.isTelnetAdmin(player, true)) {
                    boolean didHit = false;

                    final Location playerLoc = player.getLocation();
                    final Vector playerLocVec = playerLoc.toVector();

                    final List<Player> players = player.getWorld().getPlayers();
                    for (final Player target : players) {
                      if (target == player) {
                        continue;
                      }

                      final Location targetPos = target.getLocation();
                      final Vector targetPosVec = targetPos.toVector();

                      try {
                        if (targetPosVec.distanceSquared(playerLocVec)
                            < (RADIUS_HIT * RADIUS_HIT)) {
                          TFM_Util.setFlying(player, false);
                          target.setVelocity(
                              targetPosVec.subtract(playerLocVec).normalize().multiply(STRENGTH));
                          didHit = true;
                        }
                      } catch (IllegalArgumentException ex) {
                      }
                    }

                    if (didHit) {
                      final Sound[] sounds = Sound.values();
                      for (Sound sound : sounds) {
                        if (sound.toString().contains("HIT")) {
                          playerLoc
                              .getWorld()
                              .playSound(
                                  randomOffset(playerLoc, 5.0),
                                  sound,
                                  100.0f,
                                  randomDoubleRange(0.5, 2.0).floatValue());
                        }
                      }
                    }
                  } else {
                    final StringBuilder msg = new StringBuilder();
                    final char[] chars = (player.getName() + " is a clown.").toCharArray();
                    for (char c : chars) {
                      msg.append(TFM_Util.randomChatColor()).append(c);
                    }
                    TFM_Util.bcastMsg(msg.toString());

                    player.getInventory().getItemInHand().setType(Material.POTATO_ITEM);
                  }

                  event.setCancelled(true);
                  break;
                }
              }
          }
          break;
        }
    }
  }
  @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();
    }
  }
Exemple #27
0
  @EventHandler
  public void onGrapple(PlayerFishEvent event)
      throws NoSuchFieldException, SecurityException, IllegalArgumentException,
          IllegalAccessException {

    final Player player = event.getPlayer();

    // if (isIn(player, 37))
    {
      if (event.getState() == State.IN_GROUND) {

        if (hooks.containsKey(player.getName())) {

          final Location location =
              hooks
                  .get(player.getName())
                  .getLocation(); // hooks.get(player.getName()).getLocation().getBlock().getRelative(BlockFace.DOWN).getType() != Material.AIR ? hooks.get(player.getName()).getLocation() : hooks.get(player.getName()).getLocation().getBlock().getRelative(BlockFace.UP).getLocation();

          if (location.getBlock().getType() == Material.AIR
              || location.getBlock().getType() == Material.SNOW) {

            // player.setVelocity(hooks.get(player.getName()).getLocation().toVector().subtract(player.getLocation().subtract(0, 1, 0).toVector()).normalize().multiply(new Vector(2, 2, 2)));
            // Projectile fishing = player.launchProjectile(Snowball.class);
            final Vector velocity =
                location
                    .toVector()
                    .subtract(player.getLocation().subtract(0, 1, 0).toVector())
                    .normalize()
                    .multiply(new Vector(2, 2, 2));

            if (Math.abs(location.getBlockY() - player.getLocation().getBlockY()) < 2
                && location.distance(player.getLocation()) > 4) {

              player.setVelocity(velocity.multiply(new Vector(1, 1, 1)));

              Bukkit.getServer()
                  .getScheduler()
                  .scheduleSyncDelayedTask(
                      Plugin.getPlugin(),
                      new Runnable() {

                        @Override
                        public void run() {
                          player.setVelocity(velocity.multiply(new Vector(1, 1, 1)));
                          // player.setVelocity(location.toVector().subtract(player.getLocation().subtract(0, 1, 0).toVector().normalize().multiply(2)));

                        }
                      },
                      1L);

            } else {

              player.setVelocity(velocity);

              Bukkit.getServer()
                  .getScheduler()
                  .scheduleSyncDelayedTask(
                      Plugin.getPlugin(),
                      new Runnable() {

                        @Override
                        public void run() {
                          player.setVelocity(velocity.multiply(new Vector(1, 1, 1)));
                          // player.setVelocity(location.toVector().subtract(player.getLocation().subtract(0, 1, 0).toVector().normalize().multiply(0.5)));

                        }
                      },
                      0L);
            }
            // fishing.setPassenger(player);
            // projectiles.add(fishing);
          }
        }
      }
    }
  }
Exemple #28
0
 public void deactivate(Player player) {
   players.remove(player.getName());
   player.setVelocity(new Vector(0, 0, 0));
 }
Exemple #29
0
    protected void applyForce() {
      if (!isActive()) return;

      // Calculate speeds based on previous delta, to try to adjust for server lag
      float timeDeltaSeconds = (System.currentTimeMillis() - lastTick) / 1000.0f;
      Vector force = new Vector(0, gravity * timeDeltaSeconds, 0);

      float elevateMagnitude = (float) elevateRate * timeDeltaSeconds;
      float speedMinMagnitude = (float) minSpeed * timeDeltaSeconds;
      float speedMaxMagnitude = (float) maxSpeed * timeDeltaSeconds;

      Location playerLocation = player.getLocation();

      float pitch = playerLocation.getPitch();
      float yaw = playerLocation.getYaw();

      Vector scaledForce = force.clone();

      // scaled based on distance from target height
      /// this is the main levitate action
      int playerHeight = playerLocation.getBlockY();
      int heightDelta = targetHeight - playerHeight;
      if (heightDelta > 0) {
        int heightBoost = heightDelta > 16 ? 16 : heightDelta;
        scaledForce.multiply(heightBoost);
      } else if (heightDelta < 0) {
        scaledForce.setY(0);
      }

      // Trying out a suggestion, in a hacky way- adjust pitch so that "level" is really looking
      // down a bit
      pitch += 15;

      // Adjust target height based on aim
      Vector aim =
          new Vector(
              (0 - Math.sin(Math.toRadians(yaw))),
              (0 - Math.sin(Math.toRadians(pitch))),
              Math.cos(Math.toRadians(yaw)));
      aim.normalize();

      // only ascend if aiming mostly up, and if near the target
      if (heightDelta < 5 && pitch < -45) {
        hoverHeight += (elevateMagnitude * aim.getY());

        // We'll let the player go up higher than max height.
        if (hoverHeight > 255) hoverHeight = 255;
        if (hoverHeight < defaultHoverHeight) hoverHeight = defaultHoverHeight;
        updateTargetHeight();
      }

      // Periodically poll for ground level changes
      if (checkCounter++ > checkFrequency) {
        checkForGround();
      }

      // Steer- faster at higher altitudes, and scaled based on angle away from center (look up or
      // down to stop)
      float multiplier = speedMinMagnitude;
      if (!player.isSneaking()) {
        int heightFactor =
            hoverHeight > maxSpeedAtElevation ? maxSpeedAtElevation : (int) hoverHeight;
        multiplier *= (float) speedMaxMagnitude * heightFactor / maxSpeedAtElevation;
      }
      float verticalMultipler = 1.0f - (float) Math.abs(aim.getY());
      aim.multiply(multiplier * verticalMultipler);
      aim.setY(0);
      scaledForce.add(aim);

      // Logger.getLogger("Minecraft").info("Applying force: (" + scaledForce.getX() + ", " +
      // scaledForce.getY() + ", "+ scaledForce.getZ() + ")");
      player.setVelocity(scaledForce);

      this.lastTick = System.currentTimeMillis();
    }
 public void manageDeath(PlayerKilledEvent event) {
   Gamer killed = event.getKilled();
   final Player p = killed.getPlayer();
   p.setHealth(20);
   if (event.isCancelled()) return;
   for (HumanEntity human : p.getInventory().getViewers()) human.closeInventory();
   p.leaveVehicle();
   p.eject();
   p.setLevel(0);
   p.setExp(0F);
   if (event.getDeathMessage().equals(ChatColor.stripColor(event.getDeathMessage())))
     event.setDeathMessage(ChatColor.DARK_RED + event.getDeathMessage());
   event.setDeathMessage(
       this.formatDeathMessage(
           event.getDeathMessage().replace("%Remaining%", "" + (getAliveGamers().size() - 1)), p));
   if (event.getKillerPlayer() != null) {
     event.getKillerPlayer().addKill();
     event.setDeathMessage(
         this.formatDeathMessage(event.getDeathMessage(), event.getKillerPlayer().getPlayer()));
   }
   Bukkit.broadcastMessage(event.getDeathMessage());
   int reward = hg.getPrize(getAliveGamers().size());
   if (reward > 0) killed.addBalance(reward);
   hg.cannon();
   killed.clearInventory();
   World world = p.getWorld();
   for (ItemStack item : event.getDrops()) {
     if (item == null
         || item.getType() == Material.AIR
         || item.containsEnchantment(EnchantmentManager.UNLOOTABLE)) continue;
     else if (item.hasItemMeta())
       world
           .dropItemNaturally(event.getDropsLocation(), item.clone())
           .getItemStack()
           .setItemMeta(item.getItemMeta());
     else world.dropItemNaturally(event.getDropsLocation(), item);
   }
   setSpectator(killed);
   ScoreboardManager.makeScore(
       "Main", DisplaySlot.SIDEBAR, cm.getScoreboardPlayersLength(), getAliveGamers().size());
   hg.checkWinner();
   p.setVelocity(new Vector());
   for (PotionEffect effect : p.getActivePotionEffects()) p.removePotionEffect(effect.getType());
   p.teleport(p.getWorld().getHighestBlockAt(p.getLocation()).getLocation().clone().add(0, 10, 0));
   p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 40, 9), true);
   p.sendBlockChange(p.getLocation(), Material.PORTAL.getId(), (byte) 0);
   p.sendBlockChange(p.getLocation(), Material.AIR.getId(), (byte) 0);
   for (Entity entity : p.getWorld().getEntities()) {
     if (entity instanceof Tameable
         && ((Tameable) entity).isTamed()
         && ((Tameable) entity).getOwner().getName().equals(p.getName())) {
       if (entity instanceof Wolf) ((Wolf) entity).setSitting(true);
       else if (entity instanceof Ocelot) ((Ocelot) entity).setSitting(true);
       else entity.remove();
     }
     if (entity instanceof Creature && ((Creature) entity).getTarget() == p)
       ((Creature) entity).setTarget(null);
   }
   if (HungergamesApi.getConfigManager().getMainConfig().isKickOnDeath()
       && !p.hasPermission("hungergames.spectate"))
     p.kickPlayer(String.format(cm.getKickDeathMessage(), event.getDeathMessage()));
   HungergamesApi.getAbilityManager().unregisterPlayer(p);
   HungergamesApi.getInventoryManager().updateSpectatorHeads();
 }