コード例 #1
0
 public Construct exec(Target t, Env environment, Construct... args)
     throws ConfigRuntimeException {
   int x;
   int z;
   MCWorld w;
   if (args.length == 2) {
     MCWorld defaultWorld =
         environment.GetPlayer() == null ? null : environment.GetPlayer().getWorld();
     MCLocation l = ObjectGenerator.GetGenerator().location(args[0], defaultWorld, t);
     x = l.getBlockX();
     z = l.getBlockZ();
     w = l.getWorld();
   } else {
     x = (int) Static.getInt(args[0]);
     z = (int) Static.getInt(args[1]);
     if (args.length == 3) {
       w = environment.GetPlayer().getWorld();
     } else {
       w = Static.getServer().getWorld(args[2].val());
     }
   }
   MCBiomeType bt;
   try {
     bt = MCBiomeType.valueOf(args[args.length - 1].val());
   } catch (IllegalArgumentException e) {
     throw new ConfigRuntimeException(
         "The biome type \"" + args[1].val() + "\" does not exist.",
         ExceptionType.FormatException,
         t);
   }
   w.setBiome(x, z, bt);
   return new CVoid(t);
 }
コード例 #2
0
ファイル: Add.java プロジェクト: EntityReborn/CH-mcMMO
    public Construct exec(Target t, Environment environment, Construct... args)
        throws ConfigRuntimeException {
      Static.checkPlugin("mcMMO", t);

      BukkitMCPlayer player = (BukkitMCPlayer) Static.GetPlayer(args[0], t);
      SkillType skill;
      int amount = 1;

      try {
        skill = SkillType.valueOf(args[1].val().toUpperCase());
      } catch (Exception e) {
        throw new ConfigRuntimeException(
            "Unknown McMMO skilltype for mcmmo_add_level, " + args[1].val(),
            Exceptions.ExceptionType.NotFoundException,
            t);
      }

      if (args.length == 3) {
        try {
          amount = Integer.parseInt(args[2].val());
        } catch (Exception e) {
          throw new ConfigRuntimeException(
              "Bad amount for mcmmo_add_level, " + args[2].val(),
              Exceptions.ExceptionType.RangeException,
              t);
        }
      }

      ExperienceAPI.addLevel(player._Player(), skill.name(), amount);

      return new CVoid(t);
    }
コード例 #3
0
ファイル: MathTest.java プロジェクト: Thezomg/commandhelper
 @Test(timeout = 10000)
 public void testRand() {
   Math.rand a = new Math.rand();
   for (int i = 0; i < 1000; i++) {
     long j = Static.getInt(a.exec(Target.UNKNOWN, env, C.onstruct(10)));
     if (!(j < 10 && j >= 0)) {
       fail("Expected a number between 0 and 10, but got " + j);
     }
     j = Static.getInt(a.exec(Target.UNKNOWN, env, C.onstruct(10), C.onstruct(20)));
     if (!(j < 20 && j >= 10)) {
       fail("Expected a number between 10 and 20, but got " + j);
     }
   }
   try {
     a.exec(Target.UNKNOWN, env, C.onstruct(20), C.onstruct(10));
     fail("Didn't expect this test to pass");
   } catch (ConfigRuntimeException e) {
   }
   try {
     a.exec(Target.UNKNOWN, env, C.onstruct(-1));
     fail("Didn't expect this test to pass");
   } catch (ConfigRuntimeException e) {
   }
   try {
     a.exec(Target.UNKNOWN, env, C.onstruct(87357983597853791L));
     fail("Didn't expect this test to pass");
   } catch (ConfigRuntimeException e) {
   }
 }
