push to git
This commit is contained in:
commit
45cb9eb63e
13
.idea/compiler.xml
Normal file
13
.idea/compiler.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="AdvancedChatFilter" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
14
.idea/misc.xml
Normal file
14
.idea/misc.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
2
AdvancedChatFilter.iml
Normal file
2
AdvancedChatFilter.iml
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4" />
|
49
pom.xml
Normal file
49
pom.xml
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>cn.dejavu</groupId>
|
||||
<artifactId>AdvancedChatFilter</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>bungeecord-repo</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.6.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.12-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.12-SNAPSHOT</version>
|
||||
<type>javadoc</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
104
src/main/java/cn/dejavu/AdvancedChatFilter/Main.java
Normal file
104
src/main/java/cn/dejavu/AdvancedChatFilter/Main.java
Normal file
|
@ -0,0 +1,104 @@
|
|||
package cn.dejavu.AdvancedChatFilter;
|
||||
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.Connection;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.ChatEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Main extends Plugin implements Listener {
|
||||
Configuration configuration;
|
||||
static Main instance;
|
||||
private List<String> censorWords = new ArrayList<>();
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
getLogger().info("AdvancedChatFilter by Deja_Vu deleveop Team");
|
||||
getLogger().info("Loading config...");
|
||||
loadConfig();
|
||||
getProxy().getPluginManager().registerListener(this,this);
|
||||
censorWords=configuration.getStringList("words");
|
||||
|
||||
}
|
||||
@EventHandler
|
||||
public void onChat(ChatEvent e){
|
||||
String msg = e.getMessage();
|
||||
ProxiedPlayer sender = (ProxiedPlayer) e.getSender();
|
||||
Connection receiver = e.getReceiver();
|
||||
//First check is or not contain censorWords.
|
||||
for (String singleCensorWord : censorWords){
|
||||
boolean contain = msg.contains(singleCensorWord);
|
||||
if(contain){
|
||||
if(msg.startsWith("/"))
|
||||
return; //Ignore command
|
||||
//Check is it contain censor username player in same server with detect player
|
||||
String bungeeServer = sender.getServer().getInfo().getName();
|
||||
ServerInfo inServer = getProxy().getServerInfo(bungeeServer);
|
||||
Collection<ProxiedPlayer> playerInSameServer = inServer.getPlayers();
|
||||
|
||||
for (ProxiedPlayer inSameServerPlayer : playerInSameServer) {
|
||||
if (inSameServerPlayer.getName().contains(singleCensorWord))
|
||||
return; //Maybe just call that player
|
||||
}
|
||||
|
||||
//All not, 盘他
|
||||
processCensorWord(sender,receiver,singleCensorWord);
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void processCensorWord(ProxiedPlayer sender, Connection receiver, String singleCensorWord){
|
||||
sender.sendMessage(ChatMessageType.CHAT, new TextComponent(configuration.getString("msg.censor-word-detected")));
|
||||
new censorWebhook(sender,receiver,singleCensorWord);
|
||||
}
|
||||
|
||||
private void loadConfig(){
|
||||
if (!getDataFolder().exists())
|
||||
getDataFolder().mkdir();
|
||||
File file = new File(getDataFolder(), "config.yml");
|
||||
|
||||
if (!file.exists()) {
|
||||
try (InputStream in = getResourceAsStream("config.yml")) {
|
||||
Files.copy(in, file.toPath()); //Create default config file.
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml"));
|
||||
}catch (IOException e){
|
||||
getLogger().log(Level.SEVERE,"Failed to load configuration.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void saveConfig(){
|
||||
try {
|
||||
ConfigurationProvider.getProvider(YamlConfiguration.class).save(configuration, new File(getDataFolder(), "config.yml"));
|
||||
}catch (IOException e){
|
||||
getLogger().log(Level.SEVERE,"Failed to save configuration.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package cn.dejavu.AdvancedChatFilter;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import net.md_5.bungee.api.connection.Connection;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class censorWebhook {
|
||||
private ExecutorService executor = Executors.newFixedThreadPool(1);
|
||||
public censorWebhook (ProxiedPlayer sender, Connection receiver, String singleCensorWord){
|
||||
submit(sender.getUniqueId(),sender.getName(),System.currentTimeMillis(),receiver.getAddress().toString(),singleCensorWord);
|
||||
}
|
||||
|
||||
private void submit(UUID uuid, String username, long timeStamp, String receiverIPAddress, String censorWord){
|
||||
executor.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try{
|
||||
URL url = new URL(Main.instance.configuration.getString("submit.url"));
|
||||
URLConnection conn = url.openConnection();
|
||||
conn.setRequestProperty("accept", "*/*");
|
||||
conn.setRequestProperty("connection", "Keep-Alive");
|
||||
conn.setRequestProperty("user-agent","AdvancedChatFilter");
|
||||
conn.setDoOutput(true);
|
||||
conn.setDoInput(true);
|
||||
PrintWriter out = new PrintWriter(conn.getOutputStream());
|
||||
Map<String,String> map = new HashMap<>();
|
||||
SubmitData data = new SubmitData(Main.instance.configuration.getString("submit.key"),uuid.toString(),username,String.valueOf(username),receiverIPAddress,censorWord);
|
||||
Gson gson = new Gson();
|
||||
gson.toJson(data);
|
||||
out.print(data);
|
||||
out.flush();
|
||||
out.close();
|
||||
}catch (Exception ex){
|
||||
Main.instance.getLogger().log(Level.WARNING,"Failed to submit censor data.");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
class SubmitData{
|
||||
String key;String uuid; String username; String time; String receiverip; String censorword;
|
||||
public SubmitData(String key,String uuid, String username, String time, String receiverip, String censorword){
|
||||
this.key=key;
|
||||
this.uuid=uuid;
|
||||
this.username=username;
|
||||
this.time=time;
|
||||
this.receiverip=receiverip;
|
||||
this.censorword=censorword;
|
||||
}
|
||||
}
|
4
src/main/resources/bungee.yml
Normal file
4
src/main/resources/bungee.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
name: AdvancedChatFilter
|
||||
main: cn.dejavu.AdvancedChatFilter.Main
|
||||
version: 1.0
|
||||
author: Ghost_chu
|
10
src/main/resources/config.yml
Normal file
10
src/main/resources/config.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
msg:
|
||||
censor-word-detected: "§c[Deja Vu] 您发出的聊天信息包含敏感词汇,因此您的信息已被拒收并记录在案,管理员将会对您的聊天信息进行审查"
|
||||
submit:
|
||||
url: "https://api.deja_vu.cn/censor/submit.php"
|
||||
#服务器端应拒绝错误Key的数据提交
|
||||
key: "@!#$%$^()(*&^%$#@!#$%^&*(*&^%$#ADF_DEJA-VU@#$%^&*&^%$#@!@#$%^&*(*&^%$#$%^&*("
|
||||
word:
|
||||
- "敏感词1"
|
||||
- "敏感词2"
|
||||
- "敏感词3"
|
Loading…
Reference in New Issue
Block a user