コード例 #1
0
ファイル: ItemStackAdapter.java プロジェクト: riking/mcore
 public static void transferFireworkMetaEffects(
     FireworkMeta meta, JsonObject json, boolean meta2json) {
   if (meta2json) {
     if (!meta.hasEffects()) return;
     json.add(FIREWORK_EFFECTS, convertFireworkEffectList(meta.getEffects()));
   } else {
     JsonElement element = json.get(FIREWORK_EFFECTS);
     if (element == null) return;
     meta.clearEffects();
     meta.addEffects(convertFireworkEffectList(element));
   }
 }
コード例 #2
0
ファイル: Api.java プロジェクト: kicjow/Crazy-Crates
 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);
 }
コード例 #3
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;
  }