Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded into commands-refactor

This commit is contained in:
ljacqu 2015-12-08 21:58:35 +01:00
commit 0710c4f531
17 changed files with 226 additions and 117 deletions

View File

@ -5,7 +5,7 @@
<groupId>fr.xephi</groupId> <groupId>fr.xephi</groupId>
<artifactId>authme</artifactId> <artifactId>authme</artifactId>
<version>5.1-SNAPSHOT</version> <version>5.2-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>AuthMeReloaded</name> <name>AuthMeReloaded</name>
@ -285,7 +285,7 @@
<dependency> <dependency>
<groupId>com.zaxxer</groupId> <groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId> <artifactId>HikariCP</artifactId>
<version>2.4.2</version> <version>2.4.3</version>
<scope>compile</scope> <scope>compile</scope>
<exclusions> <exclusions>
<exclusion> <exclusion>

View File

@ -57,25 +57,6 @@ public class CommandDescription {
*/ */
private CommandPermissions permissions; private CommandPermissions permissions;
/**
* Constructor.
*
* @param executableCommand The executable command, or null.
* @param labels List of command labels.
* @param description Command description.
* @param detailedDescription Detailed comment description.
* @param parent Parent command.
*/
@Deprecated
public CommandDescription(ExecutableCommand executableCommand, List<String> labels, String description, String detailedDescription, CommandDescription parent) {
setExecutableCommand(executableCommand);
this.labels = labels;
this.description = description;
this.detailedDescription = detailedDescription;
setParent(parent);
this.arguments = new ArrayList<>();
}
/** /**
* Private constructor. Use {@link CommandDescription#builder()} to create instances of this class. * Private constructor. Use {@link CommandDescription#builder()} to create instances of this class.
* <p /> * <p />

View File

@ -184,7 +184,6 @@ public final class CommandInitializer {
.withArgument("player", "Player Name", false) .withArgument("player", "Player Name", false)
.build(); .build();
// Register the spawn command // Register the spawn command
CommandDescription.builder() CommandDescription.builder()
.executableCommand(new SpawnCommand()) .executableCommand(new SpawnCommand())
@ -216,7 +215,6 @@ public final class CommandInitializer {
.permissions(OP_ONLY, AdminPermission.FIRST_SPAWN) .permissions(OP_ONLY, AdminPermission.FIRST_SPAWN)
.build(); .build();
// Register the setfirstspawn command // Register the setfirstspawn command
CommandDescription.builder() CommandDescription.builder()
.executableCommand(new SetFirstSpawnCommand()) .executableCommand(new SetFirstSpawnCommand())
@ -242,7 +240,8 @@ public final class CommandInitializer {
CommandDescription.builder() CommandDescription.builder()
.executableCommand(new PurgeLastPositionCommand()) .executableCommand(new PurgeLastPositionCommand())
.parent(AUTHME_BASE) .parent(AUTHME_BASE)
.labels("resetpos", "purgelastposition", "purgelastpos", "resetposition", "resetlastposition", "resetlastpos") .labels("resetpos", "purgelastposition", "purgelastpos", "resetposition",
"resetlastposition", "resetlastpos")
.description("Purge player's last position") .description("Purge player's last position")
.detailedDescription("Purge the last know position of the specified player.") .detailedDescription("Purge the last know position of the specified player.")
.permissions(OP_ONLY, AdminPermission.PURGE_LAST_POSITION) .permissions(OP_ONLY, AdminPermission.PURGE_LAST_POSITION)
@ -250,7 +249,7 @@ public final class CommandInitializer {
.build(); .build();
// Register the purgebannedplayers command // Register the purgebannedplayers command
CommandDescription purgeBannedPlayersCommand = CommandDescription.builder() CommandDescription.builder()
.executableCommand(new PurgeBannedPlayersCommand()) .executableCommand(new PurgeBannedPlayersCommand())
.parent(AUTHME_BASE) .parent(AUTHME_BASE)
.labels("purgebannedplayers", "purgebannedplayer", "deletebannedplayers", "deletebannedplayer") .labels("purgebannedplayers", "purgebannedplayer", "deletebannedplayers", "deletebannedplayer")
@ -260,7 +259,7 @@ public final class CommandInitializer {
.build(); .build();
// Register the switchantibot command // Register the switchantibot command
CommandDescription switchAntiBotCommand = CommandDescription.builder() CommandDescription.builder()
.executableCommand(new SwitchAntiBotCommand()) .executableCommand(new SwitchAntiBotCommand())
.parent(AUTHME_BASE) .parent(AUTHME_BASE)
.labels("switchantibot", "toggleantibot", "antibot") .labels("switchantibot", "toggleantibot", "antibot")
@ -270,26 +269,13 @@ public final class CommandInitializer {
.withArgument("mode", "ON / OFF", true) .withArgument("mode", "ON / OFF", true)
.build(); .build();
// // Register the resetname command
// CommandDescription resetNameCommand = new CommandDescription(
// new ResetNameCommand(),
// new ArrayList<String>() {{
// add("resetname");
// add("resetnames");
// }},
// "Reset name",
// "Reset name",
// authMeCommand);
// resetNameCommand.setCommandPermissions("authme.admin.resetname",
// CommandPermissions.DefaultPermission.OP_ONLY);
// Register the reload command // Register the reload command
CommandDescription reloadCommand = CommandDescription.builder() CommandDescription.builder()
.executableCommand(new PurgeLastPositionCommand()) .executableCommand(new ReloadCommand())
.parent(AUTHME_BASE) .parent(AUTHME_BASE)
.labels("reload", "reload") .labels("reload", "rld")
.description("Reload plugin") .description("Reload plugin")
.detailedDescription("Reload the AutheMeReloaded plugin.") .detailedDescription("Reload the AuthMeReloaded plugin.")
.permissions(OP_ONLY, AdminPermission.RELOAD) .permissions(OP_ONLY, AdminPermission.RELOAD)
.build(); .build();
@ -315,13 +301,12 @@ public final class CommandInitializer {
.build(); .build();
// Register the help command // Register the help command
CommandDescription loginHelpCommand = CommandDescription.builder() CommandDescription.builder()
.executableCommand(helpCommandExecutable) .executableCommand(helpCommandExecutable)
.parent(LOGIN_BASE) .parent(LOGIN_BASE)
.labels(helpCommandLabels) .labels(helpCommandLabels)
.description("View Help") .description("View Help")
.detailedDescription("View detailed help pages about AuthMeReloaded login commands.") .detailedDescription("View detailed help pages about AuthMeReloaded login commands.")
.permissions(ALLOWED)
.withArgument("query", "The command or query to view help for.", true) .withArgument("query", "The command or query to view help for.", true)
.build(); .build();
@ -336,13 +321,12 @@ public final class CommandInitializer {
.build(); .build();
// Register the help command // Register the help command
CommandDescription logoutHelpCommand = CommandDescription.builder() CommandDescription.builder()
.executableCommand(helpCommandExecutable) .executableCommand(helpCommandExecutable)
.parent(LOGOUT_BASE) .parent(LOGOUT_BASE)
.labels(helpCommandLabels) .labels(helpCommandLabels)
.description("View help") .description("View help")
.detailedDescription("View detailed help pages about AuthMeReloaded logout commands.") .detailedDescription("View detailed help pages about AuthMeReloaded logout commands.")
.permissions(ALLOWED)
.withArgument("query", "The command or query to view help for.", true) .withArgument("query", "The command or query to view help for.", true)
.build(); .build();
@ -359,13 +343,12 @@ public final class CommandInitializer {
.build(); .build();
// Register the help command // Register the help command
CommandDescription registerHelpCommand = CommandDescription.builder() CommandDescription.builder()
.executableCommand(helpCommandExecutable) .executableCommand(helpCommandExecutable)
.parent(REGISTER_BASE) .parent(REGISTER_BASE)
.labels(helpCommandLabels) .labels(helpCommandLabels)
.description("View help") .description("View help")
.detailedDescription("View detailed help pages about AuthMeReloaded register commands.") .detailedDescription("View detailed help pages about AuthMeReloaded register commands.")
.permissions(ALLOWED)
.withArgument("query", "The command or query to view help for.", true) .withArgument("query", "The command or query to view help for.", true)
.build(); .build();
@ -381,13 +364,12 @@ public final class CommandInitializer {
.build(); .build();
// Register the help command // Register the help command
CommandDescription unregisterHelpCommand = CommandDescription.builder() CommandDescription.builder()
.executableCommand(helpCommandExecutable) .executableCommand(helpCommandExecutable)
.parent(UNREGISTER_BASE) .parent(UNREGISTER_BASE)
.labels(helpCommandLabels) .labels(helpCommandLabels)
.description("View help") .description("View help")
.detailedDescription("View detailed help pages about AuthMeReloaded unregister commands.") .detailedDescription("View detailed help pages about AuthMeReloaded unregister commands.")
.permissions(ALLOWED)
.withArgument("query", "The command or query to view help for.", true) .withArgument("query", "The command or query to view help for.", true)
.build(); .build();
@ -404,13 +386,12 @@ public final class CommandInitializer {
.build(); .build();
// Register the help command // Register the help command
CommandDescription changePasswordHelpCommand = CommandDescription.builder() CommandDescription.builder()
.executableCommand(helpCommandExecutable) .executableCommand(helpCommandExecutable)
.parent(CHANGE_PASSWORD_BASE) .parent(CHANGE_PASSWORD_BASE)
.labels(helpCommandLabels) .labels(helpCommandLabels)
.description("View help") .description("View help")
.detailedDescription("View detailed help pages about AuthMeReloaded changepassword commands.") .detailedDescription("View detailed help pages about AuthMeReloaded changepassword commands.")
.permissions(ALLOWED)
.withArgument("query", "The command or query to view help for.", true) .withArgument("query", "The command or query to view help for.", true)
.build(); .build();
@ -421,39 +402,37 @@ public final class CommandInitializer {
.labels("email", "mail") .labels("email", "mail")
.description("Email command") .description("Email command")
.detailedDescription("The AuthMeReloaded Email command base.") .detailedDescription("The AuthMeReloaded Email command base.")
.permissions(ALLOWED)
.build(); .build();
// Register the help command // Register the help command
CommandDescription emailHelpCommand = CommandDescription.builder() CommandDescription.builder()
.executableCommand(helpCommandExecutable) .executableCommand(helpCommandExecutable)
.parent(EMAIL_BASE) .parent(EMAIL_BASE)
.labels(helpCommandLabels) .labels(helpCommandLabels)
.description("View help") .description("View help")
.detailedDescription("View detailed help pages about AuthMeReloaded email commands.") .detailedDescription("View detailed help pages about AuthMeReloaded email commands.")
.permissions(ALLOWED)
.withArgument("query", "The command or query to view help for.", true) .withArgument("query", "The command or query to view help for.", true)
.build(); .build();
// Register the add command // Register the add command
CommandDescription addEmailCommand = CommandDescription.builder() CommandDescription.builder()
.executableCommand(new AddEmailCommand()) .executableCommand(new AddEmailCommand())
.parent(EMAIL_BASE) .parent(EMAIL_BASE)
.labels("add", "addemail", "addmail") .labels("add", "addemail", "addmail")
.description("Add Email") .description("Add Email")
.detailedDescription("Add a new Email address to your account.") .detailedDescription("Add a new email address to your account.")
.permissions(ALLOWED, PlayerPermission.ADD_EMAIL) .permissions(ALLOWED, PlayerPermission.ADD_EMAIL)
.withArgument("email", "Email address", false) .withArgument("email", "Email address", false)
.withArgument("verifyEmail", "Email address verification", false) .withArgument("verifyEmail", "Email address verification", false)
.build(); .build();
// Register the change command // Register the change command
CommandDescription changeEmailCommand = CommandDescription.builder() CommandDescription.builder()
.executableCommand(new ChangeEmailCommand()) .executableCommand(new ChangeEmailCommand())
.parent(EMAIL_BASE) .parent(EMAIL_BASE)
.labels("change", "changeemail", "changemail") .labels("change", "changeemail", "changemail")
.description("Change Email") .description("Change Email")
.detailedDescription("Change an Email address of your account.") .detailedDescription("Change an email address of your account.")
.permissions(ALLOWED, PlayerPermission.CHANGE_EMAIL) .permissions(ALLOWED, PlayerPermission.CHANGE_EMAIL)
.withArgument("oldEmail", "Old email address", false) .withArgument("oldEmail", "Old email address", false)
.withArgument("newEmail", "New email address", false) .withArgument("newEmail", "New email address", false)
@ -461,12 +440,13 @@ public final class CommandInitializer {
// Register the recover command // Register the recover command
CommandDescription recoverEmailCommand = CommandDescription.builder() CommandDescription.builder()
.executableCommand(new RecoverEmailCommand()) .executableCommand(new RecoverEmailCommand())
.parent(EMAIL_BASE) .parent(EMAIL_BASE)
.labels("recover", "recovery", "recoveremail", "recovermail") .labels("recover", "recovery", "recoveremail", "recovermail")
.description("Recover password using Email") .description("Recover password using Email")
.detailedDescription("Recover your account using an Email address by sending a mail containing a new password.") .detailedDescription("Recover your account using an Email address by sending a mail containing " +
"a new password.")
.permissions(ALLOWED, PlayerPermission.RECOVER_EMAIL) .permissions(ALLOWED, PlayerPermission.RECOVER_EMAIL)
.withArgument("email", "Email address", false) .withArgument("email", "Email address", false)
.build(); .build();
@ -477,19 +457,18 @@ public final class CommandInitializer {
.parent(null) .parent(null)
.labels("captcha", "capt") .labels("captcha", "capt")
.description("Captcha Command") .description("Captcha Command")
.detailedDescription("Captcha command for AuthMeRelaoded.") .detailedDescription("Captcha command for AuthMeReloaded.")
.permissions(ALLOWED, PlayerPermission.CAPTCHA) .permissions(ALLOWED, PlayerPermission.CAPTCHA)
.withArgument("captcha", "The Captcha", false) .withArgument("captcha", "The Captcha", false)
.build(); .build();
// Register the help command // Register the help command
CommandDescription captchaHelpCommand = CommandDescription.builder() CommandDescription.builder()
.executableCommand(helpCommandExecutable) .executableCommand(helpCommandExecutable)
.parent(CAPTCHA_BASE) .parent(CAPTCHA_BASE)
.labels(helpCommandLabels) .labels(helpCommandLabels)
.description("View help") .description("View help")
.detailedDescription("View detailed help pages about AuthMeReloaded captcha commands.") .detailedDescription("View detailed help pages about AuthMeReloaded captcha commands.")
.permissions(ALLOWED)
.withArgument("query", "The command or query to view help for.", true) .withArgument("query", "The command or query to view help for.", true)
.build(); .build();
@ -499,19 +478,19 @@ public final class CommandInitializer {
.parent(null) .parent(null)
.labels("converter", "convert", "conv") .labels("converter", "convert", "conv")
.description("Converter Command") .description("Converter Command")
.detailedDescription("Converter command for AuthMeRelaoded.") .detailedDescription("Converter command for AuthMeReloaded.")
.permissions(OP_ONLY, AdminPermission.CONVERTER) .permissions(OP_ONLY, AdminPermission.CONVERTER)
.withArgument("job", "Conversion job: flattosql / flattosqlite /| xauth / crazylogin / rakamak / royalauth / vauth / sqltoflat", false) .withArgument("job", "Conversion job: flattosql / flattosqlite /| xauth / crazylogin / rakamak / " +
"royalauth / vauth / sqltoflat", false)
.build(); .build();
// Register the help command // Register the help command
CommandDescription converterHelpCommand = CommandDescription.builder() CommandDescription.builder()
.executableCommand(helpCommandExecutable) .executableCommand(helpCommandExecutable)
.parent(CONVERTER_BASE) .parent(CONVERTER_BASE)
.labels(helpCommandLabels) .labels(helpCommandLabels)
.description("View help") .description("View help")
.detailedDescription("View detailed help pages about AuthMeReloaded converter commands.") .detailedDescription("View detailed help pages about AuthMeReloaded converter commands.")
.permissions(OP_ONLY)
.withArgument("query", "The command or query to view help for.", true) .withArgument("query", "The command or query to view help for.", true)
.build(); .build();

View File

@ -7,7 +7,6 @@ import fr.xephi.authme.permission.PermissionNode;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**

View File

@ -1,11 +1,10 @@
package fr.xephi.authme.command; package fr.xephi.authme.command;
import java.util.List;
import fr.xephi.authme.util.CollectionUtils; import fr.xephi.authme.util.CollectionUtils;
import fr.xephi.authme.util.StringUtils; import fr.xephi.authme.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
public final class CommandUtils { public final class CommandUtils {
public static int getMinNumberOfArguments(CommandDescription command) { public static int getMinNumberOfArguments(CommandDescription command) {

View File

@ -1,5 +1,14 @@
package fr.xephi.authme.command.help; package fr.xephi.authme.command.help;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandArgumentDescription; import fr.xephi.authme.command.CommandArgumentDescription;
import fr.xephi.authme.command.CommandDescription; import fr.xephi.authme.command.CommandDescription;
@ -8,15 +17,6 @@ import fr.xephi.authme.command.CommandPermissions;
import fr.xephi.authme.permission.PermissionNode; import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.util.CollectionUtils; import fr.xephi.authme.util.CollectionUtils;
import fr.xephi.authme.util.StringUtils; import fr.xephi.authme.util.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/** /**
*/ */

View File

@ -32,6 +32,12 @@ public class AuthMeBlockListener implements Listener {
if (Utils.checkAuth(event.getPlayer())) { if (Utils.checkAuth(event.getPlayer())) {
return; return;
} }
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC(event.getPlayer())) {
return;
}
event.setCancelled(true); event.setCancelled(true);
} }
@ -45,6 +51,12 @@ public class AuthMeBlockListener implements Listener {
if (Utils.checkAuth(event.getPlayer())) { if (Utils.checkAuth(event.getPlayer())) {
return; return;
} }
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC(event.getPlayer())) {
return;
}
event.setCancelled(true); event.setCancelled(true);
} }

