Search in sources :

Example 1 with PlayerStorage

use of com.pixelmonmod.pixelmon.storage.PlayerStorage in project PixelmonPlaceholders by happyzleaf.

the class Placeholders method trainer.

@Placeholder(id = "trainer")
public Object trainer(@Source Player player, @Token String token) throws NoValueException {
    Optional<PlayerStorage> optStorage = PixelmonStorage.pokeBallManager.getPlayerStorage((EntityPlayerMP) player);
    if (optStorage.isPresent()) {
        PlayerStorage storage = optStorage.get();
        String[] values = token.split("_");
        switch(values[0]) {
            case "dexcount":
                return storage.pokedex.countCaught();
            case "dexpercentage":
                String result1 = String.valueOf((double) storage.pokedex.countCaught() * 100 / EnumPokemon.values().length);
                if (result1.substring(result1.indexOf(".") + 1).length() == 1) {
                    return result1.substring(0, result1.length() - 2);
                } else {
                    return result1.substring(0, result1.indexOf(".") + 3);
                }
            case "seencount":
                return storage.pokedex.getSeenMap().size();
            case "wins":
                return storage.stats.getWins();
            case "losses":
                return storage.stats.getLosses();
            case "wlratio":
                int wins = storage.stats.getWins();
                int total = wins + storage.stats.getLosses();
                double result2;
                if (total <= 0) {
                    result2 = 1;
                } else {
                    result2 = (double) wins / total;
                }
                if (String.valueOf(result2).substring(String.valueOf(result2).indexOf(".") + 1).length() == 1) {
                    return String.valueOf(result2).concat("0");
                } else {
                    return String.valueOf(result2).substring(0, String.valueOf(result2).indexOf(".") + 3);
                }
            case "balance":
                return formatBigNumbers(storage.getCurrency());
            case // TODO move to %party_[...]%
            "team":
                if (values.length > 1) {
                    String[] pokeValues = Arrays.copyOfRange(values, 1, values.length);
                    try {
                        return parsePokemonInfo(player, storage, storage.getIDFromPosition(Integer.parseInt(pokeValues[0]) - 1), pokeValues);
                    } catch (NumberFormatException ignored) {
                    }
                }
                break;
        }
    }
    throw new NoValueException();
}
Also used : PlayerStorage(com.pixelmonmod.pixelmon.storage.PlayerStorage)

Aggregations

PlayerStorage (com.pixelmonmod.pixelmon.storage.PlayerStorage)1