Пример #1
0
  @EventHandler(priority = EventPriority.HIGHEST)
  private void onEntityDamage(EntityDamageEvent evt) {
    if (!(evt.getEntity() instanceof Player)) {
      return;
    }
    Player p = (Player) evt.getEntity();
    PlayerDataClass pData = plugin.getPlayerHandler().findPlayer(p.getDisplayName());
    if (pData != null) {
      if (evt.getCause() == DamageCause.FALL) {
        Player player = (Player) evt.getEntity();
        if (plugin.getPlayerHandler().findPlayer(player.getDisplayName()) != null) {

          PlayerDataClass playerData =
              plugin.getPlayerHandler().findPlayer(player.getDisplayName());

          if (playerData.getType().equalsIgnoreCase("soldier")) {
            if (evt.getDamage() > 4) {
              evt.setDamage(4);
            }
          }
        }
      }
    } else {
      evt.setCancelled(true);
    }
  }
Пример #2
0
 @EventHandler(priority = EventPriority.HIGHEST)
 private void onProjectileLaunch(ProjectileLaunchEvent evt) {
   if (evt.getEntity() instanceof Arrow) {
     Arrow arrow = (Arrow) evt.getEntity();
     if (arrow.getShooter() instanceof Player) {
       Player shooter = (Player) arrow.getShooter();
       PlayerDataClass shooterData =
           plugin.getPlayerHandler().findPlayer(shooter.getDisplayName());
       if (shooterData != null) {
         if (shooter.getInventory().contains(Material.ARROW)) {
           if (shooterData.getType().equalsIgnoreCase("sniper") && arrow.hasMetadata("charged")) {
             evt.setCancelled(true);
             // shooter.getInventory().removeItem(new ItemStack (Material.ARROW, 1));
             // shooter.updateInventory();
             // ItemStack is = shooter.getInventory().getItem(Material.ARROW.getId());
             // is.setAmount(is.getAmount() - 1);
             // shooter.getInventory().setItem(Material.ARROW.getId(), is);
             // Location loc = shooter.getLocation();
             // loc.add(0,1,0);
             Location arrowLocation = shooter.getEyeLocation();
             arrowLocation.setY(arrowLocation.getY() + 0.1);
             Arrow sniperArrow =
                 shooter
                     .getWorld()
                     .spawnArrow(arrowLocation, shooter.getLocation().getDirection(), 0.6f, 1);
             sniperArrow.setShooter(shooter);
             sniperArrow.setBounce(false);
             sniperArrow.setVelocity(
                 shooter.getLocation().getDirection().normalize().multiply(10));
           }
           if (shooterData.getType().equalsIgnoreCase("soldier")) {
             arrow.setMetadata("rocket", new FixedMetadataValue(plugin, true));
             ArrowDataClass arrowData = new ArrowDataClass();
             arrowData.setArrow(arrow);
             arrow.setTicksLived(30);
             arrowData.setVector(shooter.getLocation().getDirection());
             plugin.getArrowsFired().add(arrowData);
           }
         }
       }
     }
   }
 }
Пример #3
0
  @EventHandler(priority = EventPriority.HIGHEST)
  private void onDeath(PlayerDeathEvent evt) {
    evt.getDrops().clear();

    final Player player = evt.getEntity().getPlayer();
    final PlayerDataClass playerData =
        plugin.getPlayerHandler().findPlayer(player.getDisplayName());

    if (playerData != null) {

      setUnscoped(player, playerData);

      plugin.getPlayerLocationListener().removePlayerFromPoint(playerData);

      if (evt.getEntity().getKiller() != null) {
        Player killer = evt.getEntity().getKiller();
        PlayerDataClass killerData = plugin.getPlayerHandler().findPlayer(killer.getDisplayName());

        playerData.setDeaths(playerData.getDeaths() + 1);
        if (killer != null) {
          killerData.setKills(killerData.getKills() + 1);
        }
      }
      if (playerData.getType().equals("spy") && playerData.getDisguised() != null) {
        playerData.setDisguised(null);
      }

      if (player.isDead()) {
        player.setHealth(20);
      }

      plugin
          .getServer()
          .getScheduler()
          .scheduleSyncDelayedTask(
              plugin,
              new Runnable() {
                public void run() {
                  if (plugin.getPlayerHandler().findPlayer(player.getDisplayName()) != null) {
                    plugin.getLogger().info("Respawning: " + player.getName());
                    plugin.getPlayerHandler().spawnPlayer(playerData);
                    TagAPI.refreshPlayer(player);
                  }
                }
              },
              5L);
    } else {
      plugin.getGameManager().teleportToSpawn(player);
    }
  }
Пример #4
0
  @EventHandler(priority = EventPriority.HIGHEST)
  private void onShootBow(EntityShootBowEvent evt) {
    if (!(evt.getEntity() instanceof Player)) {
      return;
    }

    Player player = (Player) evt.getEntity();
    PlayerDataClass playerData = plugin.getPlayerHandler().findPlayer(player.getDisplayName());

    if (playerData != null) {
      if (playerData.getType().equals("sniper")
          && evt.getForce() == 1
          && playerData.isScoped() == true) {
        evt.getProjectile().setMetadata("charged", new FixedMetadataValue(plugin, true));
      }
    }
  }
Пример #5
0
  @EventHandler(priority = EventPriority.HIGHEST)
  private void onPlayerDamage(EntityDamageByEntityEvent evt) {
    if (evt.getEntity() instanceof Player && evt.getDamager() instanceof Player) {
      Player player = (Player) evt.getEntity();
      PlayerDataClass playerData = plugin.getPlayerHandler().findPlayer(player.getDisplayName());
      Player attacker = (Player) evt.getDamager();
      PlayerDataClass attackerData =
          plugin.getPlayerHandler().findPlayer(attacker.getDisplayName());

      if (attackerData != null && playerData != null) {
        if (attackerData.getTeam() == playerData.getTeam()) {
          evt.setCancelled(true);
          return;
        }

        if (attackerData.getType().equals("spy")) {
          plugin.getLogger().info("Logged knife stab");
          if (plugin
              .getUtilities()
              .checkPlayerInCone(
                  player, attacker.getLocation(), 4, 80, (int) attacker.getLocation().getYaw())) {
            plugin.getLogger().info(attackerData.getName() + " behind " + playerData.getName());
          }
        }
      } else {
        evt.setCancelled(true);
      }
    }

    if (evt.getDamager() instanceof Arrow) {
      Arrow arrow = (Arrow) evt.getDamager();
      Player attacker = (Player) arrow.getShooter();
      PlayerDataClass attackerData =
          plugin.getPlayerHandler().findPlayer(attacker.getDisplayName());

      Player player = (Player) evt.getEntity();
      PlayerDataClass playerData = plugin.getPlayerHandler().findPlayer(player.getDisplayName());

      if (attackerData != null && playerData != null) {
        if (attackerData.getTeam() == playerData.getTeam()) {
          evt.setCancelled(true);
        }
      }
    }
  }
Пример #6
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;
    }
  }