Java Code Examples for org.bukkit.configuration.file.YamlConfiguration#getString()

The following examples show how to use org.bukkit.configuration.file.YamlConfiguration#getString() . 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: HelperProfilesPlugin.java    From helper with MIT License 6 votes vote down vote up
@Override
protected void enable() {
    SqlProvider sqlProvider = getService(SqlProvider.class);
    Sql sql;

    // load sql instance
    YamlConfiguration config = loadConfig("config.yml");
    if (config.getBoolean("use-global-credentials", true)) {
        sql = sqlProvider.getSql();
    } else {
        sql = sqlProvider.getSql(DatabaseCredentials.fromConfig(config));
    }

    // init the table
    String tableName = config.getString("table-name", "helper_profiles");
    int preloadAmount = config.getInt("preload-amount", 2000);

    // provide the ProfileRepository service
    provideService(ProfileRepository.class, bindModule(new HelperProfileRepository(sql, tableName, preloadAmount)));
}
 
Example 2
Source File: CustomGunItem.java    From QualityArmory with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void initIronsights(File dataFolder) {
	File ironsights = new File(dataFolder, "default_ironsightstoggleitem.yml");
	YamlConfiguration ironconfig = YamlConfiguration.loadConfiguration(ironsights);
	if (!ironconfig.contains("displayname")) {
		ironconfig.set("material", Material.CROSSBOW.name());
		ironconfig.set("id", 68);
		ironconfig.set("displayname", IronsightsHandler.ironsightsDisplay);
		try {
			ironconfig.save(ironsights);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	IronsightsHandler.ironsightsMaterial = Material.matchMaterial(ironconfig.getString("material"));
	IronsightsHandler.ironsightsData = ironconfig.getInt("id");
	IronsightsHandler.ironsightsDisplay = ironconfig.getString("displayname");

}
 
Example 3
Source File: CustomGunItem.java    From QualityArmory with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void initIronsights(File dataFolder) {
	File ironsights = new File(dataFolder,"default_ironsightstoggleitem.yml");
	YamlConfiguration ironconfig = YamlConfiguration.loadConfiguration(ironsights);
	if(!ironconfig.contains("displayname")){
		ironconfig.set("material",Material.DIAMOND_AXE.name());
		ironconfig.set("id",21);
		ironconfig.set("displayname",IronsightsHandler.ironsightsDisplay);
		try {
			ironconfig.save(ironsights);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	IronsightsHandler.ironsightsMaterial = Material.matchMaterial(ironconfig.getString("material"));
	IronsightsHandler.ironsightsData = ironconfig.getInt("id");
	IronsightsHandler.ironsightsDisplay = ironconfig.getString("displayname");
}
 
Example 4
Source File: ListenerDamageDeath.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void onDeath(PlayerDeathEvent e) {
    Player player = e.getEntity();
    if(player.hasMetadata("NPC")) return;
    
    NPCManager npcManager = this.expansion.getNPCManager();
    YamlConfiguration data = npcManager.getData(player);
    String deathMessage = data.getString("citizens-compatibility.last-death-message");
    if(deathMessage == null) return;
    
    e.setDeathMessage(null);
    player.sendMessage(deathMessage);
    
    data.set("citizens-compatibility.last-death-message", null);
    npcManager.setData(player, data);
}
 
Example 5
Source File: ExpansionClassLoader.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
private ExpansionDescription createDescription(YamlConfiguration config) throws IllegalStateException {
    String mainClassName = config.getString("main");
    if(mainClassName == null) throw new IllegalStateException("'main' is required in expansion.yml");
    
    String unlocalizedName = config.getString("name");
    if(unlocalizedName == null) throw new IllegalStateException("'name' is required in expansion.yml");
    
    String version = config.getString("version");
    if(version == null) throw new IllegalStateException("'version' is required in expansion.yml");
    
    String displayName = config.getString("display-name", null);
    String description = config.getString("description", null);
    List<String> authorList = config.getStringList("authors");
    
    String author = config.getString("author", null);
    if(author != null) authorList.add(author);
    
    Builder builder = new Builder(mainClassName, unlocalizedName, version)
            .setDescription(description)
            .setDisplayName(displayName)
            .setAuthors(authorList.toArray(new String[0]));
    return new ExpansionDescription(builder);
}
 
Example 6
Source File: VaultManager.java    From PlayerVaults with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Load the player's vault and return it.
 *
 * @param player The holder of the vault.
 * @param number The vault number.
 */
public Inventory loadOwnVault(Player player, int number, int size) {
    if (size % 9 != 0) {
        size = PlayerVaults.getInstance().getDefaultVaultSize();
    }

    PlayerVaults.debug("Loading self vault for " + player.getName() + " (" + player.getUniqueId() + ')');

    String title = Lang.VAULT_TITLE.toString().replace("%number", String.valueOf(number)).replace("%p", player.getName());
    VaultViewInfo info = new VaultViewInfo(player.getUniqueId().toString(), number);
    if (PlayerVaults.getInstance().getOpenInventories().containsKey(info.toString())) {
        PlayerVaults.debug("Already open");
        return PlayerVaults.getInstance().getOpenInventories().get(info.toString());
    }

    YamlConfiguration playerFile = getPlayerVaultFile(player.getUniqueId().toString(), true);
    VaultHolder vaultHolder = new VaultHolder(number);
    if (playerFile.getString(String.format(VAULTKEY, number)) == null) {
        PlayerVaults.debug("No vault matching number");
        Inventory inv = Bukkit.createInventory(vaultHolder, size, title);
        vaultHolder.setInventory(inv);
        return inv;
    } else {
        return getInventory(vaultHolder, player.getUniqueId().toString(), playerFile, size, number, title);
    }
}
 
Example 7
Source File: LanguageManager.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This function has the same effect as getString(String path) if the Player in null.
 *
 * @param path the Path to the Strings location
 * @return "" on failure (empty String)
 * the requested String on success
 */
@NotNull
public static String getString(@NotNull String path, @Nullable Player player) {
	if (player == null) return getString(path);
	if (playerLocale && !player.getLocale().equals(MineTinker.getPlugin().getConfig().getString("Language"))) {
		YamlConfiguration langFile = loadLanguage(player.getLocale());
		if (langFile != null) {
			String ret = langFile.getString(path);
			if (ret != null && !ret.equals("")) {
				return ChatWriter.addColors(ret);
			}
		}
	}
	return getString(path);
}
 
Example 8
Source File: Util.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Parse colors for the YamlConfiguration.
 *
 * @param config yaml config
 */
public static void parseColours(@NotNull YamlConfiguration config) {
    Set<String> keys = config.getKeys(true);
    for (String key : keys) {
        String filtered = config.getString(key);
        if (filtered == null) {
            continue;
        }
        if (filtered.startsWith("MemorySection")) {
            continue;
        }
        filtered = parseColours(filtered);
        config.set(key, filtered);
    }
}
 
Example 9
Source File: VaultManager.java    From PlayerVaults with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get an inventory from file. Returns null if the inventory doesn't exist. SHOULD ONLY BE USED INTERNALLY
 *
 * @param playerFile the YamlConfiguration file.
 * @param size the size of the vault.
 * @param number the vault number.
 * @return inventory if exists, otherwise null.
 */
private Inventory getInventory(InventoryHolder owner, String ownerName, YamlConfiguration playerFile, int size, int number, String title) {
    Inventory inventory = Bukkit.createInventory(owner, size, title);

    String data = playerFile.getString(String.format(VAULTKEY, number));
    Inventory deserialized = Base64Serialization.fromBase64(data, ownerName);
    if (deserialized == null) {
        PlayerVaults.debug("Loaded vault as null");
        return inventory;
    }

    // Check if deserialized has more used slots than the limit here.
    // Happens on change of permission or if people used the broken version.
    // In this case, players will lose items.
    if (deserialized.getContents().length > size) {
        for (ItemStack stack : deserialized.getContents()) {
            if (stack != null) {
                inventory.addItem(stack);
            }
        }
    } else {
        inventory.setContents(deserialized.getContents());
    }

    PlayerVaults.debug("Loaded vault");
    return inventory;
}
 
Example 10
Source File: EconomyOperations.java    From PlayerVaults with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Have a player get his money back when vault is deleted.
 *
 * @param player The player to receive the money.
 * @param number The vault number to delete.
 * @return The transaction success.
 */
public static boolean refundOnDelete(Player player, int number) {
    if (!PlayerVaults.getInstance().isEconomyEnabled() || PlayerVaults.getInstance().getConf().getEconomy().getRefundOnDelete() == 0 || player.hasPermission("playervaults.free")) {
        return true;
    }

    File playerFile = new File(PlayerVaults.getInstance().getVaultData(), player.getUniqueId().toString() + ".yml");
    if (playerFile.exists()) {
        YamlConfiguration playerData = YamlConfiguration.loadConfiguration(playerFile);
        if (playerData.getString("vault" + number) == null) {
            player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.VAULT_DOES_NOT_EXIST);
            return false;
        }
    } else {
        player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.VAULT_DOES_NOT_EXIST);
        return false;
    }

    double cost = PlayerVaults.getInstance().getConf().getEconomy().getRefundOnDelete();
    EconomyResponse resp = PlayerVaults.getInstance().getEconomy().depositPlayer(player, cost);
    if (resp.transactionSuccess()) {
        player.sendMessage(Lang.TITLE.toString() + Lang.REFUND_AMOUNT.toString().replaceAll("%price", String.valueOf(cost)));
        return true;
    }

    return false;
}
 
Example 11
Source File: UUIDVaultManager.java    From PlayerVaults with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get an inventory from file. Returns null if the inventory doesn't exist. SHOULD ONLY BE USED INTERNALLY
 *
 * @param playerFile the YamlConfiguration file.
 * @param size       the size of the vault.
 * @param number     the vault number.
 * @return inventory if exists, otherwise null.
 */
private Inventory getInventory(YamlConfiguration playerFile, int size, int number, String title) {
    List<String> data = new ArrayList<>();
    for (int x = 0; x < size; x++) {
        String line = playerFile.getString("vault" + number + "." + x);
        if (line != null) {
            data.add(line);
        } else {
            data.add("null");
        }
    }
    return Serialization.toInventory(data, number, size, title);
}
 
Example 12
Source File: VaultManager.java    From PlayerVaults with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets an inventory without storing references to it. Used for dropping a players inventories on death.
 *
 * @param holder The holder of the vault.
 * @param number The vault number.
 * @return The inventory of the specified holder and vault number. Can be null.
 */
public Inventory getVault(String holder, int number) {
    YamlConfiguration playerFile = getPlayerVaultFile(holder, true);
    String serialized = playerFile.getString(String.format(VAULTKEY, number));
    return Base64Serialization.fromBase64(serialized, holder);
}