From bb5a6764300738c04fd59becb213d7f9197f1001 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Mon, 24 Oct 2011 09:28:08 +0200 Subject: [PATCH] Changes to the ascii map and minor tweaking --- src/com/massivecraft/factions/Board.java | 95 +++++++++---------- src/com/massivecraft/factions/Conf.java | 12 +-- src/com/massivecraft/factions/Faction.java | 6 +- .../massivecraft/factions/cmd/CmdFlag.java | 5 +- .../massivecraft/factions/cmd/CmdPerm.java | 5 +- .../listeners/FactionsBlockListener.java | 49 +++++----- .../massivecraft/factions/struct/FPerm.java | 9 +- .../util/MapFLocToStringSetTypeAdapter.java | 1 + .../factions/util/RelationUtil.java | 22 ++--- 9 files changed, 101 insertions(+), 103 deletions(-) diff --git a/src/com/massivecraft/factions/Board.java b/src/com/massivecraft/factions/Board.java index 28939dfb..3e22812b 100644 --- a/src/com/massivecraft/factions/Board.java +++ b/src/com/massivecraft/factions/Board.java @@ -12,7 +12,7 @@ import java.util.TreeMap; import org.bukkit.ChatColor; import com.google.gson.reflect.TypeToken; -import com.massivecraft.factions.struct.Rel; +import com.massivecraft.factions.iface.RelationParticipator; import com.massivecraft.factions.util.AsciiCompass; import com.massivecraft.factions.zcore.util.DiscUtil; @@ -159,11 +159,11 @@ public class Board * north is in the direction of decreasing x * east is in the direction of decreasing z */ - public static ArrayList getMap(Faction faction, FLocation flocation, double inDegrees) + public static ArrayList getMap(RelationParticipator observer, FLocation flocation, double inDegrees) { ArrayList ret = new ArrayList(); Faction factionLoc = getFactionAt(flocation); - ret.add(P.p.txt.titleize("("+flocation.getCoordString()+") "+factionLoc.getTag(faction))); + ret.add(P.p.txt.titleize("("+flocation.getCoordString()+") "+factionLoc.getTag(observer))); int halfWidth = Conf.mapWidth / 2; int halfHeight = Conf.mapHeight / 2; @@ -171,12 +171,12 @@ public class Board int width = halfWidth * 2 + 1; int height = halfHeight * 2 + 1; - if (Conf.showMapFactionKey) + /*if (Conf.showMapFactionKey) { height--; - } + }*/ - Map fList = new HashMap(); + Map fList = new HashMap(); int chrIdx = 0; // For each row @@ -189,47 +189,38 @@ public class Board if(dz == -(halfWidth) && dx == halfHeight) { row += ChatColor.AQUA+"+"; + continue; } - else + + FLocation flocationHere = topLeft.getRelative(dx, dz); + Faction factionHere = getFactionAt(flocationHere); + //Rel relation = faction.getRelationTo(factionHere); + if (factionHere.isNone()) { - FLocation flocationHere = topLeft.getRelative(dx, dz); - Faction factionHere = getFactionAt(flocationHere); - Rel relation = faction.getRelationTo(factionHere); - if (factionHere.isNone()) - { - row += ChatColor.GRAY+"-"; - } - /*else if (factionHere.isSafeZone()) - { - row += Conf.colorPeaceful+"+"; - } - else if (factionHere.isWarZone()) - { - row += ChatColor.DARK_RED+"+"; - }*/ - else if - ( - factionHere == faction - || - factionHere == factionLoc - || - relation.isAtLeast(Rel.ALLY) - || - (Conf.showNeutralFactionsOnMap && relation.equals(Rel.NEUTRAL)) - || - (Conf.showEnemyFactionsOnMap && relation.equals(Rel.ENEMY)) - ) - { - if (!fList.containsKey(factionHere.getTag())) - fList.put(factionHere.getTag(), Conf.mapKeyChrs[chrIdx++]); - char tag = fList.get(factionHere.getTag()); - row += factionHere.getColorTo(faction) + "" + tag; - } - else - { - row += ChatColor.GRAY+"-"; - } + row += ChatColor.GRAY+"-"; } + else /*if + ( + factionHere == faction + || + factionHere == factionLoc + || + relation.isAtLeast(Rel.ALLY) + || + (Conf.showNeutralFactionsOnMap && relation.equals(Rel.NEUTRAL)) + || + (Conf.showEnemyFactionsOnMap && relation.equals(Rel.ENEMY)) + )*/ + { + if (!fList.containsKey(factionHere.getTag())) + fList.put(factionHere, Conf.mapKeyChrs[chrIdx++]); + char tag = fList.get(factionHere); + row += factionHere.getColorTo(observer) + "" + tag; + } + /*else + { + row += ChatColor.GRAY+"-"; + }*/ } ret.add(row); } @@ -243,15 +234,17 @@ public class Board ret.set(3, asciiCompass.get(2)+ret.get(3).substring(3*3)); // Add the faction key - if (Conf.showMapFactionKey) + // TODO: relation color for them + //if (Conf.showMapFactionKey) + //{ + + String fRow = ""; + for(Faction keyfaction : fList.keySet()) { - String fRow = ""; - for(String key : fList.keySet()) - { - fRow += String.format("%s%s: %s ", ChatColor.GRAY, fList.get(key), key); - } - ret.add(fRow); + fRow += String.format("%s%s: %s ", keyfaction.getColorTo(observer), fList.get(keyfaction), keyfaction.getTag()); } + ret.add(fRow); + //} return ret; } diff --git a/src/com/massivecraft/factions/Conf.java b/src/com/massivecraft/factions/Conf.java index fc78ffc6..01ab22b0 100644 --- a/src/com/massivecraft/factions/Conf.java +++ b/src/com/massivecraft/factions/Conf.java @@ -17,12 +17,12 @@ public class Conf // Colors public static ChatColor colorMember = ChatColor.GREEN; public static ChatColor colorAlly = ChatColor.LIGHT_PURPLE; - public static ChatColor colorTruce = ChatColor.GOLD; + public static ChatColor colorTruce = ChatColor.DARK_PURPLE; public static ChatColor colorNeutral = ChatColor.WHITE; public static ChatColor colorEnemy = ChatColor.RED; - //public static ChatColor colorPeaceful = ChatColor.GOLD; - //public static ChatColor colorWar = ChatColor.DARK_RED; + public static ChatColor colorNoPVP = ChatColor.GOLD; + public static ChatColor colorFriendlyFire = ChatColor.DARK_RED; //public static ChatColor colorWilderness = ChatColor.DARK_GREEN; public static Map factionFlagDefaults; @@ -51,9 +51,9 @@ public class Conf // what faction ID to start new players in when they first join the server; default is 0, "no faction" public static String newPlayerStartingFactionID = "0"; - public static boolean showMapFactionKey = true; - public static boolean showNeutralFactionsOnMap = true; - public static boolean showEnemyFactionsOnMap = true; + //public static boolean showMapFactionKey = true; + //public static boolean showNeutralFactionsOnMap = true; + //public static boolean showEnemyFactionsOnMap = true; // Disallow joining/leaving/kicking while power is negative public static boolean canLeaveWithNegativePower = true; diff --git a/src/com/massivecraft/factions/Faction.java b/src/com/massivecraft/factions/Faction.java index e29a48c8..a072e01d 100644 --- a/src/com/massivecraft/factions/Faction.java +++ b/src/com/massivecraft/factions/Faction.java @@ -38,13 +38,13 @@ public class Faction extends Entity implements EconomyParticipator private String tag; public String getTag() { return this.tag; } public String getTag(String prefix) { return prefix+this.tag; } - public String getTag(Faction otherFaction) + public String getTag(RelationParticipator observer) { - if (otherFaction == null) + if (observer == null) { return getTag(); } - return this.getTag(this.getColorTo(otherFaction).toString()); + return this.getTag(this.getColorTo(observer).toString()); } public String getTag(FPlayer otherFplayer) { if (otherFplayer == null) diff --git a/src/com/massivecraft/factions/cmd/CmdFlag.java b/src/com/massivecraft/factions/cmd/CmdFlag.java index b8844d28..77d1d121 100644 --- a/src/com/massivecraft/factions/cmd/CmdFlag.java +++ b/src/com/massivecraft/factions/cmd/CmdFlag.java @@ -37,10 +37,9 @@ public class CmdFlag extends FCommand } if (faction == null) return; - msg(p.txt.titleize("Flag(s) for " + faction.describeTo(fme))); - if ( ! this.argIsSet(1)) { + msg(p.txt.titleize("Flags for " + faction.describeTo(fme))); for (FFlag flag : FFlag.values()) { msg(flag.getStateInfo(faction.getFlag(flag), true)); @@ -52,6 +51,7 @@ public class CmdFlag extends FCommand if (flag == null) return; if ( ! this.argIsSet(2)) { + msg(p.txt.titleize("Flag for " + faction.describeTo(fme))); msg(flag.getStateInfo(faction.getFlag(flag), true)); return; } @@ -81,6 +81,7 @@ public class CmdFlag extends FCommand } // Do the change + msg(p.txt.titleize("Flag for " + faction.describeTo(fme))); faction.setFlag(flag, targetValue); msg(flag.getStateInfo(faction.getFlag(flag), true)); } diff --git a/src/com/massivecraft/factions/cmd/CmdPerm.java b/src/com/massivecraft/factions/cmd/CmdPerm.java index bef2231d..e963eb05 100644 --- a/src/com/massivecraft/factions/cmd/CmdPerm.java +++ b/src/com/massivecraft/factions/cmd/CmdPerm.java @@ -42,10 +42,9 @@ public class CmdPerm extends FCommand } if (faction == null) return; - msg(p.txt.titleize("Perm(s) for " + faction.describeTo(fme))); - if ( ! this.argIsSet(1)) { + msg(p.txt.titleize("Perms for " + faction.describeTo(fme))); for (FPerm perm : FPerm.values()) { msg(perm.getStateInfo(faction.getPermittedRelations(perm), true)); @@ -57,6 +56,7 @@ public class CmdPerm extends FCommand if (perm == null) return; if ( ! this.argIsSet(2)) { + msg(p.txt.titleize("Perm for " + faction.describeTo(fme))); msg(perm.getStateInfo(faction.getPermittedRelations(perm), true)); return; } @@ -81,6 +81,7 @@ public class CmdPerm extends FCommand // Do the change faction.setPermittedRelations(perm, targetValue); + msg(p.txt.titleize("Perm for " + faction.describeTo(fme))); msg(perm.getStateInfo(faction.getPermittedRelations(perm), true)); } diff --git a/src/com/massivecraft/factions/listeners/FactionsBlockListener.java b/src/com/massivecraft/factions/listeners/FactionsBlockListener.java index 65ba9d36..d0db889a 100644 --- a/src/com/massivecraft/factions/listeners/FactionsBlockListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsBlockListener.java @@ -28,6 +28,29 @@ public class FactionsBlockListener extends BlockListener this.p = p; } + public static boolean playerCanBuildDestroyBlock(Player player, Block block, String action, boolean justCheck) + { + FPlayer me = FPlayers.i.get(player); + + if (me.isAdminBypassing()) return true; + + Location location = block.getLocation(); + FLocation loc = new FLocation(location); + Faction factionHere = Board.getFactionAt(loc); + + if (FPerm.PAINBUILD.has(me, location)) + { + if (!justCheck) + { + me.msg("It is painful to %s in the territory of %s.", action, factionHere.describeTo(me)); + player.damage(Conf.actionDeniedPainAmount); + } + return true; + } + + return FPerm.BUILD.has(me, location, true); + } + @Override public void onBlockPlace(BlockPlaceEvent event) { @@ -62,8 +85,9 @@ public class FactionsBlockListener extends BlockListener public void onBlockDamage(BlockDamageEvent event) { if (event.isCancelled()) return; + if ( ! event.getInstaBreak()) return; - if (event.getInstaBreak() && ! playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock(), "destroy", false)) + if (! playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock(), "destroy", false)) { event.setCancelled(true); } @@ -113,27 +137,4 @@ public class FactionsBlockListener extends BlockListener event.setCancelled(true); } } - - public static boolean playerCanBuildDestroyBlock(Player player, Block block, String action, boolean justCheck) - { - FPlayer me = FPlayers.i.get(player); - - if (me.isAdminBypassing()) return true; - - Location location = block.getLocation(); - FLocation loc = new FLocation(location); - Faction factionHere = Board.getFactionAt(loc); - - if (FPerm.PAINBUILD.has(me, location)) - { - if (!justCheck) - { - me.msg("It is painful to %s in the territory of %s.", action, factionHere.describeTo(me)); - player.damage(Conf.actionDeniedPainAmount); - } - return true; - } - - return FPerm.BUILD.has(me, location, true); - } } diff --git a/src/com/massivecraft/factions/struct/FPerm.java b/src/com/massivecraft/factions/struct/FPerm.java index ec2fbe24..cffaae03 100644 --- a/src/com/massivecraft/factions/struct/FPerm.java +++ b/src/com/massivecraft/factions/struct/FPerm.java @@ -81,7 +81,14 @@ public enum FPerm { rels.add("

"+rel.nicename); } - ret += TextUtil.implode(rels, "+"); + if (rels.size() > 0) + { + ret += TextUtil.implode(rels, "+"); + } + else + { + ret += "NOONE"; + } if (withDesc) { diff --git a/src/com/massivecraft/factions/util/MapFLocToStringSetTypeAdapter.java b/src/com/massivecraft/factions/util/MapFLocToStringSetTypeAdapter.java index 2a1cbfc4..23231cc0 100644 --- a/src/com/massivecraft/factions/util/MapFLocToStringSetTypeAdapter.java +++ b/src/com/massivecraft/factions/util/MapFLocToStringSetTypeAdapter.java @@ -22,6 +22,7 @@ import com.massivecraft.factions.FLocation; import com.massivecraft.factions.P; +// TODO: Is this one even used anymore?? public class MapFLocToStringSetTypeAdapter implements JsonDeserializer>>, JsonSerializer>> { diff --git a/src/com/massivecraft/factions/util/RelationUtil.java b/src/com/massivecraft/factions/util/RelationUtil.java index f019f1d2..79aa4fd0 100644 --- a/src/com/massivecraft/factions/util/RelationUtil.java +++ b/src/com/massivecraft/factions/util/RelationUtil.java @@ -2,6 +2,7 @@ package com.massivecraft.factions.util; import org.bukkit.ChatColor; +import com.massivecraft.factions.Conf; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.iface.RelationParticipator; @@ -121,26 +122,19 @@ public class RelationUtil public static ChatColor getColorOfThatToMe(RelationParticipator that, RelationParticipator me) { - //Faction thatFaction = getFaction(that); - // TODO: Add special colors to zone as a feature to replace this one - /*if (thatFaction != null) + Faction thatFaction = getFaction(that); + if (thatFaction != null && thatFaction != getFaction(me)) { - if (thatFaction.isPeaceful() && thatFaction != getFaction(me)) + if (thatFaction.getFlag(FFlag.FRIENDLYFIRE) == true) { - return Conf.colorPeaceful; + return Conf.colorFriendlyFire; } - if (thatFaction.isSafeZone() && thatFaction != getFaction(me)) + if (thatFaction.getFlag(FFlag.PVP) == false) { - return Conf.colorPeaceful; + return Conf.colorNoPVP; } - - if (thatFaction.isWarZone() && thatFaction != getFaction(me)) - { - return Conf.colorWar; - } - }*/ - + } return getRelationTo(that, me).getColor(); } }