コード例 #1
0
 @Override
 public void onBlockDispense(BlockDispenseEvent event) {
   for (Field field : plugin.fields) {
     if (field.enableDispense && field.inField(event.getBlock().getLocation(), event.getItem())) {
       Vector v =
           new Vector(0, .2, -1)
               .multiply(
                   field
                       .dispensePower); // event.getVelocity().normalize().multiply(field.dispensePower);
       event.setVelocity(v);
       return;
     }
   }
 }
コード例 #2
0
  /*
   * Called when a block is damaged.
   */
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onBlockDispense(BlockDispenseEvent event) {
    ConfigurationManager cfg = plugin.getGlobalStateManager();
    WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());

    if (wcfg.blockPotions.size() > 0) {
      ItemStack item = event.getItem();
      if (item.getType() == Material.POTION && !BukkitUtil.isWaterPotion(item)) {
        Potion potion = Potion.fromDamage(BukkitUtil.getPotionEffectBits(item));
        for (PotionEffect effect : potion.getEffects()) {
          if (potion.isSplash() && wcfg.blockPotions.contains(effect.getType())) {
            event.setCancelled(true);
            return;
          }
        }
      }
    }
  }
コード例 #3
0
  @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);
      }
    }
  }