77 lines
3.1 KiB
Java
77 lines
3.1 KiB
Java
package eu.mhsl.craftattack.chatbridge;
|
|
|
|
import com.google.inject.Inject;
|
|
import com.velocitypowered.api.event.Subscribe;
|
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
|
import com.velocitypowered.api.plugin.Dependency;
|
|
import com.velocitypowered.api.plugin.Plugin;
|
|
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
|
import com.velocitypowered.api.proxy.ProxyServer;
|
|
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
|
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
|
import net.luckperms.api.LuckPermsProvider;
|
|
import org.slf4j.Logger;
|
|
|
|
import java.nio.file.Path;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
@Plugin(
|
|
id = "chat-bridge",
|
|
name = "chat-bridge",
|
|
version = "1.2.0",
|
|
description = "Serverübergreifender Chat und Tabliste: öffentlicher Chat, /msg, Adminchat, Mute, Join/Leave",
|
|
authors = {"MHSL"},
|
|
dependencies = {@Dependency(id = "luckperms")}
|
|
)
|
|
public final class ChatBridge {
|
|
/** Kanal zu spawn (Appliance NetworkChat): Rang-Prefixe und Chat-Einstellungen, Format siehe dort. */
|
|
static final ChannelIdentifier CHANNEL = MinecraftChannelIdentifier.create("craftattack", "chat");
|
|
|
|
/** Abgleich der Tablisten; nach Join, Wechsel und Quit zusätzlich kurz danach. */
|
|
static final long TAB_REFRESH_SECONDS = 2;
|
|
|
|
private final ProxyServer proxy;
|
|
private final Logger logger;
|
|
private final Path dataDirectory;
|
|
|
|
@Inject
|
|
public ChatBridge(ProxyServer proxy, Logger logger, @DataDirectory Path dataDirectory) {
|
|
this.proxy = proxy;
|
|
this.logger = logger;
|
|
this.dataDirectory = dataDirectory;
|
|
}
|
|
|
|
@Subscribe
|
|
public void onProxyInitialize(ProxyInitializeEvent event) {
|
|
Config config;
|
|
try {
|
|
config = Config.load(this.dataDirectory);
|
|
} catch (Exception e) {
|
|
this.logger.error("Konfiguration ungültig, chat-bridge ist aus", e);
|
|
return;
|
|
}
|
|
|
|
ChatSettings settings;
|
|
try {
|
|
settings = new ChatSettings(this.dataDirectory, this.logger);
|
|
} catch (Exception e) {
|
|
this.logger.error("settings.properties nicht lesbar, chat-bridge ist aus", e);
|
|
return;
|
|
}
|
|
|
|
Names names = new Names(config);
|
|
Mutes mutes = new Mutes(LuckPermsProvider.get());
|
|
Chat chat = new Chat(this.proxy, this.logger, config, names, mutes, settings);
|
|
PrivateMessages privateMessages = new PrivateMessages(this.proxy, this.logger, config, names, chat);
|
|
|
|
TabLists tabLists = new TabLists(this.proxy, config, names);
|
|
|
|
this.proxy.getChannelRegistrar().register(CHANNEL);
|
|
this.proxy.getEventManager().register(this, new ChatListener(this, this.proxy, this.logger, config, names, chat, privateMessages, settings, tabLists));
|
|
this.proxy.getScheduler().buildTask(this, tabLists::refresh).repeat(TAB_REFRESH_SECONDS, TimeUnit.SECONDS).schedule();
|
|
Commands.register(this, this.proxy, this.logger, config, names, chat, privateMessages, mutes);
|
|
|
|
this.logger.info("chat-bridge aktiv, Symbole {}, ohne Silencer {}", config.serverSymbols(), config.unsilencedServers());
|
|
}
|
|
}
|