예제 #1
0
  @Override
  public synchronized void unloadWorld(World world) {
    if (world == null) return;

    closeAll();
    String worldName = world.getName();

    List<String> keys = new ArrayList<String>(store.keySet());
    for (String key : keys) {
      String[] info = key.split(",");
      if (worldName.equals(info[0])) {
        int cx = 0;
        int cz = 0;

        try {
          cx = Integer.parseInt(info[1]);
          cz = Integer.parseInt(info[2]);
        } catch (Exception e) {
          continue;
        }
        unloadChunk(cx, cz, world);
      }
    }

    safeToRemoveMobs = false;

    List<Entity> tempSpawnedMobs = new ArrayList<Entity>(spawnedMobs);
    for (Entity entity : tempSpawnedMobs) {
      World entityWorld = entity.getWorld();

      if (world != entityWorld) continue;

      int cx = entity.getLocation().getChunk().getX();
      int cz = entity.getLocation().getChunk().getZ();

      unloadChunk(cx, cz, world);
    }

    List<Entity> tempSpawnedPets = new ArrayList<Entity>(spawnedPets);
    for (Entity entity : tempSpawnedPets) {
      World entityWorld = entity.getWorld();

      if (world != entityWorld) continue;

      int cx = entity.getLocation().getChunk().getX();
      int cz = entity.getLocation().getChunk().getZ();

      unloadChunk(cx, cz, world);
    }

    safeToRemoveMobs = true;

    spawnedMobs.remove(mobsToRemove);
    spawnedPets.remove(mobsToRemove);
    mobsToRemove.clear();
  }
  private boolean killDecision(
      Entity e,
      List<String> thingsToKill,
      boolean negateAnimals,
      boolean negateMonsters,
      boolean specifiedAnimals,
      boolean specifiedMonsters) {
    boolean negate = false;
    boolean specified = false;
    if (e instanceof Golem || e instanceof Squid || e instanceof Animals) {
      // it's an animal
      if (specifiedAnimals && !negateAnimals) {
        Logging.finest(
            "Removing an entity because I was told to remove all animals in world %s: %s",
            e.getWorld().getName(), e);
        return true;
      }
      if (specifiedAnimals) specified = true;
      negate = negateAnimals;
    } else if (e instanceof Monster || e instanceof Ghast || e instanceof Slime) {
      // it's a monster
      if (specifiedMonsters && !negateMonsters) {
        Logging.finest(
            "Removing an entity because I was told to remove all monsters in world %s: %s",
            e.getWorld().getName(), e);
        return true;
      }
      if (specifiedMonsters) specified = true;
      negate = negateMonsters;
    }
    for (String s : thingsToKill) {
      EntityType type = EntityType.fromName(s);
      if (type != null && type.equals(e.getType())) {
        specified = true;
        if (!negate) {
          Logging.finest(
              "Removing an entity because it WAS specified and we are NOT negating in world %s: %s",
              e.getWorld().getName(), e);
          return true;
        }
        break;
      }
    }
    if (!specified && negate) {
      Logging.finest(
          "Removing an entity because it was NOT specified and we ARE negating in world %s: %s",
          e.getWorld().getName(), e);
      return true;
    }

    return false;
  }
예제 #3
0
  public static void removeGoalSelectors(org.bukkit.entity.Entity paramEntity) {
    try {
      if (_goalSelector == null) {
        _goalSelector = EntityInsentient.class.getDeclaredField("goalSelector");
        _goalSelector.setAccessible(true);
      }
      if ((((CraftEntity) paramEntity).getHandle() instanceof EntityInsentient)) {
        EntityInsentient localEntityInsentient =
            (EntityInsentient) ((CraftEntity) paramEntity).getHandle();

        PathfinderGoalSelector localPathfinderGoalSelector =
            new PathfinderGoalSelector(
                ((CraftWorld) paramEntity.getWorld()).getHandle().methodProfiler);

        _goalSelector.set(localEntityInsentient, localPathfinderGoalSelector);
      }
    } catch (IllegalArgumentException localIllegalArgumentException) {
      localIllegalArgumentException.printStackTrace();
    } catch (IllegalAccessException localIllegalAccessException) {
      localIllegalAccessException.printStackTrace();
    } catch (NoSuchFieldException localNoSuchFieldException) {
      localNoSuchFieldException.printStackTrace();
    } catch (SecurityException localSecurityException) {
      localSecurityException.printStackTrace();
    }
  }
