当前位置: 首页>>代码示例>>Java>>正文


Java Utils类代码示例

本文整理汇总了Java中cn.nukkit.utils.Utils的典型用法代码示例。如果您正苦于以下问题:Java Utils类的具体用法?Java Utils怎么用?Java Utils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Utils类属于cn.nukkit.utils包,在下文中一共展示了Utils类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPluginDescription

import cn.nukkit.utils.Utils; //导入依赖的package包/类
@Override
public PluginDescription getPluginDescription(File file) {
    try (JarFile jar = new JarFile(file)) {
        JarEntry entry = jar.getJarEntry("nukkit.yml");
        if (entry == null) {
            entry = jar.getJarEntry("plugin.yml");
            if (entry == null) {
                return null;
            }
        }
        try (InputStream stream = jar.getInputStream(entry)) {
            return new PluginDescription(Utils.readFile(stream));
        }
    } catch (IOException e) {
        return null;
    }
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:18,代码来源:JavaPluginLoader.java

示例2: initEntity

import cn.nukkit.utils.Utils; //导入依赖的package包/类
@Override
protected void initEntity() {
    this.setDataFlag(DATA_PLAYER_FLAGS, DATA_PLAYER_FLAG_SLEEP, false);
    this.setDataFlag(DATA_FLAGS, DATA_FLAG_GRAVITY);

    this.setDataProperty(new IntPositionEntityData(DATA_PLAYER_BED_POSITION, 0, 0, 0), false);

    if (!(this instanceof Player)) {
        if (this.namedTag.contains("NameTag")) {
            this.setNameTag(this.namedTag.getString("NameTag"));
        }

        if (this.namedTag.contains("Skin") && this.namedTag.get("Skin") instanceof CompoundTag) {
            if (!this.namedTag.getCompound("Skin").contains("Transparent")) {
                this.namedTag.getCompound("Skin").putBoolean("Transparent", false);
            }
            this.setSkin(new Skin(this.namedTag.getCompound("Skin").getByteArray("Data"), this.namedTag.getCompound("Skin").getString("ModelId")));
        }

        this.uuid = Utils.dataToUUID(String.valueOf(this.getId()).getBytes(StandardCharsets.UTF_8), this.getSkin()
                .getData(), this.getNameTag().getBytes(StandardCharsets.UTF_8));
    }

    super.initEntity();
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:26,代码来源:EntityHuman.java

示例3: load

import cn.nukkit.utils.Utils; //导入依赖的package包/类
public void load() {
    this.list = new LinkedHashMap<>();
    File file = new File(this.file);
    try {
        if (!file.exists()) {
            file.createNewFile();
            this.save();
        } else {

            LinkedList<TreeMap<String, String>> list = new Gson().fromJson(Utils.readFile(this.file), new TypeToken<LinkedList<TreeMap<String, String>>>() {
            }.getType());
            for (TreeMap<String, String> map : list) {
                BanEntry entry = BanEntry.fromMap(map);
                this.list.put(entry.getName(), entry);
            }
        }
    } catch (IOException e) {
        MainLogger.getLogger().error("Could not load ban list: ", e);
    }

}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:22,代码来源:BanList.java

示例4: save

import cn.nukkit.utils.Utils; //导入依赖的package包/类
public void save() {
    this.removeExpired();

    try {
        File file = new File(this.file);
        if (!file.exists()) {
            file.createNewFile();
        }

        LinkedList<LinkedHashMap<String, String>> list = new LinkedList<>();
        for (BanEntry entry : this.list.values()) {
            list.add(entry.getMap());
        }
        Utils.writeFile(this.file, new ByteArrayInputStream(new GsonBuilder().setPrettyPrinting().create().toJson(list).getBytes(StandardCharsets.UTF_8)));
    } catch (IOException e) {
        MainLogger.getLogger().error("Could not save ban list ", e);
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:19,代码来源:BanList.java

示例5: saveResource

import cn.nukkit.utils.Utils; //导入依赖的package包/类
@Override
public boolean saveResource(String filename, String outputName, boolean replace) {
    Preconditions.checkArgument(filename != null && outputName != null, "Filename can not be null!");
    Preconditions.checkArgument(filename.trim().length() != 0 && outputName.trim().length() != 0, "Filename can not be empty!");

    File out = new File(dataFolder, outputName);
    if (!out.exists() || replace) {
        try (InputStream resource = getResource(filename)) {
            if (resource != null) {
                File outFolder = out.getParentFile();
                if (!outFolder.exists()) {
                    outFolder.mkdirs();
                }
                Utils.writeFile(out, resource);

                return true;
            }
        } catch (IOException e) {
            Server.getInstance().getLogger().logException(e);
        }
    }
    return false;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:24,代码来源:PluginBase.java

示例6: saveOfflinePlayerData

import cn.nukkit.utils.Utils; //导入依赖的package包/类
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);
            }
        }
    }
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:17,代码来源:Server.java

示例7: getPluginDescription

import cn.nukkit.utils.Utils; //导入依赖的package包/类
@Override
public PluginDescription getPluginDescription(File file) {
    try {
        JarFile jar = new JarFile(file);
        JarEntry entry = jar.getJarEntry("nukkit.yml");
        if (entry == null) {
            entry = jar.getJarEntry("plugin.yml");
            if (entry == null) {
                return null;
            }
        }
        InputStream stream = jar.getInputStream(entry);
        return new PluginDescription(Utils.readFile(stream));
    } catch (IOException e) {
        return null;
    }
}
 
开发者ID:Creeperface01,项目名称:NukkitGT,代码行数:18,代码来源:JavaPluginLoader.java

示例8: getEventListeners

import cn.nukkit.utils.Utils; //导入依赖的package包/类
private HandlerList getEventListeners(Class<? extends Event> type) throws IllegalAccessException {
    try {
        Method method = getRegistrationClass(type).getDeclaredMethod("getHandlers");
        method.setAccessible(true);
        return (HandlerList) method.invoke(null);
    } catch (Exception e) {
        throw new IllegalAccessException(Utils.getExceptionMessage(e));
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:10,代码来源:PluginManager.java

示例9: reloadConfig

import cn.nukkit.utils.Utils; //导入依赖的package包/类
@Override
public void reloadConfig() {
    this.config = new Config(this.configFile);
    InputStream configStream = this.getResource("config.yml");
    if (configStream != null) {
        DumperOptions dumperOptions = new DumperOptions();
        dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
        Yaml yaml = new Yaml(dumperOptions);
        try {
            this.config.setDefault(yaml.loadAs(Utils.readFile(this.configFile), LinkedHashMap.class));
        } catch (IOException e) {
            Server.getInstance().getLogger().logException(e);
        }
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:16,代码来源:PluginBase.java

示例10: setName

import cn.nukkit.utils.Utils; //导入依赖的package包/类
@Override
public void setName(String name) {
    QueryRegenerateEvent info = this.server.getQueryInformation();
    String[] names = name.split("[email protected]#");  //Split double names within the program
    this.handler.sendOption("name",
            "MCPE;" + Utils.rtrim(names[0].replace(";", "\\;"), '\\') + ";" +
                    ProtocolInfo.CURRENT_PROTOCOL + ";" +
                    ProtocolInfo.MINECRAFT_VERSION_NETWORK + ";" +
                    info.getPlayerCount() + ";" +
                    info.getMaxPlayerCount() + ";" +
                    this.server.getServerUniqueId().toString() + ";" +
                    (names.length > 1 ? Utils.rtrim(names[1].replace(";", "\\;"), '\\') : "") + ";" +
                    Server.getGamemodeString(this.server.getDefaultGamemode(), true) + ";");
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:15,代码来源:RakNetInterface.java

示例11: loadLang

import cn.nukkit.utils.Utils; //导入依赖的package包/类
protected Map<String, String> loadLang(String path) {
    try {
        String content = Utils.readFile(path);
        Map<String, String> d = new HashMap<>();
        for (String line : content.split("\n")) {
            line = line.trim();
            if (line.equals("") || line.charAt(0) == '#') {
                continue;
            }
            String[] t = line.split("=");
            if (t.length < 2) {
                continue;
            }
            String key = t[0];
            String value = "";
            for (int i = 1; i < t.length - 1; i++) {
                value += t[i] + "=";
            }
            value += t[t.length - 1];
            if (value.equals("")) {
                continue;
            }
            d.put(key, value);
        }
        return d;
    } catch (IOException e) {
        Server.getInstance().getLogger().logException(e);
        return null;
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:31,代码来源:BaseLang.java


注:本文中的cn.nukkit.utils.Utils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。