Search in sources :

Example 1 with EntityPixelmon

use of com.pixelmonmod.pixelmon.entities.pixelmon.EntityPixelmon in project PixelmonPlaceholders by happyzleaf.

the class ParserUtility method parsePokemonInfo.

public static Object parsePokemonInfo(Player player, PlayerStorage storage, int[] id, String[] values) throws NoValueException {
    // The nbt "IsInBall" might be incorrect, so we save the real value here, before we load the pixelmon.
    boolean isSentOut = true;
    EntityPixelmon pokemon = storage.getAlreadyExists(id, (World) player.getWorld()).orElse(null);
    if (pokemon == null) {
        pokemon = storage.sendOut(id, (World) player.getWorld());
        isSentOut = false;
    }
    if (pokemon == null) {
        return PPConfig.entityNotFoundText;
    }
    if (pokemon.isEgg && PPConfig.disableEggInfo) {
        return PPConfig.disabledEggText;
    }
    if (values.length >= 2) {
        switch(values[1]) {
            case "nickname":
                return pokemon.hasNickname() ? pokemon.getNickname() : pokemon.getName();
            case "exp":
                return formatBigNumbers(pokemon.getLvl().getExp());
            case "level":
                return pokemon.getLvl().getLevel();
            case "exptolevelup":
                return formatBigNumbers(pokemon.getLvl().getExpForNextLevelClient());
            case "stats":
                if (values.length >= 3) {
                    Stats stats = pokemon.stats;
                    switch(values[2]) {
                        case "hp":
                            return stats.HP;
                        case "atk":
                            return stats.Attack;
                        case "def":
                            return stats.Defence;
                        case "spa":
                            return stats.SpecialAttack;
                        case "spd":
                            return stats.SpecialDefence;
                        case "spe":
                            return stats.Speed;
                        case "ivs":
                            if (values.length >= 4) {
                                IVStore ivs = stats.IVs;
                                switch(values[3]) {
                                    case "hp":
                                        return ivs.HP;
                                    case "atk":
                                        return ivs.Attack;
                                    case "def":
                                        return ivs.Defence;
                                    case "spa":
                                        return ivs.SpAtt;
                                    case "spd":
                                        return ivs.SpDef;
                                    case "spe":
                                        return ivs.Speed;
                                    case // since 1.2.3
                                    "total":
                                        return ivs.HP + ivs.Attack + ivs.Defence + ivs.SpAtt + ivs.SpDef + ivs.Speed;
                                    case "totalpercentage":
                                        String result3 = "" + (ivs.HP + ivs.Attack + ivs.Defence + ivs.SpAtt + ivs.SpDef + ivs.Speed) * 100 / 186;
                                        if (result3.substring(result3.indexOf(".") + 1).length() == 1) {
                                            return result3.substring(0, result3.length() - 2);
                                        } else {
                                            return result3.substring(0, result3.indexOf(".") + 3);
                                        }
                                }
                            }
                            break;
                        case "evs":
                            if (values.length >= 4) {
                                EVsStore evs = stats.EVs;
                                switch(values[3]) {
                                    case "hp":
                                        return evs.HP;
                                    case "atk":
                                        return evs.Attack;
                                    case "def":
                                        return evs.Defence;
                                    case "spa":
                                        return evs.SpecialAttack;
                                    case "spd":
                                        return evs.SpecialDefence;
                                    case "spe":
                                        return evs.Speed;
                                    case // since 1.2.3
                                    "total":
                                        return evs.HP + evs.Attack + evs.Defence + evs.SpecialAttack + evs.SpecialDefence + evs.Speed;
                                    case "totalpercentage":
                                        String result4 = "" + (evs.HP + evs.Attack + evs.Defence + evs.SpecialAttack + evs.SpecialDefence + evs.Speed) / 510;
                                        if (result4.substring(result4.indexOf(".") + 1).length() == 1) {
                                            return result4.substring(0, result4.length() - 2);
                                        } else {
                                            return result4.substring(0, result4.indexOf(".") + 3);
                                        }
                                }
                            }
                            break;
                    }
                }
                break;
            case "helditem":
                return pokemon.heldItem == null ? PPConfig.noneText : pokemon.heldItem.getDisplayName();
            case // Before 1.3.0: last known position. After: exact pokémon position or player's position if carried in a ball
            "pos":
                if (values.length >= 3) {
                    // Vector3d pos = isSentOut ? new Vector3d(pokemon.getPosition().getX(), pokemon.getPosition().getY(), pokemon.getPosition().getZ()) : player.getPosition();
                    switch(values[2]) {
                        case "x":
                            // return pos.getX(); <-- this is way more elegant but i'd like to avoid creating a new vector on every placeholder request
                            return // NOTE: This method won't work with 7.0.0!
                            formatDouble(isSentOut ? pokemon.getPosition().getX() : player.getPosition().getX());
                        case "y":
                            return formatDouble(isSentOut ? pokemon.getPosition().getY() : player.getPosition().getY());
                        case "z":
                            return formatDouble(isSentOut ? pokemon.getPosition().getZ() : player.getPosition().getZ());
                    }
                }
                break;
            case "moveset":
                Moveset moveset = pokemon.getMoveset();
                try {
                    return moveset.get(Integer.parseInt(values[2]) - 1);
                } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
                    return asReadableList(values, 2, moveset.attacks);
                }
            case "friendship":
                return formatBigNumbers(pokemon.friendship.getFriendship());
            case "ability":
                if (values.length == 2) {
                    // why did i put this check here? UPDATE: Ohhh yeah so it is reflected over the generic placeholders
                    return pokemon.getAbility().getName();
                }
                break;
            case // Updated 1.3.0: uses localized names
            "ball":
                return pokemon.caughtBall.getItem().getLocalizedName();
            // return asReadableList(pokeValues, 2, DropItemRegistry.getDropsForPokemon(pokemon).stream().map(ParserUtility::getItemStackInfo).toArray());
            case "nature":
                return pokemon.getNature();
            case // since 1.2.3
            "gender":
                return pokemon.getGender().name();
            case "growth":
                return pokemon.getGrowth().name();
            case // Since 1.3.0
            "shiny":
                return pokemon.getIsShiny();
        }
    }
    return parsePokedexInfo(EnumPokemon.getFromNameAnyCase(pokemon.getPokemonName()), values);
}
Also used : DatabaseStats(com.pixelmonmod.pixelmon.database.DatabaseStats) EntityPixelmon(com.pixelmonmod.pixelmon.entities.pixelmon.EntityPixelmon) World(net.minecraft.world.World)

Aggregations

DatabaseStats (com.pixelmonmod.pixelmon.database.DatabaseStats)1 EntityPixelmon (com.pixelmonmod.pixelmon.entities.pixelmon.EntityPixelmon)1 World (net.minecraft.world.World)1