Add.. PAWS
This commit is contained in:
32
src/main/java/com/vixis/event/ChatKeywordHandler.java
Normal file
32
src/main/java/com/vixis/event/ChatKeywordHandler.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package com.vixis.event;
|
||||
|
||||
import com.vixis.Vixis;
|
||||
import com.vixis.advancement.VixisAdvancements;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.event.ServerChatEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = Vixis.MODID)
|
||||
public final class ChatKeywordHandler {
|
||||
private static final Pattern VORE_WORD = Pattern.compile("\\bvore\\b", Pattern.CASE_INSENSITIVE);
|
||||
private static final Pattern PAW_WORD = Pattern.compile("\\bpaws?\\b", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
private ChatKeywordHandler() {
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onChat(ServerChatEvent event) {
|
||||
String message = event.getMessage();
|
||||
grantIfMatch(event, message, VORE_WORD, VixisAdvancements.VORE_MENTIONED);
|
||||
grantIfMatch(event, message, PAW_WORD, VixisAdvancements.PAW_MENTIONED);
|
||||
}
|
||||
|
||||
private static void grantIfMatch(ServerChatEvent event, String message, Pattern pattern, ResourceLocation advancement) {
|
||||
if (pattern.matcher(message).find()) {
|
||||
VixisAdvancements.grant(event.getPlayer(), advancement);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user