Esempio n. 1
0
  @Override
  public boolean onDamageOther(EntityDamageByEntityEvent e, Player p, int level) {
    if (e.getEntity() instanceof LivingEntity) {
      LivingEntity le = (LivingEntity) e.getEntity();

      try {
        fireworks.playFirework(
            le.getWorld(),
            le.getLocation(),
            FireworkEffect.builder().with(Type.BURST).withColor(Color.WHITE).build());
      } catch (Exception ex) {
        Logger.getLogger(Burst.class.getName()).log(Level.SEVERE, null, ex);
      }

      Vector unitVector =
          le.getLocation().toVector().subtract(e.getDamager().getLocation().toVector()).normalize();

      unitVector.setY(0.55 / level);

      le.setVelocity(unitVector.multiply(level * 2));

      e.setCancelled(true);

      return true;
    }
    return false;
  }
Esempio n. 2
0
  /**
   * Return a random firework effect.
   *
   * @param boolean allowCreeperType if true, creeper shaped firework explosion types are allowed.
   * @return a FireworkEffect instance.
   */
  protected FireworkEffect randomFireworkFffect(boolean allowCreeperType) {
    FireworkEffect.Builder builder = FireworkEffect.builder();
    if (Math.random() < 0.3) {
      builder.withFlicker();
    }
    if (Math.random() < 0.3) {
      builder.withTrail();
    }

    final FireworkEffect.Type[] TYPES =
        allowCreeperType ? FireworkEffect.Type.values() : NON_CREEPER_FIREWORK_TYPES;
    builder.with(TYPES[random(0, TYPES.length - 1)]);

    final int primaryColors = random(1, 4);
    for (int i = 0; i < primaryColors; ++i) {
      builder.withColor(Color.fromRGB(random(0, 255), random(0, 255), random(0, 255)));
    }

    final int fadeColors = random(1, 4);
    for (int i = 0; i < fadeColors; ++i) {
      builder.withFade(Color.fromRGB(random(0, 255), random(0, 255), random(0, 255)));
    }

    return builder.build();
  }
Esempio n. 3
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);
  }
Esempio n. 4
0
 public FireworkEffect getFireworkEffect(
     Color one, Color two, Color three, Color four, Color five, Type type) {
   return FireworkEffect.builder()
       .flicker(false)
       .withColor(one, two, three, four)
       .withFade(five)
       .with(type)
       .trail(true)
       .build();
 }
 private void launchExplodeFirework(Location loc) {
   FireworkEffect fe =
       FireworkEffect.builder()
           .withColor(Color.ORANGE)
           .withColor(Color.YELLOW)
           .flicker(true)
           .with(Type.BURST)
           .build();
   TaskMaster.syncTask(new FireWorkTask(fe, loc.getWorld(), loc, 3), 0);
 }
Esempio n. 6
0
  public void fancyDestroyStructureBlocks() {
    for (BlockCoord coord : this.structureBlocks.keySet()) {

      if (CivGlobal.getStructureChest(coord) != null) {
        continue;
      }

      if (CivGlobal.getStructureSign(coord) != null) {
        continue;
      }

      if (ItemManager.getId(coord.getBlock()) == CivData.BEDROCK
          || ItemManager.getId(coord.getBlock()) == CivData.AIR) {
        // Be a bit more careful not to destroy any of the item frames..
        continue;
      }

      Random rand = new Random();

      // Each block has a 10% chance to turn into gravel
      if (rand.nextInt(100) <= 10) {
        ItemManager.setTypeId(coord.getBlock(), CivData.GRAVEL);
        continue;
      }

      // Each block has a 50% chance of starting a fire
      if (rand.nextInt(100) <= 50) {
        ItemManager.setTypeId(coord.getBlock(), CivData.FIRE);
        continue;
      }

      // Each block has a 1% chance of launching an explosion effect
      if (rand.nextInt(100) <= 1) {
        FireworkEffect effect =
            FireworkEffect.builder()
                .with(org.bukkit.FireworkEffect.Type.BURST)
                .withColor(Color.ORANGE)
                .withColor(Color.RED)
                .withTrail()
                .withFlicker()
                .build();
        FireworkEffectPlayer fePlayer = new FireworkEffectPlayer();
        for (int i = 0; i < 3; i++) {
          try {
            fePlayer.playFirework(coord.getBlock().getWorld(), coord.getLocation(), effect);
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }
    }
  }
Esempio n. 7
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);
 }
Esempio n. 8
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);
  }
  @Override
  public void run() {
    timesRan++;

    Location lFx = l;
    lFx.add(0, 2 * timesRan, 0);

    if (timesRan == 0) {

    } else if (timesRan == 5) {
      try {
        fireworks.playFirework(
            lFx.getWorld(),
            lFx,
            FireworkEffect.builder()
                .with(FireworkEffect.Type.CREEPER)
                .withColor(Color.GREEN)
                .build());
      } catch (Exception ex) {
        // Gracefully downgrade
      }

      plugin.bossManager.hatchBossAtLocation(l);

      this.cancel();

      return;
    }

    try {
      fireworks.playFirework(
          lFx.getWorld(),
          lFx,
          FireworkEffect.builder().with(FireworkEffect.Type.BALL).withColor(Color.PURPLE).build());
    } catch (Exception ex) {
      // Gracefully downgrade
    }
  }
