Browse Source

Fixed issue with token saving

Linus 8 years ago
parent
commit
e43630fa0a

+ 5 - 5
de/Linus122/TelegramChat/LinkTelegramCmd.java

@@ -12,24 +12,24 @@ public class LinkTelegramCmd implements CommandExecutor {
 	@Override
 	public boolean onCommand(CommandSender cs, Command arg1, String arg2, String[] args) {
 		if(!(cs instanceof Player)){
-			cs.sendMessage("§cSorry, but you can't link the console currently.");
+			cs.sendMessage("§cSorry, but you can't link the console currently.");
 		}
 		if(!cs.hasPermission("telegram.linktelegram")){
-			cs.sendMessage("§cYou don't have permissions to use this!");
+			cs.sendMessage("§cYou don't have permissions to use this!");
 			return true;
 		}
 		if(Main.data == null){
 			Main.data = new Data();
 		}
 		if(Telegram.authJson == null){
-			cs.sendMessage("§cPlease add a bot to your server first! /telegram");
+			cs.sendMessage("§cPlease add a bot to your server first! /telegram");
 			return true;
 		}
 		
 		String token = Main.generateLinkToken();
 		Main.data.linkCodes.put(token, ((Player) cs).getUniqueId());
-		cs.sendMessage("§aAdd " + Telegram.authJson.getAsJsonObject("result").get("username").getAsString() + " to Telegram and send this message to " + Telegram.authJson.getAsJsonObject("result").get("username").getAsString() + ":");
-		cs.sendMessage("§c" + token);
+		cs.sendMessage("§aAdd " + Telegram.authJson.getAsJsonObject("result").get("username").getAsString() + " to Telegram and send this message to " + Telegram.authJson.getAsJsonObject("result").get("username").getAsString() + ":");
+		cs.sendMessage("§c" + token);
 		
 		return true;
 	}

+ 7 - 4
de/Linus122/TelegramChat/Main.java

@@ -31,7 +31,7 @@ import de.Linus122.TelegramComponents.Chat;
 
 
 public class Main extends JavaPlugin implements Listener{
-	File datad = new File("plugins/TelegramChat/data.json");
+	public static File datad = new File("plugins/TelegramChat/data.json");
 	public static FileConfiguration cfg;
 	
 	public static Data data = new Data();
@@ -69,8 +69,7 @@ public class Main extends JavaPlugin implements Listener{
 			}
 		}, 20L, 20L);
 	}
-	@Override
-	public void onDisable(){
+	public static void save(){
 		Gson gson = new Gson();
 		
 		try {
@@ -85,12 +84,16 @@ public class Main extends JavaPlugin implements Listener{
 			e.printStackTrace();
 		}
 	}
+	@Override
+	public void onDisable(){
+		save();
+	}
 	public 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.remove((Object) sender);
-		String msgF = Main.cfg.getString("chat-format").replace('&', '§').replace("%player%", op.getName()).replace("%message%", msg);
+		String msgF = Main.cfg.getString("chat-format").replace('&', '�').replace("%player%", op.getName()).replace("%message%", msg);
 		for(int id : recievers){
 			Telegram.sendMsg(id, msgF);
 		}

+ 6 - 5
de/Linus122/TelegramChat/TelegramCmd.java

@@ -9,25 +9,26 @@ public class TelegramCmd implements CommandExecutor {
 	@Override
 	public boolean onCommand(CommandSender cs, Command arg1, String arg2, String[] args) {
 		if(!cs.hasPermission("telegram.settoken")){
-			cs.sendMessage("§cYou don't have permissions to use this!");
+			cs.sendMessage("§cYou don't have permissions to use this!");
 			return true;
 		}
 		if(args.length == 0){
-			cs.sendMessage("§c/telegram [token]");
+			cs.sendMessage("§c/telegram [token]");
 			return true;
 		}
 		if(Main.data == null){
 			Main.data = new Data();
 		}
 		Main.data.token = args[0];
+		Main.save();
 		boolean success = false;
 	
 		success = Telegram.auth();
 		if(success){
-			cs.sendMessage("§cSuccessfully connected to Telegram!");
-			cs.sendMessage("§aAdd " + Telegram.authJson.getAsJsonObject("result").get("username").getAsString() + " to Telegram!");
+			cs.sendMessage("§cSuccessfully connected to Telegram!");
+			cs.sendMessage("§aAdd " + Telegram.authJson.getAsJsonObject("result").get("username").getAsString() + " to Telegram!");
 		}else{
-			cs.sendMessage("§cWrong token. Paste in the whole token!");
+			cs.sendMessage("§cWrong token. Paste in the whole token!");
 		}
 		return true;
 	}