mirror of
https://e.coding.net/circlecloud/MiaoChat.git
synced 2025-09-11 11:37:02 +00:00
47
src/main/java/pw/yumc/MiaoChat/MiaoChat.java
Normal file
47
src/main/java/pw/yumc/MiaoChat/MiaoChat.java
Normal file
@ -0,0 +1,47 @@
|
||||
package pw.yumc.MiaoChat;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import pw.yumc.MiaoChat.config.ChatConfig;
|
||||
import pw.yumc.MiaoChat.listeners.ChatListener;
|
||||
import pw.yumc.YumCore.commands.CommandArgument;
|
||||
import pw.yumc.YumCore.commands.CommandExecutor;
|
||||
import pw.yumc.YumCore.commands.CommandManager;
|
||||
import pw.yumc.YumCore.commands.annotation.Cmd;
|
||||
import pw.yumc.YumCore.commands.annotation.Help;
|
||||
import pw.yumc.YumCore.config.FileConfig;
|
||||
|
||||
public class MiaoChat extends JavaPlugin implements CommandExecutor {
|
||||
private ChatConfig chatConfig;
|
||||
private FileConfig config;
|
||||
|
||||
public ChatConfig getChatConfig() {
|
||||
return chatConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileConfiguration getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
new ChatListener();
|
||||
new CommandManager("MiaoChat", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
config = new FileConfig();
|
||||
chatConfig = new ChatConfig();
|
||||
}
|
||||
|
||||
@Cmd(permission = "MiaoChat.reload")
|
||||
@Help("重载配置文件")
|
||||
public void reload(final CommandArgument e) {
|
||||
config.reload();
|
||||
chatConfig.reload();
|
||||
e.getSender().sendMessage("§a配置文件已重载!");
|
||||
}
|
||||
}
|
6
src/main/java/pw/yumc/MiaoChat/config/CLICKTYPE.java
Normal file
6
src/main/java/pw/yumc/MiaoChat/config/CLICKTYPE.java
Normal file
@ -0,0 +1,6 @@
|
||||
package pw.yumc.MiaoChat.config;
|
||||
|
||||
public enum CLICKTYPE {
|
||||
COMMAND,
|
||||
SUGGEST;
|
||||
}
|
51
src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java
Normal file
51
src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java
Normal file
@ -0,0 +1,51 @@
|
||||
package pw.yumc.MiaoChat.config;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import pw.yumc.YumCore.bukkit.P;
|
||||
import pw.yumc.YumCore.config.FileConfig;
|
||||
|
||||
public class ChatConfig {
|
||||
private static String PrefixKey = "Format.Prefix";
|
||||
private static String SuffixKey = "Format.Suffix";
|
||||
private final FileConfig config;
|
||||
private final List<ChatMessagePart> prefixs;
|
||||
private final List<ChatMessagePart> suffixs;
|
||||
private ChatMessagePart player;
|
||||
|
||||
public ChatConfig() {
|
||||
config = P.getConfig();
|
||||
prefixs = new LinkedList<>();
|
||||
suffixs = new LinkedList<>();
|
||||
reload();
|
||||
}
|
||||
|
||||
public ChatMessagePart getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public List<ChatMessagePart> getPrefixs() {
|
||||
return prefixs;
|
||||
}
|
||||
|
||||
public List<ChatMessagePart> getSuffixs() {
|
||||
return suffixs;
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
prefixs.clear();
|
||||
if (config.isSet(PrefixKey)) {
|
||||
for (final String part : config.getConfigurationSection(PrefixKey).getKeys(false)) {
|
||||
prefixs.add(new ChatMessagePart(config.getConfigurationSection(PrefixKey + "." + part)));
|
||||
}
|
||||
}
|
||||
player = new ChatMessagePart(config.getConfigurationSection("Format.Player"));
|
||||
suffixs.clear();
|
||||
if (config.isSet(SuffixKey)) {
|
||||
for (final String part : config.getConfigurationSection(SuffixKey).getKeys(false)) {
|
||||
suffixs.add(new ChatMessagePart(config.getConfigurationSection(SuffixKey + "." + part)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
52
src/main/java/pw/yumc/MiaoChat/config/ChatMessagePart.java
Normal file
52
src/main/java/pw/yumc/MiaoChat/config/ChatMessagePart.java
Normal file
@ -0,0 +1,52 @@
|
||||
package pw.yumc.MiaoChat.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import pw.yumc.YumCore.config.ConfigNode;
|
||||
import pw.yumc.YumCore.config.InjectConfigurationSection;
|
||||
import pw.yumc.YumCore.tellraw.Tellraw;
|
||||
|
||||
public class ChatMessagePart extends InjectConfigurationSection {
|
||||
private String text;
|
||||
private List<String> tip;
|
||||
@ConfigNode("click.type")
|
||||
private String typestring;
|
||||
private transient CLICKTYPE type = CLICKTYPE.SUGGEST;
|
||||
@ConfigNode("click.command")
|
||||
private String command;
|
||||
|
||||
public ChatMessagePart(final ConfigurationSection config) {
|
||||
super(config);
|
||||
if (typestring != null) {
|
||||
type = CLICKTYPE.valueOf(typestring);
|
||||
}
|
||||
}
|
||||
|
||||
public Tellraw then(final Tellraw tr, final Player p) {
|
||||
tr.then(f(p, text));
|
||||
if (tip != null && !tip.isEmpty()) {
|
||||
tr.tip(f(p, tip));
|
||||
}
|
||||
if (command != null && !command.isEmpty()) {
|
||||
final String tc = f(p, command);
|
||||
if (type == CLICKTYPE.SUGGEST) {
|
||||
tr.suggest(tc);
|
||||
} else if (type == CLICKTYPE.COMMAND) {
|
||||
tr.command(tc);
|
||||
}
|
||||
}
|
||||
return tr;
|
||||
}
|
||||
|
||||
private List<String> f(final Player player, final List<String> text) {
|
||||
return PlaceholderAPI.setPlaceholders(player, text);
|
||||
}
|
||||
|
||||
private String f(final Player player, final String text) {
|
||||
return PlaceholderAPI.setPlaceholders(player, text);
|
||||
}
|
||||
}
|
44
src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java
Normal file
44
src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java
Normal file
@ -0,0 +1,44 @@
|
||||
package pw.yumc.MiaoChat.listeners;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
import pw.yumc.MiaoChat.MiaoChat;
|
||||
import pw.yumc.MiaoChat.config.ChatConfig;
|
||||
import pw.yumc.MiaoChat.config.ChatMessagePart;
|
||||
import pw.yumc.YumCore.bukkit.P;
|
||||
import pw.yumc.YumCore.statistic.Statistics;
|
||||
import pw.yumc.YumCore.tellraw.Tellraw;
|
||||
import pw.yumc.YumCore.update.SubscribeTask;
|
||||
|
||||
public class ChatListener implements Listener {
|
||||
MiaoChat plugin = P.getPlugin();
|
||||
|
||||
public ChatListener() {
|
||||
Bukkit.getPluginManager().registerEvents(this, P.instance);
|
||||
new Statistics();
|
||||
new SubscribeTask(true, true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChat(final AsyncPlayerChatEvent e) {
|
||||
e.setCancelled(true);
|
||||
final Player p = e.getPlayer();
|
||||
final ChatConfig cc = plugin.getChatConfig();
|
||||
final String msg = e.getMessage();
|
||||
final Tellraw tr = Tellraw.create();
|
||||
for (final ChatMessagePart cmp : cc.getPrefixs()) {
|
||||
cmp.then(tr, p);
|
||||
}
|
||||
cc.getPlayer().then(tr, p);
|
||||
for (final ChatMessagePart cmp : cc.getSuffixs()) {
|
||||
cmp.then(tr, p);
|
||||
}
|
||||
tr.then(ChatColor.translateAlternateColorCodes('&', msg));
|
||||
tr.broadcast();
|
||||
}
|
||||
}
|
40
src/main/resources/config.yml
Normal file
40
src/main/resources/config.yml
Normal file
@ -0,0 +1,40 @@
|
||||
#格式化配置
|
||||
Format:
|
||||
#前缀配置 于玩家名称前
|
||||
Prefix:
|
||||
#顺序
|
||||
1:
|
||||
#文本 支持PAPI变量
|
||||
text: '&6[&a%player_world%&6]'
|
||||
#悬浮提示 支持PAPI
|
||||
tip:
|
||||
- '&6当前所在位置:'
|
||||
- '&6世界: &d%layer_world%'
|
||||
- '&6坐标: &aX:%layer_x% Y: %player_y% Z: %player_z%'
|
||||
- '&c点击即可TP我!'
|
||||
#点击操作
|
||||
click:
|
||||
#操作类型: [COMMAND,SUGGEST]
|
||||
#COMMAND代表执行命令
|
||||
#SUGGEST代表命令补全
|
||||
type: 'COMMAND'
|
||||
#命令 支持PAPI
|
||||
command: '/tpa %player_name%'
|
||||
#玩家名称配置
|
||||
Player:
|
||||
text: '&6[&b%player_name%&6] '
|
||||
tip:
|
||||
- '点击与我聊天'
|
||||
click:
|
||||
type: 'SUGGEST'
|
||||
command: '/tell %player_name%'
|
||||
#后缀配置 于玩家名称后 由于一般没人用 我注释掉了
|
||||
# Suffix:
|
||||
# 1:
|
||||
# text: '[变量1]'
|
||||
# tip:
|
||||
# - '变量1提示'
|
||||
# click:
|
||||
# type: 'COMMAND'
|
||||
# command: 'say 命令执行'
|
||||
|
22
src/main/resources/plugin.yml
Normal file
22
src/main/resources/plugin.yml
Normal file
@ -0,0 +1,22 @@
|
||||
name: ${project.artifactId}
|
||||
description: ${project.description}
|
||||
main: ${project.groupId}.${project.artifactId}.${project.artifactId}
|
||||
version: ${project.version}-git-${env.GIT_COMMIT}
|
||||
author: 喵♂呜
|
||||
website: ${ciManagement.url}
|
||||
commands:
|
||||
${project.artifactId}:
|
||||
description: ${project.artifactId} - ${project.description}
|
||||
aliases:
|
||||
- mct
|
||||
- mchat
|
||||
usage: §b使用/${project.artifactId} help 查看帮助!
|
||||
permission: ${project.artifactId}.reload
|
||||
permission-message: §c你没有 <permission> 的权限来执行此命令!
|
||||
permissions:
|
||||
${project.artifactId}.use:
|
||||
description: ${project.artifactId} 使用!
|
||||
default: true
|
||||
${project.artifactId}.reload:
|
||||
description: 重新载入插件!
|
||||
default: op
|
Reference in New Issue
Block a user