Skip to content

Commit

Permalink
BungeeCord support
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Apr 17, 2024
1 parent 9f00e25 commit a4a4076
Show file tree
Hide file tree
Showing 21 changed files with 200 additions and 6 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
cache: 'maven'
- name: Build
run: mvn -V -B clean package --file pom.xml
- name: Upload Artifacts
- name: Upload Bukkit Artifacts
uses: actions/upload-artifact@v3.1.2
with:
name: Download-Bukkit
Expand All @@ -31,6 +31,11 @@ jobs:
with:
name: Download-Velocity
path: ./velocity/target/AdvancedSensitiveWords-velocity.jar
- name: Upload BungeeCord Artifacts
uses: actions/upload-artifact@v3.1.2
with:
name: Download-BungeeCord
path: ./bungee/target/AdvancedSensitiveWords-bungee.jar
runtime-test:
name: Plugin Runtime Test
needs: [Build]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Logo designed by GPT-4
## Supported Platforms
- Spigot(stable)
- Velocity(experimental)
- BungeeCord(WIP)
- BungeeCord(experimental)
- Sponge(WIP)
- Fabric(Planned)
- Forge/NeoForge(Coming s∞n)
Expand Down
2 changes: 1 addition & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Logo 由 GPT-4 生成
## 支持平台
- Spigot(稳定)
- Velocity(测试)
- BungeeCord(在做了在做了)
- BungeeCord(测试)
- Sponge(在做了在做了)
- Fabric(计划中)
- Forge/NeoForge(Coming s∞n)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import io.wdsj.asw.bukkit.listener.packet.ASWPacketListener;
import io.wdsj.asw.bukkit.listener.packet.ProtocolLibListener;
import io.wdsj.asw.bukkit.method.*;
import io.wdsj.asw.bukkit.proxy.bungee.BungeeCordChannel;
import io.wdsj.asw.bukkit.proxy.bungee.BungeeReceiver;
import io.wdsj.asw.bukkit.proxy.velocity.VelocityChannel;
import io.wdsj.asw.bukkit.proxy.velocity.VelocityReceiver;
import io.wdsj.asw.bukkit.setting.PluginMessages;
Expand Down Expand Up @@ -134,6 +136,10 @@ public void onEnable() {
getServer().getMessenger().registerOutgoingPluginChannel(this, VelocityChannel.CHANNEL);
getServer().getMessenger().registerIncomingPluginChannel(this, VelocityChannel.CHANNEL, new VelocityReceiver());
}
if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) {
getServer().getMessenger().registerOutgoingPluginChannel(this, BungeeCordChannel.BUNGEE_CHANNEL);
getServer().getMessenger().registerIncomingPluginChannel(this, BungeeCordChannel.BUNGEE_CHANNEL, new BungeeReceiver());
}
long endTime = System.currentTimeMillis();
logger.info("AdvancedSensitiveWords is enabled!(took " + (endTime - startTime) + "ms)");
if (settingsManager.getProperty(PluginSettings.CHECK_FOR_UPDATE)) {
Expand Down Expand Up @@ -177,6 +183,11 @@ public void onDisable() {
} else {
com.comphenix.protocol.ProtocolLibrary.getProtocolManager().removePacketListeners(this);
}
if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD) ||
settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) {
getServer().getMessenger().unregisterOutgoingPluginChannel(this);
getServer().getMessenger().unregisterIncomingPluginChannel(this);
}
TimingUtils.cleanStatisticCache();
ChatContext.forceClearContext();
BookCache.forceClearCache();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.wdsj.asw.bukkit.event.EventType;
import io.wdsj.asw.bukkit.manage.notice.Notifier;
import io.wdsj.asw.bukkit.manage.punish.Punishment;
import io.wdsj.asw.bukkit.proxy.bungee.BungeeSender;
import io.wdsj.asw.bukkit.proxy.velocity.VelocitySender;
import io.wdsj.asw.bukkit.setting.PluginMessages;
import io.wdsj.asw.bukkit.setting.PluginSettings;
Expand Down Expand Up @@ -71,6 +72,11 @@ public void onAnvil(InventoryClickEvent event) {
if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) {
VelocitySender.send(player, EventType.ANVIL, originalItemName);
}

