Skip to content

Commit

Permalink
修复聊天在Folia无法运行
Browse files Browse the repository at this point in the history
  • Loading branch information
CSneko committed Nov 26, 2023
1 parent 7b3106e commit 649a56d
Show file tree
Hide file tree
Showing 67 changed files with 118 additions and 12 deletions.
Binary file modified .gradle/8.1.1/checksums/checksums.lock
Binary file not shown.
Binary file modified .gradle/8.1.1/checksums/md5-checksums.bin
Binary file not shown.
Binary file modified .gradle/8.1.1/checksums/sha1-checksums.bin
Binary file not shown.
Binary file modified .gradle/8.1.1/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/8.1.1/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/8.1.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/8.1.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/8.1.1/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ repositories {
url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
}
maven { url = 'https://oss.sonatype.org/content/groups/public/' }
maven {
name = 'papermc'
url = 'https://repo.papermc.io/repository/maven-public/'
}
mavenCentral()

}
Expand All @@ -45,6 +49,7 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
compileOnly 'dev.folia:folia-api:1.20.2-R0.1-SNAPSHOT'
}

processResources {
Expand Down
Binary file modified build/classes/java/main/com/crystalneko/toneko/ToNeko.class
Binary file not shown.
Binary file modified build/classes/java/main/com/crystalneko/toneko/chat/nekoed.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified build/kotlin/compileKotlin/cacheable/last-build.bin
Binary file not shown.
Binary file modified build/kotlin/compileKotlin/local-state/build-history.bin
Binary file not shown.
Binary file removed build/libs/toNekoFabric-0.0.10-sources.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion build/resources/main/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "tonekofabric",
"version": "0.1.0",
"version": "0.1.1",
"name": "toNekoFabric",
"description": "toNeko插件的Fabric版本",
"authors": [
Expand Down
5 changes: 4 additions & 1 deletion build/resources/main/language/en_us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ command:
Invalid: "§cInvalid subcommand, please enter §a/neko help§c to view the help"
help: "§b/neko help:\n§a/neko help §bGet help\n§a/neko jump §bGet jump boost"
toneko:
help: "§b/toneko Help:\n§a/toneko help §bGet help\n§a/toneko player <player name> §bTurn a player into a catgirl (but you will be sacrificed)\n§a/ toneko item §bGet the cat stick\n§a/toneko remove <cat girl name> §bDelete cat girl§c (This is a dangerous operation, please use it with caution)\n§a/toneko xp <cat girl name> §bCheck the favorability Experience\n§a/toneko aliases <cat girl name> add or remove <alias> §bAdd or remove aliases for you (a word that will be converted to 'owner')\n§a/toneko block <cat girl name> add or remove <Blocking word> <Replacement word> word or all §bAdd a masking word (the masking word will be replaced with a replacement word, all means replacing the entire sentence, word replaces the word)"
help: "§b/toneko Help:\n§a/toneko help §bGet help\n§a/toneko player <player name> §bTurn a player into a catgirl (but you will be sacrificed)\n§a/ toneko item §bGet the cat stick\n§a/toneko remove <cat girl name> §bDelete cat girl§c (This is a dangerous operation, please use it with caution)\n§a/toneko xp <cat girl name> §bCheck the favorability Experience\n§a/toneko aliases <cat girl name> add or remove <alias> §bAdd or remove aliases for you (a word that will be converted to 'owner')\n§a/toneko block <cat girl name> add or remove <Blocking word> <Replacement word> word or all §bAdd a masking word (the masking word will be replaced with a replacement word, all means replacing the entire sentence, word replaces the word)"
folia:
use:
chatEvent: "Use of paper/Folia detected, Paper/Folia's chat listener will be used"
5 changes: 4 additions & 1 deletion build/resources/main/language/zh_cn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ command:
Invalid: "§c无效的子命令,请输入§a/neko help§c查看帮助"
help: "§b/neko 帮助:\n§a/neko help §b获取帮助\n§a/neko jump §b获取跳跃提升"
toneko:
help: "§b/toneko 帮助:\n§a/toneko help §b获取帮助\n§a/toneko player <玩家名> §b将一位玩家变成猫娘(但是你会被祭献)\n§a/toneko item §b获取撅猫棍\n§a/toneko remove <猫娘名称> §b删除猫娘§c(这是个危险操作,请谨慎使用)\n§a/toneko xp <猫娘名称> §b查看好感经验\n§a/toneko aliases <猫娘名称> add或remove <别名> §b为你添加或删除别名(会转换为'主人'的词)\n§a/toneko block <猫娘名称> add或remove <屏蔽词> <替换词> word或all §b添加屏蔽词(屏蔽词会被替换成替换词,all代表替换整句,word替换单词)"
help: "§b/toneko 帮助:\n§a/toneko help §b获取帮助\n§a/toneko player <玩家名> §b将一位玩家变成猫娘(但是你会被祭献)\n§a/toneko item §b获取撅猫棍\n§a/toneko remove <猫娘名称> §b删除猫娘§c(这是个危险操作,请谨慎使用)\n§a/toneko xp <猫娘名称> §b查看好感经验\n§a/toneko aliases <猫娘名称> add或remove <别名> §b为你添加或删除别名(会转换为'主人'的词)\n§a/toneko block <猫娘名称> add或remove <屏蔽词> <替换词> word或all §b添加屏蔽词(屏蔽词会被替换成替换词,all代表替换整句,word替换单词)"
folia:
use:
chatEvent: "检测到使用Paper/Folia,将使用Paper/Folia的聊天监听器"
2 changes: 1 addition & 1 deletion build/resources/main/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: toNeko
version: '0.1.0'
version: '0.1.1'
main: com.crystalneko.toneko.ToNeko
api-version: '1.20'
author: CrystalNeko
Expand Down
Binary file modified build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.14.23

# Mod Properties
mod_version = 0.1.0
mod_version = 0.1.1
maven_group = com.crystalneko
archives_base_name = toNekoFabric

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/crystalneko/toneko/ToNeko.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.logging.Logger;


public final class ToNeko extends JavaPlugin {
Expand All @@ -41,11 +42,16 @@ public final class ToNeko extends JavaPlugin {
private String language;
private PlayerQuit playerQuit;
public stickLevel2 stickLevel;
public static Logger logger;


@Override
public void onEnable() {
//温馨提示:代码中所有的判断是否为猫娘都是判断是否有主人,这意味着猫娘必须有主人,否则就不被判断为猫娘

//获取logger
logger = Logger.getLogger("toNeko");

int pluginId = 19899;
Metrics metrics = new Metrics(this, pluginId);
//判断是否启用了ctLib
Expand Down
83 changes: 79 additions & 4 deletions src/main/java/com/crystalneko/toneko/chat/nekoed.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,53 @@
import com.crystalneko.ctlib.chat.chatPrefix;
import com.crystalneko.ctlib.sql.sqlite;
import com.crystalneko.toneko.ToNeko;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.*;
import org.bukkit.event.player.PlayerChatEvent;
import io.papermc.paper.event.player.AsyncChatEvent;
import org.bukkit.plugin.EventExecutor;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

import static com.crystalneko.toneko.ToNeko.logger;
import static org.bukkit.Bukkit.getServer;

public class nekoed implements Listener{
private ToNeko plugin;
public nekoed(ToNeko plugin) {
this.plugin = plugin;
//注册玩家聊天监听器
getServer().getPluginManager().registerEvents(this, plugin);
try {
//使用Paper的聊天监听器
Class.forName("io.papermc.paper.event.player.AsyncChatEvent");
logger.info(ToNeko.getMessage("folia.use.chatEvent"));
getServer().getPluginManager().registerEvent(AsyncChatEvent.class,this, EventPriority.NORMAL,new EventExecutor() {
@Override
public void execute(Listener listener, Event event) throws EventException {
onPlayerChatPaper((AsyncChatEvent) event);
}
},plugin);
} catch (ClassNotFoundException e) {
getServer().getPluginManager().registerEvent(PlayerChatEvent.class,this, EventPriority.NORMAL,new EventExecutor() {
@Override
public void execute(Listener listener, Event event) throws EventException {
onPlayerChat((PlayerChatEvent) event);
}
},plugin);
}


}

@EventHandler
public void onPlayerChat(PlayerChatEvent event) {
//创建数据文件实例
File dataFile = new File( "plugins/toNeko/nekos.yml");
Expand Down Expand Up @@ -67,6 +90,58 @@ public void onPlayerChat(PlayerChatEvent event) {
}

}

public void onPlayerChatPaper(AsyncChatEvent event){
event.setCancelled(true);
//创建数据文件实例
File dataFile = new File( "plugins/toNeko/nekos.yml");
// 加载数据文件
YamlConfiguration data = YamlConfiguration.loadConfiguration(dataFile);
Player player = event.getPlayer();
String message = MiniMessage.miniMessage().serialize(event.message());
//获取前缀
String publicPrefix = chatPrefix.getAllPublicPrefixValues();
String privatePrefix = chatPrefix.getPrivatePrefix(player);
//判断是否有私有前缀
if(privatePrefix.equalsIgnoreCase("[§a无前缀§f§r]")){
privatePrefix = "";
} else if (privatePrefix.equalsIgnoreCase("[§a无任何前缀§f§r]")) {
privatePrefix = "";
}
String prefix = publicPrefix + privatePrefix;
//判断是否有主人
if(data.getString(player.getName() + ".owner") != null) {
//获取主人名称
String owner =data.getString(player.getName()+".owner");
List<String> aliases = new ArrayList<>();
//获取主人别名
if (data.getList(player.getName()+".aliases") !=null){
aliases = data.getStringList(player.getName() + ".aliases");
} else {
//算是夹带私货吧(ps:这是我的正版账户名称)
aliases.add("Crystal_Neko");
}
// 对消息进行处理
String catMessage = catChatMessage(message,owner,aliases);
//替换屏蔽词
catMessage = replaceBlocks(catMessage,player.getName());
//Component modifiedMessage = Component.text(prefix + player.getName() + " >> §7" + catMessage);
// 修改消息的格式并重新发送
for (Player players : Bukkit.getOnlinePlayers()) {
// 向每个玩家发送消息
players.sendMessage(prefix + player.getName() + " >> §7" + catMessage);
}
} else {
//Component modifiedMessage = Component.text(prefix + player.getName() + " >> §7" + message);
for (Player players : Bukkit.getOnlinePlayers()) {
// 向每个玩家发送消息
players.sendMessage(prefix + player.getName() + " >> §7" + message);
}
}
}



public String catChatMessage(String message, String owner, List<String> aliases){
//将玩家名称替换为主人
message = message.replaceAll(owner, ToNeko.getMessage("other.owner"));
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/language/en_us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ command:
Invalid: "§cInvalid subcommand, please enter §a/neko help§c to view the help"
help: "§b/neko help:\n§a/neko help §bGet help\n§a/neko jump §bGet jump boost"
toneko:
help: "§b/toneko Help:\n§a/toneko help §bGet help\n§a/toneko player <player name> §bTurn a player into a catgirl (but you will be sacrificed)\n§a/ toneko item §bGet the cat stick\n§a/toneko remove <cat girl name> §bDelete cat girl§c (This is a dangerous operation, please use it with caution)\n§a/toneko xp <cat girl name> §bCheck the favorability Experience\n§a/toneko aliases <cat girl name> add or remove <alias> §bAdd or remove aliases for you (a word that will be converted to 'owner')\n§a/toneko block <cat girl name> add or remove <Blocking word> <Replacement word> word or all §bAdd a masking word (the masking word will be replaced with a replacement word, all means replacing the entire sentence, word replaces the word)"
help: "§b/toneko Help:\n§a/toneko help §bGet help\n§a/toneko player <player name> §bTurn a player into a catgirl (but you will be sacrificed)\n§a/ toneko item §bGet the cat stick\n§a/toneko remove <cat girl name> §bDelete cat girl§c (This is a dangerous operation, please use it with caution)\n§a/toneko xp <cat girl name> §bCheck the favorability Experience\n§a/toneko aliases <cat girl name> add or remove <alias> §bAdd or remove aliases for you (a word that will be converted to 'owner')\n§a/toneko block <cat girl name> add or remove <Blocking word> <Replacement word> word or all §bAdd a masking word (the masking word will be replaced with a replacement word, all means replacing the entire sentence, word replaces the word)"
folia:
use:
chatEvent: "Use of paper/Folia detected, Paper/Folia's chat listener will be used"
5 changes: 4 additions & 1 deletion src/main/resources/language/zh_cn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ command:
Invalid: "§c无效的子命令,请输入§a/neko help§c查看帮助"
help: "§b/neko 帮助:\n§a/neko help §b获取帮助\n§a/neko jump §b获取跳跃提升"
toneko:
help: "§b/toneko 帮助:\n§a/toneko help §b获取帮助\n§a/toneko player <玩家名> §b将一位玩家变成猫娘(但是你会被祭献)\n§a/toneko item §b获取撅猫棍\n§a/toneko remove <猫娘名称> §b删除猫娘§c(这是个危险操作,请谨慎使用)\n§a/toneko xp <猫娘名称> §b查看好感经验\n§a/toneko aliases <猫娘名称> add或remove <别名> §b为你添加或删除别名(会转换为'主人'的词)\n§a/toneko block <猫娘名称> add或remove <屏蔽词> <替换词> word或all §b添加屏蔽词(屏蔽词会被替换成替换词,all代表替换整句,word替换单词)"
help: "§b/toneko 帮助:\n§a/toneko help §b获取帮助\n§a/toneko player <玩家名> §b将一位玩家变成猫娘(但是你会被祭献)\n§a/toneko item §b获取撅猫棍\n§a/toneko remove <猫娘名称> §b删除猫娘§c(这是个危险操作,请谨慎使用)\n§a/toneko xp <猫娘名称> §b查看好感经验\n§a/toneko aliases <猫娘名称> add或remove <别名> §b为你添加或删除别名(会转换为'主人'的词)\n§a/toneko block <猫娘名称> add或remove <屏蔽词> <替换词> word或all §b添加屏蔽词(屏蔽词会被替换成替换词,all代表替换整句,word替换单词)"
folia:
use:
chatEvent: "检测到使用Paper/Folia,将使用Paper/Folia的聊天监听器"
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: toNeko
version: '0.1.0'
version: '0.1.1'
main: com.crystalneko.toneko.ToNeko
api-version: '1.20'
author: CrystalNeko
Expand Down

0 comments on commit 649a56d

Please sign in to comment.