cn.nukkit.scheduler.FileWriteTask Java Examples

The following examples show how to use cn.nukkit.scheduler.FileWriteTask. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Server.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public void saveOfflinePlayerData(String name, CompoundTag tag, boolean async) {
    if (this.shouldSavePlayerData()) {
        try {
            if (async) {
                this.getScheduler().scheduleAsyncTask(new FileWriteTask(FastAppender.get(this.getDataPath() + "players/", name.toLowerCase(), ".dat"), NBTIO.writeGZIPCompressed(tag, ByteOrder.BIG_ENDIAN)));
            } else {
                Utils.writeFile(FastAppender.get(this.getDataPath(), "players/", name.toLowerCase(), ".dat"), new ByteArrayInputStream(NBTIO.writeGZIPCompressed(tag, ByteOrder.BIG_ENDIAN)));
            }
        } catch (Exception e) {
            this.logger.critical(this.getLanguage().translateString("nukkit.data.saveError", new String[]{name, e.getMessage()}));
            if (Nukkit.DEBUG > 1) {
                this.logger.logException(e);
            }
        }
    }
}
 
Example #2
Source File: Server.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public void saveOfflinePlayerData(String name, CompoundTag tag, boolean async) {
    if (this.shouldSavePlayerData()) {
        try {
            if (async) {
                this.getScheduler().scheduleAsyncTask(new FileWriteTask(this.getDataPath() + "players/" + name.toLowerCase() + ".dat", NBTIO.writeGZIPCompressed(tag, ByteOrder.BIG_ENDIAN)));
            } else {
                Utils.writeFile(this.getDataPath() + "players/" + name.toLowerCase() + ".dat", new ByteArrayInputStream(NBTIO.writeGZIPCompressed(tag, ByteOrder.BIG_ENDIAN)));
            }
        } catch (Exception e) {
            this.logger.critical(this.getLanguage().translateString("nukkit.data.saveError", new String[]{name, e.getMessage()}));
            if (Nukkit.DEBUG > 1) {
                this.logger.logException(e);
            }
        }
    }
}
 
Example #3
Source File: Config.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public boolean save(Boolean async) {
    if (this.file == null) throw new IllegalStateException("Failed to save Config. File object is undefined.");
    if (this.correct) {
        String content = "";
        switch (this.type) {
            case Config.PROPERTIES:
                content = this.writeProperties();
                break;
            case Config.JSON:
                content = new GsonBuilder().setPrettyPrinting().create().toJson(this.config);
                break;
            case Config.YAML:
                DumperOptions dumperOptions = new DumperOptions();
                dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
                Yaml yaml = new Yaml(dumperOptions);
                content = yaml.dump(this.config);
                break;
            case Config.ENUM:
                for (Object o : this.config.entrySet()) {
                    Map.Entry entry = (Map.Entry) o;
                    content += String.valueOf(entry.getKey()) + "\r\n";
                }
                break;
        }
        if (async) {
            Server.getInstance().getScheduler().scheduleAsyncTask(new FileWriteTask(this.file, content));

        } else {
            try {
                Utils.writeFile(this.file, content);
            } catch (IOException e) {
                Server.getInstance().getLogger().logException(e);
            }
        }
        return true;
    } else {
        return false;
    }
}
 
Example #4
Source File: Config.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public boolean save(Boolean async) {
    if (this.file == null) throw new IllegalStateException("Failed to save Config. File object is undefined.");
    if (this.correct) {
        String content = "";
        switch (this.type) {
            case Config.PROPERTIES:
                content = this.writeProperties();
                break;
            case Config.JSON:
                content = new GsonBuilder().setPrettyPrinting().create().toJson(this.config);
                break;
            case Config.YAML:
                DumperOptions dumperOptions = new DumperOptions();
                dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
                Yaml yaml = new Yaml(dumperOptions);
                content = yaml.dump(this.config);
                break;
            case Config.ENUM:
                for (Object o : this.config.entrySet()) {
                    Map.Entry entry = (Map.Entry) o;
                    content += entry.getKey() + "\r\n";
                }
                break;
        }
        if (async) {
            Server.getInstance().getScheduler().scheduleAsyncTask(new FileWriteTask(this.file, content));

        } else {
            try {
                Utils.writeFile(this.file, content);
            } catch (IOException e) {
                Server.getInstance().getLogger().logException(e);
            }
        }
        return true;
    } else {
        return false;
    }
}
 
Example #5
Source File: Config.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public boolean save(Boolean async) {
    if (this.file == null) throw new IllegalStateException("Failed to save Config. File object is undefined.");
    if (this.correct) {
        String content = "";
        switch (this.type) {
            case Config.PROPERTIES:
                content = this.writeProperties();
                break;
            case Config.JSON:
                content = new GsonBuilder().setPrettyPrinting().create().toJson(this.config);
                break;
            case Config.YAML:
                DumperOptions dumperOptions = new DumperOptions();
                dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
                Yaml yaml = new Yaml(dumperOptions);
                content = yaml.dump(this.config);
                break;
            case Config.ENUM:
                for (Object o : this.config.entrySet()) {
                    Map.Entry entry = (Map.Entry) o;
                    content += String.valueOf(entry.getKey()) + "\r\n";
                }
                break;
        }
        if (async) {
            Server.getInstance().getScheduler().scheduleAsyncTask(new FileWriteTask(this.file, content));

        } else {
            try {
                Utils.writeFile(this.file, content);
            } catch (IOException e) {
                Server.getInstance().getLogger().logException(e);
            }
        }
        return true;
    } else {
        return false;
    }
}