Add Emote to FilterType.java
Add EmoteList command.
This commit is contained in:
parent
643fb5a633
commit
3888298827
|
|
@ -3,6 +3,7 @@ package com.alttd.chat.managers;
|
||||||
import com.alttd.chat.ChatAPI;
|
import com.alttd.chat.ChatAPI;
|
||||||
import com.alttd.chat.config.RegexConfig;
|
import com.alttd.chat.config.RegexConfig;
|
||||||
import com.alttd.chat.objects.ChatFilter;
|
import com.alttd.chat.objects.ChatFilter;
|
||||||
|
import com.alttd.chat.objects.FilterType;
|
||||||
import com.alttd.chat.objects.ModifiableString;
|
import com.alttd.chat.objects.ModifiableString;
|
||||||
import com.alttd.chat.util.ALogger;
|
import com.alttd.chat.util.ALogger;
|
||||||
import net.luckperms.api.cacheddata.CachedPermissionData;
|
import net.luckperms.api.cacheddata.CachedPermissionData;
|
||||||
|
|
@ -17,11 +18,24 @@ public class RegexManager {
|
||||||
|
|
||||||
private static List<ChatFilter> chatFilters;
|
private static List<ChatFilter> chatFilters;
|
||||||
private static final Pattern pattern = Pattern.compile("(.)\\1{4,}");
|
private static final Pattern pattern = Pattern.compile("(.)\\1{4,}");
|
||||||
|
private static final List<ChatFilter> emotes = new ArrayList<>();
|
||||||
|
public static final List<String> emotesList = new ArrayList<>();
|
||||||
|
|
||||||
public static void initialize() {
|
public static void initialize() {
|
||||||
chatFilters = new ArrayList<>();
|
chatFilters = new ArrayList<>();
|
||||||
|
|
||||||
RegexConfig.init();
|
RegexConfig.init();
|
||||||
|
loadEmotes();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadEmotes() {
|
||||||
|
emotes.clear();
|
||||||
|
for(ChatFilter chatFilter : chatFilters) {
|
||||||
|
if (chatFilter.getType() != FilterType.EMOTE) return;
|
||||||
|
|
||||||
|
emotes.add(chatFilter);
|
||||||
|
emotesList.add(chatFilter.getRegex());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addFilter(ChatFilter filter) {
|
public static void addFilter(ChatFilter filter) {
|
||||||
|
|
@ -65,4 +79,11 @@ public class RegexManager {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<ChatFilter> getChatFilters() {
|
||||||
|
return chatFilters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<ChatFilter> getEmoteFilters() {
|
||||||
|
return emotes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
64
api/src/main/java/com/alttd/chat/objects/EmoteList.java
Normal file
64
api/src/main/java/com/alttd/chat/objects/EmoteList.java
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
package com.alttd.chat.objects;
|
||||||
|
|
||||||
|
import com.alttd.chat.config.Config;
|
||||||
|
import com.alttd.chat.managers.RegexManager;
|
||||||
|
import com.alttd.chat.util.Utility;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class EmoteList {
|
||||||
|
|
||||||
|
public static final Map<UUID, EmoteList> emoteLists = new HashMap<>();
|
||||||
|
public static final int pageSize = 7;
|
||||||
|
// public static int pages = RegexManager.getEmoteFilters().size() / pageSize;// TODO reload this when config is reloaded.
|
||||||
|
|
||||||
|
public static EmoteList getEmoteList(UUID uuid) {
|
||||||
|
synchronized (emoteLists) {
|
||||||
|
return emoteLists.computeIfAbsent(uuid, k -> new EmoteList());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int page;
|
||||||
|
public Component showEmotePage() {
|
||||||
|
int startIndex = page * pageSize;
|
||||||
|
int pages = RegexManager.getEmoteFilters().size() / pageSize;
|
||||||
|
int endIndex = Math.min(startIndex + pageSize, RegexManager.getEmoteFilters().size());
|
||||||
|
TagResolver placeholders = TagResolver.resolver(
|
||||||
|
Placeholder.unparsed("page", String.valueOf(page)),
|
||||||
|
Placeholder.unparsed("pages", String.valueOf(pages))
|
||||||
|
);
|
||||||
|
Component list = Utility.parseMiniMessage(Config.EMOTELIST_HEADER, placeholders);
|
||||||
|
|
||||||
|
for (int i = startIndex; i < endIndex; i++) {
|
||||||
|
ChatFilter emote = RegexManager.getEmoteFilters().get(i);
|
||||||
|
TagResolver emotes = TagResolver.resolver(
|
||||||
|
Placeholder.parsed("regex", emote.getRegex()),
|
||||||
|
Placeholder.parsed("emote", emote.getReplacement())
|
||||||
|
);
|
||||||
|
list = list.append(Utility.parseMiniMessage(Config.EMOTELIST_ITEM, emotes));
|
||||||
|
}
|
||||||
|
list = list.append(Utility.parseMiniMessage(Config.EMOTELIST_FOOTER, placeholders));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPage(int page) {
|
||||||
|
this.page = Math.min(page, RegexManager.getEmoteFilters().size() / pageSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void nextPage() {
|
||||||
|
this.page = Math.min(page + 1, RegexManager.getEmoteFilters().size() / pageSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void prevPage() {
|
||||||
|
this.page -= 1;
|
||||||
|
this.page = Math.max(page - 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@ package com.alttd.chat.objects;
|
||||||
|
|
||||||
public enum FilterType {
|
public enum FilterType {
|
||||||
REPLACE("replace"),
|
REPLACE("replace"),
|
||||||
|
EMOTE("emote"),
|
||||||
CHAT("chat"),
|
CHAT("chat"),
|
||||||
REPLACEMATCHER("replacematcher"),
|
REPLACEMATCHER("replacematcher"),
|
||||||
BLOCK("block");
|
BLOCK("block");
|
||||||
|
|
|
||||||
33
galaxy/src/main/java/com/alttd/chat/commands/Emotes.java
Normal file
33
galaxy/src/main/java/com/alttd/chat/commands/Emotes.java
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.alttd.chat.commands;
|
||||||
|
|
||||||
|
import com.alttd.chat.objects.EmoteList;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class Emotes implements CommandExecutor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||||
|
if(!(sender instanceof Player player)) { // must be a player
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
EmoteList emoteList = EmoteList.getEmoteList(player.getUniqueId());
|
||||||
|
if(args.length > 0) {
|
||||||
|
try {
|
||||||
|
int page = Integer.parseInt(args[0]);
|
||||||
|
emoteList.setPage(page);
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
|
switch (args[0].toLowerCase()) {
|
||||||
|
case "next" -> emoteList.nextPage();
|
||||||
|
case "prev", "previous" -> emoteList.prevPage();
|
||||||
|
default -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
player.sendMessage(emoteList.showEmotePage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user