Delay objective event registration to hopefully prevent random failures.

This commit is contained in:
Nathan Wolf 2015-11-12 10:12:36 -08:00
parent 1afeff873c
commit c847fd0c37

View File

@ -57,6 +57,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
@ -665,24 +666,29 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
Class<? extends CustomObjective> objectiveClass = c.asSubclass(CustomObjective.class); Class<? extends CustomObjective> objectiveClass = c.asSubclass(CustomObjective.class);
Constructor<? extends CustomObjective> cstrctr = objectiveClass.getConstructor(); Constructor<? extends CustomObjective> cstrctr = objectiveClass.getConstructor();
CustomObjective objective = cstrctr.newInstance(); final CustomObjective objective = cstrctr.newInstance();
customObjectives.add(objective); customObjectives.add(objective);
String name = objective.getName() == null ? "[" + jar.getName() + "]" : objective.getName(); final String name = objective.getName() == null ? "[" + jar.getName() + "]" : objective.getName();
String author = objective.getAuthor() == null ? "[Unknown]" : objective.getAuthor(); String author = objective.getAuthor() == null ? "[Unknown]" : objective.getAuthor();
count++; count++;
getLogger().info("Loaded Module: " + name + " by " + author); getLogger().info("Loaded Module: " + name + " by " + author);
final Plugin plugin = this;
try { getServer().getScheduler().runTaskLater(this, new Runnable() {
getServer().getPluginManager().registerEvents(objective, this); @Override
getLogger().info("Registered events for custom objective \"" + name + "\""); public void run() {
} catch (Exception ex) { try {
getLogger().warning("Failed to register events for custom objective \"" + name + "\". Does the objective class listen for events?"); getServer().getPluginManager().registerEvents(objective, plugin);
if (debug) { getLogger().info("Registered events for custom objective \"" + name + "\"");
getLogger().warning("Error log:"); } catch (Exception ex) {
ex.printStackTrace(); getLogger().warning("Failed to register events for custom objective \"" + name + "\". Does the objective class listen for events?");
if (debug) {
getLogger().warning("Error log:");
ex.printStackTrace();
}
}
} }
} }, 20);
} }
} }