package com.Acrobot.ChestShop.Listeners.PreShopCreation;

import com.Acrobot.ChestShop.Configuration.Properties;
import com.Acrobot.ChestShop.Economy.Economy;
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Utils.uName;
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.Signs.ChestShopSign.NAME_LINE;

/**
 * @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();
        boolean isBank = name.startsWith(uName.BANK_PREFIX);
        boolean noAccess;
        boolean exists;
        if (isBank) {
            name = uName.stripBankPrefix(name);
            exists = Economy.bankExists(name);
            noAccess = !Economy.hasBankSupport() || !Permission.has(player, Permission.BANK);
            if (Properties.BANK_MEMBERS_ALLOWED) {
                noAccess = noAccess || !Economy.isBankMember(player.getName(), name);
            } else {
                noAccess = noAccess || !Economy.isBankOwner(player.getName(), name);
            }
        } else {
            noAccess = !uName.canUseName(player, name);
            exists = Economy.hasAccount(name);
        }

        if (name.isEmpty() || !exists || (noAccess && !Permission.has(player, Permission.ADMIN))) {
            String shortName = uName.shortenName(player);
            event.setSignLine(NAME_LINE, shortName);
        }
    }
}

@@ -802,33 +802,21 @@
 ();%0A
- 
+%0A
        
-boolean isBank = 
+ if (
 name
@@ -849,78 +849,8 @@
 FIX)
-;%0A        boolean noAccess;%0A        boolean exists;%0A        if (isBank
 ) %7B%0A
@@ -901,33 +901,45 @@
 e);%0A            
-e
+boolean bankE
 xists = Economy.
@@ -960,34 +960,43 @@
 e);%0A            
-no
+boolean has
 Access = !Econom
@@ -988,17 +988,16 @@
 ccess = 
-!
 Economy.
@@ -1013,20 +1013,19 @@
 pport() 
-%7C%7C !
+&& 
 Permissi
@@ -1057,16 +1057,17 @@
 .BANK);%0A
+%0A
         
@@ -1117,34 +1117,35 @@
                 
-no
+has
 Access = noAcces
@@ -1133,37 +1133,37 @@
 hasAccess = 
-no
+has
 Access 
-%7C%7C !
+&& 
 Economy.isBa
@@ -1225,34 +1225,35 @@
                 
-no
+has
 Access = noAcces
@@ -1249,21 +1249,21 @@
 s = 
-no
+has
 Access 
-%7C%7C !
+&& 
 Econ
@@ -1317,24 +1317,25 @@
       %7D%0A
+%0A
         
 %7D else %7B
@@ -1330,53 +1330,148 @@
     
-%7D else %7B%0A            noAccess = !uName.canUse
+    if (!bankExists %7C%7C (!hasAccess && !Permission.has(player, Permission.ADMIN))) %7B%0A                event.setSignLine(NAME_LINE, uName.strip
 Name
@@ -1477,22 +1477,17 @@
 e(player
-, name
+)
 );%0A     
@@ -1497,41 +1497,29 @@
     
-exists = Economy.hasAccount(name)
+%7D%0A%0A            return
 ;%0A  
@@ -1561,28 +1561,40 @@
  %7C%7C 
-!exists %7C%7C (noAccess
+(!uName.canUseName(player, name)
  && 
@@ -1681,14 +1681,12 @@
 me.s
-horten
+trip
 Name

Fix the name checker!