コード例 #4
0
ファイル: CArray.java プロジェクト: Jessassin/commandhelper
 public Construct get(Construct index, Target t) {
   if (!associative_mode) {
     try {
       return array.get(Static.getInt32(index, t));
     } catch (IndexOutOfBoundsException e) {
       throw new ConfigRuntimeException(
           "The element at index \"" + index.val() + "\" does not exist",
           ExceptionType.IndexOverflowException,
           t);
     }
   } else {
     if (associative_array.containsKey(normalizeConstruct(index))) {
       Construct val = associative_array.get(normalizeConstruct(index));
       if (val instanceof CEntry) {
         return ((CEntry) val).construct();
       }
       return val;
     } else {
       throw new ConfigRuntimeException(
           "The element at index \"" + index.val() + "\" does not exist",
           ExceptionType.IndexOverflowException,
           t);
     }
   }
 }
コード例 #5
0
ファイル: CArray.java プロジェクト: Techcable/CommandHelper
 /**
  * @param index
  * @param c
  */
 public void set(Construct index, Construct c, Target t) {
   if (!associative_mode) {
     try {
       int indx = Static.getInt32(index, t);
       if (indx > next_index || indx < 0) {
         throw ConfigRuntimeException.BuildException(
             "", ExceptionType.IndexOverflowException, Target.UNKNOWN);
       } else if (indx == next_index) {
         this.push(c, t);
       } else {
         array.set(indx, c);
       }
     } catch (ConfigRuntimeException e) {
       // Not a number. Convert to associative.
       associative_array = new TreeMap<String, Construct>(comparator);
       for (int i = 0; i < array.size(); i++) {
         associative_array.put(Integer.toString(i), array.get(i));
       }
       associative_mode = true;
       array = null; // null out the original array container so it can be GC'd
     }
   }
   if (associative_mode) {
     associative_array.put(normalizeConstruct(index), c);
   }
   if (c instanceof CArray) {
     ((CArray) c).parent = this;
   }
   regenValue(new HashSet<CArray>());
 }
コード例 #6
0
ファイル: CArray.java プロジェクト: Techcable/CommandHelper
 @Override
 public Construct get(Construct index, Target t) {
   if (!associative_mode) {
     try {
       return array.get(Static.getInt32(index, t));
     } catch (IndexOutOfBoundsException e) {
       throw ConfigRuntimeException.BuildException(
           "The element at index \"" + index.val() + "\" does not exist",
           ExceptionType.IndexOverflowException,
           t,
           e);
     }
   } else {
     if (associative_array.containsKey(normalizeConstruct(index))) {
       Construct val = associative_array.get(normalizeConstruct(index));
       if (val instanceof CEntry) {
         return ((CEntry) val).construct();
       }
       return val;
     } else {
       // Create this so we can at least attach a stacktrace.
       @SuppressWarnings({"ThrowableInstanceNotThrown", "ThrowableInstanceNeverThrown"})
       IndexOutOfBoundsException ioobe = new IndexOutOfBoundsException();
       throw ConfigRuntimeException.BuildException(
           "The element at index \"" + index.val() + "\" does not exist",
           ExceptionType.IndexOverflowException,
           t,
           ioobe);
     }
   }
 }
コード例 #7
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);
 }
コード例 #8
0
 @Before
 public void setUp() throws Exception {
   fakeServer = GetFakeServer();
   fakePlayer = GetOnlinePlayer(fakeServer);
   env.getEnv(CommandHelperEnvironment.class).SetPlayer(fakePlayer);
   StaticTest.InstallFakeConvertor(fakePlayer);
   Static.InjectPlayer(fakePlayer);
 }
コード例 #9
0
 @Override
 public void onStartup() {
   try {
     Static.checkPlugin("GriefPrevention", Target.UNKNOWN);
   } catch (Exception e) {
     System.out.println(
         "[CommandHelper] CHGriefPrevention Could not find GriefPrevention please make sure you have it installed.");
   }
   System.out.println("[CommandHelper] CHGriefPrevention: Initialized");
 }
コード例 #10
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));
    }
