浏览代码

Add basic vanish support for join/quit messages

Lorenzo Dellacà 3 年之前
父节点
当前提交
2b6262df9a

+ 44 - 0
src/main/java/de/Linus122/Handlers/VanishHandler.java

@@ -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);
+        }
+    }
+}

+ 12 - 0
src/main/java/de/Linus122/TelegramChat/TelegramChat.java

@@ -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;
+	}
+
 }