소스 검색

restructure project

MasterCake 3 년 전
부모
커밋
61ee137c95

+ 7 - 0
pom.xml

@@ -6,12 +6,18 @@
 	<version>1.0.15</version>
 	<name>TelegramChat</name>
 	<url>https://www.spigotmc.org/resources/telegramchat.16576/</url>
+	
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+	</properties>
+	
 	<repositories>
 		<repository>
 			<id>spigot-repo</id>
 			<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
 		</repository>
 	</repositories>
+	
 	<dependencies>
 		<dependency>
 			<groupId>org.spigotmc</groupId>
@@ -20,6 +26,7 @@
 			<scope>provided</scope>
 		</dependency>
 	</dependencies>
+	
 	<build>
 		<!-- Uses the properties in this file for plugin.yml and config.yml -->
 		<resources>

+ 28 - 0
src/main/java/de/Linus122/Handlers/BanHandler.java

@@ -0,0 +1,28 @@
+package de.Linus122.Handlers;
+
+import org.bukkit.Bukkit;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.entity.Player;
+
+import de.Linus122.Telegram.TelegramActionListener;
+import de.Linus122.TelegramComponents.ChatMessageToMc;
+import de.Linus122.TelegramComponents.ChatMessageToTelegram;
+
+public class BanHandler implements TelegramActionListener{
+
+	@Override
+	public void onSendToTelegram(ChatMessageToTelegram chat) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void onSendToMinecraft(ChatMessageToMc chatMsg) {
+		OfflinePlayer player = Bukkit.getOfflinePlayer(chatMsg.getUuid_sender());
+
+		if(player != null && player.isBanned()) {
+			chatMsg.setCancelled(true);
+		}
+	}
+
+}

+ 9 - 0
src/main/java/de/Linus122/Telegram/API.java

@@ -0,0 +1,9 @@
+package de.Linus122.Telegram;
+
+import de.Linus122.TelegramChat.TelegramChat;
+
+public class API {
+	public static Telegram getTelegramHook() {
+		return TelegramChat.telegramHook;
+	}
+}

+ 19 - 16
src/main/java/de/Linus122/TelegramChat/Telegram.java → src/main/java/de/Linus122/Telegram/Telegram.java

@@ -1,4 +1,4 @@
-package de.Linus122.TelegramChat;
+package de.Linus122.Telegram;
 
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
@@ -18,6 +18,7 @@ import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
 
 import de.Linus122.TelegramComponents.ChatMessageToTelegram;
+import de.Linus122.TelegramChat.TelegramChat;
 import de.Linus122.TelegramComponents.Chat;
 import de.Linus122.TelegramComponents.ChatMessageToMc;
 import de.Linus122.TelegramComponents.Update;