if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) {
BungeeSender.send(player, EventType.ANVIL, originalItemName);
}

long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.ANVIL, originalItemName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.wdsj.asw.bukkit.impl.list.AdvancedList;
import io.wdsj.asw.bukkit.manage.notice.Notifier;
import io.wdsj.asw.bukkit.manage.punish.Punishment;
import io.wdsj.asw.bukkit.proxy.bungee.BungeeSender;
import io.wdsj.asw.bukkit.proxy.velocity.VelocitySender;
import io.wdsj.asw.bukkit.setting.PluginMessages;
import io.wdsj.asw.bukkit.setting.PluginSettings;
Expand Down Expand Up @@ -115,6 +116,9 @@ public void onBook(PlayerEditBookEvent event) {
if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) {
VelocitySender.send(player, EventType.BOOK, outMessage);
}
if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) {
BungeeSender.send(player, EventType.BOOK, outMessage);
}
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.BOOK, outMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.wdsj.asw.bukkit.event.EventType;
import io.wdsj.asw.bukkit.manage.notice.Notifier;
import io.wdsj.asw.bukkit.manage.punish.Punishment;
import io.wdsj.asw.bukkit.proxy.bungee.BungeeSender;
import io.wdsj.asw.bukkit.proxy.velocity.VelocitySender;
import io.wdsj.asw.bukkit.setting.PluginMessages;
import io.wdsj.asw.bukkit.setting.PluginSettings;
Expand Down Expand Up @@ -63,6 +64,9 @@ public void onChat(AsyncPlayerChatEvent event) {
if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) {
VelocitySender.send(player, EventType.CHAT, originalMessage);
}
if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) {
BungeeSender.send(player, EventType.CHAT, originalMessage);
}
long endTime = System.currentTimeMillis();
TimingUtils.addProcessStatistic(endTime, startTime);
getScheduler().runTask(()-> {
Expand Down Expand Up @@ -99,6 +103,9 @@ public void onChat(AsyncPlayerChatEvent event) {
if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) {
VelocitySender.send(player, EventType.CHAT, originalContext);
}
if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) {
BungeeSender.send(player, EventType.CHAT, originalContext);
}
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
getScheduler().runTask(()-> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.wdsj.asw.bukkit.event.EventType;
import io.wdsj.asw.bukkit.manage.notice.Notifier;
import io.wdsj.asw.bukkit.manage.punish.Punishment;
import io.wdsj.asw.bukkit.proxy.bungee.BungeeSender;
import io.wdsj.asw.bukkit.proxy.velocity.VelocitySender;
import io.wdsj.asw.bukkit.setting.PluginMessages;
import io.wdsj.asw.bukkit.setting.PluginSettings;
Expand Down Expand Up @@ -55,6 +56,9 @@ public void onCommand(PlayerCommandPreprocessEvent event) {
if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) {
VelocitySender.send(player, EventType.CHAT, originalCommand);
}
if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) {
BungeeSender.send(player, EventType.CHAT, originalCommand);
}
long endTime = System.currentTimeMillis();
TimingUtils.addProcessStatistic(endTime, startTime);
if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.CHAT, originalCommand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.wdsj.asw.bukkit.event.EventType;
import io.wdsj.asw.bukkit.manage.notice.Notifier;
import io.wdsj.asw.bukkit.manage.punish.Punishment;
import io.wdsj.asw.bukkit.proxy.bungee.BungeeSender;
import io.wdsj.asw.bukkit.proxy.velocity.VelocitySender;
import io.wdsj.asw.bukkit.setting.PluginMessages;
import io.wdsj.asw.bukkit.setting.PluginSettings;
Expand Down Expand Up @@ -101,6 +102,9 @@ public void onDrop(PlayerDropItemEvent event) {
if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) {
VelocitySender.send(player, EventType.ITEM, originalName);
}
if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) {
BungeeSender.send(player, EventType.ITEM, originalName);
}
long endTime = System.currentTimeMillis();
TimingUtils.addProcessStatistic(endTime, startTime);
if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.ITEM, originalName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.wdsj.asw.bukkit.event.EventType;
import io.wdsj.asw.bukkit.manage.notice.Notifier;
import io.wdsj.asw.bukkit.manage.punish.Punishment;
import io.wdsj.asw.bukkit.proxy.bungee.BungeeSender;
import io.wdsj.asw.bukkit.proxy.velocity.VelocitySender;
import io.wdsj.asw.bukkit.setting.PluginMessages;
import io.wdsj.asw.bukkit.setting.PluginSettings;
Expand Down Expand Up @@ -59,6 +60,9 @@ public void onLogin(PlayerLoginEvent event) {
if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) {
VelocitySender.send(player, EventType.NAME, playerName);
}
if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) {
BungeeSender.send(player, EventType.NAME, playerName);
}
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.NAME, playerName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.wdsj.asw.bukkit.impl.list.AdvancedList;
import io.wdsj.asw.bukkit.manage.notice.Notifier;
import io.wdsj.asw.bukkit.manage.punish.Punishment;
import io.wdsj.asw.bukkit.proxy.bungee.BungeeSender;
import io.wdsj.asw.bukkit.proxy.velocity.VelocitySender;
import io.wdsj.asw.bukkit.setting.PluginMessages;
import io.wdsj.asw.bukkit.setting.PluginSettings;
Expand Down Expand Up @@ -96,7 +97,11 @@ public void onSign(SignChangeEvent event) {
}

