Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/Channels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
# range is in blocks (if set to a limit).
#
# -1 = no limits
# 0 = same world only
# any positive value = limited range in the same world.
# 0 = same world only
# any positive value = limited range in the same world.

# Text colouring
# --------------
Expand All @@ -49,7 +49,7 @@ Channels:
permission: 'towny.chat.town'
craftIRCTag: 'admin'
range: '-1'

nation:
commands: [nc]
type: NATION
Expand All @@ -59,6 +59,15 @@ Channels:
craftIRCTag: 'admin'
range: '-1'

coalition:
commands: [cc]
type: COALITION
channeltag: '&f[&9CC&f]'
messagecolour: '&d'
permission: 'towny.chat.nation'
craftIRCTag: 'admin'
range: '-1'

admin:
commands: [a,admin]
type: DEFAULT
Expand All @@ -84,4 +93,4 @@ Channels:
messagecolour: '&f'
permission: 'towny.chat.local'
craftIRCTag: 'admin'
range: '100'
range: '100'
2 changes: 2 additions & 0 deletions src/ChatConfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
town: '[townformat]'
# NATION channel types.
nation: '[nationformat]'
# COALITION channel types.
coalition: '[coalitionformat]'
# DEFAULT channel types.
default: '[defaultformat]'

Expand Down
166 changes: 94 additions & 72 deletions src/com/palmergames/bukkit/TownyChat/channels/StandardChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ public void chatProcess(AsyncPlayerChatEvent event) {
Resident resident = null;
Town town = null;
Nation nation = null;
List<Nation> coalition = new ArrayList<Nation>();
String Format = "";

try {
resident = TownyUniverse.getDataSource().getResident(player.getName());
town = resident.getTown();
nation = resident.getTown().getNation();
coalition.addAll(nation.getAllies());
coalition.add(nation);

} catch (NotRegisteredException e1) {
// Not in a town/nation (doesn't matter which)
}
Expand All @@ -65,8 +69,8 @@ public void chatProcess(AsyncPlayerChatEvent event) {
}

/*
* Retrieve the channel specific format
* and compile a set of recipients
* Retrieve the channel specific format
* and compile a set of recipients
*/
switch (exec) {

Expand All @@ -89,6 +93,20 @@ public void chatProcess(AsyncPlayerChatEvent event) {
recipients = new HashSet<Player>(findRecipients(player, TownyUniverse.getOnlinePlayers(nation)));
recipients = checkSpying(recipients);
break;

case COALITION:
if (coalition.isEmpty()) {
event.setCancelled(true);
return;
}
Format = ChatSettings.getRelevantFormatGroup(player).getCOALITION();
//recipients = new HashSet<Player>(findRecipients(player, TownyUniverse.getOnlinePlayers(coalition)));
recipients = new HashSet<Player>();
for(Nation ally : coalition) {
recipients.addAll(findRecipients(player, TownyUniverse.getOnlinePlayers(ally)));
}
recipients = checkSpying(recipients);
break;

case DEFAULT:
Format = ChatSettings.getRelevantFormatGroup(player).getDEFAULT();
Expand Down Expand Up @@ -118,37 +136,37 @@ public void chatProcess(AsyncPlayerChatEvent event) {
event.setFormat(TownyChatFormatter.getChatFormat(chatEvent));

/*
* Set all the listeners for Bukkit to send this message to.
* Set all the listeners for Bukkit to send this message to.
*/
event.getRecipients().clear();
event.getRecipients().addAll(recipients);
if (isHooked()) {
AsyncChatHookEvent hookEvent = new AsyncChatHookEvent(event, this);
Bukkit.getServer().getPluginManager().callEvent(hookEvent);
if (hookEvent.isCancelled()) {
event.setCancelled(true);
return;
}
if (hookEvent.isChanged()) {
event.setMessage(hookEvent.getMessage());
event.setFormat(hookEvent.getFormat());
event.getRecipients().clear();
event.getRecipients().addAll(hookEvent.getRecipients());
}
}
event.getRecipients().clear();
event.getRecipients().addAll(recipients);
if (isHooked()) {
AsyncChatHookEvent hookEvent = new AsyncChatHookEvent(event, this);
Bukkit.getServer().getPluginManager().callEvent(hookEvent);
if (hookEvent.isCancelled()) {
event.setCancelled(true);
return;
}
if (hookEvent.isChanged()) {
event.setMessage(hookEvent.getMessage());
event.setFormat(hookEvent.getFormat());
event.getRecipients().clear();
event.getRecipients().addAll(hookEvent.getRecipients());
}
}

if (notifyjoin) {
if (notifyjoin) {
TownyMessaging.sendMsg(player, "You join " + Colors.White + getName());
}
}

/*
* Perform any last channel specific functions
* like logging this chat and relaying to IRC/Dynmap.
*/
String msg = event.getFormat().replace("%1$s", event.getPlayer().getDisplayName()).replace("%2$s", event.getMessage());
switch (exec) {
/*
* Perform any last channel specific functions
* like logging this chat and relaying to IRC/Dynmap.
*/
String msg = event.getFormat().replace("%1$s", event.getPlayer().getDisplayName()).replace("%2$s", event.getMessage());
switch (exec) {

case TOWN:
//plugin.getLogger().info(ChatTools.stripColour("[Town Msg] " + town.getName() + ": " + msg));
Expand All @@ -157,7 +175,11 @@ public void chatProcess(AsyncPlayerChatEvent event) {
case NATION:
//plugin.getLogger().info(ChatTools.stripColour("[Nation Msg] " + nation.getName() + ": " + msg));
break;


case COALITION:
//plugin.getLogger().info(ChatTools.stripColour("[Coalition Msg] " + nation.getName() + ": " + msg));
break;

case DEFAULT:
break;

Expand All @@ -169,11 +191,11 @@ public void chatProcess(AsyncPlayerChatEvent event) {
dynMap.postPlayerMessageToWeb(player, event.getMessage());
break;
}
// Relay to IRC
CraftIRCHandler ircHander = plugin.getIRC();
if (ircHander != null)
ircHander.IRCSender(msg, getCraftIRCTag());
// Relay to IRC
CraftIRCHandler ircHander = plugin.getIRC();
if (ircHander != null)
ircHander.IRCSender(msg, getCraftIRCTag());

}

Expand Down Expand Up @@ -219,24 +241,24 @@ private Set<Player> findRecipients(Player sender, List<Player> list) {
String sendersName = sender.getName();

// Compile the list of recipients
for (Player test : list) {
/*
* If Not using permissions, or the player has the correct permission node.
*/
if (!plugin.getTowny().isPermissions() || (plugin.getTowny().isPermissions() && TownyUniverse.getPermissionSource().has(test, getPermission()))) {
/*
* If the player is within range for this channel
* or the recipient has the spy mode.
*/
if ((testDistance(sender, test, getRange())) || (plugin.getTowny().hasPlayerMode(test, "spy"))) {
if (bEssentials) {
for (Player test : list) {
/*
* If Not using permissions, or the player has the correct permission node.
*/
if (!plugin.getTowny().isPermissions() || (plugin.getTowny().isPermissions() && TownyUniverse.getPermissionSource().has(test, getPermission()))) {
/*
* If the player is within range for this channel
* or the recipient has the spy mode.
*/
if ((testDistance(sender, test, getRange())) || (plugin.getTowny().hasPlayerMode(test, "spy"))) {
if (bEssentials) {
try {
User targetUser = plugin.getTowny().getEssentials().getUser(test);
/*
* Don't send this message if the user is ignored
* Don't send this message if the user is ignored
*/
if (targetUser.isIgnoredPlayer(sendersName))
continue;
Expand All @@ -245,22 +267,22 @@ private Set<Player> findRecipients(Player sender, List<Player> list) {
}
}

// Spy's can leave channels and we'll respect that
if (absentPlayers != null) {
// Ignore players who have left this channel
if (absentPlayers.containsKey(test.getName())) {
continue;
}
}
recipients.add(test);
}
}
}
//if (recipients.size() <= 1)
// sender.sendMessage(TownySettings.parseSingleLineString("&cYou feel so lonely."));
return recipients;
// Spy's can leave channels and we'll respect that
if (absentPlayers != null) {
// Ignore players who have left this channel
if (absentPlayers.containsKey(test.getName())) {
continue;
}
}
recipients.add(test);
}
}
}
//if (recipients.size() <= 1)
// sender.sendMessage(TownySettings.parseSingleLineString("&cYou feel so lonely."));
return recipients;
}

/**
Expand All @@ -274,13 +296,13 @@ private Set<Player> checkSpying(Set<Player> recipients) {
List<Player> allOnline = new ArrayList<Player>(Arrays.asList(BukkitTools.getOnlinePlayers()));

// Compile the list of recipients with spy perms
for (Player test : allOnline) {
if ((plugin.getTowny().hasPlayerMode(test, "spy")) && !(recipients.contains(test))) {
recipients.add(test);
}
for (Player test : allOnline) {
if ((plugin.getTowny().hasPlayerMode(test, "spy")) && !(recipients.contains(test))) {
recipients.add(test);
}

}
}

return recipients;
}
Expand Down
31 changes: 24 additions & 7 deletions src/com/palmergames/bukkit/TownyChat/channels/channelFormats.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public channelFormats(String name) {
this.name = name.toLowerCase();
}

private String name, GLOBAL, TOWN, NATION, DEFAULT;
private String name, GLOBAL, TOWN, NATION, COALITION, DEFAULT;

/**
* @return a clone of this channelFormats
Expand All @@ -26,6 +26,7 @@ public channelFormats clone(String name) {
clone.setGLOBAL(this.getGLOBAL());
clone.setTOWN(this.getTOWN());
clone.setNATION(this.getNATION());
clone.setCOALITION(this.getCOALITION());
clone.setDEFAULT(this.getDEFAULT());

return clone;
Expand All @@ -40,7 +41,7 @@ public String getName() {

/**
* @param name
* the name to set
* the name to set
*/
public void setName(String name) {
this.name = name;
Expand All @@ -55,7 +56,7 @@ public String getGLOBAL() {

/**
* @param GLOBAL
* the gLOBAL to set
* the gLOBAL to set
*/
public void setGLOBAL(String GLOBAL) {
this.GLOBAL = GLOBAL;
Expand All @@ -70,7 +71,7 @@ public String getTOWN() {

/**
* @param TOWN
* the TOWN to set
* the TOWN to set
*/
public void setTOWN(String TOWN) {
this.TOWN = TOWN;
Expand All @@ -85,11 +86,27 @@ public String getNATION() {

/**
* @param NATION
* the nATION to set
* the NATION to set
*/
public void setNATION(String NATION) {
this.NATION = NATION;
}

/**
* @return the COALITION
*/
public String getCOALITION() {
return this.COALITION;
}

/**

* @param COALITION
* the COALITION to set
*/
public void setCOALITION(String COALITION) {
this.COALITION = COALITION;
}

/**
* @return the DEFAULT
Expand All @@ -100,9 +117,9 @@ public String getDEFAULT() {

/**
* @param DEFAULT
* the dEFAULT to set
* the dEFAULT to set
*/
public void setDEFAULT(String DEFAULT) {
this.DEFAULT = DEFAULT;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
public enum channelTypes {
TOWN,
NATION,
COALITION,
DEFAULT,
GLOBAL,
PRIVATE
}
}
Loading