Add basic vanish support for join/quit messages

This commit is contained in:
Bea 2021-10-02 17:03:34 +02:00
parent f3336c9722
commit 2b6262df9a
2 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,44 @@
package de.Linus122.Handlers;
import de.Linus122.Telegram.Utils;
import de.Linus122.TelegramChat.TelegramChat;
import de.Linus122.TelegramComponents.ChatMessageToTelegram;
import de.myzelyam.api.vanish.PlayerHideEvent;
import de.myzelyam.api.vanish.PlayerShowEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class VanishHandler implements Listener
{
@EventHandler
public void onVanish(PlayerHideEvent e) {
Player p = e.getPlayer();
if(e.isCancelled()) return;
if (!TelegramChat.getInstance().getConfig().getBoolean("enable-joinquitmessages"))
return;
if (TelegramChat.telegramHook.connected) {
ChatMessageToTelegram chat = new ChatMessageToTelegram();
chat.parse_mode = "Markdown";
chat.text = Utils.formatMSG("quit-message", e.getPlayer().getName())[0];
TelegramChat.telegramHook.sendAll(chat);
}
}
@EventHandler
public void onShow(PlayerShowEvent e) {
Player p = e.getPlayer();
if(e.isCancelled()) return;
if (!TelegramChat.getInstance().getConfig().getBoolean("enable-joinquitmessages"))
return;
if (TelegramChat.telegramHook.connected) {
ChatMessageToTelegram chat = new ChatMessageToTelegram();
chat.parse_mode = "Markdown";
chat.text = Utils.formatMSG("join-message", e.getPlayer().getName())[0];
TelegramChat.telegramHook.sendAll(chat);
}
}
}

View File

@ -12,6 +12,7 @@ import java.util.Random;
import java.util.UUID;
import java.util.logging.Level;
import de.Linus122.Handlers.VanishHandler;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.file.FileConfiguration;
@ -40,17 +41,23 @@ public class TelegramChat extends JavaPlugin implements Listener {
private static Data data = new Data();
public static Telegram telegramHook;
private static TelegramChat instance;
@Override
public void onEnable() {
this.saveDefaultConfig();
cfg = this.getConfig();
instance = this;
Utils.cfg = cfg;
Bukkit.getPluginCommand("telegram").setExecutor(new TelegramCmd());
Bukkit.getPluginCommand("linktelegram").setExecutor(new LinkTelegramCmd());
Bukkit.getPluginManager().registerEvents(this, this);
if (Bukkit.getPluginManager().isPluginEnabled("SuperVanish") || Bukkit.getPluginManager().isPluginEnabled("PremiumVanish")) {
Bukkit.getPluginManager().registerEvents(new VanishHandler(), this);
}
File dir = new File("plugins/TelegramChat/");
dir.mkdir();
data = new Data();
@ -238,4 +245,9 @@ public class TelegramChat extends JavaPlugin implements Listener {
}
}
public static TelegramChat getInstance()
{
return instance;
}
}