public void onDataSave() { File dir = new File("data", "quotes"); dir.mkdir(); BinBuffer binb = new BinBuffer(); Iterator<Entry<String, ArrayList<Quote>>> it = quotes.entrySet().iterator(); while (it.hasNext()) { binb.clear(); Entry<String, ArrayList<Quote>> pair = it.next(); ArrayList<Quote> quotes = pair.getValue(); for (Quote quote : quotes) { binb.writeUString( StringTools.implode(quote.nicks.toArray(new String[quote.nicks.size()]), " ")); binb.writeUString(quote.quote); } binb.setPos(0); new BinFile(new File(dir, pair.getKey())).write(binb); } }
public void onEnable() { File dir = new File("data", "quotes"); dir.mkdir(); File[] files = dir.listFiles(); for (File f : files) { if (f.isDirectory()) return; String channel = f.getName(); BinBuffer binb = new BinFile(f).read(); binb.setPos(0); quotes.put(channel, new ArrayList<Quote>()); while (binb.bytesLeft() > 0) { String[] nicks = binb.readUString().split(" "); String quote = binb.readUString(); quotes.get(channel).add(new Quote(nicks, quote)); } } Command.addCommands( this, cmd = new CmdQuote(), cmdAdd = new CmdQuoteAdd(), cmdRemove = new CmdQuoteRemove()); Command.addCommand(this, "q", cmd); Command.addCommand(this, "qadd", cmdAdd); Command.addCommand(this, "qdel", cmdRemove); }
public void readData(BinBuffer buffer) { super.readData(buffer); value = buffer.readUInt(); }
public void writeData(BinBuffer buffer) { super.writeData(buffer); buffer.writeUInt(value); }
public void readData(BinBuffer buffer) { super.readData(buffer); value = buffer.readChars(buffer.readUShort()); }
public void writeData(BinBuffer buffer) { super.writeData(buffer); buffer.writeUShort(value.length()); buffer.writeChars(value); }
public void writeBinBuffer(BinBuffer binb, int bytes) { for (int i = 0; i < bytes; i++) writeByte(binb.readByte()); }
public void writeBinBuffer(BinBuffer binb) { writeBinBuffer(binb, binb.bytesLeft()); }
public BinBuffer copy(int bytes) { BinBuffer binb = new BinBuffer(); for (int i = 0; i < bytes; i++) binb.writeByte(readByte()); return binb; }