Skip to content

Commit

Permalink
cleanup a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
byBackfish committed Jun 13, 2022
1 parent ab8a5b9 commit 35b936f
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 61 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/de/bybackfish/wynnstats/WynnMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object WynnMod {
@Mod.EventHandler
fun preinit(event: FMLPreInitializationEvent) {
val commandHandler = ClientCommandHandler.instance
PlayerStatsCommand()
PlayerStatsCommand()
GuildStatsCommand()
GuildMembersCommand()
ServersCommand()
Expand Down
25 changes: 19 additions & 6 deletions src/main/kotlin/de/bybackfish/wynnstats/adapter/Adapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ class Adapter : ILanguageAdapter {
target.set(modObject, proxy)
}

override fun getNewInstance(container: FMLModContainer?, objectClass: Class<*>, classLoader: ClassLoader, factoryMarkedAnnotation: Method?): Any? {
override fun getNewInstance(
container: FMLModContainer?,
objectClass: Class<*>,
classLoader: ClassLoader,
factoryMarkedAnnotation: Method?
): Any? {
val instanceField = findInstanceFieldOrThrow(objectClass)
val modObject = findModObjectOrThrow(instanceField)
return modObject
Expand Down Expand Up @@ -52,10 +57,18 @@ class Adapter : ILanguageAdapter {
return modObject
}

private fun noInstanceFieldException(exception: Exception) = KotlinAdapterException("Couldn't find INSTANCE singleton on Kotlin @Mod container", exception)
private fun instanceSecurityException(exception: Exception) = KotlinAdapterException("Security violation accessing INSTANCE singleton on Kotlin @Mod container", exception)
private fun unexpectedInitializerSignatureException(exception: Exception) = KotlinAdapterException("Kotlin @Mod object has an unexpected initializer signature, somehow?", exception)
private fun wrongVisibilityOnInitializerException(exception: Exception) = KotlinAdapterException("Initializer on Kotlin @Mod object isn't `public`", exception)
private fun noInstanceFieldException(exception: Exception) =
KotlinAdapterException("Couldn't find INSTANCE singleton on Kotlin @Mod container", exception)

private class KotlinAdapterException(message: String, exception: Exception): RuntimeException("Kotlin adapter error - do not report to Forge! " + message, exception)
private fun instanceSecurityException(exception: Exception) =
KotlinAdapterException("Security violation accessing INSTANCE singleton on Kotlin @Mod container", exception)

private fun unexpectedInitializerSignatureException(exception: Exception) =
KotlinAdapterException("Kotlin @Mod object has an unexpected initializer signature, somehow?", exception)

private fun wrongVisibilityOnInitializerException(exception: Exception) =
KotlinAdapterException("Initializer on Kotlin @Mod object isn't `public`", exception)

private class KotlinAdapterException(message: String, exception: Exception) :
RuntimeException("Kotlin adapter error - do not report to Forge! " + message, exception)
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ open class Kommand(
args: Array<out String>,
targetPos: BlockPos?
): MutableList<String> {
if(autoComplete == null) return super.getTabCompletions(server, sender, args, targetPos);
if (autoComplete == null) return super.getTabCompletions(server, sender, args, targetPos)
return super.getTabCompletions(server, sender, args, targetPos)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import net.minecraft.util.text.TextComponentString
import net.minecraft.util.text.event.ClickEvent
import net.minecraft.util.text.event.HoverEvent

class GuildMembersCommand: Kommand(k@{
class GuildMembersCommand : Kommand(k@{

if (it.isEmpty()) {
send(TextComponentString("§cPlease specify a guild name!"))
Expand Down Expand Up @@ -49,5 +49,4 @@ class GuildMembersCommand: Kommand(k@{

send(TextComponentString("§6-------------"))

}, "guildmembers") {
}
}, "guildmembers")
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import net.minecraft.util.text.TextComponentString
import net.minecraft.util.text.event.ClickEvent
import net.minecraft.util.text.event.HoverEvent

class GuildStatsCommand: Kommand(k@{
class GuildStatsCommand : Kommand(k@{

if (it.isEmpty()) {
send(TextComponentString("§cPlease specify a guild name!"))
Expand Down Expand Up @@ -60,8 +60,9 @@ class GuildStatsCommand: Kommand(k@{
send(TextComponentString("§6- Created at: §7${guild.created}"))
send(TextComponentString("§6-------------"))

}, "guildstats", alias = arrayOf("guildstat", "gstat", "gv", "gs"), autoComplete = autocomplete@{ args ->
val container: UpdateContainer = WynnMod.data.getOrDefaultContainer("guildstatsUpdate", UpdateContainer(data = arrayListOf<String>()))
}, "guildstats", alias = arrayOf("guildstat", "gstat", "gv", "gs"), autoComplete = autocomplete@{ args ->
val container: UpdateContainer =
WynnMod.data.getOrDefaultContainer("guildstatsUpdate", UpdateContainer(data = arrayListOf<String>()))
if (container.isUpdateNeeded()) {
Thread {
container.lastUpdate = System.currentTimeMillis()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package de.bybackfish.wynnstats.commands.stats

import camelCase
import com.mojang.realmsclient.gui.ChatFormatting
import de.bybackfish.wynnapi.WynnStats
import de.bybackfish.wynnapi.player.classes.PlayerClasses
import de.bybackfish.wynnstats.WynnMod
import de.bybackfish.wynnstats.commands.Kommand
Expand All @@ -14,14 +13,15 @@ import net.minecraft.util.text.event.HoverEvent

class PlayerStatsCommand : Kommand(k@{ args ->

val playerName = if (args.isEmpty()) player.name else args[0]
val player = WynnMod.stats.getPlayer(playerName) ?: return@k player.sendMessage(TextComponentString("§7The specified player does not exist."))
val playerName = if (args.isEmpty()) Minecraft.getMinecraft().player.name else args[0]
val player = WynnMod.stats.getPlayer(playerName)
?: return@k player.sendMessage(TextComponentString("§7The specified player does not exist."))

val data = player.getData()

if (args.size == 1) {
if (args.size == 1 || args.isEmpty()) {

send("§6--- Player §7[${if(data.rank == "Player") data.meta.tag?.value ?: "None" else data.rank }] ${data.username} §6---")
send("§6--- Player §7[${if (data.rank == "Player") data.meta.tag?.value ?: "None" else data.rank}] ${data.username} §6---")
send("§7Click on a class to get more info!")

send("")
Expand All @@ -42,8 +42,8 @@ class PlayerStatsCommand : Kommand(k@{ args ->
hoverEvent = HoverEvent(
HoverEvent.Action.SHOW_TEXT, TextComponentString(
"§7Click to get more data about this class!\n\n" +
"§7Combat: §b${clazz.professions.combat.level}\n"
+ "§7Playtime: §b${clazz.playtime}min\n"
"§7Combat: §b${clazz.professions.combat.level}\n"
+ "§7Playtime: §b${clazz.playtime}min\n"
)
),
clickEvent = ClickEvent(
Expand Down Expand Up @@ -87,19 +87,19 @@ class PlayerStatsCommand : Kommand(k@{ args ->
HoverEvent(
HoverEvent.Action.SHOW_TEXT, TextComponentString(
"§6Combat: §7${playerClass.professions.combat.level}\n" +
"§6Farming: §7${playerClass.professions.farming.level}\n" +
"§6Mining: §7${playerClass.professions.mining.level}\n" +
"§6Foraging: §7${playerClass.professions.woodcutting.level}\n" +
"§6Fishing: §7${playerClass.professions.fishing.level}\n" +
"\n" +
"§6Cooking: §7${playerClass.professions.cooking.level}\n" +
"§6Alchemism: §7${playerClass.professions.alchemism.level}\n" +
"§6Armouring: §7${playerClass.professions.armouring.level}\n" +
"§6Jeweling: §7${playerClass.professions.jeweling.level}\n" +
"§6Scribing: §7${playerClass.professions.scribing.level}\n" +
"§6Tailoring: §7${playerClass.professions.tailoring.level}\n" +
"§6Weaponsmithing: §7${playerClass.professions.weaponsmithing.level}\n" +
"§6Woodworking: §7${playerClass.professions.woodworking.level}\n"
"§6Farming: §7${playerClass.professions.farming.level}\n" +
"§6Mining: §7${playerClass.professions.mining.level}\n" +
"§6Foraging: §7${playerClass.professions.woodcutting.level}\n" +
"§6Fishing: §7${playerClass.professions.fishing.level}\n" +
"\n" +
"§6Cooking: §7${playerClass.professions.cooking.level}\n" +
"§6Alchemism: §7${playerClass.professions.alchemism.level}\n" +
"§6Armouring: §7${playerClass.professions.armouring.level}\n" +
"§6Jeweling: §7${playerClass.professions.jeweling.level}\n" +
"§6Scribing: §7${playerClass.professions.scribing.level}\n" +
"§6Tailoring: §7${playerClass.professions.tailoring.level}\n" +
"§6Weaponsmithing: §7${playerClass.professions.weaponsmithing.level}\n" +
"§6Woodworking: §7${playerClass.professions.woodworking.level}\n"

)
)
Expand All @@ -122,7 +122,7 @@ class PlayerStatsCommand : Kommand(k@{ args ->
send(guild)
send("")

val component = TextComponentString("§7- §6Skills: ${buildSkillString(playerClass)}");
val component = TextComponentString("§7- §6Skills: ${buildSkillString(playerClass)}")
send(component)


Expand All @@ -134,11 +134,11 @@ class PlayerStatsCommand : Kommand(k@{ args ->
HoverEvent(
HoverEvent.Action.SHOW_TEXT, TextComponentString(
"§6Quests completed: ${playerClass.quests.list.size}\n" +
"§6Kills: §7${playerClass.mobsKilled}\n" +
"§6Deaths: §7${playerClass.deaths}\n" +
"§6Chests found: §7${playerClass.chestsFound}\n" +
"§6Discoveries: §7${playerClass.discoveries}\n" +
"§6Logins: §7${playerClass.logins}\n"
"§6Kills: §7${playerClass.mobsKilled}\n" +
"§6Deaths: §7${playerClass.deaths}\n" +
"§6Chests found: §7${playerClass.chestsFound}\n" +
"§6Discoveries: §7${playerClass.discoveries}\n" +
"§6Logins: §7${playerClass.logins}\n"
)
)
)
Expand All @@ -150,9 +150,9 @@ class PlayerStatsCommand : Kommand(k@{ args ->

dungeons.style = Style().setHoverEvent(HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponentString(
"§6Dungeons completed: \n§6Unique: §7${playerClass.dungeons.list.size} §7| §6Total: §7${playerClass.dungeons.list.sumOf { it.completed }}\n" +
playerClass.dungeons.list.joinToString("\n") {
"§6${it.name!!.camelCase()}: §7${it.completed}"
}
playerClass.dungeons.list.joinToString("\n") {
"§6${it.name!!.camelCase()}: §7${it.completed}"
}
)))

send(dungeons)
Expand All @@ -161,9 +161,9 @@ class PlayerStatsCommand : Kommand(k@{ args ->

raids.style = Style().setHoverEvent(HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponentString(
"Raids completed: \n§6Unique: §7${playerClass.raids.list.size} §7 | §6Total: §7${playerClass.raids.completed}\n" +
playerClass.raids.list.joinToString("\n") {
"§6${it.name!!.camelCase()}: §7${it.completed}"
}
playerClass.raids.list.joinToString("\n") {
"§6${it.name!!.camelCase()}: §7${it.completed}"
}
)))


Expand All @@ -172,32 +172,28 @@ class PlayerStatsCommand : Kommand(k@{ args ->
send(TextComponentString("§6- Playtime (Class): §7${playerClass.playtime}min"))
send(TextComponentString("§6-------------"))





}, "playerstats", alias = arrayOf("pv"))

fun buildSkillString(clazz: PlayerClasses): String {
var output = "";
var output = ""
output += ChatFormatting.DARK_GREEN.toString() + clazz.skills.strength + " "
output += ChatFormatting.YELLOW.toString() + clazz.skills.dexterity + " "
output += ChatFormatting.AQUA.toString() + clazz.skills.intelligence + " "
output += ChatFormatting.RED.toString() + clazz.skills.defence + " "
output += ChatFormatting.WHITE.toString() + clazz.skills.agility

return output;
return output
}

fun buildGamemodeString(clazz: PlayerClasses): String{
var output = "";
fun buildGamemodeString(clazz: PlayerClasses): String {
var output = ""

if(clazz.gamemode.hardcore) output+= GamemodeIcons.HARDCORE;
if(clazz.gamemode.ironman) output+= GamemodeIcons.IRONMAN;
if(clazz.gamemode.craftsman) output+= GamemodeIcons.CRAFTSMAN;
if(clazz.gamemode.hunted) output+= GamemodeIcons.HUNTED;
if (clazz.gamemode.hardcore) output += GamemodeIcons.HARDCORE
if (clazz.gamemode.ironman) output += GamemodeIcons.IRONMAN
if (clazz.gamemode.craftsman) output += GamemodeIcons.CRAFTSMAN
if (clazz.gamemode.hunted) output += GamemodeIcons.HUNTED

return output;
return output
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import net.minecraft.util.text.TextComponentString
import net.minecraft.util.text.event.ClickEvent
import net.minecraft.util.text.event.HoverEvent

class ServersCommand: Kommand(k@{
class ServersCommand : Kommand(k@{

val servers = WynnMod.stats.getServers()!!
if (it.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class DataContainer {

fun <T> getOrDefaultContainer(key: String, default: T): T {
val data = data[key]
if(data == null) {
if (data == null) {
Minecraft.getMinecraft().player.sendMessage(
net.minecraft.util.text.TextComponentString("No data found for key: $key")
)
Expand Down

0 comments on commit 35b936f

Please sign in to comment.