Search in sources :

Example 1 with FileConfiguration

use of org.bukkit.configuration.file.FileConfiguration in project Prism-Bukkit by prism.

the class RadiusParameter method process.

/**
	 * 
	 */
@Override
public void process(QueryParameters query, String alias, String input, CommandSender sender) {
    Player player = null;
    if (sender instanceof Player) {
        player = (Player) sender;
    }
    String inputValue = input;
    final FileConfiguration config = Bukkit.getPluginManager().getPlugin("Prism").getConfig();
    if (TypeUtils.isNumeric(inputValue) || (inputValue.contains(":") && inputValue.split(":").length >= 1 && TypeUtils.isNumeric(inputValue.split(":")[1]))) {
        int radius, desiredRadius;
        Location coordsLoc = null;
        if (inputValue.contains(":")) {
            desiredRadius = Integer.parseInt(inputValue.split(":")[1]);
            final String radiusLocOrPlayer = inputValue.split(":")[0];
            if (radiusLocOrPlayer.contains(",") && player != null) {
                // Coordinates;
                // x,y,z
                final String[] coordinates = radiusLocOrPlayer.split(",");
                if (coordinates.length != 3) {
                    throw new IllegalArgumentException("Couldn't parse the coordinates '" + radiusLocOrPlayer + "'. Perhaps you have more than two commas?");
                }
                for (final String s : coordinates) {
                    if (!TypeUtils.isNumeric(s)) {
                        throw new IllegalArgumentException("The coordinate '" + s + "' is not a number.");
                    }
                }
                coordsLoc = (new Location(player.getWorld(), Integer.parseInt(coordinates[0]), Integer.parseInt(coordinates[1]), Integer.parseInt(coordinates[2])));
            } else // Try to find an online player
            if (Bukkit.getServer().getPlayer(radiusLocOrPlayer) != null) {
                player = Bukkit.getServer().getPlayer(radiusLocOrPlayer);
            } else {
                throw new IllegalArgumentException("Couldn't find the player named '" + radiusLocOrPlayer + "'. Perhaps they are not online or you misspelled their name?");
            }
        } else {
            desiredRadius = Integer.parseInt(inputValue);
        }
        if (desiredRadius <= 0) {
            throw new IllegalArgumentException("Radius must be greater than zero. Or leave it off to use the default. Use /prism ? for help.");
        }
        // If neither sender or a named player found, die here
        if (player == null) {
            throw new IllegalArgumentException("The radius parameter must be used by a player. Use w:worldname if attempting to limit to a world.");
        }
        // Clamp radius based on perms, configs
        radius = MiscUtils.clampRadius(player, desiredRadius, query.getProcessType(), config);
        if (desiredRadius != radius) {
            if (sender != null)
                sender.sendMessage(Prism.messenger.playerError("Forcing radius to " + radius + " as allowed by config."));
        }
        if (radius > 0) {
            query.setRadius(radius);
            if (coordsLoc != null) {
                // We
                query.setMinMaxVectorsFromPlayerLocation(coordsLoc);
            // need
            // to
            // set
            // this
            // *after*
            // the
            // radius
            // has
            // been
            // set
            // or
            // it
            // won't
            // work.
            } else {
                query.setMinMaxVectorsFromPlayerLocation(player.getLocation());
            }
        }
    } else {
        // If neither sender or a named player found, die here
        if (player == null) {
            throw new IllegalArgumentException("The radius parameter must be used by a player. Use w:worldname if attempting to limit to a world.");
        }
        // User wants an area inside of a worldedit selection
        if (inputValue.equals("we")) {
            if (Prism.plugin_worldEdit == null) {
                throw new IllegalArgumentException("This feature is disabled because Prism couldn't find WorldEdit.");
            } else {
                // Load a selection from world edit as our area.
                final Prism prism = (Prism) Bukkit.getPluginManager().getPlugin("Prism");
                if (!WorldEditBridge.getSelectedArea(prism, player, query)) {
                    throw new IllegalArgumentException("Invalid region selected. Make sure you have a region selected, and that it doesn't exceed the max radius.");
                }
            }
        } else // Confine to the chunk
        if (inputValue.equals("c") || inputValue.equals("chunk")) {
            final Chunk ch = player.getLocation().getChunk();
            query.setWorld(ch.getWorld().getName());
            query.setMinLocation(ChunkUtils.getChunkMinVector(ch));
            query.setMaxLocation(ChunkUtils.getChunkMaxVector(ch));
        } else // User wants no radius, but contained within the current world
        if (inputValue.equals("world")) {
            // Do they have permission to override the global lookup radius
            if (query.getProcessType().equals(PrismProcessType.LOOKUP) && !player.hasPermission("prism.override-max-lookup-radius")) {
                throw new IllegalArgumentException("You do not have permission to override the max radius.");
            }
            // Do they have permission to override the global applier radius
            if (!query.getProcessType().equals(PrismProcessType.LOOKUP) && !player.hasPermission("prism.override-max-applier-radius")) {
                throw new IllegalArgumentException("You do not have permission to override the max radius.");
            }
            // Use the world defined in the w: param
            if (query.getWorld() != null) {
                inputValue = query.getWorld();
            } else // Use the current world
            {
                inputValue = player.getWorld().getName();
            }
            query.setWorld(inputValue);
            query.setAllowNoRadius(true);
        } else // User has asked for a global radius
        if (inputValue.equals("global")) {
            // Do they have permission to override the global lookup radius
            if (query.getProcessType().equals(PrismProcessType.LOOKUP) && !player.hasPermission("prism.override-max-lookup-radius")) {
                throw new IllegalArgumentException("You do not have permission to override the max radius.");
            }
            // Do they have permission to override the global applier radius
            if (!query.getProcessType().equals(PrismProcessType.LOOKUP) && !player.hasPermission("prism.override-max-applier-radius")) {
                throw new IllegalArgumentException("You do not have permission to override the max radius.");
            }
            // Either they have permission or player is null
            query.setWorld(null);
            query.setAllowNoRadius(true);
        } else {
            throw new IllegalArgumentException("Radius is invalid. There's a bunch of choice, so use /prism actions for assistance.");
        }
    }
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) Player(org.bukkit.entity.Player) Chunk(org.bukkit.Chunk) Prism(me.botsko.prism.Prism) Location(org.bukkit.Location)

