Search in sources :

Example 11 with NPCClass

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

the class NPCCommand method manageAttributes.

private void manageAttributes(CommandSender sender, String[] args) {
    NPCClass npcClass = lookupNPCClass(sender, args[0]);
    if (npcClass == null)
        return;
    if (args.length == 2) {
        sender.sendMessage(ChatColor.GREEN + "Listing custom base attributes for NPC class " + npcClass.getClassName() + ":");
        for (Entry<Attribute, Double> attribute : npcClass.getCustomAttributes().entrySet()) {
            sender.sendMessage(ChatColor.GRAY + "- " + attribute.getKey() + ": " + attribute.getValue());
        }
        return;
    } else if (args.length < 4) {
        sender.sendMessage(ChatColor.RED + "Insufficient arguments! /npc <ClassName> attribute <Attribute> <Value|DEL>");
        sender.sendMessage(ChatColor.RED + "Valid attributes are: " + StringUtil.parseList(Attribute.values()));
        return;
    }
    Document base = Document.parse(npcClass.getData().toJson());
    Attribute att = StringUtil.parseEnum(sender, Attribute.class, args[2]);
    if (att == null)
        return;
    if (args[3].equalsIgnoreCase("DEL")) {
        npcClass.removeCustomAttribute(att);
    } else {
        Double value = parseDouble(sender, args[3]);
        if (value == null)
            return;
        npcClass.setCustomAttribute(att, value);
    }
    AUDIT_LOG.saveEntry(npcClass, user(sender), base, "Updated attributes");
    sender.sendMessage(ChatColor.GREEN + "Updated attributes successfully.");
}
Also used : NPCClass(mc.dragons.core.gameobject.npc.NPCClass) Attribute(org.bukkit.attribute.Attribute) Document(org.bson.Document)

Example 12 with NPCClass

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

the class NPCCommand method displayClass.

private void displayClass(CommandSender sender, String[] args) {
    NPCClass npcClass = lookupNPCClass(sender, args[0]);
    if (npcClass == null)
        return;
    sender.sendMessage(ChatColor.GREEN + "=== NPC Class: " + npcClass.getClassName() + " ===");
    sender.sendMessage(ChatColor.GRAY + "Database identifier: " + ChatColor.GREEN + npcClass.getIdentifier().toString());
    sender.sendMessage(ChatColor.GRAY + "Display name: " + ChatColor.GREEN + npcClass.getName());
    sender.sendMessage(ChatColor.GRAY + "Entity type: " + ChatColor.GREEN + npcClass.getEntityType().toString());
    sender.sendMessage(ChatColor.GRAY + "Max health: " + ChatColor.GREEN + npcClass.getMaxHealth());
    sender.sendMessage(ChatColor.GRAY + "Level: " + ChatColor.GREEN + npcClass.getLevel());
    sender.sendMessage(ChatColor.GRAY + "NPC type: " + ChatColor.GREEN + npcClass.getNPCType().toString());
    sender.sendMessage(ChatColor.GRAY + "AI: " + ChatColor.GREEN + npcClass.hasAI());
    sender.sendMessage(ChatColor.GRAY + "Immortal: " + ChatColor.GREEN + npcClass.isImmortal());
    Material heldItemType = npcClass.getHeldItemType();
    String heldItemTypeName = "Nothing";
    if (heldItemType != null) {
        heldItemTypeName = heldItemType.toString();
    }
    sender.sendMessage(ChatColor.GRAY + "Holding: " + ChatColor.GREEN + heldItemTypeName);
    if (!npcClass.verifyAddons()) {
        sender.sendMessage(ChatColor.RED + "NPC class add-on verification failed!");
    }
    sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.GRAY + "[Spawn] ", "/npc spawn " + npcClass.getClassName(), true, "Click to Spawn"), ObjectMetadataCommand.getClickableMetadataLink(GameObjectType.NPC_CLASS, npcClass.getUUID()));
    sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.GRAY + "/npc " + npcClass.getClassName() + " loot" + ChatColor.YELLOW + " to view loot table", "/npc " + npcClass.getClassName() + " loot", "Click to view loot table"));
    sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.GRAY + "/npc " + npcClass.getClassName() + " behavior" + ChatColor.YELLOW + " to view behaviors", "/npc " + npcClass.getClassName() + " behavior", "Click to view behaviors"));
    sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.GRAY + "/npc " + npcClass.getClassName() + " addon" + ChatColor.YELLOW + " to view addons", "/npc " + npcClass.getClassName() + " addon", "Click to view addons"));
    sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.GRAY + "/npc " + npcClass.getClassName() + " attribute" + ChatColor.YELLOW + " to view attributes", "/npc " + npcClass.getClassName() + " attribute", "Click to view attributes"));
}
Also used : NPCClass(mc.dragons.core.gameobject.npc.NPCClass) Material(org.bukkit.Material)

