Java Code Examples for org.bukkit.plugin.Plugin#getDataFolder()

The following examples show how to use org.bukkit.plugin.Plugin#getDataFolder() . 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: HologramDatabase.java    From HolographicDisplays with GNU General Public License v3.0 6 votes vote down vote up
public static void loadYamlFile(Plugin plugin) {
	file = new File(plugin.getDataFolder(), "database.yml");
	
	if (!file.exists()) {
		plugin.getDataFolder().mkdirs();
		plugin.saveResource("database.yml", true);
	}
	
	config = YamlConfiguration.loadConfiguration(file);
}
 
Example 2
Source File: Converter.java    From NametagEdit with GNU General Public License v3.0 6 votes vote down vote up
private List<String> getLines(CommandSender commandSender, Plugin plugin, String oldFileName) throws IOException {
    File oldFile = new File(plugin.getDataFolder(), oldFileName);
    if (!oldFile.exists()) {
        NametagMessages.FILE_DOESNT_EXIST.send(commandSender, oldFileName);
        return new ArrayList<>();
    }

    return getLines(oldFile);
}
 
Example 3
Source File: Messaging.java    From SkyWarsReloaded with GNU General Public License v3.0 6 votes vote down vote up
public Messaging(Plugin plugin) {
    File storageFile = new File(plugin.getDataFolder(), "messages.yml");

    if (!storageFile.exists()) {
        plugin.saveResource("messages.yml", false);
    }

    copyDefaults(storageFile);
    storage = YamlConfiguration.loadConfiguration(storageFile);
}
 
Example 4
Source File: Messaging.java    From SkyWarsReloaded with GNU General Public License v3.0 6 votes vote down vote up
public Messaging(Plugin plugin) {
    File storageFile = new File(plugin.getDataFolder(), "messages.yml");

    if (!storageFile.exists()) {
        plugin.saveResource("messages.yml", false);
    }

    copyDefaults(storageFile);
    storage = YamlConfiguration.loadConfiguration(storageFile);
}
 
Example 5
Source File: PluginHookService.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
/**
 * If CMI is hooked into, return CMI' data folder.
 *
 * @return The CMI data folder, or null if unavailable
 */
public File getCmiDataFolder() {
    Plugin plugin = pluginManager.getPlugin("CMI");
    if (plugin == null) {
        return null;
    }
    return plugin.getDataFolder();
}
 
Example 6
Source File: EffectManager.java    From EffectLib with MIT License 5 votes vote down vote up
public EffectManager(Plugin owningPlugin) {
    imageCacheFolder = owningPlugin == null ? null : new File(owningPlugin.getDataFolder(), "imagecache");
    this.owningPlugin = owningPlugin;
    Transforms.setEffectManager(this);
    effects = new HashMap<Effect, BukkitTask>();
    disposed = false;
    disposeOnTermination = false;
}
 
Example 7
Source File: ClipsPlaceholderHook.java    From MarriageMaster with GNU General Public License v3.0 5 votes vote down vote up
private void removeECouldFile()
{
	Plugin papi = plugin.getServer().getPluginManager().getPlugin("PlaceholderAPI");
	if(papi != null)
	{
		File eCloudFolder = new File(papi.getDataFolder(), "expansions");
		if(eCloudFolder.exists())
		{
			File[] marriageMasterFiles = { new File(eCloudFolder,  "Expansion-MarriageMaster.jar"), new File(eCloudFolder,  "Expansion-MarriageMaster_3WNs7dj.jar") };
			for(File file : marriageMasterFiles)
			{
				if(file.exists())
				{
					if(file.delete())
					{
						plugin.getLogger().info("Marriage Master PAPI eCloud extension deleted! It is not needed and not compatible with Marriage Master v2.0 and newer.");
					}
					else
					{
						plugin.getLogger().warning("Failed to delete Marriage Master PAPI eCloud extension! Please remove it!\nIt is not needed and not compatible with Marriage Master v2.0 and newer.");
					}
				}
			}
		}
	}

}
 
Example 8
Source File: NBTData.java    From Item-NBT-API with MIT License 5 votes vote down vote up
public static NBTFile getPluginData(Plugin plugin) {
	try {
		plugin.getDataFolder().mkdirs();
		return new NBTFile(new File(plugin.getDataFolder(), "settings.dat"));
	} catch (IOException e) {
		throw new NbtApiException("Error getting Plugin data!", e);
	}
}
 
