Search in sources :

Example 1 with GameObjectType

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

the class ObjectMetadataCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!requirePermission(sender, PermissionLevel.GM))
        return true;
    if (args.length == 0) {
        sender.sendMessage(ChatColor.RED + "/objmeta <gameobject type> <gameobject uuid>");
        return true;
    }
    GameObjectType type = StringUtil.parseEnum(sender, GameObjectType.class, args[0]);
    UUID uuid = parseUUID(sender, args[1]);
    if (type == null || uuid == null)
        return true;
    GameObject gameObject = type.getLoader().loadObject(dragons.getPersistentStorageManager().getStorageAccess(type, uuid));
    if (gameObject == null) {
        sender.sendMessage(ChatColor.RED + "No game object was found matching these criteria!");
        return true;
    }
    // MetadataConstants.displayMetadata(sender, gameObject);
    List<AuditLogEntry> entries = AUDIT_LOG.getEntries(gameObject.getIdentifier());
    int count = entries.size();
    if (count == 0) {
        sender.sendMessage(ChatColor.RED + "There is no metadata for this game object!");
        return true;
    }
    AuditLogEntry first = entries.get(0);
    AuditLogEntry last = entries.get(entries.size() - 1);
    AuditLogEntry lastPush = AUDIT_LOG.getLastPush(gameObject.getIdentifier());
    if (first != null && first.getLine().equals("Created")) {
        sender.sendMessage(ChatColor.GRAY + "Created By: " + ChatColor.GREEN + ObjectUtil.get(first.getBy(), () -> first.getBy().getName(), UNKNOWN));
        sender.sendMessage(ChatColor.GRAY + "Created On: " + ChatColor.GREEN + ObjectUtil.get(first.getDate(), () -> StringUtil.DATE_FORMAT.format(first.getDate()), UNKNOWN));
    }
    sender.sendMessage(ChatColor.GRAY + "Revision Count: " + ChatColor.GREEN + count);
    if (last != null) {
        sender.sendMessage(ChatColor.GRAY + "Last Revised By: " + ChatColor.GREEN + ObjectUtil.get(last.getBy(), () -> last.getBy().getName(), UNKNOWN));
        sender.sendMessage(ChatColor.GRAY + "Last Revised On: " + ChatColor.GREEN + ObjectUtil.get(last.getDate(), () -> StringUtil.DATE_FORMAT.format(last.getDate()), UNKNOWN));
    }
    if (lastPush != null) {
        sender.sendMessage(ChatColor.GRAY + "Last Pushed On: " + ChatColor.GREEN + StringUtil.DATE_FORMAT.format(lastPush.getDate()));
    }
    if (last == null || lastPush == null) {
        sender.sendMessage(ChatColor.GRAY + "Sync Status: " + UNKNOWN);
    } else if (last.getId() == lastPush.getId()) {
        sender.sendMessage(ChatColor.GRAY + "Sync Status: " + ChatColor.GREEN + "Matched in production");
    } else if (last.getId() > lastPush.getId()) {
        sender.sendMessage(ChatColor.GRAY + "Sync Status: " + ChatColor.YELLOW + "Changes made since last push");
    } else {
        sender.sendMessage(ChatColor.GRAY + "Sync Status: " + ChatColor.RED + "Behind production (SYNC ERROR)");
    }
    return true;
}
Also used : GameObjectType(mc.dragons.core.gameobject.GameObjectType) AuditLogEntry(mc.dragons.tools.content.AuditLogLoader.AuditLogEntry) GameObject(mc.dragons.core.gameobject.GameObject) UUID(java.util.UUID)

Example 2 with GameObjectType

use of mc.dragons.core.gameobject.GameObjectType 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)

Aggregations

UUID (java.util.UUID)2 GameObjectType (mc.dragons.core.gameobject.GameObjectType)2 Dragons (mc.dragons.core.Dragons)1 DragonsCommandExecutor (mc.dragons.core.commands.DragonsCommandExecutor)1 GameObject (mc.dragons.core.gameobject.GameObject)1 GameObjectRegistry (mc.dragons.core.gameobject.GameObjectRegistry)1 User (mc.dragons.core.gameobject.user.User)1 UserLoader (mc.dragons.core.gameobject.user.UserLoader)1 SystemProfileFlag (mc.dragons.core.gameobject.user.permission.SystemProfile.SystemProfileFlags.SystemProfileFlag)1 StorageManager (mc.dragons.core.storage.StorageManager)1 StringUtil (mc.dragons.core.util.StringUtil)1 AuditLogEntry (mc.dragons.tools.content.AuditLogLoader.AuditLogEntry)1 ChatColor (org.bukkit.ChatColor)1 Command (org.bukkit.command.Command)1 CommandSender (org.bukkit.command.CommandSender)1