Example 13 with NPCClass

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

the class NPCCommand method locate.

private void locate(CommandSender sender, String[] args) {
    NPCClass npcClass = lookupNPCClass(sender, args[0]);
    if (npcClass == null)
        return;
    if (!npcClass.getNPCType().isPersistent()) {
        sender.sendMessage(ChatColor.RED + "Can only locate persistent NPCs!");
        return;
    }
    List<NPC> result = gameObjectRegistry.getRegisteredObjects(GameObjectType.NPC).stream().map(o -> (NPC) o).filter(npc -> npc.getNPCClass().equals(npcClass)).collect(Collectors.toList());
    sender.sendMessage(ChatColor.GREEN + "" + result.size() + " results for class " + npcClass.getClassName() + ":");
    for (NPC npc : result) {
        sender.sendMessage(ChatColor.GRAY + StringUtil.locToString(npc.getEntity().getLocation()) + ", " + npc.getEntity().getWorld().getName());
    }
}
Also used : NPC(mc.dragons.core.gameobject.npc.NPC) Document(org.bson.Document) Addon(mc.dragons.core.addon.Addon) NPCLoader(mc.dragons.core.gameobject.npc.NPCLoader) Arrays(java.util.Arrays) AddonRegistry(mc.dragons.core.addon.AddonRegistry) NPCClass(mc.dragons.core.gameobject.npc.NPCClass) NPCConditionType(mc.dragons.core.gameobject.npc.NPCCondition.NPCConditionType) NPCCondition(mc.dragons.core.gameobject.npc.NPCCondition) User(mc.dragons.core.gameobject.user.User) Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) Quest(mc.dragons.core.gameobject.quest.Quest) GameObjectType(mc.dragons.core.gameobject.GameObjectType) AuditLogLoader(mc.dragons.tools.content.AuditLogLoader) AddonType(mc.dragons.core.addon.AddonType) DragonsCommandExecutor(mc.dragons.core.commands.DragonsCommandExecutor) Map(java.util.Map) GameObjectRegistry(mc.dragons.core.gameobject.GameObjectRegistry) HttpUtil(mc.dragons.core.util.HttpUtil) NPCAction(mc.dragons.core.gameobject.npc.NPCAction) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) NPCType(mc.dragons.core.gameobject.npc.NPC.NPCType) ShopItem(mc.dragons.core.gameobject.npc.NPCAction.ShopItem) Attribute(org.bukkit.attribute.Attribute) StringUtil(mc.dragons.core.util.StringUtil) CommandSender(org.bukkit.command.CommandSender) Entity(org.bukkit.entity.Entity) FloorLoader(mc.dragons.core.gameobject.floor.FloorLoader) NPCActionType(mc.dragons.core.gameobject.npc.NPCAction.NPCActionType) EntityType(org.bukkit.entity.EntityType) NPCTrigger(mc.dragons.core.gameobject.npc.NPCConditionalActions.NPCTrigger) SystemProfileFlag(mc.dragons.core.gameobject.user.permission.SystemProfile.SystemProfileFlags.SystemProfileFlag) Collectors(java.util.stream.Collectors) Dragons(mc.dragons.core.Dragons) Floor(mc.dragons.core.gameobject.floor.Floor) List(java.util.List) NPCAddon(mc.dragons.core.addon.NPCAddon) GameObject(mc.dragons.core.gameobject.GameObject) Entry(java.util.Map.Entry) ChatColor(org.bukkit.ChatColor) Command(org.bukkit.command.Command) Pattern(java.util.regex.Pattern) NPCConditionalActions(mc.dragons.core.gameobject.npc.NPCConditionalActions) NPC(mc.dragons.core.gameobject.npc.NPC) NPCClass(mc.dragons.core.gameobject.npc.NPCClass)

