@Override
 public void Run(Player player, Server server, String[] args) {
   Location spawnLocation = player.getLocation().add(player.getLocation().getDirection());
   Fireball fireball =
       (Fireball) player.getWorld().spawnEntity(spawnLocation, EntityType.FIREBALL);
   fireball.setDirection(player.getLocation().getDirection());
 }
Exemple #2
0
  private void spawnMeteorNaturallyAndRandomly(World world, double x, double z) {
    net.minecraft.server.World meteoriteWorld = ((CraftWorld) world).getHandle();

    EntityMeteor meteor =
        new EntityMeteor(
            meteoriteWorld,
            rand.nextInt(7) + 1,
            10,
            rand.nextInt(5) + 5,
            rand.nextInt(50) + 25,
            100,
            glob.Natural__Disasters_Meteor_Message__On__Meteor__Crash,
            9,
            80,
            glob.Natural__Disasters_Meteor_Shockwave_Damage__Message,
            rand.nextInt(100) + 200,
            glob.Natural__Disasters_Meteor_Meteor_Spawn,
            glob.Natural__Disasters_Meteor_Meteor_Radius);

    meteor.spawn();

    meteor.setPosition(x, rand.nextInt(100) + 156, z);
    meteor.yaw = (float) rand.nextInt(360);
    meteor.pitch = -9;
    meteoriteWorld.addEntity(meteor, SpawnReason.DEFAULT);

    Fireball fireMeteor = (Fireball) meteor.getBukkitEntity();

    fireMeteor.setDirection(fireMeteor.getDirection().setY(-1));
  }
 @Override
 public void castSpell(Player player) {
   // Launch a fireball and make it 2x faster
   Fireball fireball = player.launchProjectile(Fireball.class);
   fireball.setVelocity(fireball.getVelocity().multiply(2));
   SoundHandler.playSound(player, Sound.GHAST_FIREBALL);
   PlayerHandler.sendMessage(player, "&7Pew pew!");
 }
 public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
   if (cmd.getName().equalsIgnoreCase("fireball")) {
     if (!plugin.isAuthorized(cs, "rcmds.fireball")) {
       RUtils.dispNoPerms(cs);
       return true;
     }
     if (!(cs instanceof Player)) {
       cs.sendMessage(ChatColor.RED + "This command is only available to players!");
       return true;
     }
     Player p = (Player) cs;
     // Fireball fb = p.launchProjectile(Fireball.class);
     Vector dir = p.getEyeLocation().getDirection().multiply(2);
     Fireball fb =
         p.getWorld()
             .spawn(p.getEyeLocation().add(dir.getX(), dir.getY(), dir.getZ()), Fireball.class);
     fb.setDirection(dir);
     // fb.teleport(p.getEyeLocation().add(dir.getX(), dir.getY(), dir.getZ()));
     fb.setIsIncendiary(true);
     return true;
   }
   return false;
 }
