From e935a56ff96afca1bf76a14e0bcb4e86e6e6bc0b Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Thu, 24 Nov 2011 16:27:14 +0100 Subject: [PATCH] New SeeChunk command and cleanup of the show command. --- src/com/massivecraft/factions/Faction.java | 15 +++ .../factions/cmd/CmdSeeChunk.java | 101 +++++++++++++++ .../massivecraft/factions/cmd/CmdShow.java | 117 +++++++----------- .../massivecraft/factions/cmd/FCmdRoot.java | 2 + 4 files changed, 163 insertions(+), 72 deletions(-) create mode 100644 src/com/massivecraft/factions/cmd/CmdSeeChunk.java diff --git a/src/com/massivecraft/factions/Faction.java b/src/com/massivecraft/factions/Faction.java index bb390164..00d311c0 100644 --- a/src/com/massivecraft/factions/Faction.java +++ b/src/com/massivecraft/factions/Faction.java @@ -252,6 +252,21 @@ public class Faction extends Entity implements EconomyParticipator } } + public Map> getFactionTagsPerRelation() + { + Map> ret = new HashMap>(); + for (Rel rel : Rel.values()) + { + ret.put(rel, new ArrayList()); + } + 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. //----------------------------------------------// // Power diff --git a/src/com/massivecraft/factions/cmd/CmdSeeChunk.java b/src/com/massivecraft/factions/cmd/CmdSeeChunk.java new file mode 100644 index 00000000..86b6105b --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdSeeChunk.java @@ -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 getChunkPillarLocations(int chunkX, int chunkZ) + { + ArrayList ret = new ArrayList(); + + + + return ret; + } + + public ArrayList getPillar(Block block) + { + ArrayList ret = new ArrayList(); + + // y 0-127 + + for (int i = 0; i <=127; i++) + { + + } + + return ret; + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdShow.java b/src/com/massivecraft/factions/cmd/CmdShow.java index e7269810..1c2d5359 100644 --- a/src/com/massivecraft/factions/cmd/CmdShow.java +++ b/src/com/massivecraft/factions/cmd/CmdShow.java @@ -1,19 +1,21 @@ package com.massivecraft.factions.cmd; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; +import java.util.Map; import com.massivecraft.factions.Conf; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.Factions; import com.massivecraft.factions.struct.FFlag; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Rel; +import com.massivecraft.factions.zcore.util.TextUtil; public class CmdShow extends FCommand { - public CmdShow() { this.aliases.add("show"); @@ -50,24 +52,21 @@ public class CmdShow extends FCommand msg(p.txt.titleize(faction.getTag(fme))); msg("Description: %s", faction.getDescription()); - /*if ( ! faction.isNormal()) - { - return; - }*/ - String peaceStatus = ""; - if (faction.getFlag(FFlag.PEACEFUL)) - { - peaceStatus = " "+Conf.colorTruce+"This faction is Peaceful"; - } - - msg("Joining: "+(faction.getOpen() ? "no invitation is needed" : "invitation is required")+peaceStatus); - msg("Land / Power / Maxpower: %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)) { msg("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("Joining: "+(faction.getOpen() ? "no invitation is needed" : "invitation is required")); + msg("Land / Power / Maxpower: %d/%d/%d", faction.getLandRounded(), faction.getPowerRounded(), faction.getPowerMaxRounded()); // show the land value if (Econ.shouldBeUsed()) @@ -82,88 +81,62 @@ public class CmdShow extends FCommand } //Show bank contents - if(Conf.bankEnabled) { + if(Conf.bankEnabled) + { msg("Bank contains: "+Econ.moneyString(faction.getAccount().balance())); } } - String listpart; + String sepparator = p.txt.parse("")+", "; - // List relation - String allyList = p.txt.parse("Allies: "); - String enemyList = p.txt.parse("Enemies: "); - for (Faction otherFaction : Factions.i.get()) - { - if (otherFaction == faction) - { - continue; - } - listpart = otherFaction.getTag(fme)+p.txt.parse("")+", "; - 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 relations to other factions + Map> relationTags = faction.getFactionTagsPerRelation(); + sendMessage(p.txt.parse("In Truce with: ") + TextUtil.implode(relationTags.get(Rel.TRUCE), sepparator)); + sendMessage(p.txt.parse("Allied to: ") + TextUtil.implode(relationTags.get(Rel.ALLY), sepparator)); + sendMessage(p.txt.parse("Enemies: ") + TextUtil.implode(relationTags.get(Rel.ENEMY), sepparator)); // List the members... - String onlineList = p.txt.parse("")+"Members online: "; - String offlineList = p.txt.parse("")+"Members offline: "; + List memberOnlineNames = new ArrayList(); + List memberOfflineNames = new ArrayList(); + for (FPlayer follower : admins) { - listpart = follower.getNameAndTitle(fme)+p.txt.parse("")+", "; if (follower.isOnline()) { - onlineList += listpart; + memberOnlineNames.add(follower.getNameAndTitle(fme)); } else { - offlineList += listpart; + memberOfflineNames.add(follower.getNameAndTitle(fme)); } } + for (FPlayer follower : mods) { - listpart = follower.getNameAndTitle(fme)+p.txt.parse("")+", "; - if - (follower.isOnline()) + if (follower.isOnline()) { - onlineList += listpart; - } else { - offlineList += listpart; + memberOnlineNames.add(follower.getNameAndTitle(fme)); } - } - for (FPlayer follower : normals) { - listpart = follower.getNameAndTitle(fme)+p.txt.parse("")+", "; - if (follower.isOnline()) { - onlineList += listpart; - } else { - offlineList += listpart; + else + { + memberOfflineNames.add(follower.getNameAndTitle(fme)); } } - if (onlineList.endsWith(", ")) { - onlineList = onlineList.substring(0, onlineList.length()-2); - } - if (offlineList.endsWith(", ")) { - offlineList = offlineList.substring(0, offlineList.length()-2); + for (FPlayer follower : normals) + { + if (follower.isOnline()) + { + memberOnlineNames.add(follower.getNameAndTitle(fme)); + } + else + { + memberOfflineNames.add(follower.getNameAndTitle(fme)); + } } - sendMessage(onlineList); - sendMessage(offlineList); + sendMessage(p.txt.parse("Members online: ") + TextUtil.implode(memberOnlineNames, sepparator)); + sendMessage(p.txt.parse("Members offline: ") + TextUtil.implode(memberOfflineNames, sepparator)); } } diff --git a/src/com/massivecraft/factions/cmd/FCmdRoot.java b/src/com/massivecraft/factions/cmd/FCmdRoot.java index 36ca91ae..b0b993de 100644 --- a/src/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/com/massivecraft/factions/cmd/FCmdRoot.java @@ -37,6 +37,7 @@ public class FCmdRoot extends FCommand public CmdRelationTruce cmdRelationTruce = new CmdRelationTruce(); public CmdReload cmdReload = new CmdReload(); public CmdSaveAll cmdSaveAll = new CmdSaveAll(); + public CmdSeeChunk cmdSeeChunks = new CmdSeeChunk(); public CmdSethome cmdSethome = new CmdSethome(); public CmdShow cmdShow = new CmdShow(); public CmdTag cmdTag = new CmdTag(); @@ -98,6 +99,7 @@ public class FCmdRoot extends FCommand this.addSubCommand(this.cmdRelationTruce); this.addSubCommand(this.cmdReload); this.addSubCommand(this.cmdSaveAll); + this.addSubCommand(this.cmdSeeChunks); this.addSubCommand(this.cmdSethome); this.addSubCommand(this.cmdShow); this.addSubCommand(this.cmdTag);