예제 #4
0
  /**
   * Monitor EntityDamageByEntity events.
   *
   * @param event The event to monitor
   */
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    if (event instanceof FakeEntityDamageByEntityEvent) {
      return;
    }

    Entity defender = event.getEntity();
    Entity attacker = event.getDamager();

    if (attacker instanceof Player && defender instanceof Player) {
      if (!defender.getWorld().getPVP()) {
        return;
      }

      if (Party.getInstance().inSameParty((Player) defender, (Player) attacker)) {
        event.setCancelled(true);
        return;
      }
    }

    /* Check for invincibility */
    if (defender instanceof LivingEntity) {
      LivingEntity livingDefender = (LivingEntity) defender;

      if (!m.isInvincible(livingDefender, event)) {
        // Make sure event isn't cancelled before trying to proc?
        if (!event.isCancelled()) Combat.combatChecks(event, plugin);
      }
    }
  }
예제 #5
0
  /* Powerups that are a single use only (like Nuke) do not need a time or the initiate variable */
  public void start(Player p) {
    name = Powers.NUKE.getName();

    api.broadcastMessage(
        ChatColor.GREEN
            + p.getDisplayName()
            + ChatColor.DARK_RED
            + " has used"
            + ChatColor.GREEN
            + " Nuke"
            + ChatColor.DARK_RED
            + "!");

    for (Entity e : p.getWorld().getEntities()) {
      if (!(e instanceof Player)) {
        if (e.isValid()) {
          e.remove();
          e.getWorld().playEffect(e.getLocation(), Effect.EXPLOSION_HUGE, 0);
          e.getWorld().playSound(e.getLocation(), Sound.EXPLODE, 10, 1);
          mobs++;
        }
      }
    }
    p.sendMessage(
        Main.tag
            + ChatColor.DARK_RED
            + "You killed "
            + ChatColor.GREEN
            + mobs
            + ChatColor.DARK_RED
            + " mobs!");
  }
예제 #6
0
  // @EventHandler(priority = EventPriority.NORMAL)
  public void explodingArrow(ProjectileHitEvent event) {
    Entity projectile = event.getEntity();
    World w = projectile.getWorld();
    Location hit = projectile.getLocation();

    if (w.getName().equals(name)) {

      if (projectile instanceof Arrow) {
        Arrow arrow = (Arrow) projectile;
        Entity shooter = arrow.getShooter();
        Location l = shooter.getLocation();
        Block bl = l.getBlock();
        Block b = bl.getRelative(BlockFace.DOWN, 2);
        Material mat = b.getType();

        if (shooter instanceof Player) {
          Player p = (Player) shooter;
          ItemStack is = p.getItemInHand();
          Material i = is.getType();
          if (i == Material.BOW && mat == Material.SPONGE) {
            p.getInventory().removeItem(new ItemStack(Material.ARROW, 20));
            w.createExplosion(hit, 8);
            int strikes = 0;
            while (strikes < 20) {
              strikes++;
              w.strikeLightning(hit);
            }
          }
          Bukkit.getWorld(name).playEffect(arrow.getLocation(), Effect.STEP_SOUND, 10);
        }
      }
    }
  }
