From 54eb09c652944e8be2f504535b97d5217271321b Mon Sep 17 00:00:00 2001 From: DaMachinator Date: Tue, 23 Jan 2018 15:25:24 -0500 Subject: [PATCH] Abstract message coloring into its own class Move Util to its own package with Color --- .../bridge/ServerChatHelper.kt | 5 +++- .../eventhandlers/AdvancementEventHandler.kt | 5 +--- .../eventhandlers/DeathEventHandler.kt | 2 +- .../eventhandlers/JoinLeaveHandler.kt | 2 +- .../kotlin/civilengineering/util/Color.kt | 24 +++++++++++++++++++ .../civilengineering/{ => util}/Util.kt | 4 ++-- 6 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 src/main/kotlin/civilengineering/util/Color.kt rename src/main/kotlin/civilengineering/{ => util}/Util.kt (63%) diff --git a/src/main/kotlin/civilengineering/bridge/ServerChatHelper.kt b/src/main/kotlin/civilengineering/bridge/ServerChatHelper.kt index 69a95da..96fc56b 100644 --- a/src/main/kotlin/civilengineering/bridge/ServerChatHelper.kt +++ b/src/main/kotlin/civilengineering/bridge/ServerChatHelper.kt @@ -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:") diff --git a/src/main/kotlin/civilengineering/eventhandlers/AdvancementEventHandler.kt b/src/main/kotlin/civilengineering/eventhandlers/AdvancementEventHandler.kt index 548f0d2..2de6547 100644 --- a/src/main/kotlin/civilengineering/eventhandlers/AdvancementEventHandler.kt +++ b/src/main/kotlin/civilengineering/eventhandlers/AdvancementEventHandler.kt @@ -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 diff --git a/src/main/kotlin/civilengineering/eventhandlers/DeathEventHandler.kt b/src/main/kotlin/civilengineering/eventhandlers/DeathEventHandler.kt index e08cb4a..9ecc9b4 100644 --- a/src/main/kotlin/civilengineering/eventhandlers/DeathEventHandler.kt +++ b/src/main/kotlin/civilengineering/eventhandlers/DeathEventHandler.kt @@ -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 diff --git a/src/main/kotlin/civilengineering/eventhandlers/JoinLeaveHandler.kt b/src/main/kotlin/civilengineering/eventhandlers/JoinLeaveHandler.kt index a3bef68..4aeff28 100644 --- a/src/main/kotlin/civilengineering/eventhandlers/JoinLeaveHandler.kt +++ b/src/main/kotlin/civilengineering/eventhandlers/JoinLeaveHandler.kt @@ -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 diff --git a/src/main/kotlin/civilengineering/util/Color.kt b/src/main/kotlin/civilengineering/util/Color.kt new file mode 100644 index 0000000..a3089c7 --- /dev/null +++ b/src/main/kotlin/civilengineering/util/Color.kt @@ -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") +} \ No newline at end of file diff --git a/src/main/kotlin/civilengineering/Util.kt b/src/main/kotlin/civilengineering/util/Util.kt similarity index 63% rename from src/main/kotlin/civilengineering/Util.kt rename to src/main/kotlin/civilengineering/util/Util.kt index ec98f07..ca0a507 100644 --- a/src/main/kotlin/civilengineering/Util.kt +++ b/src/main/kotlin/civilengineering/util/Util.kt @@ -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) } } \ No newline at end of file