Changes to the ascii map and minor tweaking

This commit is contained in:
Olof Larsson 2011-10-24 09:28:08 +02:00
parent 1ec7842ed4
commit bb5a676430
9 changed files with 101 additions and 103 deletions

View File

@ -12,7 +12,7 @@ import java.util.TreeMap;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import com.google.gson.reflect.TypeToken; 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.util.AsciiCompass;
import com.massivecraft.factions.zcore.util.DiscUtil; import com.massivecraft.factions.zcore.util.DiscUtil;
@ -159,11 +159,11 @@ public class Board
* north is in the direction of decreasing x * north is in the direction of decreasing x
* east is in the direction of decreasing z * east is in the direction of decreasing z
*/ */
public static ArrayList<String> getMap(Faction faction, FLocation flocation, double inDegrees) public static ArrayList<String> getMap(RelationParticipator observer, FLocation flocation, double inDegrees)
{ {
ArrayList<String> ret = new ArrayList<String>(); ArrayList<String> ret = new ArrayList<String>();
Faction factionLoc = getFactionAt(flocation); 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 halfWidth = Conf.mapWidth / 2;
int halfHeight = Conf.mapHeight / 2; int halfHeight = Conf.mapHeight / 2;
@ -171,12 +171,12 @@ public class Board
int width = halfWidth * 2 + 1; int width = halfWidth * 2 + 1;
int height = halfHeight * 2 + 1; int height = halfHeight * 2 + 1;
if (Conf.showMapFactionKey) /*if (Conf.showMapFactionKey)
{ {
height--; height--;
} }*/
Map<String, Character> fList = new HashMap<String, Character>(); Map<Faction, Character> fList = new HashMap<Faction, Character>();
int chrIdx = 0; int chrIdx = 0;
// For each row // For each row
@ -189,47 +189,38 @@ public class Board
if(dz == -(halfWidth) && dx == halfHeight) if(dz == -(halfWidth) && dx == halfHeight)
{ {
row += ChatColor.AQUA+"+"; 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); row += ChatColor.GRAY+"-";
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+"-";
}
} }
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); ret.add(row);
} }
@ -243,15 +234,17 @@ public class Board
ret.set(3, asciiCompass.get(2)+ret.get(3).substring(3*3)); ret.set(3, asciiCompass.get(2)+ret.get(3).substring(3*3));
// Add the faction key // Add the faction key
if (Conf.showMapFactionKey) // TODO: relation color for them
//if (Conf.showMapFactionKey)
//{
String fRow = "";
for(Faction keyfaction : fList.keySet())
{ {
String fRow = ""; fRow += String.format("%s%s: %s ", keyfaction.getColorTo(observer), fList.get(keyfaction), keyfaction.getTag());
for(String key : fList.keySet())
{
fRow += String.format("%s%s: %s ", ChatColor.GRAY, fList.get(key), key);
}
ret.add(fRow);
} }
ret.add(fRow);
//}
return ret; return ret;
} }

View File

@ -17,12 +17,12 @@ public class Conf
// Colors // Colors
public static ChatColor colorMember = ChatColor.GREEN; public static ChatColor colorMember = ChatColor.GREEN;
public static ChatColor colorAlly = ChatColor.LIGHT_PURPLE; 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 colorNeutral = ChatColor.WHITE;
public static ChatColor colorEnemy = ChatColor.RED; public static ChatColor colorEnemy = ChatColor.RED;
//public static ChatColor colorPeaceful = ChatColor.GOLD; public static ChatColor colorNoPVP = ChatColor.GOLD;
//public static ChatColor colorWar = ChatColor.DARK_RED; public static ChatColor colorFriendlyFire = ChatColor.DARK_RED;
//public static ChatColor colorWilderness = ChatColor.DARK_GREEN; //public static ChatColor colorWilderness = ChatColor.DARK_GREEN;
public static Map<FFlag, Boolean> factionFlagDefaults; public static Map<FFlag, Boolean> 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" // 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 String newPlayerStartingFactionID = "0";
public static boolean showMapFactionKey = true; //public static boolean showMapFactionKey = true;
public static boolean showNeutralFactionsOnMap = true; //public static boolean showNeutralFactionsOnMap = true;
public static boolean showEnemyFactionsOnMap = true; //public static boolean showEnemyFactionsOnMap = true;
// Disallow joining/leaving/kicking while power is negative // Disallow joining/leaving/kicking while power is negative
public static boolean canLeaveWithNegativePower = true; public static boolean canLeaveWithNegativePower = true;

View File

