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); }