Merge pull request #19 from iCaitlyn/master
Refactor user ids and chat ids from integer type to long type
This commit is contained in:
commit
fda86cc69e
@ -27,7 +27,7 @@ import net.milkbowl.vault.permission.Permission;
|
||||
public class CommandHandler extends ConsoleHandler implements TelegramActionListener {
|
||||
|
||||
private Permission permissionsAdapter;
|
||||
private int lastChatId = -1;
|
||||
private long lastChatId = -1;
|
||||
private long lastCommandTyped;
|
||||
|
||||
private Telegram telegram;
|
||||
|
@ -108,7 +108,7 @@ public class Telegram {
|
||||
|
||||
} else if (!chat.isPrivate()) {
|
||||
// group chat
|
||||
int id = chat.getId();
|
||||
long id = chat.getId();
|
||||
if (!TelegramChat.getBackend().chat_ids.contains(id))
|
||||
TelegramChat.getBackend().chat_ids.add(id);
|
||||
|
||||
@ -127,7 +127,7 @@ public class Telegram {
|
||||
|
||||
public void handleUserMessage(String text, Update update) {
|
||||
Chat chat = update.getMessage().getChat();
|
||||
int user_id = update.getMessage().getFrom().getId();
|
||||
long user_id = update.getMessage().getFrom().getId();
|
||||
if (TelegramChat.getBackend().getLinkCodes().containsKey(text)) {
|
||||
// LINK
|
||||
TelegramChat.link(TelegramChat.getBackend().getUUIDFromLinkCode(text), user_id);
|
||||
@ -148,7 +148,7 @@ public class Telegram {
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMsg(int id, String msg) {
|
||||
public void sendMsg(long id, String msg) {
|
||||
ChatMessageToTelegram chat = new ChatMessageToTelegram();
|
||||
chat.chat_id = id;
|
||||
chat.text = msg;
|
||||
@ -168,7 +168,7 @@ public class Telegram {
|
||||
public void sendAll(final ChatMessageToTelegram chat) {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
for (int id : TelegramChat.getBackend().chat_ids) {
|
||||
for (long id : TelegramChat.getBackend().chat_ids) {
|
||||
chat.chat_id = id;
|
||||
// post("sendMessage", gson.toJson(chat, Chat.class));
|
||||
sendMsg(chat);
|
||||
|
@ -9,12 +9,12 @@ public class Data {
|
||||
private String token = "";
|
||||
|
||||
// User ID : Player ID
|
||||
private HashMap<Integer, UUID> linkedChats = new HashMap<Integer, UUID>();
|
||||
private HashMap<Long, UUID> linkedChats = new HashMap<Long, UUID>();
|
||||
|
||||
// Token : Player ID
|
||||
private HashMap<String, UUID> linkCodes = new HashMap<String, UUID>();
|
||||
|
||||
public List<Integer> chat_ids = new ArrayList<Integer>();
|
||||
public List<Long> chat_ids = new ArrayList<Long>();
|
||||
|
||||
private boolean firstUse = true;
|
||||
|
||||
@ -28,11 +28,11 @@ public class Data {
|
||||
}
|
||||
|
||||
// chats
|
||||
public HashMap<Integer, UUID> getLinkedChats() {
|
||||
public HashMap<Long, UUID> getLinkedChats() {
|
||||
return linkedChats;
|
||||
}
|
||||
|
||||
public void setLinkedChats(HashMap<Integer, UUID> linkedChats) {
|
||||
public void setLinkedChats(HashMap<Long, UUID> linkedChats) {
|
||||
this.linkedChats = linkedChats;
|
||||
}
|
||||
|
||||
@ -44,11 +44,11 @@ public class Data {
|
||||
this.linkCodes = linkCodes;
|
||||
}
|
||||
|
||||
public List<Integer> getIds() {
|
||||
public List<Long> getIds() {
|
||||
return chat_ids;
|
||||
}
|
||||
|
||||
public void setIds(List<Integer> ids) {
|
||||
public void setIds(List<Long> ids) {
|
||||
this.chat_ids = ids;
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ public class Data {
|
||||
this.firstUse = firstUse;
|
||||
}
|
||||
|
||||
public void addChatPlayerLink(int chatID, UUID player) {
|
||||
public void addChatPlayerLink(long chatID, UUID player) {
|
||||
linkedChats.put(chatID, player);
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ public class Data {
|
||||
linkCodes.remove(code);
|
||||
}
|
||||
|
||||
public UUID getUUIDFromUserID(int userID) {
|
||||
public UUID getUUIDFromUserID(long userID) {
|
||||
return linkedChats.get(userID);
|
||||
}
|
||||
|
||||
|
@ -149,20 +149,20 @@ public class TelegramChat extends JavaPlugin implements Listener {
|
||||
sendToMC(chatMsg.getUuid_sender(), chatMsg.getContent(), chatMsg.getChatID_sender());
|
||||
}
|
||||
|
||||
private static void sendToMC(UUID uuid, String msg, int sender_chat) {
|
||||
private static void sendToMC(UUID uuid, String msg, long sender_chat) {
|
||||
OfflinePlayer op = Bukkit.getOfflinePlayer(uuid);
|
||||
List<Integer> recievers = new ArrayList<Integer>();
|
||||
List<Long> recievers = new ArrayList<Long>();
|
||||
recievers.addAll(TelegramChat.data.chat_ids);
|
||||
recievers.remove((Object) sender_chat);
|
||||
String msgF = Utils.formatMSG("general-message-to-mc", op.getName(), msg)[0];
|
||||
for (int id : recievers) {
|
||||
for (long id : recievers) {
|
||||
telegramHook.sendMsg(id, msgF.replaceAll("§.", ""));
|
||||
}
|
||||
Bukkit.broadcastMessage(msgF.replace("&", "§"));
|
||||
|
||||
}
|
||||
|
||||
public static void link(UUID player, int userID) {
|
||||
public static void link(UUID player, long userID) {
|
||||
TelegramChat.data.addChatPlayerLink(userID, player);
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(player);
|
||||
telegramHook.sendMsg(userID, "Success! Linked " + p.getName());
|
||||
|
@ -1,14 +1,14 @@
|
||||
package de.Linus122.TelegramComponents;
|
||||
|
||||
public class Chat {
|
||||
private int id;
|
||||
private long id;
|
||||
private String type;
|
||||
|
||||
public int getId() {
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
@ -5,9 +5,9 @@ import java.util.UUID;
|
||||
public class ChatMessageToMc extends Cancellable {
|
||||
UUID uuid_sender;
|
||||
String content;
|
||||
int chatID_sender;
|
||||
long chatID_sender;
|
||||
|
||||
public ChatMessageToMc(UUID uuid_sender, String content, int chatID_sender) {
|
||||
public ChatMessageToMc(UUID uuid_sender, String content, long chatID_sender) {
|
||||
this.uuid_sender = uuid_sender;
|
||||
this.content = content;
|
||||
this.chatID_sender = chatID_sender;
|
||||
@ -29,11 +29,11 @@ public class ChatMessageToMc extends Cancellable {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public int getChatID_sender() {
|
||||
public long getChatID_sender() {
|
||||
return chatID_sender;
|
||||
}
|
||||
|
||||
public void setChatID_sender(int chatID_sender) {
|
||||
public void setChatID_sender(long chatID_sender) {
|
||||
this.chatID_sender = chatID_sender;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,6 @@ package de.Linus122.TelegramComponents;
|
||||
|
||||
public class ChatMessageToTelegram extends Cancellable {
|
||||
public String text;
|
||||
public int chat_id;
|
||||
public long chat_id;
|
||||
public String parse_mode;
|
||||
}
|
||||
|
@ -1,16 +1,16 @@
|
||||
package de.Linus122.TelegramComponents;
|
||||
|
||||
public class User {
|
||||
private int id;
|
||||
private long id;
|
||||
private boolean is_bot;
|
||||
private String first_name;
|
||||
private String last_name;
|
||||
|
||||
public int getId() {
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user