コード例 #11
0
 @EventHandler(priority = EventPriority.LOWEST)
 public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
   BukkitMCPlayer currentPlayer =
       (BukkitMCPlayer) Static.GetPlayer(event.getPlayer().getName(), Target.UNKNOWN);
   // Apparently this happens sometimes, so prevent it
   if (!event.getFrom().equals(currentPlayer._Player().getWorld())) {
     EventUtils.TriggerListener(
         Driver.WORLD_CHANGED,
         "world_changed",
         new BukkitPlayerEvents.BukkitMCWorldChangedEvent(event));
   }
 }
コード例 #12
0
 @Override
 public Construct exec(Target t, Environment environment, Construct... args)
     throws ConfigRuntimeException {
   String parameter = args[0].val();
   Construct value = args[1];
   boolean throwOnFailure = false;
   if (args.length == 3) {
     throwOnFailure = Static.getBoolean(args[3]);
   }
   if (environment.getEnv(GlobalEnv.class).GetEvent() == null) {
     throw new ConfigRuntimeException(
         this.getName() + " must be called from within an event handler",
         ExceptionType.BindException,
         t);
   }
   Event e = environment.getEnv(GlobalEnv.class).GetEvent().getEventDriver();
   if (environment
       .getEnv(GlobalEnv.class)
       .GetEvent()
       .getBoundEvent()
       .getPriority()
       .equals(Priority.MONITOR)) {
     throw new ConfigRuntimeException(
         "Monitor level handlers may not modify an event!", ExceptionType.BindException, t);
   }
   ActiveEvent active = environment.getEnv(GlobalEnv.class).GetEvent();
   boolean success = false;
   if (!active.isLocked(parameter)) {
     try {
       success =
           e.modifyEvent(
               parameter,
               value,
               environment.getEnv(GlobalEnv.class).GetEvent().getUnderlyingEvent());
     } catch (ConfigRuntimeException ex) {
       ex.setFile(t.file());
       ex.setLineNum(t.line());
       ex.setColumn(t.col());
       throw ex;
     }
   } else {
     success = false;
   }
   if (throwOnFailure && !success) {
     throw new ConfigRuntimeException(
         "Event parameter is already locked!", ExceptionType.BindException, t);
   }
   return CBoolean.get(success);
 }
コード例 #13
0
 public Construct exec(Target t, Env environment, Construct... args)
     throws ConfigRuntimeException {
   int x;
   int z;
   MCWorld w;
   if (args.length == 1) {
     MCWorld defaultWorld =
         environment.GetPlayer() == null ? null : environment.GetPlayer().getWorld();
     MCLocation l = ObjectGenerator.GetGenerator().location(args[0], defaultWorld, t);
     x = l.getBlockX();
     z = l.getBlockZ();
     w = l.getWorld();
   } else {
     x = (int) Static.getInt(args[0]);
     z = (int) Static.getInt(args[1]);
     if (args.length == 2) {
       w = environment.GetPlayer().getWorld();
     } else {
       w = Static.getServer().getWorld(args[2].val());
     }
   }
   MCBiomeType bt = w.getBiome(x, z);
   return new CString(bt.name(), t);
 }
コード例 #14
0
    @Override
    public Construct exec(Target t, Environment environment, Construct... args)
        throws ConfigRuntimeException {
      boolean cancelled = true;
      if (args.length == 1) {
        cancelled = Static.getBoolean(args[0]);
      }

      BoundEvent.ActiveEvent original = environment.getEnv(GlobalEnv.class).GetEvent();
      if (original == null) {
        throw new ConfigRuntimeException(
            "cancel cannot be called outside an event handler", ExceptionType.BindException, t);
      }
      if (original.getUnderlyingEvent() != null && original.isCancellable()) {
        original.setCancelled(cancelled);
      }
      return CVoid.VOID;
    }
