Search in sources :

Example 11 with ItemClass

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

the class ResetProfileCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!requirePermission(sender, PermissionLevel.TESTER))
        return true;
    User target = user(sender);
    if (args.length != 0 && requirePermission(sender, PermissionLevel.ADMIN)) {
        target = lookupUser(sender, args[0]);
    }
    if (target == null)
        return true;
    boolean resetRank = false;
    if (args.length > 1) {
        resetRank = hasPermission(sender, PermissionLevel.ADMIN) && (args[1].equalsIgnoreCase("-r") || args[1].equalsIgnoreCase("-resetrank"));
    }
    target.setXP(0);
    target.setActivePermissionLevel(PermissionLevel.USER);
    target.setGold(0.0);
    target.setChatSpy(false);
    target.setGodMode(false);
    target.setGameMode(GameMode.ADVENTURE, true);
    // target.setDebuggingErrors(false);
    target.setStreamConsoleLevel(Level.OFF);
    target.clearInventory();
    for (SkillType skill : SkillType.values()) {
        target.setSkillLevel(skill, 0);
        target.setSkillProgress(skill, 0.0);
    }
    for (Quest quest : new HashSet<>(target.getQuestProgress().keySet())) {
        target.updateQuestProgress(quest, null);
    }
    target.sendToFloor("BeginnerTown");
    for (ItemClass itemClass : PlayerEventListeners.DEFAULT_INVENTORY) {
        target.giveItem(itemLoader.registerNew(itemClass));
    }
    if (resetRank) {
        target.setRank(Rank.DEFAULT);
    }
    target.getPlayer().sendTitle(ChatColor.DARK_RED + "RESET", ChatColor.RED + "Your stats have been wiped!", 10, 70, 20);
    target.sendActionBar(ChatColor.DARK_RED + "- Your stats have been wiped! -");
    target.debug("Profile forcibly reset");
    if (target.equals(user(sender))) {
        sender.sendMessage(ChatColor.GREEN + "Wiped your stats.");
    } else {
        sender.sendMessage(ChatColor.GREEN + "Wiped " + target.getName() + "'s stats.");
    }
    return true;
}
Also used : ItemClass(mc.dragons.core.gameobject.item.ItemClass) User(mc.dragons.core.gameobject.user.User) SkillType(mc.dragons.core.gameobject.user.SkillType) Quest(mc.dragons.core.gameobject.quest.Quest) HashSet(java.util.HashSet)

Example 12 with ItemClass

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

the class NPCAction method execute.

/**
 * Run the specified action on the specified user and NPC.
 *
 * @param user
 * @param npc
 */
