From da89ff4ecd03d6df3e9ae29cff2e95fd3b58caa4 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Sat, 12 Feb 2011 18:05:05 +0100 Subject: [PATCH] Better chat integration with other plugins. In fact the whole chat system has been reprogrammed. Fix ascii compass typo. Fix claim at the border of enemy territory bug. New faction chat. Some refactoring --- plugin.yml | 2 +- src/com/bukkit/mcteam/factions/Commands.java | 161 ++++++++------ src/com/bukkit/mcteam/factions/Factions.java | 2 +- .../mcteam/factions/entities/Board.java | 7 +- .../bukkit/mcteam/factions/entities/Conf.java | 128 ++++------- .../bukkit/mcteam/factions/entities/EM.java | 16 +- .../mcteam/factions/entities/Faction.java | 101 ++++----- .../mcteam/factions/entities/Follower.java | 208 ++++++++++++------ .../listeners/FactionsBlockListener.java | 8 +- .../listeners/FactionsEntityListener.java | 8 +- .../listeners/FactionsPlayerListener.java | 59 ++++- .../mcteam/factions/struct/Relation.java | 10 +- .../bukkit/mcteam/factions/struct/Role.java | 14 ++ .../bukkit/mcteam/factions/util/TextUtil.java | 20 ++ src/com/bukkit/mcteam/util/AsciiCompass.java | 2 +- 15 files changed, 417 insertions(+), 329 deletions(-) diff --git a/plugin.yml b/plugin.yml index d146cc62..375a8f38 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,3 +1,3 @@ name: Factions -version: 1.0 beta2 +version: 1.0 beta3 main: com.bukkit.mcteam.factions.Factions \ No newline at end of file diff --git a/src/com/bukkit/mcteam/factions/Commands.java b/src/com/bukkit/mcteam/factions/Commands.java index ef340d03..20840f38 100644 --- a/src/com/bukkit/mcteam/factions/Commands.java +++ b/src/com/bukkit/mcteam/factions/Commands.java @@ -21,15 +21,16 @@ public class Commands { pageLines = new ArrayList(); - pageLines.add(TextUtil.commandHelp(Conf.aliasHelp, "[page]", "Display this, or the next help page")); + pageLines.add(TextUtil.commandHelp(Conf.aliasHelp, "*[page]", "Display a help page")); pageLines.add(TextUtil.commandHelp(Conf.aliasList, "", "List all factions")); pageLines.add(TextUtil.commandHelp(Conf.aliasShow, "*[faction name]", "Show faction information")); // TODO display relations! 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.aliasCreate, "[faction name]", "Create new faction")); - pageLines.add(TextUtil.commandHelp(Conf.aliasName, "[faction name]", "Rename your faction")); - pageLines.add(TextUtil.commandHelp(Conf.aliasDescription, "[description]", "Set the description for your faction")); + pageLines.add(TextUtil.commandHelp(Conf.aliasChat, "[message]", "Send message to your faction only.")); + 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")); helpPages.add(pageLines); pageLines = new ArrayList(); @@ -37,11 +38,11 @@ public class Commands { pageLines.add(TextUtil.commandHelp(Conf.aliasTitle, "[player name] *[title]", "Set or remove a players title")); pageLines.add(TextUtil.commandHelp(Conf.aliasInvite, "[player name]", "Invite player")); pageLines.add(TextUtil.commandHelp(Conf.aliasDeinvite, "[player name]", "Remove a pending invitation")); + pageLines.add(TextUtil.commandHelp(Conf.aliasClaim, "", "Claim the land where you are standing")); + pageLines.add(TextUtil.commandHelp(Conf.aliasUnclaim, "", "Unclaim the land where you are standing")); pageLines.add(TextUtil.commandHelp(Conf.aliasKick, "[player name]", "Kick a player from the faction")); pageLines.add(TextUtil.commandHelp(Conf.aliasModerator, "[player name]", "Give or revoke moderator rights")); pageLines.add(TextUtil.commandHelp(Conf.aliasAdmin, "[player name]", "Hand over your admin rights")); - pageLines.add(TextUtil.commandHelp(Conf.aliasClaim, "", "Claim the land where you are standing")); - pageLines.add(TextUtil.commandHelp(Conf.aliasUnclaim, "", "Unclaim the land where you are standing")); helpPages.add(pageLines); pageLines = new ArrayList(); @@ -95,6 +96,8 @@ public class Commands { // Some utils //----------------------------------------------// + // Update to work with tag and follower names + public static Follower findFollower(Follower me, String name, boolean defaultsToMe) { if (name.length() == 0 && defaultsToMe) { return me; @@ -121,7 +124,7 @@ public class Commands { } // Then faction names - Faction faction = Faction.find(name); + Faction faction = Faction.findByTag(name); if (faction != null) { return faction; } @@ -132,7 +135,7 @@ public class Commands { public static boolean canIAdministerYou(Follower i, Follower you) { if ( ! i.getFaction().equals(you.getFaction())) { - i.sendMessage(you.getFullName(i)+Conf.colorSystem+" is not in the same faction as you."); + i.sendMessage(you.getNameAndRelevant(i)+Conf.colorSystem+" is not in the same faction as you."); return false; } @@ -176,8 +179,12 @@ public class Commands { join(me, TextUtil.implode(tokens)); } else if (Conf.aliasCreate.contains(command)) { create(me, TextUtil.implode(tokens)); - } else if (Conf.aliasName.contains(command)) { + } else if (Conf.aliasTag.contains(command)) { name(me, TextUtil.implode(tokens)); + } else if (Conf.aliasDescription.contains(command)) { + description(me, TextUtil.implode(tokens)); + } else if (Conf.aliasChat.contains(command)) { + chat(me, TextUtil.implode(tokens)); } else if (Conf.aliasList.contains(command)) { list(me); } else if (Conf.aliasShow.contains(command)) { @@ -208,8 +215,6 @@ public class Commands { relation(me, Relation.NEUTRAL, TextUtil.implode(tokens)); } else if (Conf.aliasRelationEnemy.contains(command)) { relation(me, Relation.ENEMY, TextUtil.implode(tokens)); - } else if (Conf.aliasDescription.contains(command)) { - description(me, TextUtil.implode(tokens)); } else if (Conf.aliasVersion.contains(command)) { version(me); } else { @@ -241,14 +246,14 @@ public class Commands { me.sendMessage(errors); if (errors.size() == 0) { - faction.sendMessage(me.getFullName(faction)+Conf.colorSystem+" left your faction."); - me.sendMessage("You left "+faction.getName(me)); + faction.sendMessage(me.getNameAndRelevant(faction)+Conf.colorSystem+" left your faction."); + me.sendMessage("You left "+faction.getTag(me)); } if (faction.getFollowersAll().size() == 0) { // Remove this faction for (Follower follower : Follower.getAll()) { - follower.sendMessage(Conf.colorSystem+"The faction "+faction.getName(follower)+Conf.colorSystem+" was disbandoned."); + follower.sendMessage(Conf.colorSystem+"The faction "+faction.getTag(follower)+Conf.colorSystem+" was disbandoned."); } EM.factionDelete(faction.id); } @@ -264,25 +269,25 @@ public class Commands { me.sendMessage(errors); if (errors.size() > 0) { - faction.sendMessage(me.getFullName(faction)+Conf.colorSystem+" tried to join your faction."); + faction.sendMessage(me.getNameAndRelevant(faction)+Conf.colorSystem+" tried to join your faction."); } else { - me.sendMessage(Conf.colorSystem+"You successfully joined "+faction.getName(me)); - faction.sendMessage(me.getFullName(faction)+Conf.colorSystem+" joined your faction."); + me.sendMessage(Conf.colorSystem+"You successfully joined "+faction.getTag(me)); + faction.sendMessage(me.getNameAndRelevant(faction)+Conf.colorSystem+" joined your faction."); } } - public static void create(Follower me, String name) { + public static void create(Follower me, String tag) { ArrayList errors = new ArrayList(); - if (me.factionId != 0) { + if (me.hasFaction()) { errors.add(Conf.colorSystem+"You must leave your current faction first."); } - if (Faction.isNameTaken(name)) { - errors.add(Conf.colorSystem+"That name is already in use."); + if (Faction.isTagTaken(tag)) { + errors.add(Conf.colorSystem+"That tag is already in use."); } - errors.addAll(Faction.validateName(name)); + errors.addAll(Faction.validateTag(tag)); if (errors.size() > 0) { me.sendMessage(errors); @@ -290,31 +295,34 @@ public class Commands { } Faction faction = EM.factionCreate(); - faction.setName(name); + faction.setTag(tag); faction.save(); me.join(faction); me.role = Role.ADMIN; me.save(); for (Follower follower : Follower.getAll()) { - follower.sendMessage(me.getFullName(follower)+Conf.colorSystem+" created a new faction "+faction.getName(follower)); + follower.sendMessage(me.getNameAndRelevant(follower)+Conf.colorSystem+" created a new faction "+faction.getTag(follower)); } + + me.sendMessage(Conf.colorSystem+"Now update your faction description. Use:"); + me.sendMessage(Conf.colorCommand+Conf.aliasBase.get(0)+" "+Conf.aliasDescription.get(0)+" "+"[description]"); } public static void name(Follower me, String name) { ArrayList errors = new ArrayList(); - if (me.factionId == 0) { + if (me.withoutFaction()) { errors.add(Conf.colorSystem+"You are not part of any faction"); } else if (me.role.value < Role.MODERATOR.value) { errors.add(Conf.colorSystem+"You must be moderator to rename your faction"); } - if (Faction.isNameTaken(name) && ! Faction.toComparisonName(name).equals(me.getFaction().getComparisonName())) { + if (Faction.isTagTaken(name) && ! TextUtil.getComparisonString(name).equals(me.getFaction().getComparisonTag())) { errors.add(Conf.colorSystem+"That name is already taken"); } - errors.addAll(Faction.validateName(name)); + errors.addAll(Faction.validateTag(name)); if (errors.size() > 0) { me.sendMessage(errors); @@ -323,23 +331,23 @@ public class Commands { Faction myFaction = me.getFaction(); - String oldname = myFaction.getName(); - myFaction.setName(name); + String oldname = myFaction.getTag(); + myFaction.setTag(name); // Inform - myFaction.sendMessage(me.getFullName(myFaction)+Conf.colorSystem+" changed the name of your faction to "+Conf.colorMember+name); + myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" changed your faction tag to "+Conf.colorMember+name); for (Faction faction : Faction.getAll()) { if (faction.id == me.factionId) { continue; } - faction.sendMessage(Conf.colorSystem+"The faction "+me.getRelationColor(faction)+oldname+Conf.colorSystem+" renamed themselves to "+me.getRelationColor(faction)+name); + faction.sendMessage(Conf.colorSystem+"The faction "+me.getRelationColor(faction)+oldname+Conf.colorSystem+" chainged their name to "+me.getRelationColor(faction)+name); } } public static void list(Follower me) { me.sendMessage(TextUtil.titleize("Faction List"), false); for (Faction faction : Faction.getAll()) { - me.sendMessage(faction.getName(me)+Conf.colorSystem+" ("+faction.getFollowersWhereOnline(true).size()+" / "+faction.getFollowersAll().size()+" online)"); + me.sendMessage(faction.getTag(me)+Conf.colorSystem+" ("+faction.getFollowersWhereOnline(true).size()+" / "+faction.getFollowersAll().size()+" online)"); } } @@ -352,12 +360,10 @@ public class Commands { Collection mods = faction.getFollowersWhereRole(Role.MODERATOR); Collection normals = faction.getFollowersWhereRole(Role.NORMAL); - me.sendMessage(TextUtil.titleize(faction.getName(me)), false); + me.sendMessage(TextUtil.titleize(faction.getTag(me)), false); me.sendMessage(Conf.colorChrome+"Description: "+Conf.colorSystem+faction.getDescription()); if (faction.id != 0) { - me.sendMessage(Conf.colorChrome+"Power: "+Conf.colorSystem+faction.getPowerRounded()+" / "+faction.getPowerMaxRounded()); // TODO this is not so easy to understand - me.sendMessage(Conf.colorChrome+"Land: "+Conf.colorSystem+faction.getLandRounded()+" / "+faction.getLandMaxRounded()); - + me.sendMessage(Conf.colorChrome+"Land / Power / Maxpower: "+Conf.colorSystem+ faction.getLandRounded()+" / "+faction.getPowerRounded()+" / "+faction.getPowerMaxRounded()); if(faction.getOpen()) { me.sendMessage(Conf.colorChrome+"Joining: "+Conf.colorSystem+"no invitation is needed"); } else { @@ -369,7 +375,7 @@ public class Commands { String offlineList = Conf.colorChrome+"Members offline: "; String listpart; for (Follower follower : admins) { - listpart = follower.getFullName(me)+Conf.colorSystem+", "; + listpart = follower.getNameAndTitle(me)+Conf.colorSystem+", "; if (follower.isOnline()) { onlineList += listpart; } else { @@ -377,7 +383,7 @@ public class Commands { } } for (Follower follower : mods) { - listpart = follower.getFullName(me)+Conf.colorSystem+", "; + listpart = follower.getNameAndTitle(me)+Conf.colorSystem+", "; if (follower.isOnline()) { onlineList += listpart; } else { @@ -385,7 +391,7 @@ public class Commands { } } for (Follower follower : normals) { - listpart = follower.getFullName(me)+Conf.colorSystem+", "; + listpart = follower.getNameAndTitle(me)+Conf.colorSystem+", "; if (follower.isOnline()) { onlineList += listpart; } else { @@ -411,6 +417,9 @@ public class Commands { // Turn on me.setMapAutoUpdating(true); me.sendMessage(Conf.colorSystem + "Map auto update ENABLED."); + + // And show the map once + showMap(me,""); } else { // Turn off me.setMapAutoUpdating(false); @@ -431,9 +440,8 @@ public class Commands { me.sendMessage(errors); if (errors.size() == 0) { - ChatColor relationColor = me.getRelationColor(follower); - follower.sendMessage(relationColor+me.getFullName()+Conf.colorSystem+" invited you to "+relationColor+me.getFaction().getName()); - me.getFaction().sendMessage(me.getFullName(me)+Conf.colorSystem+" invited "+follower.getFullName(me)+Conf.colorSystem+" to your faction."); + follower.sendMessage(me.getNameAndRelevant(follower)+Conf.colorSystem+" invited you to "+me.getFaction().getTag(follower)); + me.getFaction().sendMessage(me.getNameAndRelevant(me)+Conf.colorSystem+" invited "+follower.getNameAndRelevant(me)+Conf.colorSystem+" to your faction."); } } @@ -447,8 +455,8 @@ public class Commands { me.sendMessage(errors); if (errors.size() == 0) { - follower.sendMessage(me.getFullName(follower)+Conf.colorSystem+" revoked your invitation to "+me.getFaction().getName(follower)); - me.getFaction().sendMessage(me.getFullName(me)+Conf.colorSystem+" revoked "+follower.getFullName(me)+"'s"+Conf.colorSystem+" invitation."); + follower.sendMessage(me.getNameAndRelevant(follower)+Conf.colorSystem+" revoked your invitation to "+me.getFaction().getTag(follower)); + me.getFaction().sendMessage(me.getNameAndRelevant(me)+Conf.colorSystem+" revoked "+follower.getNameAndRelevant(me)+"'s"+Conf.colorSystem+" invitation."); } } @@ -463,12 +471,12 @@ public class Commands { String open = myFaction.getOpen() ? "open" : "closed"; // Inform - myFaction.sendMessage(me.getFullName(myFaction)+Conf.colorSystem+" changed the faction to "+open); + myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" changed the faction to "+open); for (Faction faction : Faction.getAll()) { if (faction.id == me.factionId) { continue; } - faction.sendMessage(Conf.colorSystem+"The faction "+myFaction.getName(faction)+Conf.colorSystem+" is now "+open); + faction.sendMessage(Conf.colorSystem+"The faction "+myFaction.getTag(faction)+Conf.colorSystem+" is now "+open); } } @@ -496,7 +504,7 @@ public class Commands { // Inform Faction myFaction = me.getFaction(); - myFaction.sendMessage(me.getFullName(myFaction)+Conf.colorSystem+" changed a title: "+you.getFullName(myFaction)); + myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" changed a title: "+you.getNameAndRelevant(myFaction)); } public static void kick(Follower me, String name) { @@ -515,8 +523,8 @@ public class Commands { if (errors.size() == 0) { Faction myFaction = me.getFaction(); - myFaction.sendMessage(me.getFullName(myFaction)+Conf.colorSystem+" kicked "+you.getFullName(myFaction)+Conf.colorSystem+" from the faction! :O"); - you.sendMessage(me.getFullName(you)+Conf.colorSystem+" kicked you from "+myFaction.getName(you)+Conf.colorSystem+"! :O"); + myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" kicked "+you.getNameAndRelevant(myFaction)+Conf.colorSystem+" from the faction! :O"); + you.sendMessage(me.getNameAndRelevant(you)+Conf.colorSystem+" kicked you from "+myFaction.getTag(you)+Conf.colorSystem+"! :O"); } } @@ -537,8 +545,7 @@ public class Commands { } if (targetFollower.factionId != me.factionId) { - ChatColor relationColor = me.getRelationColor(targetFollower); - me.sendMessage(relationColor+targetFollower.getFullName()+Conf.colorSystem+" is not a member in your faction."); + me.sendMessage(targetFollower.getNameAndRelevant(me)+Conf.colorSystem+" is not a member in your faction."); return; } @@ -554,26 +561,26 @@ public class Commands { // Inform all players for (Follower follower : Follower.getAll()) { if (follower.factionId == me.factionId) { - follower.sendMessage(Conf.colorMember+me.getFullName()+Conf.colorSystem+" gave "+Conf.colorMember+targetFollower.getFullName()+Conf.colorSystem+" the leadership of your faction."); + follower.sendMessage(me.getNameAndRelevant(me)+Conf.colorSystem+" gave "+targetFollower.getNameAndRelevant(me)+Conf.colorSystem+" the leadership of your faction."); } else { - follower.sendMessage(me.getFullName(follower)+Conf.colorSystem+" gave "+targetFollower.getFullName(follower)+Conf.colorSystem+" the leadership of "+me.getFaction().getName(follower)); + follower.sendMessage(me.getNameAndRelevant(follower)+Conf.colorSystem+" gave "+targetFollower.getNameAndRelevant(follower)+Conf.colorSystem+" the leadership of "+me.getFaction().getTag(follower)); } } } else if (targetRole == Role.MODERATOR) { if (targetFollower.role == Role.MODERATOR) { // Revoke targetFollower.role = Role.NORMAL; - me.getFaction().sendMessage(Conf.colorMember+targetFollower.getName()+Conf.colorSystem+" is no longer moderator in your faction."); + me.getFaction().sendMessage(targetFollower.getNameAndRelevant(me.getFaction())+Conf.colorSystem+" is no longer moderator in your faction."); } else { // Give targetFollower.role = Role.MODERATOR; - me.getFaction().sendMessage(Conf.colorMember+targetFollower.getName()+Conf.colorSystem+" was promoted to moderator in your faction."); + me.getFaction().sendMessage(targetFollower.getNameAndRelevant(me.getFaction())+Conf.colorSystem+" was promoted to moderator in your faction."); } } } public static void claim(Follower me) { - if (me.factionId == 0) { + if (me.withoutFaction()) { me.sendMessage(Conf.colorSystem+"You are not part of any faction."); return; } @@ -592,7 +599,7 @@ public class Commands { return; } - if (myFaction.getLandRounded() >= myFaction.getLandMaxRounded()) { + if (myFaction.getLandRounded() >= myFaction.getPowerRounded()) { me.sendMessage(Conf.colorSystem+"You can't claim more land! You need more power!"); return; } @@ -603,8 +610,8 @@ public class Commands { } if (otherFaction.id != 0) { - if ( ! otherFaction.hasLandInflation()) { // TODO more messages - me.sendMessage(me.getRelationColor(otherFaction)+otherFaction.getName()+Conf.colorSystem+" owns this land and are strong enough to keep it."); + if ( ! otherFaction.hasLandInflation()) { // TODO more messages WARN current faction most importantly + me.sendMessage(me.getRelationColor(otherFaction)+otherFaction.getTag()+Conf.colorSystem+" owns this land and are strong enough to keep it."); return; } @@ -615,20 +622,19 @@ public class Commands { } if (otherFaction.id == 0) { - myFaction.sendMessage(Conf.colorMember+me.getFullName()+Conf.colorSystem+" claimed some new land :D"); + myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" claimed some new land :D"); } else { // ASDF claimed some of your land 450 blocks NNW of you. // ASDf claimed some land from FACTION NAME - ChatColor relcolor = myFaction.getRelationColor(otherFaction); - otherFaction.sendMessage(relcolor+me.getFullName()+Conf.colorSystem+" from "+relcolor+myFaction.getName()+Conf.colorSystem+" stole some of your land :O"); - myFaction.sendMessage(Conf.colorMember+me.getFullName()+Conf.colorSystem+" claimed some land from "+relcolor+otherFaction.getName()); + otherFaction.sendMessage(me.getNameAndRelevant(otherFaction)+Conf.colorSystem+" stole some of your land :O"); + myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" claimed some land from "+otherFaction.getTag(myFaction)); } Board.claim(coord, myFaction); } public static void unclaim(Follower me) { - if (me.factionId == 0) { + if (me.withoutFaction()) { me.sendMessage(Conf.colorSystem+"You are not part of any faction"); return; } @@ -646,11 +652,11 @@ public class Commands { } Board.unclaim(coord); - me.getFaction().sendMessage(Conf.colorMember+me.getFullName()+Conf.colorSystem+" unclaimed some land..."); + me.getFaction().sendMessage(me.getNameAndRelevant(me)+Conf.colorSystem+" unclaimed some land."); } public static void relation(Follower me, Relation whishedRelation, String otherFactionName) { - if (me.factionId == 0) { + if (me.withoutFaction()) { me.sendMessage(Conf.colorSystem+"You are not part of any faction."); return; } @@ -685,17 +691,17 @@ public class Commands { Relation currentRelation = myFaction.getRelation(otherFaction); ChatColor currentRelationColor = currentRelation.getColor(); if (whishedRelation == currentRelation) { - otherFaction.sendMessage(Conf.colorSystem+"Your faction is now "+currentRelationColor+whishedRelation.toString()+Conf.colorSystem+" to "+currentRelationColor+myFaction.getName()); - myFaction.sendMessage(Conf.colorSystem+"Your faction is now "+currentRelationColor+whishedRelation.toString()+Conf.colorSystem+" to "+currentRelationColor+otherFaction.getName()); + otherFaction.sendMessage(Conf.colorSystem+"Your faction is now "+currentRelationColor+whishedRelation.toString()+Conf.colorSystem+" to "+currentRelationColor+myFaction.getTag()); + myFaction.sendMessage(Conf.colorSystem+"Your faction is now "+currentRelationColor+whishedRelation.toString()+Conf.colorSystem+" to "+currentRelationColor+otherFaction.getTag()); } else { - otherFaction.sendMessage(currentRelationColor+myFaction.getName()+Conf.colorSystem+ " whishes to be your "+whishedRelation.getColor()+whishedRelation.toString()); - otherFaction.sendMessage(Conf.colorSystem+"Type "+Conf.colorCommand+Conf.aliasBase.get(0)+" "+whishedRelation+" "+myFaction.getName()+Conf.colorSystem+" to accept."); - myFaction.sendMessage(currentRelationColor+otherFaction.getName()+Conf.colorSystem+ " were informed you wishes to be "+whishedRelation.getColor()+whishedRelation); + otherFaction.sendMessage(currentRelationColor+myFaction.getTag()+Conf.colorSystem+ " whishes to be your "+whishedRelation.getColor()+whishedRelation.toString()); + otherFaction.sendMessage(Conf.colorSystem+"Type "+Conf.colorCommand+Conf.aliasBase.get(0)+" "+whishedRelation+" "+myFaction.getTag()+Conf.colorSystem+" to accept."); + myFaction.sendMessage(currentRelationColor+otherFaction.getTag()+Conf.colorSystem+ " were informed you wishes to be "+whishedRelation.getColor()+whishedRelation); } } public static void description(Follower me, String desc) { - if (me.factionId == 0) { + if (me.withoutFaction()) { me.sendMessage(Conf.colorSystem+"You are not part of any faction"); return; } @@ -711,11 +717,20 @@ public class Commands { // Broadcast the description to everyone for (Follower follower : EM.followerGetAll()) { - follower.sendMessage(Conf.colorSystem+"The faction "+follower.getRelationColor(me)+me.getFaction().getName()+Conf.colorSystem+" changed their description to:"); + follower.sendMessage(Conf.colorSystem+"The faction "+follower.getRelationColor(me)+me.getFaction().getTag()+Conf.colorSystem+" changed their description to:"); follower.sendMessage(Conf.colorSystem+desc); } } + public static void chat(Follower me, String msg) { + if (me.withoutFaction()) { + me.sendMessage(Conf.colorSystem+"You are not part of any faction"); + return; + } + + me.getFaction().sendMessage(String.format(Conf.factionChatFormat, me.getNameAndRelevant(me), msg), false); + } + public static void version(Follower me) { me.sendMessage(Conf.colorSystem+"You are running "+Factions.desc.getFullName()); } diff --git a/src/com/bukkit/mcteam/factions/Factions.java b/src/com/bukkit/mcteam/factions/Factions.java index 13c5ec55..72823380 100644 --- a/src/com/bukkit/mcteam/factions/Factions.java +++ b/src/com/bukkit/mcteam/factions/Factions.java @@ -45,9 +45,9 @@ public class Factions extends JavaPlugin { // Register events PluginManager pm = instance.getPluginManager(); + pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Event.Priority.Highest, this); pm.registerEvent(Event.Type.PLAYER_COMMAND, this.playerListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_JOIN, this.playerListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_QUIT, this.playerListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_DEATH, this.entityListener, Event.Priority.Normal, this); diff --git a/src/com/bukkit/mcteam/factions/entities/Board.java b/src/com/bukkit/mcteam/factions/entities/Board.java index 0116f165..7eb72c45 100644 --- a/src/com/bukkit/mcteam/factions/entities/Board.java +++ b/src/com/bukkit/mcteam/factions/entities/Board.java @@ -38,13 +38,16 @@ public class Board { save(); } + + // Is this coord NOT completely surrounded by coords claimed by the same faction? + // Simpler: Is there any nearby coord with a faction other than the faction here? public static boolean isBorderCoord(Coord coord) { Faction faction = Board.getFactionAt(coord); Coord a = coord.getRelative(1, 0); Coord b = coord.getRelative(-1, 0); Coord c = coord.getRelative(0, 1); Coord d = coord.getRelative(0, -1); - return faction != a.getFaction() && faction != b.getFaction() && faction != c.getFaction() && faction != d.getFaction(); + return faction != a.getFaction() || faction != b.getFaction() || faction != c.getFaction() || faction != d.getFaction(); } public static void purgeFaction(Faction faction) { @@ -84,7 +87,7 @@ public class Board { */ public static ArrayList getMap(Faction faction, Coord coord, double inDegrees) { ArrayList ret = new ArrayList(); - ret.add(TextUtil.titleize("("+coord+") "+coord.getFaction().getName(faction))); + ret.add(TextUtil.titleize("("+coord+") "+coord.getFaction().getTag(faction))); int halfWidth = Conf.mapWidth / 2; int halfHeight = Conf.mapHeight / 2; diff --git a/src/com/bukkit/mcteam/factions/entities/Conf.java b/src/com/bukkit/mcteam/factions/entities/Conf.java index 3fb5346b..c59a8d2d 100644 --- a/src/com/bukkit/mcteam/factions/entities/Conf.java +++ b/src/com/bukkit/mcteam/factions/entities/Conf.java @@ -1,38 +1,47 @@ package com.bukkit.mcteam.factions.entities; import java.util.*; - import org.bukkit.*; -import com.bukkit.mcteam.factions.struct.Relation; - public class Conf { - public static Integer logThreshold; - public static String prefixAdmin; - public static String prefixMod; - public static int factionNameMinLength; - public static int factionNameMaxLength; - - public static int mapHeight; - public static int mapWidth; - - public static double territoryShieldFactor; - - // Chat control: - public static boolean useRelationColoredChat; // This can interfere with other chat formatting plugins. Test to turn it on or off. - // TODO experiment with displayname feature of bukkit - // TODO test to set format instead of overriding and offer a non colored mut **Title alternative... - // Colors - public static ChatColor colorMember; - public static ChatColor colorAlly; - public static ChatColor colorNeutral; - public static ChatColor colorEnemy; + public static ChatColor colorMember = ChatColor.GREEN; + public static ChatColor colorAlly = ChatColor.LIGHT_PURPLE; + public static ChatColor colorNeutral = ChatColor.WHITE; + public static ChatColor colorEnemy = ChatColor.RED; - public static ChatColor colorSystem; - public static ChatColor colorChrome; - public static ChatColor colorCommand; - public static ChatColor colorParameter; + public static ChatColor colorSystem = ChatColor.YELLOW; + public static ChatColor colorChrome = ChatColor.GOLD; + public static ChatColor colorCommand = ChatColor.AQUA; + public static ChatColor colorParameter = ChatColor.DARK_AQUA; + + public static Integer logThreshold = 10; + + // Power + public static double powerPlayerMax = 10; + public static double powerPlayerMin = -10; + public static double powerPerMinute = 0.2; // Default health rate... it takes 5 min to heal one power + public static double powerPerDeath = 2; //A death makes you loose 2 power + + public static String prefixAdmin = "**"; + public static String prefixMod = "*"; + + public static int factionTagLengthMin = 3; + public static int factionTagLengthMax = 3; + + // Configuration on the Faction tag in chat messages. + + public static boolean chatTagEnabled = true; + public static boolean chatTagRelationColored = true; + public static int chatTagInsertIndex = 1; + public static String chatTagFormat = "%s"+ChatColor.WHITE+" "; + public static String factionChatFormat = colorMember+"%s"+ChatColor.WHITE+" %s"; + + public static int mapHeight = 8; + public static int mapWidth = 49; + + public static double territoryShieldFactor = 0.5; + public static List territoryProtectedMaterials = new ArrayList(); // Command names / aliases public static List aliasBase = new ArrayList(); @@ -47,7 +56,9 @@ public class Conf { public static List aliasLeave = new ArrayList(); public static List aliasCreate = new ArrayList(); - public static List aliasName = new ArrayList(); + public static List aliasTag = new ArrayList(); + public static List aliasDescription = new ArrayList(); + public static List aliasChat = new ArrayList(); public static List aliasTitle = new ArrayList(); public static List aliasInvite = new ArrayList(); @@ -65,48 +76,17 @@ public class Conf { public static List aliasRelationNeutral = new ArrayList(); public static List aliasRelationEnemy = new ArrayList(); - public static List aliasDescription = new ArrayList(); - public static List aliasVersion = new ArrayList(); // Value aliases public static List aliasTrue = new ArrayList(); - // Power - public static double powerPerPlayer; - public static double powerPerMinute; // Default health rate - public static double powerPerDeath; - - // Protected blocks - public static List territoryProtectedMaterials = new ArrayList(); - static { - logThreshold = 10; - prefixAdmin = "**"; - prefixMod = "*"; - useRelationColoredChat = true; - - powerPerPlayer = 10; // One player has 10 power - powerPerMinute = 0.2; // Default health rate... it takes 5 min to heal one power - powerPerDeath = 2; //A death makes you loose 2 power - - territoryShieldFactor = 0.5; - territoryProtectedMaterials.add(Material.WOODEN_DOOR); territoryProtectedMaterials.add(Material.DISPENSER); territoryProtectedMaterials.add(Material.CHEST); territoryProtectedMaterials.add(Material.FURNACE); - colorMember = ChatColor.GREEN; - colorAlly = ChatColor.LIGHT_PURPLE; - colorNeutral = ChatColor.WHITE; - colorEnemy = ChatColor.RED; - - colorSystem = ChatColor.YELLOW; - colorChrome = ChatColor.GOLD; - colorCommand = ChatColor.AQUA; - colorParameter = ChatColor.DARK_AQUA; - aliasBase.add("/f"); aliasBase.add("f"); aliasBase.add("/faction"); @@ -132,9 +112,11 @@ public class Conf { aliasCreate.add("create"); aliasCreate.add("new"); + aliasTag.add("tag"); + aliasDescription.add("desc"); - aliasName.add("name"); - aliasName.add("rename"); + aliasChat.add("chat"); + aliasChat.add("c"); aliasTitle.add("title"); @@ -162,8 +144,6 @@ public class Conf { aliasRelationNeutral.add("neutral"); aliasRelationEnemy.add("enemy"); - aliasDescription.add("desc"); - aliasVersion.add("version"); aliasTrue.add("true"); @@ -172,28 +152,6 @@ public class Conf { aliasTrue.add("ok"); aliasTrue.add("on"); aliasTrue.add("+"); - - factionNameMinLength = 3; - factionNameMaxLength = 40; - - mapHeight = 8; - mapWidth = 49; - } - - //----------------------------------------------// - // Color picking and stuff - //----------------------------------------------// - - public static ChatColor relationColor(Relation relation) { - if (relation == Relation.MEMBER) { - return colorMember; - } else if (relation == Relation.ALLY) { - return colorAlly; - } else if (relation == Relation.NEUTRAL) { - return colorNeutral; - } else { //if (relation == FactionRelation.ENEMY) { - return colorEnemy; - } } //----------------------------------------------// diff --git a/src/com/bukkit/mcteam/factions/entities/EM.java b/src/com/bukkit/mcteam/factions/entities/EM.java index 2ac486ff..70c76657 100644 --- a/src/com/bukkit/mcteam/factions/entities/EM.java +++ b/src/com/bukkit/mcteam/factions/entities/EM.java @@ -114,18 +114,6 @@ public class EM { // Follower methods (loadAll, get, save) //----------------------------------------------// - /** - * This method will create a follower entity and assign the link to the corresponding player. - */ - public static void onPlayerLogin(Player player) { - Follower follower = followerGet(player); - follower.player = player; - } - - public static void onPlayerLogout(Player player) { - followers.get(player.getName()).player = null; - } - /** * This method loads all followers from disc into memory. */ @@ -256,7 +244,7 @@ public class EM { // Make sure the default neutral faction exists if ( ! factions.containsKey(0)) { Faction faction = new Faction(); - faction.name = "*No faction*"; + faction.tag = "*No faction*"; faction.description = "\"The faction for the factionless :P\""; faction.id = 0; factions.put(faction.id, faction); @@ -271,7 +259,7 @@ public class EM { return factions.values(); } - public static Faction factionCreate(){ + public static Faction factionCreate() { Faction faction = new Faction(); faction.id = nextFactionId; nextFactionId += 1; diff --git a/src/com/bukkit/mcteam/factions/entities/Faction.java b/src/com/bukkit/mcteam/factions/entities/Faction.java index 4a8e109d..54c111f0 100644 --- a/src/com/bukkit/mcteam/factions/entities/Faction.java +++ b/src/com/bukkit/mcteam/factions/entities/Faction.java @@ -9,6 +9,7 @@ import com.bukkit.mcteam.factions.Factions; import com.bukkit.mcteam.factions.struct.Relation; import com.bukkit.mcteam.factions.struct.Role; import com.bukkit.mcteam.factions.util.Log; +import com.bukkit.mcteam.factions.util.TextUtil; import com.bukkit.mcteam.util.ChatFixUtil; public class Faction { @@ -17,36 +18,34 @@ public class Faction { protected Map relationWish; protected Set invites; // Where string is a follower id (lower case name) protected boolean open; - protected String name; + protected String tag; protected String description; public Faction() { this.relationWish = new HashMap(); this.invites = new HashSet(); this.open = true; - this.name = "Untitled Faction :("; + this.tag = "???"; this.description = "Default faction description :("; } // ------------------------------- // Information // ------------------------------- - public String getName() { - return this.getName(""); + public String getTag() { + return this.getTag(""); } - public String getName(String prefix) { - return prefix+this.name; + public String getTag(String prefix) { + return prefix+this.tag; } - public String getName(Faction otherFaction) { - return this.getName(otherFaction.getRelationColor(this).toString()); + public String getTag(Faction otherFaction) { + return this.getTag(otherFaction.getRelationColor(this).toString()); } - - public String getName(Follower otherFollower) { - return this.getName(otherFollower.getRelationColor(this).toString()); + public String getTag(Follower otherFollower) { + return this.getTag(otherFollower.getRelationColor(this).toString()); } - - public void setName(String newName) { - this.name = newName; + public void setTag(String str) { + this.tag = str.toUpperCase(); this.save(); } @@ -99,16 +98,8 @@ public class Faction { return Board.getFactionCoordCount(this); } - public double getLandMax() { - return this.getPower(); - } - - public int getLandMaxRounded() { - return (int) Math.round(this.getLandMax()); - } - public boolean hasLandInflation() { - return Board.getFactionCoordCount(this) > this.getLandMaxRounded(); + return this.getLandRounded() > this.getPowerRounded(); } // ------------------------------- @@ -116,14 +107,14 @@ public class Faction { // ------------------------------- - public ArrayList invite(Follower follower) { + public ArrayList invite(Follower follower) { // TODO Move out ArrayList errors = new ArrayList(); Log.debug("follower.getFaction().id"+follower.getFaction().id); Log.debug("this.id"+this.id); if (follower.getFaction().equals(this)) { // error här? - errors.add(Conf.colorSystem+follower.getFullName()+" is already a member of "+this.getName()); + errors.add(Conf.colorSystem+follower.getName()+" is already a member of "+this.getTag()); } if(errors.size() > 0) { @@ -135,11 +126,11 @@ public class Faction { return errors; } - public ArrayList deinvite(Follower follower) { + public ArrayList deinvite(Follower follower) { // TODO move out! ArrayList errors = new ArrayList(); if (follower.getFaction() == this) { - errors.add(Conf.colorSystem+follower.getFullName()+" is already a member of "+this.getName()); + errors.add(Conf.colorSystem+follower.getName()+" is already a member of "+this.getTag()); errors.add(Conf.colorSystem+"You might want to "+Conf.colorCommand+Conf.aliasBase.get(0)+" "+Conf.aliasKick.get(0)+Conf.colorParameter+" "+follower.getName()); } @@ -222,58 +213,45 @@ public class Faction { } //----------------------------------------------// - // Faction name + // Faction tag //----------------------------------------------// - private transient static ArrayList nameWhitelist = new ArrayList(Arrays.asList(new String []{ - "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", - "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", - "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", - "s", "t", "u", "v", "w", "x", "y", "z" - })); - - public static String toComparisonName(String name) { - String ret = ""; - - for (char c : name.toCharArray()) { - if (nameWhitelist.contains(String.valueOf(c))) { - ret += c; - } - } - - return ret.toLowerCase(); + public String getComparisonTag() { + return TextUtil.getComparisonString(this.tag); } - public static ArrayList validateName(String name) { + public static ArrayList validateTag(String str) { ArrayList errors = new ArrayList(); - if(Faction.toComparisonName(name).length() < Conf.factionNameMinLength) { - errors.add(Conf.colorSystem+"That name is to short"); + if(TextUtil.getComparisonString(str).length() < Conf.factionTagLengthMin) { + errors.add(Conf.colorSystem+"The faction tag can't be shorter than "+Conf.factionTagLengthMin+ " chars."); } - if(name.length() > Conf.factionNameMaxLength) { - errors.add(Conf.colorSystem+"That name is to long"); + if(str.length() > Conf.factionTagLengthMax) { + errors.add(Conf.colorSystem+"The faction tag can't be longer than "+Conf.factionTagLengthMax+ " chars."); + } + + for (char c : str.toCharArray()) { + if ( ! TextUtil.substanceChars.contains(String.valueOf(c))) { + errors.add(Conf.colorSystem+"Faction tag must be alphanumeric. \""+c+"\" is not allowed."); + } } return errors; } - public String getComparisonName() { - return Faction.toComparisonName(this.name); - } - - public static Faction find(String name) { - String compName = Faction.toComparisonName(name); + public static Faction findByTag(String str) { + String compStr = TextUtil.getComparisonString(str); for (Faction faction : Faction.getAll()) { - if (faction.getComparisonName().equals(compName)) { + if (faction.getComparisonTag().equals(compStr)) { return faction; } } return null; } - public static boolean isNameTaken(String name) { - return Faction.find(name) != null; + public static boolean isTagTaken(String str) { + return Faction.findByTag(str) != null; } //----------------------------------------------// @@ -306,9 +284,10 @@ public class Faction { public void setRelationWish(Faction otherFaction, Relation relation) { if (this.relationWish.containsKey(otherFaction.id) && relation.equals(Relation.NEUTRAL)){ this.relationWish.remove(otherFaction.id); - return; + } else { + this.relationWish.put(otherFaction.id, relation); } - this.relationWish.put(otherFaction.id, relation); + this.save(); } public Relation getRelation(Faction otherFaction) { diff --git a/src/com/bukkit/mcteam/factions/entities/Follower.java b/src/com/bukkit/mcteam/factions/entities/Follower.java index 85ddb88a..f7951bb7 100644 --- a/src/com/bukkit/mcteam/factions/entities/Follower.java +++ b/src/com/bukkit/mcteam/factions/entities/Follower.java @@ -5,13 +5,13 @@ import java.util.*; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import com.bukkit.mcteam.factions.Factions; import com.bukkit.mcteam.factions.struct.*; import com.bukkit.mcteam.factions.util.Log; import com.bukkit.mcteam.util.ChatFixUtil; public class Follower { public transient String id; // The is the name of the player - public transient Player player; // The is the name of the player public int factionId; public Role role; @@ -34,7 +34,7 @@ public class Follower { } public Player getPlayer() { - return this.player; + return Factions.server.getPlayer(this.getName()); } public boolean isOnline() { @@ -48,7 +48,13 @@ public class Follower { public void setMapAutoUpdating(boolean mapAutoUpdating) { this.mapAutoUpdating = mapAutoUpdating; } - + + //----------------------------------------------// + // Title, Name, Faction Tag and Chat + //----------------------------------------------// + + // Base: + public String getTitle() { return title; } @@ -58,6 +64,117 @@ public class Follower { this.save(); } + public String getName() { + return this.id; + } + + public String getTag() { + if (this.withoutFaction()) { + return ""; + } + return this.getFaction().getTag(); + } + + // Base concatenations: + + public String getNameAndSomething(String something) { + String ret = this.role.getPrefix(); + if (something.length() > 0) { + ret += something+" "; + } + ret += this.getName(); + return ret; + } + + public String getNameAndTitle() { + return this.getNameAndSomething(this.getTitle()); + } + + public String getNameAndTag() { + return this.getNameAndSomething(this.getTag()); + } + + // Colored concatenations: + // These are used in information messages + + public String getNameAndTitle(Faction faction) { + return this.getRelationColor(faction)+this.getNameAndTitle(); + } + public String getNameAndTitle(Follower follower) { + return this.getRelationColor(follower)+this.getNameAndTitle(); + } + + public String getNameAndTag(Faction faction) { + return this.getRelationColor(faction)+this.getNameAndTag(); + } + public String getNameAndTag(Follower follower) { + return this.getRelationColor(follower)+this.getNameAndTag(); + } + + public String getNameAndRelevant(Faction faction) { + // Which relation? + Relation rel = this.getRelation(faction); + + // For member we show title + if (rel == Relation.MEMBER) { + return rel.getColor() + this.getNameAndTitle(); + } + + // For non members we show tag + return rel.getColor() + this.getNameAndTag(); + } + public String getNameAndRelevant(Follower follower) { + return getNameAndRelevant(follower.getFaction()); + } + + // Chat Tag: + // These are injected into the format of global chat messages. + + public String getChatTag() { + if (this.withoutFaction()) { + return ""; + } + + return String.format(Conf.chatTagFormat, this.role.getPrefix()+this.getTag()); + } + + // Colored Chat Tag + public String getChatTag(Faction faction) { + if (this.withoutFaction()) { + return ""; + } + + return this.getRelation(faction).getColor()+getChatTag(); + } + public String getChatTag(Follower follower) { + if (this.withoutFaction()) { + return ""; + } + + return this.getRelation(follower).getColor()+getChatTag(); + } + + // ------------------------------- + // Relation and relation colors + // ------------------------------- + + public Relation getRelation(Faction faction) { + return faction.getRelation(this); + } + + public Relation getRelation(Follower follower) { + return this.getFaction().getRelation(follower); + } + + public ChatColor getRelationColor(Faction faction) { + return faction.getRelationColor(this); + } + + public ChatColor getRelationColor(Follower follower) { + return this.getRelation(follower).getColor(); + } + + //----------------------------------------------// // Health //----------------------------------------------// @@ -85,15 +202,15 @@ public class Follower { } else if (this.power < this.getPowerMin()) { this.power = this.getPowerMin(); } - Log.debug("Power of "+this.getFullName()+" is now: "+this.power); + Log.debug("Power of "+this.getName()+" is now: "+this.power); } public double getPowerMax() { - return Conf.powerPerPlayer; + return Conf.powerPlayerMax; } public double getPowerMin() { - return -Conf.powerPerPlayer; + return Conf.powerPlayerMin; } public int getPowerRounded() { @@ -141,7 +258,10 @@ public class Follower { public void sendFactionHereMessage() { Faction factionHere = Board.getFactionAt(this.getCoord()); - String msg = Conf.colorSystem+" ~ "+factionHere.getName(this); + String msg = Conf.colorSystem+" ~ "+factionHere.getTag(this); + if (factionHere.id != 0) { + msg += " - "+factionHere.getDescription(); + } this.sendMessage(msg); } @@ -152,17 +272,24 @@ public class Follower { return EM.factionGet(factionId); } + public boolean hasFaction() { + return factionId != 0; + } + public boolean withoutFaction() { + return factionId == 0; + } + public ArrayList join(Faction faction) { ArrayList errors = new ArrayList(); if (faction.id == this.factionId) { - errors.add(Conf.colorSystem+"You are already a member of "+faction.getRelationColor(this)+faction.getName()); + errors.add(Conf.colorSystem+"You are already a member of "+faction.getRelationColor(this)+faction.getTag()); } if( ! faction.getOpen() && ! faction.isInvited(this)) { errors.add(Conf.colorSystem+"This guild requires invitation."); } - if (this.factionId != 0) { + if (this.hasFaction()) { errors.add(Conf.colorSystem+"You must leave your current faction first."); } @@ -189,7 +316,7 @@ public class Follower { errors.add(Conf.colorSystem+"You must give the admin role to someone else first."); } - if(this.factionId == 0) { + if(this.withoutFaction()) { errors.add(Conf.colorSystem+"You are not member of any faction."); } @@ -239,7 +366,7 @@ public class Follower { ArrayList errors = new ArrayList(); if ( ! follower.getFaction().equals(this.getFaction())) { - errors.add(this.getRelationColor(follower)+follower.getFullName()+Conf.colorSystem+" is not a member of "+Conf.colorMember+this.getFaction().getName()); + errors.add(follower.getNameAndRelevant(this)+Conf.colorSystem+" is not a member of "+Conf.colorMember+this.getFaction().getTag()); } else if (follower.equals(this)) { errors.add(Conf.colorSystem+"You can not kick yourself."); errors.add(Conf.colorSystem+"You might want to "+Conf.colorCommand+Conf.aliasBase.get(0)+" "+Conf.aliasLeave.get(0)); @@ -296,65 +423,6 @@ public class Follower { return null; } - // ------------------------------- - // Relation and relation colors - // ------------------------------- - - public Relation getRelation(Faction faction) { - return faction.getRelation(this); - } - - public Relation getRelation(Follower follower) { - return this.getFaction().getRelation(follower); - } - - public ChatColor getRelationColor(Faction faction) { - return faction.getRelationColor(this); - } - - public ChatColor getRelationColor(Follower follower) { - return this.getRelation(follower).getColor(); - } - - //----------------------------------------------// - // Display the name of this follower - //----------------------------------------------// - - public String getName() { - return this.id; - } - - public String getFullName() { - return getFullName(""); - } - - public String getFullName(Faction otherFaction) { - return getFullName(otherFaction.getRelationColor(this).toString()); - } - - public String getFullName(Follower otherFollower) { - return getFullName(otherFollower.getRelationColor(this).toString()); - } - - public String getFullName(String prefix) { - String ret = prefix; - if (this.role.equals(Role.ADMIN)) { - ret += Conf.prefixAdmin; - } else if (this.role.equals(Role.MODERATOR)) { - ret += Conf.prefixMod; - } - - if (this.title.length() > 0) { - ret += this.title + " "; - } - - ret += this.getName(); - - return ret; - } - - - //----------------------------------------------// // Persistance and entity management //----------------------------------------------// diff --git a/src/com/bukkit/mcteam/factions/listeners/FactionsBlockListener.java b/src/com/bukkit/mcteam/factions/listeners/FactionsBlockListener.java index ef4c7c07..d7da005e 100644 --- a/src/com/bukkit/mcteam/factions/listeners/FactionsBlockListener.java +++ b/src/com/bukkit/mcteam/factions/listeners/FactionsBlockListener.java @@ -52,8 +52,8 @@ public class FactionsBlockListener extends BlockListener { // Cancel if we are not in our own territory if (myFaction != otherFaction) { - me.sendMessage(Conf.colorSystem+"You can't "+action+" in the territory of "+otherFaction.getName(myFaction)); - otherFaction.sendMessage(me.getFullName(otherFaction)+Conf.colorSystem+" tried to "+action+" "+TextUtil.getMaterialName(block.getType())+" in your territory"); + me.sendMessage(Conf.colorSystem+"You can't "+action+" in the territory of "+otherFaction.getTag(myFaction)); + otherFaction.sendMessage(me.getNameAndRelevant(otherFaction)+Conf.colorSystem+" tried to "+action+" "+TextUtil.getMaterialName(block.getType())+" in your territory"); return false; } @@ -93,8 +93,8 @@ public class FactionsBlockListener extends BlockListener { Faction otherFaction = blockCoord.getFaction(); if (otherFaction.id != 0 && myFaction != otherFaction) { - me.sendMessage(Conf.colorSystem+"You can't use "+TextUtil.getMaterialName(material)+" in the territory of "+otherFaction.getName(myFaction)); - otherFaction.sendMessage(me.getFullName(otherFaction)+Conf.colorSystem+" tried to use "+TextUtil.getMaterialName(material)+" in your territory"); + me.sendMessage(Conf.colorSystem+"You can't use "+TextUtil.getMaterialName(material)+" in the territory of "+otherFaction.getTag(myFaction)); + otherFaction.sendMessage(me.getNameAndRelevant(otherFaction)+Conf.colorSystem+" tried to use "+TextUtil.getMaterialName(material)+" in your territory"); return false; } return true; diff --git a/src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java b/src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java index 10148737..c7157bee 100644 --- a/src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java +++ b/src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java @@ -69,15 +69,15 @@ public class FactionsEntityListener extends EntityListener { // You can never hurt faction members or allies if (relation == Relation.MEMBER || relation == Relation.ALLY) { - attacker.sendMessage(Conf.colorSystem+"You can't hurt "+relation.getColor()+defender.getFullName()); + attacker.sendMessage(Conf.colorSystem+"You can't hurt "+defender.getNameAndRelevant(attacker)); event.setCancelled(true); return; } // You can not hurt neutrals in their own territory. if (relation == Relation.NEUTRAL && defender.isInOwnTerritory()) { - attacker.sendMessage(Conf.colorSystem+"You can't hurt "+relation.getColor()+defender.getFullName()+" in their own territory."); - defender.sendMessage(relation.getColor()+attacker.getFullName()+Conf.colorSystem+" tried to hurt you."); + attacker.sendMessage(Conf.colorSystem+"You can't hurt "+relation.getColor()+defender.getNameAndRelevant(attacker)+" in their own territory."); + defender.sendMessage(attacker.getNameAndRelevant(defender)+Conf.colorSystem+" tried to hurt you."); event.setCancelled(true); return; } @@ -85,7 +85,7 @@ public class FactionsEntityListener extends EntityListener { // Damage will be dealt. However check if the damage should be reduced. if (defender.isInOwnTerritory()) { int damage = event.getDamage(); - int toHeal = (int)Math.round(damage * Conf.territoryShieldFactor); + int toHeal = (int)(damage * Conf.territoryShieldFactor); defender.heal(toHeal); // Send message diff --git a/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java b/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java index 2b9fbfd3..579bdbd0 100644 --- a/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java +++ b/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java @@ -1,8 +1,8 @@ package com.bukkit.mcteam.factions.listeners; import java.util.*; +import java.util.logging.Logger; -import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.entity.*; import org.bukkit.event.player.PlayerChatEvent; @@ -37,17 +37,54 @@ public class FactionsPlayerListener extends PlayerListener{ @Override public void onPlayerChat(PlayerChatEvent event) { - Player player = event.getPlayer(); + if (event.isCancelled()) { + return; // Some other plugin ate this... + } + + Player talkingPlayer = event.getPlayer(); String msg = event.getMessage(); - // Process the command or - if ( ! handleCommandOrChat(player, msg) && Conf.useRelationColoredChat) { - for (Player receiver : Factions.server.getOnlinePlayers()) { - Follower follower = Follower.get(player); - receiver.sendMessage("<"+follower.getFullName(Follower.get(receiver))+ChatColor.WHITE+"> "+msg); - } + // Is this a faction command?... + if ( handleCommandOrChat(talkingPlayer, msg) ) { + // ... Yes it was! We should choke the chat message. + event.setCancelled(true); + return; + } + + // ... it was not a command. This means that it is a chat message! + + // Are we to insert the Faction tag into the format? + // If we are not to insert it - we are done. + if ( ! Conf.chatTagEnabled) { + return; + } + + Follower me = Follower.get(talkingPlayer); + + String formatStart = event.getFormat().substring(0, Conf.chatTagInsertIndex); + String formatEnd = event.getFormat().substring(Conf.chatTagInsertIndex); + + String nonColoredMsgFormat = formatStart + me.getChatTag() + formatEnd; + + // Relation Colored? + if (Conf.chatTagRelationColored) { + // We must choke the standard message and send out individual messages to all players + // Why? Because the relations will differ. + event.setCancelled(true); + + for (Player listeningPlayer : Factions.server.getOnlinePlayers()) { + Follower you = Follower.get(listeningPlayer); + String yourFormat = formatStart + me.getChatTag(you) + formatEnd; + listeningPlayer.sendMessage(String.format(yourFormat, talkingPlayer.getDisplayName(), msg)); + } + + // Write to the log... We will write the non colored message. + String nonColoredMsg = String.format(nonColoredMsgFormat, talkingPlayer.getDisplayName(), msg); + Logger.getLogger("Minecraft").info(nonColoredMsg); + } else { + // No relation color. + event.setFormat(nonColoredMsgFormat); } - event.setCancelled(true); } public boolean handleCommandOrChat(Player player, String msg) { @@ -63,16 +100,14 @@ public class FactionsPlayerListener extends PlayerListener{ @Override public void onPlayerJoin(PlayerEvent event) { - EM.onPlayerLogin(event.getPlayer()); //Follower.get(event.getPlayer()).sendJoinInfo(); } @Override public void onPlayerQuit(PlayerEvent event) { Follower follower = Follower.get(event.getPlayer()); - Log.debug("Saved follower on player quit: "+follower.getFullName()); + Log.debug("Saved follower on player quit: "+follower.getName()); follower.save(); // We save the followers on logout in order to save their non autosaved state like power. - EM.onPlayerLogout(event.getPlayer()); // Remove the player link. } @Override diff --git a/src/com/bukkit/mcteam/factions/struct/Relation.java b/src/com/bukkit/mcteam/factions/struct/Relation.java index c1a4404d..f3626df7 100644 --- a/src/com/bukkit/mcteam/factions/struct/Relation.java +++ b/src/com/bukkit/mcteam/factions/struct/Relation.java @@ -24,6 +24,14 @@ public enum Relation { } public ChatColor getColor() { - return Conf.relationColor(this); + if (this == Relation.MEMBER) { + return Conf.colorMember; + } else if (this == Relation.ALLY) { + return Conf.colorAlly; + } else if (this == Relation.NEUTRAL) { + return Conf.colorNeutral; + } else { //if (relation == FactionRelation.ENEMY) { + return Conf.colorEnemy; + } } } diff --git a/src/com/bukkit/mcteam/factions/struct/Role.java b/src/com/bukkit/mcteam/factions/struct/Role.java index ea307a10..0349c993 100644 --- a/src/com/bukkit/mcteam/factions/struct/Role.java +++ b/src/com/bukkit/mcteam/factions/struct/Role.java @@ -1,5 +1,7 @@ package com.bukkit.mcteam.factions.struct; +import com.bukkit.mcteam.factions.entities.Conf; + public enum Role { ADMIN(2, "admin"), MODERATOR(1, "moderator"), @@ -17,4 +19,16 @@ public enum Role { public String toString() { return this.nicename; } + + public String getPrefix() { + if (this == Role.ADMIN) { + return Conf.prefixAdmin; + } + + if (this == Role.MODERATOR) { + return Conf.prefixMod; + } + + return ""; + } } diff --git a/src/com/bukkit/mcteam/factions/util/TextUtil.java b/src/com/bukkit/mcteam/factions/util/TextUtil.java index 0eba30a6..0cff1ef3 100644 --- a/src/com/bukkit/mcteam/factions/util/TextUtil.java +++ b/src/com/bukkit/mcteam/factions/util/TextUtil.java @@ -58,6 +58,26 @@ public class TextUtil { ret = ret.toLowerCase(); return ret.substring(0, 1).toUpperCase()+ret.substring(1); } + + /// TODO create tag whitelist!! + public static ArrayList substanceChars = new ArrayList(Arrays.asList(new String []{ + "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", + "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", + "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", + "s", "t", "u", "v", "w", "x", "y", "z" + })); + + public static String getComparisonString(String str) { + String ret = ""; + + for (char c : str.toCharArray()) { + if (substanceChars.contains(String.valueOf(c))) { + ret += c; + } + } + + return ret.toLowerCase(); + } } diff --git a/src/com/bukkit/mcteam/util/AsciiCompass.java b/src/com/bukkit/mcteam/util/AsciiCompass.java index c7471202..cead2e76 100644 --- a/src/com/bukkit/mcteam/util/AsciiCompass.java +++ b/src/com/bukkit/mcteam/util/AsciiCompass.java @@ -8,7 +8,7 @@ public class AsciiCompass { public enum Point { N('N'), NE('/'), - E('W'), + E('E'), SE('\\'), S('S'), SW('/'),