Try to create an account when creating shop for other players

This commit is contained in:
Phoenix616 2021-04-18 18:24:22 +01:00
parent 4172d8d484
commit 07a22fa534
No known key found for this signature in database
GPG Key ID: 40E2321E71738EB0
1 changed files with 14 additions and 2 deletions

View File

@ -1,10 +1,10 @@
package com.Acrobot.ChestShop.Listeners.PreShopCreation;
import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Database.Account;
import com.Acrobot.ChestShop.Events.AccountQueryEvent;
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -41,8 +41,20 @@ public class NameChecker implements Listener {
account = NameManager.getOrCreateAccount(player);
} else {
AccountQueryEvent accountQueryEvent = new AccountQueryEvent(name);
Bukkit.getPluginManager().callEvent(accountQueryEvent);
ChestShop.callEvent(accountQueryEvent);
account = accountQueryEvent.getAccount();
if (account == null) {
Player otherPlayer = ChestShop.getBukkitServer().getPlayer(name);
try {
if (otherPlayer != null) {
account = NameManager.getOrCreateAccount(otherPlayer);
} else {
account = NameManager.getOrCreateAccount(ChestShop.getBukkitServer().getOfflinePlayer(name));
}
} catch (IllegalArgumentException e) {
event.getPlayer().sendMessage(e.getMessage());
}
}
}
} catch (Exception e) {
e.printStackTrace();