public static boolean isOfflineVersion() { return inst.getResource("libs") != null; }
public boolean copyResource(Plugin plugin, String ressource, File destination) { try { InputStream template = plugin.getResource(ressource); OutputStream out = new FileOutputStream(destination); byte[] buf = new byte[1024]; int len; while ((len = template.read(buf)) > 0) { out.write(buf, 0, len); } template.close(); out.close(); return true; } catch (IOException e) { e.printStackTrace(); return false; } }
public static YamlConfiguration getConfig(File file, String resource, Plugin plugin) { try { if (!file.exists()) { file.createNewFile(); InputStream inputStream = plugin.getResource(resource); OutputStream outputStream = new FileOutputStream(file); byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } inputStream.close(); outputStream.flush(); outputStream.close(); } } catch (IOException e) { e.printStackTrace(); } return YamlConfiguration.loadConfiguration(file); }
private static void releaseLocales(Plugin plugin) { getLocalePriority().stream().filter(localeName -> !new File(plugin.getDataFolder(), "lang/" + localeName + ".yml").exists() && plugin.getResource("lang/" + localeName + ".yml") != null).forEach(localeName -> plugin.saveResource("lang/" + localeName + ".yml", true)); }
public void load() throws IOException, InvalidConfigurationException { if (!file.isFile()) { if (plugin.getResource(file.getName()) != null) { plugin.saveResource(file.getName(), false); } else { if (file.getParentFile() != null) { file.getParentFile().mkdirs(); } file.createNewFile(); } } // To reset all the values when loading for (String section : this.getKeys(false)) { set(section, null); } load(file); }
private static void process(Plugin plugin, String resource, ConfigurationSection section, boolean addOnlyIfEmpty, boolean removeObsolete) { YamlConfiguration defaults = resourceCache.computeIfAbsent(resource, res -> { InputStream is = plugin.getResource("res/" + res); if (is == null) { throw new IllegalStateException("Couldn't read " + res + " from jar, please re-install MobArena"); } Scanner scanner = new Scanner(is).useDelimiter("\\A"); if (!scanner.hasNext()) { throw new IllegalStateException("No content in " + res + " in jar, please re-install MobArena"); } String contents = scanner.next(); YamlConfiguration yaml = new YamlConfiguration(); try { yaml.loadFromString(contents); return yaml; } catch (InvalidConfigurationException e) { throw new IllegalStateException("Invalid contents in " + res + " in jar, please re-install MobArena", e); } }); boolean modified = process(defaults, section, addOnlyIfEmpty, removeObsolete); if (modified) { plugin.saveConfig(); } }
File file = getPluginJarFile(plugin); if (pluginJarFile.equals(file)) { InputStream stream = plugin.getResource(resourcePath); if (stream == null) { throw new IOException("Resource not found: " + resourcePath);
public void reload(String languageName) { createFolder(plugin); languageName = formatName(languageName); languageFile = new File(languageFolder, languageName); if (!languageFile.exists()) { if (plugin.getResource("Language2/" + languageName) == null) { TLocale.Logger.error("LANGUAGE2.FAIL-NOTFOUND-FILE", languageName); } else { plugin.saveResource("Language2/" + languageName, true); } } configuration = ConfigUtils.load(plugin, languageFile); }
private void addVersionConfigs(ConfigurationSection config, String fileName) throws InvalidConfigurationException, IOException { int firstVersion = CompatibilityUtils.isCurrentVersion() ? firstCurrentMinorVersion : firstSupportedMinorVersion; int[] serverVersion = CompatibilityUtils.getServerVersion(); int majorVersion = serverVersion[0]; for (int minorVersion = firstVersion; minorVersion <= serverVersion[1]; minorVersion++) { String versionExample = majorVersion + "." + minorVersion; String versionFileName = "examples/" + versionExample + "/" + fileName + ".yml"; InputStream versionInput = plugin.getResource(versionFileName); if (versionInput != null) { ConfigurationSection versionConfig = CompatibilityUtils.loadConfiguration(versionInput); // Version patches will never add to configs, the top-level nodes they are modifying must exist. // This allows them to tweak things from example configs but get safely ignored if not loading // those examples. ConfigurationUtils.addConfigurations(config, versionConfig, true, true); getLogger().info(" Using compatibility configs: " + versionFileName); } } }
InputStream input = plugin.getResource(examplesFileName); if (input != null)
YamlConfiguration config = CompatibilityUtils.loadConfiguration(plugin.getResource(defaultsFileName)); info(" Based on defaults " + defaultsFileName); InputStream input = plugin.getResource(examplesFileName); if (input != null) { ConfigurationSection exampleConfig = CompatibilityUtils.loadConfiguration(input); for (String example : addExamples) { examplesFileName = "examples/" + example + "/" + fileName + ".yml"; InputStream input = plugin.getResource(examplesFileName); if (input != null)
YamlConfiguration defaultConfig = CompatibilityUtils.loadConfiguration(plugin.getResource(defaultsFileName)); String header = defaultConfig.options().header(); for (String inheritFrom : inherits) { String inheritFileName = "examples/" + inheritFrom + "/" + fileName + ".yml"; InputStream input = plugin.getResource(inheritFileName); if (input != null) { List<String> disable = ConfigurationUtils.getStringList(mainConfiguration, "disable_inherited"); InputStream input = plugin.getResource(examplesFileName); if (input != null) { ConfigurationSection exampleConfig = CompatibilityUtils.loadConfiguration(input); for (String example : addExamples) { examplesFileName = "examples/" + example + "/" + fileName + ".yml"; InputStream input = plugin.getResource(examplesFileName); if (input != null)
public boolean addMarker(String id, String group, String title, String world, int x, int y, int z, String description) { boolean created = false; if (dynmap != null && dynmap.markerAPIInitialized()) { MarkerAPI markers = dynmap.getMarkerAPI(); MarkerSet markerSet = markers.getMarkerSet(group); if (markerSet == null) { markerSet = markers.createMarkerSet(group, group, null, false); } MarkerIcon wandIcon = markers.getMarkerIcon("wand"); if (wandIcon == null) { wandIcon = markers.createMarkerIcon("wand", "Wand", plugin.getResource("wand_icon32.png")); } Marker marker = markerSet.findMarker(id); if (marker == null) { created = true; marker = markerSet.createMarker(id, title, world, x, y, z, wandIcon, false); } else { marker.setLocation(world, x, y, z); marker.setLabel(title); } if (description != null) { marker.setDescription(description); } } return created; }