View File

@ -49,7 +49,12 @@ public class AuthMeEntityListener implements Listener {
} }
Player player = (Player) entity; Player player = (Player) entity;
if (Utils.checkAuth(player)) { if (Utils.checkAuth(player) ) {
return;
}
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC(player)) {
return; return;
} }
player.setFireTicks(0); player.setFireTicks(0);
@ -73,6 +78,11 @@ public class AuthMeEntityListener implements Listener {
return; return;
} }
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC((Player) entity)) {
return;
}
event.setTarget(null); event.setTarget(null);
event.setCancelled(true); event.setCancelled(true);
} }
@ -83,7 +93,7 @@ public class AuthMeEntityListener implements Listener {
* @param event EntityDamageByEntityEvent * @param event EntityDamageByEntityEvent
*/ */
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onDmg(EntityDamageByEntityEvent event) { public void onDamage(EntityDamageByEntityEvent event) {
Entity entity = event.getDamager(); Entity entity = event.getDamager();
if (entity == null || !(entity instanceof Player)) { if (entity == null || !(entity instanceof Player)) {
return; return;
@ -94,6 +104,11 @@ public class AuthMeEntityListener implements Listener {
return; return;
} }
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC(player)) {
return;
}
event.setCancelled(true); event.setCancelled(true);
} }
@ -113,6 +128,11 @@ public class AuthMeEntityListener implements Listener {
return; return;
} }
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC((Player) entity)) {
return;
}
event.setCancelled(true); event.setCancelled(true);
} }
@ -132,6 +152,11 @@ public class AuthMeEntityListener implements Listener {
return; return;
} }
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC((Player) entity)) {
return;
}
event.setAmount(0); event.setAmount(0);
event.setCancelled(true); event.setCancelled(true);
} }
@ -152,6 +177,11 @@ public class AuthMeEntityListener implements Listener {
return; return;
} }
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC((Player) entity)) {
return;
}
event.setCancelled(true); event.setCancelled(true);
} }
@ -171,6 +201,11 @@ public class AuthMeEntityListener implements Listener {
return; return;
} }
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC((Player) entity)) {
return;
}
event.setCancelled(true); event.setCancelled(true);
} }
@ -210,6 +245,11 @@ public class AuthMeEntityListener implements Listener {
return; return;
} }
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC(player)) {
return;
}
event.setCancelled(true); event.setCancelled(true);
} }
@ -230,6 +270,11 @@ public class AuthMeEntityListener implements Listener {
return; return;
} }
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC(player)) {
return;
}
event.setCancelled(true); event.setCancelled(true);
} }

