From 27af8253da413103edf1901f0d050d2a6ec4679a Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Mon, 29 Nov 2021 13:17:46 -0700 Subject: [PATCH] load vault hook after server load (#114) --- .../java/com/andrei1058/bedwars/BedWars.java | 50 +++++++++++-------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java index a420ba20d..4c4e94e2c 100644 --- a/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java +++ b/bedwars-plugin/src/main/java/com/andrei1058/bedwars/BedWars.java @@ -421,31 +421,37 @@ public void onEnable() { new PAPISupport().register(); SupportPAPI.setSupportPAPI(new SupportPAPI.withPAPI()); } - /* Vault support */ - if (this.getServer().getPluginManager().getPlugin("Vault") != null) { - try { - //noinspection rawtypes - RegisteredServiceProvider rsp = this.getServer().getServicesManager().getRegistration(net.milkbowl.vault.chat.Chat.class); - WithChat.setChat((net.milkbowl.vault.chat.Chat) rsp.getProvider()); - plugin.getLogger().info("Hook into vault chat support!"); - chat = new WithChat(); - } catch (Exception var2_2) { + /* + * Vault support + * The task is to initialize after all plugins have loaded, + * to make sure any economy/chat plugins have been loaded and registered. + */ + Bukkit.getScheduler().runTask(this, () -> { + if (this.getServer().getPluginManager().getPlugin("Vault") != null) { + try { + //noinspection rawtypes + RegisteredServiceProvider rsp = this.getServer().getServicesManager().getRegistration(net.milkbowl.vault.chat.Chat.class); + WithChat.setChat((net.milkbowl.vault.chat.Chat) rsp.getProvider()); + plugin.getLogger().info("Hook into vault chat support!"); + chat = new WithChat(); + } catch (Exception var2_2) { + chat = new NoChat(); + } + try { + //noinspection rawtypes + registerEvents(new MoneyListeners()); + RegisteredServiceProvider rsp = this.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); + WithEconomy.setEconomy((net.milkbowl.vault.economy.Economy) rsp.getProvider()); + plugin.getLogger().info("Hook into vault economy support!"); + economy = new WithEconomy(); + } catch (Exception var2_2) { + economy = new NoEconomy(); + } + } else { chat = new NoChat(); - } - try { - //noinspection rawtypes - registerEvents(new MoneyListeners()); - RegisteredServiceProvider rsp = this.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); - WithEconomy.setEconomy((net.milkbowl.vault.economy.Economy) rsp.getProvider()); - plugin.getLogger().info("Hook into vault economy support!"); - economy = new WithEconomy(); - } catch (Exception var2_2) { economy = new NoEconomy(); } - } else { - chat = new NoChat(); - economy = new NoEconomy(); - } + }); /* Chat support */ if (config.getBoolean("formatChat")) {