From 075353427a81f2455e10367c6eb76031048826f2 Mon Sep 17 00:00:00 2001 From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> Date: Sun, 9 Jun 2024 13:11:44 +0800 Subject: Add AbstractContainerMatcher --- .../skyblock/item/slottext/SlotTextAdder.java | 18 +++++------------- .../skyblocker/skyblock/item/tooltip/TooltipAdder.java | 17 ++++++----------- 2 files changed, 11 insertions(+), 24 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker/skyblock/item') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextAdder.java index 7ffa5fba..6618cda1 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextAdder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextAdder.java @@ -1,10 +1,9 @@ package de.hysky.skyblocker.skyblock.item.slottext; import de.hysky.skyblocker.config.SkyblockerConfigManager; -import de.hysky.skyblocker.skyblock.ChestValue; +import de.hysky.skyblocker.utils.render.gui.AbstractContainerMatcher; import net.minecraft.screen.slot.Slot; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.regex.Pattern; @@ -12,21 +11,14 @@ import java.util.regex.Pattern; /** * Extend this class and add it to {@link SlotTextManager#adders} to add text to any arbitrary slot. */ -public abstract class SlotTextAdder { - /** - * The title of the screen must match this pattern for this adder to be applied. Null means it will be applied to all screens. - * @implNote Don't end your regex with a {@code $} as {@link ChestValue} appends text to the end of the title, - * so the regex will stop matching if the player uses it. - */ - public final @Nullable Pattern titlePattern; - +public abstract class SlotTextAdder extends AbstractContainerMatcher { /** * Utility constructor that will compile the given string into a pattern. * * @see #SlotTextAdder(Pattern) */ protected SlotTextAdder(@NotNull String titlePattern) { - this(Pattern.compile(titlePattern)); + super(titlePattern); } /** @@ -35,14 +27,14 @@ public abstract class SlotTextAdder { * @param titlePattern The pattern to match the screen title against. */ protected SlotTextAdder(@NotNull Pattern titlePattern) { - this.titlePattern = titlePattern; + super(titlePattern); } /** * Creates a SlotTextAdder that will be applied to all screens. */ protected SlotTextAdder() { - this.titlePattern = null; + super(); } /** diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/TooltipAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/TooltipAdder.java index 7c43957e..07b9ac30 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/TooltipAdder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/TooltipAdder.java @@ -1,6 +1,6 @@ package de.hysky.skyblocker.skyblock.item.tooltip; -import de.hysky.skyblocker.skyblock.ChestValue; +import de.hysky.skyblocker.utils.render.gui.AbstractContainerMatcher; import net.minecraft.screen.slot.Slot; import net.minecraft.text.Text; @@ -10,13 +10,7 @@ import java.util.regex.Pattern; /** * Extend this class and add it to {@link TooltipManager#adders} to add additional text to tooltips. */ -public abstract class TooltipAdder { - /** - * The title of the screen must match this pattern for this adder to be applied. Null means it will be applied to all screens. - * @implNote Don't end your regex with a {@code $} as {@link ChestValue} appends text to the end of the title, - * so the regex will stop matching if the player uses it. - */ - public final Pattern titlePattern; +public abstract class TooltipAdder extends AbstractContainerMatcher { /** * The priority of this adder. Lower priority means it will be applied first. * @apiNote Consider taking this value on your class' constructor and setting it from {@link TooltipManager#adders} to make it easy to read and maintain. @@ -24,11 +18,12 @@ public abstract class TooltipAdder { public final int priority; protected TooltipAdder(String titlePattern, int priority) { - this(Pattern.compile(titlePattern), priority); + super(titlePattern); + this.priority = priority; } protected TooltipAdder(Pattern titlePattern, int priority) { - this.titlePattern = titlePattern; + super(titlePattern); this.priority = priority; } @@ -36,7 +31,7 @@ public abstract class TooltipAdder { * Creates a TooltipAdder that will be applied to all screens. */ protected TooltipAdder(int priority) { - this.titlePattern = null; + super(); this.priority = priority; } -- cgit