View File

@ -28,7 +28,24 @@ import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.*; import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerShearEntityEvent;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -53,7 +70,6 @@ public class AuthMePlayerListener implements Listener {
} }
final Player player = event.getPlayer(); final Player player = event.getPlayer();
if (Utils.checkAuth(player)) { if (Utils.checkAuth(player)) {
for (Player p : Utils.getOnlinePlayers()) { for (Player p : Utils.getOnlinePlayers()) {
if (!PlayerCache.getInstance().isAuthenticated(p.getName())) { if (!PlayerCache.getInstance().isAuthenticated(p.getName())) {
@ -64,6 +80,11 @@ public class AuthMePlayerListener implements Listener {
} }
event.setCancelled(true); event.setCancelled(true);
sendLoginRegisterMSG(player);
}
// TODO: new name
private void sendLoginRegisterMSG(final Player player) {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override @Override
public void run() { public void run() {
@ -93,6 +114,7 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
event.setCancelled(true); event.setCancelled(true);
sendLoginRegisterMSG(event.getPlayer());
} }
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL) @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
@ -169,17 +191,22 @@ public class AuthMePlayerListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
if (event.getPlayer() == null || Utils.isNPC(event.getPlayer())) { final Player player = event.getPlayer();
if (player == null) {
return; return;
} }
final Player player = event.getPlayer(); /* IMPOSSIBLE!!!! TODO: check this!
if(Utils.isNPC(player)) {
return;
}
*/
String name = player.getName().toLowerCase(); String name = player.getName().toLowerCase();
String joinMsg = event.getJoinMessage(); String joinMsg = event.getJoinMessage();
boolean delay = Settings.delayJoinLeaveMessages && joinMsg != null;
// Remove the join message while the player isn't logging in // Remove the join message while the player isn't logging in
if (delay) { if (Settings.delayJoinLeaveMessages && joinMsg != null) {
event.setJoinMessage(null); event.setJoinMessage(null);
joinMessage.put(name, joinMsg); joinMessage.put(name, joinMsg);
} }
@ -237,11 +264,16 @@ public class AuthMePlayerListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerLogin(PlayerLoginEvent event) { public void onPlayerLogin(PlayerLoginEvent event) {
if (event.getPlayer() == null || Utils.isUnrestricted(event.getPlayer())) { final Player player = event.getPlayer();
if (player == null || Utils.isUnrestricted(player)) {
return; return;
} }
if (event.getResult() == PlayerLoginEvent.Result.KICK_FULL) { // Get the permissions manager
PermissionsManager permsMan = plugin.getPermissionsManager();
if (event.getResult() == PlayerLoginEvent.Result.KICK_FULL
&& permsMan.hasPermission(player, PlayerPermission.IS_VIP)) {
int playersOnline = Utils.getOnlinePlayers().size(); int playersOnline = Utils.getOnlinePlayers().size();
if (playersOnline > plugin.getServer().getMaxPlayers()) { if (playersOnline > plugin.getServer().getMaxPlayers()) {
event.allow(); event.allow();
@ -262,10 +294,6 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
// Get the permissions manager
PermissionsManager permsMan = plugin.getPermissionsManager();
final Player player = event.getPlayer();
if (event.getResult() == PlayerLoginEvent.Result.KICK_FULL && !permsMan.hasPermission(player, PlayerPermission.IS_VIP)) { if (event.getResult() == PlayerLoginEvent.Result.KICK_FULL && !permsMan.hasPermission(player, PlayerPermission.IS_VIP)) {
event.setKickMessage(m.retrieveSingle(MessageKey.KICK_FULL_SERVER)); event.setKickMessage(m.retrieveSingle(MessageKey.KICK_FULL_SERVER));
event.setResult(PlayerLoginEvent.Result.KICK_FULL); event.setResult(PlayerLoginEvent.Result.KICK_FULL);
@ -311,12 +339,12 @@ public class AuthMePlayerListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
if (event.getPlayer() == null) { Player player = event.getPlayer();
if (player == null) {
return; return;
} }
Player player = event.getPlayer();
if (Settings.delayJoinLeaveMessages && !Utils.checkAuth(player)) { if (Settings.delayJoinLeaveMessages && !Utils.checkAuth(player)) {
event.setQuitMessage(null); event.setQuitMessage(null);
} }
@ -326,7 +354,9 @@ public class AuthMePlayerListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerKick(PlayerKickEvent event) { public void onPlayerKick(PlayerKickEvent event) {
if (event.getPlayer() == null) { Player player = event.getPlayer();
if (player == null) {
return; return;
} }
@ -336,13 +366,15 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
Player player = event.getPlayer();
plugin.getManagement().performQuit(player, true); plugin.getManagement().performQuit(player, true);
} }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerPickupItem(PlayerPickupItemEvent event) { public void onPlayerPickupItem(PlayerPickupItemEvent event) {
if (Utils.checkAuth(event.getPlayer())) { Player player = event.getPlayer();
// TODO: npc status can be used to bypass security!!!
if (Utils.checkAuth(player) || Utils.isNPC(player)) {
return; return;
} }
event.setCancelled(true); event.setCancelled(true);
@ -350,7 +382,10 @@ public class AuthMePlayerListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
if (Utils.checkAuth(event.getPlayer())) { Player player = event.getPlayer();
// TODO: npc status can be used to bypass security!!!
if (Utils.checkAuth(player) || Utils.isNPC(player)) {
return; return;
} }
event.setCancelled(true); event.setCancelled(true);
@ -358,7 +393,10 @@ public class AuthMePlayerListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL) @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onPlayerConsumeItem(PlayerItemConsumeEvent event) { public void onPlayerConsumeItem(PlayerItemConsumeEvent event) {
if (Utils.checkAuth(event.getPlayer())) { Player player = event.getPlayer();
// TODO: npc status can be used to bypass security!!!
if (Utils.checkAuth(player) || Utils.isNPC(player)) {
return; return;
} }
event.setCancelled(true); event.setCancelled(true);
@ -367,7 +405,9 @@ public class AuthMePlayerListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerInventoryOpen(InventoryOpenEvent event) { public void onPlayerInventoryOpen(InventoryOpenEvent event) {
final Player player = (Player) event.getPlayer(); final Player player = (Player) event.getPlayer();
if (Utils.checkAuth(player)) {
// TODO: npc status can be used to bypass security!!!
if (Utils.checkAuth(player) || Utils.isNPC(player)) {
return; return;
} }
event.setCancelled(true); event.setCancelled(true);
@ -392,6 +432,10 @@ public class AuthMePlayerListener implements Listener {
return; return;
if (Utils.checkAuth((Player) event.getWhoClicked())) if (Utils.checkAuth((Player) event.getWhoClicked()))
return; return;
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC((Player) event.getWhoClicked()))
return;
event.setCancelled(true); event.setCancelled(true);
} }
@ -404,6 +448,11 @@ public class AuthMePlayerListener implements Listener {
if (Utils.checkAuth((Player) damager)) { if (Utils.checkAuth((Player) damager)) {
return; return;
} }
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC((Player) damager)) {
return;
}
event.setCancelled(true); event.setCancelled(true);
} }
@ -412,6 +461,11 @@ public class AuthMePlayerListener implements Listener {
if (Utils.checkAuth(event.getPlayer())) { if (Utils.checkAuth(event.getPlayer())) {
return; return;
} }
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC(event.getPlayer())) {
return;
}
event.setCancelled(true); event.setCancelled(true);
} }
@ -420,6 +474,11 @@ public class AuthMePlayerListener implements Listener {
if (Utils.checkAuth(event.getPlayer())) { if (Utils.checkAuth(event.getPlayer())) {
return; return;
} }
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC(event.getPlayer())) {
return;
}
event.setCancelled(true); event.setCancelled(true);
} }
@ -428,6 +487,11 @@ public class AuthMePlayerListener implements Listener {
if (Utils.checkAuth(event.getPlayer())) { if (Utils.checkAuth(event.getPlayer())) {
return; return;
} }
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC(event.getPlayer())) {
return;
}
event.setCancelled(true); event.setCancelled(true);
} }
@ -436,6 +500,11 @@ public class AuthMePlayerListener implements Listener {
if (Utils.checkAuth(event.getPlayer())) { if (Utils.checkAuth(event.getPlayer())) {
return; return;
} }
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC(event.getPlayer())) {
return;
}
event.setCancelled(true); event.setCancelled(true);
} }
@ -445,6 +514,11 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC(event.getPlayer())) {
return;
}
Player player = event.getPlayer(); Player player = event.getPlayer();
String name = player.getName().toLowerCase(); String name = player.getName().toLowerCase();
Location spawn = plugin.getSpawnLocation(player); Location spawn = plugin.getSpawnLocation(player);
@ -463,6 +537,11 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC(event.getPlayer())) {
return;
}
Player player = event.getPlayer(); Player player = event.getPlayer();
if (plugin.getPermissionsManager().hasPermission(player, PlayerPermission.BYPASS_FORCE_SURVIVAL)) { if (plugin.getPermissionsManager().hasPermission(player, PlayerPermission.BYPASS_FORCE_SURVIVAL)) {
return; return;
@ -481,6 +560,11 @@ public class AuthMePlayerListener implements Listener {
if (Utils.checkAuth(event.getPlayer())) { if (Utils.checkAuth(event.getPlayer())) {
return; return;
} }
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC(event.getPlayer())) {
return;
}
event.setCancelled(true); event.setCancelled(true);
} }
@ -489,6 +573,11 @@ public class AuthMePlayerListener implements Listener {
if (Utils.checkAuth(event.getPlayer())) { if (Utils.checkAuth(event.getPlayer())) {
return; return;
} }
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC(event.getPlayer())) {
return;
}
event.setCancelled(true); event.setCancelled(true);
} }

View File

@ -32,6 +32,11 @@ public class AuthMePlayerListener16 implements Listener {
if (Utils.checkAuth(event.getPlayer())) { if (Utils.checkAuth(event.getPlayer())) {
return; return;
} }
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC(event.getPlayer())) {
return;
}
event.setCancelled(true); event.setCancelled(true);
} }

