Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
1de5301f71 | |||
4d8b7e16ca | |||
71b9d85f3c | |||
85014a68b7 | |||
aec2de9305 | |||
7ffd227fa4 | |||
81f3ba5a5f | |||
810649c0a1 | |||
99ed66cbab | |||
d8e6ab016a | |||
e0292702d7 | |||
1042618392 | |||
1b863a9786 |
42
GlobalChatSuppressor/pom.xml
Normal file
42
GlobalChatSuppressor/pom.xml
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<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>de.viper.globalchat</groupId>
|
||||||
|
<artifactId>GlobalChatSuppressor</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>GlobalChatSuppressor</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<java.version>17</java.version>
|
||||||
|
<spigot.version>1.21.1-R0.1-SNAPSHOT</spigot.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>${spigot.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.13.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>${java.version}</source>
|
||||||
|
<target>${java.version}</target>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@@ -0,0 +1,79 @@
|
|||||||
|
package de.viper.globalchat.suppressor;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class GlobalChatSuppressor extends JavaPlugin implements PluginMessageListener, Listener {
|
||||||
|
|
||||||
|
private static final String CHANNEL = "global:control";
|
||||||
|
private final Set<UUID> suppressJoinQuit = new HashSet<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
getServer().getMessenger().registerIncomingPluginChannel(this, CHANNEL, this);
|
||||||
|
getServer().getMessenger().registerOutgoingPluginChannel(this, CHANNEL);
|
||||||
|
getServer().getPluginManager().registerEvents(this, this);
|
||||||
|
getLogger().info("GlobalChatSuppressor aktiviert!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
getServer().getMessenger().unregisterIncomingPluginChannel(this, CHANNEL);
|
||||||
|
getServer().getMessenger().unregisterOutgoingPluginChannel(this, CHANNEL);
|
||||||
|
getLogger().info("GlobalChatSuppressor deaktiviert!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||||
|
if (!channel.equals(CHANNEL)) return;
|
||||||
|
|
||||||
|
try (DataInputStream in = new DataInputStream(new ByteArrayInputStream(message))) {
|
||||||
|
String subChannel = in.readUTF();
|
||||||
|
if ("suppress".equalsIgnoreCase(subChannel)) {
|
||||||
|
String uuidStr = in.readUTF();
|
||||||
|
UUID playerUUID = UUID.fromString(uuidStr);
|
||||||
|
suppressJoinQuit.add(playerUUID);
|
||||||
|
getLogger().info("Suppress für Spieler UUID: " + playerUUID + " aktiviert.");
|
||||||
|
// Entferne die Unterdrückung nach 2 Sekunden (synchron mit BungeeCord)
|
||||||
|
getServer().getScheduler().runTaskLater(this, () -> {
|
||||||
|
suppressJoinQuit.remove(playerUUID);
|
||||||
|
getLogger().info("Suppress für Spieler UUID: " + playerUUID + " entfernt.");
|
||||||
|
}, 40L); // 40 Ticks = 2 Sekunden
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (suppressJoinQuit.contains(player.getUniqueId())) {
|
||||||
|
event.setJoinMessage(null);
|
||||||
|
getLogger().info("Join-Nachricht für " + player.getName() + " unterdrückt.");
|
||||||
|
suppressJoinQuit.remove(player.getUniqueId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (suppressJoinQuit.contains(player.getUniqueId())) {
|
||||||
|
event.setQuitMessage(null);
|
||||||
|
getLogger().info("Quit-Nachricht für " + player.getName() + " unterdrückt.");
|
||||||
|
suppressJoinQuit.remove(player.getUniqueId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,35 @@
|
|||||||
|
package de.viper.globalchat.suppressor;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class SuppressManager {
|
||||||
|
|
||||||
|
private static final Set<UUID> suppressedPlayers = Collections.synchronizedSet(new HashSet<>());
|
||||||
|
|
||||||
|
public static void register(GlobalChatSuppressor plugin) {
|
||||||
|
// Nichts weiter nötig, die Nachrichten werden beim Join/Quit-Event unterdrückt
|
||||||
|
// via AsyncPlayerPreLogin oder PlayerJoin/Leave in Hauptplugin
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void suppress(UUID playerUUID) {
|
||||||
|
suppressedPlayers.add(playerUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void unsuppress(UUID playerUUID) {
|
||||||
|
suppressedPlayers.remove(playerUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isSuppressed(UUID playerUUID) {
|
||||||
|
return suppressedPlayers.contains(playerUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Set<UUID> getSuppressedPlayers() {
|
||||||
|
return suppressedPlayers;
|
||||||
|
}
|
||||||
|
}
|
6
GlobalChatSuppressor/src/main/resources/plugin.yml
Normal file
6
GlobalChatSuppressor/src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
name: GlobalChatSuppressor
|
||||||
|
version: 1.0.0
|
||||||
|
main: de.viper.globalchat.suppressor.GlobalChatSuppressor
|
||||||
|
api-version: 1.21
|
||||||
|
author: M_Viper
|
||||||
|
commands: {}
|
Reference in New Issue
Block a user