Abstract message coloring into its own class

Move Util to its own package with Color
This commit is contained in:
DaMachinator 2018-01-23 15:25:24 -05:00 committed by Arcanitor
parent a56131344b
commit 54eb09c652
6 changed files with 33 additions and 9 deletions

View File

@ -2,6 +2,8 @@ package civilengineering.bridge
import civilengineering.CivilEngineering
import civilengineering.cfg
import civilengineering.util.Color
import civilengineering.util.color
import net.minecraft.util.text.TextComponentString
import net.minecraftforge.fml.common.FMLCommonHandler
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@ -17,6 +19,7 @@ class ServerChatHelper {
if (nextMessage != null && nextMessage.gateway == cfg!!.connect.gateway) {
val user = nextMessage.username
val text = nextMessage.text.trim()
val chan = nextMessage.channel
val message: String
@ -26,7 +29,7 @@ class ServerChatHelper {
message = when (event) {
"user_action" -> "* $user $text"
"" -> "<$user> $text"
"join_leave" -> section.toString()+"6-- $user $text"
"join_leave" -> "-- $user $text $chan".color(Color.GOLD)
else -> {
CivilEngineering.logger.debug("Threw out message with unhandled event: $event")
CivilEngineering.logger.debug(" Message contents:")

View File

@ -1,9 +1,6 @@
package civilengineering.eventhandlers
import civilengineering.Util.antiping
import civilengineering.CivilEngineering
import civilengineering.CivilEngineeringConfig
import civilengineering.Util
import civilengineering.util.Util.antiping
import civilengineering.bridge.ApiMessage
import civilengineering.bridge.MessageHandler
import civilengineering.cfg

View File

@ -1,6 +1,6 @@
package civilengineering.eventhandlers
import civilengineering.Util.antiping
import civilengineering.util.Util.antiping
import civilengineering.bridge.ApiMessage
import civilengineering.bridge.MessageHandler
import civilengineering.cfg

View File

@ -2,7 +2,7 @@ package civilengineering.eventhandlers
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.PlayerEvent
import civilengineering.Util.antiping
import civilengineering.util.Util.antiping
import civilengineering.bridge.ApiMessage
import civilengineering.bridge.MessageHandler
import civilengineering.cfg

View File

@ -0,0 +1,24 @@
package civilengineering.util
fun String.color(color: Color):String {
return color.code+this
}
enum class Color(val index:Int,val code:String) {
BLACK(0,"§0"),
DARK_BLUE(1,"§1"),
DARK_GREEN(2,"§2"),
DARK_AQUA(3,"§3"),
DARK_RED(4,"§4"),
DARK_PURPLE(5,"§5"),
GOLD(6,"§6"),
GRAY(7,"§7"),
DARK_GRAY(8,"§8"),
BLUE(9,"§9"),
GREEN(10,"§a"),
AQUA(11,"§b"),
RED(12,"§c"),
LIGHT_PURPLE(13,"§d"),
YELLOW(14,"§e"),
WHITE(15,"§f")
}

View File

@ -1,4 +1,4 @@
package civilengineering
package civilengineering.util
object Util {
@ -7,7 +7,7 @@ object Util {
//Inserts a zero-width space at index 1 in the string'
fun String.antiping(): String {
return this[0].toString()+ZWSP+this.substring(1)
return this[0].toString()+ ZWSP +this.substring(1)
}
}