Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
AxieFeat authored Apr 10, 2024
1 parent 763d40d commit 68d82a9
Show file tree
Hide file tree
Showing 7 changed files with 352 additions and 0 deletions.
141 changes: 141 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?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>net</groupId>
<artifactId>FunFilter</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<name>FunFilter</name>

<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.version>1.9.23</kotlin.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>1.8</jvmTarget>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

<repositories>
<repository>
<id>papermc-repo</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/repository/public/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>5.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
30 changes: 30 additions & 0 deletions src/main/java/me/arial/filter/Color.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package me.arial.filter

import net.md_5.bungee.api.ChatColor
import java.util.regex.Pattern

class Color {
companion object {
fun parseString(message: String): String {
var message = message
val pattern = Pattern.compile("&#[a-fA-F0-9]{6}")
var matcher = pattern.matcher(message)

while (matcher.find()) {
val color = message.substring(matcher.start() + 1, matcher.end())
message = message.replace("&$color", ChatColor.of(color).toString() + "")
matcher = pattern.matcher(message)
}

return ChatColor.translateAlternateColorCodes('&', message)
}

fun parse(message: Any): Any {
return when (message) {
is String -> parseString(message)
is MutableList<*> -> message.stream().map { parseString(it.toString()) }.toList()
else -> message
}
}
}
}
28 changes: 28 additions & 0 deletions src/main/java/me/arial/filter/Command.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package me.arial.filter

import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import org.bukkit.command.TabExecutor

class Command : TabExecutor {
override fun onTabComplete(
p0: CommandSender,
p1: Command,
p2: String,
p3: Array<out String>?
): MutableList<String> {
return mutableListOf()
}

override fun onCommand(sender: CommandSender, p1: Command, p2: String, p3: Array<out String>?): Boolean {
if (!sender.hasPermission("funfilter.admin")) {
return true
}

Main.instance!!.reloadConfig()
Main.instance!!.load()

sender.sendMessage("Плагин перезагружен!")
return true
}
}
96 changes: 96 additions & 0 deletions src/main/java/me/arial/filter/EventListener.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package me.arial.filter

import com.comphenix.protocol.PacketType
import com.comphenix.protocol.ProtocolLibrary
import com.comphenix.protocol.events.ListenerPriority
import com.comphenix.protocol.events.PacketAdapter
import com.comphenix.protocol.events.PacketEvent
import com.comphenix.protocol.wrappers.WrappedChatComponent
import org.bukkit.Bukkit
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.AsyncPlayerChatEvent
import java.util.regex.Matcher
import java.util.regex.Pattern


class EventListener : Listener {

init {
Bukkit.getServer().pluginManager.registerEvents(this, Main.instance!!)

val protocolManager = ProtocolLibrary.getProtocolManager()

protocolManager.addPacketListener(
object : PacketAdapter(
Main.instance!!,
ListenerPriority.NORMAL,
PacketType.Play.Server.CHAT
) {
override fun onPacketSending(e: PacketEvent) {
if (!e.player.hasPermission("funfilter.view")) {
val container = e.packet
val newPacket = container.deepClone()

val chatComponent: WrappedChatComponent? = newPacket.chatComponents.read(0) ?: return
val message = parseMessage(
chatComponent!!.json,
Main.instance!!.blockedWords,
Main.instance!!.config.getString("toBlock")!!
)

chatComponent.json = message;
newPacket.chatComponents.write(0, chatComponent);

e.packet = newPacket
}
}
}
)
}

@EventHandler
fun onChat(e: AsyncPlayerChatEvent) {
if (!e.isAsynchronous) return

val player = e.player

if (Main.instance!!.config.getBoolean("symbolBlocker.enabled") && !player.hasPermission("funfilter.symbolblocker.bypass")) {
val pattern: Pattern = Pattern.compile(
Main.instance!!.config.getString("symbolBlocker.regex")!!
)
val matcher: Matcher = pattern.matcher(e.message)

while (!matcher.find()) {
player.sendMessage(
Color.parseString(
Main.instance!!.config.getString("symbolBlocker.message")!!
)
)
e.isCancelled = true
return
}
}

// if (!player.hasPermission("funfilter.blocker.bypass")) {
// e.message = parseMessage(
// e.message,
// Main.instance!!.blockedWords,
// Main.instance!!.config.getString("toBlock")!!
// )
// }
}

private fun parseMessage(message: String, words: List<String>, replace: String): String {
var updatedMessage = message
for (word in words) {
val regex = Regex("\\b$word\\b", RegexOption.IGNORE_CASE)
updatedMessage = regex.replace(updatedMessage) { matchResult ->
matchResult.value.replaceRange(1, matchResult.value.length - 1, replace.repeat(matchResult.value.length - 2))
}
}
return updatedMessage
}

}
32 changes: 32 additions & 0 deletions src/main/java/me/arial/filter/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package me.arial.filter

import org.bukkit.plugin.java.JavaPlugin

class Main : JavaPlugin() {

companion object {
var instance: Main? = null
}

val blockedWords: MutableList<String> = mutableListOf()

override fun onEnable() {
instance = this

saveDefaultConfig()

EventListener()
getCommand("funfilter")!!.setExecutor(Command())
getCommand("funfilter")!!.tabCompleter = Command()

load()
}

fun load() {
blockedWords.clear()

config.getStringList("blockedWords").forEach {
blockedWords.add(it)
}
}
}
16 changes: 16 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# /funfilter - перезагрузка плагина (Пермишен funfilter.admin)
#
# funfilter.symbolblocker.bypass - обход ограничений по символам
# funfilter.view - просмотр мата в сообщениях

symbolBlocker:
enabled: true
regex: "[а-яА-ЯёЁa-zA-Z0-9]"
message: "Вы используете запрещённые символы!"

# Символ, которым заменяется
toBlock: '*'

# Список заблокированных слов
blockedWords:
- "блять"
9 changes: 9 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: FunFilter
version: '1.0'
main: me.arial.filter.Main
api-version: '1.16'
depend:
- ProtocolLib

commands:
funfilter:

0 comments on commit 68d82a9

Please sign in to comment.