aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock/barn/HungryHiker.java
blob: 828b68c34f225c2060d0a6997de74c4312bb0f6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package de.hysky.skyblocker.skyblock.barn;

import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.chat.ChatFilterResult;
import de.hysky.skyblocker.utils.chat.ChatPatternListener;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Text;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;

public class HungryHiker extends ChatPatternListener {

    private static final Map<String, String> foods;

    public HungryHiker() { super("^\\[NPC] Hungry Hiker: (The food I want is|(I asked for) food that is) ([a-zA-Z, '\\-]*\\.)$"); }

    @Override
    public ChatFilterResult state() {
    return SkyblockerConfigManager.get().otherLocations.barn.solveHungryHiker ? ChatFilterResult.FILTER : ChatFilterResult.PASS;
    }

    @Override
    public boolean onMatch(Text message, Matcher matcher) {
        MinecraftClient client = MinecraftClient.getInstance();
        if (client.player == null) return false;
        String foodDescription = matcher.group(3);
        String food = foods.get(foodDescription);
        if (food == null) return false;
        String middlePartOfTheMessageToSend = matcher.group(2) != null ? matcher.group(2) : matcher.group(1);
        Utils.sendMessageToBypassEvents(Text.of("§e[NPC] Hungry Hiker§f: " + middlePartOfTheMessageToSend + " " + food + "."));
        return true;
    }

    static {
        foods = new HashMap<>();
        foods.put("from a cow.", Text.translatable("item.minecraft.cooked_beef").getString());
        foods.put("meat from a fowl.", Text.translatable("item.minecraft.cooked_chicken").getString());
        foods.put("red on the inside, green on the outside.", Text.translatable("item.minecraft.melon_slice").getString());
        foods.put("a cooked potato.", Text.translatable("item.minecraft.baked_potato").getString());
        foods.put("a stew.", Text.translatable("item.minecraft.rabbit_stew").getString());
        foods.put("a grilled meat.", Text.translatable("item.minecraft.cooked_porkchop").getString());
        foods.put("red and crunchy.", Text.translatable("item.minecraft.apple").getString());
        foods.put("made of wheat.", Text.translatable("item.minecraft.bread").getString());
    }
}