mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-04 15:41:38 +00:00
初步添加emoji
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
templates:
|
||||
default:emoji/basic:
|
||||
content: "<hover:show_text:'<i18n:emoji.tip>'><arg:emoji></hover>"
|
||||
default:emoji/addition_info:
|
||||
content: "<hover:show_text:'<i18n:emoji.tip>'>{text}<arg:emoji></hover>"
|
||||
|
||||
emoji:
|
||||
default:emoji_location:
|
||||
template: "default:emoji/addition_info"
|
||||
arguments:
|
||||
text: "<i18n:emoji.location>"
|
||||
overrides:
|
||||
image: "default:icons:0:0"
|
||||
permission: emoji.location
|
||||
keywords:
|
||||
- ":location:"
|
||||
- ":pos:"
|
||||
default:emoji_time:
|
||||
template: "default:emoji/addition_info"
|
||||
arguments:
|
||||
text: "<i18n:emoji.time>"
|
||||
overrides:
|
||||
image: "default:icons:0:1"
|
||||
permission: emoji.time
|
||||
keywords:
|
||||
- ":time:"
|
||||
@@ -39,6 +39,9 @@ i18n:
|
||||
category.topaz: "Topaz"
|
||||
category.furniture: "Furniture"
|
||||
category.misc: "Misc"
|
||||
emoji.tip: "Use <yellow>'<arg:keyword>'</yellow> to send the '<arg:emoji>' emoji"
|
||||
emoji.time: "<bold>Current time: <papi:player_world_time_12></bold>"
|
||||
emoji.location: "<bold>Current coordinates: <papi:player_x>,<papi:player_y>,<papi:player_z></bold>"
|
||||
zh_cn:
|
||||
item.chinese_lantern: "灯笼"
|
||||
item.fairy_flower: "仙灵花"
|
||||
@@ -78,4 +81,7 @@ i18n:
|
||||
category.palm_tree: "棕榈树"
|
||||
category.topaz: "黄玉"
|
||||
category.furniture: "家具"
|
||||
category.misc: "杂项"
|
||||
category.misc: "杂项"
|
||||
emoji.tip: "使用<yellow>'<arg:keyword>'</yellow>来发送表情'<arg:emoji>'"
|
||||
emoji.time: "<bold>当前时间: <papi:player_world_time_12></bold>"
|
||||
emoji.location: "<bold>当前坐标: <papi:player_x>,<papi:player_y>,<papi:player_z></bold>"
|
||||
@@ -102,4 +102,7 @@ warning.config.block.state.model.lack_path: "<yellow>Issue found in file <arg:0>
|
||||
warning.config.block.state.model.invalid_resource_location: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' has a 'path' argument [<arg:2>] that contains legal characters. Please read https://minecraft.wiki/w/Resource_location#Legal_characters</yellow>"
|
||||
warning.config.model.generation.conflict: "<yellow>Issue found in file <arg:0> - Failed to generate model for '<arg:1>' as two or more configurations attempt to generate different json models with the same path: '<arg:2>'</yellow>"
|
||||
warning.config.model.generation.texture.invalid_resource_location: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' has a '<arg:2>' texture argument [<arg:3>] that contains legal characters. Please read https://minecraft.wiki/w/Resource_location#Legal_characters</yellow>"
|
||||
warning.config.model.generation.parent.invalid_resource_location: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' has a parent argument [<arg:2>] that contains legal characters. Please read https://minecraft.wiki/w/Resource_location#Legal_characters</yellow>"
|
||||
warning.config.model.generation.parent.invalid_resource_location: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' has a parent argument [<arg:2>] that contains legal characters. Please read https://minecraft.wiki/w/Resource_location#Legal_characters</yellow>"
|
||||
warning.config.emoji.lack_keywords: "<yellow>Issue found in file <arg:0> - The emoji '<arg:1>' is missing the required 'keywords' argument.</yellow>"
|
||||
warning.config.emoji.duplicated: "<yellow>Issue found in file <arg:0> - Duplicated emoji '<arg:1>'.</yellow>"
|
||||
warning.config.emoji.invalid_image: "<yellow>Issue found in file <arg:0> - The emoji '<arg:1>' has an invalid 'image' argument '<arg:2>'.</yellow>"
|
||||
@@ -102,4 +102,7 @@ warning.config.block.state.model.lack_path: "<yellow>在文件 <arg:0> 中发现
|
||||
warning.config.block.state.model.invalid_resource_location: "<yellow>在文件 <arg:0> 中发现问题 - 方块 '<arg:1>' 的 'path' 路径参数 [<arg:2>] 包含非法字符,请参考资源路径规范:https://zh.minecraft.wiki/w/%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4ID#%E5%90%88%E6%B3%95%E5%AD%97%E7%AC%A6</yellow>"
|
||||
warning.config.model.generation.conflict: "<yellow>在文件 <arg:0> 中发现问题 - 无法为 '<arg:1>' 生成模型,多个配置尝试用相同路径 '<arg:2>' 生成不同的JSON模型</yellow>"
|
||||
warning.config.model.generation.texture.invalid_resource_location: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 的 '<arg:2>' 纹理参数 [<arg:3>] 包含非法字符,请参考资源路径规范:https://zh.minecraft.wiki/w/%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4ID#%E5%90%88%E6%B3%95%E5%AD%97%E7%AC%A6</yellow>"
|
||||
warning.config.model.generation.parent.invalid_resource_location: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 的父模型参数 [<arg:2>] 包含非法字符,请参考资源路径规范:https://zh.minecraft.wiki/w/%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4ID#%E5%90%88%E6%B3%95%E5%AD%97%E7%AC%A6</yellow>"
|
||||
warning.config.model.generation.parent.invalid_resource_location: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 的父模型参数 [<arg:2>] 包含非法字符,请参考资源路径规范:https://zh.minecraft.wiki/w/%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4ID#%E5%90%88%E6%B3%95%E5%AD%97%E7%AC%A6</yellow>"
|
||||
warning.config.emoji.lack_keywords: "<yellow>在文件 <arg:0> 中发现问题 - 表情 '<arg:1>' 缺少必要的 'keywords' 配置</yellow>"
|
||||
warning.config.emoji.duplicated: "<yellow>在文件 <arg:0> 中发现问题 - 表情 '<arg:1>' 重复定义</yellow>"
|
||||
warning.config.emoji.invalid_image: "<yellow>在文件 <arg:0> 中发现问题 - 表情 '<arg:1>' 使用了无效的 'image' 图片参数 '<arg:2>'.</yellow>"
|
||||
@@ -2,7 +2,6 @@ package net.momirealms.craftengine.bukkit.font;
|
||||
|
||||
import io.papermc.paper.event.player.AsyncChatCommandDecorateEvent;
|
||||
import io.papermc.paper.event.player.AsyncChatDecorateEvent;
|
||||
import io.papermc.paper.event.player.PlayerSignCommandPreprocessEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.util.ComponentUtils;
|
||||
@@ -10,6 +9,7 @@ import net.momirealms.craftengine.bukkit.util.Reflections;
|
||||
import net.momirealms.craftengine.core.font.AbstractFontManager;
|
||||
import net.momirealms.craftengine.core.font.FontManager;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.plugin.text.minimessage.NamedArgumentTag;
|
||||
import net.momirealms.craftengine.core.util.CharacterUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -17,11 +17,10 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class BukkitFontManager extends AbstractFontManager implements Listener {
|
||||
private final BukkitCraftEngine plugin;
|
||||
@@ -59,10 +58,12 @@ public class BukkitFontManager extends AbstractFontManager implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onCommand(PlayerCommandPreprocessEvent event) {
|
||||
if (!Config.filterCommand()) return;
|
||||
if (event.getPlayer().hasPermission(FontManager.BYPASS_COMMAND)) {
|
||||
return;
|
||||
if (!event.getPlayer().hasPermission(FontManager.BYPASS_COMMAND)) {
|
||||
IllegalCharacterProcessResult result = processIllegalCharacters(event.getMessage());
|
||||
if (result.has()) {
|
||||
event.setMessage(result.newText());
|
||||
}
|
||||
}
|
||||
runIfContainsIllegalCharacter(event.getMessage(), event::setMessage);
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
@@ -71,23 +72,28 @@ public class BukkitFontManager extends AbstractFontManager implements Listener {
|
||||
if (player == null) return;
|
||||
try {
|
||||
Object originalMessage = Reflections.field$AsyncChatDecorateEvent$originalMessage.get(event);
|
||||
String jsonMessage = ComponentUtils.paperAdventureToJson(originalMessage);
|
||||
String rawJsonMessage = ComponentUtils.paperAdventureToJson(originalMessage);
|
||||
String jsonMessage = replaceEmoji(rawJsonMessage, this.plugin.adapt(player));
|
||||
boolean hasChanged = !rawJsonMessage.equals(jsonMessage);
|
||||
if (!player.hasPermission(FontManager.BYPASS_CHAT)) {
|
||||
runIfContainsIllegalCharacter(jsonMessage, (json) -> {
|
||||
Object component = ComponentUtils.jsonToPaperAdventure(json);
|
||||
try {
|
||||
Reflections.method$AsyncChatDecorateEvent$result.invoke(event, component);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
IllegalCharacterProcessResult result = processIllegalCharacters(jsonMessage);
|
||||
if (result.has()) {
|
||||
Object component = ComponentUtils.jsonToPaperAdventure(result.newText());
|
||||
Reflections.method$AsyncChatDecorateEvent$result.invoke(event, component);
|
||||
} else if (hasChanged) {
|
||||
Object component = ComponentUtils.jsonToPaperAdventure(jsonMessage);
|
||||
Reflections.method$AsyncChatDecorateEvent$result.invoke(event, component);
|
||||
}
|
||||
} else if (hasChanged) {
|
||||
Object component = ComponentUtils.jsonToPaperAdventure(jsonMessage);
|
||||
Reflections.method$AsyncChatDecorateEvent$result.invoke(event, component);
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void runIfContainsIllegalCharacter(String raw, Consumer<String> callback) {
|
||||
private IllegalCharacterProcessResult processIllegalCharacters(String raw) {
|
||||
boolean hasIllegal = false;
|
||||
// replace illegal image usage
|
||||
Map<String, Component> tokens = matchTags(raw);
|
||||
@@ -113,11 +119,24 @@ public class BukkitFontManager extends AbstractFontManager implements Listener {
|
||||
hasIllegal = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasIllegal) {
|
||||
callback.accept(new String(newCodepoints, 0, newCodepoints.length));
|
||||
return IllegalCharacterProcessResult.has(new String(newCodepoints, 0, newCodepoints.length));
|
||||
}
|
||||
} else if (hasIllegal) {
|
||||
callback.accept(raw);
|
||||
return IllegalCharacterProcessResult.has(raw);
|
||||
}
|
||||
return IllegalCharacterProcessResult.not();
|
||||
}
|
||||
|
||||
public record IllegalCharacterProcessResult(boolean has, String newText) {
|
||||
|
||||
public static IllegalCharacterProcessResult has(String newText) {
|
||||
return new IllegalCharacterProcessResult(true, newText);
|
||||
}
|
||||
|
||||
public static IllegalCharacterProcessResult not() {
|
||||
return new IllegalCharacterProcessResult(false, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user