Search in sources :

Example 1 with StatFormat

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

the class MenuItemModifyStatSetting method onClick.

@Override
public ItemStack onClick() {
    Menu subMenu = new Menu(6, "Edit " + stat.getDisplayName(), getContainer().getViewer());
    subMenu.addItem(new MenuItemString("Display Name", Material.NAME_TAG, new Callback<String>() {

        @Override
        public void setValue(String value) {
            minigame.getSettings(stat).setDisplayName(value);
        }

        @Override
        public String getValue() {
            return minigame.getSettings(stat).getDisplayName();
        }
    }));
    if (stat != MinigameStats.Losses) {
        subMenu.addItem(new MenuItemList("Storage Format", Material.ENDER_CHEST, new Callback<String>() {

            @Override
            public void setValue(String value) {
                StatFormat format = StatFormat.valueOf(value);
                minigame.getSettings(stat).setFormat(format);
            }

            @Override
            public String getValue() {
                return minigame.getSettings(stat).getFormat().toString();
            }
        }, Lists.transform(Arrays.asList(StatFormat.values()), Functions.toStringFunction())));
    }
    subMenu.addItem(new MenuItemBack(getContainer()), subMenu.getSize() - 9);
    subMenu.displayMenu(getContainer().getViewer());
    return super.onClick();
}
Also used : StatFormat(au.com.mineauz.minigames.stats.StatFormat)

Example 2 with StatFormat

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

the class ScoreboardCommand method onTabComplete.

@Override
public List<String> onTabComplete(CommandSender sender, Minigame ignore, String alias, String[] args) {
    if (args.length == 1) {
        // Minigame
        List<String> mgs = new ArrayList<String>(plugin.mdata.getAllMinigames().keySet());
        return MinigameUtils.tabCompleteMatch(mgs, args[0]);
    } else if (args.length == 2) {
        // Stat
        return MinigameUtils.tabCompleteMatch(Lists.newArrayList(MinigameStats.getAllStats().keySet()), args[1]);
    } else if (args.length == 3) {
        // Field
        MinigameStat stat = MinigameStats.getStat(args[1]);
        if (stat == null) {
            return null;
        }
        final Minigame minigame = plugin.mdata.getMinigame(args[0]);
        StatFormat format;
        if (minigame == null) {
            format = stat.getFormat();
        } else {
            StatSettings settings = minigame.getSettings(stat);
            format = settings.getFormat();
        }
        String toMatch = args[2].toLowerCase();
        List<String> matches = Lists.newArrayList();
        for (StatValueField field : format.getFields()) {
            if (field.name().toLowerCase().startsWith(toMatch)) {
                matches.add(field.name());
            }
        }
        return matches;
    } else if (args.length > 3) {
        if (args.length % 2 == 0) {
            // Option
            return MinigameUtils.tabCompleteMatch(Arrays.asList("-o", "-l", "-s"), args[args.length - 1]);
        } else {
            // Option Parameter
            String previous = args[args.length - 2].toLowerCase();
            String toMatch = args[args.length - 1].toLowerCase();
            if (previous.equals("-o")) {
                // Order
                return MinigameUtils.tabCompleteMatch(Arrays.asList("asc", "ascending", "desc", "descending"), toMatch);
            }
        // The others cannot be tab completed
        }
    }
    return null;
}
Also used : StatFormat(au.com.mineauz.minigames.stats.StatFormat) StatValueField(au.com.mineauz.minigames.stats.StatValueField) MinigameStat(au.com.mineauz.minigames.stats.MinigameStat) ArrayList(java.util.ArrayList) StatSettings(au.com.mineauz.minigames.stats.StatSettings) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Example 3 with StatFormat

use of au.com.mineauz.minigames.stats.StatFormat 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 4 with StatFormat

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

the class SQLExport method exportStatMetadata.

private void exportStatMetadata() throws SQLException {
    notifyNext("Exporting metadata...");
    ResultSet rs = handler.executeQuery(getStatMetadata);
    try {
        while (rs.next()) {
            String rawFormat = rs.getString("format");
            StatFormat format = null;
            for (StatFormat f : StatFormat.values()) {
                if (f.name().equalsIgnoreCase(rawFormat)) {
                    format = f;
                    break;
                }
            }
            if (format == null) {
                continue;
            }
            callback.acceptStatMetadata(rs.getInt("minigame_id"), rs.getString("stat"), rs.getString("display_name"), format);
            ++notifyCount;
            notifyProgress();
        }
    } finally {
        rs.close();
    }
}
Also used : StatFormat(au.com.mineauz.minigames.stats.StatFormat) ResultSet(java.sql.ResultSet)

Example 5 with StatFormat

use of au.com.mineauz.minigames.stats.StatFormat 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)

Aggregations

StatFormat (au.com.mineauz.minigames.stats.StatFormat)7 MinigameStat (au.com.mineauz.minigames.stats.MinigameStat)5 StatSettings (au.com.mineauz.minigames.stats.StatSettings)3 ResultSet (java.sql.ResultSet)3 ConnectionHandler (au.com.mineauz.minigames.backend.ConnectionHandler)2 SQLException (java.sql.SQLException)2 Minigame (au.com.mineauz.minigames.minigame.Minigame)1 StatValueField (au.com.mineauz.minigames.stats.StatValueField)1 ArrayList (java.util.ArrayList)1