Search in sources :

Example 1 with MinigameStat

use of au.com.mineauz.minigames.stats.MinigameStat in project Minigames by AddstarMC.

the class Minigame method loadMinigame.

public void loadMinigame() {
    MinigameSave minigame = new MinigameSave(name, "config");
    FileConfiguration cfg = minigame.getConfig();
    for (MinigameModule module : getModules()) {
        if (!module.useSeparateConfig()) {
            module.load(cfg);
            if (module.getFlags() != null) {
                for (String flag : module.getFlags().keySet()) {
                    if (cfg.contains(name + "." + flag))
                        module.getFlags().get(flag).loadValue(name, cfg);
                }
            }
        } else {
            MinigameSave modsave = new MinigameSave("minigames/" + name + "/" + module.getName().toLowerCase());
            module.load(modsave.getConfig());
            if (module.getFlags() != null) {
                for (String flag : module.getFlags().keySet()) {
                    if (modsave.getConfig().contains(name + "." + flag))
                        module.getFlags().get(flag).loadValue(name, modsave.getConfig());
                }
            }
        }
    }
    for (String flag : configFlags.keySet()) {
        if (cfg.contains(name + "." + flag))
            configFlags.get(flag).loadValue(name, cfg);
    }
    if (minigame.getConfig().contains(name + ".whitelistmode")) {
        getBlockRecorder().setWhitelistMode(minigame.getConfig().getBoolean(name + ".whitelistmode"));
    }
    if (minigame.getConfig().contains(name + ".whitelistblocks")) {
        List<String> blocklist = minigame.getConfig().getStringList(name + ".whitelistblocks");
        for (String block : blocklist) {
            Material material = Material.matchMaterial(block);
            if (material == null) {
                material = Material.matchMaterial(block, true);
                if (material == null) {
                    Minigames.log().info(" Failed to match config material.");
                    Minigames.log().info(block + " did not match a material please update config: " + this.name);
                } else {
                    Minigames.log().info(block + " is a legacy material please review the config we will attempt to auto update..but you may want to add newer materials GAME: " + this.name);
                    getBlockRecorder().addWBBlock(material);
                }
            } else {
                getBlockRecorder().addWBBlock(material);
            }
        }
    }
    // Bukkit.getLogger().info("------- Minigame Load -------");
    // Bukkit.getLogger().info("Name: " + getName());
    // Bukkit.getLogger().info("Type: " + getType());
    // Bukkit.getLogger().info("Enabled: " + isEnabled());
    // Bukkit.getLogger().info("-----------------------------");
    final Minigame mgm = this;
    if (getType() == MinigameType.GLOBAL && isEnabled()) {
        Bukkit.getScheduler().scheduleSyncDelayedTask(Minigames.getPlugin(), () -> Minigames.getPlugin().getMinigameManager().startGlobalMinigame(mgm, null));
    }
    getScoreboardData().loadDisplays(minigame, this);
    ListenableFuture<Map<MinigameStat, StatSettings>> settingsFuture = Minigames.getPlugin().getBackend().loadStatSettings(this);
    Minigames.getPlugin().getBackend().addServerThreadCallback(settingsFuture, new FutureCallback<Map<MinigameStat, StatSettings>>() {

        @Override
        public void onSuccess(Map<MinigameStat, StatSettings> result) {
            statSettings.clear();
            statSettings.putAll(result);
            getScoreboardData().reload();
        }

        @Override
        public void onFailure(Throwable t) {
            t.printStackTrace();
        }
    });
    saveMinigame();
}
Also used : MinigameModule(au.com.mineauz.minigames.minigame.modules.MinigameModule) Material(org.bukkit.Material) MenuItemString(au.com.mineauz.minigames.menu.MenuItemString) MinigameSave(au.com.mineauz.minigames.config.MinigameSave) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) MinigameStat(au.com.mineauz.minigames.stats.MinigameStat) StatSettings(au.com.mineauz.minigames.stats.StatSettings) MenuItemSaveMinigame(au.com.mineauz.minigames.menu.MenuItemSaveMinigame)

Example 2 with MinigameStat

use of au.com.mineauz.minigames.stats.MinigameStat in project Minigames by AddstarMC.

the class MySQLStatSaver method saveStats.

