From 26c0107adc319e169da89eb32ee50c4afb0709db Mon Sep 17 00:00:00 2001 From: Lorenz Date: Thu, 7 Jul 2022 00:31:50 +0200 Subject: init lorenz mod --- build.gradle | 31 +- src/main/java/at/lorenz/mod/GuiContainerHook.kt | 61 +++ .../java/at/lorenz/mod/HideNotClickableItems.kt | 444 +++++++++++++++++++++ src/main/java/at/lorenz/mod/bazaar/BazaarApi.kt | 59 +++ src/main/java/at/lorenz/mod/bazaar/BazaarData.kt | 3 + .../java/at/lorenz/mod/bazaar/BazaarDataGrabber.kt | 116 ++++++ .../java/at/lorenz/mod/bazaar/BazaarOrderHelper.kt | 87 ++++ src/main/java/at/lorenz/mod/chat/ChatFilter.kt | 279 +++++++++++++ src/main/java/at/lorenz/mod/chat/ChatManager.kt | 47 +++ .../java/at/lorenz/mod/chat/PlayerChatFilter.kt | 78 ++++ .../at/lorenz/mod/chat/PlayerMessageChannel.kt | 10 + src/main/java/at/lorenz/mod/config/LorenzConfig.kt | 12 + .../at/lorenz/mod/dungeon/DungeonChatFilter.kt | 259 ++++++++++++ .../java/at/lorenz/mod/events/GuiContainerEvent.kt | 54 +++ .../java/at/lorenz/mod/events/LorenzChatEvent.kt | 5 + src/main/java/at/lorenz/mod/events/LorenzEvent.kt | 20 + .../at/lorenz/mod/events/PlayerSendChatEvent.kt | 11 + .../at/lorenz/mod/mixins/MixinGuiContainer.java | 50 +++ src/main/java/at/lorenz/mod/utils/APIUtil.kt | 116 ++++++ src/main/java/at/lorenz/mod/utils/ItemUtil.kt | 211 ++++++++++ src/main/java/at/lorenz/mod/utils/ItemUtils.kt | 39 ++ src/main/java/at/lorenz/mod/utils/LorenzColor.kt | 27 ++ src/main/java/at/lorenz/mod/utils/LorenzLogger.kt | 70 ++++ src/main/java/at/lorenz/mod/utils/LorenzUtils.kt | 91 +++++ src/main/java/at/lorenz/mod/utils/RenderUtil.kt | 20 + .../com/thatgravyboat/skyblockhud/SkyblockHud.java | 346 ++++++++-------- src/main/resources/mixins.skyblockhud.json | 9 +- 27 files changed, 2360 insertions(+), 195 deletions(-) create mode 100644 src/main/java/at/lorenz/mod/GuiContainerHook.kt create mode 100644 src/main/java/at/lorenz/mod/HideNotClickableItems.kt create mode 100644 src/main/java/at/lorenz/mod/bazaar/BazaarApi.kt create mode 100644 src/main/java/at/lorenz/mod/bazaar/BazaarData.kt create mode 100644 src/main/java/at/lorenz/mod/bazaar/BazaarDataGrabber.kt create mode 100644 src/main/java/at/lorenz/mod/bazaar/BazaarOrderHelper.kt create mode 100644 src/main/java/at/lorenz/mod/chat/ChatFilter.kt create mode 100644 src/main/java/at/lorenz/mod/chat/ChatManager.kt create mode 100644 src/main/java/at/lorenz/mod/chat/PlayerChatFilter.kt create mode 100644 src/main/java/at/lorenz/mod/chat/PlayerMessageChannel.kt create mode 100644 src/main/java/at/lorenz/mod/config/LorenzConfig.kt create mode 100644 src/main/java/at/lorenz/mod/dungeon/DungeonChatFilter.kt create mode 100644 src/main/java/at/lorenz/mod/events/GuiContainerEvent.kt create mode 100644 src/main/java/at/lorenz/mod/events/LorenzChatEvent.kt create mode 100644 src/main/java/at/lorenz/mod/events/LorenzEvent.kt create mode 100644 src/main/java/at/lorenz/mod/events/PlayerSendChatEvent.kt create mode 100644 src/main/java/at/lorenz/mod/mixins/MixinGuiContainer.java create mode 100644 src/main/java/at/lorenz/mod/utils/APIUtil.kt create mode 100644 src/main/java/at/lorenz/mod/utils/ItemUtil.kt create mode 100644 src/main/java/at/lorenz/mod/utils/ItemUtils.kt create mode 100644 src/main/java/at/lorenz/mod/utils/LorenzColor.kt create mode 100644 src/main/java/at/lorenz/mod/utils/LorenzLogger.kt create mode 100644 src/main/java/at/lorenz/mod/utils/LorenzUtils.kt create mode 100644 src/main/java/at/lorenz/mod/utils/RenderUtil.kt diff --git a/build.gradle b/build.gradle index 7a73a20c7..3bd0ac747 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,5 @@ buildscript { + ext.kotlin_version = '1.7.0' repositories { maven { name = 'jitpack' @@ -6,15 +7,18 @@ buildscript { } maven { url = 'https://maven.minecraftforge.net/' } maven { url = 'https://repo.spongepowered.org/maven' } + mavenCentral() } dependencies { classpath 'com.github.asbyth:ForgeGradle:8708bf3e01' classpath 'com.github.xcfrg:MixinGradle:0.6-SNAPSHOT' classpath 'com.github.jengelman.gradle.plugins:shadow:6.1.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } apply plugin: 'java' +apply plugin: 'kotlin' apply plugin: 'net.minecraftforge.gradle.forge' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' @@ -22,15 +26,20 @@ apply plugin: 'com.github.johnrengelman.shadow' sourceCompatibility = 1.8 targetCompatibility = 1.8 -version = '1.13' +version = '0.1' group= 'com.thatgravyboat.skyblockhud' -archivesBaseName = 'SkyBlockHud' +archivesBaseName = 'LorenzMod' String mixinClassifier = 'dep' minecraft { version = '1.8.9-11.15.1.2318-1.8.9' runDir = 'run' mappings = 'stable_22' +// clientRunArgs.addAll( +// arrayOf( +// "--mixin mixins.skytils.json" +// ) +// ) } repositories { @@ -38,11 +47,17 @@ repositories { flatDir { dirs 'deps' } + mavenCentral() } dependencies { compile('org.spongepowered:mixin:0.7.11-SNAPSHOT') annotationProcessor('org.spongepowered:mixin:0.7.11-SNAPSHOT') + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" +} + +compileJava { + [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' } mixin { @@ -101,4 +116,14 @@ task moveResources { } } moveResources.dependsOn processResources -classes.dependsOn moveResources \ No newline at end of file +classes.dependsOn moveResources +compileKotlin { + kotlinOptions { + jvmTarget = "1.8" + } +} +compileTestKotlin { + kotlinOptions { + jvmTarget = "1.8" + } +} \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/GuiContainerHook.kt b/src/main/java/at/lorenz/mod/GuiContainerHook.kt new file mode 100644 index 000000000..55b30e964 --- /dev/null +++ b/src/main/java/at/lorenz/mod/GuiContainerHook.kt @@ -0,0 +1,61 @@ +package at.lorenz.mod + +import at.lorenz.mod.events.GuiContainerEvent +import at.lorenz.mod.events.GuiContainerEvent.CloseWindowEvent +import at.lorenz.mod.events.GuiContainerEvent.SlotClickEvent +import net.minecraft.client.gui.inventory.GuiContainer +import net.minecraft.inventory.Slot +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo + +class GuiContainerHook(guiAny: Any) { + + val gui: GuiContainer + + init { + gui = guiAny as GuiContainer + } + + fun closeWindowPressed(ci: CallbackInfo) { + if (CloseWindowEvent(gui, gui.inventorySlots).postAndCatch()) ci.cancel() + } + + fun backgroundDrawn(mouseX: Int, mouseY: Int, partialTicks: Float, ci: CallbackInfo) { + GuiContainerEvent.BackgroundDrawnEvent( + gui, + gui.inventorySlots, + mouseX, + mouseY, + partialTicks + ).postAndCatch() + } + + fun foregroundDrawn(mouseX: Int, mouseY: Int, partialTicks: Float, ci: CallbackInfo) { + GuiContainerEvent.ForegroundDrawnEvent(gui, gui.inventorySlots, mouseX, mouseY, partialTicks).postAndCatch() + } + + fun onDrawSlot(slot: Slot, ci: CallbackInfo) { + if (GuiContainerEvent.DrawSlotEvent.Pre( + gui, + gui.inventorySlots, + slot + ).postAndCatch() + ) ci.cancel() + } + + fun onDrawSlotPost(slot: Slot, ci: CallbackInfo) { + GuiContainerEvent.DrawSlotEvent.Post(gui, gui.inventorySlots, slot).postAndCatch() + } + + fun onMouseClick(slot: Slot?, slotId: Int, clickedButton: Int, clickType: Int, ci: CallbackInfo) { + if ( + SlotClickEvent( + gui, + gui.inventorySlots, + slot, + slotId, + clickedButton, + clickType + ).postAndCatch() + ) ci.cancel() + } +} \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/HideNotClickableItems.kt b/src/main/java/at/lorenz/mod/HideNotClickableItems.kt new file mode 100644 index 000000000..3f94a1479 --- /dev/null +++ b/src/main/java/at/lorenz/mod/HideNotClickableItems.kt @@ -0,0 +1,444 @@ +package at.lorenz.mod + +import at.lorenz.mod.bazaar.BazaarApi +import at.lorenz.mod.config.LorenzConfig +import at.lorenz.mod.utils.LorenzUtils.Companion.removeColorCodes +import at.lorenz.mod.events.GuiContainerEvent +import at.lorenz.mod.utils.ItemUtils +import at.lorenz.mod.utils.ItemUtils.Companion.cleanName +import at.lorenz.mod.utils.ItemUtils.Companion.getLore +import at.lorenz.mod.utils.LorenzColor +import at.lorenz.mod.utils.LorenzUtils +import at.lorenz.mod.utils.RenderUtil.Companion.highlight +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.inventory.GuiChest +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.inventory.ContainerChest +import net.minecraft.item.ItemStack +import net.minecraftforge.event.entity.player.ItemTooltipEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.lwjgl.opengl.GL11 + +class HideNotClickableItems { + + private var hideReason = "" + + private var lastClickTime = 0L + private var bypassUntil = 0L + + @SubscribeEvent + fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { + if (isDisabled()) return + if (event.gui !is GuiChest) return + val guiChest = event.gui + val chest = guiChest.inventorySlots as ContainerChest + val chestName = chest.lowerChestInventory.displayName.unformattedText.trim() + + val lightingState = GL11.glIsEnabled(GL11.GL_LIGHTING) + GlStateManager.disableLighting() + GlStateManager.color(1f, 1f, 1f, 1f) + + for (slot in chest.inventorySlots) { + if (slot == null) continue + + if (slot.slotNumber == slot.slotIndex) continue + if (slot.stack == null) continue + + if (hide(chestName, slot.stack)) { + slot highlight LorenzColor.GRAY + } + } + + if (lightingState) GlStateManager.enableLighting() + } + + @SubscribeEvent + fun onDrawSlot(event: GuiContainerEvent.DrawSlotEvent.Pre) { + if (isDisabled()) return + if (event.gui !is GuiChest) return + val guiChest = event.gui + val chest = guiChest.inventorySlots as ContainerChest + val chestName = chest.lowerChestInventory.displayName.unformattedText.trim() + + val slot = event.slot + if (slot.slotNumber == slot.slotIndex) return + if (slot.stack == null) return + + val stack = slot.stack + + if (hide(chestName, stack)) { + event.isCanceled = true + } + } + + @SubscribeEvent + fun onTooltip(event: ItemTooltipEvent) { + if (isDisabled()) return + if (event.toolTip == null) return + val guiChest = Minecraft.getMinecraft().currentScreen + if (guiChest !is GuiChest) return + val chest = guiChest.inventorySlots as ContainerChest + val chestName = chest.lowerChestInventory.displayName.unformattedText.trim() + + val stack = event.itemStack + if (ItemUtils.getItemsInOpenChest().contains(stack)) return + + if (hide(chestName, stack)) { + val first = event.toolTip[0] + event.toolTip.clear() + event.toolTip.add("§7" + first.removeColorCodes()) + event.toolTip.add("") + if (hideReason == "") { + event.toolTip.add("§4No hide reason!") + LorenzUtils.warning("Not hide reason for not clickable item!") + } else { + event.toolTip.add("§c$hideReason") + } + } + } + + @SubscribeEvent + fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { + if (isDisabled()) return + if (event.gui !is GuiChest) return + val guiChest = event.gui + val chest = guiChest.inventorySlots as ContainerChest + val chestName = chest.lowerChestInventory.displayName.unformattedText.trim() + + val slot = event.slot ?: return + + if (slot.slotNumber == slot.slotIndex) return + if (slot.stack == null) return + + val stack = slot.stack + + if (hide(chestName, stack)) { + event.isCanceled = true +// SoundQueue.addToQueue("note.bass", 0.5f, 1f) + + if (System.currentTimeMillis() > lastClickTime + 5_000) { + lastClickTime = System.currentTimeMillis() +// EssentialAPI.getNotifications() +// .push( +// "§cThis item cannot be moved!", +// "§eClick here §fto disable this feature for 10 seconds!\n" + +// "§fOr disable it forever: §6/st §f+ '§6Hide Not Clickable Items§f'.", +// 5f, +// action = { +// bypassUntil = System.currentTimeMillis() + 10_000 +// }) + } + return + } + } + + private fun isDisabled(): Boolean { + if (bypassUntil > System.currentTimeMillis()) return true + + return !LorenzConfig.hideNotClickableItems + } + + private fun hide(chestName: String, stack: ItemStack): Boolean { + hideReason = "" + return when { + hideNpcSell(chestName, stack) -> true + hideChestBackpack(chestName, stack) -> true + hideSalvage(chestName, stack) -> true + hideTrade(chestName, stack) -> true + hideBazaarOrAH(chestName, stack) -> true + hideAccessoryBag(chestName, stack) -> true + hideSackOfSacks(chestName, stack) -> true + hideFishingBag(chestName, stack) -> true + hidePotionBag(chestName, stack) -> true + + else -> false + } + } + + private fun hidePotionBag(chestName: String, stack: ItemStack): Boolean { + if (!chestName.startsWith("Potion Bag")) return false + + val name = stack.cleanName() + if (isSkyBlockMenuItem(name)) { + hideReason = "The SkyBlock Menu cannot be put into the potion bag!" + return true + } + + if (stack.cleanName().endsWith(" Potion")) return false + + hideReason = "This item is not a potion!" + return true + } + + private fun hideFishingBag(chestName: String, stack: ItemStack): Boolean { + if (!chestName.startsWith("Fishing Bag")) return false + + val name = stack.cleanName() + if (isSkyBlockMenuItem(name)) { + hideReason = "The SkyBlock Menu cannot be put into the fishing bag!" + return true + } + + if (stack.cleanName().endsWith(" Bait")) return false + + hideReason = "This item is not a fishing bait!" + return true + } + + private fun hideSackOfSacks(chestName: String, stack: ItemStack): Boolean { + if (!chestName.startsWith("Sack of Sacks")) return false + + val name = stack.cleanName() + if (ItemUtils.isSack(name)) return false + if (isSkyBlockMenuItem(name)) return false + + hideReason = "This item is not a sack!" + return true + } + + private fun hideAccessoryBag(chestName: String, stack: ItemStack): Boolean { + if (!chestName.startsWith("Accessory Bag")) return false + + if (stack.getLore().any { it.contains("ACCESSORY") }) return false + if (isSkyBlockMenuItem(stack.cleanName())) return false + + hideReason = "This item is not an accessory!" + return true + } + + private fun hideTrade(chestName: String, stack: ItemStack): Boolean { + if (!chestName.startsWith("You ")) return false + + if (ItemUtils.isCoOpSoulBound(stack)) { + hideReason = "Coop-Soulbound items cannot be traded!" + return true + } + + val name = stack.cleanName() + + if (ItemUtils.isSack(name)) { + hideReason = "Sacks cannot be traded!" + return true + } + + if (isSkyBlockMenuItem(name)) { + hideReason = "The SkyBlock Menu cannot be traded!" + return true + } + + val result = when { + name.contains("Personal Deletor") -> true + name.contains("Day Crystal") -> true + name.contains("Night Crystal") -> true + name.contains("Cat Talisman") -> true + name.contains("Lynx Talisman") -> true + name.contains("Cheetah Talisman") -> true + else -> false + } + + if (result) hideReason = "This item cannot be traded!" + return result + } + + private fun hideNpcSell(chestName: String, stack: ItemStack): Boolean { + if (chestName != "Trades" && chestName != "Ophelia") return false + + var name = stack.cleanName() + val size = stack.stackSize + val amountText = " x$size" + if (name.endsWith(amountText)) { + name = name.substring(0, name.length - amountText.length) + } + + if (isSkyBlockMenuItem(name)) { + hideReason = "The SkyBlock Menu cannot be sold at the NPC!" + return true + } + + if (!ItemUtils.isRecombobulated(stack)) { + when (name) { + "Health Potion VIII Splash Potion" -> return false + "Stone Button" -> return false + "Revive Stone" -> return false + "Premium Flesh" -> return false + "Defuse Kit" -> return false + "White Wool" -> return false + "Enchanted Wool" -> return false + "Training Weights" -> return false + "Journal Entry" -> return false + + "Fairy's Galoshes" -> return false + } + + if (name.startsWith("Music Disc")) return false + } + + hideReason = "This item should not be sold at the NPC!" + return true + } + + private fun hideChestBackpack(chestName: String, stack: ItemStack): Boolean { + if (!chestName.contains("Ender Chest") && !chestName.contains("Backpack")) return false + + val name = stack.cleanName() + + if (isSkyBlockMenuItem(name)) { + hideReason = "The SkyBlock Menu cannot be put into the storage!" + return true + } + if (ItemUtils.isSack(name)) { + hideReason = "Sacks cannot be put into the storage!" + return true + } + + val result = when { + name.endsWith(" New Year Cake Bag") -> true + name == "Nether Wart Pouch" -> true + name == "Basket of Seeds" -> true + name == "Builder's Wand" -> true + + else -> false + } + + if (result) hideReason = "Bags cannot be put into the storage!" + return result + } + + private fun hideSalvage(chestName: String, stack: ItemStack): Boolean { + if (chestName != "Salvage Item") return false + + val name = stack.cleanName() + + val armorSets = listOf( + "Zombie Knight", + "Heavy", + "Zombie Soldier", + "Skeleton Grunt", + "Skeleton Soldier", + "Zombie Commander", + "Skeleton Master", + "Sniper", + "Skeletor", + "Rotten", + ) + + val items = mutableListOf() + for (armor in armorSets) { + items.add("$armor Helmet") + items.add("$armor Chestplate") + items.add("$armor Leggings") + items.add("$armor Boots") + } + + items.add("Zombie Soldier Cutlass") + items.add("Silent Death") + items.add("Zombie Knight Sword") + items.add("Conjuring") + items.add("Dreadlord Sword") + items.add("Soulstealer Bow") + items.add("Machine Gun Bow") + items.add("Earth Shard") + items.add("Zombie Commander Whip") + + for (item in items) { + if (name.endsWith(" $item")) { + + if (ItemUtils.isRecombobulated(stack)) { + hideReason = "This item should not be salvaged! (Recombobulated)" + return true + } +// val rarity = stack.getSkyBlockRarity() +// if (rarity == ItemRarity.LEGENDARY || rarity == ItemRarity.MYTHIC) { +// hideReason = "This item should not be salvaged! (Rarity)" +// return true +// } + + return false + } + } + + if (isSkyBlockMenuItem(name)) { + hideReason = "The SkyBlock Menu cannot be salvaged!" + return true + } + + hideReason = "This item cannot be salvaged!" + return true + } + + private fun hideBazaarOrAH(chestName: String, stack: ItemStack): Boolean { + val bazaarInventory = BazaarApi.isBazaarInventory(chestName) + + val auctionHouseInventory = + chestName == "Co-op Auction House" || chestName == "Auction House" || chestName == "Create BIN Auction" || chestName == "Create Auction" + if (!bazaarInventory && !auctionHouseInventory) return false + + + val displayName = stack.displayName + + if (isSkyBlockMenuItem(displayName.removeColorCodes())) { + if (bazaarInventory) hideReason = "The SkyBlock Menu is not a Bazaar Product!" + if (auctionHouseInventory) hideReason = "The SkyBlock Menu cannot be auctioned!" + return true + } + + if (bazaarInventory != BazaarApi.isBazaarItem(displayName)) { + if (bazaarInventory) hideReason = "This item is not a Bazaar Product!" + if (auctionHouseInventory) hideReason = "Bazaar Products cannot be auctioned!" + + return true + } + + if (isNotAuctionable(stack)) return true + + return false + } + + private fun isNotAuctionable(stack: ItemStack): Boolean { + if (ItemUtils.isCoOpSoulBound(stack)) { + hideReason = "Coop-Soulbound items cannot be auctioned!" + return true + } + + val name = stack.cleanName() + + if (ItemUtils.isSack(name)) { + hideReason = "Sacks cannot be auctioned!" + return true + } + + val result = when { + name.contains("Personal Deletor") -> true + name.contains("Day Crystal") -> true + name.contains("Night Crystal") -> true + + name.contains("Cat Talisman") -> true + name.contains("Lynx Talisman") -> true + name.contains("Cheetah Talisman") -> true + + name.contains("Hoe of Great Tilling") -> true + name.contains("Hoe of Greater Tilling") -> true + name.contains("InfiniDirt") -> true + name.contains("Prismapump") -> true + name.contains("Mathematical Hoe Blueprint") -> true + name.contains("Basket of Seeds") -> true + name.contains("Nether Wart Pouch") -> true + + name.contains("Carrot Hoe") -> true + name.contains("Sugar Cane Hoe") -> true + name.contains("Nether Warts Hoe") -> true + name.contains("Potato Hoe") -> true + name.contains("Melon Dicer") -> true + name.contains("Pumpkin Dicer") -> true + name.contains("Coco Chopper") -> true + name.contains("Wheat Hoe") -> true + + else -> false + } + + if (result) hideReason = "This item cannot be auctioned!" + return result + } + + private fun isSkyBlockMenuItem(name: String): Boolean = name == "SkyBlock Menu (Right Click)" +} diff --git a/src/main/java/at/lorenz/mod/bazaar/BazaarApi.kt b/src/main/java/at/lorenz/mod/bazaar/BazaarApi.kt new file mode 100644 index 000000000..28ce228e2 --- /dev/null +++ b/src/main/java/at/lorenz/mod/bazaar/BazaarApi.kt @@ -0,0 +1,59 @@ +package at.lorenz.mod.bazaar + +import at.lorenz.mod.utils.LorenzUtils + +class BazaarApi { + + companion object { + private val bazaarMap = mutableMapOf() + + fun isBazaarInventory(inventoryName: String): Boolean { + if (inventoryName.contains(" ➜ ") && !inventoryName.contains("Museum")) return true + if (BazaarOrderHelper.isBazaarOrderInventory(inventoryName)) return true + + return when (inventoryName) { + "Your Bazaar Orders" -> true + "How many do you want?" -> true + "How much do you want to pay?" -> true + "Confirm Buy Order" -> true + "Confirm Instant Buy" -> true + "At what price are you selling?" -> true + "Confirm Sell Offer" -> true + "Order options" -> true + + else -> false + } + } + + fun getCleanBazaarName(name: String): String { + if (name.endsWith(" Gemstone")) { + return name.substring(6) + } + if (name.startsWith("§")) { + return name.substring(2) + } + + return name + } + + fun getBazaarDataForName(name: String): BazaarData { + if (bazaarMap.containsKey(name)) { + val bazaarData = bazaarMap[name] + if (bazaarData != null) { + return bazaarData + } + LorenzUtils.error("Bazaar data is null for item '$name'") + } + throw Error("no bz data found for name '$name'") + } + + fun isBazaarItem(name: String): Boolean { + val bazaarName = getCleanBazaarName(name) + return bazaarMap.containsKey(bazaarName) + } + } + + init { + BazaarDataGrabber(bazaarMap).start() + } +} \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/bazaar/BazaarData.kt b/src/main/java/at/lorenz/mod/bazaar/BazaarData.kt new file mode 100644 index 000000000..a9f75370c --- /dev/null +++ b/src/main/java/at/lorenz/mod/bazaar/BazaarData.kt @@ -0,0 +1,3 @@ +package at.lorenz.mod.bazaar + +data class BazaarData(val apiName: String, val itemName: String, val sellPrice: Double, val buyPrice: Double) \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/bazaar/BazaarDataGrabber.kt b/src/main/java/at/lorenz/mod/bazaar/BazaarDataGrabber.kt new file mode 100644 index 000000000..78341e05c --- /dev/null +++ b/src/main/java/at/lorenz/mod/bazaar/BazaarDataGrabber.kt @@ -0,0 +1,116 @@ +package at.lorenz.mod.bazaar + +import at.lorenz.mod.utils.APIUtil +import at.lorenz.mod.utils.LorenzUtils +import at.lorenz.mod.utils.LorenzUtils.Companion.round +import kotlin.concurrent.fixedRateTimer + +internal class BazaarDataGrabber(private var bazaarMap: MutableMap) { + + companion object { + private val itemNames = mutableMapOf() + + private var lastData = "" + var lastTime = 0L + var blockNoChange = false + var currentlyUpdating = false + } + + private fun loadItemNames(): Boolean { + currentlyUpdating = true + try { + val itemsData = APIUtil.getJSONResponse("https://api.hypixel.net/resources/skyblock/items") + for (element in itemsData["items"].asJsonArray) { + val jsonObject = element.asJsonObject + val name = jsonObject["name"].asString + val id = jsonObject["id"].asString + itemNames[id] = name + } + currentlyUpdating = false + return true + } catch (e: Throwable) { + e.printStackTrace() + LorenzUtils.error("Error while trying to read bazaar item list from api: " + e.message) + currentlyUpdating = false + return false + } + } + + fun start() { + fixedRateTimer(name = "lorenz-bazaar-update", period = 1000L) { + //TODO add +// if (!LorenzUtils.inSkyBlock) { +// return@fixedRateTimer +// } + + if (currentlyUpdating) { + LorenzUtils.error("Bazaar update took too long! Error?") + return@fixedRateTimer + } + + if (itemNames.isEmpty()) { + if (!loadItemNames()) { + return@fixedRateTimer + } + } + checkIfUpdateNeeded() + } + } + + private fun checkIfUpdateNeeded() { + if (lastData != "") { + if (System.currentTimeMillis() - lastTime > 9_000) { + blockNoChange = true + } else { + if (blockNoChange) { + return + } + } + } + + currentlyUpdating = true + updateBazaarData() + currentlyUpdating = false + } + + private fun updateBazaarData() { + val bazaarData = APIUtil.getJSONResponse("https://api.hypixel.net/skyblock/bazaar") + if (bazaarData.toString() != lastData) { + lastData = bazaarData.toString() + lastTime = System.currentTimeMillis() + } + + val products = bazaarData["products"].asJsonObject + + for (entry in products.entrySet()) { + val apiName = entry.key + + if (apiName == "ENCHANTED_CARROT_ON_A_STICK") continue + if (apiName == "BAZAAR_COOKIE") continue + + val itemData = entry.value.asJsonObject + + val itemName = itemNames.getOrDefault(apiName, null) + if (itemName == null) { + LorenzUtils.error("Bazaar item name is null for '$apiName'! Restart to fix this problem!") + continue + } + + val sellPrice: Double = try { + itemData["sell_summary"].asJsonArray[0].asJsonObject["pricePerUnit"].asDouble.round(1) + } catch (e: Exception) { +// LorenzUtils.warning("Bazaar buy order for $itemName not found!") + 0.0 + } + val buyPrice: Double = try { + itemData["buy_summary"].asJsonArray[0].asJsonObject["pricePerUnit"].asDouble.round(1) + } catch (e: Exception) { +// LorenzUtils.warning("Bazaar sell offers for $itemName not found!") + 0.0 + } + + val data = BazaarData(apiName, itemName, sellPrice, buyPrice) + bazaarMap[itemName] = data + } + } +} \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/bazaar/BazaarOrderHelper.kt b/src/main/java/at/lorenz/mod/bazaar/BazaarOrderHelper.kt new file mode 100644 index 000000000..0daa12b7d --- /dev/null +++ b/src/main/java/at/lorenz/mod/bazaar/BazaarOrderHelper.kt @@ -0,0 +1,87 @@ +package at.lorenz.mod.bazaar + +import at.lorenz.mod.config.LorenzConfig +import at.lorenz.mod.events.GuiContainerEvent +import at.lorenz.mod.utils.ItemUtils.Companion.getLore +import at.lorenz.mod.utils.LorenzColor +import at.lorenz.mod.utils.RenderUtil.Companion.highlight +import net.minecraft.client.gui.inventory.GuiChest +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.inventory.ContainerChest +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.lwjgl.opengl.GL11 + +class BazaarOrderHelper { + + companion object { + fun isBazaarOrderInventory(inventoryName: String): Boolean = when (inventoryName) { + "Your Bazaar Orders" -> true + "Co-op Bazaar Orders" -> true + else -> false + } + } + + @SubscribeEvent + fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { + if (!LorenzConfig.lorenzBazaarOrderHelper) return + if (event.gui !is GuiChest) return + val guiChest = event.gui + val chest = guiChest.inventorySlots as ContainerChest + val inventoryName = chest.lowerChestInventory.displayName.unformattedText.trim() + + if (!isBazaarOrderInventory(inventoryName)) return + val lightingState = GL11.glIsEnabled(GL11.GL_LIGHTING) + GlStateManager.disableLighting() + GlStateManager.color(1f, 1f, 1f, 1f) + + out@ for (slot in chest.inventorySlots) { + if (slot == null) continue + if (slot.slotNumber != slot.slotIndex) continue + if (slot.stack == null) continue + + val stack = slot.stack + val displayName = stack.displayName + val isSelling = displayName.startsWith("§6§lSELL§7: ") + val isBuying = displayName.startsWith("§a§lBUY§7: ") + if (!isSelling && !isBuying) continue + + val text = displayName.split("§7: ")[1] + val name = BazaarApi.getCleanBazaarName(text) + val data = BazaarApi.getBazaarDataForName(name) + val buyPrice = data.buyPrice + val sellPrice = data.sellPrice + + val itemLore = stack.getLore() + for (line in itemLore) { + if (line.startsWith("§7Filled:")) { + if (line.endsWith(" §a§l100%!")) { + slot highlight LorenzColor.GREEN + continue@out + } + } + } + for (line in itemLore) { + if (line.startsWith("§7Price per unit:")) { + var text = line.split(": §6")[1] + text = text.substring(0, text.length - 6) + text = text.replace(",", "") + val price = text.toDouble() + if (isSelling) { + if (buyPrice < price) { + slot highlight LorenzColor.GOLD + continue@out + } + } else { + if (sellPrice > price) { + slot highlight LorenzColor.GOLD + continue@out + } + } + + } + } + } + + if (lightingState) GlStateManager.enableLighting() + } +} diff --git a/src/main/java/at/lorenz/mod/chat/ChatFilter.kt b/src/main/java/at/lorenz/mod/chat/ChatFilter.kt new file mode 100644 index 000000000..8e2160928 --- /dev/null +++ b/src/main/java/at/lorenz/mod/chat/ChatFilter.kt @@ -0,0 +1,279 @@ +package at.lorenz.mod.chat + +import at.lorenz.mod.config.LorenzConfig +import at.lorenz.mod.utils.LorenzUtils +import at.lorenz.mod.utils.LorenzUtils.Companion.matchRegex +import at.lorenz.mod.events.LorenzChatEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class ChatFilter { + + @SubscribeEvent + fun onChatMessage(event: LorenzChatEvent) { + if (!LorenzConfig.chatFilter) return + + val blockReason = block(event.message) + if (blockReason != "") { + event.blockedReason = blockReason + } + } + + private fun block(message: String): String = when { + message.startsWith("§aYou are playing on profile: §e") -> "profile"//TODO move into own class + lobby(message) -> "lobby" + empty(message) -> "empty" + warping(message) -> "warping" + welcome(message) -> "welcome" + guild(message) -> "guild" + PlayerChatFilter.shouldBlock(message) -> "player_chat" + killCombo(message) -> "kill_combo" + bazaarAndAHMiniMessages(message) -> "bz_ah_minis" + watchdogAnnouncement(message) -> "watchdog" + slayer(message) -> "slayer" + slayerDrop(message) -> "slayer_drop" + uselessDrop(message) -> "useless_drop" + uselessNotification(message) -> "useless_notification" + party(message) -> "party" + money(message) -> "money" + winterIsland(message) -> "winter_island" + uselessWarning(message) -> "useless_warning" + friendJoin(message) -> "friend_join" + + + else -> "" + } + + private fun friendJoin(message: String): Boolean { + return when { + message.matchRegex("§aFriend > §r(.*) §r§e(joined|left).") -> { + true + } + else -> false + } + + } + + private fun uselessNotification(message: String): Boolean { + return when { + message == "§eYour previous §r§6Plasmaflux Power Orb §r§ewas removed!" -> true + + else -> false + } + } + + private fun uselessWarning(message: String): Boolean = when { + message == "§cYou are sending commands too fast! Please slow down." -> true//TODO prevent in the future + message == "§cYou can't use this while in combat!" -> true + message == "§cYou can not modify your equipped armor set!" -> true + message == "§cPlease wait a few seconds between refreshing!" -> true + message == "§cThis item is not salvageable!" -> true//prevent in the future + message == "§cPlace a Dungeon weapon or armor piece above the anvil to salvage it!" -> true + message == "§cWhoa! Slow down there!" -> true + message == "§cWait a moment before confirming!" -> true + message == "§cYou need to be out of combat for 3 seconds before opening the SkyBlock Menu!" -> true//TODO prevent in the future + + else -> false + } + + private fun uselessDrop(message: String): Boolean { + when { + message.matchRegex("§6§lRARE DROP! §r§aEnchanted Ender Pearl (.*)") -> return true + + message.matchRegex("§6§lRARE DROP! §r§fCarrot (.*)") -> return true + message.matchRegex("§6§lRARE DROP! §r§fPotato (.*)") -> return true + + message.matchRegex("§6§lRARE DROP! §r§9Machine Gun Bow (.*)") -> return true + message.matchRegex("§6§lRARE DROP! §r§5Earth Shard (.*)") -> return true + message.matchRegex("§6§lRARE DROP! §r§5Zombie Lord Chestplate (.*)") -> return true + } + + return false + } + + private fun winterIsland(message: String): Boolean = when { + message.matchRegex(" §r§f☃ §r§7§r(.*) §r§7mounted a §r§fSnow Cannon§r§7!") -> true + + else -> false + } + + private fun money(message: String): Boolean { + if (isBazaar(message)) return true + if (isAuctionHouse(message)) return true + + return false + } + + private fun isAuctionHouse(message: String): Boolean { + if (message == "§b-----------------------------------------------------") return true + if (message == "§eVisit the Auction House to collect your item!") return true + + return false + } + + private fun isBazaar(message: String): Boolean { + if (message.matchRegex("§eBuy Order Setup! §r§a(.*)§r§7x (.*) §r§7for §r§6(.*) coins§r§7.")) return true + if (message.matchRegex("§eSell Offer Setup! §r§a(.*)§r§7x (.*) §r§7for §r§6(.*) coins§r§7.")) return true + if (message.matchRegex("§cCancelled! §r§7Refunded §r§6(.*) coins §r§7from cancelling buy order!")) return true + if (message.matchRegex("§cCancelled! §r§7Refunded §r§a(.*)§r§7x (.*) §r§7from cancelling sell offer!")) return true + + return false + } + + private fun party(message: String): Boolean { + if (message == "§9§m-----------------------------") return true + if (message == "§9§m-----------------------------------------------------") return true + + return false + } + + private fun slayerDrop(message: String): Boolean { + //Revenant + if (message.matchRegex("§b§lRARE DROP! §r§7\\(§r§f§r§9Revenant Viscera§r§7\\) (.*)")) return true + if (message.matchRegex("§b§lRARE DROP! §r§7\\(§r§f§r§7(.*)x §r§f§r§9Foul Flesh§r§7\\) (.*)")) return true + if (message.matchRegex("§b§lRARE DROP! §r§7\\(§r§f§r§9Foul Flesh§r§7\\) (.*)")) return true + if (message.matchRegex("§6§lRARE DROP! §r§5Golden Powder (.*)")) return true + if (message.matchRegex("§9§lVERY RARE DROP! §r§7\\(§r§f§r§2(.*) Pestilence Rune I§r§7\\) (.*)")) { + LorenzUtils.debug("check regex for this blocked message!") + return true + } + if (message.matchRegex("§5§lVERY RARE DROP! §r§7\\(§r§f§r§5Revenant Catalyst§r§7\\) (.*)")) return true + if (message.matchRegex("§5§lVERY RARE DROP! §r§7\\(§r§f§r§9Undead Catalyst§r§7\\) (.*)")) return true + + //Enderman + if (message.matchRegex("§b§lRARE DROP! §r§7\\(§r§f§r§7(.*)x §r§f§r§aTwilight Arrow Poison§r§7\\) (.*)")) return true + if (message.matchRegex("§9§lVERY RARE DROP! §r§7\\(§r§fMana Steal I§r§7\\) (.*)")) return true + if (message.matchRegex("§5§lVERY RARE DROP! §r§7\\(§r§f§r§5Sinful Dice§r§7\\) (.*)")) return true + if (message.matchRegex("§9§lVERY RARE DROP! §r§7\\(§r§f§r§9Null Atom§r§7\\) (.*)")) return true + if (message.matchRegex("§9§lVERY RARE DROP! §r§7\\(§r§f§r§5Transmission Tuner§r§7\\) (.*)")) return true + if (message.matchRegex("§9§lVERY RARE DROP! §r§7\\(§r§fMana Steal I§r§7\\) (.*)")) return true + if (message.matchRegex("§9§lVERY RARE DROP! §r§7\\(§r§f§r§5◆ Endersnake Rune I§r§7\\) (.*)")) return true + if (message.matchRegex("§d§lCRAZY RARE DROP! §r§7\\(§r§f§r§fPocket Espresso Machine§r§7\\) (.*)")) return true + if (message.matchRegex("§5§lVERY RARE DROP! §r§7\\(§r§f§r§5◆ End Rune I§r§7\\) (.*)")) return true + + return false + } + + private fun slayer(message: String): Boolean { + //start + if (message.matchRegex(" §r§5§lSLAYER QUEST STARTED!")) return true + if (message.matchRegex(" §5§l» §7Slay §c(.*) Combat XP §7worth of (.*)§7.")) return true + + //end + if (message.matchRegex(" §r§a§lSLAYER QUEST COMPLETE!")) return true + if (message == " §r§6§lNICE! SLAYER BOSS SLAIN!") return true + if (message.matchRegex(" §r§e(.*)Slayer LVL 9 §r§5- §r§a§lLVL MAXED OUT!")) return true + if (message.matchRegex(" §r§5§l» §r§7Talk to Maddox to claim your (.*) Slayer XP!")) return true + + + if (message == "§eYou received kill credit for assisting on a slayer miniboss!") return true + + if (message == "§e✆ Ring... ") return true + if (message == "§e✆ Ring... Ring... ") return true + if (message == "§e✆ Ring... Ring... Ring... ") return true + + return false + } + + private fun watchdogAnnouncement(message: String): Boolean = when { + message == "§4[WATCHDOG ANNOUNCEMENT]" -> true + message.matchRegex("§fWatchdog has banned §r§c§l(.*)§r§f players in the last 7 days.") -> true + message.matchRegex("§fStaff have banned an additional §r§c§l(.*)§r§f in the last 7 days.") -> true + message == "§cBlacklisted modifications are a bannable offense!" -> true + else -> false + } + + private fun bazaarAndAHMiniMessages(message: String): Boolean = when (message) { + "§7Putting item in escrow...", + "§7Putting goods in escrow...", + "§7Putting coins in escrow...", + + //Auction House + "§7Setting up the auction...", + "§7Processing purchase...", + "§7Claiming order...", + "§7Processing bid...", + "§7Claiming BIN auction...", + + //Bazaar + "§7Submitting sell offer...", + "§7Submitting buy order...", + "§7Executing instant sell...", + "§7Executing instant buy...", + + //Bank + "§8Depositing coins...", + "§8Withdrawing coins..." -> true + else -> false + } + + private fun killCombo(message: String): Boolean { + //§a§l+5 Kill Combo §r§8+§r§b3% §r§b? Magic Find + return when { + message.matchRegex("§.§l\\+(.*) Kill Combo §r§8\\+(.*)") -> true + message.matchRegex("§cYour Kill Combo has expired! You reached a (.*) Kill Combo!") -> true + else -> false + } + } + + private fun lobby(message: String): Boolean = when { + //player join + message.matchRegex("(.*) §6joined the lobby!") -> true + message.matchRegex(" §b>§c>§a>§r (.*) §6joined the lobby!§r §a<§c<§b<") -> true + + //mystery box + message.matchRegex("§b✦ §r(.*) §r§7found a §r§e(.*) §r§bMystery Box§r§7!") -> true + message.matchRegex("§b✦ §r(.*) §r§7found (a|an) §r(.*) §r§7in a §r§aMystery Box§r§7!") -> true + + //prototype + message.contains("§r§6§lWelcome to the Prototype Lobby§r") -> true + message == " §r§f§l➤ §r§6You have reached your Hype limit! Add Hype to Prototype Lobby minigames by right-clicking with the Hype Diamond!" -> true + + //hypixel tournament notifications + message.contains("§r§e§6§lHYPIXEL§e is hosting a §b§lBED WARS DOUBLES§e tournament!") -> true + message.contains("§r§e§6§lHYPIXEL BED WARS DOUBLES§e tournament is live!") -> true + + //other + message.contains("§aYou are still radiating with §bGenerosity§r§a!") -> true + else -> false + } + + private fun guild(message: String): Boolean = when { + message.matchRegex("§2Guild > (.*) §r§e(joined|left).") -> true + message.matchRegex("§aYou earned §r§2(.*) GEXP §r§afrom playing SkyBlock!") -> true + message.matchRegex("§aYou earned §r§2(.*) GEXP §r§a\\+ §r§e(.*) Event EXP §r§afrom playing SkyBlock!") -> true + message == "§b§m-----------------------------------------------------" -> true + else -> false + } + + private fun welcome(message: String): Boolean = message == "§eWelcome to §r§aHypixel SkyBlock§r§e!" + + private fun warping(message: String): Boolean = when { + message.matchRegex("§7Sending to server (.*)\\.\\.\\.") -> true + message.matchRegex("§7Request join for Hub (.*)\\.\\.\\.") -> true + message.matchRegex("§7Request join for Dungeon Hub #(.*)\\.\\.\\.") -> true + message == "§7Warping..." -> true + message == "§7Warping you to your SkyBlock island..." -> true + message == "§7Warping using transfer token..." -> true + + //visiting other players + message == "§7Finding player..." -> true + message == "§7Sending a visit request..." -> true + + //warp portals on public islands (canvas room - flower house, election room - community center, void sepulture - the end) + message.matchRegex("§dWarped to (.*)§r§d!") -> true + else -> false + } + + private fun empty(message: String): Boolean = when (message) { + "§8 §r§8 §r§1 §r§3 §r§3 §r§7 §r§8 ", + + "§f §r§f §r§1 §r§0 §r§2 §r§4§r§f §r§f §r§2 §r§0 §r§4 §r§8§r§0§r§1§r§0§r§1§r§2§r§f§r§f§r§0§r§1§r§3§r§4§r§f§r§f§r§0§r§1§r§5§r§f§r§f§r§0§r§1§r§6§r§f§r§f§r§0§r§1§r§8§r§9§r§a§r§b§r§f§r§f§r§0§r§1§r§7§r§f§r§f§r§3 §r§9 §r§2 §r§0 §r§0 §r§1§r§3 §r§9 §r§2 §r§0 §r§0 §r§2§r§3 §r§9 §r§2 §r§0 §r§0 §r§3§r§0§r§0§r§1§r§f§r§e§r§0§r§0§r§2§r§f§r§e§r§0§r§0§r§3§r§4§r§5§r§6§r§7§r§8§r§f§r§e§r§3 §r§6 §r§3 §r§6 §r§3 §r§6 §r§e§r§3 §r§6 §r§3 §r§6 §r§3 §r§6 §r§d", + + "§f §r§r§r§f §r§r§r§1 §r§r§r§0 §r§r§r§2 §r§r§r§f §r§r§r§f §r§r§r§2 §r§r§r§0 §r§r§r§4 §r§r§r§3 §r§r§r§9 §r§r§r§2 §r§r§r§0 §r§r§r§0 §r§r§r§3 §r§r§r§9 §r§r§r§2 §r§r§r§0 §r§r§r§0 §r§r§r§3 §r§r§r§9 §r§r§r§2 §r§r§r§0 §r§r§r§0 ", + + "", + "§f", + "§c" -> true + else -> false + } +} diff --git a/src/main/java/at/lorenz/mod/chat/ChatManager.kt b/src/main/java/at/lorenz/mod/chat/ChatManager.kt new file mode 100644 index 000000000..a85643e1b --- /dev/null +++ b/src/main/java/at/lorenz/mod/chat/ChatManager.kt @@ -0,0 +1,47 @@ +package at.lorenz.mod.chat + +import at.lorenz.mod.utils.LorenzLogger +import at.lorenz.mod.events.LorenzChatEvent +import at.lorenz.mod.utils.LorenzUtils +import net.minecraftforge.client.event.ClientChatReceivedEvent +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class ChatManager { + + private val loggerAll = LorenzLogger("chat/filter_all") + private val loggerFiltered = LorenzLogger("chat/filter_blocked") + private val loggerAllowed = LorenzLogger("chat/filter_allowed") + private val loggerFilteredTypes = mutableMapOf() + + @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) + fun onChatPacket(event: ClientChatReceivedEvent) { + val messageComponent = event.message + + val message = LorenzUtils.stripVanillaMessage(messageComponent.formattedText) + if (event.type.toInt() == 2) { +// val actionBarEvent = LorenzActionBarEvent(message) +// actionBarEvent.postAndCatch() + } else { + + val chatEvent = LorenzChatEvent(message, messageComponent) + chatEvent.postAndCatch() + + val blockReason = chatEvent.blockedReason.uppercase() + if (blockReason != "") { + event.isCanceled = true + loggerFiltered.log("[$blockReason] $message") + loggerAll.log("[$blockReason] $message") + loggerFilteredTypes.getOrPut(blockReason) { LorenzLogger("chat/filter_blocked/$blockReason") } + .log(message) + return + } + + if (!message.startsWith("§f{\"server\":\"")) { + loggerAllowed.log(message) + loggerAll.log("[allowed] $message") + } + + } + } +} \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/chat/PlayerChatFilter.kt b/src/main/java/at/lorenz/mod/chat/PlayerChatFilter.kt new file mode 100644 index 000000000..427b25e37 --- /dev/null +++ b/src/main/java/at/lorenz/mod/chat/PlayerChatFilter.kt @@ -0,0 +1,78 @@ +package at.lorenz.mod.chat + +import at.lorenz.mod.utils.LorenzLogger +import at.lorenz.mod.utils.LorenzUtils +import at.lorenz.mod.utils.LorenzUtils.Companion.removeColorCodes +import at.lorenz.mod.events.PlayerSendChatEvent + +class PlayerChatFilter { + + companion object { + val loggerPlayerChat = LorenzLogger("chat/player") + + fun shouldBlock(originalMessage: String): Boolean { + val split: List = if (originalMessage.contains("§7§r§7: ")) { + originalMessage.split("§7§r§7: ") + } else if (originalMessage.contains("§f: ")) { + originalMessage.split("§f: ") + } else { + return false + } + + var rawName = split[0] + val message = split[1] + + val channel: PlayerMessageChannel + if (rawName.startsWith("§9Party §8> ")) { + channel = PlayerMessageChannel.PARTY + rawName = rawName.substring(12) + } else if (rawName.startsWith("§2Guild > ")) { + channel = PlayerMessageChannel.GUILD + rawName = rawName.substring(10) + } else if (rawName.startsWith("§bCo-op > ")) { + channel = PlayerMessageChannel.COOP + rawName = rawName.substring(10) + } else { + channel = PlayerMessageChannel.ALL + } + + val nameSplit = rawName.split(" ") + val first = nameSplit[0] + + val last = nameSplit.last() + val name = if (last.endsWith("]")) { + nameSplit[nameSplit.size - 2] + } else { + last + } + + if (first != name) { + if (!first.contains("VIP") && !first.contains("MVP")) { + //TODO support yt + admin + return false + } + } + + send(channel, name.removeColorCodes(), message.removeColorCodes()) + return true + } + + private fun send(channel: PlayerMessageChannel, name: String, message: String) { + loggerPlayerChat.log("[$channel] $name: $message") + val event = PlayerSendChatEvent(channel, name, message) + event.postAndCatch() + + if (event.cancelledReason != "") { + loggerPlayerChat.log("cancelled: " + event.cancelledReason) + } else { + val finalMessage = event.message + if (finalMessage != message) { + loggerPlayerChat.log("message changed: $finalMessage") + } + + val prefix = channel.prefix + LorenzUtils.chat("$prefix §b$name §f$finalMessage") + } + } + } +} \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/chat/PlayerMessageChannel.kt b/src/main/java/at/lorenz/mod/chat/PlayerMessageChannel.kt new file mode 100644 index 000000000..0e44b88f0 --- /dev/null +++ b/src/main/java/at/lorenz/mod/chat/PlayerMessageChannel.kt @@ -0,0 +1,10 @@ +package at.lorenz.mod.chat + +enum class PlayerMessageChannel(val prefix: String) { + + ALL("§fA>"), + ALL_ADVERTISEMENT("§8A>"), + PARTY("§9P>"), + GUILD("§2G>"), + COOP("§bCC>"), +} \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/config/LorenzConfig.kt b/src/main/java/at/lorenz/mod/config/LorenzConfig.kt new file mode 100644 index 000000000..67268b6ca --- /dev/null +++ b/src/main/java/at/lorenz/mod/config/LorenzConfig.kt @@ -0,0 +1,12 @@ +package at.lorenz.mod.config + +class LorenzConfig { + + companion object { + val chatFilter = true + val dungeonHideAnnoyingMessages = true + val hideNotClickableItems = true + + val lorenzBazaarOrderHelper = true + } +} \ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/dungeon/DungeonChatFilter.kt b/src/main/java/at/lorenz/mod/dungeon/DungeonChatFilter.kt new file mode 100644 index 000000000..86fc67cfd --- /dev/null +++ b/src/main/java/at/lorenz/mod/dungeon/DungeonChatFilter.kt @@ -0,0 +1,259 @@ +package at.lorenz.mod.dungeon + +import at.lorenz.mod.config.LorenzConfig +import at.lorenz.mod.events.LorenzChatEvent +import at.lorenz.mod.utils.LorenzUtils.Companion.matchRegex +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class DungeonChatFilter { + + @SubscribeEvent + fun onChatMessage(event: LorenzChatEvent) { + if (!LorenzConfig.dungeonHideAnnoyingMessages) return + + val blockReason = block(event.message) + if (blockReason != "") { + event.blockedReason = "dungeon_$blockReason" + } + } + + private fun block(message: String): String { + when { + isPrepare(message) -> return "prepare" + isStart(message) -> return "start" + } + + //TODO add +// if (!LorenzUtils.inDungeon) return "" + + return when { + isKey(message) -> "key" + isDoor(message) -> "door" + isPickup(message) -> "pickup" + isReminder(message) -> "reminder" + isBuff(message) -> "buff" + isNotPossible(message) -> "not_possible" + isDamage(message) -> "damage" + isAbility(message) -> "ability" + isPuzzle(message) -> "puzzle" + isBoss(message) -> "boss" + isEnd(message) -> "end" + //TODO add +// DungeonMilestoneDisplay.isMilestoneMessage(message) -> "milestone" + + else -> "" + } + } + + private fun isDoor(message: String): Boolean = message == "§cThe §r§c§lBLOOD DOOR§r§c has been opened!" + + private fun isBoss(message: String): Boolean { + when { + message.matchRegex("§([cd4])\\[BOSS] (.*)") -> { + when { + message.contains(" The Watcher§r§f: ") -> return true + message.contains(" Bonzo§r§f: ") -> return true + message.contains(" Scarf§r§f:") -> return true + message.contains("Professor§r§f") -> return true + message.contains(" Livid§r§f: ") || message.contains(" Enderman§r§f: ") -> return true + message.contains(" Thorn§r§f: ") -> return true + message.contains(" Sadan§r§f: ") -> return true + message.contains(" Maxor§r§c: ") -> return true + message.contains(" Storm§r§c: ") -> return true + message.contains(" Goldor§r§c: ") -> return true + message.contains(" Necron§r§c: ") -> return true + message.contains(" §r§4§kWither King§r§c:") -> return true + + message.endsWith(" Necron§r§c: That is enough, fool!") -> return true + message.endsWith(" Necron§r§c: Adventurers! Be careful of who you are messing with..") -> return true + message.endsWith(" Necron§r§c: Before I have to deal with you myself.") -> return true + } + } + + //M7 - Dragons + message == "§cThe Crystal withers your soul as you hold it in your hands!" -> return true + message == "§cIt doesn't seem like that is supposed to go there." -> return true + } + return false + } + + private fun isEnd(message: String): Boolean = when { + message.matchRegex("(.*) §r§eunlocked §r§d(.*) Essence §r§8x(.*)§r§e!") -> true + message.matchRegex(" §r§d(.*) Essence §r§8x(.*)") -> true + message.endsWith(" Experience §r§b(Team Bonus)") -> true + else -> false + } + + private fun isAbility(message: String): Boolean = when { + message == "§a§r§6Guided Sheep §r§ais now available!" -> true + message.matchRegex("§7Your Guided Sheep hit §r§c(.*) §r§7enemy for §r§c(.*) §r§7damage.") -> true + message == "§6Rapid Fire§r§a is ready to use! Press §r§6§lDROP§r§a to activate it!" -> true + message == "§6Castle of Stone§r§a is ready to use! Press §r§6§lDROP§r§a to activate it!" -> true + + + message.matchRegex("§a§lBUFF! §fYou were splashed by (.*) §fwith §r§cHealing VIII§r§f!") -> true + message.matchRegex("§aYou were healed for (.*) health by (.*)§a!") -> true + message.matchRegex("§aYou gained (.*) HP worth of absorption for 3s from §r(.*)§r§a!") -> true + message.matchRegex("§c(.*) §r§epicked up your (.*) Orb!") -> true + message.matchRegex("§cThis ability is on cooldown for (.*)s.") -> true + message.matchRegex("§a§l(.*) healed you for (.*) health!") -> true + message == "§aYou used your §r§6Mining Speed Boost §r§aPickaxe Ability!" -> true + message == "§cYour Mining Speed Boost has expired!" -> true + message == "§a§r§6Mining Speed Boost §r§ais now available!" -> true + message.matchRegex("§eYour bone plating reduced the damage you took by §r§c(.*)§r§e!") -> true + message.matchRegex("(.*) §r§eformed a tether with you!") -> true + message.matchRegex("§eYour tether with (.*) §r§ehealed you for §r§a(.*) §r§ehealth.") -> true + message.matchRegex("§7Your Implosion hit §r§c(.*) §r§7enemy for §r§c(.*) §r§7damage.") -> true + + message.matchRegex("§eYour §r§6Spirit Pet §r§ehealed (.*) §r§efor §r§a(.*) §r§ehealth!") -> true + message.matchRegex("§eYour §r§6Spirit Pet §r§ehit (.*) enemy for §r§c(.*) §r§edamage.") -> true + + message == "§dCreeper Veil §r§aActivated!" -> true + message == "§dCreeper Veil §r§cDe-activated!" -> true + message.matchRegex("§cYou need at least (.*) mana to activate this!") -> true + + message.matchRegex( + "§eYou were healed for §r§a(.*)§r§e health by §r(.*)§r§e's §r§9Healing Bow§r§e and " + "gained §r§c\\+(.*) Strength§r§e for 10 seconds." + ) -> true + message.matchRegex("(.*)§r§a granted you §r§c(.*) §r§astrength for §r§e20 §r§aseconds!") -> true + + message.matchRegex("§eYour fairy healed §r§ayourself §r§efor §r§a(.*) §r§ehealth!") -> true + message.matchRegex("§eYour fairy healed §r(.*) §r§efor §r§a(.*) §r§ehealth!") -> true + message.matchRegex("(.*) fairy healed you for §r§a(.*) §r§ehealth!") -> true + + else -> false + } + + private fun isDamage(message: String): Boolean = when { + message == "§cMute silenced you!" -> true + message.matchRegex("(.*) §r§aused §r(.*) §r§aon you!") -> true + message.matchRegex("§cThe (.*)§r§c struck you for (.*) damage!") -> true + message.matchRegex("§cThe (.*) hit you for (.*) damage!") -> true + message.matchRegex("§7(.*) struck you for §r§c(.*)§r§7 damage.") -> true + message.matchRegex("(.*) hit you for §r§c(.*)§r§7 damage.") -> true + message.matchRegex("(.*) hit you for §r§c(.*)§r§7 true damage.") -> true + message.matchRegex("§7(.*) exploded, hitting you for §r§c(.*)§r§7 damage.") -> true + message.matchRegex("(.*)§r§c hit you with §r(.*) §r§cfor (.*) damage!") -> true + message.matchRegex("(.*)§r§a struck you for §r§c(.*)§r§a damage!") -> true + message.matchRegex("(.*)§r§c struck you for (.*)!") -> true + + //TODO abstract if more "burnt" messages are found + message.matchRegex("§7The Mage's Magma burnt you for §r§c(.*)§r§7 true damage.") -> true + + message.matchRegex("§7Your (.*) hit §r§c(.*) §r§7(enemy|enemies) for §r§c(.*) §r§7damage.") -> true + else -> false + } + + private fun isNotPossible(message: String): Boolean = when (message) { + "§cYou cannot hit the silverfish while it's moving!", + "§cYou cannot move the silverfish in that direction!", + "§cThere are blocks in the way!", + "§cThis chest has already been searched!", + "§cThis lever has already been used.", + "§cYou cannot do that in this room!", + "§cYou do not have the key for this door!", + "§cYou have already opened this dungeon chest!", + "§cYou cannot use abilities in this room!", + "§cA mystical force in this room prevents you from using that ability!" -> true + + else -> false + } + + private fun isBuff(message: String): Boolean = when { + message.matchRegex("§6§lDUNGEON BUFF! (.*) §r§ffound a §r§dBlessing of (.*)§r§f!(.*)") -> true + message.matchRegex("§6§lDUNGEON BUFF! §r§fYou found a §r§dBlessing of (.*)§r§f!(.*)") -> true + message.matchRegex("§6§lDUNGEON BUFF! §r§fA §r§dBlessing of (.*)§r§f was found! (.*)") -> true + message.matchRegex("§eA §r§a§r§dBlessing of (.*)§r§e was picked up!") -> true + message.matchRegex("(.*) §r§ehas obtained §r§a§r§dBlessing of (.*)§r§e!") -> true + message.matchRegex(" §r§7(Grants|Granted) you §r§a(.*) Strength §r§7and §r§a(.*) Crit Damage§r§7.") -> true + message.matchRegex(" §r§7(Grants|Granted) you §r§a(.*) Defense §r§7and §r§a+(.*) Damage§r§7.") -> true + message.matchRegex(" §r§7(Grants|Granted) you §r§a(.*) HP §r§7and §r§a+(.*)% §r§7health regeneration.") -> true + message.matchRegex(" §r§7(Grants|Granted) you §r§a(.*) Intelligence §r§7and §r§a+(.*)? Speed§r§7.") -> true + message.matchRegex(" §r§7Granted you §r§a+(.*) HP§r§7, §r§a(.*) Defense§r§7, §r§a(.*) Intelligence§r§7, and §r§a(.*) Strength§r§7.") -> true + message == "§a§lBUFF! §fYou have gained §r§cHealing V§r§f!" -> true + else -> false + } + + private fun isPuzzle(message: String): Boolean = when { + message.matchRegex("§a§lPUZZLE SOLVED! (.*) §r§ewasn't fooled by §r§c(.*)§r§e! §r§4G§r§co§r§6o§r§ed§r§a §r§2j§r§bo§r§3b§r§5!") -> true + message.matchRegex("§a§lPUZZLE SOLVED! (.*) §r§etied Tic Tac Toe! §r§4G§r§co§r§6o§r§ed§r§a §r§2j§r§bo§r§3b§r§5!") -> true + message == "§4[STATUE] Oruo the Omniscient§r§f