Merge pull request #41 from eXeC64/alliancechat

New Alliance chat mode: like faction chat, but includes allied factions as well.
New conf.json setting "allianceChatFormat" for alliance chat message display format.
/f chat now rotates between public chat, alliance chat, and faction chat, and has an optional "mode" parameter which accepts "p", "a", or "f" to switch to the respective chat mode.
An outstanding contribution from eXeC64, thanks.
This commit is contained in:
Brett Flannigan 2011-10-01 01:08:59 -07:00
commit 593580c127
6 changed files with 95 additions and 20 deletions

View File

@ -65,6 +65,7 @@ public class Conf {
public static boolean chatTagPadAfter = true;
public static String chatTagFormat = "%s"+ChatColor.WHITE;
public static String factionChatFormat = "%s"+ChatColor.WHITE+" %s";
public static String allianceChatFormat = "%s"+ChatColor.WHITE+" %s";
public static boolean allowNoSlashCommand = true;

View File

@ -11,6 +11,7 @@ import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.google.gson.reflect.TypeToken;
import com.massivecraft.factions.struct.ChatMode;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.DiscUtil;
@ -50,7 +51,7 @@ public class FPlayer {
private transient boolean autoSafeZoneEnabled;
private transient boolean autoWarZoneEnabled;
private transient boolean loginPvpDisabled;
private boolean factionChatting;
private ChatMode chatMode;
// -------------------------------------------- //
// Construct
@ -80,7 +81,7 @@ public class FPlayer {
}
this.factionId = 0; // The default neutral faction
this.factionChatting = false;
this.chatMode = ChatMode.PUBLIC;
this.role = Role.NORMAL;
this.title = "";
@ -139,15 +140,15 @@ public class FPlayer {
SpoutFeatures.updateAppearances(this.getPlayer());
}
public boolean isFactionChatting() {
if (this.factionId == 0) {
return false;
public ChatMode getChatMode() {
if(this.factionId == 0 ) {
return ChatMode.PUBLIC;
}
return factionChatting;
return chatMode;
}
public void setFactionChatting(boolean factionChatting) {
this.factionChatting = factionChatting;
public void setChatMode(ChatMode chatMode) {
this.chatMode = chatMode;
}
public long getLastLoginTime() {

View File

@ -27,6 +27,7 @@ import com.massivecraft.factions.listeners.FactionsBlockListener;
import com.massivecraft.factions.listeners.FactionsChatEarlyListener;
import com.massivecraft.factions.listeners.FactionsEntityListener;
import com.massivecraft.factions.listeners.FactionsPlayerListener;
import com.massivecraft.factions.struct.ChatMode;
import com.massivecraft.factions.util.JarLoader;
import com.massivecraft.factions.util.MapFLocToStringSetTypeAdapter;
import com.massivecraft.factions.util.MyLocationTypeAdapter;
@ -285,7 +286,7 @@ public class Factions extends JavaPlugin {
FPlayer me = FPlayer.get(player);
if (me == null)
return false;
return me.isFactionChatting();
return me.getChatMode().isAtLeast(ChatMode.ALLIANCE);
}
// Is this chat message actually a Factions command, and thus should be left alone by other plugins?

View File

@ -1,6 +1,7 @@
package com.massivecraft.factions.commands;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.struct.ChatMode;
public class FCommandChat extends FBaseCommand {
@ -8,7 +9,9 @@ public class FCommandChat extends FBaseCommand {
aliases.add("chat");
aliases.add("c");
helpDescription = "Switch faction only chat on and off";
optionalParameters.add("mode");
helpDescription = "Change chat mode";
}
@Override
@ -21,15 +24,34 @@ public class FCommandChat extends FBaseCommand {
return;
}
if ( ! me.isFactionChatting()) {
// Turn on
me.setFactionChatting(true);
sendMessage("Faction-only chat ENABLED.");
if( this.parameters.size() >= 1 ) {
String mode = this.parameters.get(0);
if(mode.startsWith("p")) {
me.setChatMode(ChatMode.PUBLIC);
sendMessage("Public chat mode.");
} else if(mode.startsWith("a")) {
me.setChatMode(ChatMode.ALLIANCE);
sendMessage("Alliance only chat mode.");
} else if(mode.startsWith("f")) {
me.setChatMode(ChatMode.FACTION);
sendMessage("Faction only chat mode.");
} else {
// Turn off
me.setFactionChatting(false);
sendMessage("Faction-only chat DISABLED.");
}
sendMessage("Unrecognised chat mode. Please enter either 'a','f' or 'p'");
}
} else {
if(me.getChatMode() == ChatMode.PUBLIC) {
me.setChatMode(ChatMode.ALLIANCE);
sendMessage("Alliance only chat mode.");
} else if (me.getChatMode() == ChatMode.ALLIANCE ) {
me.setChatMode(ChatMode.FACTION);
sendMessage("Faction only chat mode.");
} else {
me.setChatMode(ChatMode.PUBLIC);
sendMessage("Public chat mode.");
}
}
}
}

View File

@ -11,7 +11,10 @@ import org.bukkit.event.player.PlayerListener;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.ChatMode;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.util.TextUtil;
@ -45,12 +48,31 @@ public class FactionsChatEarlyListener extends PlayerListener{
FPlayer me = FPlayer.get(talkingPlayer);
// Is it a faction chat message?
if (me.isFactionChatting()) {
if (me.getChatMode() == ChatMode.FACTION) {
String message = String.format(Conf.factionChatFormat, me.getNameAndRelevant(me), msg);
me.getFaction().sendMessage(message);
Logger.getLogger("Minecraft").info(ChatColor.stripColor("FactionChat "+me.getFaction().getTag()+": "+message));
event.setCancelled(true);
return;
} else if (me.getChatMode() == ChatMode.ALLIANCE ) {
Faction myFaction = me.getFaction();
String factionAndName = ChatColor.stripColor(me.getNameAndTag());
String message = Conf.colorAlly+factionAndName+ChatColor.WHITE+" "+msg;
//Send message to our own faction
myFaction.sendMessage(message);
for (FPlayer fplayer : FPlayer.getAllOnline()) {
if(myFaction.getRelation(fplayer) == Relation.ALLY) {
//Send to all our allies
fplayer.sendMessage(message);
}
}
Logger.getLogger("Minecraft").info(ChatColor.stripColor("AllianceChat "+me.getFaction().getTag()+": "+message));
event.setCancelled(true);
return;
}
}
}

View File

@ -0,0 +1,28 @@
package com.massivecraft.factions.struct;
public enum ChatMode {
FACTION(2, "faction chat"),
ALLIANCE(1, "alliance chat"),
PUBLIC(0, "public chat");
public final int value;
public final String nicename;
private ChatMode(final int value, final String nicename) {
this.value = value;
this.nicename = nicename;
}
public boolean isAtLeast(ChatMode role) {
return this.value >= role.value;
}
public boolean isAtMost(ChatMode role) {
return this.value <= role.value;
}
@Override
public String toString() {
return this.nicename;
}
}