示例#1
0
 public NMSNPC(UUID uuid, EntityType type, NMSRegistry registry) {
   if (!type.equals(EntityType.PLAYER))
     throw new UnsupportedOperationException("Can only spawn players");
   this.type = type;
   this.UUID = uuid;
   this.registry = registry;
   runTaskTimer(getRegistry().getPlugin(), 20, 1);
 }
示例#2
0
 @EventHandler
 public void onHealthRegenerate(EntityRegainHealthEvent event) {
   EntityType entityType = event.getEntityType();
   if (entityType.equals(EntityType.PLAYER)) {
     if (GameManager.INSTANCE.getSession((Player) event.getEntity()) == null) return;
     if (event.getRegainReason().equals(EntityRegainHealthEvent.RegainReason.SATIATED)) {
       event.setCancelled(true);
     }
   }
 }
  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;
  }
示例#4
0
  @EventHandler
  public void onLaunch(ProjectileLaunchEvent event) {
    LivingEntity shooter = event.getEntity().getShooter();
    EntityType entity = event.getEntityType();

    if (shooter instanceof Player && entity.equals(EntityType.ARROW)) {
      Player player = (Player) shooter;
      Location loc = player.getLocation();
      if (player.hasPermission("shockpvp.loudbow")) {
        loc.getWorld().playEffect(loc, Effect.GHAST_SHOOT, 50);
      }
    }
  }
  @EventHandler(priority = EventPriority.HIGH)
  public void handleCustomMobDrops(EntityDeathEvent event) {

    if (!EventUtil.passesFilter(event)) return;
    EntityType entityType = event.getEntityType();
    if (entityType == null || !entityType.isAlive() || entityType.equals(EntityType.PLAYER)) return;
    CustomDropManager.DropDefinition[] drops = customDrops.getMobDrop(event.getEntity());
    if (drops != null) {
      if (!drops[0].append) {
        event.getDrops().clear();
        ((ExperienceOrb)
                event
                    .getEntity()
                    .getWorld()
                    .spawnEntity(event.getEntity().getLocation(), EntityType.EXPERIENCE_ORB))
            .setExperience(event.getDroppedExp());
      }
      // Add the custom drops
      for (CustomDropManager.DropDefinition dropDefinition : drops) {
        ItemStack stack = dropDefinition.getItemStack();
        if (ItemUtil.isStackValid(stack)) event.getDrops().add(stack);
      }
    }
  }
 /*
  * Returns a classic block type id related to the material
  */
 @SuppressWarnings("deprecation")
 public static int toID(EntityType entityType) {
   if (entityType.equals(EntityType.DROPPED_ITEM)) {
     return 1;
   } else if (entityType.equals(EntityType.EXPERIENCE_ORB)) {
     return 2;
   } else if (entityType.equals(EntityType.LEASH_HITCH)) {
     return 8;
   } else if (entityType.equals(EntityType.PAINTING)) {
     return 9;
   } else if (entityType.equals(EntityType.ARROW)) {
     return 10;
   } else if (entityType.equals(EntityType.SNOWBALL)) {
     return 11;
   } else if (entityType.equals(EntityType.FIREBALL)) {
     return 12;
   } else if (entityType.equals(EntityType.SMALL_FIREBALL)) {
     return 13;
   } else if (entityType.equals(EntityType.ENDER_PEARL)) {
     return 14;
   } else if (entityType.equals(EntityType.ENDER_SIGNAL)) {
     return 15;
   } else if (entityType.equals(EntityType.THROWN_EXP_BOTTLE)) {
     return 17;
   } else if (entityType.equals(EntityType.ITEM_FRAME)) {
     return 18;
   } else if (entityType.equals(EntityType.WITHER_SKULL)) {
     return 19;
   } else if (entityType.equals(EntityType.PRIMED_TNT)) {
     return 20;
   } else if (entityType.equals(EntityType.FALLING_BLOCK)) {
     return 21;
   } else if (entityType.equals(EntityType.FIREWORK)) {
     return 22;
   } else if (entityType.equals(EntityType.TIPPED_ARROW)) {
     return 23;
   } else if (entityType.equals(EntityType.SPECTRAL_ARROW)) {
     return 24;
   } else if (entityType.equals(EntityType.SHULKER_BULLET)) {
     return 25;
   } else if (entityType.equals(EntityType.DRAGON_FIREBALL)) {
     return 26;
   } else if (entityType.equals(EntityType.ARMOR_STAND)) {
     return 30;
   } else if (entityType.equals(EntityType.MINECART_COMMAND)) {
     return 40;
   } else if (entityType.equals(EntityType.BOAT)) {
     return 41;
   } else if (entityType.equals(EntityType.MINECART)) {
     return 42;
   } else if (entityType.equals(EntityType.MINECART_CHEST)) {
     return 43;
   } else if (entityType.equals(EntityType.MINECART_FURNACE)) {
     return 44;
   } else if (entityType.equals(EntityType.MINECART_TNT)) {
     return 45;
   } else if (entityType.equals(EntityType.MINECART_HOPPER)) {
     return 46;
   } else if (entityType.equals(EntityType.MINECART_MOB_SPAWNER)) {
     return 47;
   } else if (entityType.equals(EntityType.CREEPER)) {
     return 50;
   } else if (entityType.equals(EntityType.SKELETON)) {
     return 51;
   } else if (entityType.equals(EntityType.SPIDER)) {
     return 52;
   } else if (entityType.equals(EntityType.GIANT)) {
     return 53;
   } else if (entityType.equals(EntityType.ZOMBIE)) {
     return 54;
   } else if (entityType.equals(EntityType.SLIME)) {
     return 55;
   } else if (entityType.equals(EntityType.GHAST)) {
     return 56;
   } else if (entityType.equals(EntityType.PIG_ZOMBIE)) {
     return 57;
   } else if (entityType.equals(EntityType.ENDERMAN)) {
     return 58;
   } else if (entityType.equals(EntityType.CAVE_SPIDER)) {
     return 59;
   } else if (entityType.equals(EntityType.SILVERFISH)) {
     return 60;
   } else if (entityType.equals(EntityType.BLAZE)) {
     return 61;
   } else if (entityType.equals(EntityType.MAGMA_CUBE)) {
     return 62;
   } else if (entityType.equals(EntityType.ENDER_DRAGON)) {
     return 63;
   } else if (entityType.equals(EntityType.WITHER)) {
     return 64;
   } else if (entityType.equals(EntityType.BAT)) {
     return 65;
   } else if (entityType.equals(EntityType.WITCH)) {
     return 66;
   } else if (entityType.equals(EntityType.ENDERMITE)) {
     return 67;
   } else if (entityType.equals(EntityType.GUARDIAN)) {
     return 68;
   } else if (entityType.equals(EntityType.SHULKER)) {
     return 69;
   } else if (entityType.equals(EntityType.PIG)) {
     return 90;
   } else if (entityType.equals(EntityType.SHEEP)) {
     return 91;
   } else if (entityType.equals(EntityType.COW)) {
     return 92;
   } else if (entityType.equals(EntityType.CHICKEN)) {
     return 93;
   } else if (entityType.equals(EntityType.SQUID)) {
     return 94;
   } else if (entityType.equals(EntityType.WOLF)) {
     return 95;
   } else if (entityType.equals(EntityType.MUSHROOM_COW)) {
     return 96;
   } else if (entityType.equals(EntityType.SNOWMAN)) {
     return 97;
   } else if (entityType.equals(EntityType.OCELOT)) {
     return 98;
   } else if (entityType.equals(EntityType.IRON_GOLEM)) {
     return 99;
   } else if (entityType.equals(EntityType.HORSE)) {
     return 100;
   } else if (entityType.equals(EntityType.RABBIT)) {
     return 101;
   } else if (entityType.equals(EntityType.VILLAGER)) {
     return 120;
   } else if (entityType.equals(EntityType.ENDER_CRYSTAL)) {
     return 200;
   }
   return entityType.getTypeId();
 }
