forked from circlecloud/MiaoChat
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d9322cbac4 | |||
| 95591ec5ff | |||
| 11fb155a37 | |||
| be66b3b9a0 | |||
| 80f2a37fc1 | |||
| 45ec56bebe | |||
| 4da0b92f3f | |||
| c25a667571 | |||
| 05219d509c | |||
| 3ad4ff2991 | |||
| 4fcaef1031 | |||
| f22113584d | |||
| ab58ee3bc6 | |||
| d5db16f780 | |||
| 6591a03475 | |||
| 8a5f96fcc0 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,5 +1,6 @@
|
||||
# Eclipse stuff
|
||||
/.settings
|
||||
/.project
|
||||
|
||||
# netbeans
|
||||
/nbproject
|
||||
|
||||
132
pom.xml
132
pom.xml
@@ -1,109 +1,53 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>pw.yumc</groupId>
|
||||
|
||||
<artifactId>MiaoChat</artifactId>
|
||||
<version>1.8.6</version>
|
||||
<build>
|
||||
<finalName>${project.name}</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.4.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>pw.yumc:YumCore</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>pw.yumc.YumCore</pattern>
|
||||
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.github.wvengen</groupId>
|
||||
<artifactId>proguard-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>proguard</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<options>
|
||||
<option>-repackageclasses \ʼ.ʽ.ʾ.${project.artifactId}</option>
|
||||
<option>-keep class ${project.groupId}.${project.artifactId}.${project.artifactId}</option>
|
||||
<option>-keep class ${project.groupId}.${project.artifactId}.${project.artifactId}Bungee</option>
|
||||
</options>
|
||||
<libs>
|
||||
<lib>${java.home}/lib/rt.jar</lib>
|
||||
</libs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<ciManagement>
|
||||
<system>Jenkins</system>
|
||||
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
|
||||
</ciManagement>
|
||||
<version>2.2.3</version>
|
||||
|
||||
<parent>
|
||||
<groupId>pw.yumc</groupId>
|
||||
<artifactId>minecraft-plugin-parent</artifactId>
|
||||
<version>1.0</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<update.description>§a正式版本 §bv1.8.6</update.description>
|
||||
<update.description>§a正式版本 §bv2.2.3 §b默认支持RGB色彩</update.description>
|
||||
<update.changes>
|
||||
§622-11-23 §a增强: 默认支持RGB色彩;
|
||||
§622-11-21 §a增强: 兼容 1.19.2(1.19.x部分版本存在BUG);
|
||||
§622-07-05 §a增强: 兼容 Paper 1.19;
|
||||
§622-06-17 §a增强: 兼容 1.19 修复 快捷指令错误;
|
||||
§622-04-13 §c修复: 部分版本JDK导致启动错误
|
||||
</update.changes>
|
||||
<update.changelog>
|
||||
§622-04-12 §a增强: 兼容 1.18.2 修复 PAPI 注销报错;
|
||||
§622-02-25 §a增强: 新增 %a-z 自定义解析 实现神奇功能 兼容 1.18.1#133+;
|
||||
§621-12-18 §a增强: 全新版本(号) 新增 itemTip 配合龙核 实现神奇功能;
|
||||
§621-12-06 §a增强: 兼容 1.18 版本 兼容新版PAPI;
|
||||
§621-06-20 §a增强: 兼容 1.17 版本;
|
||||
§620-10-10 §c修复: 1.16.3聊天包格式调整的问题;
|
||||
§620-04-10 §c修复: L10N 本地化组件报错的问题;
|
||||
§620-04-09 §c修复: 1.13-1.15.2新增物品不兼容的问题;
|
||||
§620-02-15 §c修复: 跨服分组分配异常的问题;
|
||||
§619-05-31 §a增强: 跨服聊天压缩数据 增加可传输内容大小;
|
||||
§619-05-29 §c修复: 1.7.10不兼容的问题;
|
||||
§619-02-23 §c修复: BungeeCord 兼容性问题;
|
||||
§617-08-08 §c修复: 解析特殊字符错误问题;
|
||||
§617-07-25 §c修复: 类库版本错误;
|
||||
§617-07-24 §c修复: 兼容 1.12 版本;
|
||||
§617-05-21 §c修复: BungeeCord未分配分组时报错;
|
||||
§617-04-07 §c修复: 控制台重复输出聊天信息;
|
||||
</update.changes>
|
||||
<update.changelog>
|
||||
</update.changelog>
|
||||
<env.GIT_COMMIT>DEV</env.GIT_COMMIT>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>yumc-repo</id>
|
||||
<url>http://repo.yumc.pw/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>jtb</id>
|
||||
<name>YUMC</name>
|
||||
<url>http://repo.yumc.pw/content/repositories/yumcenter/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>pw.yumc</groupId>
|
||||
<artifactId>YumCore</artifactId>
|
||||
<type>jar</type>
|
||||
<version>[1.8.1,)</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -1,5 +1,9 @@
|
||||
package pw.yumc.MiaoChat;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -11,13 +15,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.clip.placeholderapi.PlaceholderHook;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import pw.yumc.MiaoChat.config.ChatConfig;
|
||||
import pw.yumc.MiaoChat.listeners.ChatListener;
|
||||
import pw.yumc.YumCore.bukkit.Log;
|
||||
@@ -33,6 +31,7 @@ public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListe
|
||||
private FileConfig cfg;
|
||||
private ChatConfig chatConfig;
|
||||
private String ServerName;
|
||||
private PlaceholderExpansion expansion;
|
||||
|
||||
public ChatConfig getChatConfig() {
|
||||
return chatConfig;
|
||||
@@ -66,6 +65,11 @@ public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListe
|
||||
L10N.getName(new ItemStack(Material.AIR));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
try {this.expansion.unregister();} catch (Throwable ignored) {}
|
||||
}
|
||||
|
||||
private void enableBungeeCord() {
|
||||
if (getChatConfig().isBungeeCord()) {
|
||||
Log.i("已开启 BungeeCord 模式!");
|
||||
@@ -74,24 +78,46 @@ public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListe
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
Bukkit.getMessenger().registerIncomingPluginChannel(this, MiaoMessage.CHANNEL, this);
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, MiaoMessage.CHANNEL);
|
||||
Bukkit.getMessenger().registerIncomingPluginChannel(this, MiaoMessage.NORMALCHANNEL, this);
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, MiaoMessage.NORMALCHANNEL);
|
||||
Bukkit.getMessenger().registerIncomingPluginChannel(this, MiaoMessage.NORMAL_CHANNEL, this);
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, MiaoMessage.NORMAL_CHANNEL);
|
||||
}
|
||||
}
|
||||
|
||||
private void hookPlaceholderAPI() {
|
||||
PlaceholderAPI.registerPlaceholderHook("mct", new PlaceholderHook() {
|
||||
this.expansion = new PlaceholderExpansion() {
|
||||
@Override
|
||||
public String onPlaceholderRequest(Player player, String s) {
|
||||
switch (s.toLowerCase()) {
|
||||
case "server":
|
||||
return getChatConfig().getServername();
|
||||
case "bserver":
|
||||
return ServerName;
|
||||
public @NotNull String getIdentifier() {
|
||||
return "mct";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getAuthor() {
|
||||
return "MiaoWoo";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getVersion() {
|
||||
return "1.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onPlaceholderRequest(Player player, @NotNull String params) {
|
||||
switch (params.toLowerCase()) {
|
||||
case "server":
|
||||
return getChatConfig().getServername();
|
||||
case "bserver":
|
||||
return ServerName;
|
||||
default:
|
||||
}
|
||||
return "未知的参数";
|
||||
}
|
||||
});
|
||||
};
|
||||
this.expansion.register();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -134,7 +160,7 @@ public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListe
|
||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||
if (MiaoMessage.CHANNEL.equals(channel)) {
|
||||
send(message);
|
||||
} else if (MiaoMessage.NORMALCHANNEL.equals(channel)) {
|
||||
} else if (MiaoMessage.NORMAL_CHANNEL.equals(channel)) {
|
||||
for (Player p : C.Player.getOnlinePlayers()) {
|
||||
p.sendMessage(MiaoMessage.decode(message).getJson());
|
||||
}
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
package pw.yumc.MiaoChat;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||
@@ -18,13 +11,22 @@ import net.md_5.bungee.event.EventHandler;
|
||||
import pw.yumc.MiaoChat.bungee.FileConfig;
|
||||
import pw.yumc.MiaoChat.bungee.Log;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author MiaoWoo
|
||||
*/
|
||||
public class MiaoChatBungee extends Plugin implements Listener {
|
||||
private Map<InetSocketAddress, Set<ServerInfo>> groups;
|
||||
private FileConfig config;
|
||||
|
||||
@EventHandler
|
||||
public void handle(final PluginMessageEvent event) {
|
||||
if (event.getTag().equals(MiaoMessage.CHANNEL) || event.getTag().equals(MiaoMessage.NORMALCHANNEL)) {
|
||||
if (event.getTag().equals(MiaoMessage.CHANNEL) || event.getTag().equals(MiaoMessage.NORMAL_CHANNEL)) {
|
||||
InetSocketAddress origin = event.getSender().getAddress();
|
||||
if (groups.containsKey(origin)) {
|
||||
groups.get(origin).forEach(server -> {
|
||||
@@ -45,43 +47,44 @@ public class MiaoChatBungee extends Plugin implements Listener {
|
||||
public void loadGroup() {
|
||||
groups = new HashMap<>();
|
||||
Map<String, ServerInfo> temp = getProxy().getServers();
|
||||
Set<ServerInfo> unused = new HashSet<>();
|
||||
Set<ServerInfo> unused = new HashSet<>(temp.values());
|
||||
Configuration groupSel = config.getSection("Groups");
|
||||
Collection<String> groupname = groupSel.getKeys();
|
||||
groupname.forEach(gname -> {
|
||||
Set<String> servers = new HashSet<>(groupSel.getStringList(gname));
|
||||
Set<ServerInfo> sers = new HashSet<>();
|
||||
servers.forEach(sname -> sers.add(temp.get(sname)));
|
||||
sers.remove(null);
|
||||
servers.forEach(sname -> {
|
||||
ServerInfo isadd = temp.get(sname);
|
||||
if (isadd != null) {
|
||||
unused.remove(isadd);
|
||||
groups.put(isadd.getAddress(), sers);
|
||||
// 读取所有的分组名称
|
||||
groupSel.getKeys().forEach(groupName -> {
|
||||
// 获取每个分组的服务器名称
|
||||
Set<String> servers = new HashSet<>(groupSel.getStringList(groupName));
|
||||
// 新建当前分组数组
|
||||
Set<ServerInfo> serverInfos = new HashSet<>();
|
||||
servers.forEach(s -> {
|
||||
if (temp.containsKey(s)) {
|
||||
ServerInfo info = temp.get(s);
|
||||
unused.remove(info);
|
||||
serverInfos.add(info);
|
||||
}
|
||||
});
|
||||
serverInfos.forEach(serverInfo -> groups.put(serverInfo.getAddress(), serverInfos));
|
||||
});
|
||||
unused.forEach(unser -> groups.put(unser.getAddress(), unused));
|
||||
unused.forEach(serverInfo -> groups.put(serverInfo.getAddress(), unused));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
loadGroup();
|
||||
getProxy().registerChannel(MiaoMessage.CHANNEL);
|
||||
getProxy().registerChannel(MiaoMessage.NORMALCHANNEL);
|
||||
getProxy().registerChannel(MiaoMessage.NORMAL_CHANNEL);
|
||||
getProxy().getPluginManager().registerListener(this, this);
|
||||
getProxy().getPluginManager().registerCommand(this, new Command("MiaoChat", "MiaoChat.admin", "mct") {
|
||||
@Override
|
||||
public void execute(CommandSender commandSender, String[] args) {
|
||||
if (args.length > 0) {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "reload":
|
||||
config.reload();
|
||||
loadGroup();
|
||||
commandSender.sendMessage("§a配置文件已重载!");
|
||||
return;
|
||||
case "version":
|
||||
default:
|
||||
case "reload":
|
||||
config.reload();
|
||||
loadGroup();
|
||||
commandSender.sendMessage("§a配置文件已重载!");
|
||||
return;
|
||||
case "version":
|
||||
default:
|
||||
}
|
||||
}
|
||||
commandSender.sendMessage("§6插件版本: §av" + getDescription().getVersion());
|
||||
|
||||
@@ -1,16 +1,28 @@
|
||||
package pw.yumc.MiaoChat;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import lombok.SneakyThrows;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
/**
|
||||
* Created on 16-9-8.
|
||||
*
|
||||
* @author MiaoWoo
|
||||
*/
|
||||
public class MiaoMessage {
|
||||
|
||||
public static final String CHANNEL = "MiaoChat";
|
||||
public static final String NORMALCHANNEL = "MiaoChatNM";
|
||||
public static final String CHANNEL = "MiaoChat:Default".toLowerCase();
|
||||
public static final String NORMAL_CHANNEL = "MiaoChat:Normal".toLowerCase();
|
||||
private static final Pattern RGB_PATTERN = Pattern.compile("#[a-fA-F0-9]{6}");
|
||||
private static final int MAX_MESSAGE_LENGTH = 32000;
|
||||
private String json;
|
||||
|
||||
private MiaoMessage(String json) {
|
||||
@@ -21,19 +33,48 @@ public class MiaoMessage {
|
||||
return new MiaoMessage(in).encode();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static MiaoMessage decode(byte[] in) {
|
||||
final ByteArrayDataInput input = ByteStreams.newDataInput(in);
|
||||
return new MiaoMessage(input.readUTF());
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
copy(new GZIPInputStream(new ByteArrayInputStream(in)), baos);
|
||||
return new MiaoMessage(baos.toString("UTF-8"));
|
||||
}
|
||||
|
||||
public String getJson() {
|
||||
return json;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public byte[] encode() {
|
||||
if (json.getBytes().length > 32000) { return null; }
|
||||
final ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF(json);
|
||||
return out.toByteArray();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
copy(new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)), new GZIPOutputStream(baos));
|
||||
if (baos.size() > MAX_MESSAGE_LENGTH) {return null;}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private static void copy(InputStream input, OutputStream output) {
|
||||
byte[] buffer = new byte[1024];
|
||||
int n;
|
||||
while ((n = input.read(buffer)) != -1) {
|
||||
output.write(buffer, 0, n);
|
||||
}
|
||||
input.close();
|
||||
output.close();
|
||||
}
|
||||
|
||||
public static String rgb(String message) {
|
||||
Matcher matcher = RGB_PATTERN.matcher(message);
|
||||
while (matcher.find()) {
|
||||
String hexCode = message.substring(matcher.start(), matcher.end());
|
||||
String replaceSharp = hexCode.replace('#', 'x');
|
||||
char[] ch = replaceSharp.toCharArray();
|
||||
StringBuilder builder = new StringBuilder("");
|
||||
for (char c : ch) {
|
||||
builder.append("&").append(c);
|
||||
}
|
||||
message = message.replace(hexCode, builder.toString());
|
||||
}
|
||||
return ChatColor.translateAlternateColorCodes('&', message);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,24 @@
|
||||
package pw.yumc.MiaoChat.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import pw.yumc.MiaoChat.MiaoMessage;
|
||||
import pw.yumc.YumCore.config.annotation.ConfigNode;
|
||||
import pw.yumc.YumCore.config.annotation.Nullable;
|
||||
import pw.yumc.YumCore.config.inject.InjectConfigurationSection;
|
||||
import pw.yumc.YumCore.tellraw.Tellraw;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ChatMessagePart extends InjectConfigurationSection {
|
||||
private String text;
|
||||
@Nullable
|
||||
private List<String> tip;
|
||||
@Nullable
|
||||
private ItemTip item;
|
||||
@Nullable
|
||||
@ConfigNode("click.type")
|
||||
private String typestring;
|
||||
@Nullable
|
||||
@@ -32,28 +35,30 @@ public class ChatMessagePart extends InjectConfigurationSection {
|
||||
|
||||
public Tellraw then(Tellraw tr, Player p) {
|
||||
tr.then(f(p, text));
|
||||
if (tip != null && !tip.isEmpty()) {
|
||||
if (item != null) {
|
||||
tr.item(item.getItemStack(p, text, tip));
|
||||
} else if (tip != null && !tip.isEmpty()) {
|
||||
tr.tip(f(p, tip));
|
||||
}
|
||||
if (command != null && !command.isEmpty()) {
|
||||
String tc = f(p, command);
|
||||
switch (type) {
|
||||
case COMMAND:
|
||||
return tr.command(tc);
|
||||
case OPENURL:
|
||||
return tr.openurl(tc);
|
||||
case SUGGEST:
|
||||
return tr.suggest(tc);
|
||||
case COMMAND:
|
||||
return tr.command(tc);
|
||||
case OPENURL:
|
||||
return tr.openurl(tc);
|
||||
case SUGGEST:
|
||||
return tr.suggest(tc);
|
||||
}
|
||||
}
|
||||
return tr;
|
||||
}
|
||||
|
||||
private List<String> f(Player player, List<String> text) {
|
||||
return PlaceholderAPI.setPlaceholders(player, text);
|
||||
return text.stream().map((line) -> f(player, line)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private String f(Player player, String text) {
|
||||
return PlaceholderAPI.setPlaceholders(player, text);
|
||||
return MiaoMessage.rgb(PlaceholderAPI.setPlaceholders(player, text));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
package pw.yumc.MiaoChat.config;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import pw.yumc.MiaoChat.MiaoChat;
|
||||
import pw.yumc.YumCore.bukkit.P;
|
||||
import pw.yumc.YumCore.config.annotation.Default;
|
||||
import pw.yumc.YumCore.config.inject.InjectConfigurationSection;
|
||||
import pw.yumc.YumCore.tellraw.Tellraw;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 聊天规则
|
||||
*
|
||||
@@ -22,8 +21,9 @@ import pw.yumc.YumCore.tellraw.Tellraw;
|
||||
* @since 2016年9月9日 下午4:59:47
|
||||
*/
|
||||
public class ChatRule extends InjectConfigurationSection {
|
||||
private transient static MiaoChat plugin = P.getPlugin();
|
||||
private transient static Pattern FORMAT_PATTERN = Pattern.compile("[\\[]([^\\[\\]]+)[]]");
|
||||
private final transient static MiaoChat plugin = P.getPlugin();
|
||||
private final transient static Pattern FORMAT_PATTERN = Pattern.compile("[\\[]([^\\[\\]]+)[]]");
|
||||
|
||||
private transient String name;
|
||||
@Default("50")
|
||||
private Integer index;
|
||||
|
||||
52
src/main/java/pw/yumc/MiaoChat/config/ItemTip.java
Normal file
52
src/main/java/pw/yumc/MiaoChat/config/ItemTip.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package pw.yumc.MiaoChat.config;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import pw.yumc.MiaoChat.bungee.Log;
|
||||
import pw.yumc.YumCore.config.annotation.Default;
|
||||
import pw.yumc.YumCore.config.annotation.Nullable;
|
||||
import pw.yumc.YumCore.config.inject.InjectConfigurationSection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ItemTip extends InjectConfigurationSection {
|
||||
private String type;
|
||||
@Default("0")
|
||||
private Short damage;
|
||||
@Nullable
|
||||
private String name;
|
||||
|
||||
private transient ItemStack itemStack;
|
||||
private transient ItemMeta itemMeta;
|
||||
|
||||
public ItemTip(ConfigurationSection config) {
|
||||
super(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
try {
|
||||
Material material = Material.valueOf(type);
|
||||
this.itemStack = new ItemStack(material, 1, damage);
|
||||
this.itemMeta = Bukkit.getItemFactory().getItemMeta(material);
|
||||
} catch (Throwable ex) {
|
||||
this.itemStack = new ItemStack(Material.STONE, 1);
|
||||
Log.w("物品 %s 解析失败 将使用默认值 STONE...", type);
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getItemStack(Player p, String name, List<String> tip) {
|
||||
ItemStack itemStack = this.itemStack.clone();
|
||||
ItemMeta itemMeta = this.itemMeta.clone();
|
||||
itemMeta.setDisplayName(PlaceholderAPI.setPlaceholders(p, this.name == null ? name : this.name));
|
||||
itemMeta.setLore(PlaceholderAPI.setPlaceholders(p, tip));
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
return itemStack;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
package pw.yumc.MiaoChat.listeners;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@@ -16,7 +9,6 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import pw.yumc.MiaoChat.MiaoChat;
|
||||
import pw.yumc.MiaoChat.MiaoMessage;
|
||||
import pw.yumc.MiaoChat.config.ChatConfig;
|
||||
@@ -28,11 +20,18 @@ import pw.yumc.YumCore.statistic.Statistics;
|
||||
import pw.yumc.YumCore.tellraw.Tellraw;
|
||||
import pw.yumc.YumCore.update.SubscribeTask;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author MiaoWoo
|
||||
*/
|
||||
public class ChatListener implements Listener {
|
||||
public static Set<Player> offList = new HashSet<>();
|
||||
private static Pattern ITEM_PATTERN = Pattern.compile("%([i1-9]?)");
|
||||
|
||||
private final Queue<String> queue = new LinkedList<>();
|
||||
private static Pattern PATTERN = Pattern.compile("%([a-z1-9]?)");
|
||||
|
||||
private MiaoChat plugin = P.getPlugin();
|
||||
private ChatConfig cc = plugin.getChatConfig();
|
||||
@@ -82,7 +81,7 @@ public class ChatListener implements Listener {
|
||||
}
|
||||
|
||||
private LinkedList<String> handlePattern(String message) {
|
||||
Matcher m = ITEM_PATTERN.matcher(message);
|
||||
Matcher m = PATTERN.matcher(message);
|
||||
Set<String> temp = new HashSet<>();
|
||||
LinkedList<String> ilist = new LinkedList<>();
|
||||
// Log.d("处理聊天物品信息...");
|
||||
@@ -111,7 +110,7 @@ public class ChatListener implements Listener {
|
||||
byte[] mm = MiaoMessage.encode(tr.toJsonString());
|
||||
// 数据流等于NULL代表数据超长
|
||||
if (mm == null) {
|
||||
p.sendPluginMessage(P.instance, MiaoMessage.NORMALCHANNEL, MiaoMessage.encode(tr.toOldMessageFormat()));
|
||||
p.sendPluginMessage(P.instance, MiaoMessage.NORMAL_CHANNEL, MiaoMessage.encode(tr.toOldMessageFormat()));
|
||||
} else {
|
||||
p.sendPluginMessage(P.instance, MiaoMessage.CHANNEL, mm);
|
||||
}
|
||||
@@ -123,10 +122,13 @@ public class ChatListener implements Listener {
|
||||
}
|
||||
|
||||
private Tellraw handleTellraw(Player player, Tellraw tr, ChatRule cr, String message) {
|
||||
if (message.isEmpty()) { return tr; }
|
||||
if (message.isEmpty()) {return tr;}
|
||||
if (player.hasPermission("MiaoChat.color")) {
|
||||
message = ChatColor.translateAlternateColorCodes('&', message);
|
||||
}
|
||||
if (player.hasPermission("MiaoChat.rgb")) {
|
||||
message = MiaoMessage.rgb(message);
|
||||
}
|
||||
if (!cr.isItem()) {
|
||||
tr.then(message);
|
||||
return tr;
|
||||
@@ -143,11 +145,30 @@ public class ChatListener implements Listener {
|
||||
String mm = ml.removeFirst();
|
||||
if (il.contains(mm)) {
|
||||
char k = mm.charAt(1);
|
||||
ItemStack is = k == 'i' ? player.getItemInHand() : player.getInventory().getItem(k - '0' - 1);
|
||||
if (is != null && is.getType() != Material.AIR) {
|
||||
// Log.d("处理物品: %s", mm);
|
||||
tr.then(String.format(ChatColor.translateAlternateColorCodes('&', cr.getItemformat()), L10N.getName(is)));
|
||||
tr.item(is);
|
||||
String key = String.valueOf(k);
|
||||
if (plugin.getChatConfig().getFormats().containsKey(key)) {
|
||||
if (!player.hasPermission("MiaoChat.format.*") && player.hasPermission("MiaoChat.format." + k)) {
|
||||
Log.sender(player, "§c你没有使用 " + mm + " 的权限!");
|
||||
continue;
|
||||
}
|
||||
plugin.getChatConfig().getFormats().get(key).then(tr, player);
|
||||
} else {
|
||||
ItemStack is = null;
|
||||
if (k == 'i') {
|
||||
is = player.getItemInHand();
|
||||
} else {
|
||||
int index = k - '0' - 1;
|
||||
if (index < 10) {
|
||||
is = player.getInventory().getItem(index);
|
||||
}
|
||||
}
|
||||
if (is != null && is.getType() != Material.AIR) {
|
||||
// Log.d("处理物品: %s", mm);
|
||||
tr.then(String.format(ChatColor.translateAlternateColorCodes('&', cr.getItemformat()), L10N.getName(is)));
|
||||
tr.item(is);
|
||||
} else {
|
||||
tr.then(cr.getLastColor() + mm);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Log.d("追加聊天: %s", mm);
|
||||
|
||||
@@ -3,12 +3,12 @@ world:
|
||||
#文本 支持PAPI变量
|
||||
text: '&6[&a%player_world%&6]'
|
||||
#悬浮提示 支持PAPI
|
||||
tip:
|
||||
- '&6当前所在位置:'
|
||||
- '&6世界: &d%player_world%'
|
||||
- '&6坐标: &aX:%player_x% Y: %player_y% Z: %player_z%'
|
||||
- ''
|
||||
- '&c点击即可TP我!'
|
||||
tip:
|
||||
- '&6当前所在位置:'
|
||||
- '&6世界: &d%player_world%'
|
||||
- '&6坐标: &aX:%player_x% Y: %player_y% Z: %player_z%'
|
||||
- ''
|
||||
- '&c点击即可TP我!'
|
||||
#点击操作
|
||||
click:
|
||||
#操作类型: [COMMAND,SUGGEST,OPENURL]
|
||||
@@ -18,25 +18,54 @@ world:
|
||||
type: 'COMMAND'
|
||||
#命令或网址 支持PAPI
|
||||
command: '/tpa %player_name%'
|
||||
player:
|
||||
player:
|
||||
text: '&b%player_name%'
|
||||
tip:
|
||||
- '&6玩家名称: &b%player_name%'
|
||||
- '&6玩家等级: &a%player_level%'
|
||||
- '&6玩家血量: &c%player_health%'
|
||||
- '&6玩家饥饿: &d%player_food_level%'
|
||||
- '&6游戏模式: &4%player_gamemode%'
|
||||
- ''
|
||||
- '&c点击与我聊天'
|
||||
click:
|
||||
# 物品化Tip 可配合龙核/萌芽做ItemTip
|
||||
#item:
|
||||
# # 物品枚举
|
||||
# type: STONE
|
||||
# # 物品子ID
|
||||
# damage: 0
|
||||
# # 物品名称(用于萌芽/龙核匹配) 为空则使用 text
|
||||
# name: '§s§v§i§p'
|
||||
tip:
|
||||
- '&6玩家名称: &b%player_name%'
|
||||
- '&6玩家等级: &a%player_level%'
|
||||
- '&6玩家血量: &c%player_health%'
|
||||
- '&6玩家饥饿: &d%player_food_level%'
|
||||
- '&6游戏模式: &4%player_gamemode%'
|
||||
- ''
|
||||
- '&c点击与我聊天'
|
||||
click:
|
||||
type: 'SUGGEST'
|
||||
command: '/tell %player_name%'
|
||||
admin:
|
||||
text: '&6[&c管理员&6]'
|
||||
help:
|
||||
text: '&4[求助]'
|
||||
tip:
|
||||
- '点击求助OP'
|
||||
click:
|
||||
tip:
|
||||
- '点击求助OP'
|
||||
click:
|
||||
type: 'COMMAND'
|
||||
command: '管理员@%player_name% 我需要你的帮助!'
|
||||
command: '管理员@%player_name% 我需要你的帮助!'
|
||||
l:
|
||||
text: '&6[&b点击看我仓库]&6'
|
||||
# item:
|
||||
# # 物品枚举
|
||||
# type: STONE
|
||||
# # 物品子ID
|
||||
# damage: 0
|
||||
# # 物品名称(用于萌芽/龙核匹配) 为空则使用 text
|
||||
# name: '§g§s§p'
|
||||
tip:
|
||||
- '&a点击查看 &b%player_name% &a的仓库'
|
||||
click:
|
||||
type: 'COMMAND'
|
||||
command: '/mgs look %player_name% local 1'
|
||||
t:
|
||||
text: '&6[&b点击和我交易&6]&r'
|
||||
tip:
|
||||
- '&a点击和 &b%player_name% &a发起交易'
|
||||
click:
|
||||
type: 'COMMAND'
|
||||
command: '/trade %player_name%'
|
||||
@@ -7,9 +7,9 @@ Version: 1.0
|
||||
Groups:
|
||||
#普通分组
|
||||
normal:
|
||||
- 'sc1'
|
||||
- 'sc2'
|
||||
# - 'sc1'
|
||||
# - 'sc2'
|
||||
#游戏分组
|
||||
games:
|
||||
- 'bw1'
|
||||
- 'sg1'
|
||||
# - 'bw1'
|
||||
# - 'sg1'
|
||||
@@ -1,8 +1,9 @@
|
||||
name: ${project.artifactId}
|
||||
description: ${project.description}
|
||||
main: ${project.groupId}.${project.artifactId}.${project.artifactId}
|
||||
version: ${project.version}-git-${env.GIT_COMMIT}
|
||||
author: 喵♂呜
|
||||
version: ${project.version}
|
||||
api-version: 1.13
|
||||
author: MiaoWoo
|
||||
website: ${ciManagement.url}
|
||||
depend:
|
||||
- PlaceholderAPI
|
||||
@@ -24,7 +25,10 @@ permissions:
|
||||
default: true
|
||||
${project.artifactId}.color:
|
||||
description: 彩字聊天权限!
|
||||
default: true
|
||||
default: op
|
||||
${project.artifactId}.rgb:
|
||||
description: RGB聊天权限!
|
||||
default: op
|
||||
${project.artifactId}.admin:
|
||||
description: 管理员格式权限!
|
||||
default: op
|
||||
|
||||
Reference in New Issue
Block a user