private void saveStats(ConnectionHandler handler, StoredGameStats data, UUID player, int minigameId) throws SQLException {
    MinigameUtils.debugMessage("MySQL saving stats for " + player + ", game " + minigameId);
    // Prepare all updates
    for (Entry<MinigameStat, Long> entry : data.getStats().entrySet()) {
        StatFormat format = data.getFormat(entry.getKey());
        // Only store this stat if it's required
        if (entry.getKey().shouldStoreStat(entry.getValue(), format)) {
            queueStat(handler, entry.getKey(), entry.getValue(), format, player, minigameId);
        }
    }
    // Push all to database
    handler.executeBatch(insertStat);
    handler.executeBatch(insertStatTotal);
    handler.executeBatch(insertStatMin);
    handler.executeBatch(insertStatMax);
    MinigameUtils.debugMessage("MySQL completed save for " + player + ", game " + minigameId);
}
Also used : StatFormat(au.com.mineauz.minigames.stats.StatFormat) MinigameStat(au.com.mineauz.minigames.stats.MinigameStat)

Example 3 with MinigameStat

use of au.com.mineauz.minigames.stats.MinigameStat in project Minigames by AddstarMC.

the class SQLiteStatSaver method saveStats.

private void saveStats(ConnectionHandler handler, StoredGameStats data, UUID player, int minigameId) throws SQLException {
    MinigameUtils.debugMessage("SQLite saving stats for " + player + ", game " + minigameId);
    // Prepare all updates
    for (Entry<MinigameStat, Long> entry : data.getStats().entrySet()) {
        StatFormat format = data.getFormat(entry.getKey());
        // Only store this stat if it's required
        if (entry.getKey().shouldStoreStat(entry.getValue(), format)) {
            queueStat(handler, entry.getKey(), entry.getValue(), format, player, minigameId);
        }
    }
    // Push all to database
    handler.executeBatch(insertStat);
    handler.executeBatch(insertStatTotal);
    handler.executeBatch(insertStatMin);
    handler.executeBatch(insertStatMax);
    MinigameUtils.debugMessage("SQLite completed save for " + player + ", game " + minigameId);
}
Also used : StatFormat(au.com.mineauz.minigames.stats.StatFormat) MinigameStat(au.com.mineauz.minigames.stats.MinigameStat)

Example 4 with MinigameStat

use of au.com.mineauz.minigames.stats.MinigameStat in project Minigames by AddstarMC.

the class MenuItemStatisticsSettings method onClick.

@Override
public ItemStack onClick() {
    Menu subMenu = new Menu(6, "Statistics Settings", getContainer().getViewer());
    for (MinigameStat stat : MinigameStats.getAllStats().values()) {
        subMenu.addItem(new MenuItemModifyStatSetting(minigame, stat, Material.WRITABLE_BOOK));
    }
    subMenu.addItem(new MenuItemBack(getContainer()), subMenu.getSize() - 9);
    subMenu.displayMenu(getContainer().getViewer());
    return super.onClick();
}
Also used : MinigameStat(au.com.mineauz.minigames.stats.MinigameStat)

Example 5 with MinigameStat

use of au.com.mineauz.minigames.stats.MinigameStat in project Minigames by AddstarMC.

the class ScoreboardDisplay method displayMenu.