public void execute(final User user, NPC npc) {
    switch(type) {
        case BEGIN_QUEST:
            if (quest.isLocked()) {
                user.getPlayer().sendMessage(ChatColor.RED + "This quest is currently locked! Try again later.");
                return;
            }
            GUI confirmation = new GUI(1, "Accept quest?");
            confirmation.add(new GUIElement(1, Material.EMERALD_BLOCK, ChatColor.GREEN + "✓ " + ChatColor.DARK_GREEN + ChatColor.BOLD + "Accept", ChatColor.GRAY + "You will be unable to interact with\n" + ChatColor.GRAY + "other players, mobs, or NPCs during\n" + ChatColor.GRAY + "quest dialogue.", u -> {
                u.updateQuestProgress(quest, quest.getSteps().get(0));
                u.closeGUI(true);
            }));
            confirmation.add(new GUIElement(4, Material.PAPER, ChatColor.YELLOW + "Quest Information", ChatColor.GRAY + "Quest: " + ChatColor.RESET + quest.getQuestName() + "\n" + ChatColor.GRAY + "Lv Min: " + ChatColor.RESET + quest.getLevelMin()));
            confirmation.add(new GUIElement(7, Material.REDSTONE_BLOCK, ChatColor.RED + "✘ " + ChatColor.DARK_RED + ChatColor.BOLD + "Not Now", ChatColor.GRAY + "You can always come back later to\n" + ChatColor.GRAY + "start the quest.", u -> u.closeGUI(true)));
            confirmation.open(user);
            break;
        case BEGIN_DIALOGUE:
            user.setDialogueBatch(null, npcClass.getName(), dialogue);
            new BukkitRunnable() {

                @Override
                public void run() {
                    if (!user.nextDialogue()) {
                        cancel();
                    }
                }
            }.runTaskTimer(Dragons.getInstance(), 0L, 40L);
            break;
        case TELEPORT_NPC:
            npc.getEntity().teleport(to);
            break;
        case PATHFIND_NPC:
            boolean hasAI = Dragons.getInstance().getBridge().hasAI(npc.getEntity());
            if (hasAI) {
                Dragons.getInstance().getBridge().setEntityAI(npc.getEntity(), false);
            }
            PathfindingUtil.walkToLocation(npc.getEntity(), to, 0.15D, (e) -> {
                if (hasAI) {
                    Dragons.getInstance().getBridge().setEntityAI(e, true);
                }
            });
            break;
        case OPEN_SHOP:
            int rows = 2 + (int) Math.ceil(shopItems.size() / 7.0D);
            GUI shop = new GUI(rows, shopName);
            user.debug("opening shop with " + rows + " rows and name " + shopName + " with " + shopItems.size() + " items");
            int slot = 10;
            for (ShopItem item : shopItems) {
                ItemClass itemClass = itemClassLoader.getItemClassByClassName(item.getItemClassName());
                shop.add(itemClass.getAsGuiElement(slot, item.getQuantity(), item.getCostPer(), false, u -> u.buyItem(itemClass, item.getQuantity(), item.getCostPer())));
                slot++;
                if ((slot + 1) % 9 == 0) {
                    slot += 2;
                }
            }
            shop.open(user);
            break;
    }
}
Also used : Document(org.bson.Document) QuestLoader(mc.dragons.core.gameobject.quest.QuestLoader) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) GUIElement(mc.dragons.core.gui.GUIElement) User(mc.dragons.core.gameobject.user.User) Collectors(java.util.stream.Collectors) ItemClassLoader(mc.dragons.core.gameobject.item.ItemClassLoader) Dragons(mc.dragons.core.Dragons) Quest(mc.dragons.core.gameobject.quest.Quest) List(java.util.List) GameObjectType(mc.dragons.core.gameobject.GameObjectType) Location(org.bukkit.Location) PathfindingUtil(mc.dragons.core.util.PathfindingUtil) GUI(mc.dragons.core.gui.GUI) StorageUtil(mc.dragons.core.storage.StorageUtil) ChatColor(org.bukkit.ChatColor) Material(org.bukkit.Material) ItemClass(mc.dragons.core.gameobject.item.ItemClass) ItemClass(mc.dragons.core.gameobject.item.ItemClass) GUIElement(mc.dragons.core.gui.GUIElement) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) GUI(mc.dragons.core.gui.GUI)

Example 13 with ItemClass

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

the class DragonsDev method onEnable.

