New SeeChunk command and cleanup of the show command.

This commit is contained in:
Olof Larsson 2011-11-24 16:27:14 +01:00
parent c43d34af79
commit e935a56ff9
4 changed files with 163 additions and 72 deletions

View File

@ -252,6 +252,21 @@ public class Faction extends Entity implements EconomyParticipator
} }
} }
public Map<Rel, List<String>> getFactionTagsPerRelation()
{
Map<Rel, List<String>> ret = new HashMap<Rel, List<String>>();
for (Rel rel : Rel.values())
{
ret.put(rel, new ArrayList<String>());
}
for (Faction faction : Factions.i.get())
{
Rel relation = faction.getRelationTo(this);
ret.get(relation).add(faction.getTag(this));
}
return ret;
}
// TODO: Implement a has enough feature. // TODO: Implement a has enough feature.
//----------------------------------------------// //----------------------------------------------//
// Power // Power

View File

@ -0,0 +1,101 @@
package com.massivecraft.factions.cmd;
import java.util.ArrayList;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import com.massivecraft.factions.struct.Permission;
// !!!! This is just an experiment.
// Proof of concept. We could use fake block updates to visualize the territories.
public class CmdSeeChunk extends FCommand
{
public CmdSeeChunk()
{
super();
this.aliases.add("sc");
this.aliases.add("seechunks");
//this.requiredArgs.add("");
//this.optionalArgs.put("", "");
this.permission = Permission.ADMIN.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
}
@Override
public void perform()
{
Location meLoc = me.getLocation();
// Which chunk are we standing in ATM?
// This bit shifting is something like divide by 16 :P
int chunkX = meLoc.getBlockX() >> 4;
int chunkZ = meLoc.getBlockZ() >> 4;
// Get the pillars for that chunk
int blockX;
int blockZ;
blockX = chunkX*16;
blockZ = chunkZ*16;
showPillar(me, me.getWorld(), blockX, blockZ);
blockX = chunkX*16 + 15;
blockZ = chunkZ*16;
showPillar(me, me.getWorld(), blockX, blockZ);
blockX = chunkX*16;
blockZ = chunkZ*16 + 15;
showPillar(me, me.getWorld(), blockX, blockZ);
blockX = chunkX*16 + 15;
blockZ = chunkZ*16 + 15;
showPillar(me, me.getWorld(), blockX, blockZ);
}
public void showPillar(Player player, World world, int blockX, int blockZ)
{
Location loc = new Location(world, blockX, 0, blockZ);
//Block block = loc.getBlock();
for (int blockY = 0; blockY <=127; blockY++)
{
loc.setY(blockY);
if (loc.getBlock().getTypeId() != 0) continue;
player.sendBlockChange(loc, blockY % 5 == 0 ? Material.GLOWSTONE : Material.GLASS, (byte) 0);
}
}
// DEV DIRT BELOW...
public ArrayList<Location> getChunkPillarLocations(int chunkX, int chunkZ)
{
ArrayList<Location> ret = new ArrayList<Location>();
return ret;
}
public ArrayList<Location> getPillar(Block block)
{
ArrayList<Location> ret = new ArrayList<Location>();
// y 0-127
for (int i = 0; i <=127; i++)
{
}
return ret;
}
}

View File

