Skip to content

Commit

Permalink
Adjust message.
Browse files Browse the repository at this point in the history
* Add colors.
* Add summary message on leaving or contest end.
  • Loading branch information
asofold committed Apr 29, 2013
1 parent e8592b9 commit 8e1ee4c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 12 deletions.
12 changes: 11 additions & 1 deletion Archer/archer_lists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,14 @@ might have to remember force too for projectile launch

check if contest is active at all.

print sign lines on /archer ?
print sign lines on /archer ?


***

notify remaining if a player leaves. Add player names that are left.
send summary to leaving players.




2 changes: 1 addition & 1 deletion Archer/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Archer
main: me.asofold.bpl.archer.Archer
version: 1.1.3
version: 1.1.4

commands:
archer:
Expand Down
8 changes: 5 additions & 3 deletions Archer/src/me/asofold/bpl/archer/Archer.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,16 @@ final void onHit(final ProjectileHitEvent event){
if (players.isEmpty() || event.getClass() != ProjectileHitEvent.class) return;
final Projectile projectile = event.getEntity();
final PlayerData data = getPlayerData(projectile);
if (data == null || !data.notifyTargets) return;
if (data == null) return;
final int entityId = projectile.getEntityId();
final Location launchLoc = data.removeLaunch(entityId);
if (launchLoc == null) return;

// TODO: later: add miss / hit events
// TODO: Might remove if shots used up...
// TODO: Might remove if shots used up...

// Target hitting:
if (!data.notifyTargets) return;
final Vector velocity = projectile.getVelocity();
final Location projLoc = projectile.getLocation();
final boolean verbose = settings.verbose;
Expand Down Expand Up @@ -319,7 +321,7 @@ final void onLaunch(final ProjectileLaunchEvent event){
if (tDiff > 60000L) data.clearLaunchs();
final Location launchLoc = data.player.getLocation().add(new Vector(0.0, data.player.getEyeHeight(), 0.0));
// Check active contests for removal due to shots.
List<String> rem = new LinkedList<String>();
final List<String> rem = new LinkedList<String>();
for (final ContestData cd : data.activeContests.values()){
if (cd.contest.addLaunch(data, cd, launchLoc)){
rem.add(cd.contest.name.toLowerCase());
Expand Down
34 changes: 28 additions & 6 deletions Archer/src/me/asofold/bpl/archer/core/Contest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.asofold.bpl.archer.core;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -217,7 +218,7 @@ public boolean checkState() {
return false;
}
started = true;
Bukkit.getServer().broadcastMessage("Contest " + name + " starts with players: " + Utils.joinObjects(getOnlineNameList(), ", "));
Bukkit.getServer().broadcastMessage("Contest " + name + " starts with players: " + Utils.joinObjects(getOnlineNameList(), ChatColor.DARK_GRAY + ", "));
notifyActive(Archer.msgStart + ChatColor.YELLOW + "Contest started: " + ChatColor.GREEN + name);
return true;
}
Expand All @@ -241,13 +242,35 @@ public boolean removePlayer(final PlayerData data, boolean notify) {
// TODO: Message other active players.
// TODO: Set finished.
boolean was = activePlayers.remove(data.playerName.toLowerCase()) != null;
if (notify) notifyActive(Archer.msgStart + data.playerName + " left contest: " + name);
if (notify){
notifyActive(Archer.msgStart + data.playerName + " left contest: " + ChatColor.RED + name + ChatColor.GRAY + ", still in: " + Utils.joinObjects(getOnlineNameList(), ChatColor.DARK_GRAY + ", "));
}
if (started && minPlayers.nonzero() && minPlayers.value > activePlayers.size()){
endContest(null);
}
sendSummary(data, data.activeContests.get(name.toLowerCase()));
return was;
}

private void sendSummary(final PlayerData data, final ContestData cd) {
if (cd == null || !cd.interesting() || data.player == null || !data.player.isOnline()){
return;
}
final StringBuilder b = new StringBuilder(200);
b.append(Archer.msgStart);
b.append("Contest " + name);
b.append(ChatColor.YELLOW + name + ChatColor.GRAY + " summary: ");
b.append(cd.hitsDealt + " hits (" + cd.hitsTaken +" taken) | ");
if (lossScore.nonzero()){
b.append(((int) Math.round(cd.score)) + " score (" + ((int) Math.round(cd.scoreSuffered)) + " taken) | ");
}
if (cd.kills > 0){
b.append(cd.kills + " kills | ");
}
b.append(cd.shotsFired + " shots fired");
data.player.sendMessage(b.toString());
}

/**
*
* @param message If set to null, some standard checks will be done if someone remaining has won.
Expand Down Expand Up @@ -279,7 +302,7 @@ public void endContest(String message) {
}
// Remove players without side effects
for (final PlayerData data : activePlayers.values()){
data.activeContests.remove(name.toLowerCase());
sendSummary(data, data.activeContests.remove(name.toLowerCase()));
}
activePlayers.clear();
this.lastTimeValid = 0;
Expand All @@ -289,10 +312,9 @@ public void endContest(String message) {
public List<String> getOnlineNameList() {
final List<String> names = new ArrayList<String>(activePlayers.size());
for (final PlayerData data : activePlayers.values()){
if (data.player != null && data.player.isOnline()){
names.add(data.playerName);
}
names.add(((data.player != null && data.player.isOnline()) ? ChatColor.WHITE : ChatColor.GRAY) + data.playerName);
}
Collections.sort(names); // TODO: Might re-think, size dependent?
return names;
}

Expand Down
3 changes: 3 additions & 0 deletions Archer/src/me/asofold/bpl/archer/core/ContestData.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ public ContestData(Contest contest){
this.contest = contest;
}

public boolean interesting(){
return shotsFired != 0 || hitsTaken != 0;
}
}
2 changes: 1 addition & 1 deletion Archer/src/me/asofold/bpl/archer/core/ContestManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void checkState(boolean notifyTime) {
final long time = System.currentTimeMillis();
final long timeDiff = time - contest.lastTimeValid;
if (timeDiff > 0 && timeDiff < contest.startDelay.value){
contest.notifyActive(Archer.msgStart + ChatColor.YELLOW + "Contest " + ChatColor.RED + contest.name + ChatColor.YELLOW + " starting in " + ((int) (contest.startDelay.value - timeDiff) / 1000) + " seconds...");
contest.notifyActive(Archer.msgStart + ChatColor.YELLOW + "Contest " + ChatColor.RED + contest.name + ChatColor.YELLOW + " starting in " + ((int) (contest.startDelay.value - timeDiff) / 1000) + " seconds (" + contest.activePlayers.size() + " players)...");
}
}
}
Expand Down

0 comments on commit 8e1ee4c

Please sign in to comment.