Search in sources :

Example 6 with GUI

use of mc.dragons.core.gui.GUI 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

GUI (mc.dragons.core.gui.GUI)6 User (mc.dragons.core.gameobject.user.User)5 GUIElement (mc.dragons.core.gui.GUIElement)5 List (java.util.List)4 ChatColor (org.bukkit.ChatColor)4 Material (org.bukkit.Material)4 Collectors (java.util.stream.Collectors)3 Dragons (mc.dragons.core.Dragons)3 StringUtil (mc.dragons.core.util.StringUtil)3 ArrayList (java.util.ArrayList)2 DragonsCommandExecutor (mc.dragons.core.commands.DragonsCommandExecutor)2 GameObjectType (mc.dragons.core.gameobject.GameObjectType)2 Item (mc.dragons.core.gameobject.item.Item)2 ItemClass (mc.dragons.core.gameobject.item.ItemClass)2 ItemClassLoader (mc.dragons.core.gameobject.item.ItemClassLoader)2 ItemLoader (mc.dragons.core.gameobject.item.ItemLoader)2 UserLoader (mc.dragons.core.gameobject.user.UserLoader)2 StorageUtil (mc.dragons.core.storage.StorageUtil)2 PathfindingUtil (mc.dragons.core.util.PathfindingUtil)2 Location (org.bukkit.Location)2