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.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
@ -665,15 +666,19 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
Class<? extends CustomObjective> objectiveClass = c.asSubclass(CustomObjective.class);
Constructor<? extends CustomObjective> cstrctr = objectiveClass.getConstructor();
CustomObjective objective = cstrctr.newInstance();
final CustomObjective objective = cstrctr.newInstance();
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();
count++;
getLogger().info("Loaded Module: " + name + " by " + author);
final Plugin plugin = this;
getServer().getScheduler().runTaskLater(this, new Runnable() {
@Override
public void run() {
try {
getServer().getPluginManager().registerEvents(objective, this);
getServer().getPluginManager().registerEvents(objective, plugin);
getLogger().info("Registered events for custom objective \"" + name + "\"");
} catch (Exception ex) {
getLogger().warning("Failed to register events for custom objective \"" + name + "\". Does the objective class listen for events?");
@ -682,7 +687,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
ex.printStackTrace();
}
}
}
}, 20);
}
}