예제 #7
0
  @Override
  public void cast(Entity entity) {
    // entity.getWorld().playSound(entity.getLocation(), Sound.GHAST_FIREBALL, 1F, 1F);
    entity.getWorld().playSound(entity.getLocation(), Sound.NOTE_STICKS, 1F, 0.4F);

    // TODO - find a better way to launch block without needing Player
    if (entity instanceof Player) {
      Player player = (Player) entity;

      Vector velocity = player.getEyeLocation().getDirection();
      velocity.normalize().multiply(power);

      FallingBlock fb =
          DeprecatedMethods.spawnFallingBlock(
              entity.getLocation().clone().add(0, 1, 0),
              DeprecatedMethods.getMaterialByID(blockID),
              (byte) 0);
      fb.setDropItem(false);
      fb.setVelocity(velocity);

      // make it do damage
      if (damage) {
        DynamicClassFunctions.setFallingBlockHurtEntities(fb, hurt, hurt);
      }
    }
  }
예제 #8
0
파일: Bows.java 프로젝트: FriedCream/lol-
 @EventHandler
 public void onland(ProjectileHitEvent e) {
   if (!Api.allowsPVP(e.getEntity())) return;
   if (Arrow.containsKey(e.getEntity())) {
     Entity arrow = e.getEntity();
     if (Enchant.get(arrow).equalsIgnoreCase("Boom")) {
       if (Api.isEnchantmentEnabled("Boom")) {
         if (Api.randomPicker(6 - Api.getPower(Arrow.get(arrow) + "", Api.getEnchName("Boom")))) {
           TNTPrimed tnt = arrow.getWorld().spawn(arrow.getLocation(), TNTPrimed.class);
           tnt.setFuseTicks(0);
           tnt.getWorld().playEffect(tnt.getLocation(), Effect.EXPLOSION_LARGE, 1);
           Explode.add(tnt);
           arrow.remove();
         }
       }
       Arrow.remove(arrow);
     }
     if (Enchant.get(arrow).equalsIgnoreCase("Lightning")) {
       if (Api.isEnchantmentEnabled("Lightning")) {
         Location loc = arrow.getLocation();
         if (Api.randomPicker(5)) {
           loc.getWorld().strikeLightning(loc);
         }
       }
     }
   }
 }
예제 #9
0
  public static EventData getEventData(EntityDamageEvent event) {
    if (event == null) return null;

    DamageType damageElement = DamageType.get(event.getCause());

    Entity attacker = null;
    Projectile projectile = null;
    Entity target = event.getEntity();
    World world = target.getWorld();

    if (event instanceof EntityDamageByEntityEvent) {
      EntityDamageByEntityEvent event_EE = (EntityDamageByEntityEvent) event;
      Entity damager = event_EE.getDamager();

      if (damager instanceof Projectile) {
        projectile = (Projectile) damager;

        attacker = projectile.getShooter();
      } else {
        attacker = damager;
      }
    }

    return myInfo.makeData(
        attacker, projectile, target, world, damageElement, event.getDamage(), event.isCancelled());
  }
예제 #10
0
  /**
   * Tag creepers hurt by players.
   *
   * <p>Only those creepers hurt recently by players will have special drops.
   */
  @EventHandler(ignoreCancelled = true)
  public void onCreeperDamage(EntityDamageByEntityEvent event) {
    if (!CONFIG.isAffectedWorld(event)) {
      return;
    }

    if (event.getEntityType() == EntityType.CREEPER) {
      boolean isPlayerAttack = false;
      if (event.getDamager() instanceof Player) {
        isPlayerAttack = true;
      } else if (event.getDamager() instanceof Projectile) {
        Projectile projectile = (Projectile) event.getDamager();
        if (projectile.getShooter() instanceof Player) {
          isPlayerAttack = true;
        }
      }

      // Tag creepers hurt by players with the damage time stamp.
      if (isPlayerAttack) {
        Entity creeper = event.getEntity();
        creeper.setMetadata(
            PLAYER_DAMAGE_TIME_KEY,
            new FixedMetadataValue(this, new Long(creeper.getWorld().getFullTime())));
      }
    }
  }
  public static EntityBreakDoorEvent callEntityBreakDoorEvent(Entity entity, int x, int y, int z) {
    org.bukkit.entity.Entity entity1 = getBukkitEntity(entity);
    Block block = entity1.getWorld().getBlockAt(x, y, z);

    EntityBreakDoorEvent event = new EntityBreakDoorEvent((LivingEntity) entity1, block);
    entity1.getServer().getPluginManager().callEvent(event);

    return event;
  }