Exemple #5
0
 public void setPower(float yield) {
   this.yield = yield;
   fireball.setYield(yield);
 }
  @SuppressWarnings("deprecation")
  public void assignMobProps(Entity baseEntity, ISpawnableEntity data) {

    // This needs to be before everything else!
    if (data.getRider() != null) {
      addRider(baseEntity, data.getRider());
    }

    Vector v1 = data.getVelocity(baseEntity);
    Vector v2 = data.getVelocity2(baseEntity);
    if (v2.getX() == 0 && v2.getY() == 0 && v2.getZ() == 0) {
      baseEntity.setVelocity(data.getVelocity(baseEntity).clone());
    } else {
      Vector v3 = randomVector(v1, v2);
      baseEntity.setVelocity(v3.clone());
    }
    baseEntity.setFireTicks(data.getFireTicks(baseEntity));

    if (baseEntity instanceof LivingEntity) {
      LivingEntity entity = (LivingEntity) baseEntity;
      setBasicProps(entity, data);

      if (data.showCustomName()) {
        setCustomName(entity, data);
      }

      if (entity instanceof Ageable) {
        Ageable a = (Ageable) entity;
        setAgeProps(a, data);
      }

      if (entity instanceof Animals) {
        Animals animal = (Animals) entity;

        // Setting animal specific properties
        if (animal instanceof Pig) {
          Pig p = (Pig) animal;
          p.setSaddle(data.isSaddled());
        } else if (animal instanceof Sheep) {
          Sheep s = (Sheep) animal;
          DyeColor color = DyeColor.valueOf(data.getColor());
          s.setColor(color);
        } else if (animal instanceof Wolf) {
          Wolf w = (Wolf) animal;
          w.setAngry(data.isAngry());
          w.setTamed(data.isTamed());
          if (data.isTamed()) {

            ArrayList<Player> nearPlayers = getNearbyPlayers(w.getLocation(), 16);
            int index = (int) Math.round(Math.rint(nearPlayers.size() - 1));
            if (nearPlayers != null) {
              w.setOwner(nearPlayers.get(index));
            }

            w.setSitting(data.isSitting());
          }
        } else if (animal instanceof Ocelot) {
          Ocelot o = (Ocelot) animal;
          o.setTamed(data.isTamed());
          if (data.isTamed()) {
            Ocelot.Type catType = Ocelot.Type.valueOf(data.getCatType());
            o.setCatType(catType);

            ArrayList<Player> nearPlayers = getNearbyPlayers(o.getLocation(), 16);
            int index = (int) Math.round(Math.rint(nearPlayers.size() - 1));
            if (nearPlayers != null) {
              o.setOwner(nearPlayers.get(index));
            }

            o.setSitting(data.isSitting());
          }
        }
      } else if (entity instanceof Villager) {
        Villager v = (Villager) entity;
        v.setAge(data.getAge(baseEntity));
        v.setProfession(data.getProfession());
      } else if (entity instanceof Monster) {
        Monster monster = (Monster) entity;

        // Setting monster specific properties.
        if (monster instanceof Enderman) {
          Enderman e = (Enderman) monster;
          e.setCarriedMaterial(data.getEndermanBlock());
        } else if (monster instanceof Creeper) {
          Creeper c = (Creeper) monster;
          c.setPowered(data.isCharged());
        } else if (monster instanceof PigZombie) {
          PigZombie p = (PigZombie) monster;
          if (data.isAngry()) {
            p.setAngry(true);
          }
          p.setBaby((data.getAge(baseEntity) < -1) ? true : false);
        } else if (monster instanceof Spider) {
          Spider s = (Spider) monster;
          if (data.isJockey()) {
            makeJockey(s, data);
          }
        } else if (monster instanceof Zombie) {
          Zombie z = (Zombie) monster;
          boolean isVillager = false;
          if (data.hasProp("zombie")) {
            isVillager = (Boolean) (data.getProp("zombie"));
          }
          z.setBaby((data.getAge(baseEntity) < -1) ? true : false);
          z.setVillager(isVillager);
        } else if (monster instanceof Skeleton) {
          Skeleton sk = (Skeleton) monster;
          SkeletonType skType = SkeletonType.NORMAL;

          if (data.hasProp("wither")) {
            skType =
                ((Boolean) (data.getProp("wither")) == true)
                    ? SkeletonType.WITHER
                    : SkeletonType.NORMAL;
          }

          sk.setSkeletonType(skType);
        }
      } else if (entity instanceof Golem) {
        Golem golem = (Golem) entity;

        if (golem instanceof IronGolem) {
          IronGolem i = (IronGolem) golem;
          if (data.isAngry()) {
            ArrayList<Player> nearPlayers = getNearbyPlayers(i.getLocation(), 16);
            int index = (int) Math.round(Math.rint(nearPlayers.size() - 1));
            if (nearPlayers != null) {
              i.setPlayerCreated(false);
              i.damage(0, nearPlayers.get(index));
              i.setTarget(nearPlayers.get(index));
            }
          }
        }
        // Some are not classified as animals or monsters
      } else if (entity instanceof Slime) {
        Slime s = (Slime) entity;
        s.setSize(data.getSlimeSize());
      } else if (entity instanceof MagmaCube) {
        MagmaCube m = (MagmaCube) entity;
        m.setSize(data.getSlimeSize());
      }

    } else if (baseEntity instanceof Projectile) {
      Projectile pro = (Projectile) baseEntity;

      // Eventually add explosive arrows and such :D

      if (pro instanceof Fireball) {
        Fireball f = (Fireball) pro;
        setExplosiveProps(f, data);
        f.setVelocity(new Vector(0, 0, 0));
        f.setDirection(data.getVelocity(baseEntity));
      } else if (pro instanceof SmallFireball) {
        SmallFireball f = (SmallFireball) pro;
        setExplosiveProps(f, data);
        f.setVelocity(new Vector(0, 0, 0));
        f.setDirection(data.getVelocity(baseEntity));
      }

    } else if (baseEntity instanceof Explosive) {

      Explosive ex = (Explosive) baseEntity;

      if (ex instanceof TNTPrimed) {
        TNTPrimed tnt = (TNTPrimed) ex;
        setExplosiveProps(tnt, data);
        tnt.setFuseTicks(data.getFuseTicks(baseEntity));
      }

    } else if (baseEntity instanceof Firework) {

      Firework f = (Firework) baseEntity;
      ItemMeta meta = data.getItemType().getItemMeta();
      if (meta != null) {
        if (meta instanceof FireworkMeta) {
          FireworkMeta fMeta = (FireworkMeta) meta;
          if (fMeta != null) {
            f.setFireworkMeta(fMeta);
          }
        }
      }

    } else if (baseEntity instanceof Minecart) {

      Minecart m = (Minecart) baseEntity;
      if (data.hasProp("minecartSpeed")) {
        m.setMaxSpeed((Double) data.getProp("minecartSpeed"));
      }

    } else if (baseEntity instanceof ExperienceOrb) {
      ExperienceOrb o = (ExperienceOrb) baseEntity;
      o.setExperience(data.getDroppedExp(baseEntity));
    }

    setNBT(baseEntity, data);
  }