@@ -63,7 +64,7 @@ public class Telegram {
 	public boolean getUpdate() {
 		JsonObject up = null;
 		try {
-			up = sendGet(String.format(API_URL_GETUPDATES, Main.getBackend().getToken(), lastUpdate + 1));
+			up = sendGet(String.format(API_URL_GETUPDATES, TelegramChat.getBackend().getToken(), lastUpdate + 1));
 		} catch (IOException e) {
 			return false;
 		}
@@ -81,16 +82,16 @@ public class Telegram {
 					if (update.getMessage() != null) {
 						Chat chat = update.getMessage().getChat();
 						if (chat.isPrivate()) {
-							if (!Main.getBackend().ids.contains(chat.getId()))
-								Main.getBackend().ids.add(chat.getId());
+							if (!TelegramChat.getBackend().ids.contains(chat.getId()))
+								TelegramChat.getBackend().ids.add(chat.getId());
 
 							if (update.getMessage().getText() != null) {
 								String text = update.getMessage().getText();
 								if (text.length() == 0)
 									return true;
 								if (text.equals("/start")) {
-									if (Main.getBackend().isFirstUse()) {
-										Main.getBackend().setFirstUse(false);
+									if (TelegramChat.getBackend().isFirstUse()) {
+										TelegramChat.getBackend().setFirstUse(false);
 										ChatMessageToTelegram chat2 = new ChatMessageToTelegram();
 										chat2.chat_id = chat.getId();
 										chat2.parse_mode = "Markdown";
@@ -98,18 +99,20 @@ public class Telegram {
 										this.sendMsg(chat2);
 									}
 									this.sendMsg(chat.getId(), Utils.formatMSG("can-see-but-not-chat")[0]);
-								} else if (Main.getBackend().getLinkCodes().containsKey(text)) {
+								} else if (TelegramChat.getBackend().getLinkCodes().containsKey(text)) {
 									// LINK
-									Main.link(Main.getBackend().getUUIDFromLinkCode(text), chat.getId());
-									Main.getBackend().removeLinkCode(text);
-								} else if (Main.getBackend().getLinkedChats().containsKey(chat.getId())) {
+									TelegramChat.link(TelegramChat.getBackend().getUUIDFromLinkCode(text), chat.getId());
+									TelegramChat.getBackend().removeLinkCode(text);
+								} else if (TelegramChat.getBackend().getLinkedChats().containsKey(chat.getId())) {
 									ChatMessageToMc chatMsg = new ChatMessageToMc(
-											Main.getBackend().getUUIDFromChatID(chat.getId()), text, chat.getId());
+											TelegramChat.getBackend().getUUIDFromChatID(chat.getId()), text, chat.getId());
+									
 									for (TelegramActionListener actionListener : listeners) {
 										actionListener.onSendToMinecraft(chatMsg);
 									}
+									
 									if(!chatMsg.isCancelled()){
-										Main.sendToMC(chatMsg);
+										TelegramChat.sendToMC(chatMsg);
 									}
 								} else {
 									this.sendMsg(chat.getId(), Utils.formatMSG("need-to-link")[0]);
@@ -118,8 +121,8 @@ public class Telegram {
 
 						} else if (!chat.isPrivate()) {
 							int id = chat.getId();
-							if (!Main.getBackend().ids.contains(id))
-								Main.getBackend().ids.add(id);
+							if (!TelegramChat.getBackend().ids.contains(id))
+								TelegramChat.getBackend().ids.add(id);
 						}
 					}
 
@@ -149,7 +152,7 @@ public class Telegram {
 	public void sendAll(final ChatMessageToTelegram chat) {
 		new Thread(new Runnable() {
 			public void run() {
-				for (int id : Main.getBackend().ids) {
+				for (int id : TelegramChat.getBackend().ids) {
 					chat.chat_id = id;
 					// post("sendMessage", gson.toJson(chat, Chat.class));
 					sendMsg(chat);
@@ -161,7 +164,7 @@ public class Telegram {
 	public void post(String method, String json) {
 		try {
 			String body = json;
-			URL url = new URL(String.format(API_URL_GENERAL, Main.getBackend().getToken(), method));
+			URL url = new URL(String.format(API_URL_GENERAL, TelegramChat.getBackend().getToken(), method));
 			HttpURLConnection connection = (HttpURLConnection) url.openConnection();
 			connection.setRequestMethod("POST");
 			connection.setDoInput(true);

+ 1 - 1
src/main/java/de/Linus122/TelegramChat/TelegramActionListener.java → src/main/java/de/Linus122/Telegram/TelegramActionListener.java

@@ -1,4 +1,4 @@
-package de.Linus122.TelegramChat;
+package de.Linus122.Telegram;
 
 import de.Linus122.TelegramComponents.ChatMessageToTelegram;
 import de.Linus122.TelegramComponents.ChatMessageToMc;

+ 1 - 1
src/main/java/de/Linus122/TelegramChat/Utils.java → src/main/java/de/Linus122/Telegram/Utils.java

@@ -1,4 +1,4 @@
-package de.Linus122.TelegramChat;
+package de.Linus122.Telegram;
 
 import org.bukkit.configuration.file.FileConfiguration;
 

+ 0 - 7
src/main/java/de/Linus122/TelegramChat/API.java

@@ -1,7 +0,0 @@
-package de.Linus122.TelegramChat;
-
-public class API {
-	public static Telegram getTelegramHook() {
-		return Main.telegramHook;
-	}
-}

+ 9 - 7
src/main/java/de/Linus122/TelegramChat/LinkTelegramCmd.java

@@ -7,6 +7,8 @@ import org.bukkit.command.CommandExecutor;
 import org.bukkit.command.CommandSender;
 import org.bukkit.entity.Player;
 
+import de.Linus122.Telegram.Utils;
+
 public class LinkTelegramCmd implements CommandExecutor {
 
 	@Override
@@ -18,19 +20,19 @@ public class LinkTelegramCmd implements CommandExecutor {
 			cs.sendMessage(Utils.formatMSG("no-permissions")[0]);
 			return true;
 		}
-		if (Main.getBackend() == null) {
-			Main.initBackend();
+		if (TelegramChat.getBackend() == null) {
+			TelegramChat.initBackend();
 		}
-		if (Main.telegramHook.authJson == null) {
+		if (TelegramChat.telegramHook.authJson == null) {
 			cs.sendMessage(Utils.formatMSG("need-to-add-bot-first")[0]);
 			return true;
 		}
 
-		String token = Main.generateLinkToken();
-		Main.getBackend().addLinkCode(token, ((Player) cs).getUniqueId());
+		String token = TelegramChat.generateLinkToken();
+		TelegramChat.getBackend().addLinkCode(token, ((Player) cs).getUniqueId());
 		cs.sendMessage(Utils.formatMSG("get-token",
-				Main.telegramHook.authJson.getAsJsonObject("result").get("username").getAsString(),
-				Main.telegramHook.authJson.getAsJsonObject("result").get("username").getAsString(), token));
+				TelegramChat.telegramHook.authJson.getAsJsonObject("result").get("username").getAsString(),
+				TelegramChat.telegramHook.authJson.getAsJsonObject("result").get("username").getAsString(), token));
 
 		return true;
 	}

+ 8 - 3
src/main/java/de/Linus122/TelegramChat/Main.java → src/main/java/de/Linus122/TelegramChat/TelegramChat.java

@@ -25,11 +25,14 @@ import org.bukkit.plugin.java.JavaPlugin;
 
 import com.google.gson.Gson;
 
+import de.Linus122.Handlers.BanHandler;
 import de.Linus122.Metrics.Metrics;
+import de.Linus122.Telegram.Telegram;
+import de.Linus122.Telegram.Utils;
 import de.Linus122.TelegramComponents.ChatMessageToMc;
 import de.Linus122.TelegramComponents.ChatMessageToTelegram;
 
-public class Main extends JavaPlugin implements Listener {
+public class TelegramChat extends JavaPlugin implements Listener {
 	private static File datad = new File("plugins/TelegramChat/data.json");
 	private static FileConfiguration cfg;
 
@@ -81,6 +84,8 @@ public class Main extends JavaPlugin implements Listener {
 
 		telegramHook = new Telegram();
 		telegramHook.auth(data.getToken());
+		
+		telegramHook.addListener(new BanHandler());
 
 		Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
 			boolean connectionLost = false;
@@ -131,7 +136,7 @@ public class Main extends JavaPlugin implements Listener {
 	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);
+		recievers.addAll(TelegramChat.data.ids);
 		recievers.remove((Object) sender);
 		String msgF = Utils.formatMSG("general-message-to-mc", op.getName(), msg)[0];
 		for (int id : recievers) {
@@ -142,7 +147,7 @@ public class Main extends JavaPlugin implements Listener {
 	}
 
 	public static void link(UUID player, int chatID) {
-		Main.data.addChatPlayerLink(chatID, player);
+		TelegramChat.data.addChatPlayerLink(chatID, player);
 		OfflinePlayer p = Bukkit.getOfflinePlayer(player);
 		telegramHook.sendMsg(chatID, "Success! Linked " + p.getName());
 	}

+ 6 - 6
src/main/java/de/Linus122/TelegramChat/TelegramCmd.java

@@ -16,17 +16,17 @@ public class TelegramCmd implements CommandExecutor {
 			cs.sendMessage("§c/telegram [token]");
 			return true;
 		}
-		if (Main.getBackend() == null) {
-			Main.initBackend();
+		if (TelegramChat.getBackend() == null) {
+			TelegramChat.initBackend();
 		}
-		Main.getBackend().setToken(args[0]);
-		Main.save();
+		TelegramChat.getBackend().setToken(args[0]);
+		TelegramChat.save();
 		boolean success = false;
 
-		success = Main.telegramHook.auth(Main.getBackend().getToken());
+		success = TelegramChat.telegramHook.auth(TelegramChat.getBackend().getToken());
 		if (success) {
 			cs.sendMessage("§cSuccessfully connected to Telegram!");
-			cs.sendMessage("§aAdd " + Main.telegramHook.authJson.getAsJsonObject("result").get("username").getAsString()
+			cs.sendMessage("§aAdd " + TelegramChat.telegramHook.authJson.getAsJsonObject("result").get("username").getAsString()
 					+ " to Telegram!");
 		} else {
 			cs.sendMessage("§cWrong token. Paste in the whole token!");