Example 9
Source File: NBTData.java    From Item-NBT-API with MIT License 5 votes vote down vote up
public static NBTFile getPluginPlayerData(Plugin plugin, UUID uuid) {
	try {
		File dataFolder = new File(plugin.getDataFolder(), "nbt-playerdata");
		dataFolder.mkdirs();
		return new NBTFile(new File(dataFolder, uuid.toString() + ".dat"));
	} catch (IOException e) {
		throw new NbtApiException("Error getting Player Plugin data!", e);
	}
}
 
Example 10
Source File: ConfigAccessor.java    From ResourcepacksPlugins with GNU General Public License v3.0 5 votes vote down vote up
public ConfigAccessor(Plugin plugin, String fileName) {
    if (plugin == null)
        throw new IllegalArgumentException("plugin cannot be null");
    this.plugin = plugin;
    this.fileName = fileName;
    File dataFolder = plugin.getDataFolder();
    if (dataFolder == null)
        throw new IllegalStateException();
    this.configFile = new File(plugin.getDataFolder(), fileName);
    this.defaults = getDefaults();
}
 
Example 11
Source File: Converter.java    From NametagEdit with GNU General Public License v3.0 5 votes vote down vote up
private void handleFile(Plugin plugin, CommandSender sender, String fileType) throws IOException {
    final boolean GROUP = fileType.equals("groups");
    File nametagConfigFile = new File(plugin.getDataFolder(), fileType + ".yml");
    YamlConfiguration nametagConfig = Utils.getConfig(nametagConfigFile);
    for (String line : getLines(sender, plugin, fileType + ".txt")) {
        if (!line.contains("=")) continue; // If the special token is missing, skip. Malformed line.
        if (GROUP) {
            handleGroup(nametagConfig, line);
        } else {
            handlePlayer(nametagConfig, line);
        }
    }

    nametagConfig.save(nametagConfigFile);
}
 
