Ejemplo n.º 1
0
 public Construct exec(Target t, Env env, Construct... args)
     throws CancelCommandException, ConfigRuntimeException {
   double x = 0;
   double y = 0;
   double z = 0;
   MCWorld w = null;
   String world = null;
   if (env.GetPlayer() instanceof MCPlayer) {
     w = env.GetPlayer().getWorld();
   }
   if (args.length == 1 || args.length == 2) {
     if (args[0] instanceof CArray) {
       MCLocation loc = ObjectGenerator.GetGenerator().location(args[0], w, t);
       x = loc.getX();
       y = loc.getY();
       z = loc.getZ();
       world = loc.getWorld().getName();
     } else {
       throw new ConfigRuntimeException(
           "get_block_at expects param 1 to be an array", ExceptionType.CastException, t);
     }
     if (args.length == 2) {
       world = args[1].val();
     }
   } else if (args.length == 3 || args.length == 4) {
     x = Static.getDouble(args[0]);
     y = Static.getDouble(args[1]);
     z = Static.getDouble(args[2]);
     if (args.length == 4) {
       world = args[3].val();
     }
   }
   if (world != null) {
     w = Static.getServer().getWorld(world);
   }
   if (w == null) {
     throw new ConfigRuntimeException(
         "The specified world " + world + " doesn't exist",
         ExceptionType.InvalidWorldException,
         t);
   }
   x = java.lang.Math.floor(x);
   y = java.lang.Math.floor(y);
   z = java.lang.Math.floor(z);
   MCBlock b = w.getBlockAt((int) x, (int) y, (int) z);
   return new CString(b.getTypeId() + ":" + b.getData(), t);
 }
Ejemplo n.º 2
0
    public Construct exec(Target t, Env env, Construct... args)
        throws CancelCommandException, ConfigRuntimeException {
      double x = 0;
      double y = 0;
      double z = 0;
      MCWorld w = null;
      String world = null;
      if (env.GetPlayer() instanceof MCPlayer) {
        w = env.GetPlayer().getWorld();
      }

      if (args[0] instanceof CArray && !(args.length == 3)) {
        MCLocation loc = ObjectGenerator.GetGenerator().location(args[0], w, t);
        x = loc.getX();
        z = loc.getZ();
        world = loc.getWorld().getName();
        if (args.length == 2) {
          world = args[1].val();
        }
      } else if (args.length == 2 || args.length == 3) {
        x = Static.getDouble(args[0]);
        z = Static.getDouble(args[1]);
        if (args.length == 3) {
          world = args[2].val();
        }
      }

      if (world != null) {
        w = Static.getServer().getWorld(world);
      }
      if (w == null) {
        throw new ConfigRuntimeException(
            "The specified world " + world + " doesn't exist",
            ExceptionType.InvalidWorldException,
            t);
      }
      x = java.lang.Math.floor(x);
      y = java.lang.Math.floor(y) - 1;
      z = java.lang.Math.floor(z);
      MCBlock b = w.getHighestBlockAt((int) x, (int) z);
      return new CArray(t, new CInt(b.getX(), t), new CInt(b.getY(), t), new CInt(b.getZ(), t));
    }
Ejemplo n.º 3
0
    public Construct exec(Target t, Env env, Construct... args)
        throws CancelCommandException, ConfigRuntimeException {
      double x = 0;
      double y = 0;
      double z = 0;
      String id = null;
      String world = null;
      MCWorld w = null;
      if (env.GetPlayer() instanceof MCPlayer) {
        w = env.GetPlayer().getWorld();
      }
      if ((args.length == 2 || args.length == 3) && args[0] instanceof CArray) {
        MCLocation l =
            ObjectGenerator.GetGenerator().location(args[0], env.GetPlayer().getWorld(), t);
        x = l.getBlockX();
        y = l.getBlockY();
        z = l.getBlockZ();
        world = l.getWorld().getName();
        id = args[1].val();
        if (args.length == 3) {
          world = args[2].val();
        }

      } else {
        x = Static.getNumber(args[0]);
        y = Static.getNumber(args[1]);
        z = Static.getNumber(args[2]);
        id = args[3].val();
        if (args.length == 5) {
          world = args[4].val();
        }
      }
      if (world != null) {
        w = Static.getServer().getWorld(world);
      }
      if (w == null) {
        throw new ConfigRuntimeException(
            "The specified world " + world + " doesn't exist",
            ExceptionType.InvalidWorldException,
            t);
      }
      x = java.lang.Math.floor(x);
      y = java.lang.Math.floor(y);
      z = java.lang.Math.floor(z);
      int ix = (int) x;
      int iy = (int) y;
      int iz = (int) z;
      MCBlock b = w.getBlockAt(ix, iy, iz);
      StringBuilder data = new StringBuilder();
      StringBuilder meta = new StringBuilder();
      boolean inMeta = false;
      for (int i = 0; i < id.length(); i++) {
        Character c = id.charAt(i);
        if (!inMeta) {
          if (!Character.isDigit(c) && c != ':') {
            throw new ConfigRuntimeException(
                "id must be formatted as such: 'x:y' where x and y are integers",
                ExceptionType.FormatException,
                t);
          }
          if (c == ':') {
            inMeta = true;
            continue;
          }
          data.append(c);
        } else {
          meta.append(c);
        }
      }
      if (meta.length() == 0) {
        meta.append("0");
      }

      int idata = Integer.parseInt(data.toString());
      byte imeta = Byte.parseByte(meta.toString());
      b.setTypeId(idata);
      b.setData(imeta);

      return new CVoid(t);
    }