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();
}
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;
}
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);
}
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();
}
}
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);
}
Aggregations