示例#7
0
  @EventHandler
  public void onHit(ProjectileHitEvent event) {
    // Get the shooter.
    LivingEntity shooter = event.getEntity().getShooter();

    // Get the entity shot.
    EntityType entity = event.getEntityType();

    // Check if it's a player.
    if (shooter instanceof Player) {
      // Get the Player
      Player player = (Player) shooter;

      // Snowball
      if (entity.equals(EntityType.SNOWBALL)) {
        // Flash grenade.
        if (player.hasPermission("shockpvp.grenade.flash")) {
          Location loc = event.getEntity().getLocation();
          double flashRadius = plugin.getConfig().getDouble("flashradius");
          List<Entity> entities =
              event.getEntity().getNearbyEntities(flashRadius, flashRadius, flashRadius);

          // Simulates explosion
          explodes.add(loc);
          loc.getWorld().createExplosion(loc, .5F);

          // Blind and slow the nearby players.
          for (Entity ents : entities) {
            if (ents instanceof Player) {
              Player victim = (Player) ents;
              victim.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 100, 1));
              victim.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 100, 0));
            }
          }
        }

        /*
         * Concussion grenade.
         * 3F is too large of explosion. Try .5
         */
        if (player.hasPermission("shockpvp.grenade.concussion")) {
          Location loc = event.getEntity().getLocation();
          double flashRadius = plugin.getConfig().getDouble("flashradius");
          List<Entity> entities =
              event.getEntity().getNearbyEntities(flashRadius, flashRadius, flashRadius);

          // Simulates explosion
          explodes.add(loc);
          loc.getWorld().createExplosion(loc, .5F);

          // Daze and slow nearby players.
          for (Entity ents : entities) {
            if (ents instanceof Player) {
              Player victim = (Player) ents;
              victim.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 100, 0));
              victim.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 100, 0));
            }
          }
        }

        // Frag grenade
        // Perfect :D
        if (player.hasPermission("shockpvp.grenade.frag")) {
          Location loc = event.getEntity().getLocation();
          loc.getWorld().createExplosion(loc, 1, false);
        }

        // Smoke grenade
        // Doesn't work
        if (player.hasPermission("shockpvp.grenade.smoke")) ;
        {
          Location loc = event.getEntity().getLocation();
          loc.getWorld().playEffect(loc, Effect.SMOKE, 1000);
        }

        // Decoy grenade
        // Not working
        if (player.hasPermission("shockpvp.grenade.decoy")) ;
        Location loc = event.getEntity().getLocation();
        loc.getWorld().playEffect(loc, Effect.STEP_SOUND, 20);
        loc.getWorld().playEffect(loc, Effect.BOW_FIRE, 10);
      }
    }
  }