diff --git a/pom.xml b/pom.xml
index f35f753..12f9869 100644
--- a/pom.xml
+++ b/pom.xml
@@ -16,17 +16,26 @@
spigot-repo
https://hub.spigotmc.org/nexus/content/groups/public/
+
+ jitpack.io
+ https://jitpack.io
+
- org.spigotmc
- spigot-api
+ org.bukkit
+ craftbukkit
1.12.2-R0.1-SNAPSHOT
provided
+
+ com.github.MilkBowl
+ VaultAPI
+ 1.7
+ provided
+
-
diff --git a/src/main/java/de/Linus122/Handlers/CommandHandler.java b/src/main/java/de/Linus122/Handlers/CommandHandler.java
new file mode 100644
index 0000000..2cc7580
--- /dev/null
+++ b/src/main/java/de/Linus122/Handlers/CommandHandler.java
@@ -0,0 +1,113 @@
+package de.Linus122.Handlers;
+
+import java.security.Permissions;
+import java.util.Arrays;
+import java.util.Locale;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Formatter;
+import java.util.logging.Handler;
+import java.util.logging.LogManager;
+import java.util.logging.LogRecord;
+import java.util.logging.SimpleFormatter;
+
+import org.bukkit.Bukkit;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.PluginLogger;
+import org.bukkit.plugin.RegisteredServiceProvider;
+
+import de.Linus122.Telegram.Telegram;
+import de.Linus122.Telegram.TelegramActionListener;
+import de.Linus122.TelegramChat.TelegramChat;
+import de.Linus122.TelegramComponents.ChatMessageToMc;
+import de.Linus122.TelegramComponents.ChatMessageToTelegram;
+import net.milkbowl.vault.permission.Permission;
+
+public class CommandHandler extends ConsoleHandler implements TelegramActionListener {
+
+ private Permission permissionsAdapter;
+ private int lastChatId = -1;
+ private long lastCommandTyped;
+
+ private Telegram telegram;
+ private Plugin plugin;
+
+ public CommandHandler(Telegram telegram, Plugin plugin) {
+ java.util.logging.Logger global = java.util.logging.Logger.getLogger("");
+ //global.addHandler(this);
+
+ LogManager.getLogManager().getLoggerNames().asIterator().forEachRemaining(c -> LogManager.getLogManager().getLogger(c).addHandler(this));
+
+
+
+ //Bukkit.getLogger().addHandler(this);
+
+ //Arrays.stream(Bukkit.getPluginManager().getPlugins()).forEach(k -> k.getLogger().addHandler(this));
+
+ setupVault();
+
+ this.telegram = telegram;
+ this.plugin = plugin;
+ }
+
+ private void setupVault() {
+ RegisteredServiceProvider rsp = Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
+ permissionsAdapter = rsp.getProvider();
+ }
+
+ @Override
+ public void onSendToTelegram(ChatMessageToTelegram chat) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void onSendToMinecraft(ChatMessageToMc chatMsg) {
+
+ if(permissionsAdapter == null) {
+ // setting up vault permissions
+ this.setupVault();
+ }
+
+ if(chatMsg.getContent().startsWith("/")) {
+
+ OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(chatMsg.getUuid_sender());
+
+ if(permissionsAdapter.playerHas(null, offlinePlayer, "telegramchat.console")) {
+ lastChatId = chatMsg.getChatID_sender();
+ lastCommandTyped = System.currentTimeMillis();
+
+ Bukkit.getScheduler().runTask(this.plugin, () -> {
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(), chatMsg.getContent().substring(1, chatMsg.getContent().length()-1));
+ });
+ }
+
+ }
+
+
+ }
+
+ @Override
+ public void close() throws SecurityException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void flush() {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void publish(LogRecord record) {
+ if(lastChatId != -1) {
+// String s = String.format(record.getMessage(), record.getParameters());
+ String s = this.getFormatter().format(record);
+ telegram.sendMsg(lastChatId, s);
+
+ }
+
+ }
+
+}
diff --git a/src/main/java/de/Linus122/TelegramChat/TelegramChat.java b/src/main/java/de/Linus122/TelegramChat/TelegramChat.java
index 355ca54..4e52570 100755
--- a/src/main/java/de/Linus122/TelegramChat/TelegramChat.java
+++ b/src/main/java/de/Linus122/TelegramChat/TelegramChat.java
@@ -26,6 +26,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import com.google.gson.Gson;
import de.Linus122.Handlers.BanHandler;
+import de.Linus122.Handlers.CommandHandler;
import de.Linus122.Metrics.Metrics;
import de.Linus122.Telegram.Telegram;
import de.Linus122.Telegram.Utils;
@@ -85,7 +86,11 @@ public class TelegramChat extends JavaPlugin implements Listener {
telegramHook = new Telegram();
telegramHook.auth(data.getToken());
+ // Ban Handler (Prevents banned players from chatting)
telegramHook.addListener(new BanHandler());
+
+ // Console sender handler, allows players to send console commands (telegram.console permission)
+ // telegramHook.addListener(new CommandHandler(telegramHook, this));
Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
boolean connectionLost = false;
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index b816b59..7f2f459 100755
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,7 +1,8 @@
name: TelegramChat
-main: de.Linus122.TelegramChat.Main
+main: de.Linus122.TelegramChat.TelegramChat
version: ${project.version}
authors: [Linus122]
+softdepend: [Vault]
description: Brings minecraft chat to Telegram!
commands:
telegram:
@@ -11,4 +12,4 @@ commands:
linktelegram:
description: Main command
usage: /
- permission: telegram.linktelegram
\ No newline at end of file
+ permission: telegram.linktelegram