public void onEnable() {
    enableDebugLogging();
    saveDefaultConfig();
    dragons = getDragonsInstance();
    buildNotifier = new DiscordNotifier(getConfig().getString("discord-notifier-webhook-url"));
    buildNotifier.setEnabled(getConfig().getBoolean("discord-notifier-enabled"));
    ADVICE_BROADCASTER_PERIOD_SECONDS = getConfig().getInt("staff-advice.period-seconds", 60 * 2);
    BACKUP_FOLDER = getConfig().getString("backup.folder", "C:\\DragonsBackups\\");
    BACKUP_PERIOD_MINUTES = getConfig().getInt("backup.period-minutes", 60);
    BACKUP_RETENTION_DAYS = getConfig().getInt("backup.retention-days", 30);
    MAX_STARS = getConfig().getInt("stars.max-stars", 5);
    MAX_ASSIGN_STARS = getConfig().getInt("stars.max-assign-stars", 10);
    Map<String, Object> shop = getConfig().getConfigurationSection("stars.staff-shop").getValues(false);
    ItemClassLoader itemClassLoader = GameObjectType.ITEM_CLASS.getLoader();
    ItemLoader itemLoader = GameObjectType.ITEM.getLoader();
    int rows = (int) Math.ceil(2 + (double) shop.size() / 7);
    int slot = 10;
    int run = 0;
    STAFF_SHOP = new GUI(rows, "Staff Shop");
    for (Entry<String, Object> entry : shop.entrySet()) {
        String className = entry.getKey();
        int price = (int) entry.getValue();
        ItemClass itemClass = itemClassLoader.getItemClassByClassName(className);
        if (itemClass == null) {
            getLogger().warning("Could not add item to staff shop: No item class \"" + className + "\" exists");
            continue;
        }
        List<String> lore = new ArrayList<>();
        lore.add(ChatColor.GRAY + "Price: " + ChatColor.GOLD + price + TaskLoader.STAR);
        lore.addAll(Item.getCompleteLore(itemClass.getData(), itemClass.getLore().<String>toArray(new String[itemClass.getLore().size()]), null, false, itemClass));
        GUIElement elem = new GUIElement(slot, itemClass.getMaterial(), itemClass.getDecoratedName(), lore, 1, user -> {
            int stars = DevUserHook.getStars(user);
            if (stars < price) {
                user.getPlayer().sendMessage(ChatColor.RED + "This item costs " + price + TaskLoader.STAR + "! (Need " + (price - stars) + " more)");
            } else {
                user.giveItem(itemLoader.registerNew(itemClass));
                dragons.getStaffAlertHandler().sendGenericMessage(PermissionLevel.TESTER, ChatColor.GOLD + user.getName() + " redeemed " + price + TaskLoader.STAR + " for a " + itemClass.getDecoratedName() + "!");
                DevUserHook.addStars(user, -price);
            }
        });
        STAFF_SHOP.add(elem);
        slot++;
        run++;
        if (run == 7) {
            run = 0;
            slot += 2;
        }
    }
    TaskLoader taskLoader = new TaskLoader(dragons);
    dragons.getLightweightLoaderRegistry().register(taskLoader);
    DevUserHook hook = new DevUserHook();
    dragons.getUserHookRegistry().registerHook(hook);
    Bukkit.getPluginManager().registerEvents(hook, this);
    CommandExecutor taskCommands = new TaskCommands(this);
    getCommand("task").setExecutor(taskCommands);
    getCommand("tasks").setExecutor(taskCommands);
    getCommand("taskinfo").setExecutor(taskCommands);
    getCommand("assign").setExecutor(taskCommands);
    getCommand("unassign").setExecutor(taskCommands);
    getCommand("done").setExecutor(taskCommands);
    getCommand("approve").setExecutor(taskCommands);
    getCommand("reject").setExecutor(taskCommands);
    getCommand("close").setExecutor(taskCommands);
    getCommand("taskloc").setExecutor(taskCommands);
    getCommand("tasknote").setExecutor(taskCommands);
    getCommand("gototask").setExecutor(taskCommands);
    getCommand("togglediscordnotifier").setExecutor(taskCommands);
    getCommand("discordnotifyraw").setExecutor(taskCommands);
    getCommand("deletetask").setExecutor(taskCommands);
    getCommand("taskhelp").setExecutor(taskCommands);
    getCommand("reopen").setExecutor(taskCommands);
    getCommand("reloadtasks").setExecutor(taskCommands);
    getCommand("stars").setExecutor(taskCommands);
    getCommand("takestars").setExecutor(taskCommands);
    getCommand("givestars").setExecutor(taskCommands);
    getCommand("getstars").setExecutor(taskCommands);
    getCommand("taskrename").setExecutor(taskCommands);
    getCommand("findtasks").setExecutor(taskCommands);
    getCommand("staffshop").setExecutor(new StaffShopCommand());
    getCommand("backup").setExecutor(new BackupCommand(this));
    getCommand("starttrial").setExecutor(new StartTrialCommand());
    getCommand("tips").setExecutor(new TipsCommand());
    new AdviceBroadcaster().runTaskTimer(this, 20L * ADVICE_BROADCASTER_PERIOD_SECONDS, 20L * ADVICE_BROADCASTER_PERIOD_SECONDS);
    syncPeriodic(() -> {
        if (Bukkit.getOnlinePlayers().size() > 0) {
            backupFloors();
        }
    }, 20 * 60 * BACKUP_PERIOD_MINUTES, 20 * 60 * BACKUP_PERIOD_MINUTES);
}
Also used : ItemClassLoader(mc.dragons.core.gameobject.item.ItemClassLoader) ItemClass(mc.dragons.core.gameobject.item.ItemClass) ArrayList(java.util.ArrayList) CommandExecutor(org.bukkit.command.CommandExecutor) GUIElement(mc.dragons.core.gui.GUIElement) StartTrialCommand(mc.dragons.dev.build.StartTrialCommand) BackupCommand(mc.dragons.dev.build.BackupCommand) ItemLoader(mc.dragons.core.gameobject.item.ItemLoader) DiscordNotifier(mc.dragons.dev.notifier.DiscordNotifier) TipsCommand(mc.dragons.dev.notifier.TipsCommand) TaskCommands(mc.dragons.dev.tasks.TaskCommands) GUI(mc.dragons.core.gui.GUI) AdviceBroadcaster(mc.dragons.dev.notifier.AdviceBroadcaster) TaskLoader(mc.dragons.dev.tasks.TaskLoader)

