Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix name length limit + Reworked patterns
- Loading branch information
Showing
4 changed files
with
77 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
import POGOProtos.Networking.Responses.NicknamePokemonResponseOuterClass.NicknamePokemonResponse; | ||
import com.pokegoapi.api.pokemon.Pokemon; | ||
import com.pokegoapi.api.pokemon.PokemonMeta; | ||
import com.pokegoapi.api.pokemon.PokemonMoveMeta; | ||
import com.pokegoapi.api.pokemon.PokemonMoveMetaRegistry; | ||
import com.pokegoapi.exceptions.LoginFailedException; | ||
import com.pokegoapi.exceptions.RemoteServerException; | ||
import com.pokegoapi.util.PokeNames; | ||
|
@@ -17,6 +19,8 @@ | |
import java.util.regex.Pattern; | ||
|
||
public class PokeHandler { | ||
public static final int MAX_NICKNAME_LENGTH = 12; | ||
|
||
private ArrayList<Pokemon> mons; | ||
|
||
public PokeHandler(Pokemon pokemon) { | ||
|
@@ -55,7 +59,7 @@ private static String generatePokemonNickname(String pattern, Pokemon pokemon, P | |
// Do nothing, nothing to replace | ||
} | ||
} | ||
return pokeNick; | ||
return StringUtils.substring(pokeNick, 0, MAX_NICKNAME_LENGTH); | ||
} | ||
|
||
/*** | ||
|
@@ -74,7 +78,7 @@ public static NicknamePokemonResponse.Result renameWithPattern(String pattern, P | |
* it every time we process a pokemon. This should save resources. | ||
*/ | ||
private static Pattern getRenamePattern() { | ||
return Pattern.compile("(%([a-zA-Z_]+)%)"); | ||
return Pattern.compile("(%([a-zA-Z0-9_]+)%)"); | ||
} | ||
|
||
/*** | ||
|
@@ -192,6 +196,18 @@ public String get(Pokemon p) { | |
return getLocalPokeName(p); | ||
} | ||
}, | ||
NAME_4("Pokémon Name (First four letters)") { | ||
@Override | ||
public String get(Pokemon p) { | ||
return StringUtils.substring(getLocalPokeName(p), 0, 4); | ||
} | ||
}, | ||
NAME_6("Pokémon Name (First six letters)") { | ||
@Override | ||
public String get(Pokemon p) { | ||
return StringUtils.substring(getLocalPokeName(p), 0, 6); | ||
} | ||
}, | ||
CP("Combat Points") { | ||
@Override | ||
public String get(Pokemon p) { | ||
|
@@ -216,10 +232,16 @@ public String get(Pokemon p) { | |
return String.valueOf(Math.round(p.getIvRatio() * 100 * 100) / 100.0); | ||
} | ||
}, | ||
IV("IV Values (All three, like \"15/15/15\")") { | ||
IV_RATING_INT("IV Rating (Rounded to integer)") { | ||
@Override | ||
public String get(Pokemon p) { | ||
return String.valueOf(Math.round(p.getIvRatio() * 100)); | ||
} | ||
}, | ||
IV_HEX("IV Values in hexadecimal, like \"9FA\" (F = 15)") { | ||
@Override | ||
public String get(Pokemon p) { | ||
return p.getIndividualAttack() + "/" + p.getIndividualDefense() + "/" + p.getIndividualStamina(); | ||
return (Integer.toHexString(p.getIndividualAttack()) + Integer.toHexString(p.getIndividualDefense()) + Integer.toHexString(p.getIndividualStamina())).toUpperCase(); | ||
} | ||
}, | ||
IV_ATT("IV Attack") { | ||
|
@@ -250,22 +272,42 @@ public String get(Pokemon p) { | |
return String.valueOf(PokemonCpUtils.getMaxCp(attack, defense, stamina)); | ||
} | ||
}, | ||
TYPE1("Pokémon Type 1") { | ||
MOVE_TYPES("Types of both moves, displayed with first letter. (Fire, Normal = FN)") { | ||
@Override | ||
public String get(Pokemon p) { | ||
PokemonMoveMeta pm1 = PokemonMoveMetaRegistry.getMeta(p.getMove1()); | ||
PokemonMoveMeta pm2 = PokemonMoveMetaRegistry.getMeta(p.getMove2()); | ||
return pm1.toString().toUpperCase().charAt(0) + "" + pm2.toString().toUpperCase().charAt(0); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Wolfsblvt
Author
Owner
|
||
} | ||
}, | ||
DPS_1("Damage per second for Move 1") { | ||
@Override | ||
public String get(Pokemon p) { | ||
return String.valueOf(Math.round(PokemonUtils.dpsForMove1(p))); | ||
} | ||
}, | ||
DPS_2("Damage per second for Move 2") { | ||
@Override | ||
public String get(Pokemon p) { | ||
return String.valueOf(Math.round(PokemonUtils.dpsForMove2(p))); | ||
} | ||
}, | ||
TYPE_1("Pokémon Type 1 (First two letters)") { | ||
@Override | ||
public String get(Pokemon p) { | ||
return StringUtils.capitalize(p.getMeta().getType1().toString().toLowerCase()); | ||
return StringUtils.substring(StringUtils.capitalize(p.getMeta().getType1().toString().toLowerCase()), 0, 2); | ||
} | ||
}, | ||
TYPE2("Pokémon Type 2") { | ||
TYPE_2("Pokémon Type 2 (First two letters)") { | ||
@Override | ||
public String get(Pokemon p) { | ||
return StringUtils.capitalize(p.getMeta().getType2().toString().toLowerCase().replaceAll("none", "")); | ||
return StringUtils.substring(StringUtils.capitalize(p.getMeta().getType2().toString().toLowerCase().replaceAll("none", "")), 0, 2); | ||
} | ||
}, | ||
ID("Pokédex Id") { | ||
@Override | ||
public String get(Pokemon p) { | ||
return String.valueOf(p.getId()); | ||
return String.valueOf(p.getPokemonId().getNumber()); | ||
} | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Move Types should pull the first two chars. Otherwise we'll have issues with types like Fighting, Flying, Fire and Fairy = F.
This fix still means we'll have issues with Fire and Ground but those can be fixed by taking the first and last char from the type string: Fire = Fe, Ground = Gd.