예제 #12
0
 /**
  * Check if a certain entity is in a cuboid.
  *
  * @param entity The entity that is to be checked for being inside of the cuboid.
  * @return A boolean that is true if the entity is inside the cuboid or false if the entity is not
  *     inside the cuboid.
  */
 public boolean isInCuboid(Entity entity) {
   return (entity.getWorld() == this.getWorld())
       && (entity.getLocation().getBlockX() >= this.getMinX())
       && (entity.getLocation().getBlockX() <= this.getMaxX())
       && (entity.getLocation().getBlockY() >= this.getMinY())
       && (entity.getLocation().getBlockY() <= this.getMaxY())
       && (entity.getLocation().getBlockZ() >= this.getMinZ())
       && (entity.getLocation().getBlockZ() <= this.getMaxZ());
 }
예제 #13
0
 public boolean inGameWorld(Entity entity) {
   World world = entity.getWorld();
   for (MineZGame game : GameManager.INSTANCE.getRawGames()) {
     for (World w : game.getWorlds()) {
       if (world.equals(w)) return true;
     }
   }
   return false;
 }
예제 #14
0
 private static Location getAcurateSpawnLocation(Entity e, MultiverseWorld world) {
   if (world != null) {
     return world.getSpawnLocation();
   } else {
     // add 0.5 to x and z to center people
     // (spawn location is stored as int meaning that you would spawn in the corner of a block)
     return e.getWorld().getSpawnLocation().add(.5, 0, .5);
   }
 }
    @EventHandler
    public void onEntityDamage(EntityDamageEvent event) {
      Heroes.debug.startTask("HeroesSkillListener");
      if ((event.isCancelled()) || (!(event instanceof EntityDamageByEntityEvent))) {
        Heroes.debug.stopTask("HeroesSkillListener");
        return;
      }

      Entity projectile = ((EntityDamageByEntityEvent) event).getDamager();
      if ((!(projectile instanceof Arrow))
          || (!(((Projectile) projectile).getShooter() instanceof Player))) {
        Heroes.debug.stopTask("HeroesSkillListener");
        return;
      }

      Player player = (Player) ((Projectile) projectile).getShooter();
      Hero hero = SkillExplodingArrow.this.plugin.getCharacterManager().getHero(player);
      if (!hero.hasEffect("ExplodingArrowBuff")) {
        Heroes.debug.stopTask("HeroesSkillListener");
        return;
      }

      int radius =
          (int)
              Math.pow(
                  SkillConfigManager.getUseSetting(hero, this.skill, "radius", 5, false), 2.0D);

      float damage = SkillConfigManager.getUseSetting(hero, this.skill, "DAMAGE", 5, false);
      float blockdamage = damage;
      int block_dmg = SkillConfigManager.getUseSetting(hero, this.skill, "block-dmg", 0, false);

      if (block_dmg == 0) {
        blockdamage = 0.0F;

        for (Entity t_entity : player.getWorld().getEntities()) {
          if ((t_entity instanceof Player)) {
            Player heroes = (Player) t_entity;
            if (heroes.getLocation().distanceSquared(projectile.getLocation()) <= radius)
              SkillExplodingArrow.damageEntity(
                  heroes, player, (int) damage, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION);
          } else if ((t_entity instanceof Creature)) {
            Creature mob = (Creature) t_entity;
            if (t_entity.getLocation().distanceSquared(projectile.getLocation()) <= radius) {
              SkillExplodingArrow.damageEntity(
                  mob, player, (int) damage, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION);
            }
          }
        }
      }

      projectile.getWorld().createExplosion(projectile.getLocation(), blockdamage);

      Heroes.debug.stopTask("HeroesSkillListener");
    }
