/** * Set the area active. * * @param player * @param bag */ public void setActive(BlockBag bag) { try { String namespace = getNamespace(); String activeID = getActiveStateID(); CuboidCopy copy = copyManager.load(namespace, activeID); if (!isNewArea && copy.distance(pt) > 4) { return; } copy.paste(bag); } catch (BlockSourceException e) {; } catch (InvalidSignNamespace e) { } catch (InvalidSignStateID e) { } catch (MissingCuboidCopyException e) { } catch (CuboidCopyException e) { } catch (IOException e) { } }
/** * Set the area inactive. * * @param player * @param bag */ public void setInactive(BlockBag bag) { try { String namespace = getNamespace(); String inactiveID = getInactiveStateID(); CuboidCopy copy = null; if (inactiveID == null) { // Do nothing } else if (inactiveID.length() == 0) { String activeID = getActiveStateID(); copy = copyManager.load(namespace, activeID); if (!isNewArea && copy.distance(pt) > 4) { return; } copy.clear(bag); } else { copy = copyManager.load(namespace, inactiveID); if (!isNewArea && copy.distance(pt) > 4) { return; } copy = copyManager.load(namespace, inactiveID); copy.paste(bag); } } catch (BlockSourceException e) { } catch (InvalidSignNamespace e) { } catch (InvalidSignStateID e) { } catch (MissingCuboidCopyException e) { } catch (CuboidCopyException e) { } catch (IOException e) { } }
/** * Load a copy. * * @param file * @return * @throws IOException * @throws CuboidCopyException */ public static CuboidCopy load(File file) throws IOException, CuboidCopyException { FileInputStream in = new FileInputStream(file); DataInputStream reader = new DataInputStream(in); int x, y, z; int width, height, length; byte[] blocks; byte[] data; try { @SuppressWarnings("unused") byte version = reader.readByte(); x = reader.readInt(); y = reader.readInt(); z = reader.readInt(); width = reader.readInt(); height = reader.readInt(); length = reader.readInt(); int size = width * height * length; blocks = new byte[size]; data = new byte[size]; if (reader.read(blocks, 0, size) != size) { throw new CuboidCopyException("File error: Bad size"); } data = new byte[size]; if (reader.read(data, 0, size) != size) { throw new CuboidCopyException("File error: Bad size"); } } finally { try { in.close(); } catch (IOException e) { } } CuboidCopy copy = new CuboidCopy(); copy.origin = new Vector(x, y, z); copy.width = width; copy.height = height; copy.length = length; copy.blocks = blocks; copy.data = data; copy.findTestOffset(); return copy; }
/** * Toggle the area. * * @param player * @param bag * @throws BlockSourceException */ public void playerToggle(CraftBookPlayer player, BlockBag bag) throws BlockSourceException { try { String namespace = getNamespace(); String activeID = getActiveStateID(); CuboidCopy copy = copyManager.load(namespace, activeID); if (!isNewArea && copy.distance(pt) > 4) { player.printError("This sign is too far away!"); return; } if (!copy.shouldClear()) { copy.paste(bag); } else { String inactiveID = getInactiveStateID(); if (inactiveID == null) { // Do nothing } else if (inactiveID.length() == 0) { copy.clear(bag); } else { copy = copyManager.load(namespace, inactiveID); copy.paste(bag); } } player.print("Toggled!"); } catch (InvalidSignNamespace e) { player.printError("The namespace on the sign is invalid."); } catch (InvalidSignStateID e) { player.printError("A copy ID on the sign is invalid."); } catch (MissingCuboidCopyException e) { player.printError("The '" + e.getCopyName() + "' area does not exist."); } catch (CuboidCopyException e) { player.printError("Could not load area: " + e.getMessage()); } catch (IOException e) { player.printError("Could not load area: " + e.getMessage()); } }