Skip to content

Commit

Permalink
cleaned up lore matching
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamKracker committed Dec 11, 2024
1 parent 1f3f32f commit 69e692f
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
import codes.cookies.mod.events.InventoryEvents;
import codes.cookies.mod.events.api.InventoryContentUpdateEvent;
import codes.cookies.mod.translations.TranslationKeys;
import codes.cookies.mod.utils.cookies.CookiesUtils;
import codes.cookies.mod.utils.exceptions.ExceptionHandler;
import codes.cookies.mod.utils.items.CookiesDataComponentTypes;
import codes.cookies.mod.utils.skyblock.LocationUtils;
import codes.cookies.mod.utils.skyblock.inventories.ItemBuilder;
import com.google.common.util.concurrent.Runnables;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.component.ComponentType;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.CustomModelDataComponent;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.screen.slot.Slot;
Expand All @@ -26,13 +23,14 @@

import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class VisitorDropProtection implements TranslationKeys {

private static final Pattern rewardsPattern = Pattern.compile("Rewards:([\\S\\s]*)(?:Click|Missing)");

private VisitorDropProtection(HandledScreen<?> handledScreen) {
InventoryContentUpdateEvent.registerSlot(handledScreen.getScreenHandler(),
ExceptionHandler.wrap(this::updateSlots));
Expand Down Expand Up @@ -66,8 +64,9 @@ private boolean handleAcceptItem(ItemStack visitorItem) {
}
var lore = String.join("\n", visitorItem.get(DataComponentTypes.LORE).lines().stream().map(Text::getString).toArray(String[]::new));

if (!lore.matches("[\\S\\s]*Rewards:([\\S\\s]*)(?:Click|Missing)[\\S\\s]*")) {
CookiesUtils.sendMessage("Invalid lore: " + lore);
Matcher matcher = rewardsPattern.matcher(lore);

if (!matcher.find()) {
return false;
}

Expand Down Expand Up @@ -98,7 +97,6 @@ private boolean handleAcceptItem(ItemStack visitorItem) {
"Harbinger",
"Overgrown Grass",
"Dye",
"Copper",
};

private static final String[] commonDrops = new String[] {
Expand Down

0 comments on commit 69e692f

Please sign in to comment.