Esempio n. 10
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);
  }
  private void launchExplodeFirework(Location loc) {
    Random rand = new Random();
    int rand1 = rand.nextInt(100);

    if (rand1 > 90) {
      FireworkEffect fe =
          FireworkEffect.builder()
              .withColor(Color.ORANGE)
              .withColor(Color.YELLOW)
              .flicker(true)
              .with(Type.BURST)
              .build();
      TaskMaster.syncTask(new FireWorkTask(fe, loc.getWorld(), loc, 3), 0);
    }
  }
Esempio n. 12
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);
 }
Esempio n. 13
0
 public static void detonateFirework(
     Location loc,
     boolean flicker,
     boolean trail,
     FireworkEffect.Type type,
     Iterable<Color> colours,
     Iterable<Color> fades) {
   detonateFirework(
       loc,
       FireworkEffect.builder()
           .flicker(flicker)
           .trail(trail)
           .with(type)
           .withColor(colours)
           .withFade(fades)
           .build());
 }
Esempio n. 14
0
 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);
 }
Esempio n. 15
0
	@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);
 }
 @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);
       }
     }
   }
 }
Esempio n. 18
0
  @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;
  }
Esempio n. 19
0
  public void onControlBlockDestroy(
      ControlPoint cp, World world, Player player, StructureBlock hit) {
    // Should always have a resident and a town at this point.
    Resident attacker = CivGlobal.getResident(player);

    ItemManager.setTypeId(hit.getCoord().getLocation().getBlock(), CivData.AIR);
    world.playSound(hit.getCoord().getLocation(), Sound.ANVIL_BREAK, 1.0f, -1.0f);
    world.playSound(hit.getCoord().getLocation(), Sound.EXPLODE, 1.0f, 1.0f);

    FireworkEffect effect =
        FireworkEffect.builder()
            .with(Type.BURST)
            .withColor(Color.YELLOW)
            .withColor(Color.RED)
            .withTrail()
            .withFlicker()
            .build();
    FireworkEffectPlayer fePlayer = new FireworkEffectPlayer();
    for (int i = 0; i < 3; i++) {
      try {
        fePlayer.playFirework(world, hit.getCoord().getLocation(), effect);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    boolean allDestroyed = true;
    for (ControlPoint c : this.controlPoints.values()) {
      if (c.isDestroyed() == false) {
        allDestroyed = false;
        break;
      }
    }
    CivMessage.sendTownSound(hit.getTown(), Sound.AMBIENCE_CAVE, 1.0f, 0.5f);

    if (allDestroyed) {

      if (this.getTown().getCiv().getCapitolName().equals(this.getTown().getName())) {
        CivMessage.global(
            CivColor.LightBlue
                + ChatColor.BOLD
                + "The civilization of "
                + this.getTown().getCiv().getName()
                + " has been conquered by "
                + attacker.getCiv().getName()
                + "!");
        for (Town town : this.getTown().getCiv().getTowns()) {
          town.defeated = true;
        }

        War.transferDefeated(this.getTown().getCiv(), attacker.getTown().getCiv());
        WarStats.logCapturedCiv(attacker.getTown().getCiv(), this.getTown().getCiv());
        War.saveDefeatedCiv(this.getCiv(), attacker.getTown().getCiv());

        if (CivGlobal.isCasualMode()) {
          HashMap<Integer, ItemStack> leftovers =
              player
                  .getInventory()
                  .addItem(
                      this.getCiv()
                          .getRandomLeaderSkull("Victory Over " + this.getCiv().getName() + "!"));
          for (ItemStack stack : leftovers.values()) {
            player.getWorld().dropItem(player.getLocation(), stack);
          }
        }

      } else {
        CivMessage.global(
            CivColor.Yellow
                + ChatColor.BOLD
                + "The town of "
                + getTown().getName()
                + " in "
                + this.getCiv().getName()
                + " has been conquered by "
                + attacker.getCiv().getName()
                + "!");
        // this.getTown().onDefeat(attacker.getTown().getCiv());
        this.getTown().defeated = true;
        // War.defeatedTowns.put(this.getTown().getName(), attacker.getTown().getCiv());
        WarStats.logCapturedTown(attacker.getTown().getCiv(), this.getTown());
        War.saveDefeatedTown(this.getTown().getName(), attacker.getTown().getCiv());
      }

    } else {
      CivMessage.sendTown(
          hit.getTown(),
          CivColor.Rose + "One of our Town Hall's Control Points has been destroyed!");
      CivMessage.sendCiv(
          attacker.getTown().getCiv(),
          CivColor.LightGreen
              + "We've destroyed a control block in "
              + hit.getTown().getName()
              + "!");
      CivMessage.sendCiv(
          hit.getTown().getCiv(),
          CivColor.Rose + "A control block in " + hit.getTown().getName() + " has been destroyed!");
    }
  }
Esempio n. 20
0
 public FireworkEffect getEffect() {
   return FireworkEffect.builder().flicker(flicker).with(getType()).withColor(getColor()).build();
 }