Esempio n. 1
0
  @Override
  public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

    Element action = scriptEntry.getElement("action");
    Element permission = scriptEntry.getElement("permission");
    Element group = scriptEntry.getElement("group");
    dWorld world = (dWorld) scriptEntry.getObject("world");

    // Report to dB
    dB.report(
        scriptEntry,
        getName(),
        action.debug()
            + permission.debug()
            + (group != null ? group.debug() : "")
            + (world != null ? world.debug() : ""));

    World bukkitWorld = null;
    if (world != null) {
      bukkitWorld = world.getWorld();
    }

    OfflinePlayer player =
        ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer()
            ? ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getOfflinePlayer()
            : null;

    switch (Action.valueOf(action.asString().toUpperCase())) {
      case ADD:
        if (group != null) {
          if (Depends.permissions.groupHas(bukkitWorld, group.asString(), permission.asString())) {
            dB.echoDebug(scriptEntry, "Group " + group + " already has permission " + permission);
          } else {
            Depends.permissions.groupAdd(bukkitWorld, group.asString(), permission.asString());
          }
        } else {
          if (Depends.permissions.playerHas(
              bukkitWorld == null ? null : bukkitWorld.getName(), player, permission.asString())) {
            dB.echoDebug(
                scriptEntry,
                "Player " + player.getName() + " already has permission " + permission);
          } else {
            Depends.permissions.playerAdd(
                bukkitWorld == null ? null : bukkitWorld.getName(), player, permission.asString());
          }
        }
        return;
      case REMOVE:
        if (group != null) {
          if (!Depends.permissions.groupHas(bukkitWorld, group.asString(), permission.asString())) {
            dB.echoDebug(
                scriptEntry,
                "Group " + group + " does not have access to permission " + permission);
          } else {
            Depends.permissions.groupRemove(bukkitWorld, group.asString(), permission.asString());
          }
        } else {
          if (!Depends.permissions.playerHas(
              bukkitWorld == null ? null : bukkitWorld.getName(), player, permission.asString())) {
            dB.echoDebug(
                scriptEntry,
                "Player " + player.getName() + " does not have access to permission " + permission);
          } else {
            Depends.permissions.playerRemove(
                bukkitWorld == null ? null : bukkitWorld.getName(), player, permission.asString());
          }
        }
        return;
    }
  }
  @Override
  public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

    ParticleHelper particleHelper = NMSHandler.getInstance().getParticleHelper();

    // Iterate through arguments
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {

      if (!scriptEntry.hasObject("location") && arg.matchesArgumentList(dLocation.class)) {

        scriptEntry.addObject("location", arg.asType(dList.class).filter(dLocation.class));
      } else if (!scriptEntry.hasObject("effect")
          && !scriptEntry.hasObject("particleeffect")
          && !scriptEntry.hasObject("iconcrack")) {

        if (particleHelper.hasParticle(arg.getValue())) {
          scriptEntry.addObject("particleeffect", particleHelper.getParticle(arg.getValue()));
        } else if (arg.matches("random")) {
          // Get another effect if "RANDOM" is used
          if (CoreUtilities.getRandom().nextDouble() < 0.5) {
            // Make sure the new effect is not an invisible effect
            List<Particle> visible = particleHelper.getVisibleParticles();
            scriptEntry.addObject(
                "particleeffect", visible.get(CoreUtilities.getRandom().nextInt(visible.size())));
          } else {
            List<Effect> visual = particleHelper.getVisualEffects();
            scriptEntry.addObject(
                "effect", visual.get(CoreUtilities.getRandom().nextInt(visual.size())));
          }
        } else if (arg.startsWith("iconcrack_")) {
          // Allow iconcrack_[id],[data] for item break effects (ex: iconcrack_1)
          String shrunk = arg.getValue().substring("iconcrack_".length());
          String[] split = shrunk.split(",");
          Element typeId = new Element(split[0]);
          if (typeId.isInt()
              && typeId.asInt() > 0
              && Material.getMaterial(typeId.asInt()) != null) {
            scriptEntry.addObject("iconcrack", typeId);
          } else {
            dB.echoError("Invalid iconcrack_[id]. Must be a valid Material ID, besides 0.");
          }
          Element dataId = new Element(split.length <= 1 ? "0" : split[1]);
          scriptEntry.addObject("iconcrack_data", dataId);
          scriptEntry.addObject("iconcrack_type", new Element("iconcrack"));
        } else if (arg.startsWith("blockcrack_")) {
          String shrunk = arg.getValue().substring("blockcrack_".length());
          Element typeId = new Element(shrunk);
          if (typeId.isInt()
              && typeId.asInt() > 0
              && Material.getMaterial(typeId.asInt()) != null) {
            scriptEntry.addObject("iconcrack", typeId);
          } else {
            dB.echoError("Invalid blockcrack_[id]. Must be a valid Material ID, besides 0.");
          }
          scriptEntry.addObject("iconcrack_type", new Element("blockcrack"));
        } else if (arg.startsWith("blockdust_")) {
          String shrunk = arg.getValue().substring("blockdust_".length());
          Element typeId = new Element(shrunk);
          if (typeId.isInt()
              && typeId.asInt() > 0
              && Material.getMaterial(typeId.asInt()) != null) {
            scriptEntry.addObject("iconcrack", typeId);
          } else {
            dB.echoError("Invalid blockdust_[id]. Must be a valid Material ID, besides 0.");
          }
          scriptEntry.addObject("iconcrack_type", new Element("blockdust"));
        } else if (particleHelper.hasEffect(arg.getValue())) {
          scriptEntry.addObject("effect", particleHelper.getEffect(arg.getValue()));
        }
      } else if (!scriptEntry.hasObject("radius")
          && arg.matchesPrimitive(aH.PrimitiveType.Double)
          && arg.matchesPrefix("visibility", "v", "radius", "r")) {

        scriptEntry.addObject("radius", arg.asElement());
      } else if (!scriptEntry.hasObject("data")
          && arg.matchesPrimitive(aH.PrimitiveType.Double)
          && arg.matchesPrefix("data", "d")) {

        scriptEntry.addObject("data", arg.asElement());
      } else if (!scriptEntry.hasObject("qty")
          && arg.matchesPrimitive(aH.PrimitiveType.Integer)
          && arg.matchesPrefix("qty", "q", "quantity")) {

        scriptEntry.addObject("qty", arg.asElement());
      } else if (!scriptEntry.hasObject("offset")
          && arg.matchesPrimitive(aH.PrimitiveType.Double)
          && arg.matchesPrefix("offset", "o")) {

        double offset = arg.asElement().asDouble();
        scriptEntry.addObject("offset", new dLocation(null, offset, offset, offset));
      } else if (!scriptEntry.hasObject("offset")
          && arg.matchesArgumentType(dLocation.class)
          && arg.matchesPrefix("offset", "o")) {

        scriptEntry.addObject("offset", arg.asType(dLocation.class));
      } else if (!scriptEntry.hasObject("targets")
          && arg.matchesArgumentList(dPlayer.class)
          && arg.matchesPrefix("targets", "target", "t")) {

        scriptEntry.addObject("targets", arg.asType(dList.class).filter(dPlayer.class));
      } else {
        arg.reportUnhandled();
      }
    }

    // Use default values if necessary
    scriptEntry.defaultObject(
        "location",
        ((BukkitScriptEntryData) scriptEntry.entryData).hasNPC()
                && ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().isSpawned()
            ? Arrays.asList(((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getLocation())
            : null,
        ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer()
                && ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().isOnline()
            ? Arrays.asList(
                ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getLocation())
            : null);
    scriptEntry.defaultObject("data", new Element(0));
    scriptEntry.defaultObject("radius", new Element(15));
    scriptEntry.defaultObject("qty", new Element(1));
    scriptEntry.defaultObject("offset", new dLocation(null, 0.5, 0.5, 0.5));

    // Check to make sure required arguments have been filled

    if (!scriptEntry.hasObject("effect")
        && !scriptEntry.hasObject("particleeffect")
        && !scriptEntry.hasObject("iconcrack")) {
      throw new InvalidArgumentsException("Missing effect argument!");
    }

    if (!scriptEntry.hasObject("location")) {
      throw new InvalidArgumentsException("Missing location argument!");
    }
  }
Esempio n. 3
0
  @Override
  public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

    Element id = scriptEntry.getElement("map-id");
    dWorld create = scriptEntry.getdObject("new");
    Element reset = scriptEntry.getElement("reset");
    dLocation resetLoc = scriptEntry.getdObject("reset-loc");
    Element image = scriptEntry.getElement("image");
    dScript script = scriptEntry.getdObject("script");
    Element resize = scriptEntry.getElement("resize");
    Element width = scriptEntry.getElement("width");
    Element height = scriptEntry.getElement("height");
    Element x = scriptEntry.getElement("x-value");
    Element y = scriptEntry.getElement("y-value");

    dB.report(
        scriptEntry,
        getName(),
        (id != null ? id.debug() : "")
            + (create != null ? create.debug() : "")
            + reset.debug()
            + (resetLoc != null ? resetLoc.debug() : "")
            + (image != null ? image.debug() : "")
            + (script != null ? script.debug() : "")
            + resize.debug()
            + (width != null ? width.debug() : "")
            + (height != null ? height.debug() : "")
            + x.debug()
            + y.debug());

    MapView map = null;
    if (create != null) {
      map = Bukkit.getServer().createMap(create.getWorld());
      scriptEntry.addObject("created_map", new Element(map.getId()));
    } else if (id != null) {
      map = Bukkit.getServer().getMap((short) id.asInt());
      if (map == null)
        throw new CommandExecutionException("No map found for ID '" + id.asInt() + "'!");
    } else {
      throw new CommandExecutionException(
          "The map command failed somehow! Report this to a developer!");
    }

    if (reset.asBoolean()) {
      List<MapRenderer> oldRenderers = DenizenMapManager.removeDenizenRenderers(map);
      for (MapRenderer renderer : oldRenderers) {
        map.addRenderer(renderer);
      }
      if (resetLoc != null) {
        map.setCenterX(resetLoc.getBlockX());
        map.setCenterZ(resetLoc.getBlockZ());
        map.setWorld(resetLoc.getWorld());
      }
    } else if (script != null) {
      DenizenMapManager.removeDenizenRenderers(map);
      ((MapScriptContainer) script.getContainer()).applyTo(map);
    } else {
      DenizenMapRenderer dmr = DenizenMapManager.getDenizenRenderer(map);
      if (image != null) {
        int wide = width != null ? width.asInt() : resize.asBoolean() ? 128 : 0;
        int high = height != null ? height.asInt() : resize.asBoolean() ? 128 : 0;
        if (CoreUtilities.toLowerCase(image.asString()).endsWith(".gif"))
          dmr.addObject(
              new MapAnimatedImage(
                  x.asString(), y.asString(), "true", false, image.asString(), wide, high));
        else
          dmr.addObject(
              new MapImage(
                  x.asString(), y.asString(), "true", false, image.asString(), wide, high));
      }
    }
  }
  @Override
  public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

    // Extract objects from ScriptEntry
    List<dLocation> locations = (List<dLocation>) scriptEntry.getObject("location");
    List<dPlayer> targets = (List<dPlayer>) scriptEntry.getObject("targets");
    Effect effect = (Effect) scriptEntry.getObject("effect");
    Particle particleEffect = (Particle) scriptEntry.getObject("particleeffect");
    Element iconcrack = scriptEntry.getElement("iconcrack");
    Element iconcrack_data = scriptEntry.getElement("iconcrack_data");
    Element iconcrack_type = scriptEntry.getElement("iconcrack_type");
    Element radius = scriptEntry.getElement("radius");
    Element data = scriptEntry.getElement("data");
    Element qty = scriptEntry.getElement("qty");
    dLocation offset = scriptEntry.getdObject("offset");

    // Report to dB
    dB.report(
        scriptEntry,
        getName(),
        (effect != null
                ? aH.debugObj("effect", effect.getName())
                : particleEffect != null
                    ? aH.debugObj("special effect", particleEffect.getName())
                    : iconcrack_type.debug()
                        + iconcrack.debug()
                        + (iconcrack_data != null ? iconcrack_data.debug() : ""))
            + aH.debugObj("locations", locations.toString())
            + (targets != null ? aH.debugObj("targets", targets.toString()) : "")
            + radius.debug()
            + data.debug()
            + qty.debug()
            + offset.debug());

    for (dLocation location : locations) {
      // Slightly increase the location's Y so effects don't seem to come out of the ground
      location.add(0, 1, 0);

      // Play the Bukkit effect the number of times specified
      if (effect != null) {
        for (int n = 0; n < qty.asInt(); n++) {
          if (targets != null) {
            for (dPlayer player : targets) {
              if (player.isValid() && player.isOnline()) {
                effect.playFor(player.getPlayerEntity(), location, data.asInt());
              }
            }
          } else {
            effect.play(location, data.asInt(), radius.asInt());
          }
        }
      }

      // Play a ParticleEffect
      else if (particleEffect != null) {
        float osX = (float) offset.getX();
        float osY = (float) offset.getY();
        float osZ = (float) offset.getZ();
        List<Player> players = new ArrayList<Player>();
        if (targets == null) {
          float rad = radius.asFloat();
          for (Player player : location.getWorld().getPlayers()) {
            if (player.getLocation().distanceSquared(location) < rad * rad) {
              players.add(player);
            }
          }
        } else {
          for (dPlayer player : targets) {
            if (player.isValid() && player.isOnline()) {
              players.add(player.getPlayerEntity());
            }
          }
        }
        for (Player player : players) {
          particleEffect.playFor(player, location, qty.asInt(), offset.toVector(), data.asFloat());
        }
      }

      // Play an iconcrack (item break) effect
      else {
        float osX = (float) offset.getX();
        float osY = (float) offset.getY();
        float osZ = (float) offset.getZ();
        List<Player> players = new ArrayList<Player>();
        if (targets == null) {
          float rad = radius.asFloat();
          for (Player player : location.getWorld().getPlayers()) {
            if (player.getLocation().distanceSquared(location) < rad * rad) {
              players.add(player);
            }
          }
        } else {
          for (dPlayer player : targets) {
            if (player.isValid() && player.isOnline()) {
              players.add(player.getPlayerEntity());
            }
          }
        }
        // TODO: better this all
        if (iconcrack_type.asString().equalsIgnoreCase("iconcrack")) {
          ItemStack itemStack =
              new ItemStack(iconcrack.asInt(), iconcrack_data != null ? iconcrack_data.asInt() : 0);
          Particle particle =
              NMSHandler.getInstance().getParticleHelper().getParticle("ITEM_CRACK");
          for (Player player : players) {
            particle.playFor(
                player, location, qty.asInt(), offset.toVector(), data.asFloat(), itemStack);
          }
        } else if (iconcrack_type.asString().equalsIgnoreCase("blockcrack")) {
          MaterialData materialData =
              new MaterialData(
                  iconcrack.asInt(), (byte) (iconcrack_data != null ? iconcrack_data.asInt() : 0));
          Particle particle =
              NMSHandler.getInstance().getParticleHelper().getParticle("BLOCK_CRACK");
          for (Player player : players) {
            particle.playFor(
                player, location, qty.asInt(), offset.toVector(), data.asFloat(), materialData);
          }
        } else { // blockdust
          MaterialData materialData =
              new MaterialData(
                  iconcrack.asInt(), (byte) (iconcrack_data != null ? iconcrack_data.asInt() : 0));
          Particle particle =
              NMSHandler.getInstance().getParticleHelper().getParticle("BLOCK_DUST");
          for (Player player : players) {
            particle.playFor(
                player, location, qty.asInt(), offset.toVector(), data.asFloat(), materialData);
          }
        }
      }
    }
  }