diff --git a/VERSION b/VERSION index 66c4c22..7ee7020 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.9 +1.0.10 diff --git a/build.gradle b/build.gradle index fa0fa17..e436af8 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ plugins { } setGroup("net.elytrium") -setVersion("1.0.9") +setVersion("1.0.10") compileJava { getOptions().setEncoding("UTF-8") diff --git a/src/main/java/net/elytrium/limboauth/socialaddon/Addon.java b/src/main/java/net/elytrium/limboauth/socialaddon/Addon.java index 0539c82..4abbb3d 100644 --- a/src/main/java/net/elytrium/limboauth/socialaddon/Addon.java +++ b/src/main/java/net/elytrium/limboauth/socialaddon/Addon.java @@ -194,6 +194,8 @@ private void load() { ) ); + this.socialManager.registerKeyboard(this.keyboard); + this.socialManager.addMessageEvent((dbField, id, message) -> { String lowercaseMessage = message.toLowerCase(Locale.ROOT); if (Settings.IMP.MAIN.START_MESSAGES.contains(lowercaseMessage)) { diff --git a/src/main/java/net/elytrium/limboauth/socialaddon/SocialManager.java b/src/main/java/net/elytrium/limboauth/socialaddon/SocialManager.java index 85b2b9f..13adadb 100644 --- a/src/main/java/net/elytrium/limboauth/socialaddon/SocialManager.java +++ b/src/main/java/net/elytrium/limboauth/socialaddon/SocialManager.java @@ -31,6 +31,7 @@ public class SocialManager { private final LinkedList socialList; private final LinkedList messageEvents = new LinkedList<>(); private final HashMap buttonEvents = new HashMap<>(); + private final HashMap buttonIdMap = new HashMap<>(); public SocialManager(AbstractSocial.Constructor... socialList) { this.socialList = new LinkedList<>(); @@ -47,6 +48,11 @@ public SocialManager(AbstractSocial.Constructor... socialList) { } private void onMessageReceived(String dbField, Long id, String message) { + String buttonId = this.buttonIdMap.get(message); + if (buttonId != null) { + this.onButtonClicked(dbField, id, buttonId); + } + this.messageEvents.forEach(event -> { try { event.accept(dbField, id, message); @@ -60,9 +66,10 @@ private void onMessageReceived(String dbField, Long id, String message) { } private void onButtonClicked(String dbField, Long id, String buttonId) { - if (this.buttonEvents.containsKey(buttonId)) { + SocialButtonListenerAdapter buttonListenerAdapter = this.buttonEvents.get(buttonId); + if (buttonListenerAdapter != null) { try { - this.buttonEvents.get(buttonId).accept(dbField, id); + buttonListenerAdapter.accept(dbField, id); } catch (Exception e) { this.broadcastMessage(dbField, id, Settings.IMP.MAIN.STRINGS.SOCIAL_EXCEPTION_CAUGHT); if (Settings.IMP.MAIN.DEBUG) { @@ -117,12 +124,24 @@ public void registerHook(String dbField, Long id) { .forEach(e -> e.onPlayerAdded(id)); } + public void registerKeyboard(List> keyboard) { + for (List items : keyboard) { + for (AbstractSocial.ButtonItem item : items) { + this.buttonIdMap.put(item.getValue(), item.getId()); + } + } + } + + public void registerButton(AbstractSocial.ButtonItem item) { + this.buttonIdMap.put(item.getValue(), item.getId()); + } + public void broadcastMessage(SocialPlayer player, String message, List> item) { this.broadcastMessage(player, message, item, AbstractSocial.ButtonVisibility.DEFAULT); } public void broadcastMessage(SocialPlayer player, String message, - List> item, AbstractSocial.ButtonVisibility visibility) { + List> item, AbstractSocial.ButtonVisibility visibility) { this.socialList.stream() .filter(e -> e.canSend(player)) .forEach(e -> e.sendMessage(player, message, item, visibility)); @@ -140,7 +159,7 @@ public void broadcastMessage(String dbField, Long id, String message, List> item, AbstractSocial.ButtonVisibility visibility) { + List> item, AbstractSocial.ButtonVisibility visibility) { this.socialList.stream() .filter(e -> e.getDbField().equals(dbField)) .forEach(e -> e.sendMessage(id, message, item, visibility)); diff --git a/src/main/java/net/elytrium/limboauth/socialaddon/listener/LimboAuthListener.java b/src/main/java/net/elytrium/limboauth/socialaddon/listener/LimboAuthListener.java index 880cf7c..9e3859e 100644 --- a/src/main/java/net/elytrium/limboauth/socialaddon/listener/LimboAuthListener.java +++ b/src/main/java/net/elytrium/limboauth/socialaddon/listener/LimboAuthListener.java @@ -91,6 +91,7 @@ public LimboAuthListener(Addon addon, LimboAuth plugin, Dao> buttons, ButtonVisibility visibility) { - ReplyKeyboard keyboard = new InlineKeyboardMarkup(buttons.stream().map(row -> row.stream().map(e -> { - - InlineKeyboardButton button = new InlineKeyboardButton(); - button.setText(e.getValue()); - button.setCallbackData(e.getId()); - - return button; - }).collect(Collectors.toList())).collect(Collectors.toList())); + ReplyKeyboard keyboard; + switch (visibility) { + case PREFER_INLINE: { + keyboard = new InlineKeyboardMarkup(buttons.stream().map(row -> row.stream().map(e -> { + InlineKeyboardButton button = new InlineKeyboardButton(); + button.setText(e.getValue()); + button.setCallbackData(e.getId()); + + return button; + }).collect(Collectors.toList())).collect(Collectors.toList())); + break; + } + default: + case PREFER_KEYBOARD: { + keyboard = new ReplyKeyboardMarkup(buttons.stream().map(row -> + new KeyboardRow(row.stream().map(e -> + new KeyboardButton(e.getValue())).collect(Collectors.toList()))) + .collect(Collectors.toList())); + break; + } + } this.bot.sendMessage(id, content, keyboard); }