Example 12
Source File: Files.java    From TabooLib with MIT License 5 votes vote down vote up
public static void releaseResource(Plugin plugin, String path, boolean replace) {
    File file = new File(plugin.getDataFolder(), path);
    if (!file.exists() || replace) {
        try (InputStream inputStream = getCanonicalResource(plugin, (plugin instanceof InternalPlugin ? "__resources__/" : "") + path)) {
            if (inputStream != null) {
                toFile(inputStream, file(file));
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
}
 
Example 13
Source File: TConfig.java    From TabooLib with MIT License 5 votes vote down vote up
public static TConfig create(Plugin plugin, String path) {
    File file = new File(plugin.getDataFolder(), path);
    if (!file.exists()) {
        Files.releaseResource(plugin, path, false);
    }
    TConfig conf = create(file, plugin);
    conf.path = path;
    return conf;
}
 
Example 14
Source File: SettingsManager.java    From Survival-Games with GNU General Public License v3.0 4 votes vote down vote up
public void setup(Plugin p) {
	SettingsManager.p = p;
	if (p.getConfig().getInt("config-version") == SurvivalGames.config_version) {
		SurvivalGames.config_todate = true;
	}else{
		File config = new File(p.getDataFolder(), "config.yml");
		config.delete();
	}
	
	p.getConfig().options().copyDefaults(true);
	p.saveDefaultConfig();
	
	f = new File(p.getDataFolder(), "spawns.yml");
	f2 = new File(p.getDataFolder(), "system.yml");
	f3 = new File(p.getDataFolder(), "kits.yml");
	f4 = new File(p.getDataFolder(), "messages.yml");
	f5 = new File(p.getDataFolder(), "chest.yml");

	try {
		if (!f.exists()) 	f.createNewFile();
		if (!f2.exists())	f2.createNewFile();
		if (!f3.exists()) 	loadFile("kits.yml");
		if (!f4.exists()) 	loadFile("messages.yml");
		if (!f5.exists()) 	loadFile("chest.yml");

	} 
	catch (Exception e) {
		e.printStackTrace();
	}
	
	reloadSystem();
	saveSystemConfig();
	
	reloadSpawns();
	saveSpawns();
	
	reloadKits();
	//saveKits();
	
	reloadChest();
	
	reloadMessages();
	saveMessages();
	
	
}
 
Example 15
Source File: BukkitPluginManifest.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@Provides @Named("pluginData")
File pluginDataFile(Plugin plugin) {
    return plugin.getDataFolder();
}
 
Example 16
Source File: PluginConfig.java    From ChestCommands with GNU General Public License v3.0 4 votes vote down vote up
public PluginConfig(Plugin plugin, String name) {
	this(plugin, new File(plugin.getDataFolder(), name));
}
 
Example 17
Source File: Files.java    From TabooLib with MIT License 4 votes vote down vote up
public static File releaseResource(Plugin plugin, String path) {
    releaseResource(plugin, path, false);
    return new File(plugin.getDataFolder(), path);
}
 
Example 18
Source File: LanguageFileUtil.java    From AntiVPN with MIT License 4 votes vote down vote up
public static Optional<File> getLanguage(Plugin plugin, Locale locale, boolean ignoreCountry) throws IOException {
    // Build resource path & file path for language
    // Use country is specified (and lang provides country)
    String resourcePath = ignoreCountry || locale.getCountry() == null || locale.getCountry().isEmpty() ? "lang_" + locale.getLanguage() + ".yml" : "lang_" + locale.getLanguage() + "_" + locale.getCountry() + ".yml";
    File langDir = new File(plugin.getDataFolder(), "lang");
    File fileOnDisk = new File(langDir, resourcePath);

    // Clean up/build language path on disk
    if (langDir.exists() && !langDir.isDirectory()) {
        Files.delete(langDir.toPath());
    }
    if (!langDir.exists()) {
        if (!langDir.mkdirs()) {
            throw new IOException("Could not create parent directory structure.");
        }
    }
    if (fileOnDisk.exists() && fileOnDisk.isDirectory()) {
        Files.delete(fileOnDisk.toPath());
    }

    // Check language version
    if (fileOnDisk.exists()) {
        try (InputStream inStream = plugin.getResource(resourcePath)) {
            if (inStream != null) {
                ConfigurationLoader<ConfigurationNode> fileLoader = YAMLConfigurationLoader.builder().setFlowStyle(DumperOptions.FlowStyle.BLOCK).setIndent(2).setFile(fileOnDisk).build();
                ConfigurationNode fileRoot = fileLoader.load();
                double fileVersion = fileRoot.getNode("acf-minecraft", "version").getDouble(1.0d);

                try (InputStreamReader reader = new InputStreamReader(inStream);
                     BufferedReader in = new BufferedReader(reader)) {
                    ConfigurationLoader<ConfigurationNode> streamLoader = YAMLConfigurationLoader.builder().setFlowStyle(DumperOptions.FlowStyle.BLOCK).setIndent(2).setSource(() -> in).build();
                    ConfigurationNode streamRoot = streamLoader.load();
                    double streamVersion = streamRoot.getNode("acf-minecraft", "version").getDouble(1.0d);

                    if (streamVersion > fileVersion) {
                        // Version update, backup & delete file on disk
                        File backupFile = new File(fileOnDisk.getParent(), fileOnDisk.getName() + ".bak");
                        if (backupFile.exists()) {
                            Files.delete(backupFile.toPath());
                        }

                        com.google.common.io.Files.copy(fileOnDisk, backupFile);
                        Files.delete(fileOnDisk.toPath());
                    }
                }
            }
        }
    }

    // Write language file to disk if not exists
    if (!fileOnDisk.exists()) {
        try (InputStream inStream = plugin.getResource(resourcePath)) {
            if (inStream != null) {
                try (InputStreamReader reader = new InputStreamReader(inStream);
                     BufferedReader in = new BufferedReader(reader);
                     FileWriter writer = new FileWriter(fileOnDisk);
                     BufferedWriter out = new BufferedWriter(writer)) {
                    String line;
                    while ((line = in.readLine()) != null) {
                        out.write(line + System.lineSeparator());
                    }
                }
            }
        }
    }

    if (fileOnDisk.exists()) {
        // Return file on disk
        return Optional.of(fileOnDisk);
    } else {
        // If we need a more generic language (eg. if we have "en_US" and we don't have "en_US.yml" but we do have "en.yml") then return the more generic language file
        // Otherwise, no language found
        return ignoreCountry ? Optional.empty() : getLanguage(plugin, locale, true);
    }
}