Search in sources :

Example 1 with CitizensTraitFactory

use of net.citizensnpcs.npc.CitizensTraitFactory in project Citizens2 by CitizensDev.

the class Citizens method onEnable.

@Override
public void onEnable() {
    setupTranslator();
    CitizensAPI.setImplementation(this);
    config = new Settings(getDataFolder());
    // Disable if the server is not using the compatible Minecraft version
    String mcVersion = Util.getMinecraftRevision();
    compatible = true;
    try {
        NMS.loadBridge(mcVersion);
    } catch (Exception e) {
        compatible = false;
        if (Messaging.isDebugging()) {
            e.printStackTrace();
        }
        Messaging.severeTr(Messages.CITIZENS_INCOMPATIBLE, getDescription().getVersion(), mcVersion);
        getServer().getPluginManager().disablePlugin(this);
        return;
    }
    registerScriptHelpers();
    saves = createStorage(getDataFolder());
    if (saves == null) {
        Messaging.severeTr(Messages.FAILED_LOAD_SAVES);
        getServer().getPluginManager().disablePlugin(this);
        return;
    }
    npcRegistry = new CitizensNPCRegistry(saves);
    traitFactory = new CitizensTraitFactory();
    selector = new NPCSelector(this);
    speechFactory = new CitizensSpeechFactory();
    speechFactory.register(Chat.class, "chat");
    getServer().getPluginManager().registerEvents(new EventListen(storedRegistries), this);
    if (Setting.NPC_COST.asDouble() > 0) {
        setupEconomy();
    }
    registerCommands();
    enableSubPlugins();
    NMS.load(commands);
    // support and for NPCs to properly register external settings)
    if (getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {

        @Override
        public void run() {
            saves.loadInto(npcRegistry);
            Messaging.logTr(Messages.NUM_LOADED_NOTIFICATION, Iterables.size(npcRegistry), "?");
            startMetrics();
            scheduleSaveTask(Setting.SAVE_TASK_DELAY.asInt());
            Bukkit.getPluginManager().callEvent(new CitizensEnableEvent());
            if (!Util.getMinecraftRevision().equals("1_8_R3")) {
                new PlayerUpdateTask().runTaskTimer(Citizens.this, 0, 1);
            }
        }
    }, 1) == -1) {
        Messaging.severeTr(Messages.LOAD_TASK_NOT_SCHEDULED);
        getServer().getPluginManager().disablePlugin(this);
    }
}
Also used : CitizensTraitFactory(net.citizensnpcs.npc.CitizensTraitFactory) CitizensSpeechFactory(net.citizensnpcs.npc.ai.speech.CitizensSpeechFactory) CitizensNPCRegistry(net.citizensnpcs.npc.CitizensNPCRegistry) PlayerUpdateTask(net.citizensnpcs.util.PlayerUpdateTask) NPCSelector(net.citizensnpcs.npc.NPCSelector) CitizensEnableEvent(net.citizensnpcs.api.event.CitizensEnableEvent) NPCLoadException(net.citizensnpcs.api.exception.NPCLoadException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 CitizensEnableEvent (net.citizensnpcs.api.event.CitizensEnableEvent)1 NPCLoadException (net.citizensnpcs.api.exception.NPCLoadException)1 CitizensNPCRegistry (net.citizensnpcs.npc.CitizensNPCRegistry)1 CitizensTraitFactory (net.citizensnpcs.npc.CitizensTraitFactory)1 NPCSelector (net.citizensnpcs.npc.NPCSelector)1 CitizensSpeechFactory (net.citizensnpcs.npc.ai.speech.CitizensSpeechFactory)1 PlayerUpdateTask (net.citizensnpcs.util.PlayerUpdateTask)1