Wrap exceptions in interpreter to prevent ctd

This commit is contained in:
Licious17
2023-02-08 12:03:40 +00:00
parent 01b424994c
commit b82f9ec790
3 changed files with 55 additions and 49 deletions
+1 -1
View File
@@ -58,7 +58,7 @@
- Fixed missing lang and interpretation for bide
- Fixed datapack Pokémon not being able to battle.
- Fixed datapack Pokémon lang key generation, a Pokémon under the namespace ``example`` named ``Pogemon`` will now correctly look for the lang key ``example.species.pogemon.name``.
- Fixed HP recovery related battle actions not animating for the client.
- Fixed HP recovery related battle actions not animating for the client nor updating the in-game Pokémon HP.
- Fixed client not receiving messages for the different "stages" for the move Bide.
- Fixed the ability Speed Boost not having a human-readable battle message, this is an ongoing effort to prettify all the different ability triggers.
- Fixed Pokémon always being created with a moveset as if they're level 1 instead of their current level.
@@ -44,6 +44,7 @@ object ShowdownInterpreter {
private val lastMover = mutableMapOf<UUID, String>()
init {
// Note '-cureteam' is a legacy thing that is only used in generation 2 and 4 mods for heal bell and aromatherapy respectively as such we can just ignore that
updateInstructions["|player|"] = this::handlePlayerInstruction
updateInstructions["|teamsize|"] = this::handleTeamSizeInstruction
updateInstructions["|gametype|"] = this::handleGameTypeInstruction
@@ -167,64 +168,67 @@ object ShowdownInterpreter {
battle.log()
battle.log(rawMessage)
battle.log()
try {
val lines = rawMessage.split("\n").toMutableList()
if (lines[0] == "update") {
lines.removeAt(0)
while (lines.isNotEmpty()) {
val line = lines.removeAt(0)
val lines = rawMessage.split("\n").toMutableList()
if (lines[0] == "update") {
lines.removeAt(0)
while (lines.isNotEmpty()) {
val line = lines.removeAt(0)
// Split blocks have a public and private message below
if (line.startsWith("|split|")) {
val showdownId = line.split("|split|")[1]
val targetActor = battle.getActor(showdownId)
// Split blocks have a public and private message below
if (line.startsWith("|split|")) {
val showdownId = line.split("|split|")[1]
val targetActor = battle.getActor(showdownId)
if (targetActor == null) {
battle.log("No actor could be found with the showdown id: $showdownId")
return
}
val privateMessage = lines[0]
val publicMessage = lines[1]
for (instruction in splitUpdateInstructions.entries) {
if (lines[0].startsWith(instruction.key)) {
instruction.value(battle, targetActor, publicMessage, privateMessage)
break
if (targetActor == null) {
battle.log("No actor could be found with the showdown id: $showdownId")
return
}
}
lines.removeFirst()
lines.removeFirst()
} else {
if (line != "|") {
val instruction = updateInstructions.entries.find { line.startsWith(it.key) }?.value
if (instruction != null) {
instruction(battle, line, lines)
} else {
battle.dispatch {
battle.broadcastChatMessage(line.text())
GO
val privateMessage = lines[0]
val publicMessage = lines[1]
for (instruction in splitUpdateInstructions.entries) {
if (lines[0].startsWith(instruction.key)) {
instruction.value(battle, targetActor, publicMessage, privateMessage)
break
}
}
lines.removeFirst()
lines.removeFirst()
} else {
if (line != "|") {
val instruction = updateInstructions.entries.find { line.startsWith(it.key) }?.value
if (instruction != null) {
instruction(battle, line, lines)
} else {
battle.dispatch {
battle.broadcastChatMessage(line.text())
GO
}
}
}
}
}
}
} else if (lines[0] == "sideupdate") {
val showdownId = lines[1]
val targetActor = battle.getActor(showdownId)
val line = lines[2]
} else if (lines[0] == "sideupdate") {
val showdownId = lines[1]
val targetActor = battle.getActor(showdownId)
val line = lines[2]
if (targetActor == null) {
battle.log("No actor could be found with the showdown id: $showdownId")
return
}
if (targetActor == null) {
battle.log("No actor could be found with the showdown id: $showdownId")
return
}
for (instruction in sideUpdateInstructions.entries) {
if (line.startsWith(instruction.key)) {
instruction.value(battle, targetActor, line)
for (instruction in sideUpdateInstructions.entries) {
if (line.startsWith(instruction.key)) {
instruction.value(battle, targetActor, line)
}
}
}
} catch (e: Exception) {
LOGGER.error("Caught exception interpreting {}", e)
}
}
@@ -729,6 +733,8 @@ object ShowdownInterpreter {
"focusband" -> battleLang("item.hung_on.end", pokemonName, CobblemonItems.FOCUS_BAND.get().name)
"mistyterrain" -> battleLang("activate.misty_terrain", pokemonName)
"psychicterrain" -> battleLang("activate.psychic_terrain", pokemonName)
"healbell" -> battleLang("activate.heal_bell")
"aromatherapy" -> battleLang("activate.aromatherapy")
else -> battle.createUnimplemented(message)
}
battle.broadcastChatMessage(lang)
@@ -1111,6 +1117,4 @@ object ShowdownInterpreter {
})
}
// ToDo -cureteam
}
@@ -388,6 +388,8 @@
"cobblemon.battle.activate.gravity": "%1$s couldn't stay airborne because of gravity!",
"cobblemon.battle.activate.misty_terrain": "%1$s surrounds itself with a protective mist!",
"cobblemon.battle.activate.psychic_terrain": "%1$s surrounds itself with psychic terrain!",
"cobblemon.battle.activate.healbell": "A bell chimed!",
"cobblemon.battle.activate.aromatherapy": "A soothing aroma wafted through the area!",
"cobblemon.battle.set_hp.pain_split": "The battlers shared their pain!",