mirror of
https://github.com/taoneill/war.git
synced 2024-12-03 15:43:27 +01:00
Toggleable team chat. Closes gh-317.
Sorry @grinning, I tried to cherry pick your stuff but it did not work _at all_.
This commit is contained in:
parent
d4d5778175
commit
66158ae44b
@ -10,6 +10,7 @@ import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@ -43,6 +44,7 @@ import com.tommytony.war.volume.Volume;
|
||||
*/
|
||||
public class Team {
|
||||
private List<Player> players = new ArrayList<Player>();
|
||||
private List<Player> teamChatPlayers = new ArrayList<Player>();
|
||||
private List<Location> teamSpawns;
|
||||
private Location teamFlag = null;
|
||||
private String name;
|
||||
@ -450,6 +452,9 @@ public class Team {
|
||||
|
||||
public void removePlayer(Player thePlayer) {
|
||||
this.players.remove(thePlayer);
|
||||
synchronized (teamChatPlayers) {
|
||||
this.teamChatPlayers.remove(thePlayer);
|
||||
}
|
||||
this.warzone.dropAllStolenObjects(thePlayer, false);
|
||||
if (War.war.isTagServer()) {
|
||||
TagAPI.refreshPlayer(thePlayer);
|
||||
@ -757,4 +762,52 @@ public class Team {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a team chat message with proper formatting.
|
||||
*
|
||||
* @param sender Player sending the message
|
||||
* @param message Message to send
|
||||
*/
|
||||
public void sendTeamChatMessage(OfflinePlayer sender, String message) {
|
||||
String player = this.getKind().getColor() + ChatColor.stripColor(sender.getName()) + ChatColor.WHITE;
|
||||
String output = String.format("%s: %s", player, message);
|
||||
teamcast(output, false);
|
||||
War.war.getLogger().info("[TeamChat] " + output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player on this team has toggled on team chat. Thread safe.
|
||||
*
|
||||
* @param player Player to check
|
||||
* @return true if the player has toggled on team chat
|
||||
*/
|
||||
public boolean isInTeamChat(Player player) {
|
||||
synchronized (teamChatPlayers) {
|
||||
return this.teamChatPlayers.contains(player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a player to team chat. Thread safe.
|
||||
* @param player Player to add
|
||||
* @throws IllegalArgumentException Player is already in team chat
|
||||
*/
|
||||
public void addTeamChatPlayer(Player player) {
|
||||
Validate.isTrue(!isInTeamChat(player), "Player is already in team chat");
|
||||
synchronized (teamChatPlayers) {
|
||||
this.teamChatPlayers.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a player from team chat. Thread safe.
|
||||
*
|
||||
* @param player Player to remove
|
||||
*/
|
||||
public void removeTeamChatPlayer(Player player) {
|
||||
synchronized (teamChatPlayers) {
|
||||
this.teamChatPlayers.remove(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,13 +30,22 @@ public class TeamCommand extends AbstractWarCommand {
|
||||
return false;
|
||||
}
|
||||
|
||||
ChatColor color = playerTeam.getKind().getColor();
|
||||
String teamMessage = color + player.getName() + ": " + ChatColor.WHITE;
|
||||
for (String part : this.args) {
|
||||
teamMessage += part + " ";
|
||||
}
|
||||
playerTeam.teamcast(teamMessage, false);
|
||||
if (this.args.length < 1) {
|
||||
if (playerTeam.isInTeamChat(player)) {
|
||||
playerTeam.removeTeamChatPlayer(player);
|
||||
this.msg("team.chat.disable");
|
||||
} else {
|
||||
playerTeam.addTeamChatPlayer(player);
|
||||
this.msg("team.chat.enable");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
StringBuilder teamMessage = new StringBuilder();
|
||||
for (String part : this.args) {
|
||||
teamMessage.append(part).append(' ');
|
||||
}
|
||||
playerTeam.sendTeamChatMessage(player, teamMessage.toString());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -17,15 +17,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.getspout.spoutapi.SpoutManager;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
@ -51,9 +43,6 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerExpChangeEvent;
|
||||
|
||||
/**
|
||||
* @author tommytony, Tim Düsterhus
|
||||
* @package bukkit.tommytony.war
|
||||
@ -884,6 +873,15 @@ public class WarPlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerChat(final AsyncPlayerChatEvent event) {
|
||||
Team team = Team.getTeamByPlayerName(event.getPlayer().getName());
|
||||
if (team != null && team.isInTeamChat(event.getPlayer())) {
|
||||
event.setCancelled(true);
|
||||
team.sendTeamChatMessage(event.getPlayer(), event.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void purgeLatestPositions() {
|
||||
this.latestLocations.clear();
|
||||
}
|
||||
|
@ -71,6 +71,9 @@ sign.team.unlimited = Team {0}\n{1}/{2} players\n{3}/{4} pts\nunlimited lives
|
||||
sign.warhub = War hub\n(/warhub)\nPick your\nbattle!
|
||||
sign.warzone = Warzone\n{0}\n{1}/{2} players\n{3} teams
|
||||
|
||||
team.chat.enable = Team chat toggled on. Your regular chat messages will be received by your team only.
|
||||
team.chat.disable = Team chat toggled off.
|
||||
|
||||
use.anvil = You can't use anvils in this warzone!
|
||||
use.enchant = You can't use enchantment tables in this warzone!
|
||||
use.ender = You can't use ender chests while playing in a warzone!
|
||||
|
Loading…
Reference in New Issue
Block a user