Exemple #7
0
  public double prepareAttacker(EntityDamageByEntityEvent e) {
    // Variable Declarations/Initializations
    Arrow arrow = null;
    List<Spell> spellBook = null;
    double damage = 0;
    rpgMobAttacker = null;

    // Determine what the source of damage was.
    if (e.getDamager() instanceof Egg) {
      cancelRpgDamage = true;
      return 0;
    } else if (e.getDamager() instanceof Fish) {
      cancelRpgDamage = true;
      return 0;
    } else if (e.getDamager() instanceof Snowball) {
      cancelRpgDamage = true;
      return 0;
    } else if (e.getDamager() instanceof Fireball) {
      boolean success = false;

      Fireball fb = (Fireball) (e.getDamager());

      if (fb.getShooter() == e.getEntity()) {
        cancelRpgDamage = true;
        return 0;
      }

      if (e.getEntity() instanceof Fireball || e.getEntity() instanceof LargeFireball) {
        cancelRpgDamage = true;
        return 0;
      }

      for (RpgPlayer rpgPlayer : FC_Rpg.rpgEntityManager.getOnlineRpgPlayers()) {
        if (rpgPlayer.summon_Owns(e.getDamager())) {
          // Variable Initializations
          rpgAttacker = rpgPlayer;
          spellBook = rpgAttacker.playerConfig.getRpgClass().getSpellBook();
          damageType = 2;

          for (int i = 0; i < spellBook.size(); i++) {
            if (spellBook.get(i).effectID == SpellEffect.FIREBALL.getID()) {
              SpellCaster sc = new SpellCaster();
              damage =
                  sc.updatefinalSpellMagnitude(
                      rpgAttacker,
                      spellBook.get(i),
                      (rpgAttacker.playerConfig.getSpellLevels().get(i) - 1));
              break;
            }
          }

          success = true;
          break;
        }
      }

      if (success == false) {
        cancelRpgDamage = true;
        return 0;
      }
    } else if (e.getDamager() instanceof Arrow) {
      // Set damage type to arrow
      damageType = 1;

      // Store the arrow.
      arrow = (Arrow) e.getDamager();

      // If the player shot the arrow, set damage to player stuff.
      if (arrow.getShooter() instanceof Player) {
        // Store the attacker
        playerAttacker = (Player) arrow.getShooter();
        rpgAttacker = FC_Rpg.rpgEntityManager.getRpgPlayer(playerAttacker);
      } else {
        // Set the creature attacker.
        creatureAttacker = arrow.getShooter();

        // Get the shooter entity monster and store.
        rpgMobAttacker = FC_Rpg.rpgEntityManager.getRpgMonster(arrow.getShooter());

        // Set the damage to the monsters strength.
        if (rpgMobAttacker != null)
          damage = rpgMobAttacker.getAttack() * FC_Rpg.balanceConfig.getPlayerStatMagnitudeAttack();
      }

      // Remove all arrows.
      arrow.remove();
    } else if (e.getDamager() instanceof LightningStrike) {
      // Initialize rpgMobAttacker;
      rpgMobAttacker = new RpgMonster();

      damage = rpgMobAttacker.getAttack() * FC_Rpg.balanceConfig.getPlayerStatMagnitudeAttack();
    }

    // Melee player attacks
    else if (e.getDamager() instanceof Player) {
      // Store the attacker
      playerAttacker = (Player) e.getDamager();
      rpgAttacker = FC_Rpg.rpgEntityManager.getRpgPlayer(playerAttacker);
    }

    // If the entity is a living entity we want to store it.
    else if (e.getDamager() instanceof LivingEntity) {
      // Set creature attacker.
      creatureAttacker = (LivingEntity) e.getDamager();

      // Initialize rpgMobAttacker;
      rpgMobAttacker = FC_Rpg.rpgEntityManager.getRpgMonster(creatureAttacker);

      damage = rpgMobAttacker.getAttack() * FC_Rpg.balanceConfig.getPlayerStatMagnitudeAttack();

      if (creatureAttacker.getEquipment().getItemInHand() != null)
        damage =
            damage
                * FC_Rpg.battleCalculations.getWeaponModifier(
                    creatureAttacker.getEquipment().getItemInHand(), 999999);
    }

    // Else if not it's an error and return the monster strength.
    else {
      FC_Rpg.plugin
          .getLogger()
          .info("Error: PrepareAttacker(), undefined entity type: " + e.getDamager().toString());

      // Initialize rpgMobAttacker;
      rpgMobAttacker = new RpgMonster();

      damage = rpgMobAttacker.getAttack() * FC_Rpg.balanceConfig.getPlayerStatMagnitudeAttack();
    }

    // Cancel damage for stunned stuff.
    if (rpgAttacker != null) {
      // If disabled cancel attack
      if (rpgAttacker.playerConfig.getStatusActiveRpgPlayer(SpellEffect.DISABLED.getID())) {
        cancelRpgDamage = true;
        return 0;
      }

      // Set damage of arrows.
      damage = rpgAttacker.getTotalAttack() * FC_Rpg.balanceConfig.getPlayerStatMagnitudeAttack();

      // Add weapon Bonus
      damage *=
          FC_Rpg.battleCalculations.getWeaponModifier(
              playerAttacker.getItemInHand(), rpgAttacker.getTotalAttack());

      // If the player has the attack buff, then...
      if (rpgAttacker.playerConfig.getStatusActiveRpgPlayer(SpellEffect.DAMAGE_BONUS.getID()))
        damage *= rpgAttacker.playerConfig.getStatusMagnitude(SpellEffect.DAMAGE_BONUS.getID());
    } else if (rpgMobAttacker != null) {
      if (rpgMobAttacker.getStatusActiveEntity(rpgMobAttacker.getStatusDisabled())) {
        cancelRpgDamage = true;
        return 0;
      }
    } else if (rpgAttacker == null) {
      MessageLib msgLib = new MessageLib(playerAttacker);
      msgLib.standardMessage("You need to pick a class before you can fight.");

      cancelRpgDamage = true;
      return 0;
    }

    return damage;
  }
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onBlockDispense(BlockDispenseEvent event) {
    Block block = event.getBlock();
    if (block.getType() == Material.DISPENSER) {

      Cannon cannon = plugin.getCannon(block, false);
      if (cannon == null) {
        return;
      }

      Material material = event.getItem().getType();

      Grenade grenade = plugin.getArmageddonConfig().getGrenade(material);

      if (grenade.getType() == Type.DUD || !grenade.isCannonUse()) {
        return;
      }

      Dispenser dispenser = (Dispenser) block.getType().getNewData(block.getData());

      double vx = cannon.getVelocity() * Math.cos((double) (Math.PI * cannon.getAngle() / 180));
      double y = cannon.getVelocity() * Math.sin((double) (Math.PI * cannon.getAngle() / 180));

      double x = 0;
      double z = 0;

      int yaw = 0;

      switch (dispenser.getFacing()) {
        case NORTH:
          x = -vx;
          yaw = 90;
          break;

        case SOUTH:
          x = vx;
          yaw = 270;
          break;

        case WEST:
          z = vx;
          yaw = 0;
          break;

        case EAST:
          z = -vx;
          yaw = 180;
          break;
      }

      Vector initialVelocity = new Vector(x, y, z);
      Location location = block.getRelative(dispenser.getFacing()).getLocation().add(0.5, 0.5, 0.5);
      World world = block.getWorld();

      Entity entity = null;

      x = location.getX();
      y = location.getY();
      z = location.getZ();

      Location locClone = location.clone();

      switch (grenade.getType()) {
        case PIG:
          entity = world.spawn(location, Pig.class);
          break;

        case COW:
          entity = world.spawn(location, Cow.class);
          break;

        case SHEEP:
          entity = world.spawn(location, Sheep.class);
          break;

        case TNT:
          entity = world.spawn(location, TNTPrimed.class);
          ((TNTPrimed) entity).setFuseTicks(cannon.getFuse());
          break;

        case EXPLOSIVE:
        case NUCLEAR:
        case WATER_BALLOON:
        case SPIDER_WEB:
        case SNARE:
        case STUN:
          entity = world.spawn(location, Snowball.class);
          break;

        case MOLOTOV:
          locClone.setPitch(0);
          locClone.setYaw(yaw);
          entity = world.spawn(locClone, Fireball.class);
          LivingEntity owner = plugin.getServer().getPlayer(cannon.getOwner());
          if (owner == null) {
            // get the closest living entity
            double distance = Double.MAX_VALUE;
            for (LivingEntity e : world.getLivingEntities()) {
              if (e.getLocation().distance(locClone) < distance) {
                distance = e.getLocation().distance(locClone);
                owner = e;
              }
            }
          }
          ((Fireball) entity).setShooter(owner);
          break;

        default:
          return;
      }

      if (entity != null) {
        if (!(entity instanceof Fireball)) {
          entity.setVelocity(initialVelocity);
        }

        if (!(entity instanceof LivingEntity)) {
          plugin.registerGrenade(entity, grenade);
        }

        plugin.adjustInventoryAndUsage(
            ((org.bukkit.block.Dispenser) block.getState()).getInventory(),
            cannon,
            material,
            grenade.getUses());

        event.setCancelled(true);
        world.createExplosion(location, 0);
      }
    }
  }