From 14ad1299b220be24b6b6575367e0bcc34406f630 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Sun, 13 Feb 2011 09:08:20 +0100 Subject: [PATCH] Faction chat is now something you turn on and off --- src/com/bukkit/mcteam/factions/Commands.java | 16 +++++++++++----- .../bukkit/mcteam/factions/entities/Conf.java | 4 ---- .../mcteam/factions/entities/Follower.java | 15 ++++++++++++++- .../listeners/FactionsEntityListener.java | 6 ++++++ .../listeners/FactionsPlayerListener.java | 12 ++++++++++-- 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/com/bukkit/mcteam/factions/Commands.java b/src/com/bukkit/mcteam/factions/Commands.java index c417d343..028b74c8 100644 --- a/src/com/bukkit/mcteam/factions/Commands.java +++ b/src/com/bukkit/mcteam/factions/Commands.java @@ -28,7 +28,7 @@ public class Commands { pageLines.add(TextUtil.commandHelp(Conf.aliasMap, "*[on|off]", "Show territory map, set optional auto update.")); pageLines.add(TextUtil.commandHelp(Conf.aliasJoin, "[faction name]", "Join a faction")); pageLines.add(TextUtil.commandHelp(Conf.aliasLeave, "", "Leave your faction")); - pageLines.add(TextUtil.commandHelp(Conf.aliasChat, "[message]", "Send message to your faction only.")); + pageLines.add(TextUtil.commandHelp(Conf.aliasChat, "", "Switch faction only chat on and off.")); pageLines.add(TextUtil.commandHelp(Conf.aliasCreate, "[faction tag]", "Create new faction")); pageLines.add(TextUtil.commandHelp(Conf.aliasTag, "[faction tag]", "Change the faction tag")); pageLines.add(TextUtil.commandHelp(Conf.aliasDescription, "[description]", "Change the faction description")); @@ -87,7 +87,7 @@ public class Commands { helpPages.add(pageLines); pageLines = new ArrayList(); - pageLines.add(TextUtil.commandHelp(Conf.aliasVersion, "", "Wich version are you using")); + pageLines.add(TextUtil.commandHelp(Conf.aliasVersion, "", "Which version are you using?")); helpPages.add(pageLines); } @@ -760,10 +760,16 @@ public class Commands { me.sendMessage(Conf.colorSystem+"You are not part of any faction"); return; } - String message = String.format(Conf.factionChatFormat, me.getNameAndRelevant(me), msg); - me.getFaction().sendMessage(message, false); - Logger.getLogger("Minecraft").info("FactionChat "+me.getFaction().getTag()+": "+message); + if ( ! me.isFactionChatting()) { + // Turn on + me.setFactionChatting(true); + me.sendMessage(Conf.colorSystem + "Faction only chat ENABLED."); + } else { + // Turn off + me.setFactionChatting(false); + me.sendMessage(Conf.colorSystem + "Faction only chat DISABLED."); + } } public static void version(Follower me) { diff --git a/src/com/bukkit/mcteam/factions/entities/Conf.java b/src/com/bukkit/mcteam/factions/entities/Conf.java index 84f51cea..42096af1 100644 --- a/src/com/bukkit/mcteam/factions/entities/Conf.java +++ b/src/com/bukkit/mcteam/factions/entities/Conf.java @@ -90,10 +90,6 @@ public class Conf { aliasBase.add("/f"); aliasBase.add("f"); - aliasBase.add("/faction"); - aliasBase.add("faction"); - aliasBase.add("/factions"); - aliasBase.add("factions"); aliasHelp.add("help"); aliasHelp.add("h"); diff --git a/src/com/bukkit/mcteam/factions/entities/Follower.java b/src/com/bukkit/mcteam/factions/entities/Follower.java index f7951bb7..5101519a 100644 --- a/src/com/bukkit/mcteam/factions/entities/Follower.java +++ b/src/com/bukkit/mcteam/factions/entities/Follower.java @@ -18,8 +18,20 @@ public class Follower { private String title; private double power; private long lastPowerUpdateTime; - private boolean mapAutoUpdating; + private boolean mapAutoUpdating; + private boolean factionChatting; + public boolean isFactionChatting() { + if (this.factionId == 0) { + return false; + } + return factionChatting; + } + + public void setFactionChatting(boolean factionChatting) { + this.factionChatting = factionChatting; + } + public Follower() { this.resetFactionData(); this.power = this.getPowerMax(); @@ -29,6 +41,7 @@ public class Follower { protected void resetFactionData() { this.factionId = 0; // The default neutral faction + this.factionChatting = false; this.role = Role.NORMAL; this.title = ""; } diff --git a/src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java b/src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java index c7157bee..26a78472 100644 --- a/src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java +++ b/src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java @@ -6,6 +6,7 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageByProjectileEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityListener; @@ -95,4 +96,9 @@ public class FactionsEntityListener extends EntityListener { } } + + /*@Override + public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) { + event. + }*/ } diff --git a/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java b/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java index 579bdbd0..0f1ed8bd 100644 --- a/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java +++ b/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java @@ -52,6 +52,16 @@ public class FactionsPlayerListener extends PlayerListener{ } // ... it was not a command. This means that it is a chat message! + Follower me = Follower.get(talkingPlayer); + + // Is it a faction chat message? + if (me.isFactionChatting()) { + String message = String.format(Conf.factionChatFormat, me.getNameAndRelevant(me), msg); + me.getFaction().sendMessage(message, false); + Logger.getLogger("Minecraft").info("FactionChat "+me.getFaction().getTag()+": "+message); + event.setCancelled(true); + return; + } // Are we to insert the Faction tag into the format? // If we are not to insert it - we are done. @@ -59,8 +69,6 @@ public class FactionsPlayerListener extends PlayerListener{ return; } - Follower me = Follower.get(talkingPlayer); - String formatStart = event.getFormat().substring(0, Conf.chatTagInsertIndex); String formatEnd = event.getFormat().substring(Conf.chatTagInsertIndex);