Example 14 with ItemClass

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

the class ItemCommand method deleteClass.

private void deleteClass(CommandSender sender, String[] args) {
    if (!requirePermission(sender, SystemProfileFlag.GM_DELETE))
        return;
    if (args.length == 1) {
        sender.sendMessage(ChatColor.RED + "Insufficient arguments! /item delete <ClassName>");
        return;
    }
    ItemClass itemClass = lookupItemClass(sender, args[1]);
    if (itemClass == null)
        return;
    registry.removeFromDatabase(itemClass);
    AUDIT_LOG.saveEntry(itemClass, user(sender), "Deleted");
    sender.sendMessage(ChatColor.GREEN + "Deleted item class successfully.");
}
Also used : ItemClass(mc.dragons.core.gameobject.item.ItemClass)

Example 15 with ItemClass

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

the class ItemCommand method displayItemClass.

private void displayItemClass(CommandSender sender, String[] args) {
    ItemClass itemClass = lookupItemClass(sender, args[0]);
    if (itemClass == null)
        return;
    sender.sendMessage(ChatColor.GREEN + "=== Item Class: " + itemClass.getClassName() + " ===");
    sender.sendMessage(ChatColor.GRAY + "Database identifier: " + ChatColor.GREEN + itemClass.getIdentifier().toString());
    sender.sendMessage(ChatColor.GRAY + "Display name: " + ChatColor.GREEN + itemClass.getDecoratedName());
    sender.sendMessage(ChatColor.GRAY + "Level min: " + ChatColor.GREEN + itemClass.getLevelMin());
    sender.sendMessage(ChatColor.GRAY + "Material type: " + ChatColor.GREEN + itemClass.getMaterial().toString());
    sender.sendMessage(ChatColor.GRAY + "Damage: " + ChatColor.GREEN + itemClass.getDamage() + ChatColor.GRAY + " - Armor: " + ChatColor.GREEN + itemClass.getArmor());
    sender.sendMessage(ChatColor.GRAY + "Cooldown: " + ChatColor.GREEN + itemClass.getCooldown());
    sender.sendMessage(ChatColor.GRAY + "Walk Speed Boost: " + ChatColor.GREEN + itemClass.getSpeedBoost());
    sender.sendMessage(ChatColor.GRAY + "Unbreakable: " + ChatColor.GREEN + itemClass.isUnbreakable());
    sender.sendMessage(ChatColor.GRAY + "Undroppable: " + ChatColor.GREEN + itemClass.isUndroppable());
    sender.sendMessage(ChatColor.GRAY + "GM Locked: " + ChatColor.GREEN + itemClass.isGMLocked());
    sender.sendMessage(ChatColor.GRAY + "Max. Stack Size: " + ChatColor.GREEN + itemClass.getMaxStackSize());
    sender.sendMessage(ChatColor.GRAY + "Lore:");
    for (String loreLine : itemClass.getLore()) {
        sender.sendMessage(ChatColor.GREEN + " " + loreLine);
    }
    if (!itemClass.verifyAddons()) {
        sender.sendMessage(ChatColor.RED + "Item class add-on verification failed!");
    }
    sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.GRAY + "[Receive Item] ", "/item give " + itemClass.getClassName(), true, "Click to receive this item"), ObjectMetadataCommand.getClickableMetadataLink(GameObjectType.ITEM_CLASS, itemClass.getUUID()));
}
Also used : ItemClass(mc.dragons.core.gameobject.item.ItemClass)

Aggregations

ItemClass (mc.dragons.core.gameobject.item.ItemClass)16 Document (org.bson.Document)8 User (mc.dragons.core.gameobject.user.User)7 Material (org.bukkit.Material)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Item (mc.dragons.core.gameobject.item.Item)2 ItemClassLoader (mc.dragons.core.gameobject.item.ItemClassLoader)2 Quest (mc.dragons.core.gameobject.quest.Quest)2 GUI (mc.dragons.core.gui.GUI)2 GUIElement (mc.dragons.core.gui.GUIElement)2 ChatColor (org.bukkit.ChatColor)2 Player (org.bukkit.entity.Player)2 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 Dragons (mc.dragons.core.Dragons)1 Addon (mc.dragons.core.addon.Addon)1 ItemAddon (mc.dragons.core.addon.ItemAddon)1 GameObject (mc.dragons.core.gameobject.GameObject)1