package com.Acrobot.ChestShop.Listeners.PreShopCreation;

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;
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.UNKNOWN_PLAYER;

/**
 * @author Acrobot
 */
public class NameChecker implements Listener {

    @EventHandler(priority = EventPriority.LOWEST)
    public static void onPreShopCreation(PreShopCreationEvent event) {
        String name = event.getSignLine(NAME_LINE);
        Player player = event.getPlayer();

        if (name.isEmpty() || !NameManager.canUseName(player, OTHER_NAME_CREATE, name)) {
            Account account = NameManager.getOrCreateAccount(player);
            if (account != null) {
                event.setSignLine(NAME_LINE, account.getShortName());
            } else {
                event.setOutcome(UNKNOWN_PLAYER);
            }
        } else {
            AccountQueryEvent accountQueryEvent = new AccountQueryEvent(name);
            Bukkit.getPluginManager().callEvent(accountQueryEvent);
            Account account = accountQueryEvent.getAccount();
            if (account == null) {
                event.setOutcome(UNKNOWN_PLAYER);
            }
        }
    }
}

@@ -563,16 +563,123 @@
 E_LINE;%0A
+import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.SHOP_CREATED_SUCCESSFULLY;%0A
 import s
@@ -766,16 +766,16 @@
 PLAYER;%0A
-
 %0A/**%0A * 
@@ -1058,16 +1058,100 @@
 layer();
+%0A        event.setSignLine(NAME_LINE, %22%22);%0A        event.setOutcome(UNKNOWN_PLAYER);
 %0A%0A      
@@ -1413,29 +1413,8 @@
 ));%0A
-            %7D else %7B%0A
     
@@ -1438,38 +1438,49 @@
 .setOutcome(
-UNKNOWN_PLAYER
+SHOP_CREATED_SUCCESSFULLY
 );%0A         
@@ -1734,17 +1734,17 @@
 account 
-=
+!
 = null) 
@@ -1770,38 +1770,119 @@
 vent.set
-Outcome(UNKNOWN_PLAYER
+SignLine(NAME_LINE, account.getShortName());%0A                event.setOutcome(SHOP_CREATED_SUCCESSFULLY
 );%0A     

Set name line empty if name isn't usable and always use account name