示例#1
0
 public static void detonateFirework(Location loc, FireworkEffect effects) {
   World world = loc.getWorld();
   Firework firework = (Firework) world.spawnEntity(loc, EntityType.FIREWORK);
   // Credit to codename_B
   Object nms_world = null;
   Object nms_firework = null;
   if (world_getHandle == null) {
     world_getHandle = getMethod(world.getClass(), "getHandle");
     firework_getHandle = getMethod(firework.getClass(), "getHandle");
   }
   try {
     nms_world = world_getHandle.invoke(world, (Object[]) null);
     nms_firework = firework_getHandle.invoke(firework, (Object[]) null);
   } catch (InvocationTargetException e) {
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     e.printStackTrace();
   }
   if (nms_world_broadcastEntityEffect == null) {
     nms_world_broadcastEntityEffect = getMethod(nms_world.getClass(), "broadcastEntityEffect");
   }
   FireworkMeta data = (FireworkMeta) firework.getFireworkMeta();
   data.clearEffects();
   data.setPower(1);
   data.addEffect(effects);
   firework.setFireworkMeta(data);
   try {
     nms_world_broadcastEntityEffect.invoke(nms_world, new Object[] {nms_firework, (byte) 17});
   } catch (IllegalAccessException e) {
     e.printStackTrace();
   } catch (InvocationTargetException e) {
     e.printStackTrace();
   }
   firework.remove();
 }
示例#2
0
  private static void spawnFireworks(Player player) {
    int power = (int) (Math.random() * 3) + 1;
    int type = (int) (Math.random() * 5) + 1;

    Type typen = Type.BALL;
    if (type == 1) typen = Type.BALL;
    if (type == 2) typen = Type.BALL_LARGE;
    if (type == 3) typen = Type.BURST;
    if (type == 4) typen = Type.CREEPER;
    if (type == 5) typen = Type.STAR;

    Firework fireworks =
        (Firework) player.getWorld().spawnEntity(player.getLocation(), EntityType.FIREWORK);
    FireworkMeta fireworkmeta = fireworks.getFireworkMeta();
    FireworkEffect effect =
        FireworkEffect.builder()
            .flicker(Misc.getRandom().nextBoolean())
            .withColor(colorchoose())
            .withFade(colorchoose())
            .with(typen)
            .trail(Misc.getRandom().nextBoolean())
            .build();
    fireworkmeta.addEffect(effect);
    fireworkmeta.setPower(power);
    fireworks.setFireworkMeta(fireworkmeta);
  }
示例#3
0
 public static void shootFirework(Player p) {
   Firework fw = (Firework) p.getWorld().spawn(p.getLocation(), Firework.class);
   FireworkMeta fwMeta = fw.getFireworkMeta();
   boolean flicker = Math.random() < 0.5;
   boolean trail = Math.random() < 0.5;
   fwMeta.addEffect(
       FireworkEffect.builder()
           .withColor(colors[new Random().nextInt(colors.length)])
           .flicker(flicker)
           .trail(trail)
           .build());
   fw.setFireworkMeta(fwMeta);
 }
示例#4
0
  protected void spawnFirework(Location location) {
    List<Location> smokeLocations = new ArrayList<Location>();
    smokeLocations.add(location);
    smokeLocations.add(location.clone().add(0, 1, 0));
    SmokeUtil.spawnCloudRandom(smokeLocations, 3);

    Firework fw = (Firework) location.getWorld().spawnEntity(location, EntityType.FIREWORK);
    FireworkMeta fwm = fw.getFireworkMeta();

    fwm.addEffect(FireworkEffect.builder().withColor(Color.BLACK).with(Type.BURST).build());
    fwm.setPower(1);
    fw.setFireworkMeta(fwm);
  }
