From 62b8af6a37e2a918edfa5c8666c3406330a3c8cb Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Sat, 1 Oct 2016 23:09:39 +0200 Subject: [PATCH] Fix #904 (Ljacqu, pls fix me :P) --- src/main/java/fr/xephi/authme/AntiBot.java | 8 ++++++-- .../java/fr/xephi/authme/permission/AdminPermission.java | 5 +++++ src/main/java/fr/xephi/authme/util/BukkitService.java | 1 + src/test/java/fr/xephi/authme/AntiBotTest.java | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AntiBot.java b/src/main/java/fr/xephi/authme/AntiBot.java index 81fd11b07..cfbc1f9de 100644 --- a/src/main/java/fr/xephi/authme/AntiBot.java +++ b/src/main/java/fr/xephi/authme/AntiBot.java @@ -2,6 +2,7 @@ package fr.xephi.authme; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.Messages; +import fr.xephi.authme.permission.AdminPermission; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerStatePermission; import fr.xephi.authme.settings.Settings; @@ -66,8 +67,11 @@ public class AntiBot { public void activateAntiBot() { antiBotStatus = AntiBotStatus.ACTIVE; - for (String s : messages.retrieve(MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE)) { - bukkitService.broadcastMessage(s); + for(Player player : bukkitService.getOnlinePlayers()) { + if(!permissionsManager.hasPermission(player, AdminPermission.ANTIBOT_MESSAGES)) { + continue; + } + messages.send(player, MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE); } final int duration = settings.getProperty(ProtectionSettings.ANTIBOT_DURATION); diff --git a/src/main/java/fr/xephi/authme/permission/AdminPermission.java b/src/main/java/fr/xephi/authme/permission/AdminPermission.java index 043ba6dc2..b34291282 100644 --- a/src/main/java/fr/xephi/authme/permission/AdminPermission.java +++ b/src/main/java/fr/xephi/authme/permission/AdminPermission.java @@ -100,6 +100,11 @@ public enum AdminPermission implements PermissionNode { */ RELOAD("authme.admin.reload", DefaultPermission.OP_ONLY), + /** + * Administrator command to reload the plugin configuration. + */ + ANTIBOT_MESSAGES("authme.admin.antibotmessages", DefaultPermission.OP_ONLY), + /** * Permission to see the other accounts of the players that log in. */ diff --git a/src/main/java/fr/xephi/authme/util/BukkitService.java b/src/main/java/fr/xephi/authme/util/BukkitService.java index 72bdacf7a..4931689ff 100644 --- a/src/main/java/fr/xephi/authme/util/BukkitService.java +++ b/src/main/java/fr/xephi/authme/util/BukkitService.java @@ -3,6 +3,7 @@ package fr.xephi.authme.util; import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.initialization.SettingsDependent; +import fr.xephi.authme.permission.PermissionNode; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.PluginSettings; import org.bukkit.BanEntry; diff --git a/src/test/java/fr/xephi/authme/AntiBotTest.java b/src/test/java/fr/xephi/authme/AntiBotTest.java index 2aee0c66e..d00bca63d 100644 --- a/src/test/java/fr/xephi/authme/AntiBotTest.java +++ b/src/test/java/fr/xephi/authme/AntiBotTest.java @@ -127,7 +127,7 @@ public class AntiBotTest { // then assertThat(antiBot.getAntiBotStatus(), equalTo(AntiBot.AntiBotStatus.ACTIVE)); ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); - verify(bukkitService, times(2)).broadcastMessage(captor.capture()); + verify(messages, times(2)).send(captor.capture()); assertThat(captor.getAllValues(), contains("Test line #1", "Test line #2")); long expectedTicks = duration * TICKS_PER_MINUTE; verify(bukkitService).scheduleSyncDelayedTask(any(Runnable.class), eq(expectedTicks));