diff --git a/README.md b/README.md
index b624dbb..64d1530 100644
--- a/README.md
+++ b/README.md
@@ -33,6 +33,7 @@ whitelist takes their IGN and their current UUID and adds them to the whitelist.
That's fully expected. But when the player is *NOT* online, then whitelist checks
Mojang database to find that player in list of registered Minecraft players.
If that player cannot be found, whitelist refuses to add that player to whitelist.
+If that player *IS* found in Mojang's database, then their online UUID is pulled.
That is no issue on online mode servers as this is fully expected and there's no
need to check if the player online does indeed exist or not, because otherwise server
diff --git a/pom.xml b/pom.xml
index e2c93be..05fce53 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.polda18
BetterWhitelist
- 1.0
+ 1.0.1
jar
BetterWhitelist
diff --git a/src/main/java/me/polda18/betterwhitelist/events/EventsListener.java b/src/main/java/me/polda18/betterwhitelist/events/EventsListener.java
index 4b37a69..7bcb319 100644
--- a/src/main/java/me/polda18/betterwhitelist/events/EventsListener.java
+++ b/src/main/java/me/polda18/betterwhitelist/events/EventsListener.java
@@ -6,10 +6,9 @@
import me.polda18.betterwhitelist.utils.OnlineUUIDException;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
-import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
-import org.bukkit.event.player.PlayerJoinEvent;
+import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import java.io.IOException;
import java.util.Objects;
@@ -17,7 +16,7 @@
import java.util.logging.Level;
/**
- * Core function of this plugin - event listener for player joining the game
+ * Core function of this plugin - event listener for player connecting
*/
public class EventsListener implements Listener {
private BetterWhitelist plugin;
@@ -39,7 +38,7 @@ public EventsListener(BetterWhitelist plugin) {
* @throws InvalidEntryException Fired when specified old player wasn't found in the whitelist (online mode update, failsafe mechanism)
*/
@EventHandler
- public void onPlayerJoin(PlayerJoinEvent event) throws IOException, AlreadyInWhitelistException, OnlineUUIDException, InvalidEntryException {
+ public void onPlayerConnect(AsyncPlayerPreLoginEvent event) throws IOException, AlreadyInWhitelistException, OnlineUUIDException, InvalidEntryException {
// Check if the server runs in an online mode or not
boolean online_mode = Bukkit.getOnlineMode();
@@ -49,18 +48,19 @@ public void onPlayerJoin(PlayerJoinEvent event) throws IOException, AlreadyInWhi
}
// Get the player and his UUID
- Player player = event.getPlayer();
- String uuid = plugin.getWhitelist().getConfig()
- .getString(player.getName() + ((online_mode) ? ".online_uuid" : ".offline_uuid"));
+ UUID uuid_joined = event.getUniqueId();
+ String player = event.getName();
+ String uuid_whitelisted = plugin.getWhitelist().getConfig()
+ .getString(player + ((online_mode) ? ".online_uuid" : ".offline_uuid"));
// Check other players if not found in online mode
- if(uuid == null && online_mode) {
+ if(!uuid_joined.toString().equals(uuid_whitelisted) && online_mode) {
boolean uuid_match = false;
String old_player_name = "";
for(String entry : plugin.getWhitelist().getConfig().getKeys(false)) {
- uuid = plugin.getWhitelist().getConfig().getString(entry + ".online_uuid");
- assert uuid != null;
- uuid_match = (player.getUniqueId().compareTo(UUID.fromString(uuid)) == 0);
+ uuid_whitelisted = plugin.getWhitelist().getConfig().getString(entry + ".online_uuid");
+ assert uuid_whitelisted != null;
+ uuid_match = (uuid_joined.compareTo(UUID.fromString(uuid_whitelisted)) == 0);
if(uuid_match) {
old_player_name = entry;
@@ -70,21 +70,22 @@ public void onPlayerJoin(PlayerJoinEvent event) throws IOException, AlreadyInWhi
// If match is found, update entries and announce name change to the console.
if(uuid_match) {
- plugin.getWhitelist().addEntry(player.getName());
+ plugin.getWhitelist().addEntry(player);
plugin.getWhitelist().deleteEntry(old_player_name);
plugin.getLogger().log(Level.INFO, ChatColor.translateAlternateColorCodes('&',
Objects.requireNonNull(plugin.getLanguage().getConfig()
.getString("messages.online_player_update"))
.replace("(old_player)", old_player_name)
- .replace("(new_player)", player.getName())));
+ .replace("(new_player)", player)));
}
}
// Kick the player if the name/UUID is not found in the whitelist or there's a mismatch
- if(uuid == null || player.getUniqueId().compareTo(UUID.fromString(uuid)) != 0) {
- player.kickPlayer(ChatColor.translateAlternateColorCodes('&',
- Objects.requireNonNull(plugin.getLanguage().getConfig().getString("messages.kick"))));
+ if(uuid_whitelisted == null || uuid_joined.compareTo(UUID.fromString(uuid_whitelisted)) != 0) {
+ event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_WHITELIST,
+ ChatColor.translateAlternateColorCodes('&',
+ Objects.requireNonNull(plugin.getLanguage().getConfig().getString("messages.kick"))));
}
}
}