mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-01-24 15:51:23 +01:00
Use AccountQueryEvent in NameManager#canUseName utility method
This commit is contained in:
parent
8c83be59ba
commit
4673a3f00c
@ -11,6 +11,7 @@ public class AccountQueryEvent extends Event {
|
|||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private final String name;
|
private final String name;
|
||||||
private Account account = null;
|
private Account account = null;
|
||||||
|
private boolean searchOfflinePlayers = true;
|
||||||
|
|
||||||
public AccountQueryEvent(String name) {
|
public AccountQueryEvent(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -28,6 +29,22 @@ public class AccountQueryEvent extends Event {
|
|||||||
this.account = account;
|
this.account = account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get whether or not offline player data should be searched (too)
|
||||||
|
* @return Whether or not offline player data should be searched (too)
|
||||||
|
*/
|
||||||
|
public boolean searchOfflinePlayers() {
|
||||||
|
return searchOfflinePlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether or not offline player data should be searched (too)
|
||||||
|
* @param searchOfflinePlayers Whether or not offline player data should be searched (too)
|
||||||
|
*/
|
||||||
|
public void searchOfflinePlayers(boolean searchOfflinePlayers) {
|
||||||
|
this.searchOfflinePlayers = searchOfflinePlayers;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
|
@ -137,7 +137,7 @@ public class NameManager implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public static void onAccountQuery(AccountQueryEvent event) {
|
public static void onAccountQuery(AccountQueryEvent event) {
|
||||||
if (event.getAccount() == null) {
|
if (event.getAccount() == null) {
|
||||||
event.setAccount(getLastAccountFromShortName(event.getName()));
|
event.setAccount(getLastAccountFromShortName(event.getName(), event.searchOfflinePlayers()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,7 +201,19 @@ public class NameManager implements Listener {
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static Account getLastAccountFromShortName(String shortName) {
|
public static Account getLastAccountFromShortName(String shortName) {
|
||||||
Account account = getAccountFromShortName(shortName); // first get the account associated with the short name
|
return getLastAccountFromShortName(shortName, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the information from the last time a player logged in that previously used the shortened name
|
||||||
|
*
|
||||||
|
* @param shortName The name of the player to get the last account for
|
||||||
|
* @param searchOfflinePlayer Whether or not to search the offline players too
|
||||||
|
* @return The last account or <tt>null</tt> if none was found
|
||||||
|
* @throws IllegalArgumentException if the username is empty
|
||||||
|
*/
|
||||||
|
private static Account getLastAccountFromShortName(String shortName, boolean searchOfflinePlayer) {
|
||||||
|
Account account = getAccountFromShortName(shortName, searchOfflinePlayer); // first get the account associated with the short name
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
return getAccount(account.getUuid()); // then get the last account that was online with that UUID
|
return getAccount(account.getUuid()); // then get the last account that was online with that UUID
|
||||||
}
|
}
|
||||||
@ -363,7 +375,10 @@ public class NameManager implements Listener {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Account account = getAccountFromShortName(name, false);
|
AccountQueryEvent queryEvent = new AccountQueryEvent(name);
|
||||||
|
queryEvent.searchOfflinePlayers(false);
|
||||||
|
ChestShop.callEvent(queryEvent);
|
||||||
|
Account account = queryEvent.getAccount();
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user