Exemple #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();
 }
Exemple #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);
  }
Exemple #3
0
 public static void transferFireworkMetaPower(
     FireworkMeta meta, JsonObject json, boolean meta2json) {
   if (meta2json) {
     json.addProperty(FIREWORK_FLIGHT, meta.getPower());
   } else {
     JsonElement element = json.get(FIREWORK_FLIGHT);
     if (element == null) return;
     meta.setPower(element.getAsInt());
   }
 }
  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);
  }
  /**
   * 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;
 }
Exemple #7
0
 public static void fireWork(Location loc) {
   Firework fw = loc.getWorld().spawn(loc, Firework.class);
   FireworkMeta fm = fw.getFireworkMeta();
   fm.addEffects(
       FireworkEffect.builder()
           .with(FireworkEffect.Type.BALL_LARGE)
           .withColor(Color.RED)
           .withColor(Color.AQUA)
           .withColor(Color.ORANGE)
           .withColor(Color.YELLOW)
           .trail(false)
           .flicker(false)
           .build());
   fm.setPower(0);
   fw.setFireworkMeta(fm);
   detonate(fw);
 }
 /**
  * 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);
 }
  /** 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
  /**
   * 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);
       }
     }
   }
 }
  @Override
  public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (cmd.getName().equalsIgnoreCase("entitymanager") || cmd.getName().equalsIgnoreCase("em")) {
      if (sender.hasPermission("entitymanager.use")) {
        if (args.length == 1) {
          if (args[0].equalsIgnoreCase("findduplicate") || args[0].equalsIgnoreCase("fd")) {
            World world = getWorld(sender);

            if (world == null) {
              message(sender, "&cCould not get world.");
              return true;
            }

            List<UUID> entityUUIDs = new ArrayList<UUID>();
            Map<UUID, Location> duplicateEntities = new HashMap<UUID, Location>();
            for (LivingEntity le : world.getLivingEntities()) {
              if (entityUUIDs.contains(le.getUniqueId())) {
                duplicateEntities.put(le.getUniqueId(), le.getLocation());
              }
              entityUUIDs.add(le.getUniqueId());
            }

            if (duplicateEntities.isEmpty()) {
              sender.sendMessage(ChatColor.RED + "Could not find any duplicate entities.");
            } else {
              String message = "";
              for (Entry<UUID, Location> e : duplicateEntities.entrySet()) {
                message +=
                    "Entity "
                        + e.getKey()
                        + " at x:"
                        + (int) e.getValue().getX()
                        + ", y:"
                        + (int) e.getValue().getY()
                        + ", z:"
                        + (int) e.getValue().getZ()
                        + "\n";
              }

              sender.sendMessage(ChatColor.GREEN + "Duplicate entities:\n" + message);
            }

            return true;
          }
        }

        if (args.length >= 2) {
          if (args[0].equalsIgnoreCase("get")) {
            UUID uuid = UUID.fromString(args[1]);
            if (uuid == null) {
              sender.sendMessage(ChatColor.RED + "Invalid UUID.");
            } else {
              World world = getWorld(sender);

              if (world == null) {
                message(sender, "&cCould not get world.");
                return true;
              }

              for (LivingEntity le : world.getLivingEntities()) {
                if (le.getUniqueId().equals(uuid)) {
                  Location loc = le.getLocation();
                  selectedEntity = le;
                  message(
                      sender,
                      "&aEntity location: x:"
                          + (int) loc.getX()
                          + ", y:"
                          + loc.getY()
                          + ", z:"
                          + loc.getZ());
                  return true;
                }
              }

              message(sender, "&cNo valid entity found.");
            }
          } else if (args[0].equalsIgnoreCase("highlight") || args[0].equalsIgnoreCase("h")) {
            if (selectedEntity == null) {
              message(sender, "&cNo entity selected.");
            } else {
              Firework firework =
                  selectedEntity.getWorld().spawn(selectedEntity.getLocation(), Firework.class);
              FireworkMeta data = (FireworkMeta) firework.getFireworkMeta();
              data.addEffects(
                  FireworkEffect.builder().withColor(Color.LIME).with(Type.BALL).build());
              data.setPower(0);
              firework.setFireworkMeta(data);
              message(sender, "&aEntity highlighted.");
            }
          }
        } else {
          message(sender, "&cInvalid subcommand.");
        }

      } else {
        sender.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
      }

      return true;
    }

    return false;
  }