diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..69fd427 --- /dev/null +++ b/pom.xml @@ -0,0 +1,57 @@ + + 4.0.0 + TelegramChat + TelegramChat + 1.0.9.9 + TelegramChat + https://www.spigotmc.org/resources/telegramchat.16576/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + + + org.spigotmc + spigot-api + 1.12.2-R0.1-SNAPSHOT + provided + + + + + + + ${basedir}/src/main/resources + true + + plugin.yml + config.yml + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + ${project.name} + + + + + \ No newline at end of file diff --git a/src/de/Linus122/Metrics/Metrics.java b/src/main/java/de/Linus122/Metrics/Metrics.java similarity index 100% rename from src/de/Linus122/Metrics/Metrics.java rename to src/main/java/de/Linus122/Metrics/Metrics.java diff --git a/src/main/java/de/Linus122/TelegramChat/API.java b/src/main/java/de/Linus122/TelegramChat/API.java new file mode 100644 index 0000000..6768f3e --- /dev/null +++ b/src/main/java/de/Linus122/TelegramChat/API.java @@ -0,0 +1,7 @@ +package de.Linus122.TelegramChat; + +public class API { + public static Telegram getTelegramHook(){ + return Main.telegramHook; + } +} diff --git a/src/de/Linus122/TelegramChat/Data.java b/src/main/java/de/Linus122/TelegramChat/Data.java similarity index 100% rename from src/de/Linus122/TelegramChat/Data.java rename to src/main/java/de/Linus122/TelegramChat/Data.java diff --git a/src/de/Linus122/TelegramChat/LinkTelegramCmd.java b/src/main/java/de/Linus122/TelegramChat/LinkTelegramCmd.java similarity index 100% rename from src/de/Linus122/TelegramChat/LinkTelegramCmd.java rename to src/main/java/de/Linus122/TelegramChat/LinkTelegramCmd.java diff --git a/src/de/Linus122/TelegramChat/Main.java b/src/main/java/de/Linus122/TelegramChat/Main.java similarity index 88% rename from src/de/Linus122/TelegramChat/Main.java rename to src/main/java/de/Linus122/TelegramChat/Main.java index 7da1e8b..cb304b0 100755 --- a/src/de/Linus122/TelegramChat/Main.java +++ b/src/main/java/de/Linus122/TelegramChat/Main.java @@ -29,6 +29,7 @@ import com.google.gson.Gson; import de.Linus122.Metrics.Metrics; import de.Linus122.TelegramComponents.Chat; +import de.Linus122.TelegramComponents.ChatMessageToMc; public class Main extends JavaPlugin implements Listener{ @@ -94,7 +95,10 @@ public class Main extends JavaPlugin implements Listener{ public void onDisable(){ save(); } - public static void sendToMC(UUID uuid, String msg, int sender){ + public static void sendToMC(ChatMessageToMc chatMsg) { + sendToMC(chatMsg.getUuid_sender(), chatMsg.getContent(), chatMsg.getChatID_sender()); + } + private static void sendToMC(UUID uuid, String msg, int sender){ OfflinePlayer op = Bukkit.getOfflinePlayer(uuid); List recievers = new ArrayList(); recievers.addAll(Main.data.ids); @@ -166,8 +170,11 @@ public class Main extends JavaPlugin implements Listener{ if(telegramHook.connected){ Chat chat = new Chat(); chat.parse_mode = "Markdown"; - chat.text = e.getPlayer().getName() + ": _" + e.getMessage().replaceAll("§.", "") + "_"; + chat.text = escape(e.getPlayer().getName()) + ": _" + e.getMessage().replaceAll("§.", "") + "_"; telegramHook.sendAll(chat); } } + public String escape(String str){ + return str.replace("_", "\\_"); + } } diff --git a/src/de/Linus122/TelegramChat/Telegram.java b/src/main/java/de/Linus122/TelegramChat/Telegram.java similarity index 85% rename from src/de/Linus122/TelegramChat/Telegram.java rename to src/main/java/de/Linus122/TelegramChat/Telegram.java index 7c831c7..e86541e 100755 --- a/src/de/Linus122/TelegramChat/Telegram.java +++ b/src/main/java/de/Linus122/TelegramChat/Telegram.java @@ -9,6 +9,8 @@ import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; +import java.util.ArrayList; +import java.util.List; import com.google.gson.Gson; import com.google.gson.JsonElement; @@ -16,6 +18,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import de.Linus122.TelegramComponents.Chat; +import de.Linus122.TelegramComponents.ChatMessageToMc; public class Telegram { @@ -25,6 +28,12 @@ public class Telegram { static int lastUpdate = 0; public String token; + private List listeners = new ArrayList(); + + public void addListener(TelegramActionListener actionListener){ + listeners.add(actionListener); + } + public boolean auth(String token){ this.token = token; return reconnect(); @@ -90,7 +99,11 @@ public class Telegram { Main.link(Main.data.linkCodes.get(text), id); Main.data.linkCodes.remove(text); }else if(Main.data.linkedChats.containsKey(id)){ - Main.sendToMC(Main.data.linkedChats.get(id), text, id); + ChatMessageToMc chatMsg = new ChatMessageToMc(Main.data.linkedChats.get(id), text, id); + for(TelegramActionListener actionListener : listeners){ + actionListener.onSendToMinecraft(chatMsg); + } + Main.sendToMC(chatMsg); }else{ this.sendMsg(id, "Sorry, please link your account with /linktelegram ingame to use the chat!"); } @@ -109,14 +122,15 @@ public class Telegram { } public void sendMsg(int id, String msg){ - Gson gson = new Gson(); Chat chat = new Chat(); chat.chat_id = id; chat.text = msg; - post("sendMessage", gson.toJson(chat, Chat.class)); - + sendMsg(chat); } public void sendMsg(Chat chat){ + for(TelegramActionListener actionListener : listeners){ + actionListener.onSendToTelegram(chat); + } Gson gson = new Gson(); post("sendMessage", gson.toJson(chat, Chat.class)); @@ -127,7 +141,8 @@ public class Telegram { Gson gson = new Gson(); for(int id : Main.data.ids){ chat.chat_id = id; - post("sendMessage", gson.toJson(chat, Chat.class)); + //post("sendMessage", gson.toJson(chat, Chat.class)); + sendMsg(chat); } } }).start(); diff --git a/src/main/java/de/Linus122/TelegramChat/TelegramActionListener.java b/src/main/java/de/Linus122/TelegramChat/TelegramActionListener.java new file mode 100644 index 0000000..bdf4ebe --- /dev/null +++ b/src/main/java/de/Linus122/TelegramChat/TelegramActionListener.java @@ -0,0 +1,9 @@ +package de.Linus122.TelegramChat; + +import de.Linus122.TelegramComponents.Chat; +import de.Linus122.TelegramComponents.ChatMessageToMc; + +public interface TelegramActionListener { + public void onSendToTelegram(Chat chat); + public void onSendToMinecraft(ChatMessageToMc chatMsg); +} diff --git a/src/de/Linus122/TelegramChat/TelegramCmd.java b/src/main/java/de/Linus122/TelegramChat/TelegramCmd.java similarity index 100% rename from src/de/Linus122/TelegramChat/TelegramCmd.java rename to src/main/java/de/Linus122/TelegramChat/TelegramCmd.java diff --git a/src/de/Linus122/TelegramComponents/Chat.java b/src/main/java/de/Linus122/TelegramComponents/Chat.java similarity index 100% rename from src/de/Linus122/TelegramComponents/Chat.java rename to src/main/java/de/Linus122/TelegramComponents/Chat.java diff --git a/src/main/java/de/Linus122/TelegramComponents/ChatMessageToMc.java b/src/main/java/de/Linus122/TelegramComponents/ChatMessageToMc.java new file mode 100644 index 0000000..3d879e4 --- /dev/null +++ b/src/main/java/de/Linus122/TelegramComponents/ChatMessageToMc.java @@ -0,0 +1,39 @@ +package de.Linus122.TelegramComponents; + +import java.util.UUID; + +public class ChatMessageToMc { + UUID uuid_sender; + String content; + int chatID_sender; + + public ChatMessageToMc(UUID uuid_sender, String content, int chatID_sender){ + this.uuid_sender = uuid_sender; + this.content = content; + this.chatID_sender = chatID_sender; + } + + public UUID getUuid_sender() { + return uuid_sender; + } + + public void setUuid_sender(UUID uuid_sender) { + this.uuid_sender = uuid_sender; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public int getChatID_sender() { + return chatID_sender; + } + + public void setChatID_sender(int chatID_sender) { + this.chatID_sender = chatID_sender; + } +} diff --git a/src/config.yml b/src/main/resources/config.yml similarity index 100% rename from src/config.yml rename to src/main/resources/config.yml diff --git a/src/plugin.yml b/src/main/resources/plugin.yml similarity index 89% rename from src/plugin.yml rename to src/main/resources/plugin.yml index 0b8b76d..b816b59 100755 --- a/src/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: TelegramChat main: de.Linus122.TelegramChat.Main -version: 1.0.9.7 +version: ${project.version} authors: [Linus122] description: Brings minecraft chat to Telegram! commands: