Skip to content

Commit

Permalink
playerlistener cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sgdc3 committed May 29, 2016
1 parent 64aacb1 commit 52c0c7d
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -23,9 +22,6 @@
*/
public class ConverterCommand implements ExecutableCommand {

@Inject
private AuthMe authMe;

@Inject
private BukkitService bukkitService;

Expand Down
39 changes: 8 additions & 31 deletions src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@

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;

/**
Expand Down Expand Up @@ -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)
Expand All @@ -128,12 +107,7 @@ public void onPlayerChat(AsyncPlayerChatEvent event) {
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();
Expand All @@ -143,6 +117,9 @@ public void run() {
iter.remove();
}
}
if (recipients.size() == 0) {
event.setCancelled(true);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/**
* Exception thrown when a verification has failed.
*/
@SuppressWarnings("serial")
public class FailedVerificationException extends Exception {

private final MessageKey reason;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/fr/xephi/authme/output/MessageKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
public enum MessageKey {

DENIED_COMMAND("denied_command"),

SAME_IP_ONLINE("same_ip_online"),

DENIED_CHAT("denied_chat"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages/messages_en.yml
Original file line number Diff line number Diff line change
@@ -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.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ private static Player newPlayerWithName(String name) {
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.
Expand Down

0 comments on commit 52c0c7d

Please sign in to comment.