aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextAdder.java18
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/TooltipAdder.java17
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/render/gui/AbstractContainerMatcher.java28
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/render/gui/ContainerSolver.java10
4 files changed, 43 insertions, 30 deletions
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;
}
diff --git a/src/main/java/de/hysky/skyblocker/utils/render/gui/AbstractContainerMatcher.java b/src/main/java/de/hysky/skyblocker/utils/render/gui/AbstractContainerMatcher.java
new file mode 100644
index 00000000..38864ec4
--- /dev/null
+++ b/src/main/java/de/hysky/skyblocker/utils/render/gui/AbstractContainerMatcher.java
@@ -0,0 +1,28 @@
+package de.hysky.skyblocker.utils.render.gui;
+
+import de.hysky.skyblocker.skyblock.ChestValue;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.regex.Pattern;
+
+public abstract class AbstractContainerMatcher {
+ /**
+ * The title of the screen must match this pattern for this 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 chest value.
+ */
+ @Nullable
+ public final Pattern titlePattern;
+
+ public AbstractContainerMatcher() {
+ this((Pattern) null);
+ }
+
+ public AbstractContainerMatcher(String titlePattern) {
+ this(Pattern.compile(titlePattern));
+ }
+
+ protected AbstractContainerMatcher(@Nullable Pattern titlePattern) {
+ this.titlePattern = titlePattern;
+ }
+}
diff --git a/src/main/java/de/hysky/skyblocker/utils/render/gui/ContainerSolver.java b/src/main/java/de/hysky/skyblocker/utils/render/gui/ContainerSolver.java
index 0417dc3c..81c9ebec 100644
--- a/src/main/java/de/hysky/skyblocker/utils/render/gui/ContainerSolver.java
+++ b/src/main/java/de/hysky/skyblocker/utils/render/gui/ContainerSolver.java
@@ -11,17 +11,15 @@ import java.util.regex.Pattern;
/**
* Abstract class for gui solvers. Extend this class to add a new gui solver, like terminal solvers or experiment solvers.
*/
-public abstract class ContainerSolver {
- private final Pattern containerName;
-
- protected ContainerSolver(String containerName) {
- this.containerName = Pattern.compile(containerName);
+public abstract class ContainerSolver extends AbstractContainerMatcher {
+ protected ContainerSolver(String titlePattern) {
+ super(titlePattern);
}
protected abstract boolean isEnabled();
public final Pattern getName() {
- return containerName;
+ return titlePattern;
}
protected void start(GenericContainerScreen screen) {