示例#5
0
  /**
   * Generates a Firework with random colors/velocity and the given Firework Type
   *
   * @param type The type of firework
   */
  public void fireWorkRandomColors(FireworkEffect.Type type, Location location) {
    Firework firework = (Firework) location.getWorld().spawnEntity(location, EntityType.FIREWORK);
    FireworkMeta fireworkMeta = firework.getFireworkMeta();

    // Generate the colors
    int rdmInt1 = plugin.getRandom().nextInt(255);
    int rdmInt2 = plugin.getRandom().nextInt(255);
    int rdmInt3 = plugin.getRandom().nextInt(255);
    Color mainColor = Color.fromRGB(rdmInt1, rdmInt2, rdmInt3);

    FireworkEffect fwEffect = FireworkEffect.builder().withColor(mainColor).with(type).build();
    fireworkMeta.addEffect(fwEffect);
    fireworkMeta.setPower(1);
    firework.setFireworkMeta(fireworkMeta);
  }
 /**
  * Make a packet object
  *
  * @param location Location to play firework effect at
  * @param fireworkEffect FireworkEffect to play
  * @return Packet constructed by the parameters
  */
 private static Object makePacket(Location location, FireworkEffect fireworkEffect) {
   try {
     Firework firework = location.getWorld().spawn(location, Firework.class);
     FireworkMeta data = firework.getFireworkMeta();
     data.clearEffects();
     data.setPower(1);
     data.addEffect(fireworkEffect);
     firework.setFireworkMeta(data);
     Object nmsFirework = ReflectionUtil.getHandle(firework);
     firework.remove();
     return PACKET_PLAY_OUT_ENTITY_STATUS.newInstance(nmsFirework, (byte) 17);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
 /**
  * Play a pretty firework at the location with the FireworkEffect when called
  *
  * @param world
  * @param loc
  * @param fe
  * @throws Exception
  */
 public static void playFirework(World world, Location loc, FireworkEffect fe) throws Exception {
   // Bukkity load (CraftFirework)
   Firework fw = (Firework) world.spawn(loc, Firework.class);
   // the net.minecraft.server.World
   Object nms_world = null;
   Object nms_firework = null;
   /*
    * The reflection part, this gives us access to funky ways of messing
    * around with things
    */
   if (world_getHandle == null) {
     // get the methods of the craftbukkit objects
     world_getHandle = getMethod(world.getClass(), "getHandle");
     firework_getHandle = getMethod(fw.getClass(), "getHandle");
   }
   // invoke with no arguments
   nms_world = world_getHandle.invoke(world, (Object[]) null);
   nms_firework = firework_getHandle.invoke(fw, (Object[]) null);
   // null checks are fast, so having this seperate is ok
   if (nms_world_broadcastEntityEffect == null) {
     // get the method of the nms_world
     nms_world_broadcastEntityEffect = getMethod(nms_world.getClass(), "broadcastEntityEffect");
   }
   /*
    * Now we mess with the metadata, allowing nice clean spawning of a
    * pretty firework (look, pretty lights!)
    */
   // metadata load
   FireworkMeta data = (FireworkMeta) fw.getFireworkMeta();
   // clear existing
   data.clearEffects();
   // power of one
   data.setPower(1);
   // add the effect
   data.addEffect(fe);
   // set the meta
   fw.setFireworkMeta(data);
   /*
    * Finally, we broadcast the entity effect then kill our fireworks
    * object
    */
   // invoke with arguments
   nms_world_broadcastEntityEffect.invoke(nms_world, new Object[] {nms_firework, (byte) 17});
   // remove from the game
   fw.remove();
 }
 public static void shootRandomFirework(Location loc, int height) {
   Firework f = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK);
   FireworkMeta fm = f.getFireworkMeta();
   fm.setPower(height);
   int effectAmount = random.nextInt(3) + 1;
   for (int i = 0; i < effectAmount; i++) {
     Builder b = FireworkEffect.builder();
     int colorAmount = random.nextInt(3) + 1;
     for (int ii = 0; ii < colorAmount; ii++) {
       b.withColor(Color.fromBGR(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
     }
     b.with(Type.values()[random.nextInt(Type.values().length)]);
     b.flicker(random.nextInt(2) == 0 ? false : true);
     b.trail(random.nextInt(2) == 0 ? false : true);
     fm.addEffect(b.build());
   }
   f.setFireworkMeta(fm);
 }
	@Override
	public boolean applyResult(final Player player) {
		if (player == null)
			return false;

		final Location loc = (target.equals("player")) ? player.getLocation() : player.getWorld().getSpawnLocation();

		final Firework fw = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK);
		final FireworkMeta fwm = fw.getFireworkMeta();
		final FireworkEffect effect = FireworkEffect.builder().withColor(colour).with(type).build();

		fwm.addEffect(effect);
		fwm.setPower(power);

		fw.setFireworkMeta(fwm);

		player.teleport(location);
		return location != null;
	}
 @Override
 public void createFireworksExplosion(
     Location location,
     boolean flicker,
     boolean trail,
     int type,
     int[] colors,
     int[] fadeColors,
     int flightDuration) {
   FireworkEffect.Type t = Type.BALL;
   if (type == 1) {
     t = Type.BALL_LARGE;
   } else if (type == 2) {
     t = Type.STAR;
   } else if (type == 3) {
     t = Type.CREEPER;
   } else if (type == 4) {
     t = Type.BURST;
   }
   Color[] c1 = new Color[colors.length];
   for (int i = 0; i < colors.length; i++) {
     c1[i] = Color.fromRGB(colors[i]);
   }
   Color[] c2 = new Color[fadeColors.length];
   for (int i = 0; i < fadeColors.length; i++) {
     c2[i] = Color.fromRGB(fadeColors[i]);
   }
   FireworkEffect effect =
       FireworkEffect.builder()
           .flicker(flicker)
           .trail(trail)
           .with(t)
           .withColor(c1)
           .withFade(c2)
           .build();
   Firework firework = location.getWorld().spawn(location, Firework.class);
   FireworkMeta meta = firework.getFireworkMeta();
   meta.addEffect(effect);
   meta.setPower(flightDuration < 1 ? 1 : flightDuration);
   firework.setFireworkMeta(meta);
 }
示例#11
0
  /** On creeper death, drop fireworks and heads with a configurable chance. */
  @EventHandler(ignoreCancelled = true)
  public void onCreeperDeath(EntityDeathEvent event) {
    if (!CONFIG.isAffectedWorld(event)) {
      return;
    }

    Entity entity = event.getEntity();
    if (entity.getType() == EntityType.CREEPER && entity.hasMetadata(SPECIAL_KEY)) {
      Creeper creeper = (Creeper) entity;

      // Require recent player damage on the creeper for special drops.
      Long damageTime = getPlayerDamageTime(entity);
      if (damageTime != null) {
        Location loc = creeper.getLocation();
        if (loc.getWorld().getFullTime() - damageTime < PLAYER_DAMAGE_TICKS) {
          if (Math.random() < CONFIG.FIREWORK_DROP_CHANCE) {
            // Replace the default drops.
            event.getDrops().clear();
            final int amount = random(CONFIG.MIN_FIREWORK_DROPS, CONFIG.MAX_FIREWORK_DROPS);
            for (int i = 0; i < amount; ++i) {
              ItemStack firework = new ItemStack(Material.FIREWORK);
              FireworkMeta meta = (FireworkMeta) firework.getItemMeta();
              meta.setPower(random(0, 3));
              meta.addEffect(randomFireworkFffect(false));
              firework.setItemMeta(meta);
              event.getDrops().add(firework);
            }
          }

          // Powered creepers may drop a creeper skull in addition to
          // fireworks.
          if (creeper.isPowered() && Math.random() < CONFIG.CHARGED_CREEPER_SKULL_CHANCE) {
            event.getDrops().add(new ItemStack(Material.SKULL_ITEM, 1, (short) 4));
          }
        }
      }
    }
  } // onCreeperDeath
示例#12
0
  /**
   * Event handler called when an explosive is primed.
   *
   * <p>We use it to detect impending creeper explosions. The event is fired immediately before the
   * explosion.
   */
  @EventHandler(ignoreCancelled = true)
  public void onCreeperDetonate(ExplosionPrimeEvent event) {
    if (!CONFIG.isAffectedWorld(event)) {
      return;
    }

    if (event.getEntityType() == EntityType.CREEPER) {
      event.setRadius((float) CONFIG.BLAST_RADIUS_SCALE * event.getRadius());

      Entity creeper = event.getEntity();
      launchReinforcements(creeper);

      Location origin = creeper.getLocation();
      World world = origin.getWorld();
      Firework firework = (Firework) world.spawnEntity(origin, EntityType.FIREWORK);
      if (firework != null) {
        FireworkMeta meta = firework.getFireworkMeta();
        meta.setPower(random(0, 1));
        meta.addEffect(randomFireworkFffect(true));
        firework.setFireworkMeta(meta);
      }
    }
  }
 @Override
 public void run() {
   if ((Boolean) Setting.BEACONS.getSetting()) {
     if (game == null || game.getFakeBeaconThread() != this) {
       cancel();
       return;
     }
     if (game.getActiveMysteryChest() == null) {
       List<MysteryBox> chests = game.getObjectsOfType(MysteryBox.class);
       if (chests.size() > 0) {
         game.setActiveMysteryChest(chests.get(rand.nextInt(chests.size())));
       }
     }
     if (game.hasStarted() && game.getActiveMysteryChest() != null) {
       if (active == null
           || !BukkitUtility.locationMatch(
               game.getActiveMysteryChest().getLocation(), active.getLocation())) {
         active = game.getActiveMysteryChest();
         fireLocations = getFiringLocations(active.getLocation());
       }
       for (Location l : fireLocations) {
         Builder effect =
             FireworkEffect.builder()
                 .trail(true)
                 .flicker(false)
                 .withColor(Color.BLUE)
                 .with(Type.BURST);
         Firework work = l.getWorld().spawn(l, Firework.class);
         EntityExplode.preventExplosion(work.getUniqueId(), true);
         FireworkMeta meta = work.getFireworkMeta();
         meta.addEffect(effect.build());
         meta.setPower(5);
         work.setFireworkMeta(meta);
       }
     }
   }
 }
示例#14
0
  @Override
  public void run() {
    if (complete) return;

    // Log.debug((NumberUtil.randomBoolean() ? "tick" : "tock"));
    Rotation rotation = Rotation.get();
    RotationSlot next = rotation.getNext();

    rotation.setRestart();
    if (!rotation.isRestarting()) {
      next.load(true);
    }

    this.next = next;
    String what = getMessage();
    ChatColor colour = ChatColor.GRAY;
    if (next != null) {
      colour = ChatColor.DARK_AQUA;
    }

    try {
      List<User> players = match.getMap().getWinner().getPlayers();
      if (players.size() > 0 && isFullSecond()) { // check for more than 1 player
        User player = players.get(NumberUtil.getRandom(0, players.size() - 1));

        Location location = player.getPlayer().getLocation();
        Firework firework =
            (Firework) location.getWorld().spawnEntity(location, EntityType.FIREWORK);
        FireworkMeta meta = firework.getFireworkMeta();
        meta.clearEffects();
        meta.addEffect(getFirework());
        firework.setFireworkMeta(meta);

        try {
          firework.detonate();
        } catch (Exception e) {
          Log.warning(
              "Server isn't running a version of Bukkit which allows the use of Firework.detonate() - resorting to manual detonation.");
          try {
            Object craft = NMSUtil.getClassBukkit("entity.CraftFirework").cast(firework);
            Method method = craft.getClass().getMethod("getHandle");
            method.setAccessible(true);
            Object handle = method.invoke(craft);
            handle.getClass().getField("expectedLifespan").set(handle, 0);
          } catch (Exception e2) {
            e2.printStackTrace();
          }
        }
      }
    } catch (NullPointerException ignored) {

    }

    if (duration <= 0 && next == null) {
      for (User player : User.getUsers()) {
        player.getPlayer().kickPlayer(ChatColor.GREEN + "Server restarting!");
      }

      complete = true;
      Bukkit.getServer().shutdown();
      return;
    }

    if (duration <= 0) {
      broadcast(what + "!");
      match.stop();
      complete = true;
      rotation.cycle();
      return;
    }

    boolean show = false;
    if (getTicks() % 20 == 0) {
      if (getSeconds() % 30 == 0) show = true;
      else if (getSeconds() < 30 && getSeconds() % 15 == 0) show = true;
      else if (getSeconds() < 15 && getSeconds() % 5 == 0) show = true;
      else if (getSeconds() < 5) show = true;
    }

    if (show)
      broadcast(
          what
              + " in "
              + ChatColor.RED
              + getSeconds()
              + " second"
              + (getSeconds() != 1 ? "s" : "")
              + colour
              + "!");
    setTicks(getTicks() - 1);
  }