Example 2 with FileConfiguration

use of org.bukkit.configuration.file.FileConfiguration in project AuthMeReloaded by AuthMe.

the class RoyalAuthConverter method execute.

@Override
public void execute(CommandSender sender) {
    for (OfflinePlayer player : plugin.getServer().getOfflinePlayers()) {
        try {
            String name = player.getName().toLowerCase();
            File file = new File(makePath(".", "plugins", "RoyalAuth", "userdata", name + ".yml"));
            if (dataSource.isAuthAvailable(name) || !file.exists()) {
                continue;
            }
            FileConfiguration configuration = YamlConfiguration.loadConfiguration(file);
            PlayerAuth auth = PlayerAuth.builder().name(name).password(configuration.getString(PASSWORD_PATH), null).lastLogin(configuration.getLong(LAST_LOGIN_PATH)).realName(player.getName()).build();
            dataSource.saveAuth(auth);
        } catch (Exception e) {
            ConsoleLogger.logException("Error while trying to import " + player.getName() + " RoyalAuth data", e);
        }
    }
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) OfflinePlayer(org.bukkit.OfflinePlayer) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) File(java.io.File)

Example 3 with FileConfiguration

use of org.bukkit.configuration.file.FileConfiguration in project AuthMeReloaded by AuthMe.

the class MessageFilePlaceholderTest method shouldHaveAllPlaceholders.

@Test
public void shouldHaveAllPlaceholders() {
    // given
    FileConfiguration configuration = YamlConfiguration.loadConfiguration(messagesFile);
    List<String> errors = new ArrayList<>();
    // when
    for (MessageKey key : MessageKey.values()) {
        List<String> missingTags = findMissingTags(key, configuration);
        if (!missingTags.isEmpty()) {
            errors.add("Message key '" + key + "' should have tags: " + String.join(", ", missingTags));
        }
    }
    // then
    if (!errors.isEmpty()) {
        fail("Errors while validating '" + messagesFilename + "':\n- " + String.join("\n- ", errors));
    }
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with FileConfiguration

use of org.bukkit.configuration.file.FileConfiguration in project AuthMeReloaded by AuthMe.

the class PermissionConsistencyTest method getPermissionsFromPluginYmlFile.

/**
     * Returns all permission entries from the plugin.yml file.
     *
     * @return map with the permission entries by permission node
     */
private static Map<String, PermissionDefinition> getPermissionsFromPluginYmlFile() {
    FileConfiguration pluginFile = YamlConfiguration.loadConfiguration(getJarFile("/plugin.yml"));
    MemorySection permsList = (MemorySection) pluginFile.get("permissions");
    Map<String, PermissionDefinition> permissions = new HashMap<>();
    addChildren(permsList, permissions);
    return ImmutableMap.copyOf(permissions);
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) MemorySection(org.bukkit.configuration.MemorySection) HashMap(java.util.HashMap)

Example 5 with FileConfiguration

use of org.bukkit.configuration.file.FileConfiguration in project AuthMeReloaded by AuthMe.

the class TranslationsGatherer method processMessagesFile.

private void processMessagesFile(String code, File file) {
    FileConfiguration configuration = YamlConfiguration.loadConfiguration(file);
    int availableMessages = 0;
    for (MessageKey key : MessageKey.values()) {
        if (configuration.contains(key.getKey())) {
            ++availableMessages;
        }
    }
    translationInfo.add(new TranslationInfo(code, (double) availableMessages / MessageKey.values().length));
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) MessageKey(fr.xephi.authme.message.MessageKey)

Aggregations

FileConfiguration (org.bukkit.configuration.file.FileConfiguration)29 File (java.io.File)6 Test (org.junit.Test)6 MinigameSave (au.com.mineauz.minigames.MinigameSave)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Map (java.util.Map)3 MemorySection (org.bukkit.configuration.MemorySection)3 Player (org.bukkit.entity.Player)3 RewardsFlag (au.com.mineauz.minigames.config.RewardsFlag)2 MenuItemString (au.com.mineauz.minigames.menu.MenuItemString)2 MinigameModule (au.com.mineauz.minigames.minigame.modules.MinigameModule)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)2 MenuItemSaveMinigame (au.com.mineauz.minigames.menu.MenuItemSaveMinigame)1 Rewards (au.com.mineauz.minigames.minigame.reward.Rewards)1 MinigameStat (au.com.mineauz.minigames.stats.MinigameStat)1 StatSettings (au.com.mineauz.minigames.stats.StatSettings)1 CommandDescription (fr.xephi.authme.command.CommandDescription)1