From 41aded9458dd5aee7339c409a3186a5b73a76774 Mon Sep 17 00:00:00 2001 From: tmbRandy Date: Sun, 30 Jun 2024 16:50:07 +0200 Subject: [PATCH] Added /auswurf and fixed some bugs including a bug caused by LabyMod itself which caused wrong key press detection. As LabyMod won't fix this we had to solve the problem with a workaround. --- README.md | 3 + build.gradle.kts | 2 +- .../tmb/randy/tmbgriefergames/core/Addon.java | 15 +-- .../randy/tmbgriefergames/core/IBridge.java | 14 +-- .../core/commands/EjectCommand.java | 21 ++++ .../core/commands/PayAllCommand.java | 2 +- .../core/config/HopperSubConfig.java | 5 +- .../core/config/NatureSubConfig.java | 5 +- .../core/widgets/NearbyWidget.java | 6 +- .../assets/tmbgriefergames/i18n/de_de.json | 4 + .../assets/tmbgriefergames/i18n/en_us.json | 4 + .../tmbgriefergames/v1_12_2/util/Auswurf.java | 101 ++++++++++++++++++ .../v1_12_2/util/AutoComp.java | 2 +- .../v1_12_2/util/AutoDecomp.java | 2 +- .../v1_12_2/util/ItemSaver.java | 26 ++--- .../v1_12_2/util/ItemShifter.java | 5 +- .../v1_12_2/util/NatureBordersRenderer.java | 2 +- .../v1_12_2/util/PlotSwitch.java | 4 +- .../v1_12_2/util/TooltipExtension.java | 73 +++++++------ .../v1_12_2/util/VersionisedBridge.java | 51 ++++++--- .../v1_12_2/util/chat/MsgTabs.java | 40 ++++--- .../v1_12_2/util/chat/PaymentValidator.java | 21 ++-- .../tmbgriefergames/v1_8_9/util/Auswurf.java | 100 +++++++++++++++++ .../tmbgriefergames/v1_8_9/util/AutoComp.java | 2 +- .../v1_8_9/util/AutoDecomp.java | 2 +- .../v1_8_9/util/ItemSaver.java | 28 ++--- .../v1_8_9/util/ItemShifter.java | 3 +- .../v1_8_9/util/NatureBordersRenderer.java | 2 +- .../v1_8_9/util/PlotSwitch.java | 4 +- .../v1_8_9/util/TooltipExtension.java | 72 +++++++------ .../v1_8_9/util/VersionisedBridge.java | 44 ++++++-- .../v1_8_9/util/chat/MsgTabs.java | 38 ++++--- .../v1_8_9/util/chat/PaymentValidator.java | 23 ++-- 33 files changed, 513 insertions(+), 213 deletions(-) create mode 100644 core/src/main/java/tmb/randy/tmbgriefergames/core/commands/EjectCommand.java create mode 100644 game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/Auswurf.java create mode 100644 game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/Auswurf.java diff --git a/README.md b/README.md index 75b9633..b5ed437 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,9 @@ Dieser Befehl ist das Gegenstück zu /pay * . Wenn z.B. 100 Spieler auf ### Befehl /fahndung Du suchst einen Spieler, von dem du weißt, dass er online ist aber er hat seinen aktuellen CB nicht im /profil angegeben? Mit diesem Befehl wechselst du der Reihe nach alle CBs durch (beginnend mit den stark besuchten CBs). Sobald der Spieler auf einem CB gefunden wurde, wird die Fahndung beendet und du erhältst eine Ausgabe im Chat. Du willst eine Nachricht in deinem Status verbreiten? Kein Problem. Gib nur /fahndung ohne einen Namen ein und du wechselst alle CBs einmal durch. +### Befehl /auswurf +Mit /auswurf kannst du ein endloses Lager automatisch leeren. Die Kiste wird immer wieder geöffnet und alle Items aus dem Kisteninventar gedroppt. Dies kann nützlich sein, wenn du ein nicht komprimierbares Item aus einem endlosen Lager in ein neues endloses Lager umschichten willst. Deaktiviere hierzu die Einsaugfunktion des alten Lagers, aktiviere sie beim neuen Lager, gib den Befehl /auswurf ein und öffne das zu leerende, endlose Lager. + ### Item Schutz Das Addon verhindert die Abnutzung wertvoller Farmitems. So ist ein Zuschlagen mit einer Bonze- oder BIRTH Klinge, das Schießen mit dem BIRTH Bogen, sowie das Platzieren eines SoS nicht möglich. Diese Funktionen wurden ausreichend getestet und funktionieren grundsätzlich. Aus Prinzip können wir jedoch keinerlei Haftung für die Funktion übernehmen. Wir werden keine Items erstatten. Diese Funktion verhindert lediglich Mausklicks, die durch den Spieler selbst ausgeführt werden. Softwareseitige Klicks, wie z.B. durch einen Autoklicker würde das Addon nicht verhindern, sodass damit z.B. ein SoS gesetzt werden könnte. diff --git a/build.gradle.kts b/build.gradle.kts index b5ec22b..2d1943e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } group = "tmb.randy" -version = "1.3" +version = "1.4" java.toolchain.languageVersion.set(JavaLanguageVersion.of(17)) diff --git a/core/src/main/java/tmb/randy/tmbgriefergames/core/Addon.java b/core/src/main/java/tmb/randy/tmbgriefergames/core/Addon.java index 26cecfd..bd663c0 100644 --- a/core/src/main/java/tmb/randy/tmbgriefergames/core/Addon.java +++ b/core/src/main/java/tmb/randy/tmbgriefergames/core/Addon.java @@ -7,6 +7,7 @@ import net.labymod.api.models.addon.annotation.AddonMain; import tmb.randy.tmbgriefergames.core.commands.AutocraftCommand; import tmb.randy.tmbgriefergames.core.commands.DKsCommand; +import tmb.randy.tmbgriefergames.core.commands.EjectCommand; import tmb.randy.tmbgriefergames.core.commands.PayAllCommand; import tmb.randy.tmbgriefergames.core.commands.PlayerTracerCommand; import tmb.randy.tmbgriefergames.core.config.Configuration; @@ -36,6 +37,7 @@ protected void enable() { this.registerCommand(new PayAllCommand()); this.registerCommand(new PlayerTracerCommand()); this.registerCommand(new AutocraftCommand()); + this.registerCommand(new EjectCommand()); gameInfoWidget = new GameInfoWidget(); @@ -88,17 +90,4 @@ public static boolean isChatGuiOpen() { return false; } - - public static boolean areKeysPressed(Key[] keys) { - if(isChatGuiOpen() || keys.length == 0) - return false; - - for (Key key : keys) { - if(!key.isPressed() || key == Key.NONE) { - return false; - } - } - - return true; - } } diff --git a/core/src/main/java/tmb/randy/tmbgriefergames/core/IBridge.java b/core/src/main/java/tmb/randy/tmbgriefergames/core/IBridge.java index cce9544..b8650be 100644 --- a/core/src/main/java/tmb/randy/tmbgriefergames/core/IBridge.java +++ b/core/src/main/java/tmb/randy/tmbgriefergames/core/IBridge.java @@ -4,11 +4,13 @@ @Referenceable public interface IBridge { - public void startPlayerTracer(String name); - public void cbChanged(); - public boolean isFlyCountdownActive(); - public String getWidgetString(); - public String getItemRemoverValue(); - public void startNewAutocrafter(); + void startPlayerTracer(String name); + void cbChanged(); + boolean isFlyCountdownActive(); + String getWidgetString(); + String getItemRemoverValue(); + void startNewAutocrafter(); boolean isCompActive(); + void changeSlot(int slot); + void startAuswurf(); } diff --git a/core/src/main/java/tmb/randy/tmbgriefergames/core/commands/EjectCommand.java b/core/src/main/java/tmb/randy/tmbgriefergames/core/commands/EjectCommand.java new file mode 100644 index 0000000..c5112cc --- /dev/null +++ b/core/src/main/java/tmb/randy/tmbgriefergames/core/commands/EjectCommand.java @@ -0,0 +1,21 @@ +package tmb.randy.tmbgriefergames.core.commands; + +import net.labymod.api.client.chat.command.Command; +import tmb.randy.tmbgriefergames.core.Addon; + +public class EjectCommand extends Command { + + public EjectCommand() { + super("auswurf"); + } + + @Override + public boolean execute(String prefix, String[] arguments) { + if(!Addon.isGG()) + return false; + + Addon.getSharedInstance().getBridge().startAuswurf(); + + return true; + } +} diff --git a/core/src/main/java/tmb/randy/tmbgriefergames/core/commands/PayAllCommand.java b/core/src/main/java/tmb/randy/tmbgriefergames/core/commands/PayAllCommand.java index 4123c84..daf129f 100644 --- a/core/src/main/java/tmb/randy/tmbgriefergames/core/commands/PayAllCommand.java +++ b/core/src/main/java/tmb/randy/tmbgriefergames/core/commands/PayAllCommand.java @@ -16,7 +16,7 @@ public PayAllCommand() { @Override public boolean execute(String prefix, String[] arguments) { if(!Addon.isGG()) - return true; + return false; if(arguments.length == 2) { if((arguments[0].equals("**") || arguments[0].equals("/")) && Float.parseFloat(arguments[1]) >= 1F) { diff --git a/core/src/main/java/tmb/randy/tmbgriefergames/core/config/HopperSubConfig.java b/core/src/main/java/tmb/randy/tmbgriefergames/core/config/HopperSubConfig.java index e83571c..30911b7 100644 --- a/core/src/main/java/tmb/randy/tmbgriefergames/core/config/HopperSubConfig.java +++ b/core/src/main/java/tmb/randy/tmbgriefergames/core/config/HopperSubConfig.java @@ -4,14 +4,15 @@ import net.labymod.api.client.gui.screen.widget.widgets.input.SwitchWidget.SwitchSetting; import net.labymod.api.client.gui.screen.widget.widgets.input.dropdown.DropdownWidget.DropdownSetting; import net.labymod.api.configuration.loader.Config; -import net.labymod.api.configuration.loader.annotation.ParentSwitch; +import net.labymod.api.configuration.loader.annotation.ShowSettingInParent; import net.labymod.api.configuration.loader.property.ConfigProperty; import tmb.randy.tmbgriefergames.core.enums.HopperFinalAction; import tmb.randy.tmbgriefergames.core.enums.HopperItemStackSizeEnum; public class HopperSubConfig extends Config { - @ParentSwitch + @ShowSettingInParent + @SwitchSetting private final ConfigProperty enabled = new ConfigProperty<>(false); @SwitchSetting private final ConfigProperty filterItem = new ConfigProperty<>(false); diff --git a/core/src/main/java/tmb/randy/tmbgriefergames/core/config/NatureSubConfig.java b/core/src/main/java/tmb/randy/tmbgriefergames/core/config/NatureSubConfig.java index e3c0b9b..30e1ae0 100644 --- a/core/src/main/java/tmb/randy/tmbgriefergames/core/config/NatureSubConfig.java +++ b/core/src/main/java/tmb/randy/tmbgriefergames/core/config/NatureSubConfig.java @@ -6,12 +6,13 @@ import net.labymod.api.client.gui.screen.widget.widgets.input.SwitchWidget.SwitchSetting; import net.labymod.api.client.gui.screen.widget.widgets.input.color.ColorPickerWidget.ColorPickerSetting; import net.labymod.api.configuration.loader.Config; -import net.labymod.api.configuration.loader.annotation.ParentSwitch; +import net.labymod.api.configuration.loader.annotation.ShowSettingInParent; import net.labymod.api.configuration.loader.property.ConfigProperty; public class NatureSubConfig extends Config { - @ParentSwitch + @ShowSettingInParent + @SwitchSetting private final ConfigProperty showBorders = new ConfigProperty<>(false); @SliderSetting(min = 1, max = 10, steps = 1) diff --git a/core/src/main/java/tmb/randy/tmbgriefergames/core/widgets/NearbyWidget.java b/core/src/main/java/tmb/randy/tmbgriefergames/core/widgets/NearbyWidget.java index f8ad807..245cad9 100644 --- a/core/src/main/java/tmb/randy/tmbgriefergames/core/widgets/NearbyWidget.java +++ b/core/src/main/java/tmb/randy/tmbgriefergames/core/widgets/NearbyWidget.java @@ -13,7 +13,7 @@ public class NearbyWidget extends TextHudWidget { - private final List blacklist = Arrays.asList( + private static final List blacklist = Arrays.asList( "Adventurer", "Admin-Shop", "Statistik", @@ -28,7 +28,9 @@ public class NearbyWidget extends TextHudWidget { "Skyblock Museum", "Impressum", "Datenschutz", - "Jobs" + "Jobs", + "Block des Tages", + "GS-Bewertungen" ); private String name; diff --git a/core/src/main/resources/assets/tmbgriefergames/i18n/de_de.json b/core/src/main/resources/assets/tmbgriefergames/i18n/de_de.json index a899c7e..f99027b 100644 --- a/core/src/main/resources/assets/tmbgriefergames/i18n/de_de.json +++ b/core/src/main/resources/assets/tmbgriefergames/i18n/de_de.json @@ -230,6 +230,10 @@ "recipeSaved": "Rezept gespeichert", "active": "Endlosmodus §a§lAKTIV", "inactive": "Endlosmodus §c§lDEAKTIVIERT" + }, + "eject": { + "enabled": "Auswurf §a§lAKTIVIERT. §fÖffne ein unendliches Lager!", + "disabled": "Auswurf §c§lDEAKTIVIERT" } } } \ No newline at end of file diff --git a/core/src/main/resources/assets/tmbgriefergames/i18n/en_us.json b/core/src/main/resources/assets/tmbgriefergames/i18n/en_us.json index f5e651f..e5676e5 100644 --- a/core/src/main/resources/assets/tmbgriefergames/i18n/en_us.json +++ b/core/src/main/resources/assets/tmbgriefergames/i18n/en_us.json @@ -230,6 +230,10 @@ "recipeSaved": "Recipe saved", "active": "Endless mode §a§ACTIVE", "inactive": "Endless mode §c§INACTIVE" + }, + "eject": { + "enabled": "Eject §a§lACTIVE. §fOpen an endless chest!", + "disabled": "Eject §c§lINACTIVE" } } } \ No newline at end of file diff --git a/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/Auswurf.java b/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/Auswurf.java new file mode 100644 index 0000000..857a019 --- /dev/null +++ b/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/Auswurf.java @@ -0,0 +1,101 @@ +package tmb.randy.tmbgriefergames.v1_12_2.util; + +import net.labymod.api.client.gui.screen.key.Key; +import net.labymod.api.event.client.input.KeyEvent; +import net.labymod.api.event.client.input.KeyEvent.State; +import net.labymod.api.event.client.lifecycle.GameTickEvent; +import net.labymod.api.util.I18n; +import net.minecraft.block.BlockChest; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.inventory.ContainerChest; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.RayTraceResult; +import net.minecraft.util.math.RayTraceResult.Type; +import tmb.randy.tmbgriefergames.core.Addon; +import tmb.randy.tmbgriefergames.core.enums.QueueType; +import tmb.randy.tmbgriefergames.v1_12_2.util.click.ClickManager; + +public class Auswurf { + private boolean active; + private BlockPos chestPos; + + public void onTickEvent(GameTickEvent event) { + if(active && Minecraft.getMinecraft().player != null && Minecraft.getMinecraft().world != null) { + if(Minecraft.getMinecraft().player.openContainer instanceof ContainerChest chest) { + IInventory inv = chest.getLowerChestInventory(); + if(inv.getName().startsWith("§0Lager: ")) { + if(chestPos == null) { + chestPos = getChestPos(); + } else { + if(ClickManager.getSharedInstance().isClickQueueEmpty(QueueType.MEDIUM)) { + for (int i = 0; i < 25; i++) { + Slot slot = chest.getSlot(i); + if(slot.getHasStack()) { + ClickManager.getSharedInstance().dropClick(i); + } + } + + if(ClickManager.getSharedInstance().isClickQueueEmpty(QueueType.MEDIUM)) { + Minecraft.getMinecraft().displayGuiScreen(null); + Minecraft.getMinecraft().player.closeScreen(); + RayTraceResult rayTraceResult = Minecraft.getMinecraft().objectMouseOver; + if(rayTraceResult.typeOfHit == Type.BLOCK && rayTraceResult.getBlockPos().equals(chestPos)) { + Minecraft.getMinecraft().playerController.processRightClickBlock(Minecraft.getMinecraft().player, Minecraft.getMinecraft().world, chestPos, rayTraceResult.sideHit, rayTraceResult.hitVec, EnumHand.MAIN_HAND); + } + + } + } + } + } + } + } + } + + public void onKeyEvent(KeyEvent event) { + if(event.state() == State.PRESS) { + if (active && event.key() == Key.ESCAPE) { + ClickManager.getSharedInstance().clearAllQueues(); + Addon.getSharedInstance().displayNotification(I18n.getTranslation("tmbgriefergames.eject.disabled")); + chestPos = null; + active = false; + } + } + } + + public void startAuswurf() { + Addon.getSharedInstance().displayNotification(I18n.getTranslation("tmbgriefergames.eject.enabled")); + active = true; + } + + private static BlockPos getChestPos() { + Minecraft mc = Minecraft.getMinecraft(); + RayTraceResult rayTraceResult = mc.objectMouseOver; + + if (rayTraceResult != null && rayTraceResult.typeOfHit == RayTraceResult.Type.BLOCK) { + BlockPos blockPosition = rayTraceResult.getBlockPos(); + IBlockState blockState = mc.world.getBlockState(blockPosition); + + if (blockState.getBlock() instanceof BlockChest) { + return blockPosition; + } + } + + return null; + } + + private static Entity getEntityInBlockPos(BlockPos pos) { + Minecraft mc = Minecraft.getMinecraft(); + for (Entity entity : mc.world.loadedEntityList) { + if (entity instanceof EntityLivingBase && entity.getDistanceSq(pos) < 2) { + return entity; + } + } + return null; + } +} diff --git a/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/AutoComp.java b/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/AutoComp.java index f53a68a..3ade07d 100644 --- a/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/AutoComp.java +++ b/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/AutoComp.java @@ -54,7 +54,7 @@ public void onKeyEvent(KeyEvent event) { } } } else { - if (Addon.areKeysPressed(Addon.getSharedInstance().configuration().getAutoCrafterConfig().getAutoCompHotkey().get())) { + if (VersionisedBridge.allKeysPressed(Addon.getSharedInstance().configuration().getAutoCrafterConfig().getAutoCompHotkey().get())) { startComp(); } } diff --git a/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/AutoDecomp.java b/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/AutoDecomp.java index 9fb3839..2db0ba0 100644 --- a/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/AutoDecomp.java +++ b/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/AutoDecomp.java @@ -27,7 +27,7 @@ public class AutoDecomp { public void onKeyEvent(KeyEvent event) { if(Key.ESCAPE.isPressed() && autoDecompActive) { stopDecomp(); - } else if (Addon.areKeysPressed(Addon.getSharedInstance().configuration().getAutoCrafterConfig().getAutoDecompHotkey().get())) { + } else if (VersionisedBridge.allKeysPressed(Addon.getSharedInstance().configuration().getAutoCrafterConfig().getAutoDecompHotkey().get())) { startDecomp(); Addon.getSharedInstance().displayNotification(I18n.getTranslation("tmbgriefergames.autoDecomp.started")); } diff --git a/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/ItemSaver.java b/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/ItemSaver.java index 881d4ac..056c19e 100644 --- a/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/ItemSaver.java +++ b/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/ItemSaver.java @@ -2,6 +2,7 @@ import net.labymod.api.Laby; import net.labymod.api.client.world.item.ItemStack; +import net.labymod.api.component.data.DataComponentKey; import net.labymod.api.event.Priority; import net.labymod.api.event.Subscribe; import net.labymod.api.event.client.input.MouseButtonEvent; @@ -18,31 +19,27 @@ public class ItemSaver { public static final String NBTTagStringBirthBow = "[{lvl:22s,id:48s},{lvl:4s,id:49s},{lvl:1s,id:51s},{lvl:4s,id:19s},{lvl:22s,id:21s}]"; - public void mouseInput(MouseButtonEvent event) { - if(!Addon.getSharedInstance().configuration().getItemProtection().get()) - return; + public void mouseButtonEvent(MouseButtonEvent event) { if(Laby.labyAPI().minecraft().getClientPlayer() != null) { if(Laby.labyAPI().minecraft().getClientPlayer().getMainHandItemStack() != null) { ItemStack stack = Laby.labyAPI().minecraft().getClientPlayer().getMainHandItemStack(); + if(stack.hasDataComponentContainer()) { + if(stack.getDataComponentContainer().has(DataComponentKey.simple("ench"))) { + String enchantments = stack.getDataComponentContainer().get(DataComponentKey.simple("ench")).toString(); - if(stack.hasNBTTag()) { - if(stack.getNBTTag().contains("ench")) { - String enchantments = stack.getNBTTag().get("ench").toString(); - - //Unfortunately there is a bug within LabyMod which doesn't cancel the event in MouseButtonEvent after performing event.setCancelled(true) for some players. So switching the slot to save the item is a workaround. As LabyMod support couldn't reproduce and fix the bug this is the only option to save the item. if(event.action() == Action.CLICK) { if((enchantments.equals(NBTTagStringBonze) || enchantments.equals(NBTTagStringBirthSword)) && event.button().isLeft()) { Addon.getSharedInstance().displayNotification("§4§l" + I18n.translate("tmbgriefergames.itemSaver.item_saver_message_sword")); - changeSlot(findHotbarSlotforItem()); + Addon.getSharedInstance().getBridge().changeSlot(findHotbarSlotforItem()); event.setCancelled(true); } else if(enchantments.equals(NBTTagStringSoS) && event.button().isRight()) { Addon.getSharedInstance().displayNotification("§4§l" + I18n.translate("tmbgriefergames.itemSaver.item_saver_message_sos")); - changeSlot(findHotbarSlotforBlock()); + Addon.getSharedInstance().getBridge().changeSlot(findHotbarSlotforBlock()); event.setCancelled(true); } else if(enchantments.equals(NBTTagStringBirthBow) && event.button().isRight()) { Addon.getSharedInstance().displayNotification("§4§l" + I18n.translate("tmbgriefergames.itemSaver.item_saver_message_birth_bow")); - changeSlot(findHotbarSlotforItem()); + Addon.getSharedInstance().getBridge().changeSlot(findHotbarSlotforItem()); event.setCancelled(true); } } @@ -72,7 +69,7 @@ public static int findHotbarSlotforBlock() { for (int i = 0; i < 9; i++) { ItemStack stack = Laby.labyAPI().minecraft().getClientPlayer().inventory().itemStackAt(i); - if(stack.isBlock() && !stack.hasNBTTag()) { + if(stack.isBlock() && !stack.hasDataComponentContainer()) { return i; } } @@ -100,7 +97,7 @@ public static int findHotbarSlotforItem() { for (int i = 0; i < 9; i++) { ItemStack stack = Laby.labyAPI().minecraft().getClientPlayer().inventory().itemStackAt(i); - if(stack.isItem() && !stack.hasNBTTag()) { + if(stack.isItem() && !stack.hasDataComponentContainer()) { return i; } } @@ -108,7 +105,4 @@ public static int findHotbarSlotforItem() { return Laby.labyAPI().minecraft().getClientPlayer().inventory().getSelectedIndex() == 8 ? 0 : Laby.labyAPI().minecraft().getClientPlayer().inventory().getSelectedIndex() + 1; } - public void changeSlot(int slot) { - Minecraft.getMinecraft().player.inventory.currentItem = slot; - } } diff --git a/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/ItemShifter.java b/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/ItemShifter.java index ca73a73..f0b771a 100644 --- a/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/ItemShifter.java +++ b/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/ItemShifter.java @@ -1,8 +1,8 @@ package tmb.randy.tmbgriefergames.v1_12_2.util; import net.labymod.api.client.gui.screen.key.Key; -import net.labymod.api.event.Phase; import net.labymod.api.event.client.input.KeyEvent; +import net.labymod.api.event.client.input.KeyEvent.State; import net.labymod.api.event.client.lifecycle.GameTickEvent; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiChest; @@ -14,6 +14,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import org.apache.commons.lang3.ArrayUtils; +import org.lwjgl.input.Keyboard; import tmb.randy.tmbgriefergames.core.Addon; import tmb.randy.tmbgriefergames.core.enums.QueueType; import tmb.randy.tmbgriefergames.v1_12_2.util.click.Click; @@ -142,7 +143,7 @@ public void tick(GameTickEvent event) { public void onKey(KeyEvent event) { if ((event.key() == Key.ARROW_UP || event.key() == Key.ARROW_LEFT || event.key() == Key.ARROW_RIGHT) && - Key.ARROW_UP.isPressed() && Key.ARROW_LEFT.isPressed() && Key.ARROW_RIGHT.isPressed() && + Keyboard.isKeyDown(Key.ARROW_UP.getId()) && Keyboard.isKeyDown(Key.ARROW_LEFT.getId()) && Keyboard.isKeyDown(Key.ARROW_RIGHT.getId()) && Minecraft.getMinecraft().player.openContainer != null && ClickManager.getSharedInstance().isClickQueueEmpty(QueueType.MEDIUM) && Minecraft.getMinecraft().currentScreen instanceof GuiInventory) { ClickManager.getSharedInstance().dropInventory(); } diff --git a/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/NatureBordersRenderer.java b/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/NatureBordersRenderer.java index bcf1fb6..9dfd6e3 100644 --- a/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/NatureBordersRenderer.java +++ b/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/NatureBordersRenderer.java @@ -39,7 +39,7 @@ public static double getDistanceSq(double x1, double z1, double x2, double z2) private float lineBlue = 0.0F; public void onKey(KeyEvent event) { - if(Addon.areKeysPressed(Addon.getSharedInstance().configuration().getNatureSubConfig().getHotkey().get())) { + if(VersionisedBridge.allKeysPressed(Addon.getSharedInstance().configuration().getNatureSubConfig().getHotkey().get())) { Addon.getSharedInstance().configuration().getNatureSubConfig().getShowBorders().set(!Addon.getSharedInstance().configuration().getNatureSubConfig().getShowBorders().get()); String activeString = Addon.getSharedInstance().configuration().getNatureSubConfig().getShowBorders().get() ? I18n.getTranslation("tmbgriefergames.natureBorders.plotBordersVisible") : I18n.getTranslation("tmbgriefergames.natureBorders.plotBordersInvisible"); diff --git a/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/PlotSwitch.java b/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/PlotSwitch.java index 677e458..2a50ab1 100644 --- a/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/PlotSwitch.java +++ b/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/PlotSwitch.java @@ -74,9 +74,9 @@ public void keyDown(KeyEvent event) { String command = null; if(event.state() == State.PRESS) { - if(Addon.areKeysPressed(Addon.getSharedInstance().configuration().getPreviousPlot().get())) { + if(VersionisedBridge.allKeysPressed(Addon.getSharedInstance().configuration().getPreviousPlot().get())) { command = getPlotCommand(lastPlot, DIRECTION.PREVIOUS); - } else if(Addon.areKeysPressed(Addon.getSharedInstance().configuration().getNextPlot().get())) { + } else if(VersionisedBridge.allKeysPressed(Addon.getSharedInstance().configuration().getNextPlot().get())) { command = getPlotCommand(lastPlot, DIRECTION.NEXT); } diff --git a/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/TooltipExtension.java b/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/TooltipExtension.java index e3badba..42315da 100644 --- a/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/TooltipExtension.java +++ b/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/TooltipExtension.java @@ -1,61 +1,64 @@ package tmb.randy.tmbgriefergames.v1_12_2.util; -import java.util.Objects; import net.labymod.api.client.component.Component; import net.labymod.api.client.world.item.ItemStack; -import net.labymod.api.event.Subscribe; +import net.labymod.api.component.data.DataComponentKey; import net.labymod.api.event.client.world.ItemStackTooltipEvent; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagInt; import tmb.randy.tmbgriefergames.core.Addon; public class TooltipExtension { - public void renderTooltip(ItemStackTooltipEvent event) { - if(!Addon.isGG()) { - return; - } + public void renderTooltip(ItemStackTooltipEvent event) { + if(!Addon.isGG()) { + return; + } - ItemStack stack = event.itemStack(); + ItemStack stack = event.itemStack(); - if(stack.hasNBTTag()) { + if(stack.hasDataComponentContainer()) { - if(Addon.getSharedInstance().configuration().getTooltipConfig().getShowCompTooltip().get() && (stack.getNBTTag().contains("currentAmount") || stack.getNBTTag().contains("stackSize"))) { - // Show com item size - int currentAmount; + if(Addon.getSharedInstance().configuration().getTooltipConfig().getShowCompTooltip().get() && (stack.getDataComponentContainer().has( + DataComponentKey.simple("currentAmount")) || stack.getDataComponentContainer().has(DataComponentKey.simple("stackSize")))) { + // Show com item size + int currentAmount; - if(stack.getNBTTag().contains("currentAmount")) { - currentAmount = stack.getNBTTag().getInt("currentAmount") * stack.getSize(); - } else { - currentAmount = stack.getNBTTag().getInt("stackSize") * stack.getSize(); - } + if(stack.getDataComponentContainer().has(DataComponentKey.simple("currentAmount"))) { + currentAmount = ((NBTTagInt)stack.getDataComponentContainer().get(DataComponentKey.simple("currentAmount"))).getInt() * stack.getSize(); + } else { + currentAmount = ((NBTTagInt)stack.getDataComponentContainer().get(DataComponentKey.simple("stackSize"))).getInt() * stack.getSize(); + } - int maxStackSize = stack.getMaximumStackSize(); + int maxStackSize = stack.getMaximumStackSize(); - int DKs = currentAmount / (maxStackSize * 9 * 6); - int rest = currentAmount - (DKs * maxStackSize * 9 * 6); + int DKs = currentAmount / (maxStackSize * 9 * 6); + int rest = currentAmount - (DKs * maxStackSize * 9 * 6); - int stacks = rest / maxStackSize; - int items = rest - (stacks * maxStackSize); + int stacks = rest / maxStackSize; + int items = rest - (stacks * maxStackSize); - event.getTooltipLines().add(Component.translatable("tmbgriefergames.tooltip.compressedTooltip", Component.text(DKs), Component.text(stacks), Component.text(items))); - } else if(Addon.getSharedInstance().configuration().getTooltipConfig().getShowAdventurerTooltip().get() && Objects.requireNonNull(stack.getNBTTag()).contains("adventure")) { - // Show extended adventurer tool data - int amount = stack.getNBTTag().getCompound("adventure").getInt("adventure.amount"); - int total = stack.getNBTTag().getCompound("adventure").getInt("adventure.req_amount"); - float percent = 100f / (float)total * (float)amount; + event.getTooltipLines().add(Component.translatable("tmbgriefergames.tooltip.compressedTooltip", Component.text(DKs), Component.text(stacks), Component.text(items))); + } else if(Addon.getSharedInstance().configuration().getTooltipConfig().getShowAdventurerTooltip().get() && stack.getDataComponentContainer().has(DataComponentKey.simple("adventure"))) { + // Show extended adventurer tool data + int amount = ((NBTTagCompound)stack.getDataComponentContainer().get(DataComponentKey.simple("adventure"))).getInteger("adventure.amount"); + int total = ((NBTTagCompound)stack.getDataComponentContainer().get(DataComponentKey.simple("adventure"))).getInteger("adventure.req_amount"); - int needed = total - amount; + float percent = 100f / (float)total * (float)amount; - int DKs = needed / (64 * 9 * 6); - int rest = needed - (DKs * 64 * 9 * 6); + int needed = total - amount; - int stacks = rest / 64; - int items = rest - (stacks * 64); + int DKs = needed / (64 * 9 * 6); + int rest = needed - (DKs * 64 * 9 * 6); - float percentRounded = Math.round(percent * 10) / 10.0f; - event.getTooltipLines().add(Component.translatable("tmbgriefergames.tooltip.adventurerTooltip", Component.text(percentRounded), Component.text(DKs), Component.text(stacks), Component.text(items))); + int stacks = rest / 64; + int items = rest - (stacks * 64); + + float percentRounded = Math.round(percent * 10) / 10.0f; + event.getTooltipLines().add(Component.translatable("tmbgriefergames.tooltip.adventurerTooltip", Component.text(percentRounded), Component.text(DKs), Component.text(stacks), Component.text(items))); + } } } - } } diff --git a/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/VersionisedBridge.java b/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/VersionisedBridge.java index 937fe71..84a06c7 100644 --- a/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/VersionisedBridge.java +++ b/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/VersionisedBridge.java @@ -2,6 +2,7 @@ import net.labymod.api.Laby; import net.labymod.api.client.gui.screen.activity.types.IngameOverlayActivity; +import net.labymod.api.client.gui.screen.key.Key; import net.labymod.api.event.Phase; import net.labymod.api.event.Priority; import net.labymod.api.event.Subscribe; @@ -17,12 +18,12 @@ import net.labymod.api.event.client.world.ItemStackTooltipEvent; import net.labymod.api.event.client.world.WorldLoadEvent; import net.labymod.api.models.Implements; -import net.labymod.core.client.gui.screen.activity.activities.ingame.chat.ChatOverlay; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiChest; import net.minecraft.client.gui.inventory.GuiCrafting; import net.minecraft.client.gui.inventory.GuiInventory; +import org.lwjgl.input.Keyboard; import tmb.randy.tmbgriefergames.core.Addon; import tmb.randy.tmbgriefergames.core.IBridge; import tmb.randy.tmbgriefergames.v1_12_2.util.chat.ChatCleaner; @@ -62,6 +63,7 @@ public class VersionisedBridge implements IBridge { private final AutoCrafter autoCrafter = new AutoCrafter(); private final AutoCrafterNew autoCrafterNew = new AutoCrafterNew(); private final AutoDecomp autoDecomp = new AutoDecomp(); + private final Auswurf auswurf = new Auswurf(); private GuiScreen lastGui; private static final int commandCountdownLimit = 20; @@ -106,7 +108,7 @@ public void mouseInput(MouseButtonEvent event) { if(!Addon.isGG()) return; - itemSaver.mouseInput(event); + itemSaver.mouseButtonEvent(event); autoHopper.mouseInput(event); flyTimer.onMouseButtonEvent(event); } @@ -149,6 +151,7 @@ public void tick(GameTickEvent event) { plotSwitch.tick(event); autoCrafterNew.onTickEvent(event); autoDecomp.onTickEvent(event); + auswurf.onTickEvent(event); commandCountdown(); } @@ -166,6 +169,7 @@ public void keyDown(KeyEvent event) { autoCrafter.onKeyEvent(event); autoCrafterNew.onKeyEvent(event); autoDecomp.onKeyEvent(event); + auswurf.onKeyEvent(event); } @Subscribe @@ -231,16 +235,6 @@ public String getItemRemoverValue() { return ItemClearTimerListener.getDisplayValue(); } - public static boolean isChatGuiOpen() { - for (IngameOverlayActivity activity : Laby.labyAPI().ingameOverlay().getActivities()) { - if(activity.isAcceptingInput()) { - return true; - } - } - - return false; - } - @Override public void startNewAutocrafter() { autoCrafterNew.startCrafter(); @@ -251,6 +245,9 @@ public boolean isCompActive() { return autoComp.isCompActive(); } + @Override + public void changeSlot(int slot) {Minecraft.getMinecraft().player.inventory.currentItem = slot;} + private static void commandCountdown() { if (commandCountdown > 0) { commandCountdown--; @@ -267,10 +264,38 @@ public static boolean sendCommand(String command) { return false; } + public static boolean isChatGuiOpen() { + for (IngameOverlayActivity activity : Laby.labyAPI().ingameOverlay().getActivities()) { + if(activity.isAcceptingInput()) { + return true; + } + } + + return false; + } + public static boolean isGUIOpen() { GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen; - // Check if a GUI is open and if it is a chest GUI return currentScreen instanceof GuiChest || currentScreen instanceof GuiInventory || currentScreen instanceof GuiCrafting; } + + public static boolean allKeysPressed(Key[] keys) { + if(keys.length == 0) + return false; + + if(isGUIOpen()) + return false; + + for (Key key : keys) { + if(!Keyboard.isKeyDown(key.getId())) + return false; + } + return true; + } + + @Override + public void startAuswurf() { + auswurf.startAuswurf(); + } } diff --git a/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/chat/MsgTabs.java b/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/chat/MsgTabs.java index bce0a5c..12e97b3 100644 --- a/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/chat/MsgTabs.java +++ b/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/chat/MsgTabs.java @@ -1,5 +1,6 @@ package tmb.randy.tmbgriefergames.v1_12_2.util.chat; +import net.labymod.api.Laby; import net.labymod.api.client.chat.filter.ChatFilter; import net.labymod.api.configuration.labymod.chat.ChatTab; import net.labymod.api.configuration.labymod.chat.ChatWindow; @@ -26,6 +27,7 @@ public void chatMessageReceived(ChatReceiveEvent event) { getTabForName(event.chatMessage().getPlainText()); if(!VersionisedBridge.isChatGuiOpen() && event.chatMessage().getPlainText().contains("[mir -> ")) { + reloadChat(); Minecraft.getMinecraft().displayGuiScreen(new GuiChat()); } } @@ -132,12 +134,16 @@ private ChatWindow getChatWindow() { } private String getChatPartnerName(String message) { - String[] split = message.split(" "); - if(split.length >= 5) { - if(split[0].equals("[mir") && split[1].equals("->")) { - return split[4].replace("]", ""); - } else if(split[3].equals("->") && split[4].equals("mir]")) { - return split[2]; + if(message.contains("[mir ->") || message.contains("-> mir]")) { + String[] split = message.split(" "); + if(split.length >= 5) { + boolean returnNext = false; + for (String string : split) { + if(returnNext) + return string.replace("[", "").replace("]", ""); + else if(string.equals("┃")) + returnNext = true; + } } } @@ -145,12 +151,16 @@ private String getChatPartnerName(String message) { } private String getChatPartnerRank(String message) { - String[] split = message.split(" "); - if(split.length >= 5) { - if(split[0].equals("[mir") && split[1].equals("->")) { - return split[2]; - } else if(split[3].equals("->") && split[4].equals("mir]")) { - return split[0].replace("[", ""); + if(message.contains("[mir ->") || message.contains("-> mir]")) { + String[] split = message.split(" "); + String previous = ""; + + for (String string : split) { + if(string.equals("┃")) { + return previous.replace("[", "").replace("]", ""); + } else { + previous = string; + } } } @@ -160,4 +170,8 @@ private String getChatPartnerRank(String message) { public static void resetCurrentChatPartner() { currentChatPartner = null; } -} + + private void reloadChat() { + Laby.references().chatAccessor().reload(); + } +} \ No newline at end of file diff --git a/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/chat/PaymentValidator.java b/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/chat/PaymentValidator.java index 38386c6..966336d 100644 --- a/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/chat/PaymentValidator.java +++ b/game-runner/src/v1_12_2/java/tmb/randy/tmbgriefergames/v1_12_2/util/chat/PaymentValidator.java @@ -8,28 +8,25 @@ public class PaymentValidator { + private final static String FAKEMONEY_PREFIX = "§4§l[§c§l✖ " + I18n.translate("autocraft.chat.fakeMoney") + "§4§l]"; + final String VALID_PREFIX = "§2§l[§a§l✔ " + I18n.translate("tmbgriefergames.chat.realMoney") + "§2§l]"; + public void messageReceived(ChatReceiveEvent event) { - if(!Addon.getSharedInstance().configuration().getChatConfig().getAntiFakeMoney().get()) + if(!Addon.isGG() || !Addon.getSharedInstance().configuration().getChatConfig().getAntiFakeMoney().get()) { return; + } String message = event.chatMessage().getPlainText(); - boolean isValid = false; - if(message.contains("hat dir") && message.contains("gegeben")) { if(message.matches(".* hat dir \\$\\d{1,3}(?:,\\d{3})*(\\.\\d{2})? gegeben\\.")) { - if(!message.contains("[") && !message.contains("]")) { - isValid = true; + if(!message.contains("[Greeting]")) { + event.setMessage(event.message().append(Component.text(VALID_PREFIX))); + return; } } - if(isValid) { - final String VALID_PREFIX = "§2§l[§a§l✔ " + I18n.translate("tmbgriefergames.chat.realMoney") + "§2§l]"; - event.setMessage(event.message().append(Component.text(VALID_PREFIX))); - } else { - final String FAKEMONEY_PREFIX = "§4§l[§c§l✖ " + I18n.translate("tmbgriefergames.chat.fakeMoney") + "§4§l]"; - event.setMessage(event.message().append(Component.text(FAKEMONEY_PREFIX))); - } + event.setMessage(event.message().append(Component.text(FAKEMONEY_PREFIX))); } } } diff --git a/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/Auswurf.java b/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/Auswurf.java new file mode 100644 index 0000000..7b6c03e --- /dev/null +++ b/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/Auswurf.java @@ -0,0 +1,100 @@ +package tmb.randy.tmbgriefergames.v1_8_9.util; + +import net.labymod.api.client.gui.screen.key.Key; +import net.labymod.api.event.client.input.KeyEvent; +import net.labymod.api.event.client.input.KeyEvent.State; +import net.labymod.api.event.client.lifecycle.GameTickEvent; +import net.labymod.api.util.I18n; +import net.minecraft.block.BlockChest; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.inventory.ContainerChest; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.util.BlockPos; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.MovingObjectPosition.MovingObjectType; +import tmb.randy.tmbgriefergames.core.Addon; +import tmb.randy.tmbgriefergames.core.enums.QueueType; +import tmb.randy.tmbgriefergames.v1_8_9.util.click.ClickManager; + +public class Auswurf { + private boolean active; + private BlockPos chestPos; + + public void onTickEvent(GameTickEvent event) { + if(active && Minecraft.getMinecraft().thePlayer != null && Minecraft.getMinecraft().theWorld != null) { + if(Minecraft.getMinecraft().thePlayer.openContainer instanceof ContainerChest chest) { + IInventory inv = chest.getLowerChestInventory(); + if(inv.getName().startsWith("§0Lager: ")) { + if(chestPos == null) { + chestPos = getChestPos(); + } else { + if(ClickManager.getSharedInstance().isClickQueueEmpty(QueueType.MEDIUM)) { + for (int i = 0; i < 25; i++) { + Slot slot = chest.getSlot(i); + if(slot.getHasStack()) { + ClickManager.getSharedInstance().dropClick(i); + } + } + + if(ClickManager.getSharedInstance().isClickQueueEmpty(QueueType.MEDIUM)) { + Minecraft.getMinecraft().displayGuiScreen(null); + Minecraft.getMinecraft().thePlayer.closeScreen(); + MovingObjectPosition rayTraceResult = Minecraft.getMinecraft().objectMouseOver; + if(rayTraceResult.typeOfHit == MovingObjectType.BLOCK && rayTraceResult.getBlockPos().equals(chestPos)) { + Minecraft.getMinecraft().playerController.onPlayerRightClick(Minecraft.getMinecraft().thePlayer, Minecraft.getMinecraft().theWorld, Minecraft.getMinecraft().thePlayer.getHeldItem(), chestPos, rayTraceResult.sideHit, rayTraceResult.hitVec); + } + + } + } + } + } + } + } + } + + public void onKeyEvent(KeyEvent event) { + if(event.state() == State.PRESS) { + if (active && event.key() == Key.ESCAPE) { + ClickManager.getSharedInstance().clearAllQueues(); + Addon.getSharedInstance().displayNotification(I18n.getTranslation("tmbgriefergames.eject.disabled")); + chestPos = null; + active = false; + } + } + } + + public void startAuswurf() { + Addon.getSharedInstance().displayNotification(I18n.getTranslation("tmbgriefergames.eject.enabled")); + active = true; + } + + private static BlockPos getChestPos() { + Minecraft mc = Minecraft.getMinecraft(); + MovingObjectPosition rayTraceResult = mc.objectMouseOver; + + if (rayTraceResult != null && rayTraceResult.typeOfHit == MovingObjectType.BLOCK) { + BlockPos blockPosition = rayTraceResult.getBlockPos(); + IBlockState blockState = mc.theWorld.getBlockState(blockPosition); + + if (blockState.getBlock() instanceof BlockChest) { + return blockPosition; + } + } + + return null; + } + + private static Entity getEntityInBlockPos(BlockPos pos) { + Minecraft mc = Minecraft.getMinecraft(); + for (Entity entity : mc.theWorld.loadedEntityList) { + if (entity instanceof EntityLivingBase && entity.getDistanceSq(pos) < 2) { + return entity; + } + } + return null; + } +} diff --git a/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/AutoComp.java b/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/AutoComp.java index 2a89c0d..e4efc54 100644 --- a/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/AutoComp.java +++ b/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/AutoComp.java @@ -53,7 +53,7 @@ public void onKeyEvent(KeyEvent event) { } } } else { - if (Addon.areKeysPressed(Addon.getSharedInstance().configuration().getAutoCrafterConfig().getAutoCompHotkey().get())) { + if (VersionisedBridge.allKeysPressed(Addon.getSharedInstance().configuration().getAutoCrafterConfig().getAutoCompHotkey().get())) { startComp(); } } diff --git a/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/AutoDecomp.java b/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/AutoDecomp.java index e081a15..6e7299e 100644 --- a/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/AutoDecomp.java +++ b/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/AutoDecomp.java @@ -26,7 +26,7 @@ public class AutoDecomp { public void onKeyEvent(KeyEvent event) { if(Key.ESCAPE.isPressed() && autoDecompActive) { stopDecomp(); - } else if (Addon.areKeysPressed(Addon.getSharedInstance().configuration().getAutoCrafterConfig().getAutoDecompHotkey().get())) { + } else if (VersionisedBridge.allKeysPressed(Addon.getSharedInstance().configuration().getAutoCrafterConfig().getAutoDecompHotkey().get())) { startDecomp(); Addon.getSharedInstance().displayNotification(I18n.getTranslation("tmbgriefergames.autoDecomp.started")); } diff --git a/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/ItemSaver.java b/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/ItemSaver.java index 174e599..9009f6f 100644 --- a/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/ItemSaver.java +++ b/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/ItemSaver.java @@ -2,6 +2,7 @@ import net.labymod.api.Laby; import net.labymod.api.client.world.item.ItemStack; +import net.labymod.api.component.data.DataComponentKey; import net.labymod.api.event.client.input.MouseButtonEvent; import net.labymod.api.event.client.input.MouseButtonEvent.Action; import net.labymod.api.util.I18n; @@ -16,31 +17,27 @@ public class ItemSaver { public static final String NBTTagStringBirthBow = "[0:{lvl:22s,id:48s},1:{lvl:4s,id:49s},2:{lvl:1s,id:51s},3:{lvl:4s,id:19s},4:{lvl:22s,id:21s}]"; - public void mouseInput(MouseButtonEvent event) { - if(!Addon.getSharedInstance().configuration().getItemProtection().get()) - return; + public void mouseButtonEvent(MouseButtonEvent event) { if(Laby.labyAPI().minecraft().getClientPlayer() != null) { if(Laby.labyAPI().minecraft().getClientPlayer().getMainHandItemStack() != null) { ItemStack stack = Laby.labyAPI().minecraft().getClientPlayer().getMainHandItemStack(); + if(stack.hasDataComponentContainer()) { + if(stack.getDataComponentContainer().has(DataComponentKey.simple("ench"))) { + String enchantments = stack.getDataComponentContainer().get(DataComponentKey.simple("ench")).toString(); - if(stack.hasNBTTag()) { - if(stack.getNBTTag().contains("ench")) { - String enchantments = stack.getNBTTag().get("ench").toString(); - - //Unfortunately there is a bug within LabyMod which doesn't cancel the event in MouseButtonEvent after performing event.setCancelled(true) for some players. So switching the slot to save the item is a workaround. As LabyMod support couldn't reproduce and fix the bug this is the only option to save the item. - if(event.action() == Action.CLICK) { + if(event.action() == Action.CLICK) { if((enchantments.equals(NBTTagStringBonze) || enchantments.equals(NBTTagStringBirthSword)) && event.button().isLeft()) { Addon.getSharedInstance().displayNotification("§4§l" + I18n.translate("tmbgriefergames.itemSaver.item_saver_message_sword")); - changeSlot(findHotbarSlotforItem()); + Addon.getSharedInstance().getBridge().changeSlot(findHotbarSlotforItem()); event.setCancelled(true); } else if(enchantments.equals(NBTTagStringSoS) && event.button().isRight()) { Addon.getSharedInstance().displayNotification("§4§l" + I18n.translate("tmbgriefergames.itemSaver.item_saver_message_sos")); - changeSlot(findHotbarSlotforBlock()); + Addon.getSharedInstance().getBridge().changeSlot(findHotbarSlotforBlock()); event.setCancelled(true); } else if(enchantments.equals(NBTTagStringBirthBow) && event.button().isRight()) { Addon.getSharedInstance().displayNotification("§4§l" + I18n.translate("tmbgriefergames.itemSaver.item_saver_message_birth_bow")); - changeSlot(findHotbarSlotforItem()); + Addon.getSharedInstance().getBridge().changeSlot(findHotbarSlotforItem()); event.setCancelled(true); } } @@ -70,7 +67,7 @@ public static int findHotbarSlotforBlock() { for (int i = 0; i < 9; i++) { ItemStack stack = Laby.labyAPI().minecraft().getClientPlayer().inventory().itemStackAt(i); - if(stack.isBlock() && !stack.hasNBTTag()) { + if(stack.isBlock() && !stack.hasDataComponentContainer()) { return i; } } @@ -98,7 +95,7 @@ public static int findHotbarSlotforItem() { for (int i = 0; i < 9; i++) { ItemStack stack = Laby.labyAPI().minecraft().getClientPlayer().inventory().itemStackAt(i); - if(stack.isItem() && !stack.hasNBTTag()) { + if(stack.isItem() && !stack.hasDataComponentContainer()) { return i; } } @@ -106,7 +103,4 @@ public static int findHotbarSlotforItem() { return Laby.labyAPI().minecraft().getClientPlayer().inventory().getSelectedIndex() == 8 ? 0 : Laby.labyAPI().minecraft().getClientPlayer().inventory().getSelectedIndex() + 1; } - public void changeSlot(int slot) { - Minecraft.getMinecraft().thePlayer.inventory.currentItem = slot; - } } diff --git a/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/ItemShifter.java b/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/ItemShifter.java index 25eb7ce..10fdb70 100644 --- a/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/ItemShifter.java +++ b/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/ItemShifter.java @@ -13,6 +13,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import org.apache.commons.lang3.ArrayUtils; +import org.lwjgl.input.Keyboard; import tmb.randy.tmbgriefergames.core.enums.QueueType; import tmb.randy.tmbgriefergames.v1_8_9.util.click.Click; import tmb.randy.tmbgriefergames.v1_8_9.util.click.ClickManager; @@ -147,7 +148,7 @@ public void tick(GameTickEvent event) { public void onKey(KeyEvent event) { if ((event.key() == Key.ARROW_UP || event.key() == Key.ARROW_LEFT || event.key() == Key.ARROW_RIGHT) && - Key.ARROW_UP.isPressed() && Key.ARROW_LEFT.isPressed() && Key.ARROW_RIGHT.isPressed() && + Keyboard.isKeyDown(Key.ARROW_UP.getId()) && Keyboard.isKeyDown(Key.ARROW_LEFT.getId()) && Keyboard.isKeyDown(Key.ARROW_RIGHT.getId()) && Minecraft.getMinecraft().thePlayer.openContainer != null && ClickManager.getSharedInstance().isClickQueueEmpty(QueueType.MEDIUM) && Minecraft.getMinecraft().currentScreen instanceof GuiInventory) { ClickManager.getSharedInstance().dropInventory(); } diff --git a/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/NatureBordersRenderer.java b/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/NatureBordersRenderer.java index 2f046d5..604f4bb 100644 --- a/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/NatureBordersRenderer.java +++ b/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/NatureBordersRenderer.java @@ -37,7 +37,7 @@ public static double getDistanceSq(double x1, double z1, double x2, double z2) private float lineBlue = 0.0F; public void onKey(KeyEvent event) { - if(Addon.areKeysPressed(Addon.getSharedInstance().configuration().getNatureSubConfig().getHotkey().get())) { + if(VersionisedBridge.allKeysPressed(Addon.getSharedInstance().configuration().getNatureSubConfig().getHotkey().get())) { Addon.getSharedInstance().configuration().getNatureSubConfig().getShowBorders().set(!Addon.getSharedInstance().configuration().getNatureSubConfig().getShowBorders().get()); String activeString = Addon.getSharedInstance().configuration().getNatureSubConfig().getShowBorders().get() ? I18n.getTranslation("tmbgriefergames.natureBorders.plotBordersVisible") : I18n.getTranslation("tmbgriefergames.natureBorders.plotBordersInvisible"); diff --git a/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/PlotSwitch.java b/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/PlotSwitch.java index d28b090..d792ba2 100644 --- a/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/PlotSwitch.java +++ b/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/PlotSwitch.java @@ -69,9 +69,9 @@ public void keyDown(KeyEvent event) { String command = null; if(event.state() == State.PRESS) { - if(Addon.areKeysPressed(Addon.getSharedInstance().configuration().getPreviousPlot().get())) { + if(VersionisedBridge.allKeysPressed(Addon.getSharedInstance().configuration().getPreviousPlot().get())) { command = getPlotCommand(lastPlot, DIRECTION.PREVIOUS); - } else if(Addon.areKeysPressed(Addon.getSharedInstance().configuration().getNextPlot().get())) { + } else if(VersionisedBridge.allKeysPressed(Addon.getSharedInstance().configuration().getNextPlot().get())) { command = getPlotCommand(lastPlot, DIRECTION.NEXT); } diff --git a/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/TooltipExtension.java b/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/TooltipExtension.java index 2a31426..d7d6ae3 100644 --- a/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/TooltipExtension.java +++ b/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/TooltipExtension.java @@ -1,60 +1,64 @@ package tmb.randy.tmbgriefergames.v1_8_9.util; -import java.util.Objects; import net.labymod.api.client.component.Component; import net.labymod.api.client.world.item.ItemStack; +import net.labymod.api.component.data.DataComponentKey; import net.labymod.api.event.client.world.ItemStackTooltipEvent; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagInt; import tmb.randy.tmbgriefergames.core.Addon; public class TooltipExtension { - public void renderTooltip(ItemStackTooltipEvent event) { - if(!Addon.isGG()) { - return; - } + public void renderTooltip(ItemStackTooltipEvent event) { + if(!Addon.isGG()) { + return; + } - ItemStack stack = event.itemStack(); + ItemStack stack = event.itemStack(); - if(stack.hasNBTTag()) { + if(stack.hasDataComponentContainer()) { - if(Addon.getSharedInstance().configuration().getTooltipConfig().getShowCompTooltip().get() && (stack.getNBTTag().contains("currentAmount") || stack.getNBTTag().contains("stackSize"))) { - // Show com item size - int currentAmount; + if(Addon.getSharedInstance().configuration().getTooltipConfig().getShowCompTooltip().get() && (stack.getDataComponentContainer().has( + DataComponentKey.simple("currentAmount")) || stack.getDataComponentContainer().has(DataComponentKey.simple("stackSize")))) { + // Show com item size + int currentAmount; - if(stack.getNBTTag().contains("currentAmount")) { - currentAmount = stack.getNBTTag().getInt("currentAmount") * stack.getSize(); - } else { - currentAmount = stack.getNBTTag().getInt("stackSize") * stack.getSize(); - } + if(stack.getDataComponentContainer().has(DataComponentKey.simple("currentAmount"))) { + currentAmount = ((NBTTagInt)stack.getDataComponentContainer().get(DataComponentKey.simple("currentAmount"))).getInt() * stack.getSize(); + } else { + currentAmount = ((NBTTagInt)stack.getDataComponentContainer().get(DataComponentKey.simple("stackSize"))).getInt() * stack.getSize(); + } - int maxStackSize = stack.getMaximumStackSize(); + int maxStackSize = stack.getMaximumStackSize(); - int DKs = currentAmount / (maxStackSize * 9 * 6); - int rest = currentAmount - (DKs * maxStackSize * 9 * 6); + int DKs = currentAmount / (maxStackSize * 9 * 6); + int rest = currentAmount - (DKs * maxStackSize * 9 * 6); - int stacks = rest / maxStackSize; - int items = rest - (stacks * maxStackSize); + int stacks = rest / maxStackSize; + int items = rest - (stacks * maxStackSize); - event.getTooltipLines().add(Component.translatable("tmbgriefergames.tooltip.compressedTooltip", Component.text(DKs), Component.text(stacks), Component.text(items))); - } else if(Addon.getSharedInstance().configuration().getTooltipConfig().getShowAdventurerTooltip().get() && Objects.requireNonNull(stack.getNBTTag()).contains("adventure")) { - // Show extended adventurer tool data - int amount = stack.getNBTTag().getCompound("adventure").getInt("adventure.amount"); - int total = stack.getNBTTag().getCompound("adventure").getInt("adventure.req_amount"); - float percent = 100f / (float)total * (float)amount; + event.getTooltipLines().add(Component.translatable("tmbgriefergames.tooltip.compressedTooltip", Component.text(DKs), Component.text(stacks), Component.text(items))); + } else if(Addon.getSharedInstance().configuration().getTooltipConfig().getShowAdventurerTooltip().get() && stack.getDataComponentContainer().has(DataComponentKey.simple("adventure"))) { + // Show extended adventurer tool data + int amount = ((NBTTagCompound)stack.getDataComponentContainer().get(DataComponentKey.simple("adventure"))).getInteger("adventure.amount"); + int total = ((NBTTagCompound)stack.getDataComponentContainer().get(DataComponentKey.simple("adventure"))).getInteger("adventure.req_amount"); - int needed = total - amount; + float percent = 100f / (float)total * (float)amount; - int DKs = needed / (64 * 9 * 6); - int rest = needed - (DKs * 64 * 9 * 6); + int needed = total - amount; - int stacks = rest / 64; - int items = rest - (stacks * 64); + int DKs = needed / (64 * 9 * 6); + int rest = needed - (DKs * 64 * 9 * 6); - float percentRounded = Math.round(percent * 10) / 10.0f; - event.getTooltipLines().add(Component.translatable("tmbgriefergames.tooltip.adventurerTooltip", Component.text(percentRounded), Component.text(DKs), Component.text(stacks), Component.text(items))); + int stacks = rest / 64; + int items = rest - (stacks * 64); + + float percentRounded = Math.round(percent * 10) / 10.0f; + event.getTooltipLines().add(Component.translatable("tmbgriefergames.tooltip.adventurerTooltip", Component.text(percentRounded), Component.text(DKs), Component.text(stacks), Component.text(items))); + } } } - } } diff --git a/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/VersionisedBridge.java b/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/VersionisedBridge.java index b5b5dc1..3e3aeaa 100644 --- a/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/VersionisedBridge.java +++ b/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/VersionisedBridge.java @@ -2,6 +2,7 @@ import net.labymod.api.Laby; import net.labymod.api.client.gui.screen.activity.types.IngameOverlayActivity; +import net.labymod.api.client.gui.screen.key.Key; import net.labymod.api.event.Phase; import net.labymod.api.event.Priority; import net.labymod.api.event.Subscribe; @@ -22,6 +23,7 @@ import net.minecraft.client.gui.inventory.GuiChest; import net.minecraft.client.gui.inventory.GuiCrafting; import net.minecraft.client.gui.inventory.GuiInventory; +import org.lwjgl.input.Keyboard; import tmb.randy.tmbgriefergames.core.Addon; import tmb.randy.tmbgriefergames.core.IBridge; import tmb.randy.tmbgriefergames.v1_8_9.util.chat.ChatCleaner; @@ -61,6 +63,7 @@ public class VersionisedBridge implements IBridge { private final AutoCrafter autoCrafter = new AutoCrafter(); private final AutoDecomp autoDecomp = new AutoDecomp(); private final AutoComp autoComp = new AutoComp(); + private final Auswurf auswurf = new Auswurf(); private GuiScreen lastGui; @@ -106,7 +109,7 @@ public void mouseInput(MouseButtonEvent event) { if(!Addon.isGG()) return; - itemSaver.mouseInput(event); + itemSaver.mouseButtonEvent(event); autoHopper.mouseInput(event); flyTimer.onMouseButtonEvent(event); } @@ -149,6 +152,7 @@ public void tick(GameTickEvent event) { plotSwitch.tick(event); autoCrafterNew.onTickEvent(event); autoDecomp.onTickEvent(event); + auswurf.onTickEvent(event); commandCountdown(); } @@ -166,6 +170,7 @@ public void keyDown(KeyEvent event) { autoCrafter.onKeyEvent(event); autoCrafterNew.onKeyEvent(event); autoDecomp.onKeyEvent(event); + auswurf.onKeyEvent(event); } @Subscribe @@ -241,6 +246,9 @@ public boolean isCompActive() { return autoComp.isCompActive(); } + @Override + public void changeSlot(int slot) {Minecraft.getMinecraft().thePlayer.inventory.currentItem = slot;} + private static void commandCountdown() { if (commandCountdown > 0) { commandCountdown--; @@ -257,13 +265,6 @@ public static boolean sendCommand(String command) { return false; } - public static boolean isGUIOpen() { - GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen; - - // Check if a GUI is open and if it is a chest GUI - return currentScreen instanceof GuiChest || currentScreen instanceof GuiInventory || currentScreen instanceof GuiCrafting; - } - public static boolean isChatGuiOpen() { for (IngameOverlayActivity activity : Laby.labyAPI().ingameOverlay().getActivities()) { if(activity.isAcceptingInput()) { @@ -273,4 +274,31 @@ public static boolean isChatGuiOpen() { return false; } + + public static boolean isGUIOpen() { + GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen; + + return currentScreen instanceof GuiChest || currentScreen instanceof GuiInventory || currentScreen instanceof GuiCrafting; + } + + public static boolean allKeysPressed(Key[] keys) { + if(keys.length == 0) + return false; + + if(isGUIOpen()) + return false; + + for (Key key : keys) { + if(!Keyboard.isKeyDown(key.getId())) + return false; + } + return true; + } + + @Override + public void startAuswurf() { + auswurf.startAuswurf(); + } + + } diff --git a/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/chat/MsgTabs.java b/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/chat/MsgTabs.java index 9553408..bc8cf5d 100644 --- a/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/chat/MsgTabs.java +++ b/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/chat/MsgTabs.java @@ -1,5 +1,6 @@ package tmb.randy.tmbgriefergames.v1_8_9.util.chat; +import net.labymod.api.Laby; import net.labymod.api.client.chat.filter.ChatFilter; import net.labymod.api.configuration.labymod.chat.ChatTab; import net.labymod.api.configuration.labymod.chat.ChatWindow; @@ -26,6 +27,7 @@ public void chatMessageReceived(ChatReceiveEvent event) { getTabForName(event.chatMessage().getPlainText()); if(!VersionisedBridge.isChatGuiOpen() && event.chatMessage().getPlainText().contains("[mir -> ")) { + reloadChat(); Minecraft.getMinecraft().displayGuiScreen(new GuiChat()); } } @@ -132,12 +134,16 @@ private ChatWindow getChatWindow() { } private String getChatPartnerName(String message) { - String[] split = message.split(" "); - if(split.length >= 5) { - if(split[0].equals("[mir") && split[1].equals("->")) { - return split[4].replace("]", ""); - } else if(split[3].equals("->") && split[4].equals("mir]")) { - return split[2]; + if(message.contains("[mir ->") || message.contains("-> mir]")) { + String[] split = message.split(" "); + if(split.length >= 5) { + boolean returnNext = false; + for (String string : split) { + if(returnNext) + return string.replace("[", "").replace("]", ""); + else if(string.equals("┃")) + returnNext = true; + } } } @@ -145,12 +151,16 @@ private String getChatPartnerName(String message) { } private String getChatPartnerRank(String message) { - String[] split = message.split(" "); - if(split.length >= 5) { - if(split[0].equals("[mir") && split[1].equals("->")) { - return split[2]; - } else if(split[3].equals("->") && split[4].equals("mir]")) { - return split[0].replace("[", ""); + if(message.contains("[mir ->") || message.contains("-> mir]")) { + String[] split = message.split(" "); + String previous = ""; + + for (String string : split) { + if(string.equals("┃")) { + return previous.replace("[", "").replace("]", ""); + } else { + previous = string; + } } } @@ -160,4 +170,8 @@ private String getChatPartnerRank(String message) { public static void resetCurrentChatPartner() { currentChatPartner = null; } + + private void reloadChat() { + Laby.references().chatAccessor().reload(); + } } diff --git a/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/chat/PaymentValidator.java b/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/chat/PaymentValidator.java index 7366fc7..20ce4ef 100644 --- a/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/chat/PaymentValidator.java +++ b/game-runner/src/v1_8_9/java/tmb/randy/tmbgriefergames/v1_8_9/util/chat/PaymentValidator.java @@ -7,28 +7,25 @@ public class PaymentValidator { + private final static String FAKEMONEY_PREFIX = "§4§l[§c§l✖ " + I18n.translate("autocraft.chat.fakeMoney") + "§4§l]"; + final String VALID_PREFIX = "§2§l[§a§l✔ " + I18n.translate("tmbgriefergames.chat.realMoney") + "§2§l]"; + public void messageReceived(ChatReceiveEvent event) { - if(!Addon.getSharedInstance().configuration().getChatConfig().getAntiFakeMoney().get()) + if(!Addon.isGG() || !Addon.getSharedInstance().configuration().getChatConfig().getAntiFakeMoney().get()) { return; + } String message = event.chatMessage().getPlainText(); - boolean isValid = false; - if(message.contains("hat dir") && message.contains("gegeben")) { if(message.matches(".* hat dir \\$\\d{1,3}(?:,\\d{3})*(\\.\\d{2})? gegeben\\.")) { - if(!message.contains("[") && !message.contains("]")) { - isValid = true; + if(!message.contains("[Greeting]")) { + event.setMessage(event.message().append(Component.text(VALID_PREFIX))); + return; } } - if(isValid) { - final String VALID_PREFIX = "§2§l[§a§l✔ " + I18n.translate("tmbgriefergames.chat.realMoney") + "§2§l]"; - event.setMessage(event.message().append(Component.text(VALID_PREFIX))); - } else { - final String FAKEMONEY_PREFIX = "§4§l[§c§l✖ " + I18n.translate("tmbgriefergames.chat.fakeMoney") + "§4§l]"; - event.setMessage(event.message().append(Component.text(FAKEMONEY_PREFIX))); - } + event.setMessage(event.message().append(Component.text(FAKEMONEY_PREFIX))); } } -} +} \ No newline at end of file