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