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.SHOP_CREATED_SUCCESSFULLY;
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();
        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);
            }
        } 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);
            }
        }
    }
}

@@ -567,115 +567,8 @@
 NE;%0A
-import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.SHOP_CREATED_SUCCESSFULLY;%0A
 impo
@@ -952,24 +952,25 @@
 ayer();%0A
+%0A
         
 event.se
@@ -965,85 +965,50 @@
     
-event.setSignLine(NAME_LINE, %22%22);%0A        event.setOutcome(UNKNOWN_PLAYER);%0A%0A
+Account account = null;%0A        try %7B%0A    
     
@@ -1097,39 +1097,35 @@
 ) %7B%0A            
+ 
-Account
+  
  account = NameM
@@ -1175,184 +1175,8 @@
     
-if (account != null) %7B%0A                event.setSignLine(NAME_LINE, account.getShortName());%0A                event.setOutcome(SHOP_CREATED_SUCCESSFULLY);%0A            %7D%0A        
 %7D el
@@ -1180,16 +1180,20 @@
  else %7B%0A
+    
         
@@ -1263,16 +1263,20 @@
 (name);%0A
+    
         
@@ -1339,39 +1339,35 @@
 t);%0A            
-Account
+   
  account = accou
@@ -1393,24 +1393,109 @@
 ount();%0A    
+        %7D%0A        %7D catch (Exception e) %7B%0A            e.printStackTrace();%0A        %7D%0A
         if (
@@ -1509,28 +1509,24 @@
  != null) %7B%0A
-    
             
@@ -1579,24 +1579,37 @@
 ame());%0A    
+    %7D else %7B%0A
             
@@ -1621,57 +1621,78 @@
 .set
-Outcome(SHOP_CREATED_SUCCESSFULLY);%0A            %7D
+SignLine(NAME_LINE, %22%22);%0A            event.setOutcome(UNKNOWN_PLAYER);
 %0A   

Fix shops creation message getting send on auto fill