if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY) && shouldSendMessage) {
VelocitySender.send(player, EventType.CHAT, outMessage);
VelocitySender.send(player, EventType.SIGN, outMessage);
}

if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) {
BungeeSender.send(player, EventType.SIGN, outMessage);
}

if (shouldSendMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.wdsj.asw.bukkit.event.EventType;
import io.wdsj.asw.bukkit.manage.notice.Notifier;
import io.wdsj.asw.bukkit.manage.punish.Punishment;
import io.wdsj.asw.bukkit.proxy.bungee.BungeeSender;
import io.wdsj.asw.bukkit.proxy.velocity.VelocitySender;
import io.wdsj.asw.bukkit.setting.PluginMessages;
import io.wdsj.asw.bukkit.setting.PluginSettings;
Expand Down Expand Up @@ -79,6 +80,9 @@ public void onPacketReceive(PacketReceiveEvent event) {
if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) {
VelocitySender.send(player, EventType.CHAT, originalMessage);
}
if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) {
BungeeSender.send(player, EventType.CHAT, originalMessage);
}
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
getScheduler().runTask(()-> {
Expand Down Expand Up @@ -115,6 +119,9 @@ public void onPacketReceive(PacketReceiveEvent event) {
if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) {
VelocitySender.send(player, EventType.CHAT, originalContext);
}
if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) {
BungeeSender.send(player, EventType.CHAT, originalContext);
}
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
getScheduler().runTask(() -> {
Expand Down Expand Up @@ -154,6 +161,9 @@ public void onPacketReceive(PacketReceiveEvent event) {
if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) {
VelocitySender.send(player, EventType.CHAT, originalCommand);
}
if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) {
BungeeSender.send(player, EventType.CHAT, originalCommand);
}
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
getScheduler().runTask(()-> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.wdsj.asw.bukkit.event.EventType;
import io.wdsj.asw.bukkit.manage.notice.Notifier;
import io.wdsj.asw.bukkit.manage.punish.Punishment;
import io.wdsj.asw.bukkit.proxy.bungee.BungeeSender;
import io.wdsj.asw.bukkit.proxy.velocity.VelocitySender;
import io.wdsj.asw.bukkit.setting.PluginMessages;
import io.wdsj.asw.bukkit.setting.PluginSettings;
Expand Down Expand Up @@ -77,6 +78,9 @@ public void onPacketReceiving(@NotNull com.comphenix.protocol.events.PacketEvent
if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) {
VelocitySender.send(player, EventType.CHAT, message);
}
if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) {
BungeeSender.send(player, EventType.CHAT, message);
}
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
getScheduler().runTask(()-> {
Expand Down Expand Up @@ -110,6 +114,9 @@ public void onPacketReceiving(@NotNull com.comphenix.protocol.events.PacketEvent
if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) {
VelocitySender.send(player, EventType.CHAT, originalContext);
}
if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) {
BungeeSender.send(player, EventType.CHAT, originalContext);
}
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
getScheduler().runTask(()-> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.wdsj.asw.bukkit.proxy.bungee;

public class BungeeCordChannel {
public static final String BUNGEE_CHANNEL = "BungeeCord";
public static final String SUB_CHANNEL = "asw";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.wdsj.asw.bukkit.proxy.bungee;

import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
import io.wdsj.asw.bukkit.setting.PluginMessages;
import io.wdsj.asw.bukkit.setting.PluginSettings;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;

import java.util.Collection;

import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.messagesManager;
import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.settingsManager;

public class BungeeReceiver implements PluginMessageListener {
@Override
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
if (channel.equals(BungeeCordChannel.BUNGEE_CHANNEL)) {
ByteArrayDataInput input = ByteStreams.newDataInput(message);
String subChannel = input.readUTF();
if (subChannel.equals(BungeeCordChannel.SUB_CHANNEL)) {
String playerName = input.readUTF();
String eventType = input.readUTF();
String originalMessage = input.readUTF();
String serverName = input.readUTF();
if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) {
Collection<? extends Player> players = Bukkit.getOnlinePlayers();
String msg = ChatColor.translateAlternateColorCodes('&', messagesManager.getProperty(PluginMessages.ADMIN_REMINDER).replace("%player%", playerName + "(" + serverName + ")").replace("%type%", eventType).replace("%message%", originalMessage));
for (Player iPlayer : players) {
if (iPlayer.hasPermission("advancedsensitivewords.notice")) {
iPlayer.sendMessage(msg);
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.wdsj.asw.bukkit.proxy.bungee;

import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import io.wdsj.asw.bukkit.AdvancedSensitiveWords;
import io.wdsj.asw.bukkit.event.EventType;
import org.bukkit.entity.Player;

public class BungeeSender {
public static void send(Player violatedPlayer, EventType eventType, String originalMessage) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF(BungeeCordChannel.SUB_CHANNEL);
out.writeUTF(violatedPlayer.getName());
out.writeUTF(eventType.toString());
out.writeUTF(originalMessage);
byte[] data = out.toByteArray();
violatedPlayer.sendPluginMessage(AdvancedSensitiveWords.getInstance(), BungeeCordChannel.BUNGEE_CHANNEL, data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public class PluginSettings implements SettingsHolder {
@Comment({"*是否启用Velocity支持",
"*Whether to enable Velocity support"})
public static final Property<Boolean> HOOK_VELOCITY = newProperty("Plugin.hookVelocity", false);
@Comment({"*是否启用BungeeCord支持",
"*Whether to enable BungeeCord support"})
public static final Property<Boolean> HOOK_BUNGEECORD = newProperty("Plugin.hookBungeeCord", false);

@Comment({"是否启用AuthMe兼容(在玩家未登录时不进行检测, 避免误判)",
"Whether to enable AuthMe compatibility (no checks on players not logged in to avoid false positives)"})
Expand Down
3 changes: 3 additions & 0 deletions bungee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
</goals>
</execution>
</executions>
<configuration>
<finalName>${project.artifactId}</finalName>
</configuration>
</plugin>
</plugins>
<resources>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package io.wdsj.asw.bungee;

import io.wdsj.asw.bungee.listener.PluginMessageListener;
import net.md_5.bungee.api.plugin.Plugin;

public final class AdvancedSensitiveWords extends Plugin {
public static final String BUNGEE_CHANNEL = "BungeeCord";
public static final String SUB_CHANNEL = "asw";

private static AdvancedSensitiveWords instance;
public static AdvancedSensitiveWords getInstance() {
return instance;
}

@Override
public void onEnable() {
// Plugin startup logic
instance = this;
getProxy().getPluginManager().registerListener(this, new PluginMessageListener());
}

@Override
public void onDisable() {
// Plugin shutdown logic
getProxy().getPluginManager().unregisterListener(new PluginMessageListener());
}
}
Loading

0 comments on commit a4a4076

Please sign in to comment.