public void setLobbySignsFromSelection(Player pl, int a) { FileConfiguration c = SettingsManager.getInstance().getSystemConfig(); SettingsManager s = SettingsManager.getInstance(); if (!c.getBoolean("walls-system.lobby.sign.set", false)) { c.set("walls-system.lobby.sign.set", true); s.saveSystemConfig(); } WorldEditPlugin we = GameManager.getInstance().getWorldEdit(); Selection sel = we.getSelection(pl); if (sel == null) { pl.sendMessage(ChatColor.RED + "You must make a WorldEdit Selection first"); return; } if ((sel.getNativeMaximumPoint().getBlockX() - sel.getNativeMinimumPoint().getBlockX()) != 0 && (sel.getNativeMinimumPoint().getBlockZ() - sel.getNativeMaximumPoint().getBlockZ() != 0)) { pl.sendMessage(ChatColor.RED + " Must be in a straight line!"); return; } Vector max = sel.getNativeMaximumPoint(); Vector min = sel.getNativeMinimumPoint(); int i = c.getInt("walls-system.lobby.signno", 0) + 1; c.set("walls-system.lobby.signno", i); c.set("walls-system.lobby.signs." + i + ".id", a); c.set("walls-system.lobby.signs." + i + ".world", pl.getWorld().getName()); c.set("walls-system.lobby.signs." + i + ".x1", max.getBlockX()); c.set("walls-system.lobby.signs." + i + ".y1", max.getBlockY()); c.set("walls-system.lobby.signs." + i + ".z1", max.getBlockZ()); c.set("walls-system.lobby.signs." + i + ".x2", min.getBlockX()); c.set("walls-system.lobby.signs." + i + ".y2", min.getBlockY()); c.set("walls-system.lobby.signs." + i + ".z2", min.getBlockZ()); pl.sendMessage(ChatColor.GREEN + "Added Lobby Wall"); // TODO s.saveSystemConfig(); loadSign(i); }
/** * Set block type. * * @param pt * @param type * @return */ @Override public boolean setBlockType(Vector pt, int type) { world.setBlockId( pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), (short) type, WorldEditPlugin.getInstance()); return world.getBlockId(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()) != type; }
public ConstructionZoneNode findOnPosition(UUID worldUUID, Vector position) { ConstructionZoneNode constructionZone = null; Map<String, Object> params = Maps.newHashMap(); params.put("worldId", worldUUID.toString()); String query = "MATCH ( world: " + WorldNode.LABEL + " { " + WorldNode.UUID_PROPERTY + ": {worldId} })" + " WITH world " + " MATCH (world)<-[:" + RelTypes.WITHIN + "]-(s:" + ConstructionZoneNode.LABEL + ")" + " WHERE " + " s." + ConstructionZoneNode.MAX_X_PROPERTY + " >= " + position.getBlockX() + " AND s." + ConstructionZoneNode.MIN_X_PROPERTY + " <= " + position.getBlockX() + " AND s." + ConstructionZoneNode.MAX_Y_PROPERTY + " >= " + position.getBlockY() + " AND s." + ConstructionZoneNode.MIN_Y_PROPERTY + " <= " + position.getBlockY() + " AND s." + ConstructionZoneNode.MAX_Z_PROPERTY + " >= " + position.getBlockZ() + " AND s." + ConstructionZoneNode.MIN_Z_PROPERTY + " <= " + position.getBlockZ() + " RETURN s as zone" + " LIMIT 1"; Result result = graph.execute(query, params); while (result.hasNext()) { Map<String, Object> map = result.next(); Node n = (Node) map.get("zone"); constructionZone = new ConstructionZoneNode(n); } return constructionZone; }
/** * Find needed chunks in the axis-aligned bounding box of the region. * * @param region The {@link Region} to iterate */ private void findNeededCuboidChunks(Region region) { Vector min = region.getMinimumPoint(); Vector max = region.getMaximumPoint(); // First, we need to group points by chunk so that we only need // to keep one chunk in memory at any given moment for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) { for (int y = min.getBlockY(); y <= max.getBlockY(); ++y) { for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) { Vector pos = new Vector(x, y, z); checkAndAddBlock(pos); } } } }
public ConstructionZoneNode add(CuboidRegion region, AccessType accessType) { Vector min = region.getMinimumPoint(); Vector max = region.getMaximumPoint(); Node n = graph.createNode(PlotNode.plotLabel(), ConstructionZoneNode.label()); n.setProperty(ConstructionZoneNode.ID_PROPERTY, nextId()); ConstructionZoneNode zone = new ConstructionZoneNode(n); zone.setAccessType(accessType); zone.setMinX(min.getBlockX()); zone.setMinY(min.getBlockY()); zone.setMinZ(min.getBlockZ()); zone.setMaxX(max.getBlockX()); zone.setMaxY(max.getBlockY()); zone.setMaxZ(max.getBlockZ()); return zone; }
@Command( aliases = {"clipboard", "copy"}, usage = "", desc = "Choose the clipboard brush", help = "Chooses the clipboard brush.\n" + "The -a flag makes it not paste air.\n" + "Without the -p flag, the paste will appear centered at the target location. " + "With the flag, then the paste will appear relative to where you had " + "stood relative to the copied area when you copied it.") @CommandPermissions("worldedit.brush.clipboard") public void clipboardBrush( Player player, LocalSession session, EditSession editSession, @Switch('a') boolean ignoreAir, @Switch('p') boolean usingOrigin) throws WorldEditException { ClipboardHolder holder = session.getClipboard(); Clipboard clipboard = holder.getClipboard(); Vector size = clipboard.getDimensions(); worldEdit.checkMaxBrushRadius(size.getBlockX()); worldEdit.checkMaxBrushRadius(size.getBlockY()); worldEdit.checkMaxBrushRadius(size.getBlockZ()); BrushTool tool = session.getBrushTool(player.getItemInHand()); tool.setBrush(new ClipboardBrush(holder, ignoreAir, usingOrigin), "worldedit.brush.clipboard"); player.print("Clipboard brush shape equipped."); }
/** * Set the minimum and maximum points of the bounding box for a region * * @param points the points to set with at least one entry */ protected void setMinMaxPoints(List<Vector> points) { int minX = points.get(0).getBlockX(); int minY = points.get(0).getBlockY(); int minZ = points.get(0).getBlockZ(); int maxX = minX; int maxY = minY; int maxZ = minZ; for (Vector v : points) { int x = v.getBlockX(); int y = v.getBlockY(); int z = v.getBlockZ(); if (x < minX) minX = x; if (y < minY) minY = y; if (z < minZ) minZ = z; if (x > maxX) maxX = x; if (y > maxY) maxY = y; if (z > maxZ) maxZ = z; } setDirty(true); min = new BlockVector(minX, minY, minZ); max = new BlockVector(maxX, maxY, maxZ); }
@Override public boolean contains(Vector position) { double x = position.getX(); double y = position.getY(); double z = position.getZ(); Vector min = getMinimumPoint(); Vector max = getMaximumPoint(); return x >= min.getBlockX() && x <= max.getBlockX() && y >= min.getBlockY() && y <= max.getBlockY() && z >= min.getBlockZ() && z <= max.getBlockZ(); }
/** * Transform NBT data in the given entity state and return a new instance if the NBT data needs to * be transformed. * * @param state the existing state * @return a new state or the existing one */ private BaseEntity transformNbtData(BaseEntity state) { CompoundTag tag = state.getNbtData(); if (tag != null) { // Handle hanging entities (paintings, item frames, etc.) boolean hasTilePosition = tag.containsKey("TileX") && tag.containsKey("TileY") && tag.containsKey("TileZ"); boolean hasDirection = tag.containsKey("Direction"); boolean hasLegacyDirection = tag.containsKey("Dir"); boolean hasFacing = tag.containsKey("Facing"); if (hasTilePosition) { Vector tilePosition = new Vector(tag.asInt("TileX"), tag.asInt("TileY"), tag.asInt("TileZ")); Vector newTilePosition = transform.apply(tilePosition.subtract(from)).add(to); CompoundTagBuilder builder = tag.createBuilder() .putInt("TileX", newTilePosition.getBlockX()) .putInt("TileY", newTilePosition.getBlockY()) .putInt("TileZ", newTilePosition.getBlockZ()); if (hasDirection || hasLegacyDirection || hasFacing) { int d; if (hasDirection) { d = tag.asInt("Direction"); } else if (hasLegacyDirection) { d = MCDirections.fromLegacyHanging((byte) tag.asInt("Dir")); } else { d = tag.asInt("Facing"); } Direction direction = MCDirections.fromHanging(d); if (direction != null) { Vector vector = transform .apply(direction.toVector()) .subtract(transform.apply(Vector.ZERO)) .normalize(); Direction newDirection = Direction.findClosest(vector, Flag.CARDINAL); if (newDirection != null) { byte hangingByte = (byte) MCDirections.toHanging(newDirection); builder.putByte("Direction", hangingByte); builder.putByte("Facing", hangingByte); builder.putByte( "Dir", MCDirections.toLegacyHanging(MCDirections.toHanging(newDirection))); } } } return new BaseEntity(state.getTypeId(), builder.build()); } } return state; }
@Override public boolean containedWithin(Vector min, Vector max) { if (min instanceof ChunkVector && max instanceof ChunkVector) { return super.containedWithin(min, max); } int minX = this.getBlockX() << 4; int minY = this.getBlockY() << 4; int minZ = this.getBlockZ() << 4; int maxX = (this.getBlockX() << 4) + 15; int maxY = (this.getBlockY() << 4) + 15; int maxZ = (this.getBlockZ() << 4) + 15; return minX >= min.getBlockX() && minY >= min.getBlockY() && minZ >= min.getBlockZ() && maxX <= max.getBlockX() && maxY <= max.getBlockY() && maxZ <= max.getBlockZ(); }
/** Checks to see if a point is inside this region. */ @Override public boolean contains(Vector pt) { int targetX = pt.getBlockX(); // wide int targetY = pt.getBlockY(); // height int targetZ = pt.getBlockZ(); // depth if (targetY < minY || targetY > maxY) { return false; } // Quick and dirty check. if (targetX < min.getBlockX() || targetX > max.getBlockX() || targetZ < min.getBlockZ() || targetZ > max.getBlockZ()) { return false; } boolean inside = false; int npoints = points.size(); int xNew, zNew; int xOld, zOld; int x1, z1; int x2, z2; int i; xOld = points.get(npoints - 1).getBlockX(); zOld = points.get(npoints - 1).getBlockZ(); for (i = 0; i < npoints; i++) { xNew = points.get(i).getBlockX(); zNew = points.get(i).getBlockZ(); // Check for corner if (xNew == targetX && zNew == targetZ) { return true; } if (xNew > xOld) { x1 = xOld; x2 = xNew; z1 = zOld; z2 = zNew; } else { x1 = xNew; x2 = xOld; z1 = zNew; z2 = zOld; } if ((xNew < targetX) == (targetX <= xOld) && ((long) targetZ - (long) z1) * (long) (x2 - x1) <= ((long) z2 - (long) z1) * (long) (targetX - x1)) { inside = !inside; } xOld = xNew; zOld = zNew; } return inside; }
@Override public Set<Vector2D> getChunks() { Set<Vector2D> chunks = new HashSet<Vector2D>(); Vector min = getMinimumPoint(); Vector max = getMaximumPoint(); for (int x = min.getBlockX() >> ChunkStore.CHUNK_SHIFTS; x <= max.getBlockX() >> ChunkStore.CHUNK_SHIFTS; ++x) { for (int z = min.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; z <= max.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; ++z) { chunks.add(new BlockVector2D(x, z)); } } return chunks; }
/** * set block type & data * * @param pt * @param type * @param data * @return */ @Override public boolean setTypeIdAndData(Vector pt, int type, int data) { int origType = getBlockType(pt), origData = getBlockData(pt); world.setBlockIdAndData( pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), (short) type, (short) data, WorldEditPlugin.getInstance()); return origType != type && origData != data; }
/** * Find needed chunks in the cuboid of the region. * * @param region */ private void findNeededCuboidChunks(Region region) { Vector min = region.getMinimumPoint(); Vector max = region.getMaximumPoint(); // First, we need to group points by chunk so that we only need // to keep one chunk in memory at any given moment for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) { for (int y = min.getBlockY(); y <= max.getBlockY(); ++y) { for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) { Vector pos = new Vector(x, y, z); BlockVector2D chunkPos = ChunkStore.toChunk(pos); // Unidentified chunk if (!neededChunks.containsKey(chunkPos)) { neededChunks.put(chunkPos, new ArrayList<Vector>()); } neededChunks.get(chunkPos).add(pos); } } } }
@Override public void load() { radius = ICUtil.parseRadius(getSign()); String radiusString = radius.getBlockX() + "," + radius.getBlockY() + "," + radius.getBlockZ(); if (radius.getBlockX() == radius.getBlockY() && radius.getBlockY() == radius.getBlockZ()) radiusString = String.valueOf(radius.getBlockX()); if (getLine(2).contains("=")) { getSign().setLine(2, radiusString + "=" + RegexUtil.EQUALS_PATTERN.split(getLine(2))[1]); centre = ICUtil.parseBlockLocation(getSign(), 2).getLocation(); } else { getSign().setLine(2, radiusString); centre = getBackBlock().getLocation(); } include = !getLine(3).startsWith("-"); for (String bit : getLine(3).replace("-", "").split(",")) { filters.add(ItemUtil.getItem(bit)); } chest = getBackBlock().getRelative(0, 1, 0); }
public boolean selectSecondary(Vector pos) { if (region.size() > 0) { final List<BlockVector2D> points = region.getPoints(); final BlockVector2D lastPoint = points.get(region.size() - 1); if (lastPoint.getBlockX() == pos.getBlockX() && lastPoint.getBlockZ() == pos.getBlockZ()) { return false; } if (maxPoints >= 0 && points.size() > maxPoints) { return false; } } region.addPoint(pos); region.expandY(pos.getBlockY()); return true; }
private RetVal subEntrance(ArrayList<String> arg, String pName) { Log.debug("CommandDungeon.subEntrance"); RetVal r = new RetVal(); if (arg.isEmpty()) { r.Err( Config.ecol + "Error - Invalid number of arguments! Command is /" + Config.command + " dungeon entrance <dungeon name> (while standing at the warp-in point)!"); return r; } DungeonData d = DungeonManager.getDungeon(arg.get(0)); if (d == null) { r.Err(Config.ecol + "Error - Invalid argument! '" + arg.get(0) + "' not a valid Dungeon!"); return r; } InstanceData i = InstanceManager.getEditInstanceForDungeon(d.name); if (i == null) { r.Err( Config.ecol + "Error - Invalid argument! '" + arg.get(0) + "' does not have an edit Instance!"); return r; } Location l = bridge.getPlayerLoc(pName); Vector v = l.getPosition(); Vector vOff = v.subtract(i.getBounds().getMinimumPoint()); d.setSpawn(vOff.getBlockX(), vOff.getBlockY(), vOff.getBlockZ(), l.getYaw(), l.getPitch()); r.add("Successfully added spawn in location to Dungeon '" + arg.get(0) + "'"); r.tru(); return r; }
public WorldEditSchematic(Object schematic) { weSchematic = (CuboidClipboard) schematic; // Center at the bottom X,Z center // This should be configurable, maybe? try { com.sk89q.worldedit.Vector weSize = weSchematic.getSize(); size = new Vector(weSize.getBlockX(), weSize.getBlockY(), weSize.getBlockZ()); center = new Vector(Math.floor(size.getBlockX() / 2), 0, Math.floor(size.getBlockZ() / 2)); } catch (Exception ex) { ex.printStackTrace(); } if (center == null) { center = new Vector(0, 0, 0); } if (size == null) { size = new Vector(0, 0, 0); } }
public Collection<ConstructionZoneNode> findWithin( UUID worldUUID, CuboidRegion searchArea, int limit) { List<ConstructionZoneNode> zones = new ArrayList<>(); Map<String, Object> params = Maps.newHashMap(); params.put("worldId", worldUUID.toString()); if (limit > 0) { params.put("limit", limit); } Vector min = searchArea.getMinimumPoint(); Vector max = searchArea.getMaximumPoint(); String query = "MATCH (world:" + WorldNode.LABEL + " { " + WorldNode.UUID_PROPERTY + ": {worldId} })" + " WITH world " + " MATCH (world)<-[:" + RelTypes.WITHIN.name() + "]-(s:" + ConstructionZoneNode.LABEL + ")" + " WHERE " + " s." + ConstructionZoneNode.MAX_X_PROPERTY + " >= " + min.getBlockX() + " AND s." + ConstructionZoneNode.MIN_X_PROPERTY + " <= " + max.getBlockX() + " AND s." + ConstructionZoneNode.MAX_Y_PROPERTY + " >= " + min.getBlockY() + " AND s." + ConstructionZoneNode.MIN_Y_PROPERTY + " <= " + max.getBlockY() + " AND s." + ConstructionZoneNode.MAX_Z_PROPERTY + " >= " + min.getBlockZ() + " AND s." + ConstructionZoneNode.MIN_Z_PROPERTY + " <= " + max.getBlockZ() + " RETURN s"; if (limit > 0) { query += " LIMIT {limit}"; } Result result = graph.execute(query, params); while (result.hasNext()) { Map<String, Object> map = result.next(); for (Object o : map.values()) { zones.add(new ConstructionZoneNode((Node) o)); } } return zones; }
@Override public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException { int id = block.getType(); switch (id) { case 54: case 130: case 142: case 27: case 137: case 52: case 154: case 84: case 25: case 144: case 138: case 176: case 177: case 63: case 68: case 323: case 117: case 116: case 28: case 66: case 157: case 61: case 62: case 140: case 146: case 149: case 150: case 158: case 23: case 123: case 124: case 29: case 33: case 151: case 178: { if (this.BSblocked) { return false; } this.BScount++; if (this.BScount > Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES) { this.BSblocked = true; PS.debug( "&cPlotSquared detected unsafe WorldEdit: " + location.getBlockX() + "," + location.getBlockZ()); } if (WEManager.maskContains( this.mask, location.getBlockX(), location.getBlockY(), location.getBlockZ())) { if (this.count++ > this.max) { if (this.parent != null) { try { Field field = AbstractDelegateExtent.class.getDeclaredField("extent"); field.setAccessible(true); field.set(this.parent, new com.sk89q.worldedit.extent.NullExtent()); } catch (Exception e) { e.printStackTrace(); } this.parent = null; } return false; } return super.setBlock(location, block); } break; } default: { int x = location.getBlockX(); int y = location.getBlockY(); int z = location.getBlockZ(); if (WEManager.maskContains( this.mask, location.getBlockX(), location.getBlockY(), location.getBlockZ())) { if (this.count++ > this.max) { if (this.parent != null) { try { Field field = AbstractDelegateExtent.class.getDeclaredField("extent"); field.setAccessible(true); field.set(this.parent, new com.sk89q.worldedit.extent.NullExtent()); } catch (Exception e) { e.printStackTrace(); } this.parent = null; } return false; } switch (id) { case 0: case 2: case 4: case 13: case 14: case 15: case 20: case 21: case 22: case 24: case 25: case 30: case 32: case 37: case 39: case 40: case 41: case 42: case 45: case 46: case 47: case 48: case 49: case 51: case 52: case 54: case 55: case 56: case 57: case 58: case 60: case 61: case 62: case 7: case 8: case 9: case 10: case 11: case 73: case 74: case 78: case 79: case 80: case 81: case 82: case 83: case 84: case 85: case 87: case 88: case 101: case 102: case 103: case 110: case 112: case 113: case 117: case 121: case 122: case 123: case 124: case 129: case 133: case 138: case 137: case 140: case 165: case 166: case 169: case 170: case 172: case 173: case 174: case 176: case 177: case 181: case 182: case 188: case 189: case 190: case 191: case 192: { if (Settings.EXPERIMENTAL_FAST_ASYNC_WORLDEDIT) { SetQueue.IMP.setBlock(this.world, x, y, z, id); } else { super.setBlock(location, block); } break; } default: { if (Settings.EXPERIMENTAL_FAST_ASYNC_WORLDEDIT) { SetQueue.IMP.setBlock( this.world, x, y, z, new PlotBlock((short) id, (byte) block.getData())); } else { super.setBlock(location, block); } break; } } return true; } } } return false; }
/** * Get block light level. * * @param pt * @return */ @Override public int getBlockLightLevel(Vector pt) { return world.getBlockMaterial(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getLightLevel(); }
public void terraform(boolean overrideChance) { for (int x = -radius.getBlockX() + 1; x < radius.getBlockX(); x++) { for (int y = -radius.getBlockY() + 1; y < radius.getBlockY(); y++) { for (int z = -radius.getBlockZ() + 1; z < radius.getBlockZ(); z++) { if (overrideChance || CraftBookPlugin.inst().getRandom().nextInt(40) == 0) { int rx = location.getX() - x; int ry = location.getY() - y; int rz = location.getZ() - z; Block b = BukkitUtil.toSign(getSign()).getWorld().getBlockAt(rx, ry, rz); if (b.getTypeId() == BlockID.CROPS && b.getData() < 0x7) { if (consumeBonemeal()) { b.setData((byte) (b.getData() + 0x1)); } return; } if ((b.getTypeId() == BlockID.CROPS || b.getTypeId() == BlockID.CARROTS || b.getTypeId() == BlockID.POTATOES || b.getTypeId() == BlockID.MELON_STEM || b.getTypeId() == BlockID.PUMPKIN_STEM) && b.getData() < 0x7) { if (consumeBonemeal()) { byte add = (byte) CraftBookPlugin.inst().getRandom().nextInt(3); if (b.getData() + add > 0x7) b.setData((byte) 0x7); else b.setData((byte) (b.getData() + add)); } return; } if (b.getTypeId() == BlockID.COCOA_PLANT && ((b.getData() & 0x8) != 0x8 || (b.getData() & 0xC) != 0xC)) { if (consumeBonemeal()) { if (CraftBookPlugin.inst().getRandom().nextInt(30) == 0) b.setData((byte) (b.getData() | 0xC)); else b.setData((byte) (b.getData() | 0x8)); } return; } if (b.getTypeId() == BlockID.NETHER_WART && b.getData() < 0x3) { if (consumeBonemeal()) { b.setData((byte) (b.getData() + 0x1)); } return; } if (b.getTypeId() == BlockID.SAPLING) { if (consumeBonemeal()) { if (!growTree(b, CraftBookPlugin.inst().getRandom())) refundBonemeal(); else return; } } if (b.getTypeId() == BlockID.BROWN_MUSHROOM || b.getTypeId() == BlockID.RED_MUSHROOM) { if (consumeBonemeal()) { if (b.getTypeId() == BlockID.BROWN_MUSHROOM) { b.setTypeId(0); if (!b.getWorld().generateTree(b.getLocation(), TreeType.BROWN_MUSHROOM)) { b.setTypeId(BlockID.BROWN_MUSHROOM); refundBonemeal(); } else return; } if (b.getTypeId() == BlockID.RED_MUSHROOM) { b.setTypeId(0); if (!b.getWorld().generateTree(b.getLocation(), TreeType.RED_MUSHROOM)) { b.setTypeId(BlockID.RED_MUSHROOM); refundBonemeal(); } else return; } } } if ((b.getTypeId() == BlockID.REED || b.getTypeId() == BlockID.CACTUS) && b.getData() < 0x15 && b.getRelative(0, 1, 0).getTypeId() == 0) { if (consumeBonemeal()) { b.getRelative(0, 1, 0).setTypeId(b.getTypeId()); } return; } if (b.getTypeId() == BlockID.DIRT && b.getRelative(0, 1, 0).getTypeId() == 0) { if (consumeBonemeal()) { b.setTypeId( b.getBiome() == Biome.MUSHROOM_ISLAND || b.getBiome() == Biome.MUSHROOM_SHORE ? BlockID.MYCELIUM : BlockID.GRASS); } return; } if (b.getTypeId() == BlockID.GRASS && b.getRelative(0, 1, 0).getTypeId() == BlockID.AIR && CraftBookPlugin.inst().getRandom().nextInt(15) == 0) { if (consumeBonemeal()) { int t = CraftBookPlugin.inst().getRandom().nextInt(7); if (t == 0) { b.getRelative(0, 1, 0).setTypeIdAndData(BlockID.LONG_GRASS, (byte) 1, true); } else if (t == 1) { b.getRelative(0, 1, 0).setTypeId(BlockID.YELLOW_FLOWER); } else if (t == 2) { b.getRelative(0, 1, 0).setTypeId(BlockID.RED_FLOWER); } else if (t == 3) { b.getRelative(0, 1, 0).setTypeIdAndData(BlockID.LONG_GRASS, (byte) 2, true); } else { b.getRelative(0, 1, 0).setTypeIdAndData(BlockID.LONG_GRASS, (byte) 1, true); } } return; } if (b.getTypeId() == BlockID.SAND && b.getRelative(0, 1, 0).getTypeId() == BlockID.AIR && CraftBookPlugin.inst().getRandom().nextInt(15) == 0) { if (consumeBonemeal()) { b.getRelative(0, 1, 0).setTypeIdAndData(BlockID.LONG_GRASS, (byte) 0, true); } return; } if (b.getTypeId() == BlockID.VINE && b.getRelative(0, -1, 0).getTypeId() == BlockID.AIR && CraftBookPlugin.inst().getRandom().nextInt(15) == 0) { if (consumeBonemeal()) { b.getRelative(0, -1, 0).setTypeIdAndData(BlockID.VINE, b.getData(), true); } return; } if (b.getTypeId() == BlockID.STATIONARY_WATER && b.getRelative(0, 1, 0).getTypeId() == BlockID.AIR && CraftBookPlugin.inst().getRandom().nextInt(30) == 0) { if (consumeBonemeal()) { b.getRelative(0, 1, 0).setTypeId(BlockID.LILY_PAD); } return; } if (b.getTypeId() == BlockID.MYCELIUM && b.getRelative(0, 1, 0).getTypeId() == BlockID.AIR && CraftBookPlugin.inst().getRandom().nextInt(15) == 0) { if (consumeBonemeal()) { int t = CraftBookPlugin.inst().getRandom().nextInt(2); if (t == 0) { b.getRelative(0, 1, 0).setTypeId(BlockID.RED_MUSHROOM); } else if (t == 1) { b.getRelative(0, 1, 0).setTypeId(BlockID.BROWN_MUSHROOM); } } return; } } } } } }
/** * Get block type. * * @param pt * @return */ @Override public int getBlockType(Vector pt) { return world.getBlockId(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); }
public RegionWrapper(Vector pos1, Vector pos2) { this.minX = Math.min(pos1.getBlockX(), pos2.getBlockX()); this.minZ = Math.min(pos1.getBlockZ(), pos2.getBlockZ()); this.maxX = Math.max(pos1.getBlockX(), pos2.getBlockX()); this.maxZ = Math.max(pos1.getBlockZ(), pos2.getBlockZ()); }
public static ChunkVector fromVector(Vector pt) { if (pt instanceof ChunkVector) return (ChunkVector) pt; return new ChunkVector(pt.getBlockX() >> 4, pt.getBlockY() >> 4, pt.getBlockZ() >> 4); }
@Command( aliases = {"save"}, desc = "Saves the selected area", usage = "[-n namespace ] <id>", flags = "n:", min = 1) public void saveArea(CommandContext context, CommandSender sender) throws CommandException { if (!(sender instanceof Player)) return; LocalPlayer player = plugin.wrapPlayer((Player) sender); String id; String namespace = player.getName(); boolean personal = true; if (context.hasFlag('n') && player.hasPermission("craftbook.mech.area.save." + context.getFlag('n'))) { namespace = context.getFlag('n'); personal = false; } else if (!player.hasPermission("craftbook.mech.area.save.self")) throw new CommandPermissionsException(); if (plugin.getConfiguration().areaShortenNames && namespace.length() > 14) namespace = namespace.substring(0, 14); if (!CopyManager.isValidNamespace(namespace)) throw new CommandException("Invalid namespace. Needs to be between 1 and 14 letters long."); if (personal) { namespace = "~" + namespace; } id = context.getString(0); if (!CopyManager.isValidName(id)) throw new CommandException("Invalid area name. Needs to be between 1 and 13 letters long."); try { WorldEditPlugin worldEdit = CraftBookPlugin.plugins.getWorldEdit(); World world = ((Player) sender).getWorld(); Selection sel = worldEdit.getSelection((Player) sender); if (sel == null) { sender.sendMessage(ChatColor.RED + "You have not made a selection!"); return; } Vector min = BukkitUtil.toVector(sel.getMinimumPoint()); Vector max = BukkitUtil.toVector(sel.getMaximumPoint()); Vector size = max.subtract(min).add(1, 1, 1); // Check maximum size if (config.areaMaxAreaSize != -1 && size.getBlockX() * size.getBlockY() * size.getBlockZ() > config.areaMaxAreaSize) { throw new CommandException( "Area is larger than allowed " + config.areaMaxAreaSize + " blocks."); } // Check to make sure that a user doesn't have too many toggle // areas (to prevent flooding the server with files) if (config.areaMaxAreaPerUser >= 0 && !namespace.equals("global")) { int count = copyManager.meetsQuota(world, namespace, id, config.areaMaxAreaPerUser); if (count > -1) { throw new CommandException( "You are limited to " + config.areaMaxAreaPerUser + " toggle area(s). " + "You have " + count + " areas."); } } // Copy CuboidCopy copy; if (config.areaUseSchematics) { copy = new MCEditCuboidCopy(min, size, world); } else { copy = new FlatCuboidCopy(min, size, world); } copy.copy(); plugin .getServer() .getLogger() .info( player.getName() + " saving toggle area with folder '" + namespace + "' and ID '" + id + "'."); // Save try { CopyManager.getInstance().save(world, namespace, id.toLowerCase(Locale.ENGLISH), copy); player.print("Area saved as '" + id + "' under the '" + namespace + "' namespace."); } catch (IOException e) { player.printError("Could not save area: " + e.getMessage()); } catch (DataException e) { player.print(e.getMessage()); } } catch (NoClassDefFoundError e) { throw new CommandException( "WorldEdit.jar does not exist in plugins/, or is outdated. (Or you are using an outdated version of CraftBook)"); } }
/** * Set block data. * * @param pt * @param data */ @Override public void setBlockData(Vector pt, int data) { setTypeIdAndData(pt, world.getBlockId(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()), data); }
/** * Get block data. * * @param pt * @return */ @Override public int getBlockData(Vector pt) { return world.getBlockData(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); }
@Override public int getBlockZ() { return m_parent.getBlockZ(); }