Abstract antiping into its own function

This commit is contained in:
DaMachinator 2018-01-23 11:16:17 -05:00 committed by Arcanitor
parent 346db118a4
commit f05de5188c
3 changed files with 18 additions and 5 deletions

View File

@ -0,0 +1,13 @@
package civilengineering
class Util {
companion object {
const val ZWSP: Char = '\u200b'
//Inserts a zero-width space at index 1 in the string'
@JvmStatic
fun antiping(str: String): String {
return str[0].toString()+ZWSP+str.substring(1)
}
}
}

View File

@ -2,6 +2,7 @@ package civilengineering.eventhandlers
import civilengineering.CivilEngineering
import civilengineering.CivilEngineeringConfig
import civilengineering.Util
import civilengineering.bridge.ApiMessage
import civilengineering.bridge.MessageHandler
import civilengineering.cfg
@ -13,9 +14,8 @@ class AdvancementEventHandler {
fun handleAdvancements(event: AdvancementEvent) {
if(cfg!!.relay.advancements && event.advancement.display != null) {
val zwsp: Char = '\u200B'
var player: String = event.entityPlayer.name
player = player[0].toString()+zwsp+player.substring(1) //antiping
//toString is necessary, otherwise the JVM thinks we're trying to do integer addition
var player: String = Util.antiping(event.entityPlayer.name)
MessageHandler.transmit(ApiMessage("Server",player+" has earned the advancement "+event.advancement.displayText.unformattedText))
}
}

View File

@ -1,5 +1,6 @@
package civilengineering.eventhandlers
import civilengineering.Util
import civilengineering.bridge.ApiMessage
import civilengineering.bridge.MessageHandler
import civilengineering.cfg
@ -14,8 +15,7 @@ class DeathEventHandler {
val entity = event.entityLiving
if (entity is EntityPlayer) {
var message: String = entity.getCombatTracker().deathMessage.unformattedText
message = message[0].toString() + '\u200b' + message.substring(1) //antiping
MessageHandler.transmit(ApiMessage(username = "Server", text = message))
MessageHandler.transmit(ApiMessage(username = "Server", text = Util.antiping(message)))
}
}
}