Merge pull request #19 from iCaitlyn/master

Refactor user ids and chat ids from integer type to long type
This commit is contained in:
MasterCake 2022-02-08 17:30:03 +00:00 committed by GitHub
commit fda86cc69e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 28 additions and 28 deletions

View File

@ -27,7 +27,7 @@ import net.milkbowl.vault.permission.Permission;
public class CommandHandler extends ConsoleHandler implements TelegramActionListener { public class CommandHandler extends ConsoleHandler implements TelegramActionListener {
private Permission permissionsAdapter; private Permission permissionsAdapter;
private int lastChatId = -1; private long lastChatId = -1;
private long lastCommandTyped; private long lastCommandTyped;
private Telegram telegram; private Telegram telegram;

View File

@ -108,7 +108,7 @@ public class Telegram {
} else if (!chat.isPrivate()) { } else if (!chat.isPrivate()) {
// group chat // group chat
int id = chat.getId(); long id = chat.getId();
if (!TelegramChat.getBackend().chat_ids.contains(id)) if (!TelegramChat.getBackend().chat_ids.contains(id))
TelegramChat.getBackend().chat_ids.add(id); TelegramChat.getBackend().chat_ids.add(id);
@ -127,7 +127,7 @@ public class Telegram {
public void handleUserMessage(String text, Update update) { public void handleUserMessage(String text, Update update) {
Chat chat = update.getMessage().getChat(); 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)) { if (TelegramChat.getBackend().getLinkCodes().containsKey(text)) {
// LINK // LINK
TelegramChat.link(TelegramChat.getBackend().getUUIDFromLinkCode(text), user_id); 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(); ChatMessageToTelegram chat = new ChatMessageToTelegram();
chat.chat_id = id; chat.chat_id = id;
chat.text = msg; chat.text = msg;
@ -168,7 +168,7 @@ public class Telegram {
public void sendAll(final ChatMessageToTelegram chat) { public void sendAll(final ChatMessageToTelegram chat) {
new Thread(new Runnable() { new Thread(new Runnable() {
public void run() { public void run() {
for (int id : TelegramChat.getBackend().chat_ids) { for (long id : TelegramChat.getBackend().chat_ids) {
chat.chat_id = id; chat.chat_id = id;
// post("sendMessage", gson.toJson(chat, Chat.class)); // post("sendMessage", gson.toJson(chat, Chat.class));
sendMsg(chat); sendMsg(chat);

View File

@ -9,12 +9,12 @@ public class Data {
private String token = ""; private String token = "";
// User ID : Player ID // 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 // Token : Player ID
private HashMap<String, UUID> linkCodes = new HashMap<String, UUID>(); 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; private boolean firstUse = true;
@ -28,11 +28,11 @@ public class Data {
} }
// chats // chats
public HashMap<Integer, UUID> getLinkedChats() { public HashMap<Long, UUID> getLinkedChats() {
return linkedChats; return linkedChats;
} }
public void setLinkedChats(HashMap<Integer, UUID> linkedChats) { public void setLinkedChats(HashMap<Long, UUID> linkedChats) {
this.linkedChats = linkedChats; this.linkedChats = linkedChats;
} }
@ -44,11 +44,11 @@ public class Data {
this.linkCodes = linkCodes; this.linkCodes = linkCodes;
} }
public List<Integer> getIds() { public List<Long> getIds() {
return chat_ids; return chat_ids;
} }
public void setIds(List<Integer> ids) { public void setIds(List<Long> ids) {
this.chat_ids = ids; this.chat_ids = ids;
} }
@ -60,7 +60,7 @@ public class Data {
this.firstUse = firstUse; this.firstUse = firstUse;
} }
public void addChatPlayerLink(int chatID, UUID player) { public void addChatPlayerLink(long chatID, UUID player) {
linkedChats.put(chatID, player); linkedChats.put(chatID, player);
} }
@ -76,7 +76,7 @@ public class Data {
linkCodes.remove(code); linkCodes.remove(code);
} }
public UUID getUUIDFromUserID(int userID) { public UUID getUUIDFromUserID(long userID) {
return linkedChats.get(userID); return linkedChats.get(userID);
} }

View File

@ -149,20 +149,20 @@ public class TelegramChat extends JavaPlugin implements Listener {
sendToMC(chatMsg.getUuid_sender(), chatMsg.getContent(), chatMsg.getChatID_sender()); 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); OfflinePlayer op = Bukkit.getOfflinePlayer(uuid);
List<Integer> recievers = new ArrayList<Integer>(); List<Long> recievers = new ArrayList<Long>();
recievers.addAll(TelegramChat.data.chat_ids); recievers.addAll(TelegramChat.data.chat_ids);
recievers.remove((Object) sender_chat); recievers.remove((Object) sender_chat);
String msgF = Utils.formatMSG("general-message-to-mc", op.getName(), msg)[0]; 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("§.", "")); telegramHook.sendMsg(id, msgF.replaceAll("§.", ""));
} }
Bukkit.broadcastMessage(msgF.replace("&", "§")); 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); TelegramChat.data.addChatPlayerLink(userID, player);
OfflinePlayer p = Bukkit.getOfflinePlayer(player); OfflinePlayer p = Bukkit.getOfflinePlayer(player);
telegramHook.sendMsg(userID, "Success! Linked " + p.getName()); telegramHook.sendMsg(userID, "Success! Linked " + p.getName());

View File

@ -1,14 +1,14 @@
package de.Linus122.TelegramComponents; package de.Linus122.TelegramComponents;
public class Chat { public class Chat {
private int id; private long id;
private String type; private String type;
public int getId() { public long getId() {
return id; return id;
} }
public void setId(int id) { public void setId(long id) {
this.id = id; this.id = id;
} }

View File

@ -5,9 +5,9 @@ import java.util.UUID;
public class ChatMessageToMc extends Cancellable { public class ChatMessageToMc extends Cancellable {
UUID uuid_sender; UUID uuid_sender;
String content; 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.uuid_sender = uuid_sender;
this.content = content; this.content = content;
this.chatID_sender = chatID_sender; this.chatID_sender = chatID_sender;
@ -29,11 +29,11 @@ public class ChatMessageToMc extends Cancellable {
this.content = content; this.content = content;
} }
public int getChatID_sender() { public long getChatID_sender() {
return chatID_sender; return chatID_sender;
} }
public void setChatID_sender(int chatID_sender) { public void setChatID_sender(long chatID_sender) {
this.chatID_sender = chatID_sender; this.chatID_sender = chatID_sender;
} }
} }

View File

@ -2,6 +2,6 @@ package de.Linus122.TelegramComponents;
public class ChatMessageToTelegram extends Cancellable { public class ChatMessageToTelegram extends Cancellable {
public String text; public String text;
public int chat_id; public long chat_id;
public String parse_mode; public String parse_mode;
} }

View File

@ -1,16 +1,16 @@
package de.Linus122.TelegramComponents; package de.Linus122.TelegramComponents;
public class User { public class User {
private int id; private long id;
private boolean is_bot; private boolean is_bot;
private String first_name; private String first_name;
private String last_name; private String last_name;
public int getId() { public long getId() {
return id; return id;
} }
public void setId(int id) { public void setId(long id) {
this.id = id; this.id = id;
} }