package com.starquestminecraft.bukkit;

import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.server.ServiceRegisterEvent;
import org.bukkit.event.server.ServiceUnregisterEvent;
import org.bukkit.plugin.java.JavaPlugin;

import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;

public class SQBase extends JavaPlugin {

    private static SQBase instance;

    public static SQBase getInstance() {
        return instance;
    }

    @Override
    public void onLoad() {

        instance = this;

        saveDefaultConfig();

        StarQuest.initialize(this);

    }

    @Override
    public void onEnable() {

        StarQuest.setupVault(this);

    }

    @EventHandler(priority = EventPriority.MONITOR)
    void onServiceRegister(final ServiceRegisterEvent event) {

        Class<?> service = event.getProvider().getService();

        if(service.equals(Chat.class) || service.equals(Economy.class) || service.equals(Permission.class)) {
            StarQuest.setupVault(this);
        }

    }

    @EventHandler(priority = EventPriority.MONITOR)
    void onServiceRegister(final ServiceUnregisterEvent event) {

        Class<?> service = event.getProvider().getService();

        if(service.equals(Chat.class) || service.equals(Economy.class) || service.equals(Permission.class)) {
            StarQuest.setupVault(this);
        }

    }

}

@@ -897,35 +897,32 @@
         
-Class%3C?%3E service = 
+onServiceChange(
 event.ge
@@ -949,170 +949,10 @@
 ce()
+)
 ;
-%0A%0A        if(service.equals(Chat.class) %7C%7C service.equals(Economy.class) %7C%7C service.equals(Permission.class)) %7B%0A            StarQuest.setupVault(this);%0A        %7D
 %0A%0A  
@@ -1086,27 +1086,24 @@
     
-Class%3C?%3E service = 
+onServiceChange(
 even
@@ -1134,85 +1134,296 @@
 ce()
+)
 ;%0A%0A    
-    if(service.equals(Chat.class) %7C%7C service.equals(Economy.class) %7C%7C 
+%7D%0A%0A    private void onServiceChange(final Class%3C?%3E service) %7B%0A%0A        if(service.equals(Chat.class)) %7B%0A            StarQuest.setupVaultChat(this);%0A        %7D%0A        else if(service.equals(Economy.class)) %7B%0A            StarQuest.setupVaultEconomy(this);%0A        %7D%0A        else if(
 serv
@@ -1478,32 +1478,42 @@
 Quest.setupVault
+Permission
 (this);%0A        

Update only the changed Vault service