Example 14 with NPCClass

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

the class NPCCommand method setAI.

private void setAI(CommandSender sender, String[] args) {
    NPCClass npcClass = lookupNPCClass(sender, args[0]);
    Boolean ai = parseBoolean(sender, args[2]);
    if (npcClass == null || ai == null)
        return;
    Document base = Document.parse(npcClass.getData().toJson());
    npcClass.setAI(ai);
    sender.sendMessage(ChatColor.GREEN + "Updated entity AI successfully.");
    AUDIT_LOG.saveEntry(npcClass, user(sender), base, "Set entity AI to " + ai);
    propagateRevisions(npcClass);
}
Also used : NPCClass(mc.dragons.core.gameobject.npc.NPCClass) Document(org.bson.Document)

Example 15 with NPCClass

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

the class NPCCommand method manageBehavior.

private void manageBehavior(CommandSender sender, String[] args) {
    NPCClass npcClass = lookupNPCClass(sender, args[0]);
    if (npcClass == null)
        return;
    if (args.length == 2) {
        displayBehavior(sender, args);
        return;
    }
    NPCTrigger trigger = NPCTrigger.valueOf(args[2]);
    NPCConditionalActions behaviorsLocal = npcClass.getConditionalActions(trigger);
    NPCConditionalActions parsedBehaviors = npcClass.getConditionalActions(trigger);
    Document conditionals = npcClass.getStorageAccess().getDocument().get("conditionals", Document.class);
    List<Document> behaviors = conditionals.getList(trigger.toString(), Document.class);
    Document base = Document.parse(npcClass.getData().toJson());
    boolean changed = false;
    if (args[3].equalsIgnoreCase("add")) {
        changed = addBehavior(sender, behaviors, conditionals, trigger, npcClass, parsedBehaviors);
    } else if (args[3].equalsIgnoreCase("remove")) {
        changed = removeBehavior(sender, args, behaviors, conditionals, trigger, npcClass, parsedBehaviors);
    } else {
        changed = manageBehavior(sender, args, behaviors, conditionals, trigger, npcClass, behaviorsLocal);
    }
    if (changed) {
        AUDIT_LOG.saveEntry(npcClass, user(sender), base, "Updated behaviors");
    }
}
Also used : NPCClass(mc.dragons.core.gameobject.npc.NPCClass) NPCConditionalActions(mc.dragons.core.gameobject.npc.NPCConditionalActions) NPCTrigger(mc.dragons.core.gameobject.npc.NPCConditionalActions.NPCTrigger) Document(org.bson.Document)

Aggregations

NPCClass (mc.dragons.core.gameobject.npc.NPCClass)19 Document (org.bson.Document)14 NPCType (mc.dragons.core.gameobject.npc.NPC.NPCType)3 NPCTrigger (mc.dragons.core.gameobject.npc.NPCConditionalActions.NPCTrigger)3 User (mc.dragons.core.gameobject.user.User)3 Material (org.bukkit.Material)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Addon (mc.dragons.core.addon.Addon)2 NPCAddon (mc.dragons.core.addon.NPCAddon)2 GameObject (mc.dragons.core.gameobject.GameObject)2 NPCAction (mc.dragons.core.gameobject.npc.NPCAction)2 NPCCondition (mc.dragons.core.gameobject.npc.NPCCondition)2 NPCConditionalActions (mc.dragons.core.gameobject.npc.NPCConditionalActions)2 Attribute (org.bukkit.attribute.Attribute)2 EntityType (org.bukkit.entity.EntityType)2 Arrays (java.util.Arrays)1 Entry (java.util.Map.Entry)1 Pattern (java.util.regex.Pattern)1