Search in sources :

Example 1 with GameObject

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

the class NPCClassLoader method loadObject.

@Override
public NPCClass loadObject(StorageAccess storageAccess) {
    lazyLoadAll();
    LOGGER.trace("Loading NPC class " + storageAccess.getIdentifier());
    for (GameObject gameObject : masterRegistry.getRegisteredObjects(GameObjectType.NPC_CLASS)) {
        NPCClass npcClass = (NPCClass) gameObject;
        if (npcClass.getIdentifier().equals(storageAccess.getIdentifier())) {
            return npcClass;
        }
    }
    NPCClass npcClass = new NPCClass(storageManager, storageAccess);
    masterRegistry.getRegisteredObjects().add(npcClass);
    cachedNPCClasses.put(npcClass.getClassName(), npcClass);
    return npcClass;
}
Also used : GameObject(mc.dragons.core.gameobject.GameObject)

Example 2 with GameObject

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

the class NPCLoader method loadObject.

public NPC loadObject(UUID uuid, UUID cid) {
    if (uuidToNpc.containsKey(uuid)) {
        LOGGER.debug("Prevented spawn of duplicate NPC " + uuid);
        return uuidToNpc.get(uuid);
    }
    LOGGER.verbose(cid, "loading NPC with uuid " + uuid);
    for (GameObject gameObject : masterRegistry.getRegisteredObjects(new GameObjectType[] { GameObjectType.NPC })) {
        NPC npc = (NPC) gameObject;
        if (npc.getUUID().equals(uuid)) {
            LOGGER.verbose("found in local cache (" + npc + "), returning");
            return npc;
        }
    }
    StorageAccess storageAccess = storageManager.getStorageAccess(GameObjectType.NPC, uuid);
    if (storageAccess == null) {
        LOGGER.warning(cid, "could not load NPC from database: returned null storage access");
        return null;
    }
    LOGGER.verbose(cid, "loaded storage access (" + storageAccess + "), constructing downstream");
    return loadObject(storageAccess);
}
Also used : GameObject(mc.dragons.core.gameobject.GameObject) LocalStorageAccess(mc.dragons.core.storage.local.LocalStorageAccess) StorageAccess(mc.dragons.core.storage.StorageAccess)

Example 3 with GameObject

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

the class ItemClassLoader method loadObject.

@Override
public ItemClass loadObject(StorageAccess storageAccess) {
    LOGGER.trace("Loading item class " + storageAccess.getIdentifier());
    for (GameObject gameObject : masterRegistry.getRegisteredObjects(GameObjectType.ITEM_CLASS)) {
        ItemClass itemClass = (ItemClass) gameObject;
        if (itemClass.getIdentifier().equals(storageAccess.getIdentifier())) {
            return itemClass;
        }
    }
    ItemClass itemClass = new ItemClass(storageManager, storageAccess);
    masterRegistry.getRegisteredObjects().add(itemClass);
    return itemClass;
}
Also used : GameObject(mc.dragons.core.gameobject.GameObject)

Example 4 with GameObject

use of mc.dragons.core.gameobject.GameObject 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 5 with GameObject

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

the class ItemCommand method listClasses.

private void listClasses(CommandSender sender, String[] args) {
    String startingWith = "";
    if (args.length > 1) {
        startingWith = args[1];
    }
    sender.sendMessage(ChatColor.GREEN + "Listing all item classes" + (startingWith.length() > 0 ? (" starting with \"" + startingWith + "\"") : "") + ":");
    for (GameObject gameObject : registry.getRegisteredObjects(GameObjectType.ITEM_CLASS)) {
        ItemClass itemClass = (ItemClass) gameObject;
        if (!itemClass.getClassName().startsWith(startingWith))
            continue;
        sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.GRAY + "- " + itemClass.getClassName() + " [Lv Min " + itemClass.getLevelMin() + "]", "/item give " + itemClass.getClassName(), true, "Click to receive this item"));
    }
}
Also used : ItemClass(mc.dragons.core.gameobject.item.ItemClass) GameObject(mc.dragons.core.gameobject.GameObject)

Aggregations

GameObject (mc.dragons.core.gameobject.GameObject)17 User (mc.dragons.core.gameobject.user.User)5 Entity (org.bukkit.entity.Entity)5 NPC (mc.dragons.core.gameobject.npc.NPC)4 Floor (mc.dragons.core.gameobject.floor.Floor)3 Player (org.bukkit.entity.Player)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3 UUID (java.util.UUID)2 Level (java.util.logging.Level)2 GameObjectType (mc.dragons.core.gameobject.GameObjectType)2 Item (mc.dragons.core.gameobject.item.Item)2 Quest (mc.dragons.core.gameobject.quest.Quest)2 Region (mc.dragons.core.gameobject.region.Region)2 StorageAccess (mc.dragons.core.storage.StorageAccess)2 LocalStorageAccess (mc.dragons.core.storage.local.LocalStorageAccess)2 World (org.bukkit.World)2 Item (org.bukkit.entity.Item)2 ItemStack (org.bukkit.inventory.ItemStack)2 ThreadMXBean (com.sun.management.ThreadMXBean)1 Base64 (java.util.Base64)1