ch.jalu.configme.SettingsManager Java Examples
The following examples show how to use
ch.jalu.configme.SettingsManager.
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: GenerateCommandsYml.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Override public void executeDefault() { File file = new File(COMMANDS_YML_FILE); // Get the default CommandConfig commandConfig = CommandSettingsHolder.COMMANDS.getDefaultValue(); // Export the value to the file SettingsManager settingsManager = SettingsManagerBuilder.withYamlFile(file) .configurationData(CommandSettingsHolder.class) .create(); settingsManager.setProperty(CommandSettingsHolder.COMMANDS, commandConfig); settingsManager.save(); System.out.println("Updated " + COMMANDS_YML_FILE); }
Example #2
Source File: UpdateConfigPageTask.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Override public void executeDefault() { File config = null; try { // Create empty temporary .yml file and save the config to it config = File.createTempFile("authme-config-", ".yml"); SettingsManager settingsManager = SettingsManagerBuilder.withYamlFile(config) .configurationData(AuthMeSettingsRetriever.buildConfigurationData()) .create(); settingsManager.save(); // Get the contents and generate template file TagValueHolder tagValueHolder = TagValueHolder.create() .put("config", FileIoUtils.readFromFile(config.toPath())); FileIoUtils.generateFileFromTemplate(TEMPLATE_FILE, OUTPUT_FILE, tagValueHolder); System.out.println("Wrote to '" + OUTPUT_FILE + "'"); } catch (IOException e) { throw new IllegalStateException(e); } finally { FileUtils.delete(config); } }
Example #3
Source File: CommandManager.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Override public void reload() { File file = new File(dataFolder, "commands.yml"); FileUtils.copyFileFromResource(file, "commands.yml"); SettingsManager settingsManager = SettingsManagerBuilder .withResource(YamlFileResourceProvider.loadFromFile(file)) .configurationData(CommandSettingsHolder.class) .migrationService(commandMigrationService) .create(); CommandConfig commandConfig = settingsManager.getProperty(CommandSettingsHolder.COMMANDS); onJoinCommands = newReplacer(commandConfig.getOnJoin()); onLoginCommands = newOnLoginCmdReplacer(commandConfig.getOnLogin()); onFirstLoginCommands = newOnLoginCmdReplacer(commandConfig.getOnFirstLogin()); onSessionLoginCommands = newReplacer(commandConfig.getOnSessionLogin()); onRegisterCommands = newReplacer(commandConfig.getOnRegister()); onUnregisterCommands = newReplacer(commandConfig.getOnUnregister()); onLogoutCommands = newReplacer(commandConfig.getOnLogout()); }
Example #4
Source File: ChallengeHandler.java From Guilds with MIT License | 6 votes |
/** * Give the rewards to the winner * @param settingsManager the settings manager * @param challenge the challenge */ public void giveRewards(SettingsManager settingsManager, GuildChallenge challenge) { List<UUID> winners; UUID teamWinner = challenge.getWinner().getId(); if (teamWinner == challenge.getChallenger().getId()) { winners = challenge.getChallengePlayers(); } else { winners = challenge.getDefendPlayers(); } List<String> commands = settingsManager.getProperty(WarSettings.WAR_REWARDS); if (settingsManager.getProperty(WarSettings.WAR_REWARDS_ENABLED)) { winners.forEach(p -> { Player player = Bukkit.getPlayer(p); if (player != null) { commands.forEach(c -> { c = c.replace("{player}", player.getName()); Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), c); }); } }); } }
Example #5
Source File: UpdateChecker.java From Guilds with MIT License | 6 votes |
/** * Run the update check for the plugin * @param guilds main plugin class * @param settingsManager settings manager */ public static void runCheck(Guilds guilds, SettingsManager settingsManager) { if (settingsManager.getProperty(PluginSettings.UPDATE_CHECK)) { UpdateChecker.init(guilds, 66176).requestUpdateCheck().whenComplete((result, exception) -> { if (result.requiresUpdate()) { guilds.getLogger().info(String.format("An update is available! Guilds %s may be downloaded on SpigotMC", result.getNewestVersion())); return; } String reason = result.getReason().toString(); switch (reason) { case "UP_TO_DATE": guilds.getLogger().info(String.format("Your version of Guilds (%s) is up to date!", result.getNewestVersion())); break; case "UNRELEASED_VERSION": guilds.getLogger().info(String.format("Your version of Guilds (%s) is more recent than the one publicly available. Are you on a development build?", result.getNewestVersion())); break; default: guilds.getLogger().warning("Could not check for a new version of Guilds. Reason: " + reason); break; } }); } }
Example #6
Source File: Serialization.java From Guilds with MIT License | 6 votes |
/** * Deserialize the inventory from JSON * @param jsons the JSON string * @param title the name of the inventory * @return the deserialized string * @throws InvalidConfigurationException */ public static Inventory deserializeInventory(String jsons, String title, SettingsManager settingsManager) throws InvalidConfigurationException { try { JsonConfiguration json = new JsonConfiguration(); json.loadFromString(jsons); int size = json.getInt("size", 54); title = StringUtils.color(settingsManager.getProperty(GuildVaultSettings.VAULT_NAME)); Inventory inventory = Bukkit.createInventory(null, size, title); Map<String, Object> items = json.getConfigurationSection("items").getValues(false); for (Map.Entry<String, Object> item : items.entrySet()) { ItemStack itemstack = (ItemStack) item.getValue(); int idx = Integer.parseInt(item.getKey()); inventory.setItem(idx, itemstack); } return inventory; } catch (InvalidConfigurationException e) { return null; } }
Example #7
Source File: GuildHandler.java From Guilds with MIT License | 5 votes |
/** * Check in a input name for the guild is proper * @param name the name input * @param settingsManager setting manager * @return valid or not */ public boolean nameCheck(String name, SettingsManager settingsManager) { String regex = settingsManager.getProperty(GuildSettings.NAME_REQUIREMENTS); if (!settingsManager.getProperty(GuildSettings.INCLUDE_COLOR_CODES)) { String tmp = StringUtils.color(name); return ChatColor.stripColor(tmp).matches(regex); } return name.matches(regex); }
Example #8
Source File: ChallengeHandler.java From Guilds with MIT License | 5 votes |
/** * Handle finishing of the arena war * @param guilds guilds instance * @param settingsManager the settings manager * @param player player to remove * @param challenge the challenge being checked */ public void handleFinish(Guilds guilds, SettingsManager settingsManager, Player player, GuildChallenge challenge) { removePlayer(player); if (checkIfOver(challenge)) { // Specify the war is over challenge.setStarted(false); challenge.setCompleted(true); // Open up the arena challenge.getArena().setInUse(false); // Broadcast the winner announceWinner(challenge, guilds.getCommandManager()); // Move rest of players out of arena teleportRemaining(challenge); // Run the reward commands giveRewards(settingsManager, challenge); // Execute post war commands if (settingsManager.getProperty(WarSettings.ENABLE_POST_CHALLENGE_COMMANDS)) { settingsManager.getProperty(WarSettings.POST_CHALLENGE_COMMANDS).forEach(c -> { c = c.replace("{challenger}", challenge.getChallenger().getName()); c = c.replace("{defender}", challenge.getDefender().getName()); c = c.replace("{winner}", challenge.getWinner().getName()); c = c.replace("{loser}", challenge.getLoser().getName()); Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), c); }); } try { // Save the details about the challenge saveData(); } catch (IOException e) { e.printStackTrace(); } } }
Example #9
Source File: ChallengeHandler.java From Guilds with MIT License | 5 votes |
/** * Check to see if a Guild can be challenged * @param guild the guild to check * @param settingsManager the settings manager * @return if they can be challenge or not */ public boolean notOnCooldown(Guild guild, SettingsManager settingsManager) { long cooldownTime = TimeUnit.MINUTES.toMillis(settingsManager.getProperty(WarSettings.DEFEND_COOLDOWN)); long lastDefended = guild.getLastDefended(); long currentTime = System.currentTimeMillis(); if (lastDefended == 0) { return true; } return (currentTime - lastDefended > cooldownTime); }
Example #10
Source File: DatabaseAdapter.java From Guilds with MIT License | 5 votes |
public DatabaseAdapter(Guilds guilds, SettingsManager settings, boolean doConnect) throws IOException { String backendName = settings.getProperty(StorageSettings.STORAGE_TYPE).toLowerCase(); DatabaseBackend backend = DatabaseBackend.getByBackendName(backendName); if (backend == null) { backend = DatabaseBackend.JSON; } this.guilds = guilds; this.settings = settings; if (doConnect) { setUpBackend(backend); } }
Example #11
Source File: Guild.java From Guilds with MIT License | 5 votes |
public void updateGuildSkull(Player player, SettingsManager settingsManager) { Guilds.newChain().async(() -> { try{ guildSkull = new GuildSkull(player); } catch (Exception ex) { guildSkull = new GuildSkull(settingsManager.getProperty(GuildListSettings.GUILD_LIST_HEAD_DEFAULT_URL)); } }).execute(); }
Example #12
Source File: GuildHandler.java From Guilds with MIT License | 5 votes |
/** * Check the guild ticket itemstack * @param settingsManager settings manager * @return the itemstack */ public ItemStack matchTicket(SettingsManager settingsManager) { ItemBuilder builder = new ItemBuilder(Material.valueOf(settingsManager.getProperty(TicketSettings.TICKET_MATERIAL))); builder.setAmount(1); builder.setName(StringUtils.color(settingsManager.getProperty(TicketSettings.TICKET_NAME))); builder.setLore(settingsManager.getProperty(TicketSettings.TICKET_LORE).stream().map(StringUtils::color).collect(Collectors.toList())); return builder.build(); }
Example #13
Source File: GuildHandler.java From Guilds with MIT License | 5 votes |
/** * Create a guild upgrade ticket * @param settingsManager the settings manager * @param amount the amount of tickets to give * @return the guild upgrade ticket */ public ItemStack getUpgradeTicket(SettingsManager settingsManager, int amount) { ItemBuilder builder = new ItemBuilder(Material.valueOf(settingsManager.getProperty(TicketSettings.TICKET_MATERIAL))); builder.setAmount(amount); builder.setName(StringUtils.color(settingsManager.getProperty(TicketSettings.TICKET_NAME))); builder.setLore(settingsManager.getProperty(TicketSettings.TICKET_LORE).stream().map(StringUtils::color).collect(Collectors.toList())); return builder.build(); }
Example #14
Source File: GuildHandler.java From Guilds with MIT License | 5 votes |
/** * Check if a word is in the blacklist or not * @param name name to check * @param settingsManager settings manager * @return blacklisted or not */ public boolean blacklistCheck(String name, SettingsManager settingsManager) { if (settingsManager.getProperty(GuildSettings.BLACKLIST_SENSITIVE)) return settingsManager.getProperty(GuildSettings.BLACKLIST_WORDS).stream().anyMatch(s -> s.toLowerCase().contains(name)); else return settingsManager.getProperty(GuildSettings.BLACKLIST_WORDS).stream().anyMatch(s -> s.equalsIgnoreCase(name)); }
Example #15
Source File: GuildHandler.java From Guilds with MIT License | 5 votes |
/** * Simple method to check in a prefix is valid or not * @param name the prefix * @param settingsManager setting manager * @return valid or not */ public boolean prefixCheck(String name, SettingsManager settingsManager) { String regex = settingsManager.getProperty(GuildSettings.PREFIX_REQUIREMENTS); if (!settingsManager.getProperty(GuildSettings.INCLUDE_COLOR_CODES)) { String tmp = StringUtils.color(name); return ChatColor.stripColor(tmp).matches(regex); } return name.matches(regex); }
Example #16
Source File: GuildHandler.java From Guilds with MIT License | 5 votes |
public GuildHandler(Guilds guildsPlugin, SettingsManager settingsManager) { this.guildsPlugin = guildsPlugin; this.settingsManager = settingsManager; loadRoles(); loadTiers(); try { loadGuilds(); } catch (IOException e) { e.printStackTrace(); } }
Example #17
Source File: Serialization.java From Guilds with MIT License | 4 votes |
public static Inventory deserializeInventory(String jsons, SettingsManager settingsManager) throws InvalidConfigurationException { return deserializeInventory(jsons, null, settingsManager); }
Example #18
Source File: DatabaseAdapter.java From Guilds with MIT License | 4 votes |
public DatabaseAdapter(Guilds guilds, SettingsManager settings) throws IOException { this(guilds, settings, true); }
Example #19
Source File: SettingsHandler.java From Guilds with MIT License | 4 votes |
public SettingsManager getMainConf() { return this.mainConf; }
Example #20
Source File: SettingsHandler.java From Guilds with MIT License | 4 votes |
public SettingsManager getTierConf() { return tierConf; }
Example #21
Source File: SettingsHandler.java From Guilds with MIT License | 4 votes |
public SettingsManager getRoleConf() { return roleConf; }
Example #22
Source File: SettingsHandler.java From Guilds with MIT License | 4 votes |
public SettingsManager getBuffConf() { return buffConf; }
Example #23
Source File: EntityListener.java From Guilds with MIT License | 4 votes |
public EntityListener(GuildHandler guildHandler, SettingsManager settingsManager, ChallengeHandler challengeHandler) { this.guildHandler = guildHandler; this.settingsManager = settingsManager; this.challengeHandler = challengeHandler; }
Example #24
Source File: ClaimSignListener.java From Guilds with MIT License | 4 votes |
public ClaimSignListener(Guilds guilds, SettingsManager settingsManager, GuildHandler guildHandler) { this.guilds = guilds; this.settingsManager = settingsManager; this.guildHandler = guildHandler; }
Example #25
Source File: VaultBlacklistListener.java From Guilds with MIT License | 4 votes |
public VaultBlacklistListener(Guilds guilds, GuildHandler guildHandler, SettingsManager settingsManager) { this.guilds = guilds; this.guildHandler = guildHandler; this.settingsManager = settingsManager; }
Example #26
Source File: GuildHandler.java From Guilds with MIT License | 2 votes |
/** * Method to create new vault * @param settingsManager settings manager * @return new vault */ public Inventory createNewVault(SettingsManager settingsManager) { return Bukkit.createInventory(null, 54, StringUtils.color(settingsManager.getProperty(GuildVaultSettings.VAULT_NAME))); }