Search in sources :

Example 1 with EntityMoveListener

use of mc.dragons.core.events.EntityMoveListener in project DragonsOnline by UniverseCraft.

the class Dragons method onEnable.

@Override
public void onEnable() {
    BukkitUtil.initRollingSync();
    playerNPCRegistry = new PlayerNPCRegistry(this);
    // Game objects must be loaded from database in a particular sequence, to ensure
    // all dependencies are ready.
    // For example, items cannot be loaded before their item classes have been loaded,
    // and regions cannot be loaded before their associated floors have been loaded.
    getLogger().info("Loading game objects...");
    GameObjectType.getLoader(FloorLoader.class).lazyLoadAll();
    GameObjectType.getLoader(RegionLoader.class).lazyLoadAll();
    GameObjectType.getLoader(ItemClassLoader.class).lazyLoadAll();
    GameObjectType.getLoader(NPCClassLoader.class).lazyLoadAll();
    GameObjectType.getLoader(QuestLoader.class).lazyLoadAll();
    // If the server did not shut down gracefully (and sometimes if it did) there may be
    // entities remaining from the previous instance which are no longer linked to a
    // live game object. These entities need to be purged as they will not be responsive
    // to new game events.
    getLogger().info("Removing stale entities...");
    boolean hasFixed = false;
    for (Entity e : getEntities()) {
        if (e.getPersistentDataContainer().has(FIXED_ENTITY_KEY, PersistentDataType.SHORT)) {
            getLogger().verbose("-Skipping fixed entity #" + e.getEntityId());
            hasFixed = true;
            continue;
        }
        if (e instanceof ItemFrame) {
            getLogger().verbose("-Skipping item frame #" + e.getEntityId());
            continue;
        }
        e.remove();
    }
    if (hasFixed) {
        getLogger().notice("The use of fixed entities is not automatically synced across servers the same way that persistent NPCs are.\n" + "Instead, the appropriate world files must be copied.");
    }
    new BukkitRunnable() {

        @Override
        public void run() {
            GameObjectType.getLoader(NPCLoader.class).lazyLoadAllPermanent();
            getLogger().info("Flushing invalid game objects from initial load...");
            new BukkitRunnable() {

                int i = 1;

                @Override
                public void run() {
                    verifyGameIntegrityRunnable.run(true);
                    i++;
                    if (i >= 5) {
                        cancel();
                        getLogger().info("... flush complete. Entity count: " + getEntities().size());
                        joinable = true;
                        getLogger().info("Server is now joinable");
                    }
                }
            }.runTaskTimer(Dragons.this, 20L, 20L);
        }
    }.runTaskLater(this, 20L);
    getLogger().info("Registering lightweight object loaders...");
    lightweightLoaderRegistry.register(new ChangeLogLoader(mongoConfig));
    lightweightLoaderRegistry.register(new FeedbackLoader(mongoConfig));
    lightweightLoaderRegistry.register(new WarpLoader(mongoConfig));
    lightweightLoaderRegistry.register(new CorrelationLogger(mongoConfig));
    lightweightLoaderRegistry.register(new SystemProfileLoader(this));
    lightweightLoaderRegistry.register(new GlobalVarLoader(mongoConfig));
    lightweightLoaderRegistry.register(new StateLoader(mongoConfig));
    UserLoader.lazyLoadGlobalVarLoader();
    getLogger().info("Registering events...");
    PluginManager pluginManager = getServer().getPluginManager();
    pluginManager.registerEvents(new EntityDeathListener(this), this);
    pluginManager.registerEvents(new EntityDamageListener(this), this);
    pluginManager.registerEvents(new WorldEventListeners(this), this);
    pluginManager.registerEvents(new EntityTargetEventListener(this), this);
    pluginManager.registerEvents(new InventoryEventListeners(), this);
    pluginManager.registerEvents(new PlayerEventListeners(this), this);
    pluginManager.registerEvents(new EntityCombustListener(), this);
    pluginManager.registerEvents(new SlimeSplitEventListener(this), this);
    getLogger().info("Registering packet listeners...");
    if (verifyProtocolLib()) {
        ProtocolLibrary.getProtocolManager().addPacketListener(new EntityMoveListener(this));
        entityHider = new EntityHider(this, EntityHider.Policy.BLACKLIST);
    }
    getLogger().info("Registering commands...");
    getCommand("dragons").setExecutor(new DragonsCommand());
    getCommand("rank").setExecutor(new RankCommand());
    getCommand("autorank").setExecutor(new AutoRankCommand());
    getCommand("syslogon").setExecutor(new SystemLogonCommand());
    getCommand("respawn").setExecutor(new RespawnCommand());
    getCommand("heal").setExecutor(new HealCommand());
    getCommand("feedback").setExecutor(new FeedbackCommand());
    getCommand("myquests").setExecutor(new MyQuestsCommand());
    getCommand("help").setExecutor(new HelpCommand());
    getCommand("stuckquest").setExecutor(new StuckQuestCommand());
    getCommand("restartinstance").setExecutor(new RestartInstanceCommand());
    getCommand("logout").setExecutor(new LogoutCommand());
    CommandExecutor stateCommands = new StateCommands();
    getCommand("getstate").setExecutor(stateCommands);
    getCommand("setstate").setExecutor(stateCommands);
    QuestDialogueCommands questDialogueCommands = new QuestDialogueCommands();
    getCommand("fastforwarddialogue").setExecutor(questDialogueCommands);
    getCommand("questchoice").setExecutor(questDialogueCommands);
    ChangeLogCommands changeLogCommandsExecutor = new ChangeLogCommands();
    getCommand("news").setExecutor(changeLogCommandsExecutor);
    getCommand("newsmanager").setExecutor(changeLogCommandsExecutor);
    CommandExecutor chatCommands = new ChatOptionsCommand();
    getCommand("chatoptions").setExecutor(chatCommands);
    getCommand("chatreply").setExecutor(chatCommands);
    getLogger().info("Scheduling tasks...");
    autoSaveRunnable.runTaskTimer(this, 0L, serverOptions.getAutoSavePeriodTicks());
    spawnEntityRunnable.runTaskTimer(this, 0L, serverOptions.getCustomSpawnRate());
    verifyGameIntegrityRunnable.runTaskTimer(this, 0L, serverOptions.getVerifyIntegritySweepRate());
    lagMeter.runTaskTimer(this, 100L, 1L);
    lagMonitorTask.runTaskAsynchronously(this);
    updateScoreboardTask.runTaskTimer(this, 100L, 20L);
    BukkitUtil.syncPeriodic(() -> Bukkit.getOnlinePlayers().stream().map(p -> UserLoader.fromPlayer(p)).forEach(u -> u.updateTablistHeaders()), 20 * 10, 20 * 5);
    getLogger().info("Registering message handlers...");
    internalMessageHandler = new InternalMessageHandler(this);
    remoteAdminHandler = new RemoteAdminMessageHandler(this);
    staffAlertHandler = new StaffAlertMessageHandler(this);
    getLogger().info("Enabling addons...");
    addonRegistry.enableAll();
}
Also used : Plugin(org.bukkit.plugin.Plugin) NPCLoader(mc.dragons.core.gameobject.npc.NPCLoader) UserHookRegistry(mc.dragons.core.gameobject.user.UserHookRegistry) CorrelationLogger(mc.dragons.core.logging.correlation.CorrelationLogger) SystemProfileLoader(mc.dragons.core.gameobject.user.permission.SystemProfileLoader) PermissionUtil(mc.dragons.core.util.PermissionUtil) SidebarManager(mc.dragons.core.gameobject.user.SidebarManager) UpdateScoreboardTask(mc.dragons.core.tasks.UpdateScoreboardTask) Bridge(mc.dragons.core.bridge.Bridge) User(mc.dragons.core.gameobject.user.User) DragonsCommand(mc.dragons.core.commands.DragonsCommand) NPCClassLoader(mc.dragons.core.gameobject.npc.NPCClassLoader) PlayerNPCRegistry(mc.dragons.core.gameobject.npc.PlayerNPCRegistry) StaffAlertMessageHandler(mc.dragons.core.networking.StaffAlertMessageHandler) MessageDispatcher(mc.dragons.core.networking.MessageDispatcher) WarpLoader(mc.dragons.core.storage.loader.WarpLoader) LagMonitorTask(mc.dragons.core.tasks.LagMonitorTask) InternalMessageHandler(mc.dragons.core.networking.InternalMessageHandler) PermissionLevel(mc.dragons.core.gameobject.user.permission.PermissionLevel) ItemFrame(org.bukkit.entity.ItemFrame) ObjectUtil(mc.dragons.core.util.ObjectUtil) World(org.bukkit.World) GlobalVarLoader(mc.dragons.core.storage.loader.GlobalVarLoader) Chunk(org.bukkit.Chunk) QuestDialogueCommands(mc.dragons.core.commands.QuestDialogueCommands) AutoRankCommand(mc.dragons.core.commands.AutoRankCommand) EntityMoveListener(mc.dragons.core.events.EntityMoveListener) Bukkit(org.bukkit.Bukkit) StuckQuestCommand(mc.dragons.core.commands.StuckQuestCommand) QuestLoader(mc.dragons.core.gameobject.quest.QuestLoader) ChangeLogCommands(mc.dragons.core.commands.ChangeLogCommands) MyQuestsCommand(mc.dragons.core.commands.MyQuestsCommand) UserLoader(mc.dragons.core.gameobject.user.UserLoader) Entity(org.bukkit.entity.Entity) FloorLoader(mc.dragons.core.gameobject.floor.FloorLoader) SystemLogonCommand(mc.dragons.core.commands.SystemLogonCommand) EntityHider(mc.dragons.core.util.EntityHider) UUID(java.util.UUID) EntityCombustListener(mc.dragons.core.events.EntityCombustListener) ItemClassLoader(mc.dragons.core.gameobject.item.ItemClassLoader) FeedbackLoader(mc.dragons.core.storage.loader.FeedbackLoader) LightweightLoaderRegistry(mc.dragons.core.storage.loader.LightweightLoaderRegistry) List(java.util.List) LogoutCommand(mc.dragons.core.commands.LogoutCommand) ChatMessageRegistry(mc.dragons.core.gameobject.user.chat.ChatMessageRegistry) RankCommand(mc.dragons.core.commands.RankCommand) StorageManager(mc.dragons.core.storage.StorageManager) LagMeter(mc.dragons.core.tasks.LagMeter) SingletonReInstantiationException(mc.dragons.core.util.singletons.SingletonReInstantiationException) ChatOptionsCommand(mc.dragons.core.commands.ChatOptionsCommand) RestartInstanceCommand(mc.dragons.core.commands.RestartInstanceCommand) ProtocolManager(com.comphenix.protocol.ProtocolManager) PersistentDataType(org.bukkit.persistence.PersistentDataType) MongoStorageManager(mc.dragons.core.storage.mongo.MongoStorageManager) AutoSaveTask(mc.dragons.core.tasks.AutoSaveTask) MongoConfig(mc.dragons.core.storage.mongo.MongoConfig) ProtocolLibrary(com.comphenix.protocol.ProtocolLibrary) AddonRegistry(mc.dragons.core.addon.AddonRegistry) HelpCommand(mc.dragons.core.commands.HelpCommand) StateCommands(mc.dragons.core.commands.StateCommands) FeedbackCommand(mc.dragons.core.commands.FeedbackCommand) StateLoader(mc.dragons.core.gameobject.user.StateLoader) BukkitUtil(mc.dragons.core.util.BukkitUtil) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) GameObjectType(mc.dragons.core.gameobject.GameObjectType) RegionLoader(mc.dragons.core.gameobject.region.RegionLoader) HealCommand(mc.dragons.core.commands.HealCommand) CustomLoggingProvider(mc.dragons.core.logging.CustomLoggingProvider) ChangeLogLoader(mc.dragons.core.storage.loader.ChangeLogLoader) GameObjectRegistry(mc.dragons.core.gameobject.GameObjectRegistry) EntityDeathListener(mc.dragons.core.events.EntityDeathListener) BridgeSpigot116R3(mc.dragons.core.bridge.impl.BridgeSpigot116R3) LocalStorageManager(mc.dragons.core.storage.local.LocalStorageManager) RespawnCommand(mc.dragons.core.commands.RespawnCommand) EntityDamageListener(mc.dragons.core.events.EntityDamageListener) NamespacedKey(org.bukkit.NamespacedKey) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) WorldEventListeners(mc.dragons.core.events.WorldEventListeners) SpawnEntityTask(mc.dragons.core.tasks.SpawnEntityTask) CommandExecutor(org.bukkit.command.CommandExecutor) EntityTargetEventListener(mc.dragons.core.events.EntityTargetEventListener) InventoryEventListeners(mc.dragons.core.events.InventoryEventListeners) VerifyGameIntegrityTask(mc.dragons.core.tasks.VerifyGameIntegrityTask) SlimeSplitEventListener(mc.dragons.core.events.SlimeSplitEventListener) Singletons(mc.dragons.core.util.singletons.Singletons) ChatColor(org.bukkit.ChatColor) PluginManager(org.bukkit.plugin.PluginManager) PlayerEventListeners(mc.dragons.core.events.PlayerEventListeners) RemoteAdminMessageHandler(mc.dragons.core.networking.RemoteAdminMessageHandler) Entity(org.bukkit.entity.Entity) RemoteAdminMessageHandler(mc.dragons.core.networking.RemoteAdminMessageHandler) SystemLogonCommand(mc.dragons.core.commands.SystemLogonCommand) WarpLoader(mc.dragons.core.storage.loader.WarpLoader) CommandExecutor(org.bukkit.command.CommandExecutor) ChangeLogLoader(mc.dragons.core.storage.loader.ChangeLogLoader) ItemFrame(org.bukkit.entity.ItemFrame) RegionLoader(mc.dragons.core.gameobject.region.RegionLoader) FeedbackLoader(mc.dragons.core.storage.loader.FeedbackLoader) FeedbackCommand(mc.dragons.core.commands.FeedbackCommand) PluginManager(org.bukkit.plugin.PluginManager) InventoryEventListeners(mc.dragons.core.events.InventoryEventListeners) QuestLoader(mc.dragons.core.gameobject.quest.QuestLoader) EntityMoveListener(mc.dragons.core.events.EntityMoveListener) EntityTargetEventListener(mc.dragons.core.events.EntityTargetEventListener) AutoRankCommand(mc.dragons.core.commands.AutoRankCommand) RankCommand(mc.dragons.core.commands.RankCommand) HelpCommand(mc.dragons.core.commands.HelpCommand) EntityHider(mc.dragons.core.util.EntityHider) SlimeSplitEventListener(mc.dragons.core.events.SlimeSplitEventListener) StaffAlertMessageHandler(mc.dragons.core.networking.StaffAlertMessageHandler) RestartInstanceCommand(mc.dragons.core.commands.RestartInstanceCommand) HealCommand(mc.dragons.core.commands.HealCommand) LogoutCommand(mc.dragons.core.commands.LogoutCommand) GlobalVarLoader(mc.dragons.core.storage.loader.GlobalVarLoader) ItemClassLoader(mc.dragons.core.gameobject.item.ItemClassLoader) EntityDamageListener(mc.dragons.core.events.EntityDamageListener) StateCommands(mc.dragons.core.commands.StateCommands) AutoRankCommand(mc.dragons.core.commands.AutoRankCommand) PlayerEventListeners(mc.dragons.core.events.PlayerEventListeners) FloorLoader(mc.dragons.core.gameobject.floor.FloorLoader) CorrelationLogger(mc.dragons.core.logging.correlation.CorrelationLogger) QuestDialogueCommands(mc.dragons.core.commands.QuestDialogueCommands) DragonsCommand(mc.dragons.core.commands.DragonsCommand) ChatOptionsCommand(mc.dragons.core.commands.ChatOptionsCommand) StateLoader(mc.dragons.core.gameobject.user.StateLoader) ChangeLogCommands(mc.dragons.core.commands.ChangeLogCommands) PlayerNPCRegistry(mc.dragons.core.gameobject.npc.PlayerNPCRegistry) EntityDeathListener(mc.dragons.core.events.EntityDeathListener) InternalMessageHandler(mc.dragons.core.networking.InternalMessageHandler) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) StuckQuestCommand(mc.dragons.core.commands.StuckQuestCommand) MyQuestsCommand(mc.dragons.core.commands.MyQuestsCommand) RespawnCommand(mc.dragons.core.commands.RespawnCommand) NPCClassLoader(mc.dragons.core.gameobject.npc.NPCClassLoader) EntityCombustListener(mc.dragons.core.events.EntityCombustListener) SystemProfileLoader(mc.dragons.core.gameobject.user.permission.SystemProfileLoader) WorldEventListeners(mc.dragons.core.events.WorldEventListeners)