public void displayMenu(MinigamePlayer player) {
    final Menu setupMenu = new Menu(3, "Setup Scoreboard", player);
    StatSettings settings = minigame.getSettings(stat);
    final MenuItemCustom statisticChoice = new MenuItemCustom("Statistic", Material.BOOK_AND_QUILL);
    statisticChoice.setDescription(Arrays.asList(ChatColor.GREEN + settings.getDisplayName()));
    final MenuItemCustom fieldChoice = new MenuItemCustom("Statistic Field", Material.PAPER);
    fieldChoice.setDescription(Arrays.asList(ChatColor.GREEN + field.getTitle()));
    statisticChoice.setClick(new InteractionInterface() {

        @Override
        public Object interact(Object object) {
            Menu childMenu = MinigameStats.createStatSelectMenu(setupMenu, new Callback<MinigameStat>() {

                @Override
                public MinigameStat getValue() {
                    throw new UnsupportedOperationException();
                }

                @Override
                public void setValue(MinigameStat value) {
                    stat = value;
                    StatSettings settings = minigame.getSettings(stat);
                    statisticChoice.setDescription(Arrays.asList(ChatColor.GREEN + settings.getDisplayName()));
                    // Check that the field is valid
                    StatValueField first = null;
                    boolean valid = false;
                    for (StatValueField sfield : settings.getFormat().getFields()) {
                        if (first == null) {
                            first = sfield;
                        }
                        if (sfield == field) {
                            valid = true;
                            break;
                        }
                    }
                    // Update the field
                    if (!valid) {
                        field = first;
                        fieldChoice.setDescription(Arrays.asList(ChatColor.GREEN + value.toString()));
                    }
                }
            });
            childMenu.displayMenu(setupMenu.getViewer());
            return null;
        }
    });
    fieldChoice.setClick(new InteractionInterface() {

        @Override
        public Object interact(Object object) {
            StatSettings settings = minigame.getSettings(stat);
            Menu childMenu = MinigameStats.createStatFieldSelectMenu(setupMenu, settings.getFormat(), new Callback<StatValueField>() {

                @Override
                public StatValueField getValue() {
                    throw new UnsupportedOperationException();
                }

                @Override
                public void setValue(StatValueField value) {
                    field = value;
                    fieldChoice.setDescription(Arrays.asList(ChatColor.GREEN + value.getTitle()));
                }
            });
            childMenu.displayMenu(setupMenu.getViewer());
            return null;
        }
    });
    setupMenu.addItem(statisticChoice);
    setupMenu.addItem(fieldChoice);
    List<String> sbotypes = new ArrayList<String>();
    for (ScoreboardOrder o : ScoreboardOrder.values()) {
        sbotypes.add(o.toString().toLowerCase());
    }
    setupMenu.addItem(new MenuItemList("Scoreboard Order", Material.ENDER_PEARL, new Callback<String>() {

        @Override
        public void setValue(String value) {
            order = ScoreboardOrder.valueOf(value.toUpperCase());
        }

        @Override
        public String getValue() {
            return order.toString().toLowerCase();
        }
    }, sbotypes));
    setupMenu.addItem(new MenuItemScoreboardSave("Create Scoreboard", Material.REDSTONE_TORCH_ON, this), setupMenu.getSize() - 1);
    setupMenu.displayMenu(player);
}
Also used : ArrayList(java.util.ArrayList) MenuItemCustom(au.com.mineauz.minigames.menu.MenuItemCustom) MenuItemScoreboardSave(au.com.mineauz.minigames.menu.MenuItemScoreboardSave) StatValueField(au.com.mineauz.minigames.stats.StatValueField) FutureCallback(com.google.common.util.concurrent.FutureCallback) Callback(au.com.mineauz.minigames.menu.Callback) InteractionInterface(au.com.mineauz.minigames.menu.InteractionInterface) MenuItemList(au.com.mineauz.minigames.menu.MenuItemList) MinigameStat(au.com.mineauz.minigames.stats.MinigameStat) Menu(au.com.mineauz.minigames.menu.Menu) StatSettings(au.com.mineauz.minigames.stats.StatSettings)

Aggregations

MinigameStat (au.com.mineauz.minigames.stats.MinigameStat)5 StatFormat (au.com.mineauz.minigames.stats.StatFormat)2 StatSettings (au.com.mineauz.minigames.stats.StatSettings)2 MinigameSave (au.com.mineauz.minigames.config.MinigameSave)1 Callback (au.com.mineauz.minigames.menu.Callback)1 InteractionInterface (au.com.mineauz.minigames.menu.InteractionInterface)1 Menu (au.com.mineauz.minigames.menu.Menu)1 MenuItemCustom (au.com.mineauz.minigames.menu.MenuItemCustom)1 MenuItemList (au.com.mineauz.minigames.menu.MenuItemList)1 MenuItemSaveMinigame (au.com.mineauz.minigames.menu.MenuItemSaveMinigame)1 MenuItemScoreboardSave (au.com.mineauz.minigames.menu.MenuItemScoreboardSave)1 MenuItemString (au.com.mineauz.minigames.menu.MenuItemString)1 MinigameModule (au.com.mineauz.minigames.minigame.modules.MinigameModule)1 StatValueField (au.com.mineauz.minigames.stats.StatValueField)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 ArrayList (java.util.ArrayList)1 Material (org.bukkit.Material)1 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)1