コード例 #15
0
 @Override
 public Construct exec(Target t, Environment environment, Construct... args)
     throws ConfigRuntimeException {
   CArray obj = null;
   if (args[1] instanceof CNull) {
     obj = new CArray(t);
   } else if (args[1] instanceof CArray) {
     obj = (CArray) args[1];
   } else {
     throw new ConfigRuntimeException(
         "The eventObject must be null, or an array", ExceptionType.CastException, t);
   }
   boolean serverWide = false;
   if (args.length == 3) {
     serverWide = Static.getBoolean(args[2]);
   }
   EventUtils.ManualTrigger(args[0].val(), obj, t, serverWide);
   return CVoid.VOID;
 }
コード例 #16
0
 public Construct exec(Target t, Env environment, Construct... args)
     throws ConfigRuntimeException {
   MCLocation l;
   MCPlayer p;
   p = environment.GetPlayer();
   MCWorld w = (p != null ? p.getWorld() : null);
   l = ObjectGenerator.GetGenerator().location(args[0], w, t);
   if (l.getWorld() instanceof CraftWorld) {
     CraftWorld cw = (CraftWorld) l.getWorld();
     net.minecraft.server.Block.byId[l.getBlock().getTypeId()].dropNaturally(
         cw.getHandle(),
         l.getBlockX(),
         l.getBlockY(),
         l.getBlockZ(),
         l.getBlock().getData(),
         1.0f,
         0);
   }
   l.getBlock().setTypeId(0);
   CraftServer cs = (CraftServer) ((BukkitMCServer) Static.getServer()).__Server();
   cs.getHandle().a(new Packet0KeepAlive(), 0);
   return new CVoid(t);
 }
