Fix shops creation message getting send on auto fill

The NameChecker now catches any exception that might be thrown when querying the account in order to properly cancel in the case of an unknown account or an error that occurred in the event to not let players create shops that they don't have access to if an exception occurs.
This commit is contained in:
Phoenix616 2019-05-08 00:22:16 +01:00
parent 2907706399
commit 17e7ab781b
1 changed files with 15 additions and 15 deletions

View File

@ -12,7 +12,6 @@ import org.bukkit.event.Listener;
import static com.Acrobot.ChestShop.Permission.OTHER_NAME_CREATE;
import static com.Acrobot.ChestShop.Signs.ChestShopSign.NAME_LINE;
import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.SHOP_CREATED_SUCCESSFULLY;
import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.UNKNOWN_PLAYER;
/**
@ -24,23 +23,24 @@ public class NameChecker implements Listener {
public static void onPreShopCreation(PreShopCreationEvent event) {
String name = event.getSignLine(NAME_LINE);
Player player = event.getPlayer();
event.setSignLine(NAME_LINE, "");
event.setOutcome(UNKNOWN_PLAYER);
if (name.isEmpty() || !NameManager.canUseName(player, OTHER_NAME_CREATE, name)) {
Account account = NameManager.getOrCreateAccount(player);
if (account != null) {
event.setSignLine(NAME_LINE, account.getShortName());
event.setOutcome(SHOP_CREATED_SUCCESSFULLY);
Account account = null;
try {
if (name.isEmpty() || !NameManager.canUseName(player, OTHER_NAME_CREATE, name)) {
account = NameManager.getOrCreateAccount(player);
} else {
AccountQueryEvent accountQueryEvent = new AccountQueryEvent(name);
Bukkit.getPluginManager().callEvent(accountQueryEvent);
account = accountQueryEvent.getAccount();
}
} catch (Exception e) {
e.printStackTrace();
}
if (account != null) {
event.setSignLine(NAME_LINE, account.getShortName());
} else {
AccountQueryEvent accountQueryEvent = new AccountQueryEvent(name);
Bukkit.getPluginManager().callEvent(accountQueryEvent);
Account account = accountQueryEvent.getAccount();
if (account != null) {
event.setSignLine(NAME_LINE, account.getShortName());
event.setOutcome(SHOP_CREATED_SUCCESSFULLY);
}
event.setSignLine(NAME_LINE, "");
event.setOutcome(UNKNOWN_PLAYER);
}
}
}