Skip to content

Commit

Permalink
Some more UUIDCore options
Browse files Browse the repository at this point in the history
  • Loading branch information
RhysB committed Feb 27, 2020
1 parent 003ccf3 commit 04fbab0
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: AuthMe
author: whoami
description: AuthMe prevents people, which aren't logged in, from doing stuff like placing blocks, moving, typing commands or seeing the inventory of the current player.
main: uk.org.whoami.authme.AuthMe
version: 3.3
version: 3.4
softdepend: [EvolutionCore, UUIDCore]
commands:
register:
Expand Down
2 changes: 1 addition & 1 deletion src/uk/org/whoami/authme/AuthMe.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void onEnable() {
Priority.Lowest, this);

this.getCommand("authme").setExecutor(new AdminCommand(database));
this.getCommand("register").setExecutor(new RegisterCommand(database));
this.getCommand("register").setExecutor(new RegisterCommand(this, database));
this.getCommand("login").setExecutor(new LoginCommand(database));
this.getCommand("changepassword").setExecutor(new ChangePasswordCommand(database));
this.getCommand("logout").setExecutor(new LogoutCommand(this, database));
Expand Down
27 changes: 22 additions & 5 deletions src/uk/org/whoami/authme/commands/RegisterCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@

package uk.org.whoami.authme.commands;

import java.security.NoSuchAlgorithmException;
import java.util.Date;

import com.johnymuffin.uuidcore.UUIDAPI;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import uk.org.whoami.authme.AuthMe;
import uk.org.whoami.authme.ConsoleLogger;
import uk.org.whoami.authme.cache.auth.PlayerAuth;
import uk.org.whoami.authme.cache.auth.PlayerCache;
Expand All @@ -35,16 +33,22 @@
import uk.org.whoami.authme.settings.Messages;
import uk.org.whoami.authme.settings.Settings;

import java.security.NoSuchAlgorithmException;
import java.util.Date;
import java.util.UUID;

import static uk.org.whoami.authme.event.callLogin.callLogin;

public class RegisterCommand implements CommandExecutor {

private Messages m = Messages.getInstance();
private Settings settings = Settings.getInstance();
private DataSource database;
private AuthMe plugin;

public RegisterCommand(DataSource database) {
public RegisterCommand(AuthMe plugin, DataSource database) {
this.database = database;
this.plugin = plugin;
}

@Override
Expand All @@ -62,6 +66,19 @@ public boolean onCommand(CommandSender sender, Command cmnd, String label, Strin
String name = player.getName().toLowerCase();
String ip = player.getAddress().getAddress().getHostAddress();

if (plugin.isUUIDCoreEnabled()) {
UUID playerUUID = UUIDAPI.getUserUUID(name, false);
if (playerUUID == null) {
//See if player without a UUID can register
if (!Settings.getInstance().isAllowUUIDFailedToRegisterEnabled()) {
//No UUID is known for the player
player.sendMessage(m._("uuidFailedRegisterError"));
return true;
}
}
}


if (PlayerCache.getInstance().isAuthenticated(name)) {
player.sendMessage(m._("logged_in"));
return true;
Expand Down
11 changes: 7 additions & 4 deletions src/uk/org/whoami/authme/listener/AuthMeCustomListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,15 @@ public void onCustomEvent(Event event) {
Player player = ((AuthLoginEvent) event).getPlayer();
String ip = player.getAddress().getAddress().getHostAddress();
//If user isn't authenticated using beta evolutions
if (isClass("com.johnymuffin.beta.evolutioncore.EvolutionAPI") && !isUserAuthenticatedInCache(player.getName(), ip)) {
//Wait 3 seconds to ensure Beta Evolutions has responsed
if (plugin.isBetaEvolutionsEnabled()) {
//Wait 3 seconds to ensure Beta Evolutions has responded
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
if (player.isOnline()) {
player.sendMessage(Messages.getInstance()._("notifyUnauthenticated"));
if(!isUserAuthenticatedInCache(player.getName(), ip)) {
if (player.isOnline()) {
player.sendMessage(Messages.getInstance()._("notifyUnauthenticated"));
}
}


Expand Down Expand Up @@ -179,6 +181,7 @@ public void run() {

//If UUID Fails
if (!uuidStatus) {
ConsoleLogger.info("User \"" + ((PlayerUUIDEvent) event).getPlayer().getName() + "\" does not have a valid UUID");
if(Settings.getInstance().isKickOnFailedUUIDEnabled()) {
player.kickPlayer(Messages.getInstance()._("uuidFetchFailedKick"));
return;
Expand Down
5 changes: 3 additions & 2 deletions src/uk/org/whoami/authme/settings/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ private void loadDefaults() {
map.put("unauthenticatedKick", "Sorry, this server requires Beta Evolutions: bit.ly/BetaEVO");
map.put("notifyUnauthenticated", "&6This server supports Beta Evolutions, you can download it at &bbit.ly/BetaEVO");
map.put("notifyUnauthenticatedStaff", "&6Staff need to have Beta Evolutions, you can download it at &bbit.ly/BetaEVO");
map.put("uuidFetchFailedMessage", "&4We failed to find a UUID for your username, please ensure you own your current username.\n&4We do not support cracked users");
map.put("uuidFetchFailedKick", "&4Please ensure you own your current account, otherwise try again later.");
map.put("uuidFetchFailedMessage", "&4We failed to find a UUID for your username, please ensure you own your current username. We do not support cracked users");
map.put("uuidFailedRegisterError", "&5Sorry, a UUID for your username could not be found, Please register with a username you own. If this is an error please try again or reconnect");
map.put("uuidFetchFailedKick", "&4Please ensure you own your current username, otherwise please try to reconnect.");
}

private void loadFile() {
Expand Down
9 changes: 9 additions & 0 deletions src/uk/org/whoami/authme/settings/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ private void write() {
isUUIDCoreSupportModeEnabled();
isMessageOnFailedUUIDEnabled();
isKickOnFailedUUIDEnabled();
isAllowUUIDFailedToRegisterEnabled();
save();
}

Expand Down Expand Up @@ -394,6 +395,14 @@ public boolean isMessageOnFailedUUIDEnabled() {
return getBoolean(key, true);
}

public boolean isAllowUUIDFailedToRegisterEnabled() {
String key = "UUIDCore.allowFailedUUIDRegistration";
if (getString(key) == null) {
setProperty(key, false);
}
return getBoolean(key, false);
}




Expand Down

0 comments on commit 04fbab0

Please sign in to comment.