예제 #16
0
  private boolean isEntityInChunk(Entity entity, int cx, int cz, World world) {
    if (entity == null || world == null) return false;

    if (entity.getLocation().getChunk().getX() != cx) return false;

    if (entity.getLocation().getChunk().getZ() != cz) return false;

    if (entity.getWorld() != world) return false;

    return true;
  }
예제 #17
0
파일: Swords.java 프로젝트: nidefawl/mcMMO
  public static void applySerratedStrikes(
      Player attacker, EntityDamageByEntityEvent event, mcMMO pluginx) {
    int targets = 0;

    if (event.getEntity() instanceof LivingEntity) {
      LivingEntity x = (LivingEntity) event.getEntity();
      targets = Utils.getTier(attacker);

      for (Entity derp : x.getWorld().getEntities()) {
        if (Utils.getDistance(x.getLocation(), derp.getLocation()) < 5) {

          // Make sure the Wolf is not friendly
          if (derp instanceof Wolf) {
            Wolf hurrDurr = (Wolf) derp;
            if (Taming.getOwner(hurrDurr, pluginx) == attacker) continue;
            //						if(Party.getInstance().inSameParty(attacker, Taming.getOwner(hurrDurr,
            // pluginx)))
            //							continue;
          }
          // Damage nearby LivingEntities
          if (derp instanceof LivingEntity && targets >= 1) {
            if (derp instanceof Player) {
              Player target = (Player) derp;

              if (target.getName().equals(attacker.getName())) continue;

              if (Users.getProfile(target).getGodMode()) continue;

              //		    				if(Party.getInstance().inSameParty(attacker, target))
              //		    					continue;
              if (targets >= 1 && derp.getWorld().getPVP()) {
                target.damage(event.getDamage() / 4);
                target.sendMessage(ChatColor.DARK_RED + "Struck by Serrated Strikes!");
                if (Combat.dealDamage(attacker, target, 0)) target.increaseBleedTicks(5);
                target.setLastCustomDamageCause(
                    new EntityDamageByEntityEvent(attacker, target, DamageCause.ENTITY_ATTACK, 0));
                targets--;
                continue;
              }
            } else {
              LivingEntity target = (LivingEntity) derp;
              target.increaseBleedTicks(5);
              target.damage(event.getDamage() / 4);
              target.setLastCustomDamageCause(
                  new EntityDamageByEntityEvent(attacker, target, DamageCause.ENTITY_ATTACK, 0));
              targets--;
            }
          }
        }
      }
    }
  }
예제 #18
0
 public Entity getVehicleEntity(Entity entity) {
   Preconditions.checkNotNull(entity, "entity cannot be null.");
   List<MetadataValue> metadata = entity.getMetadata(this.nametagMetadata);
   if (!metadata.isEmpty()) {
     int targetId = (int) metadata.get(0).value();
     for (Entity e : entity.getWorld().getEntities()) {
       if (e.getEntityId() == targetId) {
         return e;
       }
     }
   }
   return null;
 }
예제 #19
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onEntityDamage(EntityDamageEvent event) {

    Entity entity = event.getEntity();
    EntityType type = event.getEntityType();

    if (isWorld(entity.getWorld())) {

      MetadataValue isFireplace;
      if (type == EntityType.ARMOR_STAND
          && (isFireplace = EntityChecker.getMeta(entity, "isFireplace")) != null
          && isFireplace.asBoolean()) {
        event.setCancelled(true); // prevent armor stand from burning away before it's done
      }
    }
  }
