converted to maven, added API and issue fix
This commit is contained in:
7
src/main/java/de/Linus122/TelegramChat/API.java
Normal file
7
src/main/java/de/Linus122/TelegramChat/API.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package de.Linus122.TelegramChat;
|
||||
|
||||
public class API {
|
||||
public static Telegram getTelegramHook(){
|
||||
return Main.telegramHook;
|
||||
}
|
||||
}
|
||||
@@ -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<Integer> recievers = new ArrayList<Integer>();
|
||||
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("_", "\\_");
|
||||
}
|
||||
}
|
||||
@@ -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<TelegramActionListener> listeners = new ArrayList<TelegramActionListener>();
|
||||
|
||||
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();
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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:
|
||||
Reference in New Issue
Block a user