Search in sources :

Example 1 with GameObjectRegistry

use of mc.dragons.core.gameobject.GameObjectRegistry in project DragonsOnline by UniverseCraft.

the class ObjectCommands method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!requirePermission(sender, SystemProfileFlag.DEVELOPMENT))
        return true;
    GameObjectRegistry registry = dragons.getGameObjectRegistry();
    StorageManager localStorageManager = dragons.getLocalStorageManager();
    if (label.equalsIgnoreCase("autosave")) {
        Dragons.getInstance().getGameObjectRegistry().executeAutoSave(true);
        sender.sendMessage(ChatColor.GREEN + "Auto-save executed successfully.");
    } else if (label.equalsIgnoreCase("invalidate")) {
        if (args.length < 2) {
            sender.sendMessage(ChatColor.RED + "/invalidate <type> <uuid>");
            return true;
        }
        GameObjectType type = StringUtil.parseEnum(sender, GameObjectType.class, args[0].toUpperCase());
        UUID uuid = StringUtil.parseUUID(sender, args[1]);
        if (type == null || uuid == null)
            return true;
        boolean result = registry.getRegisteredObjects().removeIf(obj -> obj.getType() == type && obj.getUUID().equals(uuid));
        if (result) {
            sender.sendMessage(ChatColor.GREEN + "Invalidated game object " + type + "#" + uuid + ".");
        } else {
            sender.sendMessage(ChatColor.RED + "Unable to locate game object (is it registered properly?)");
        }
    } else if (label.equalsIgnoreCase("invalidateall")) {
        registry.getRegisteredObjects().clear();
        sender.sendMessage(ChatColor.GREEN + "Invalidated all game objects.");
    } else if (label.equalsIgnoreCase("invalidatetype")) {
        if (args.length == 0) {
            sender.sendMessage(ChatColor.RED + "/invalidatetype <type>");
            return true;
        }
        GameObjectType type = StringUtil.parseEnum(sender, GameObjectType.class, args[0].toUpperCase());
        if (type == null)
            return true;
        registry.getRegisteredObjects().removeIf(obj -> obj.getType() == type);
        sender.sendMessage(ChatColor.GREEN + "Invalidated all game objects of type " + type);
    } else if (label.equalsIgnoreCase("invalidateuser")) {
        if (args.length == 0) {
            sender.sendMessage(ChatColor.RED + "/invalidateuser <player>");
            return true;
        }
        boolean result = UserLoader.allUsers().removeIf(u -> u.getName().equalsIgnoreCase(args[0]));
        result &= registry.getRegisteredObjects(GameObjectType.USER).removeIf(u -> ((User) u).getName().equalsIgnoreCase(args[0]));
        if (result) {
            sender.sendMessage(ChatColor.GREEN + "Invalidated user " + args[0]);
        } else {
            sender.sendMessage(ChatColor.RED + "That user was not found locally!");
        }
    } else if (label.equalsIgnoreCase("localize")) {
        if (args.length < 2) {
            sender.sendMessage(ChatColor.RED + "/localize <type> <uuid>");
            return true;
        }
        GameObjectType type = StringUtil.parseEnum(sender, GameObjectType.class, args[0].toUpperCase());
        UUID uuid = StringUtil.parseUUID(sender, args[1]);
        if (type == null || uuid == null)
            return true;
        registry.getRegisteredObjects().stream().filter(obj -> obj.getType() == type && obj.getUUID().equals(uuid)).forEach(obj -> obj.replaceStorageAccess(localStorageManager.getNewStorageAccess(type, obj.getData())));
        sender.sendMessage(ChatColor.GREEN + "Localized game object " + type + "#" + uuid + ".");
    } else if (label.equalsIgnoreCase("localizeall")) {
        registry.getRegisteredObjects().forEach(obj -> obj.replaceStorageAccess(localStorageManager.getNewStorageAccess(obj.getType(), obj.getData())));
        sender.sendMessage(ChatColor.GREEN + "Localized all game objects.");
    } else if (label.equalsIgnoreCase("localizetype")) {
        if (args.length == 0) {
            sender.sendMessage(ChatColor.RED + "/localizetype <type>");
            return true;
        }
        GameObjectType type = StringUtil.parseEnum(sender, GameObjectType.class, args[0].toUpperCase());
        if (type == null)
            return true;
        registry.getRegisteredObjects().stream().filter(obj -> obj.getType() == type).forEach(obj -> obj.replaceStorageAccess(localStorageManager.getNewStorageAccess(type, obj.getData())));
        sender.sendMessage(ChatColor.GREEN + "Localized all game objects of type " + type);
    } else if (label.equalsIgnoreCase("localizeuser")) {
        if (args.length == 0) {
            sender.sendMessage(ChatColor.RED + "/localizeuser <player>");
            return true;
        }
        UserLoader.allUsers().stream().filter(u -> u.getName().equalsIgnoreCase(args[0])).forEach(u -> u.replaceStorageAccess(localStorageManager.getNewStorageAccess(GameObjectType.USER, u.getData())));
        sender.sendMessage(ChatColor.GREEN + "Localized user " + args[0]);
    }
    return true;
}
Also used : StringUtil(mc.dragons.core.util.StringUtil) CommandSender(org.bukkit.command.CommandSender) UserLoader(mc.dragons.core.gameobject.user.UserLoader) User(mc.dragons.core.gameobject.user.User) UUID(java.util.UUID) SystemProfileFlag(mc.dragons.core.gameobject.user.permission.SystemProfile.SystemProfileFlags.SystemProfileFlag) Dragons(mc.dragons.core.Dragons) GameObjectType(mc.dragons.core.gameobject.GameObjectType) DragonsCommandExecutor(mc.dragons.core.commands.DragonsCommandExecutor) StorageManager(mc.dragons.core.storage.StorageManager) GameObjectRegistry(mc.dragons.core.gameobject.GameObjectRegistry) ChatColor(org.bukkit.ChatColor) Command(org.bukkit.command.Command) GameObjectType(mc.dragons.core.gameobject.GameObjectType) StorageManager(mc.dragons.core.storage.StorageManager) UUID(java.util.UUID) GameObjectRegistry(mc.dragons.core.gameobject.GameObjectRegistry)

