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); }
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); }
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)); }
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); }
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); }
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); }
/** * Given a Location Object, returns a MCLocation. If the optional world is not specified in the * object, the world provided is used instead. Location "objects" are MethodScript arrays that * represent a location in game. There are 4 usages: * * <ul> * <li>(x, y, z) * <li>(x, y, z, world) * <li>(x, y, z, yaw, pitch) * <li>(x, y, z, world, yaw, pitch) * </ul> * * In all cases, the pitch and yaw default to 0, and the world defaults to the specified world. * <em>More conveniently: ([world], x, y, z, [yaw, pitch])</em> */ public MCLocation location(Construct c, MCWorld w, Target t) { if (!(c instanceof CArray)) { throw new ConfigRuntimeException( "Expecting an array, received " + c.getCType(), ExceptionType.FormatException, t); } CArray array = (CArray) c; MCWorld world = w; double x = 0; double y = 0; double z = 0; float yaw = 0; float pitch = 0; if (!array.inAssociativeMode()) { if (array.size() == 3) { // Just the xyz, with default yaw and pitch, and given world x = Static.getNumber(array.get(0, t), t); y = Static.getNumber(array.get(1, t), t); z = Static.getNumber(array.get(2, t), t); } else if (array.size() == 4) { // x, y, z, world x = Static.getNumber(array.get(0, t), t); y = Static.getNumber(array.get(1, t), t); z = Static.getNumber(array.get(2, t), t); world = Static.getServer().getWorld(array.get(3, t).val()); } else if (array.size() == 5) { // x, y, z, yaw, pitch, with given world x = Static.getNumber(array.get(0, t), t); y = Static.getNumber(array.get(1, t), t); z = Static.getNumber(array.get(2, t), t); yaw = (float) Static.getNumber(array.get(3, t), t); pitch = (float) Static.getNumber(array.get(4, t), t); } else if (array.size() == 6) { // All have been given x = Static.getNumber(array.get(0, t), t); y = Static.getNumber(array.get(1, t), t); z = Static.getNumber(array.get(2, t), t); world = Static.getServer().getWorld(array.get(3, t).val()); yaw = (float) Static.getNumber(array.get(4, t), t); pitch = (float) Static.getNumber(array.get(5, t), t); } else { throw new ConfigRuntimeException( "Expecting a Location array, but the array did not meet the format specifications", ExceptionType.FormatException, t); } } if (array.containsKey("x")) { x = Static.getNumber(array.get("x"), t); } if (array.containsKey("y")) { y = Static.getNumber(array.get("y"), t); } if (array.containsKey("z")) { z = Static.getNumber(array.get("z"), t); } if (array.containsKey("world")) { world = Static.getServer().getWorld(array.get("world").val()); } if (array.containsKey("yaw")) { yaw = (float) Static.getDouble(array.get("yaw"), t); } if (array.containsKey("pitch")) { pitch = (float) Static.getDouble(array.get("pitch"), t); } // If world is still null at this point, it's an error if (world == null) { throw new ConfigRuntimeException( "The specified world doesn't exist, or no world was provided", ExceptionType.InvalidWorldException, t); } return StaticLayer.GetLocation(world, x, y, z, yaw, pitch); }
public MCItemMeta itemMeta(Construct c, int i, Target t) { MCItemMeta meta = Static.getServer().getItemFactory().getItemMeta(StaticLayer.GetConvertor().getMaterial(i)); if (c instanceof CNull) { return meta; } CArray ma = null; if (c instanceof CArray) { ma = (CArray) c; try { if (ma.containsKey("display")) { Construct dni = ma.get("display"); if (!(dni instanceof CNull)) { meta.setDisplayName(dni.val()); } } if (ma.containsKey("lore")) { Construct li = ma.get("lore"); if (li instanceof CNull) { // do nothing } else if (li instanceof CArray) { CArray la = (CArray) li; List<String> ll = new ArrayList<String>(); for (int j = 0; j < la.size(); j++) { ll.add(la.get(j).val()); } meta.setLore(ll); } else { throw new Exceptions.FormatException("Lore was expected to be an array.", t); } } if (meta instanceof MCLeatherArmorMeta) { if (ma.containsKey("color")) { Construct ci = ma.get("color"); if (ci instanceof CNull) { // nothing } else if (ci instanceof CArray) { ((MCLeatherArmorMeta) meta).setColor(color((CArray) ci, t)); } else { throw new Exceptions.FormatException("Color was expected to be an array.", t); } } } if (meta instanceof MCBookMeta) { if (ma.containsKey("title")) { Construct title = ma.get("title"); if (!(title instanceof CNull)) { ((MCBookMeta) meta).setTitle(title.val()); } } if (ma.containsKey("author")) { Construct author = ma.get("author"); if (!(author instanceof CNull)) { ((MCBookMeta) meta).setAuthor(author.val()); } } if (ma.containsKey("pages")) { Construct pages = ma.get("pages"); if (pages instanceof CNull) { // nothing } else if (pages instanceof CArray) { CArray pa = (CArray) pages; List<String> pl = new ArrayList<String>(); for (int j = 0; j < pa.size(); j++) { pl.add(pa.get(j).val()); } ((MCBookMeta) meta).setPages(pl); } else { throw new Exceptions.FormatException("Pages field was expected to be an array.", t); } } } if (meta instanceof MCSkullMeta) { if (ma.containsKey("owner")) { Construct owner = ma.get("owner"); if (!(owner instanceof CNull)) { ((MCSkullMeta) meta).setOwner(owner.val()); } } } if (meta instanceof MCEnchantmentStorageMeta) { if (ma.containsKey("stored")) { Construct stored = ma.get("stored"); if (stored instanceof CNull) { // Still doing nothing } else if (stored instanceof CArray) { for (String index : ((CArray) stored).keySet()) { try { CArray earray = (CArray) ((CArray) stored).get(index); MCEnchantment etype = StaticLayer.GetConvertor().GetEnchantmentByName(earray.get("etype").val()); int elevel = Static.getInt32(earray.get("elevel"), t); ((MCEnchantmentStorageMeta) meta).addStoredEnchant(etype, elevel, true); } catch (Exception bade) { throw new Exceptions.FormatException( "Could not get enchantment data from index " + index, t); } } } else { throw new Exceptions.FormatException( "Stored field was expected to be an array of Enchantment arrays", t); } } } } catch (Exception ex) { throw new Exceptions.FormatException( "Could not get ItemMeta from the given information.", t); } } else { throw new Exceptions.FormatException( "An array was expected but recieved " + c + " instead.", t); } return meta; }