@ -38,13 +38,13 @@ public class Faction extends Entity implements EconomyParticipator
private String tag; private String tag;
public String getTag() { return this.tag; } public String getTag() { return this.tag; }
public String getTag(String prefix) { return prefix+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 getTag();
} }
return this.getTag(this.getColorTo(otherFaction).toString()); return this.getTag(this.getColorTo(observer).toString());
} }
public String getTag(FPlayer otherFplayer) { public String getTag(FPlayer otherFplayer) {
if (otherFplayer == null) if (otherFplayer == null)

View File

@ -37,10 +37,9 @@ public class CmdFlag extends FCommand
} }
if (faction == null) return; if (faction == null) return;
msg(p.txt.titleize("Flag(s) for " + faction.describeTo(fme)));
if ( ! this.argIsSet(1)) if ( ! this.argIsSet(1))
{ {
msg(p.txt.titleize("Flags for " + faction.describeTo(fme)));
for (FFlag flag : FFlag.values()) for (FFlag flag : FFlag.values())
{ {
msg(flag.getStateInfo(faction.getFlag(flag), true)); msg(flag.getStateInfo(faction.getFlag(flag), true));
@ -52,6 +51,7 @@ public class CmdFlag extends FCommand
if (flag == null) return; if (flag == null) return;
if ( ! this.argIsSet(2)) if ( ! this.argIsSet(2))
{ {
msg(p.txt.titleize("Flag for " + faction.describeTo(fme)));
msg(flag.getStateInfo(faction.getFlag(flag), true)); msg(flag.getStateInfo(faction.getFlag(flag), true));
return; return;
} }
@ -81,6 +81,7 @@ public class CmdFlag extends FCommand
} }
// Do the change // Do the change
msg(p.txt.titleize("Flag for " + faction.describeTo(fme)));
faction.setFlag(flag, targetValue); faction.setFlag(flag, targetValue);
msg(flag.getStateInfo(faction.getFlag(flag), true)); msg(flag.getStateInfo(faction.getFlag(flag), true));
} }

View File

@ -42,10 +42,9 @@ public class CmdPerm extends FCommand
} }
if (faction == null) return; if (faction == null) return;
msg(p.txt.titleize("Perm(s) for " + faction.describeTo(fme)));
if ( ! this.argIsSet(1)) if ( ! this.argIsSet(1))
{ {
msg(p.txt.titleize("Perms for " + faction.describeTo(fme)));
for (FPerm perm : FPerm.values()) for (FPerm perm : FPerm.values())
{ {
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true)); msg(perm.getStateInfo(faction.getPermittedRelations(perm), true));
@ -57,6 +56,7 @@ public class CmdPerm extends FCommand
if (perm == null) return; if (perm == null) return;
if ( ! this.argIsSet(2)) if ( ! this.argIsSet(2))
{ {
msg(p.txt.titleize("Perm for " + faction.describeTo(fme)));
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true)); msg(perm.getStateInfo(faction.getPermittedRelations(perm), true));
return; return;
} }
@ -81,6 +81,7 @@ public class CmdPerm extends FCommand
// Do the change // Do the change
faction.setPermittedRelations(perm, targetValue); faction.setPermittedRelations(perm, targetValue);
msg(p.txt.titleize("Perm for " + faction.describeTo(fme)));
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true)); msg(perm.getStateInfo(faction.getPermittedRelations(perm), true));
} }

View File

@ -28,6 +28,29 @@ public class FactionsBlockListener extends BlockListener
this.p = p; 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("<b>It is painful to %s in the territory of %s<b>.", action, factionHere.describeTo(me));
player.damage(Conf.actionDeniedPainAmount);
}
return true;
}
return FPerm.BUILD.has(me, location, true);
}
@Override @Override
public void onBlockPlace(BlockPlaceEvent event) public void onBlockPlace(BlockPlaceEvent event)
{ {
@ -62,8 +85,9 @@ public class FactionsBlockListener extends BlockListener
public void onBlockDamage(BlockDamageEvent event) public void onBlockDamage(BlockDamageEvent event)
{ {
if (event.isCancelled()) return; 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); event.setCancelled(true);
} }
@ -113,27 +137,4 @@ public class FactionsBlockListener extends BlockListener
event.setCancelled(true); 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("<b>It is painful to %s in the territory of %s<b>.", action, factionHere.describeTo(me));
player.damage(Conf.actionDeniedPainAmount);
}
return true;
}
return FPerm.BUILD.has(me, location, true);
}
} }

View File

@ -81,7 +81,14 @@ public enum FPerm
{ {
rels.add("<p>"+rel.nicename); rels.add("<p>"+rel.nicename);
} }
ret += TextUtil.implode(rels, "<c>+"); if (rels.size() > 0)
{
ret += TextUtil.implode(rels, "<c>+");
}
else
{
ret += "NOONE";
}
if (withDesc) if (withDesc)
{ {

View File

@ -22,6 +22,7 @@ import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.P; import com.massivecraft.factions.P;
// TODO: Is this one even used anymore??
public class MapFLocToStringSetTypeAdapter implements JsonDeserializer<Map<FLocation, Set<String>>>, JsonSerializer<Map<FLocation, Set<String>>> public class MapFLocToStringSetTypeAdapter implements JsonDeserializer<Map<FLocation, Set<String>>>, JsonSerializer<Map<FLocation, Set<String>>>
{ {

View File

@ -2,6 +2,7 @@ package com.massivecraft.factions.util;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.iface.RelationParticipator; import com.massivecraft.factions.iface.RelationParticipator;
@ -121,26 +122,19 @@ public class RelationUtil
public static ChatColor getColorOfThatToMe(RelationParticipator that, RelationParticipator me) public static ChatColor getColorOfThatToMe(RelationParticipator that, RelationParticipator me)
{ {
//Faction thatFaction = getFaction(that); Faction thatFaction = getFaction(that);
// TODO: Add special colors to zone as a feature to replace this one if (thatFaction != null && thatFaction != getFaction(me))
/*if (thatFaction != null)
{ {
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(); return getRelationTo(that, me).getColor();
} }
} }