Added Spout notifications for battle and match end as well as monument captures (and tweaked the flag capture ones). Turns out ChatColors work great OOTB with GenericLabel - yay. The War message feed at top left + notifications look awesome.

This commit is contained in:
taoneill 2012-01-08 20:34:15 -05:00
parent 5c3fca5001
commit 0d7f2feef4
9 changed files with 192 additions and 105 deletions

View File

@ -25,6 +25,7 @@ import com.tommytony.war.Warzone;
import com.tommytony.war.config.TeamConfig;
import com.tommytony.war.config.WarConfig;
import com.tommytony.war.config.WarzoneConfig;
import com.tommytony.war.spout.SpoutMessenger;
/**
*
@ -56,6 +57,20 @@ public class WarBlockListener extends BlockListener {
if (monument != null && !monument.hasOwner()) {
monument.capture(team);
List<Team> teams = zone.getTeams();
if (War.war.isSpoutServer()) {
for (Player p : team.getPlayers()) {
SpoutPlayer sp = SpoutManager.getPlayer(p);
if (sp.isSpoutCraftEnabled()) {
sp.sendNotification(
SpoutMessenger.cleanForNotification("Monument " + ChatColor.WHITE + monument.getName()),
SpoutMessenger.cleanForNotification(ChatColor.YELLOW + "capped by " + team.getKind().getColor() + player.getName()),
team.getKind().getMaterial(),
team.getKind().getData(),
5000);
}
}
}
for (Team t : teams) {
t.teamcast("Monument " + monument.getName() + " has been captured by team " + team.getName() + ".");
}
@ -197,6 +212,19 @@ public class WarBlockListener extends BlockListener {
Monument monument = warzone.getMonumentFromCenterBlock(block);
if (monument.hasOwner()) {
List<Team> teams = warzone.getTeams();
if (War.war.isSpoutServer()) {
for (Player p : team.getPlayers()) {
SpoutPlayer sp = SpoutManager.getPlayer(p);
if (sp.isSpoutCraftEnabled()) {
sp.sendNotification(
SpoutMessenger.cleanForNotification("Monument " + ChatColor.WHITE + monument.getName()),
SpoutMessenger.cleanForNotification(ChatColor.YELLOW + "freed by " + team.getKind().getColor() + player.getName()),
Material.OBSIDIAN,
(short)0,
5000);
}
}
}
for (Team t : teams) {
t.teamcast("Team " + monument.getOwnerTeam().getName() + " loses control of monument " + monument.getName());
}
@ -248,8 +276,12 @@ public class WarBlockListener extends BlockListener {
for (Player p : t.getPlayers()) {
SpoutPlayer sp = SpoutManager.getPlayer(p);
if (sp.isSpoutCraftEnabled()) {
String tn = team.getName();
sp.sendNotification(tn.substring(0,1).toUpperCase()+tn.substring(1).toLowerCase()+" stole your Flag!","Stolen by "+player.getName(),lostFlagTeam.getKind().getMaterial(),lostFlagTeam.getKind().getData(),3000);
sp.sendNotification(
SpoutMessenger.cleanForNotification(team.getKind().getColor() + player.getName() + ChatColor.YELLOW + " stole"),
SpoutMessenger.cleanForNotification("your flag!"),
lostFlagTeam.getKind().getMaterial(),
lostFlagTeam.getKind().getData(),
5000);
}
}
}

View File

@ -115,8 +115,8 @@ public class WarEntityListener extends EntityListener {
// Detect death, prevent it and respawn the player
if (event.getDamage() >= d.getHealth()) {
String killMessage = "";
String attackerString = attackerTeam.getKind().getColor() + a.getDisplayName();
String defenderString = defenderTeam.getKind().getColor() + d.getDisplayName();
String attackerString = attackerTeam.getKind().getColor() + a.getName();
String defenderString = defenderTeam.getKind().getColor() + d.getName();
if (attacker.getEntityId() != defender.getEntityId()) {
Material killerWeapon = a.getItemInHand().getType();

View File

@ -37,6 +37,7 @@ import com.tommytony.war.ZoneLobby;
import com.tommytony.war.ZoneSetter;
import com.tommytony.war.config.TeamConfig;
import com.tommytony.war.config.WarzoneConfig;
import com.tommytony.war.spout.SpoutMessenger;
/**
* @author tommytony, Tim Düsterhus
@ -506,6 +507,28 @@ public class WarPlayerListener extends PlayerListener {
synchronized (playerWarzone) {
// flags can be captured at own spawn or own flag pole
playerTeam.addPoint();
Team victim = playerWarzone.getVictimTeamForThief(player.getName());
// Notify everyone
for (Team t : playerWarzone.getTeams()) {
if (War.war.isSpoutServer()) {
for (Player p : t.getPlayers()) {
SpoutPlayer sp = SpoutManager.getPlayer(p);
if (sp.isSpoutCraftEnabled()) {
sp.sendNotification(
SpoutMessenger.cleanForNotification(playerTeam.getKind().getColor() + player.getName() + ChatColor.YELLOW + " captured"),
SpoutMessenger.cleanForNotification(victim.getKind().getColor() + victim.getName() + ChatColor.YELLOW + " flag"),
victim.getKind().getMaterial(),
victim.getKind().getData(),
5000);
}
}
}
t.teamcast(playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE
+ " captured team " + victim.getName() + "'s flag. Team " + playerTeam.getName() + " scores one point.");
}
// Detect win conditions
if (playerTeam.getPoints() >= playerTeam.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)) {
if (playerWarzone.hasPlayerState(player.getName())) {
playerWarzone.restorePlayerState(player);
@ -513,23 +536,10 @@ public class WarPlayerListener extends PlayerListener {
playerWarzone.handleScoreCapReached(player, playerTeam.getName());
event.setTo(playerWarzone.getTeleport());
} else {
// added a point
Team victim = playerWarzone.getVictimTeamForThief(player.getName());
// just added a point
victim.getFlagVolume().resetBlocks(); // bring back flag to team that lost it
victim.initializeTeamFlag();
for (Team t : playerWarzone.getTeams()) {
if (War.war.isSpoutServer()) {
for (Player p : t.getPlayers()) {
SpoutPlayer sp = SpoutManager.getPlayer(p);
if (sp.isSpoutCraftEnabled()) {
String tn = playerTeam.getName();
sp.sendNotification(tn.substring(0,1).toUpperCase()+tn.substring(1).toLowerCase()+" captures Flag!","Capped by "+player.getName(),victim.getKind().getMaterial(),victim.getKind().getData(),3000);
}
}
}
t.teamcast(playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE
+ " captured team " + victim.getName() + "'s flag. Team " + playerTeam.getName() + " scores one point.");
}
playerWarzone.respawnPlayer(event, playerTeam, player);
playerTeam.resetSign();
playerWarzone.getLobby().resetTeamGateSign(playerTeam);

View File

@ -126,6 +126,6 @@ public class WarSpoutListener extends SpoutListener {
}
public static void removeStats(SpoutPlayer sp) {
sp.getMainScreen().removeWidgets(plugin);
//sp.getMainScreen().removeWidgets(plugin);
}
}

View File

@ -36,7 +36,7 @@ public class TeamCommand extends AbstractWarCommand {
for (String part : this.args) {
teamMessage += part + " ";
}
playerTeam.teamcast(teamMessage);
playerTeam.teamcast(teamMessage, false);
return true;
}

View File

@ -356,11 +356,17 @@ public class Team {
public List<Player> getPlayers() {
return this.players;
}
public void teamcast(String message) {
// by default a teamcast is a notification
teamcast(message, true);
}
public void teamcast(String message, boolean isNotification) {
for (Player player : this.players) {
SpoutPlayer sp = SpoutManager.getPlayer(player);
if (sp.isSpoutCraftEnabled()) {
if (sp.isSpoutCraftEnabled() && isNotification) {
// team notifications go to the top left for Spout players to lessen War spam in chat box
War.war.getSpoutMessenger().msg(sp, message);
} else {
War.war.msg(player, message);

View File

@ -36,6 +36,7 @@ import com.tommytony.war.jobs.InitZoneJob;
import com.tommytony.war.jobs.LoadoutResetJob;
import com.tommytony.war.jobs.ScoreCapReachedJob;
import com.tommytony.war.mappers.LoadoutYmlMapper;
import com.tommytony.war.spout.SpoutMessenger;
import com.tommytony.war.utils.PlayerState;
import com.tommytony.war.volumes.ZoneVolume;
@ -720,6 +721,19 @@ public class Warzone {
List<Team> teams = playerWarzone.getTeams();
String scores = "";
for (Team t : teams) {
if (War.war.isSpoutServer()) {
for (Player p : t.getPlayers()) {
SpoutPlayer sp = SpoutManager.getPlayer(p);
if (sp.isSpoutCraftEnabled()) {
sp.sendNotification(
SpoutMessenger.cleanForNotification("Round over! " + ChatColor.WHITE + "Team " + playerTeam.getKind().getColor() + playerTeam.getName()),
SpoutMessenger.cleanForNotification("had no more lives."),
playerTeam.getKind().getMaterial(),
playerTeam.getKind().getData(),
5000);
}
}
}
t.teamcast("The battle is over. Team " + playerTeam.getName() + " lost: " + player.getName() + " died and there were no lives left in their life pool.");
if (t.getPlayers().size() != 0 && !t.getTeamConfig().resolveBoolean(TeamConfig.FLAGPOINTSONLY)) {
@ -839,7 +853,6 @@ public class Warzone {
sp.resetTitle();
}
War.war.msg(player, "Your inventory is being restored.");
if (War.war.getWarHub() != null) {
War.war.getWarHub().resetZoneSign(this);
@ -925,8 +938,6 @@ public class Warzone {
}
public void handleScoreCapReached(Player player, String winnersStr) {
winnersStr = "Score cap reached. Game is over! Winning team(s): " + winnersStr;
winnersStr += ". Resetting warzone and your inventory...";
// Score cap reached. Reset everything.
ScoreCapReachedJob job = new ScoreCapReachedJob(this, winnersStr);
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job);

View File

@ -1,5 +1,7 @@
package com.tommytony.war.jobs;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.getspout.spoutapi.SpoutManager;
@ -10,6 +12,7 @@ import bukkit.tommytony.war.WarSpoutListener;
import com.tommytony.war.Team;
import com.tommytony.war.Warzone;
import com.tommytony.war.spout.SpoutMessenger;
public class ScoreCapReachedJob implements Runnable {
@ -23,9 +26,25 @@ public class ScoreCapReachedJob implements Runnable {
public void run() {
for (Team t : this.zone.getTeams()) {
t.teamcast(this.winnersStr);
if (War.war.isSpoutServer()) {
for (Player p : t.getPlayers()) {
SpoutPlayer sp = SpoutManager.getPlayer(p);
if (sp.isSpoutCraftEnabled()) {
sp.sendNotification(
SpoutMessenger.cleanForNotification("Match won! " + ChatColor.WHITE + "Winners:"),
SpoutMessenger.cleanForNotification(SpoutMessenger.addMissingColor(winnersStr, zone)),
Material.CAKE,
(short)0,
5000);
}
}
}
String winnersStrAndExtra = "Score cap reached. Game is over! Winning team(s): " + this.winnersStr;
winnersStrAndExtra += ". Resetting warzone and your inventory...";
t.teamcast(winnersStr);
boolean isSpoutServer = War.war.isSpoutServer();
for (Player tp : t.getPlayers()) {
if (isSpoutServer) {
SpoutPlayer sp = SpoutManager.getPlayer(tp);
if (sp.isSpoutCraftEnabled()) {

View File

@ -4,24 +4,21 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.gui.Color;
import org.getspout.spoutapi.gui.Container;
import org.getspout.spoutapi.gui.ContainerType;
import org.getspout.spoutapi.gui.GenericContainer;
import org.getspout.spoutapi.gui.GenericLabel;
import org.getspout.spoutapi.gui.WidgetAnchor;
import org.getspout.spoutapi.player.SpoutPlayer;
import bukkit.tommytony.war.War;
import com.tommytony.war.Team;
import com.tommytony.war.TeamKind;
import com.tommytony.war.Warzone;
import bukkit.tommytony.war.War;
public class SpoutMessenger {
Map<String, List<PlayerMessage>> playerMessages = new HashMap<String, List<PlayerMessage>>();
@ -40,7 +37,8 @@ public class SpoutMessenger {
List<PlayerMessage> toRemove = new ArrayList<PlayerMessage>();
for (PlayerMessage message : messages) {
if (System.currentTimeMillis() - message.getSendTime() > 10000) {
if (System.currentTimeMillis() - message.getSendTime() > 12000) {
toRemove.add(message);
}
}
@ -49,7 +47,9 @@ public class SpoutMessenger {
messages.remove(removing);
}
drawMessages(playerName);
if (toRemove.size() > 0) {
drawMessages(playerName);
}
}
}
@ -75,92 +75,101 @@ public class SpoutMessenger {
}
}
public static String cleanForNotification(String toNotify) {
if (toNotify.length() > 26) {
return toNotify.substring(0, 25);
}
return toNotify;
}
private void drawMessages(String playerName) {
SpoutPlayer player = SpoutManager.getPlayer(War.war.getServer().getPlayer(playerName));
List<PlayerMessage> messages = playerMessages.get(playerName);
Player bukkitPlayer = War.war.getServer().getPlayer(playerName);
if (bukkitPlayer != null) {
SpoutPlayer player = SpoutManager.getPlayer(bukkitPlayer);
List<PlayerMessage> messages = playerMessages.get(playerName);
clear(player);
if (messages.size() > 0) {
// Container msgListContainer = new GenericContainer();
// msgListContainer.setAlign(WidgetAnchor.TOP_LEFT);
// msgListContainer.setLayout(ContainerType.VERTICAL);
// remove old widgets
clear(player);
int rank = 0;
int maxLineWidth = 0;
int verticalOffset = 2;
for (PlayerMessage message : messages) {
// Container msgContainer = new GenericContainer();
// msgContainer.setLayout(ContainerType.VERTICAL);
if (messages.size() > 0) {
int rank = 0;
Warzone zone = Warzone.getZoneByPlayerName(playerName);
int verticalOffset = 2;
int horizontalOffset = 2;
String messageStr = "War> " + message.getMessage();
String[] words = messageStr.split(" ");
int noOfLetters = 0;
for (String word : words) {
noOfLetters += word.length() + 1;
for (PlayerMessage message : messages) {
int horizontalOffset = 2;
if (noOfLetters > 50) {
horizontalOffset = 2;
verticalOffset += 12;
String messageStr = "War> " + message.getMessage();
String[] words = messageStr.split(" ");
for (String word : words) {
if (horizontalOffset > 230) {
horizontalOffset = 2;
verticalOffset += 8;
}
word = addMissingColor(word, zone);
GenericLabel label = new GenericLabel(word);
int width = GenericLabel.getStringWidth(word);
label.setAlign(WidgetAnchor.TOP_LEFT);
label.setWidth(width);
label.setHeight(GenericLabel.getStringHeight(word));
label.setX(horizontalOffset);
label.setY(verticalOffset);
player.getMainScreen().attachWidget(War.war, label);
horizontalOffset += width + 2;
}
GenericLabel label = new GenericLabel(word);
label.setTextColor(getWordColor(word, playerName));
verticalOffset += 9;
int width = GenericLabel.getStringWidth(word);
label.setAlign(WidgetAnchor.TOP_LEFT);
label.setWidth(width);
label.setHeight(GenericLabel.getStringHeight(word));
label.setX(horizontalOffset);
label.setY(verticalOffset);
player.getMainScreen().attachWidget(War.war, label);
//label.shiftXPos(horizOffset);
//lineContainer.addChild(label);
//lineWidth += GenericLabel.getStringWidth(word);
horizontalOffset += width + 2;
rank++;
}
// lineContainer.setWidth(lineWidth + 50);
// lineContainer.setHeight(12);
// msgContainer.addChild(lineContainer);
//
// msgContainer.setWidth(maxLineWidth + 50);
// msgContainer.setHeight(40);
// msgListContainer.addChild(msgContainer);
verticalOffset += 12;
rank++;
}
// remove old message list
// new message list
// msgListContainer.setWidth(maxLineWidth);
// msgListContainer.setHeight(200);
// player.getMainScreen().attachWidget(War.war, msgListContainer);
}
}
}
}
private Color getWordColor(String word, String playerName) {
Warzone zone = Warzone.getZoneByPlayerName(playerName);
for (Team team : zone.getTeams()) {
for (Player player : team.getPlayers()) {
if (word.contains(player.getName())) {
return team.getKind().getSpoutColor();
public static String addMissingColor(String word, Warzone zone) {
if (zone != null) {
for (Team team : zone.getTeams()) {
for (Player player : team.getPlayers()) {
if (word.startsWith(player.getName())) {
return team.getKind().getColor() + word + ChatColor.WHITE;
}
}
}
}
for (TeamKind kind : TeamKind.values()) {
if (word.contains(kind.toString())) {
if (word.startsWith(kind.toString())) {
return kind.getColor() + word + ChatColor.WHITE;
}
}
if (word.equals("War>")) {
return ChatColor.GRAY + word + ChatColor.WHITE;
}
// white by default
return word;
}
private Color getWordColor(String word, Warzone zone) {
if (zone != null) {
for (Team team : zone.getTeams()) {
for (Player player : team.getPlayers()) {
if (word.startsWith(player.getName())) {
return team.getKind().getSpoutColor();
}
}
}
}
for (TeamKind kind : TeamKind.values()) {
if (word.startsWith(kind.toString())) {
return kind.getSpoutColor();
}
}