use of mc.dragons.core.networking.InternalMessageHandler in project DragonsOnline by UniverseCraft.
the class LocateCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!requirePermission(sender, PermissionLevel.HELPER))
return true;
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "/locate <player>");
return true;
}
InternalMessageHandler internalHandler = dragons.getInternalMessageHandler();
long start = System.currentTimeMillis();
User target = lookupUser(sender, args[0]);
if (target == null)
return true;
String server = target.getServerName();
if (server == null) {
sender.sendMessage(ChatColor.RED + "That player is not currently connected to any server!");
return true;
}
internalHandler.sendCheckUserPing(server, target.getUUID(), online -> {
long end = System.currentTimeMillis();
if (online.isEmpty()) {
if (hasPermission(sender, PermissionLevel.DEVELOPER)) {
sender.sendMessage(ChatColor.RED + "That player is not currently connected to any server! (Last server " + server + " did not respond)");
} else {
sender.sendMessage(ChatColor.RED + "That player is not currently connected to any server!");
}
} else if (online.get()) {
sender.sendMessage(ChatColor.GREEN + target.getName() + " is connected to " + target.getServerName() + " (took " + (end - start) + "ms)");
} else {
if (hasPermission(sender, PermissionLevel.DEVELOPER)) {
sender.sendMessage(ChatColor.RED + "That player is not currently connected to any server! (Stale user data indicated " + server + ")");
} else {
sender.sendMessage(ChatColor.RED + "That player is not currently connected to any server!");
}
}
});
return true;
}
use of mc.dragons.core.networking.InternalMessageHandler 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();
}
Aggregations