Beispiel #1
0
  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);
    }
  }
Beispiel #2
0
  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);
  }
Beispiel #3
0
 public void readData(BinBuffer buffer) {
   super.readData(buffer);
   value = buffer.readUInt();
 }
Beispiel #4
0
 public void writeData(BinBuffer buffer) {
   super.writeData(buffer);
   buffer.writeUInt(value);
 }
Beispiel #5
0
 public void readData(BinBuffer buffer) {
   super.readData(buffer);
   value = buffer.readChars(buffer.readUShort());
 }
Beispiel #6
0
  public void writeData(BinBuffer buffer) {
    super.writeData(buffer);

    buffer.writeUShort(value.length());
    buffer.writeChars(value);
  }
Beispiel #7
0
 public void writeBinBuffer(BinBuffer binb, int bytes) {
   for (int i = 0; i < bytes; i++) writeByte(binb.readByte());
 }
Beispiel #8
0
 public void writeBinBuffer(BinBuffer binb) {
   writeBinBuffer(binb, binb.bytesLeft());
 }
Beispiel #9
0
 public BinBuffer copy(int bytes) {
   BinBuffer binb = new BinBuffer();
   for (int i = 0; i < bytes; i++) binb.writeByte(readByte());
   return binb;
 }