Search in sources :

Example 1 with StartTrialCommand

use of mc.dragons.dev.build.StartTrialCommand 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)

Aggregations

ArrayList (java.util.ArrayList)1 ItemClass (mc.dragons.core.gameobject.item.ItemClass)1 ItemClassLoader (mc.dragons.core.gameobject.item.ItemClassLoader)1 ItemLoader (mc.dragons.core.gameobject.item.ItemLoader)1 GUI (mc.dragons.core.gui.GUI)1 GUIElement (mc.dragons.core.gui.GUIElement)1 BackupCommand (mc.dragons.dev.build.BackupCommand)1 StartTrialCommand (mc.dragons.dev.build.StartTrialCommand)1 AdviceBroadcaster (mc.dragons.dev.notifier.AdviceBroadcaster)1 DiscordNotifier (mc.dragons.dev.notifier.DiscordNotifier)1 TipsCommand (mc.dragons.dev.notifier.TipsCommand)1 TaskCommands (mc.dragons.dev.tasks.TaskCommands)1 TaskLoader (mc.dragons.dev.tasks.TaskLoader)1 CommandExecutor (org.bukkit.command.CommandExecutor)1