Example 2 with GameObjectRegistry

use of mc.dragons.core.gameobject.GameObjectRegistry in project DragonsOnline by UniverseCraft.

the class Dragons method onLoad.

@Override
public synchronized void onLoad() {
    FIXED_ENTITY_KEY = new NamespacedKey(this, "fixed");
    started = System.currentTimeMillis();
    getLogger().info("Searching for compatible version...");
    switch(BUKKIT_API_VERSION) {
        case "1_16_R3":
            bridge = new BridgeSpigot116R3();
            break;
        default:
            getLogger().severe("Incompatible server version (" + BUKKIT_API_VERSION + ")");
            getLogger().severe("Cannot run DragonsOnline.");
            getServer().getPluginManager().disablePlugin(this);
            return;
    }
    joinable = false;
    getLogger().info("Disabled player joins until Dragons startup completes");
    serverName = getConfig().getString("serverName");
    getLogger().info("Server instance name is " + serverName);
    getLogger().info("Initializing storage and registries...");
    saveDefaultConfig();
    mongoConfig = new MongoConfig(this);
    persistentStorageManager = new MongoStorageManager(this);
    localStorageManager = new LocalStorageManager();
    gameObjectRegistry = new GameObjectRegistry(this, persistentStorageManager);
    addonRegistry = new AddonRegistry(this);
    userHookRegistry = new UserHookRegistry();
    lightweightLoaderRegistry = new LightweightLoaderRegistry();
    sidebarManager = new SidebarManager(this);
    chatMessageRegistry = new ChatMessageRegistry();
    messageDispatcher = new MessageDispatcher(this);
    setCustomLoggingProvider(new CustomLoggingProvider(this));
    autoSaveRunnable = new AutoSaveTask(this);
    spawnEntityRunnable = new SpawnEntityTask(this);
    verifyGameIntegrityRunnable = new VerifyGameIntegrityTask(this);
    lagMeter = new LagMeter();
    lagMonitorTask = new LagMonitorTask();
    updateScoreboardTask = new UpdateScoreboardTask(this);
    serverOptions = new ServerOptions(this);
    serverOptions.setLogLevel(Level.parse(getConfig().getString("loglevel")));
    debug = getConfig().getBoolean("debug");
    if (debug) {
        if (serverOptions.getLogLevel().intValue() > Level.CONFIG.intValue()) {
            serverOptions.setLogLevel(Level.CONFIG);
        }
        serverOptions.setVerifyIntegrityEnabled(false);
        getLogger().warning("==========================================================");
        getLogger().warning("THIS SERVER IS IN DEVELOPMENT MODE.");
        getLogger().warning("GAME INTEGRITY WILL NOT BE VERIFIED AFTER INITIAL LOAD.");
        getLogger().warning("==========================================================");
    }
    customLoggingProvider.enableCustomLogging();
    enableDebugLogging();
    getLogger().info("Log token is " + customLoggingProvider.getCustomLogFilter().getLogEntryUUID());
}
Also used : LightweightLoaderRegistry(mc.dragons.core.storage.loader.LightweightLoaderRegistry) AddonRegistry(mc.dragons.core.addon.AddonRegistry) ChatMessageRegistry(mc.dragons.core.gameobject.user.chat.ChatMessageRegistry) SidebarManager(mc.dragons.core.gameobject.user.SidebarManager) LocalStorageManager(mc.dragons.core.storage.local.LocalStorageManager) UserHookRegistry(mc.dragons.core.gameobject.user.UserHookRegistry) LagMonitorTask(mc.dragons.core.tasks.LagMonitorTask) MongoConfig(mc.dragons.core.storage.mongo.MongoConfig) MongoStorageManager(mc.dragons.core.storage.mongo.MongoStorageManager) GameObjectRegistry(mc.dragons.core.gameobject.GameObjectRegistry) MessageDispatcher(mc.dragons.core.networking.MessageDispatcher) LagMeter(mc.dragons.core.tasks.LagMeter) AutoSaveTask(mc.dragons.core.tasks.AutoSaveTask) SpawnEntityTask(mc.dragons.core.tasks.SpawnEntityTask) NamespacedKey(org.bukkit.NamespacedKey) CustomLoggingProvider(mc.dragons.core.logging.CustomLoggingProvider) UpdateScoreboardTask(mc.dragons.core.tasks.UpdateScoreboardTask) VerifyGameIntegrityTask(mc.dragons.core.tasks.VerifyGameIntegrityTask) BridgeSpigot116R3(mc.dragons.core.bridge.impl.BridgeSpigot116R3)

