11package codes .biscuit .sellchest .hooks ;
22
33import codes .biscuit .sellchest .SellChest ;
4- import com .sun .org .apache .regexp .internal .RE ;
54import net .milkbowl .vault .economy .Economy ;
5+ import org .bukkit .Bukkit ;
66import org .bukkit .Location ;
77import org .bukkit .OfflinePlayer ;
8- import org .bukkit .entity .Minecart ;
98import org .bukkit .entity .Player ;
109import org .bukkit .event .player .PlayerInteractEvent ;
1110import org .bukkit .inventory .ItemStack ;
1211import org .bukkit .plugin .PluginManager ;
12+ import org .bukkit .plugin .RegisteredServiceProvider ;
1313
1414import java .util .HashMap ;
1515import java .util .Map ;
1616
17+ import static org .bukkit .Bukkit .getServer ;
18+
1719public class HookUtils {
1820
1921 private SellChest main ;
@@ -23,7 +25,11 @@ public class HookUtils {
2325
2426 public HookUtils (SellChest main ) {
2527 this .main = main ;
26- economy = main .getServer ().getServicesManager ().getRegistration (Economy .class ).getProvider ();
28+ boolean foundEconomy = setupEconomy ();
29+ if (!foundEconomy ) {
30+ main .getLogger ().severe ("Didn't get the economy registration!" );
31+ main .getPluginLoader ().disablePlugin (main );
32+ }
2733 PluginManager pm = main .getServer ().getPluginManager ();
2834 if (pm .getPlugin ("MassiveCore" ) != null &&
2935 pm .getPlugin ("Factions" ) != null ) {
@@ -58,6 +64,19 @@ public HookUtils(SellChest main) {
5864 }
5965 }
6066
67+ private boolean setupEconomy () {
68+ if (Bukkit .getPluginManager ().getPlugin ("Vault" ) == null ) {
69+ return false ;
70+ }
71+
72+ RegisteredServiceProvider <Economy > rsp = getServer ().getServicesManager ().getRegistration (Economy .class );
73+ if (rsp == null ) {
74+ return false ;
75+ }
76+ economy = rsp .getProvider ();
77+ return economy != null ;
78+ }
79+
6180 public double getValue (ItemStack sellItem , Player p ) {
6281 if (main .getConfigValues ().essentialsHookEnabled () && enabledHooks .containsKey (Hooks .ESSENTIALS )) {
6382 return ((EssentialsHook ) enabledHooks .get (Hooks .ESSENTIALS )).getSellPrice (sellItem );
0 commit comments