예제 #20
0
 @EventHandler(priority = EventPriority.NORMAL)
 public void onEntityExplode(final EntityExplodeEvent e) {
   if (Game.getGames().size() != 0) {
     List<Block> blockList = e.blockList();
     List<Game> affectedGames = new ArrayList<Game>();
     for (Game game : Game.getGames().values()) {
       if (affectedGames.contains(game)) continue;
       GameConfig config = game.getGameConfig();
       List<Block> gameBlocks = config.getPartList().getList();
       for (Block b : blockList) {
         if (gameBlocks.contains(b)) {
           affectedGames.add(game);
           break;
         }
       }
     }
     if (affectedGames.size() != 0) {
       e.setCancelled(true);
       for (Game game : affectedGames) {
         GameConfig config = game.getGameConfig();
         game.broadcastMessage(
             Text.getLabelArgs("game.canceled_explosion", config.getName(), "" + config.getId()));
       }
     }
     Entity ent = e.getEntity();
     if ((ent instanceof Creature) || (ent instanceof Explosive)) {
       Debug.warning("Entity found");
       World w = ent.getWorld();
       for (Game rmGame : Game.getGames().values()) {
         if (rmGame.getGameConfig().getWorld() == w) {
           Debug.warning("Same world found");
           if (rmGame.inRangeXZ(ent, rmGame.getGameConfig().getSettingInt(Setting.playarea))) {
             rmGame.addLog(blockList.toArray(new Block[blockList.size()]));
             return;
           }
           for (GamePlayer rmp : rmGame.getOnlineTeamPlayers()) {
             Debug.warning("rmp: " + rmp.getName());
             if (rmp.inRange(ent.getLocation(), 32)) {
               rmGame.addLog(blockList.toArray(new Block[blockList.size()]));
               return;
             } else Debug.warning("not near location");
           }
         }
       }
     }
   }
 }
예제 #21
0
  @Override
  public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (sender instanceof Player) {
      Player p = (Player) sender;
      if (!plugin.hasPerm(p, "petcreeper.saddle")) {
        plugin.message(p, ChatColor.RED + "You do not have permission to use this command.");
        return true;
      }
      if (plugin.isPetOwner(p)) {
        if (args.length == 1 && args[0].matches("\\d+")) {
          int idx = Integer.parseInt(args[0]) - 1;
          if (idx >= 0 && idx < plugin.getPetsOf(p).size()) {
            Pet pet = plugin.getPetsOf(p).get(idx);
            if (pet.type.equals(EntityType.PIG)) {
              Entity e = plugin.getEntityOfPet(pet);
              if (e != null) {
                if (((Pig) e).hasSaddle()) {
                  ((Pig) e).setSaddle(false);
                  plugin.message(p, ChatColor.GREEN + "Your pet dropped the saddle!");
                  e.getWorld()
                      .dropItemNaturally(e.getLocation(), new ItemStack(Material.SADDLE, 1));
                  p.playSound(e.getLocation(), Sound.PIG_DEATH, 10, 1);

                } else {
                  plugin.message(p, ChatColor.GREEN + "Your pet looks at you strangely.");
                }
              }
            } else {
              plugin.message(p, ChatColor.RED + "Invalid pet ID.");
            }
          } else {
            plugin.message(
                p,
                ChatColor.YELLOW
                    + "Usage: "
                    + ChatColor.WHITE
                    + "/"
                    + plugin.config.commandPrefix
                    + "saddle [id]");
          }
        } else {
          plugin.message(p, ChatColor.RED + "You have no pets. :(");
        }
      }
    }
    return true;
  }
예제 #22
0
 @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
 public void CreatureDamagedbyEntity(final EntityDamageByEntityEvent event) {
   final Entity entity = event.getEntity();
   entity.removeMetadata(PeacefulMeta.METAHEADER, plugin);
   double alarmRange = plugin.getDefaultAlarmRange();
   final List<MetadataValue> metas = entity.getMetadata(AlarmMeta.METAHEADER);
   for (final MetadataValue meta : metas)
     if (meta instanceof AlarmMeta) {
       final AlarmMeta alarm = (AlarmMeta) meta;
       alarmRange = alarm.asDouble();
       break;
     }
   final Location location = entity.getLocation();
   for (final LivingEntity nearby : entity.getWorld().getEntitiesByClass(LivingEntity.class))
     if (location.distance(nearby.getLocation()) < alarmRange)
       nearby.removeMetadata(PeacefulMeta.METAHEADER, plugin);
 }