View File

@ -32,6 +32,11 @@ public class AuthMePlayerListener18 implements Listener {
if (Utils.checkAuth(event.getPlayer())) { if (Utils.checkAuth(event.getPlayer())) {
return; return;
} }
// TODO: npc status can be used to bypass security!!!
if (Utils.isNPC(event.getPlayer())) {
return;
}
event.setCancelled(true); event.setCancelled(true);
} }

View File

@ -328,7 +328,8 @@ public class PermissionsManager implements PermissionsService {
} }
public boolean hasPermission(Player player, CommandDescription command) { public boolean hasPermission(Player player, CommandDescription command) {
if (CollectionUtils.isEmpty(command.getCommandPermissions().getPermissionNodes())) { if (command.getCommandPermissions() == null
|| CollectionUtils.isEmpty(command.getCommandPermissions().getPermissionNodes())) {
return true; return true;
} }

View File

@ -80,15 +80,12 @@ public class AsynchronousLogin {
plugin.captcha.remove(name); plugin.captcha.remove(name);
plugin.captcha.putIfAbsent(name, i); plugin.captcha.putIfAbsent(name, i);
} }
if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) >= Settings.maxLoginTry) { if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) > Settings.maxLoginTry) {
plugin.cap.put(name, rdm.nextString()); plugin.cap.putIfAbsent(name, rdm.nextString());
for (String s : m.retrieve(MessageKey.USAGE_CAPTCHA)) { for (String s : m.retrieve(MessageKey.USAGE_CAPTCHA)) {
player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(name)).replace("<theCaptcha>", plugin.cap.get(name))); player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(name)).replace("<theCaptcha>", plugin.cap.get(name)));
} }
return true; return true;
} else if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) >= Settings.maxLoginTry) {
plugin.captcha.remove(name);
plugin.cap.remove(name);
} }
} }
return false; return false;

View File

@ -47,7 +47,7 @@ public class AsynchronousQuit {
public void process() { public void process() {
if (player == null) if (player == null)
return; return;
if (Utils.isNPC(player) || Utils.isUnrestricted(player)) { if (Utils.isUnrestricted(player)) {
return; return;
} }

View File

@ -137,7 +137,7 @@ public final class Utils {
// TODO: Move to a Manager // TODO: Move to a Manager
public static boolean checkAuth(Player player) { public static boolean checkAuth(Player player) {
if (player == null || Utils.isUnrestricted(player) || Utils.isNPC(player)) { if (player == null || Utils.isUnrestricted(player)) {
return true; return true;
} }

View File

@ -13,19 +13,16 @@ import org.bukkit.Server;
import org.bukkit.command.BlockCommandSender; import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;

View File

@ -3,4 +3,4 @@ if "%jarfile%" == "" (
call setvars.bat call setvars.bat
) )
mvn clean install -f "%pomfile%" mvn clean install -f "%pomfile%" -B