Search in sources :

Example 6 with StatSettings

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

the class MySQLBackend method saveStatSettings.

@Override
public void saveStatSettings(Minigame minigame, Collection<StatSettings> settings) {
    ConnectionHandler handler = null;
    try {
        handler = pool.getConnection();
        handler.beginTransaction();
        int minigameId = getMinigameId(handler, minigame);
        for (StatSettings setting : settings) {
            handler.batchUpdate(saveStatSettings, minigameId, setting.getStat().getName(), setting.getDisplayName(), setting.getFormat().name().toUpperCase());
        }
        handler.executeBatch(saveStatSettings);
        handler.endTransaction();
    } catch (SQLException e) {
        e.printStackTrace();
        handler.endTransactionFail();
    } finally {
        if (handler != null) {
            handler.release();
        }
    }
}
Also used : ConnectionHandler(au.com.mineauz.minigames.backend.ConnectionHandler) SQLException(java.sql.SQLException) StatSettings(au.com.mineauz.minigames.stats.StatSettings)

Example 7 with StatSettings

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

the class SQLiteBackend method loadStatSettings.

@Override
public Map<MinigameStat, StatSettings> loadStatSettings(Minigame minigame) {
    ConnectionHandler handler = null;
    try {
        handler = pool.getConnection();
        int minigameId = getMinigameId(handler, minigame);
        ResultSet rs = handler.executeQuery(loadStatSettings, minigameId);
        Map<MinigameStat, StatSettings> settings = Maps.newHashMap();
        try {
            while (rs.next()) {
                String statName = rs.getString("stat");
                String rawFormat = rs.getString("format");
                String displayName = rs.getString("display_name");
                MinigameStat stat = MinigameStats.getStat(statName);
                if (stat == null) {
                    // Just ignore it
                    continue;
                }
                // Decode format
                StatFormat format = null;
                for (StatFormat f : StatFormat.values()) {
                    if (f.name().equalsIgnoreCase(rawFormat)) {
                        format = f;
                        break;
                    }
                }
                if (format == null) {
                    format = stat.getFormat();
                }
                StatSettings setting = new StatSettings(stat, format, displayName);
                settings.put(stat, setting);
            }
            return settings;
        } finally {
            rs.close();
        }
    } catch (SQLException e) {
        e.printStackTrace();
        return Collections.emptyMap();
    } finally {
        if (handler != null) {
            handler.release();
        }
    }
}
Also used : StatFormat(au.com.mineauz.minigames.stats.StatFormat) ConnectionHandler(au.com.mineauz.minigames.backend.ConnectionHandler) MinigameStat(au.com.mineauz.minigames.stats.MinigameStat) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) StatSettings(au.com.mineauz.minigames.stats.StatSettings)

Example 8 with StatSettings

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

the class MySQLBackend method loadStatSettings.

@Override
public Map<MinigameStat, StatSettings> loadStatSettings(Minigame minigame) {
    ConnectionHandler handler = null;
    try {
        handler = pool.getConnection();
        int minigameId = getMinigameId(handler, minigame);
        ResultSet rs = handler.executeQuery(loadStatSettings, minigameId);
        Map<MinigameStat, StatSettings> settings = Maps.newHashMap();
        try {
            while (rs.next()) {
                String statName = rs.getString("stat");
                String rawFormat = rs.getString("format");
                String displayName = rs.getString("display_name");
                MinigameStat stat = MinigameStats.getStat(statName);
                if (stat == null) {
                    // Just ignore it
                    continue;
                }
                // Decode format
                StatFormat format = null;
                for (StatFormat f : StatFormat.values()) {
                    if (f.name().equalsIgnoreCase(rawFormat)) {
                        format = f;
                        break;
                    }
                }
                if (format == null) {
                    format = stat.getFormat();
                }
                StatSettings setting = new StatSettings(stat, format, displayName);
                settings.put(stat, setting);
            }
            return settings;
        } finally {
            rs.close();
        }
    } catch (SQLException e) {
        e.printStackTrace();
        return Collections.emptyMap();
    } finally {
        if (handler != null) {
            handler.release();
        }
    }
}
Also used : StatFormat(au.com.mineauz.minigames.stats.StatFormat) ConnectionHandler(au.com.mineauz.minigames.backend.ConnectionHandler) MinigameStat(au.com.mineauz.minigames.stats.MinigameStat) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) StatSettings(au.com.mineauz.minigames.stats.StatSettings)

Example 9 with StatSettings

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

StatSettings (au.com.mineauz.minigames.stats.StatSettings)9 MinigameStat (au.com.mineauz.minigames.stats.MinigameStat)6 ConnectionHandler (au.com.mineauz.minigames.backend.ConnectionHandler)4 SQLException (java.sql.SQLException)4 StatFormat (au.com.mineauz.minigames.stats.StatFormat)3 StatValueField (au.com.mineauz.minigames.stats.StatValueField)3 ArrayList (java.util.ArrayList)3 Minigame (au.com.mineauz.minigames.minigame.Minigame)2 ResultSet (java.sql.ResultSet)2 MinigameSave (au.com.mineauz.minigames.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 ScoreboardOrder (au.com.mineauz.minigames.minigame.ScoreboardOrder)1 MinigameModule (au.com.mineauz.minigames.minigame.modules.MinigameModule)1