@ -1,19 +1,21 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import java.util.Map;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.FFlag; import com.massivecraft.factions.struct.FFlag;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Rel; import com.massivecraft.factions.struct.Rel;
import com.massivecraft.factions.zcore.util.TextUtil;
public class CmdShow extends FCommand public class CmdShow extends FCommand
{ {
public CmdShow() public CmdShow()
{ {
this.aliases.add("show"); this.aliases.add("show");
@ -50,25 +52,22 @@ public class CmdShow extends FCommand
msg(p.txt.titleize(faction.getTag(fme))); msg(p.txt.titleize(faction.getTag(fme)));
msg("<a>Description: <i>%s", faction.getDescription()); msg("<a>Description: <i>%s", faction.getDescription());
/*if ( ! faction.isNormal())
{
return;
}*/
String peaceStatus = "";
if (faction.getFlag(FFlag.PEACEFUL))
{
peaceStatus = " "+Conf.colorTruce+"This faction is Peaceful";
}
msg("<a>Joining: <i>"+(faction.getOpen() ? "no invitation is needed" : "invitation is required")+peaceStatus);
msg("<a>Land / Power / Maxpower: <i> %d/%d/%d", faction.getLandRounded(), faction.getPowerRounded(), faction.getPowerMaxRounded());
// Display important flags
// TODO: Find the non default flags, and display them instead.
if (faction.getFlag(FFlag.PERMANENT)) if (faction.getFlag(FFlag.PERMANENT))
{ {
msg("<a>This faction is permanent, remaining even with no members."); msg("<a>This faction is permanent, remaining even with no members.");
} }
if (faction.getFlag(FFlag.PEACEFUL))
{
sendMessage(Conf.colorTruce+"This faction is peaceful - in truce with everyone.");
}
msg("<a>Joining: <i>"+(faction.getOpen() ? "no invitation is needed" : "invitation is required"));
msg("<a>Land / Power / Maxpower: <i> %d/%d/%d", faction.getLandRounded(), faction.getPowerRounded(), faction.getPowerMaxRounded());
// show the land value // show the land value
if (Econ.shouldBeUsed()) if (Econ.shouldBeUsed())
{ {
@ -82,88 +81,62 @@ public class CmdShow extends FCommand
} }
//Show bank contents //Show bank contents
if(Conf.bankEnabled) { if(Conf.bankEnabled)
{
msg("<a>Bank contains: <i>"+Econ.moneyString(faction.getAccount().balance())); msg("<a>Bank contains: <i>"+Econ.moneyString(faction.getAccount().balance()));
} }
} }
String listpart; String sepparator = p.txt.parse("<i>")+", ";
// List relation // List the relations to other factions
String allyList = p.txt.parse("<a>Allies: "); Map<Rel, List<String>> relationTags = faction.getFactionTagsPerRelation();
String enemyList = p.txt.parse("<a>Enemies: "); sendMessage(p.txt.parse("<a>In Truce with: ") + TextUtil.implode(relationTags.get(Rel.TRUCE), sepparator));
for (Faction otherFaction : Factions.i.get()) sendMessage(p.txt.parse("<a>Allied to: ") + TextUtil.implode(relationTags.get(Rel.ALLY), sepparator));
{ sendMessage(p.txt.parse("<a>Enemies: ") + TextUtil.implode(relationTags.get(Rel.ENEMY), sepparator));
if (otherFaction == faction)
{
continue;
}
listpart = otherFaction.getTag(fme)+p.txt.parse("<i>")+", ";
if (otherFaction.getRelationTo(faction) == Rel.ALLY)
{
allyList += listpart;
}
else if (otherFaction.getRelationTo(faction) == Rel.ENEMY)
{
enemyList += listpart;
}
}
if (allyList.endsWith(", "))
{
allyList = allyList.substring(0, allyList.length()-2);
}
if (enemyList.endsWith(", "))
{
enemyList = enemyList.substring(0, enemyList.length()-2);
}
sendMessage(allyList);
sendMessage(enemyList);
// List the members... // List the members...
String onlineList = p.txt.parse("<a>")+"Members online: "; List<String> memberOnlineNames = new ArrayList<String>();
String offlineList = p.txt.parse("<a>")+"Members offline: "; List<String> memberOfflineNames = new ArrayList<String>();
for (FPlayer follower : admins) for (FPlayer follower : admins)
{ {
listpart = follower.getNameAndTitle(fme)+p.txt.parse("<i>")+", ";
if (follower.isOnline()) if (follower.isOnline())
{ {
onlineList += listpart; memberOnlineNames.add(follower.getNameAndTitle(fme));
} }
else else
{ {
offlineList += listpart; memberOfflineNames.add(follower.getNameAndTitle(fme));
} }
} }
for (FPlayer follower : mods) for (FPlayer follower : mods)
{ {
listpart = follower.getNameAndTitle(fme)+p.txt.parse("<i>")+", "; if (follower.isOnline())
if
(follower.isOnline())
{ {
onlineList += listpart; memberOnlineNames.add(follower.getNameAndTitle(fme));
} else {
offlineList += listpart;
} }
} else
for (FPlayer follower : normals) { {
listpart = follower.getNameAndTitle(fme)+p.txt.parse("<i>")+", "; memberOfflineNames.add(follower.getNameAndTitle(fme));
if (follower.isOnline()) {
onlineList += listpart;
} else {
offlineList += listpart;
} }
} }
if (onlineList.endsWith(", ")) { for (FPlayer follower : normals)
onlineList = onlineList.substring(0, onlineList.length()-2); {
} if (follower.isOnline())
if (offlineList.endsWith(", ")) { {
offlineList = offlineList.substring(0, offlineList.length()-2); memberOnlineNames.add(follower.getNameAndTitle(fme));
}
else
{
memberOfflineNames.add(follower.getNameAndTitle(fme));
}
} }
sendMessage(onlineList); sendMessage(p.txt.parse("<a>Members online: ") + TextUtil.implode(memberOnlineNames, sepparator));
sendMessage(offlineList); sendMessage(p.txt.parse("<a>Members offline: ") + TextUtil.implode(memberOfflineNames, sepparator));
} }
} }

View File

@ -37,6 +37,7 @@ public class FCmdRoot extends FCommand
public CmdRelationTruce cmdRelationTruce = new CmdRelationTruce(); public CmdRelationTruce cmdRelationTruce = new CmdRelationTruce();
public CmdReload cmdReload = new CmdReload(); public CmdReload cmdReload = new CmdReload();
public CmdSaveAll cmdSaveAll = new CmdSaveAll(); public CmdSaveAll cmdSaveAll = new CmdSaveAll();
public CmdSeeChunk cmdSeeChunks = new CmdSeeChunk();
public CmdSethome cmdSethome = new CmdSethome(); public CmdSethome cmdSethome = new CmdSethome();
public CmdShow cmdShow = new CmdShow(); public CmdShow cmdShow = new CmdShow();
public CmdTag cmdTag = new CmdTag(); public CmdTag cmdTag = new CmdTag();
@ -98,6 +99,7 @@ public class FCmdRoot extends FCommand
this.addSubCommand(this.cmdRelationTruce); this.addSubCommand(this.cmdRelationTruce);
this.addSubCommand(this.cmdReload); this.addSubCommand(this.cmdReload);
this.addSubCommand(this.cmdSaveAll); this.addSubCommand(this.cmdSaveAll);
this.addSubCommand(this.cmdSeeChunks);
this.addSubCommand(this.cmdSethome); this.addSubCommand(this.cmdSethome);
this.addSubCommand(this.cmdShow); this.addSubCommand(this.cmdShow);
this.addSubCommand(this.cmdTag); this.addSubCommand(this.cmdTag);