コード例 #17
0
ファイル: SQL.java プロジェクト: CraftMinecraft/commandhelper
 @Override
 public Construct exec(Target t, Environment environment, Construct... args)
     throws ConfigRuntimeException {
   try {
     Profiles.Profile profile;
     if (args[0] instanceof CArray) {
       Map<String, String> data = new HashMap<String, String>();
       for (String key : ((CArray) args[0]).keySet()) {
         data.put(key, ((CArray) args[0]).get(key).val());
       }
       profile = Profiles.getProfile(data);
     } else {
       Profiles profiles = environment.getEnv(GlobalEnv.class).getSQLProfiles();
       profile = profiles.getProfileById(args[0].val());
     }
     String query = args[1].val();
     Construct[] params = new Construct[args.length - 2];
     for (int i = 2; i < args.length; i++) {
       int index = i - 2;
       params[index] = args[i];
     }
     // Parameters are now all parsed into java objects.
     Connection conn = DriverManager.getConnection(profile.getConnectionString());
     PreparedStatement ps = null;
     try {
       ps = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
       for (int i = 0; i < params.length; i++) {
         int type = ps.getParameterMetaData().getParameterType(i + 1);
         if (params[i] == null) {
           if (ps.getParameterMetaData().isNullable(i + 1)
               == ParameterMetaData.parameterNoNulls) {
             throw new ConfigRuntimeException(
                 "Parameter "
                     + (i + 1)
                     + " cannot be set to null. Check your parameters and try again.",
                 ExceptionType.SQLException,
                 t);
           } else {
             ps.setNull(i + 1, type);
             continue;
           }
         }
         try {
           if (params[i] instanceof CInt) {
             ps.setLong(i + 1, Static.getInt(params[i], t));
           } else if (params[i] instanceof CDouble) {
             ps.setDouble(i + 1, (Double) Static.getDouble(params[i], t));
           } else if (params[i] instanceof CString) {
             ps.setString(i + 1, (String) params[i].val());
           } else if (params[i] instanceof CByteArray) {
             ps.setBytes(i + 1, ((CByteArray) params[i]).asByteArrayCopy());
           } else if (params[i] instanceof CBoolean) {
             ps.setBoolean(i + 1, Static.getBoolean(params[i]));
           } else {
             throw new ConfigRuntimeException(
                 "The type "
                     + params[i].getClass().getSimpleName()
                     + " of parameter "
                     + (i + 1)
                     + " is not supported.",
                 ExceptionType.CastException,
                 t);
           }
         } catch (ClassCastException ex) {
           throw new ConfigRuntimeException(
               "Could not cast parameter "
                   + (i + 1)
                   + " to "
                   + ps.getParameterMetaData().getParameterTypeName(i + 1)
                   + " from "
                   + params[i].getClass().getSimpleName()
                   + ".",
               ExceptionType.CastException,
               t,
               ex);
         }
       }
       boolean isResultSet = ps.execute();
       if (isResultSet) {
         // Result set
         CArray ret = new CArray(t);
         ResultSetMetaData md = ps.getMetaData();
         ResultSet rs = ps.getResultSet();
         while (rs.next()) {
           CArray row = new CArray(t);
           for (int i = 1; i <= md.getColumnCount(); i++) {
             Construct value;
             int columnType = md.getColumnType(i);
             if (columnType == Types.INTEGER
                 || columnType == Types.TINYINT
                 || columnType == Types.SMALLINT
                 || columnType == Types.BIGINT) {
               value = new CInt(rs.getLong(i), t);
             } else if (columnType == Types.FLOAT
                 || columnType == Types.DOUBLE
                 || columnType == Types.REAL
                 || columnType == Types.DECIMAL
                 || columnType == Types.NUMERIC) {
               value = new CDouble(rs.getDouble(i), t);
             } else if (columnType == Types.VARCHAR
                 || columnType == Types.CHAR
                 || columnType == Types.LONGVARCHAR) {
               value = new CString(rs.getString(i), t);
             } else if (columnType == Types.BLOB
                 || columnType == Types.BINARY
                 || columnType == Types.VARBINARY
                 || columnType == Types.LONGVARBINARY) {
               value = CByteArray.wrap(rs.getBytes(i), t);
             } else if (columnType == Types.DATE
                 || columnType == Types.TIME
                 || columnType == Types.TIMESTAMP) {
               if (md.getColumnTypeName(i).equals("YEAR")) {
                 value = new CInt(rs.getLong(i), t);
               } else {
                 value = new CInt(rs.getTimestamp(i).getTime(), t);
               }
             } else if (columnType == Types.BOOLEAN || columnType == Types.BIT) {
               value = new CBoolean(rs.getBoolean(i), t);
             } else {
               throw new ConfigRuntimeException(
                   "SQL returned a unhandled column type "
                       + md.getColumnTypeName(i)
                       + " for column "
                       + md.getColumnName(i)
                       + ".",
                   ExceptionType.CastException,
                   t);
             }
             row.set(md.getColumnName(i), value, t);
           }
           ret.push(row);
         }
         return ret;
       } else {
         ResultSet rs = ps.getGeneratedKeys();
         if (rs.next()) {
           // This was an insert or something that returned generated keys. So we return
           // that here.
           return new CInt(rs.getInt(1), t);
         }
         // Update count. Just return null.
         return new CNull(t);
       }
     } finally {
       if (ps != null) {
         ps.close();
       }
       if (conn != null) {
         conn.close();
       }
     }
   } catch (Profiles.InvalidProfileException ex) {
     throw new ConfigRuntimeException(ex.getMessage(), ExceptionType.SQLException, t, ex);
   } catch (SQLException ex) {
     throw new ConfigRuntimeException(ex.getMessage(), ExceptionType.SQLException, t, ex);
   }
 }
コード例 #18
0
 @Before
 public void setUp() throws Exception {
   fakePlayer = StaticTest.GetOnlinePlayer();
   StaticTest.InstallFakeConvertor(fakePlayer);
   Static.InjectPlayer(fakePlayer);
 }
コード例 #19
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);
    }
コード例 #20
0
 public EnchantmentsTest() throws Exception {
   InstallFakeServerFrontend();
   env = Static.GenerateStandaloneEnvironment();
 }