use of com.playmonumenta.scriptedquests.quests.QuestContext in project scripted-quests by TeamMonumenta.
the class QuestActions method serializeForClientAPI.
public Optional<JsonElement> serializeForClientAPI(QuestContext context) {
if (mDelayTicks <= 0) {
JsonArray a = new JsonArray();
mActions.stream().map(v -> v.serializeForClientAPI(context)).forEach(a::add);
return Optional.of(a);
}
return Optional.empty();
}
use of com.playmonumenta.scriptedquests.quests.QuestContext in project scripted-quests by TeamMonumenta.
the class Race method win.
public void win(int endTime) {
end();
/* Set score on player */
if (mScoreboard != null) {
Score score = mScoreboard.getScore(mPlayer.getName());
if (!score.isScoreSet() || score.getScore() == 0 || endTime < score.getScore()) {
score.setScore(endTime);
/* If the RedisSync plugin is also present, update the score in the leaderboard cache */
if (Bukkit.getServer().getPluginManager().getPlugin("MonumentaRedisSync") != null) {
MonumentaRedisSyncAPI.updateLeaderboardAsync(mScoreboard.getName(), mPlayer.getName(), endTime);
}
// handle new world record
if (mWRTime > endTime) {
String cmdStr = "broadcastcommand tellraw @a [\"\",{\"text\":\"" + mPlayer.getName() + "\",\"color\":\"blue\"},{\"text\":\" has set a new world record for \",\"color\":\"dark_aqua\"},{\"text\":\"" + mName + "\",\"color\":\"blue\"},{\"text\":\"\\nNew time: \",\"color\":\"dark_aqua\"},{\"text\":\"" + RaceUtils.msToTimeString(endTime) + "\",\"color\":\"blue\"}]";
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmdStr);
}
}
}
// header
if (mShowStats) {
mPlayer.sendMessage("" + ChatColor.DARK_AQUA + ChatColor.BOLD + "----====---- " + ChatColor.AQUA + ChatColor.BOLD + "Speedruns" + ChatColor.DARK_AQUA + ChatColor.BOLD + " ----====----\n");
mPlayer.sendMessage(" " + String.format("%s - %s", "" + ChatColor.AQUA + "Race Recap", " " + ChatColor.YELLOW + mName));
mPlayer.sendMessage(" ");
}
// TODO: World record time first
mPlayer.sendMessage(String.format(" %sWorld Record - %16s | %s %s", "" + ChatColor.AQUA + ChatColor.BOLD, "" + RaceUtils.msToTimeString(mWRTime), "" + ((endTime <= mWRTime) ? ("" + ChatColor.AQUA + ChatColor.BOLD + "\u272A") : ("" + ChatColor.GRAY + ChatColor.BOLD + "\u272A")), "" + ((endTime <= mWRTime) ? ("" + ChatColor.BLUE + ChatColor.BOLD + "( -" + RaceUtils.msToTimeString(mWRTime - endTime) + ")") : ("" + ChatColor.RED + ChatColor.BOLD + "( +" + RaceUtils.msToTimeString(endTime - mWRTime) + ")"))));
int bestMedalTime = Integer.MAX_VALUE;
String bestMedalColor = null;
for (RaceTime time : mTimes) {
int medalTime = time.getTime();
if (mShowStats) {
mPlayer.sendMessage(String.format(" %s %s - %16s | %s %s", "" + time.getColor(), "" + time.getLabel(), "" + RaceUtils.msToTimeString(medalTime), "" + ((endTime <= medalTime) ? ("" + time.getColor() + "\u272A") : ("" + ChatColor.GRAY + ChatColor.BOLD + "\u272A")), "" + ((endTime <= medalTime) ? ("" + ChatColor.BLUE + ChatColor.BOLD + "( -" + RaceUtils.msToTimeString(medalTime - endTime) + ")") : ("" + ChatColor.RED + ChatColor.BOLD + "( +" + RaceUtils.msToTimeString(endTime - medalTime) + ")"))));
}
if (endTime <= medalTime) {
if (medalTime < bestMedalTime) {
bestMedalTime = medalTime;
bestMedalColor = time.getColor();
}
}
}
if (mShowStats) {
mPlayer.sendMessage(" ");
}
if (mScoreboard != null && mShowStats) {
int personalBest = mScoreboard.getScore(mPlayer.getName()).getScore();
mPlayer.sendMessage(String.format(" %s Personal Best - %16s | %s", "" + ChatColor.BLUE + ChatColor.BOLD, "" + RaceUtils.msToTimeString(personalBest), "" + ((endTime <= personalBest) ? ("" + ChatColor.BLUE + ChatColor.BOLD + "( -" + RaceUtils.msToTimeString(personalBest - endTime) + ")") : ("" + ChatColor.RED + ChatColor.BOLD + "( +" + RaceUtils.msToTimeString(endTime - personalBest) + ")"))));
}
if (mShowStats) {
mPlayer.sendMessage(String.format(" %s Your Time - %16s", "" + ChatColor.BLUE + ChatColor.BOLD, "" + ChatColor.ITALIC + bestMedalColor + RaceUtils.msToTimeString(endTime)));
}
/* Last thing is to do any actions associated with the race */
for (RaceTime time : mTimes) {
if (endTime <= time.getTime()) {
time.doActions(new QuestContext(mPlugin, mPlayer, null));
}
}
}
use of com.playmonumenta.scriptedquests.quests.QuestContext in project scripted-quests by TeamMonumenta.
the class Race method restart.
public void restart() {
if (mCountdownActive) {
// Refuse this restart request if still starting
return;
}
if (mTimeBar != null) {
mTimeBar.cancel();
}
if (mStartActions != null) {
mStartActions.doActions(new QuestContext(mPlugin, mPlayer, null));
}
mPlayer.addScoreboardTag(RaceManager.PLAYER_RACE_TAG);
mStartTime = System.currentTimeMillis();
mMaxTime = mTimes.get(mTimes.size() - 1).getTime();
// Copy the waypoints to something local to work with
mRemainingWaypoints = new ArrayDeque<RaceWaypoint>(mWaypoints);
mNextWaypoint = mRemainingWaypoints.removeFirst();
// Create the timetracking bar
mTimeBar = new TimeBar(mPlayer, mTimes);
countdownStart();
}
Aggregations