Skip to content

Commit d7f119f

Browse files
committed
更新1.8快照版,修复一堆bug
1 parent 6ac76be commit d7f119f

File tree

7 files changed

+63
-24
lines changed

7 files changed

+63
-24
lines changed

README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
# MessageSync
2-
消息同步
1+
# ~~MessageSync~~ 多功能插件
2+
不仅仅是消息同步插件
33

44
# 概述
55
- 起源:[帖子](https://www.minept.top/p.php?id=30)
6+
这个插件其实是我学习Spigot插件写的,所有很多地方写的不好
7+
**由于功能越写越多,所以该插件目前的功能已经不仅仅是消息同步了**
68
- 版本:我也不知道兼容哪个版本,测试兼容spigot-1.19.3
7-
- 特别鸣谢:通过灰灰的[脏话屏蔽](https://github.com/MinecraftProgrammingTeam/ZangHuaPingBi)插件魔改
89

910
# 使用
10-
需配合[小猪比机器人](https://qb.xzy.center)使用,可以代替运行的Python脚本
11-
视频教程:[【MC服务器消息同步 - 小猪比机器人】 ](https://www.bilibili.com/video/BV1XU4y1r7z1/?share_source=copy_web&vd_source=6550d40762e4dc7c8327189d8582544b)
12-
需要填写配置,位于`./plugins/MessageSync/config.yml`
13-
其中:
14-
- `qn`:要将消息同步到的群号
15-
- `uuid`:机器人UUID
11+
相关视频教程:[【MC服务器消息同步 - 小猪比机器人】 ](https://www.bilibili.com/video/BV1XU4y1r7z1/?share_source=copy_web&vd_source=6550d40762e4dc7c8327189d8582544b)
12+
填写配置,位于`./plugins/MessageSync/config.yml`
13+
注释都很详细,全中文,看着填就行
1614

1715
# 已知问题
1816
可能会与以下插件发生冲突:

pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
<id>sonatype</id>
6464
<url>https://oss.sonatype.org/content/groups/public/</url>
6565
</repository>
66+
<repository>
67+
<id>puha-repo</id>
68+
<url>https://repo.puha.io/repo/</url>
69+
</repository>
6670
</repositories>
6771

6872
<dependencies>
@@ -77,5 +81,10 @@
7781
<artifactId>sqlite-jdbc</artifactId>
7882
<version>3.40.0.0</version>
7983
</dependency>
84+
<dependency>
85+
<groupId>io.puharesource.mc</groupId>
86+
<artifactId>TitleManager</artifactId>
87+
<version>2.2.0</version>
88+
</dependency>
8089
</dependencies>
8190
</project>

src/main/java/center/xzy/qb/messagesync/Main.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import center.xzy.qb.messagesync.executor.*;
44
import center.xzy.qb.messagesync.commands.*;
5+
import org.bukkit.GameMode;
56
import org.bukkit.Material;
67
import org.bukkit.inventory.ItemStack;
78
import org.bukkit.inventory.meta.ItemMeta;
@@ -25,23 +26,22 @@
2526
public final class Main extends JavaPlugin {
2627
public static boolean pluginStatus = true;
2728
public static Main instance;
28-
public static Map<String, List<String>> LoginData = new HashMap<>();
29-
public static Map<String, List<String>> regData = new HashMap<>();
30-
public static Map<String, String> regIpData = new HashMap<>();
31-
public static Connection dbConn;
32-
static {
29+
public static Map<String, List<String>> LoginData = new HashMap<>(); // 登录储存的玩家数据
30+
public static Map<String, String> gmData = new HashMap<>(); // 玩家游戏模式数据
31+
public static Map<String, List<String>> regData = new HashMap<>(); // 注册(二次输入密码)储存的玩家数据
32+
public static Map<String, String> regIpData = new HashMap<>(); // prelogin储存的登录IP数据
33+
public static Connection dbConn; // 数据库连接,在`onEnable`方法中初始化
34+
35+
@Override
36+
public void onEnable() {
37+
instance = this;
3338
try {
3439
dbConn = DriverManager.getConnection("jdbc:sqlite:"+System.getProperty("user.dir")+"/plugins/MessageSync/user.db");
3540
initDatabase(dbConn);
3641
} catch (SQLException e) {
3742
throw new RuntimeException(e);
3843
}
39-
}
40-
4144

42-
@Override
43-
public void onEnable() {
44-
instance = this;
4545
// Plugin startup logic
4646
// config.yml
4747
getConfig().options().copyDefaults();
@@ -55,7 +55,13 @@ public void onEnable() {
5555
// register events
5656
getServer().getPluginManager().registerEvents(new customEventHandler(), this);
5757
getServer().getPluginManager().registerEvents(new inventoryEventHandler(), this);
58-
getLogger().info(ChatColor.GREEN + "Enabled Message Sync Plugin for PBF!");
58+
59+
// check TitleManager
60+
// more code...
61+
62+
// log information
63+
getLogger().info(ChatColor.GREEN + "More info on " + ChatColor.BLUE + "https://minept.top");
64+
getLogger().info(ChatColor.GREEN + "Enabled MessageSync Plugin for PBF!");
5965
}
6066

6167
@Override

src/main/java/center/xzy/qb/messagesync/events/customEventHandler.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import center.xzy.qb.messagesync.scheduler.PlayerLogin;
44
import org.bukkit.Bukkit;
55
import org.bukkit.ChatColor;
6+
import org.bukkit.GameMode;
67
import org.bukkit.Material;
78
import org.bukkit.entity.Player;
89
import org.bukkit.event.EventHandler;
@@ -49,6 +50,17 @@ public void PlayerChat(AsyncPlayerChatEvent event) {
4950
sendRequest("<" + event.getPlayer().getName() + "> " + event.getMessage());
5051
}
5152

53+
@EventHandler
54+
public void PlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
55+
if (Main.regData.containsKey(event.getPlayer().getName()) || Main.LoginData.containsKey(event.getPlayer().getName())){
56+
if (!event.getMessage().equals("/ms login")){
57+
event.setMessage(" ");
58+
event.setCancelled(true);
59+
event.getPlayer().sendMessage(ChatColor.RED + "在通过登录/注册之前不可使用指令!");
60+
}
61+
}
62+
}
63+
5264
@EventHandler
5365
public void PlayerPreLogin(AsyncPlayerPreLoginEvent event) {
5466
if (Main.regIpData.containsKey(event.getName())){
@@ -89,6 +101,14 @@ public void PlayerLogin(PlayerJoinEvent event) {
89101
PlayerLogin playerLogin = new PlayerLogin();
90102
playerLogin.setPlayer(event.getPlayer());
91103
playerLogin.runTaskLater(Main.instance, timeout);
104+
Player player = event.getPlayer();
105+
if (Main.gmData.containsKey(player.getName())){
106+
Main.gmData.replace(player.getName(), player.getGameMode().toString());
107+
} else {
108+
Main.gmData.put(player.getName(), player.getGameMode().toString());
109+
}
110+
Main.instance.getLogger().warning(player.getGameMode().toString());
111+
player.setGameMode(GameMode.ADVENTURE);
92112
openInv(event.getPlayer(), title);
93113
}
94114
}

src/main/java/center/xzy/qb/messagesync/events/inventoryEventHandler.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package center.xzy.qb.messagesync.events;
22

33
import org.bukkit.ChatColor;
4+
import org.bukkit.GameMode;
45
import org.bukkit.entity.Player;
56
import org.bukkit.event.EventHandler;
67
import org.bukkit.event.Listener;
@@ -32,7 +33,11 @@ public class inventoryEventHandler implements Listener {
3233
}
3334

3435
private void cleanData(Player p) {
36+
p.setInvulnerable(false);
37+
Main.instance.getLogger().info(Main.gmData.get(p.getName()).toString());
38+
p.setGameMode(GameMode.valueOf(Main.gmData.get(p.getName())));
3539
Main.LoginData.remove(p.getName());
40+
Main.gmData.remove(p.getName());
3641
Main.regData.remove(p.getName());
3742
}
3843

@@ -64,6 +69,7 @@ public void onInventoryClick(InventoryClickEvent event) throws SQLException {
6469
if (Main.regIpData.containsKey(p.getName())) {
6570
ip = Main.regIpData.get(p.getName());
6671
} else {
72+
cleanData(p);
6773
p.kickPlayer("没有ID的PreLogin数据,请重试!");
6874
return ;
6975
}
@@ -75,6 +81,7 @@ public void onInventoryClick(InventoryClickEvent event) throws SQLException {
7581
}
7682

7783
if (ipCount >= plugin.getConfig().getInt("reg-ip-count") && plugin.getConfig().getInt("reg-ip-count") != 0) {
84+
cleanData(p);
7885
p.kickPlayer(plugin.getConfig().getString("reg-ip-max-fail-msg"));
7986
return ;
8087
}
@@ -86,10 +93,8 @@ public void onInventoryClick(InventoryClickEvent event) throws SQLException {
8693
statement.executeUpdate("insert into password values('" + p.getName() + "', '" + Main.MD5(password) + "', '" + dateString + "', '" + ip + "')");
8794
cleanData(p);
8895
p.closeInventory();
89-
p.setInvulnerable(false);
9096
p.sendMessage(ChatColor.GREEN + plugin.getConfig().getString("reg-success-msg"));
9197
} else {
92-
p.setInvulnerable(false);
9398
cleanData(p);
9499
p.kickPlayer(ChatColor.RED + "重复密码与密码不一致,请重试!");
95100
}
@@ -101,13 +106,11 @@ public void onInventoryClick(InventoryClickEvent event) throws SQLException {
101106
// 登录成功
102107
cleanData(p);
103108
p.closeInventory();
104-
p.setInvulnerable(false);
105109
p.sendMessage(ChatColor.GREEN + plugin.getConfig().getString("login-success-msg"));
106110
} else {
107111
// 密码错误
108112
cleanData(p);
109113
p.closeInventory();
110-
p.setInvulnerable(false);
111114
p.kickPlayer(ChatColor.RED + plugin.getConfig().getString("login-fail-msg"));
112115
}
113116
}

src/main/java/center/xzy/qb/messagesync/scheduler/PlayerLogin.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ public void setPlayer(Player p) {
1313
@Override
1414
public void run() {
1515
if (Main.regData.containsKey(player.getName())){
16+
Main.regData.remove(player.getName());
1617
player.kickPlayer(Main.instance.getConfig().getString("reg-allow-tick-msg"));
1718
} else if (Main.LoginData.containsKey(player.getName())) {
19+
Main.LoginData.remove(player.getName());
1820
player.kickPlayer(Main.instance.getConfig().getString("login-allow-tick-msg"));
1921
}
2022
}

src/main/resources/plugin.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ version: '${project.version}'
33
main: center.xzy.qb.messagesync.Main
44
api-version: 1.13
55
authors: [xzyStudio]
6+
soft-depend: [TitleManager]
67
description: Message Sync Plugin for PigBotFramework
78
website: https://qb.xzy.center
89
commands:

0 commit comments

Comments
 (0)