예제 #23
0
  /*
   * General methods
   */
  public static Entity GetEntity(World world, String name) {

    Object[] entityArray = entityList.keySet().toArray();
    for (int i = 0; i < entityArray.length; i++) {
      Entity tempEntity = (Entity) entityArray[i];
      if (tempEntity.getWorld().equals(world) && getEntityName(tempEntity).equalsIgnoreCase(name)) {
        return tempEntity;
      }
    }

    List<Entity> entityList = world.getEntities();
    for (Entity entity : entityList) {
      if (getEntityName(entity).equalsIgnoreCase(name)) {
        return entity;
      }
    }
    return null;
  }
예제 #24
0
 // Rotates an NPC.
 public static void faceEntity(HumanNPC npc, Entity entity) {
   if (npc.getWorld() != entity.getWorld()) return;
   if (Settings.getBoolean("RealisticPathing")
       && !npc.getHandle().isInSight(((CraftEntity) entity).getHandle())) return;
   Location loc = npc.getLocation(), pl = entity.getLocation();
   double xDiff = pl.getX() - loc.getX();
   double yDiff = pl.getY() - loc.getY();
   double zDiff = pl.getZ() - loc.getZ();
   double DistanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
   double DistanceY = Math.sqrt(DistanceXZ * DistanceXZ + yDiff * yDiff);
   double yaw = (Math.acos(xDiff / DistanceXZ) * 180 / Math.PI);
   double pitch = (Math.acos(yDiff / DistanceY) * 180 / Math.PI) - 90;
   if (zDiff < 0.0) {
     yaw = yaw + (Math.abs(180 - yaw) * 2);
   }
   npc.getHandle().yaw = (float) yaw - 90;
   npc.getHandle().az = npc.getHandle().yaw;
   npc.getHandle().pitch = (float) pitch;
 }
예제 #25
0
  /**
   * Tests the attacker against defender to see if we need to cancel the damage event due to world
   * PvP, Plot PvP or Friendly Fire settings. Only allow a Wolves owner to cause it damage, and
   * residents with destroy permissions to damage passive animals and villagers while in a town.
   *
   * @param attacker
   * @param defender
   * @return true if we should cancel.
   */
  public static boolean preventDamageCall(Towny plugin, Entity attacker, Entity defender) {

    try {
      TownyWorld world = TownyUniverse.getDataSource().getWorld(defender.getWorld().getName());

      // World using Towny
      if (!world.isUsingTowny()) return false;

      Player a = null;
      Player b = null;

      /*
       * Find the shooter if this is a projectile.
       */
      if (attacker instanceof Projectile) {

        Projectile projectile = (Projectile) attacker;
        Object source = projectile.getShooter();

        if (source instanceof Entity) {
          attacker = (Entity) source;
        } else {
          return false; // TODO: prevent damage from dispensers
        }
      }

      if (attacker instanceof Player) a = (Player) attacker;
      if (defender instanceof Player) b = (Player) defender;

      // Allow players to injure themselves
      if (a == b) return false;

      return preventDamageCall(plugin, world, attacker, defender, a, b);

    } catch (Exception e) {
      // Failed to fetch world
    }

    return false;
  }
예제 #26
0
파일: _37.java 프로젝트: r0306/RollTheDice
  public Block getHookBlock(final Entity hook)
      throws NoSuchFieldException, SecurityException, IllegalArgumentException,
          IllegalAccessException {

    World world = hook.getWorld();

    EntityFishingHook entityHook = ((CraftFish) hook).getHandle();

    Field fieldX = net.minecraft.server.EntityFishingHook.class.getDeclaredField("d");
    Field fieldY = net.minecraft.server.EntityFishingHook.class.getDeclaredField("e");
    Field fieldZ = net.minecraft.server.EntityFishingHook.class.getDeclaredField("f");

    fieldX.setAccessible(true);
    fieldY.setAccessible(true);
    fieldZ.setAccessible(true);

    int x = fieldX.getInt(entityHook);
    int y = fieldY.getInt(entityHook);
    int z = fieldZ.getInt(entityHook);

    return world.getBlockAt(x, y, z);
  }