Aggregations

GameObjectRegistry (mc.dragons.core.gameobject.GameObjectRegistry)2 UUID (java.util.UUID)1 Dragons (mc.dragons.core.Dragons)1 AddonRegistry (mc.dragons.core.addon.AddonRegistry)1 BridgeSpigot116R3 (mc.dragons.core.bridge.impl.BridgeSpigot116R3)1 DragonsCommandExecutor (mc.dragons.core.commands.DragonsCommandExecutor)1 GameObjectType (mc.dragons.core.gameobject.GameObjectType)1 SidebarManager (mc.dragons.core.gameobject.user.SidebarManager)1 User (mc.dragons.core.gameobject.user.User)1 UserHookRegistry (mc.dragons.core.gameobject.user.UserHookRegistry)1 UserLoader (mc.dragons.core.gameobject.user.UserLoader)1 ChatMessageRegistry (mc.dragons.core.gameobject.user.chat.ChatMessageRegistry)1 SystemProfileFlag (mc.dragons.core.gameobject.user.permission.SystemProfile.SystemProfileFlags.SystemProfileFlag)1 CustomLoggingProvider (mc.dragons.core.logging.CustomLoggingProvider)1 MessageDispatcher (mc.dragons.core.networking.MessageDispatcher)1 StorageManager (mc.dragons.core.storage.StorageManager)1 LightweightLoaderRegistry (mc.dragons.core.storage.loader.LightweightLoaderRegistry)1 LocalStorageManager (mc.dragons.core.storage.local.LocalStorageManager)1 MongoConfig (mc.dragons.core.storage.mongo.MongoConfig)1 MongoStorageManager (mc.dragons.core.storage.mongo.MongoStorageManager)1