use of au.com.mineauz.minigames.stats.StatSettings in project Minigames by AddstarMC.
the class ScoreboardCommand method onCommand.
@Override
public boolean onCommand(final CommandSender sender, Minigame ignore, String label, String[] args) {
if (args == null || args.length < 3) {
return false;
}
// Decode arguments
final Minigame minigame = plugin.mdata.getMinigame(args[0]);
if (minigame == null) {
sender.sendMessage(ChatColor.RED + "No Minigame found by the name " + args[0]);
return true;
}
final MinigameStat stat = MinigameStats.getStat(args[1]);
if (stat == null) {
sender.sendMessage(ChatColor.RED + "No statistic found by the name " + args[1]);
return true;
}
final StatSettings settings = minigame.getSettings(stat);
StatValueField field = null;
for (StatValueField f : settings.getFormat().getFields()) {
if (f.name().equalsIgnoreCase(args[2])) {
field = f;
break;
}
}
if (field == null) {
sender.sendMessage(ChatColor.RED + "No field found by the name " + args[2] + " for the statistic " + stat.getDisplayName());
return true;
}
// Prepare defaults for optionals
ScoreboardOrder order;
switch(field) {
case Last:
case Total:
case Max:
order = ScoreboardOrder.DESCENDING;
break;
case Min:
order = ScoreboardOrder.ASCENDING;
break;
default:
throw new AssertionError();
}
int start = 0;
int length = 8;
// Now the optionals
for (int i = 3; i < args.length - 1; i += 2) {
if (args[i].equalsIgnoreCase("-o")) {
// Order
if (args[i + 1].equalsIgnoreCase("asc") || args[i + 1].equalsIgnoreCase("ascending")) {
order = ScoreboardOrder.ASCENDING;
} else if (args[i + 1].equalsIgnoreCase("desc") || args[i + 1].equalsIgnoreCase("descending")) {
order = ScoreboardOrder.DESCENDING;
} else {
sender.sendMessage(ChatColor.RED + "Unknown order " + args[i + 1] + ". Expected asc, ascending, desc, or descending.");
return true;
}
} else if (args[i].equalsIgnoreCase("-l")) {
// Length
if (args[i + 1].matches("[1-9][0-9]*")) {
length = Integer.parseInt(args[i + 1]);
} else {
sender.sendMessage(ChatColor.RED + "Unknown length " + args[i + 1] + ". Expected positive non-zero number");
return true;
}
} else if (args[i].equalsIgnoreCase("-s")) {
// Start
if (args[i + 1].matches("[1-9][0-9]*")) {
start = Integer.parseInt(args[i + 1]) - 1;
} else {
sender.sendMessage(ChatColor.RED + "Unknown start " + args[i + 1] + ". Expected positive non-zero number");
return true;
}
} else {
sender.sendMessage(ChatColor.RED + "Unknown option " + args[i] + ". Expected -o, -l, or -s");
return true;
}
}
final ScoreboardOrder fOrder = order;
final StatValueField fField = field;
sender.sendMessage(ChatColor.GRAY + "Loading scoreboard...");
// Now load the values
ListenableFuture<List<StoredStat>> future = plugin.getBackend().loadStats(minigame, stat, field, order, start, length);
Futures.addCallback(future, new FutureCallback<List<StoredStat>>() {
@Override
public void onSuccess(List<StoredStat> result) {
sender.sendMessage(ChatColor.GREEN + minigame.getName(true) + " Scoreboard: " + settings.getDisplayName() + " - " + fField.getTitle() + " " + fOrder.toString().toLowerCase());
for (StoredStat playerStat : result) {
sender.sendMessage(ChatColor.AQUA + playerStat.getPlayerDisplayName() + ": " + ChatColor.WHITE + stat.displayValue(playerStat.getValue(), settings));
}
}
@Override
public void onFailure(Throwable t) {
sender.sendMessage(ChatColor.RED + "An internal error occured while loading the statistics");
t.printStackTrace();
}
});
return true;
}
use of au.com.mineauz.minigames.stats.StatSettings 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.StatSettings in project Minigames by AddstarMC.
the class SQLiteBackend 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();
}
}
}
use of au.com.mineauz.minigames.stats.StatSettings in project Minigames by AddstarMC.
the class Minigame method getSettings.
public StatSettings getSettings(MinigameStat stat) {
StatSettings settings = statSettings.get(stat);
if (settings == null) {
settings = new StatSettings(stat);
statSettings.put(stat, settings);
}
return settings;
}
use of au.com.mineauz.minigames.stats.StatSettings in project Minigames by AddstarMC.
the class Minigame method loadMinigame.
public void loadMinigame() {
MinigameSave minigame = new MinigameSave(name, "config");
FileConfiguration cfg = minigame.getConfig();
//TODO: Remove me after 1.7
if (cfg.contains(name + ".type")) {
//Minigames.plugin.getLogger().warning("Your configuration files ("+cfg.getCurrentPath()+") are of an old version. They will not be supported past ver1.11");
if (cfg.getString(name + ".type").equals("TEAMS")) {
cfg.set(name + ".type", "MULTIPLAYER");
TeamsModule.getMinigameModule(this).addTeam(TeamColor.RED);
TeamsModule.getMinigameModule(this).addTeam(TeamColor.BLUE);
} else if (cfg.getString(name + ".type").equals("FREE_FOR_ALL")) {
cfg.set(name + ".type", "MULTIPLAYER");
} else if (cfg.getString(name + ".type").equals("TREASURE_HUNT")) {
cfg.set(name + ".type", "GLOBAL");
cfg.set(name + ".scoretype", "treasure_hunt");
cfg.set(name + ".timer", Minigames.plugin.getConfig().getInt("treasurehunt.findtime") * 60);
}
}
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) {
getBlockRecorder().addWBBlock(Material.matchMaterial(block));
}
}
// 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.plugin, new Runnable() {
@Override
public void run() {
Minigames.plugin.mdata.startGlobalMinigame(mgm, null);
}
});
}
getScoreboardData().loadDisplays(minigame, this);
ListenableFuture<Map<MinigameStat, StatSettings>> settingsFuture = Minigames.plugin.getBackend().loadStatSettings(this);
Minigames.plugin.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();
}
Aggregations