예제 #27
0
 @EventHandler(priority = EventPriority.NORMAL)
 public void onEntityDamage(EntityDamageEvent event) {
   if (event.isCancelled()) return;
   Entity ent = event.getEntity();
   boolean tamedWolf = ent instanceof Wolf ? ((Wolf) ent).isTamed() : false;
   ClaimedResidence area = Residence.getResidenceManager().getByLoc(ent.getLocation());
   /* Living Entities */
   if (event instanceof EntityDamageByEntityEvent) {
     EntityDamageByEntityEvent attackevent = (EntityDamageByEntityEvent) event;
     Entity damager = attackevent.getDamager();
     ClaimedResidence srcarea = null;
     if (damager != null)
       srcarea = Residence.getResidenceManager().getByLoc(damager.getLocation());
     boolean srcpvp = true;
     if (srcarea != null) srcpvp = srcarea.getPermissions().has("pvp", true);
     ent = attackevent.getEntity();
     if ((ent instanceof Player || tamedWolf)
         && (damager instanceof Player
             || (damager instanceof Arrow
                 && (((Arrow) damager).getShooter() instanceof Player)))) {
       Player attacker = null;
       if (damager instanceof Player) attacker = (Player) damager;
       else if (damager instanceof Arrow) attacker = (Player) ((Arrow) damager).getShooter();
       if (!srcpvp) {
         attacker.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPVPZone"));
         event.setCancelled(true);
         return;
       }
       /* Check for Player vs Player */
       if (area == null) {
         /* World PvP */
         if (!Residence.getWorldFlags().getPerms(damager.getWorld().getName()).has("pvp", true)) {
           attacker.sendMessage(
               ChatColor.RED + Residence.getLanguage().getPhrase("WorldPVPDisabled"));
           event.setCancelled(true);
         }
       } else {
         /* Normal PvP */
         if (!area.getPermissions().has("pvp", true)) {
           attacker.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPVPZone"));
           event.setCancelled(true);
         }
       }
       return;
     } else if ((ent instanceof Player || tamedWolf) && (damager instanceof Creeper)) {
       if (area == null) {
         if (!Residence.getWorldFlags()
             .getPerms(damager.getWorld().getName())
             .has("creeper", true)) {
           event.setCancelled(true);
         }
       } else {
         if (!area.getPermissions().has("creeper", true)) {
           event.setCancelled(true);
         }
       }
     }
   }
   if (area == null) {
     if (!Residence.getWorldFlags().getPerms(ent.getWorld().getName()).has("damage", true)
         && (ent instanceof Player || tamedWolf)) {
       event.setCancelled(true);
     }
   } else {
     if (!area.getPermissions().has("damage", true) && (ent instanceof Player || tamedWolf)) {
       event.setCancelled(true);
     }
   }
   if (event.isCancelled()) {
     /* Put out a fire on a player */
     if ((ent instanceof Player || tamedWolf)
         && (event.getCause() == EntityDamageEvent.DamageCause.FIRE
             || event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK)) {
       ent.setFireTicks(0);
     }
   }
 }
예제 #28
0
 public static boolean isCase(World self, Entity val) {
   return val.getWorld().equals(self);
 }
예제 #29
0
 /**
  * Removes a single entity from the world
  *
  * @param entity to remove
  */
 public static void removeEntity(org.bukkit.entity.Entity entity) {
   Entity e = NativeUtil.getNative(entity);
   e.world.removeEntity(e);
   getTracker(entity.getWorld()).untrackEntity(e);
 }
예제 #30
0
 public MCWorld getWorld() {
   if (e == null || e.getWorld() == null) {
     return null;
   }
   return new BukkitMCWorld(e.getWorld());
 }