Aggregations

ProtocolLibrary (com.comphenix.protocol.ProtocolLibrary)1 ProtocolManager (com.comphenix.protocol.ProtocolManager)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1 Level (java.util.logging.Level)1 AddonRegistry (mc.dragons.core.addon.AddonRegistry)1 Bridge (mc.dragons.core.bridge.Bridge)1 BridgeSpigot116R3 (mc.dragons.core.bridge.impl.BridgeSpigot116R3)1 AutoRankCommand (mc.dragons.core.commands.AutoRankCommand)1 ChangeLogCommands (mc.dragons.core.commands.ChangeLogCommands)1 ChatOptionsCommand (mc.dragons.core.commands.ChatOptionsCommand)1 DragonsCommand (mc.dragons.core.commands.DragonsCommand)1 FeedbackCommand (mc.dragons.core.commands.FeedbackCommand)1 HealCommand (mc.dragons.core.commands.HealCommand)1 HelpCommand (mc.dragons.core.commands.HelpCommand)1 LogoutCommand (mc.dragons.core.commands.LogoutCommand)1 MyQuestsCommand (mc.dragons.core.commands.MyQuestsCommand)1 QuestDialogueCommands (mc.dragons.core.commands.QuestDialogueCommands)1 RankCommand (mc.dragons.core.commands.RankCommand)1