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:
commit
593580c127
@ -65,6 +65,7 @@ public class Conf {
|
|||||||
public static boolean chatTagPadAfter = true;
|
public static boolean chatTagPadAfter = true;
|
||||||
public static String chatTagFormat = "%s"+ChatColor.WHITE;
|
public static String chatTagFormat = "%s"+ChatColor.WHITE;
|
||||||
public static String factionChatFormat = "%s"+ChatColor.WHITE+" %s";
|
public static String factionChatFormat = "%s"+ChatColor.WHITE+" %s";
|
||||||
|
public static String allianceChatFormat = "%s"+ChatColor.WHITE+" %s";
|
||||||
|
|
||||||
public static boolean allowNoSlashCommand = true;
|
public static boolean allowNoSlashCommand = true;
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import com.massivecraft.factions.struct.ChatMode;
|
||||||
import com.massivecraft.factions.struct.Relation;
|
import com.massivecraft.factions.struct.Relation;
|
||||||
import com.massivecraft.factions.struct.Role;
|
import com.massivecraft.factions.struct.Role;
|
||||||
import com.massivecraft.factions.util.DiscUtil;
|
import com.massivecraft.factions.util.DiscUtil;
|
||||||
@ -50,7 +51,7 @@ public class FPlayer {
|
|||||||
private transient boolean autoSafeZoneEnabled;
|
private transient boolean autoSafeZoneEnabled;
|
||||||
private transient boolean autoWarZoneEnabled;
|
private transient boolean autoWarZoneEnabled;
|
||||||
private transient boolean loginPvpDisabled;
|
private transient boolean loginPvpDisabled;
|
||||||
private boolean factionChatting;
|
private ChatMode chatMode;
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// Construct
|
// Construct
|
||||||
@ -80,7 +81,7 @@ public class FPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.factionId = 0; // The default neutral faction
|
this.factionId = 0; // The default neutral faction
|
||||||
this.factionChatting = false;
|
this.chatMode = ChatMode.PUBLIC;
|
||||||
this.role = Role.NORMAL;
|
this.role = Role.NORMAL;
|
||||||
this.title = "";
|
this.title = "";
|
||||||
|
|
||||||
@ -139,15 +140,15 @@ public class FPlayer {
|
|||||||
SpoutFeatures.updateAppearances(this.getPlayer());
|
SpoutFeatures.updateAppearances(this.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFactionChatting() {
|
public ChatMode getChatMode() {
|
||||||
if(this.factionId == 0 ) {
|
if(this.factionId == 0 ) {
|
||||||
return false;
|
return ChatMode.PUBLIC;
|
||||||
}
|
}
|
||||||
return factionChatting;
|
return chatMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFactionChatting(boolean factionChatting) {
|
public void setChatMode(ChatMode chatMode) {
|
||||||
this.factionChatting = factionChatting;
|
this.chatMode = chatMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLastLoginTime() {
|
public long getLastLoginTime() {
|
||||||
|
@ -27,6 +27,7 @@ import com.massivecraft.factions.listeners.FactionsBlockListener;
|
|||||||
import com.massivecraft.factions.listeners.FactionsChatEarlyListener;
|
import com.massivecraft.factions.listeners.FactionsChatEarlyListener;
|
||||||
import com.massivecraft.factions.listeners.FactionsEntityListener;
|
import com.massivecraft.factions.listeners.FactionsEntityListener;
|
||||||
import com.massivecraft.factions.listeners.FactionsPlayerListener;
|
import com.massivecraft.factions.listeners.FactionsPlayerListener;
|
||||||
|
import com.massivecraft.factions.struct.ChatMode;
|
||||||
import com.massivecraft.factions.util.JarLoader;
|
import com.massivecraft.factions.util.JarLoader;
|
||||||
import com.massivecraft.factions.util.MapFLocToStringSetTypeAdapter;
|
import com.massivecraft.factions.util.MapFLocToStringSetTypeAdapter;
|
||||||
import com.massivecraft.factions.util.MyLocationTypeAdapter;
|
import com.massivecraft.factions.util.MyLocationTypeAdapter;
|
||||||
@ -285,7 +286,7 @@ public class Factions extends JavaPlugin {
|
|||||||
FPlayer me = FPlayer.get(player);
|
FPlayer me = FPlayer.get(player);
|
||||||
if (me == null)
|
if (me == null)
|
||||||
return false;
|
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?
|
// Is this chat message actually a Factions command, and thus should be left alone by other plugins?
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.massivecraft.factions.commands;
|
package com.massivecraft.factions.commands;
|
||||||
|
|
||||||
import com.massivecraft.factions.Conf;
|
import com.massivecraft.factions.Conf;
|
||||||
|
import com.massivecraft.factions.struct.ChatMode;
|
||||||
|
|
||||||
public class FCommandChat extends FBaseCommand {
|
public class FCommandChat extends FBaseCommand {
|
||||||
|
|
||||||
@ -8,7 +9,9 @@ public class FCommandChat extends FBaseCommand {
|
|||||||
aliases.add("chat");
|
aliases.add("chat");
|
||||||
aliases.add("c");
|
aliases.add("c");
|
||||||
|
|
||||||
helpDescription = "Switch faction only chat on and off";
|
optionalParameters.add("mode");
|
||||||
|
|
||||||
|
helpDescription = "Change chat mode";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -21,15 +24,34 @@ public class FCommandChat extends FBaseCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! me.isFactionChatting()) {
|
if( this.parameters.size() >= 1 ) {
|
||||||
// Turn on
|
String mode = this.parameters.get(0);
|
||||||
me.setFactionChatting(true);
|
|
||||||
sendMessage("Faction-only chat ENABLED.");
|
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 {
|
} else {
|
||||||
// Turn off
|
sendMessage("Unrecognised chat mode. Please enter either 'a','f' or 'p'");
|
||||||
me.setFactionChatting(false);
|
|
||||||
sendMessage("Faction-only chat DISABLED.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} 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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,10 @@ import org.bukkit.event.player.PlayerListener;
|
|||||||
|
|
||||||
import com.massivecraft.factions.Conf;
|
import com.massivecraft.factions.Conf;
|
||||||
import com.massivecraft.factions.FPlayer;
|
import com.massivecraft.factions.FPlayer;
|
||||||
|
import com.massivecraft.factions.Faction;
|
||||||
import com.massivecraft.factions.Factions;
|
import com.massivecraft.factions.Factions;
|
||||||
|
import com.massivecraft.factions.struct.ChatMode;
|
||||||
|
import com.massivecraft.factions.struct.Relation;
|
||||||
import com.massivecraft.factions.util.TextUtil;
|
import com.massivecraft.factions.util.TextUtil;
|
||||||
|
|
||||||
|
|
||||||
@ -45,12 +48,31 @@ public class FactionsChatEarlyListener extends PlayerListener{
|
|||||||
FPlayer me = FPlayer.get(talkingPlayer);
|
FPlayer me = FPlayer.get(talkingPlayer);
|
||||||
|
|
||||||
// Is it a faction chat message?
|
// Is it a faction chat message?
|
||||||
if (me.isFactionChatting()) {
|
if (me.getChatMode() == ChatMode.FACTION) {
|
||||||
|
|
||||||
String message = String.format(Conf.factionChatFormat, me.getNameAndRelevant(me), msg);
|
String message = String.format(Conf.factionChatFormat, me.getNameAndRelevant(me), msg);
|
||||||
me.getFaction().sendMessage(message);
|
me.getFaction().sendMessage(message);
|
||||||
Logger.getLogger("Minecraft").info(ChatColor.stripColor("FactionChat "+me.getFaction().getTag()+": "+message));
|
Logger.getLogger("Minecraft").info(ChatColor.stripColor("FactionChat "+me.getFaction().getTag()+": "+message));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
28
src/com/massivecraft/factions/struct/ChatMode.java
Normal file
28
src/com/massivecraft/factions/struct/ChatMode.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user