mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-19 23:28:59 +01:00
playerlistener cleanup
This commit is contained in:
parent
64aacb12db
commit
52c0c7dd64
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.converter.Converter;
|
||||
@ -23,9 +22,6 @@ import java.util.List;
|
||||
*/
|
||||
public class ConverterCommand implements ExecutableCommand {
|
||||
|
||||
@Inject
|
||||
private AuthMe authMe;
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
|
@ -51,7 +51,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static fr.xephi.authme.listener.ListenerService.shouldCancelEvent;
|
||||
import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOWED_MOVEMENT_RADIUS;
|
||||
import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOW_ALL_COMMANDS_IF_REGISTRATION_IS_OPTIONAL;
|
||||
import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT;
|
||||
|
||||
/**
|
||||
@ -82,41 +81,21 @@ public class AuthMePlayerListener implements Listener {
|
||||
@Inject
|
||||
private AuthMe plugin;
|
||||
|
||||
private void sendLoginOrRegisterMessage(final Player player) {
|
||||
bukkitService.runTaskAsynchronously(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (dataSource.isAuthAvailable(player.getName().toLowerCase())) {
|
||||
m.send(player, MessageKey.LOGIN_MESSAGE);
|
||||
} else {
|
||||
if (settings.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)) {
|
||||
m.send(player, MessageKey.REGISTER_EMAIL_MESSAGE);
|
||||
} else {
|
||||
m.send(player, MessageKey.REGISTER_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
String cmd = event.getMessage().split(" ")[0].toLowerCase();
|
||||
if (settings.getProperty(HooksSettings.USE_ESSENTIALS_MOTD) && "/motd".equals(cmd)) {
|
||||
return;
|
||||
}
|
||||
if (!settings.getProperty(RegistrationSettings.FORCE)
|
||||
&& settings.getProperty(ALLOW_ALL_COMMANDS_IF_REGISTRATION_IS_OPTIONAL)) {
|
||||
if (settings.getProperty(HooksSettings.USE_ESSENTIALS_MOTD) && cmd.equals("/motd")) {
|
||||
return;
|
||||
}
|
||||
if (settings.getProperty(RestrictionSettings.ALLOW_COMMANDS).contains(cmd)) {
|
||||
return;
|
||||
}
|
||||
if (Utils.checkAuth(event.getPlayer())) {
|
||||
final Player player = event.getPlayer();
|
||||
if (!shouldCancelEvent(player)) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
sendLoginOrRegisterMessage(event.getPlayer());
|
||||
m.send(player, MessageKey.DENIED_COMMAND);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
@ -128,12 +107,7 @@ public class AuthMePlayerListener implements Listener {
|
||||
final Player player = event.getPlayer();
|
||||
if (shouldCancelEvent(player)) {
|
||||
event.setCancelled(true);
|
||||
bukkitService.runTaskAsynchronously(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
m.send(player, MessageKey.DENIED_CHAT);
|
||||
}
|
||||
});
|
||||
m.send(player, MessageKey.DENIED_CHAT);
|
||||
} else if (settings.getProperty(RestrictionSettings.HIDE_CHAT)) {
|
||||
Set<Player> recipients = event.getRecipients();
|
||||
Iterator<Player> iter = recipients.iterator();
|
||||
@ -143,6 +117,9 @@ public class AuthMePlayerListener implements Listener {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
if (recipients.size() == 0) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import fr.xephi.authme.util.StringUtils;
|
||||
/**
|
||||
* Exception thrown when a verification has failed.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class FailedVerificationException extends Exception {
|
||||
|
||||
private final MessageKey reason;
|
||||
|
@ -5,6 +5,8 @@ package fr.xephi.authme.output;
|
||||
*/
|
||||
public enum MessageKey {
|
||||
|
||||
DENIED_COMMAND("denied_command"),
|
||||
|
||||
SAME_IP_ONLINE("same_ip_online"),
|
||||
|
||||
DENIED_CHAT("denied_chat"),
|
||||
|
@ -22,12 +22,6 @@ public class RestrictionSettings implements SettingsClass {
|
||||
public static final Property<Boolean> HIDE_CHAT =
|
||||
newProperty("settings.restrictions.hideChat", false);
|
||||
|
||||
@Comment({
|
||||
"Allow unlogged users to use all the commands if registration is not forced!",
|
||||
"WARNING: use this only if you need it!"})
|
||||
public static final Property<Boolean> ALLOW_ALL_COMMANDS_IF_REGISTRATION_IS_OPTIONAL =
|
||||
newProperty("settings.restrictions.allowAllCommandsIfRegistrationIsOptional", false);
|
||||
|
||||
@Comment("Allowed commands for unauthenticated players")
|
||||
public static final Property<List<String>> ALLOW_COMMANDS =
|
||||
newListProperty("settings.restrictions.allowCommands",
|
||||
|
@ -1,3 +1,4 @@
|
||||
denied_command: '&cIn order to be able to use this command you must be authenticated!'
|
||||
same_ip_online: 'A player with the same IP is already in game!'
|
||||
denied_chat: '&cIn order to be able to chat you must be authenticated!'
|
||||
kick_antibot: 'AntiBot protection mode is enabled! You have to wait some minutes before joining the server.'
|
||||
|
@ -388,7 +388,7 @@ public class OnJoinVerifierTest {
|
||||
return player;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private void returnOnlineListFromBukkitServer(Collection<Player> onlineList) {
|
||||
// Note ljacqu 20160529: The compiler gets lost in generics because Collection<? extends Player> is returned
|
||||
// from getOnlinePlayers(). We need to uncheck onlineList to a simple Collection or it will refuse to compile.
|
||||
|
Loading…
Reference in New Issue
Block a user