From 2ac847fe14a0be791758a72ec927af26c1bb3e07 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 22 Oct 2014 07:50:30 +0200 Subject: [PATCH] Added tip to /f set. Empowered board interface with extra methods. --- .../factions/cmd/CmdFactionsDisband.java | 2 +- .../factions/cmd/CmdFactionsSet.java | 4 + .../massivecraft/factions/entity/Board.java | 58 +++++++++++++ .../factions/entity/BoardColl.java | 81 +++++++++++++++++++ .../factions/entity/BoardInterface.java | 4 + .../massivecraft/factions/entity/MPlayer.java | 10 +-- 6 files changed, 153 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDisband.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDisband.java index 812bd499..e1187149 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDisband.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDisband.java @@ -40,7 +40,7 @@ public class CmdFactionsDisband extends FactionsCommand @Override public void perform() - { + { // Args Faction faction = this.arg(0, ARFaction.get(), msenderFaction); if (faction == null) return; diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSet.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSet.java index 8c712c08..2133ea5c 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSet.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSet.java @@ -33,9 +33,13 @@ public class CmdFactionsSet extends FactionsCommand this.addSubCommand(this.cmdFactionsSetSquare); this.addSubCommand(this.cmdFactionsSetCircle); this.addSubCommand(this.cmdFactionsSetTransfer); + + this.setHelp("Tip: Set faction none to unclaim."); // Requirements this.addRequirements(ReqHasPerm.get(Perm.SET.node)); } + + } diff --git a/src/main/java/com/massivecraft/factions/entity/Board.java b/src/main/java/com/massivecraft/factions/entity/Board.java index 2ad90349..e0bc8d90 100644 --- a/src/main/java/com/massivecraft/factions/entity/Board.java +++ b/src/main/java/com/massivecraft/factions/entity/Board.java @@ -17,6 +17,8 @@ import com.massivecraft.factions.Factions; import com.massivecraft.factions.RelationParticipator; import com.massivecraft.factions.TerritoryAccess; import com.massivecraft.factions.util.AsciiCompass; +import com.massivecraft.massivecore.collections.MassiveMap; +import com.massivecraft.massivecore.collections.MassiveSet; import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.store.Entity; import com.massivecraft.massivecore.util.Txt; @@ -181,6 +183,7 @@ public class Board extends Entity implements BoardInterface return this.getChunks(faction.getId()); } + @Override public Set getChunks(String factionId) { Set ret = new HashSet(); @@ -196,6 +199,35 @@ public class Board extends Entity implements BoardInterface return ret; } + @Override + public Map> getFactionToChunks() + { + Map> ret = new MassiveMap<>(); + + for (Entry entry : this.map.entrySet()) + { + // Get Faction + TerritoryAccess ta = entry.getValue(); + Faction faction = ta.getHostFaction(); + if (faction == null) continue; + + // Get Chunks + Set chunks = ret.get(faction); + if (chunks == null) + { + chunks = new MassiveSet<>(); + ret.put(faction, chunks); + } + + // Add Chunk + PS chunk = entry.getKey(); + chunk = chunk.withWorld(this.getId()); + chunks.add(chunk); + } + + return ret; + } + // COUNT @Override @@ -216,6 +248,32 @@ public class Board extends Entity implements BoardInterface return ret; } + @Override + public Map getFactionToCount() + { + Map ret = new MassiveMap<>(); + + for (Entry entry : this.map.entrySet()) + { + // Get Faction + TerritoryAccess ta = entry.getValue(); + Faction faction = ta.getHostFaction(); + if (faction == null) continue; + + // Get Count + Integer count = ret.get(faction); + if (count == null) + { + count = 0; + } + + // Add Chunk + ret.put(faction, count + 1); + } + + return ret; + } + // NEARBY DETECTION // Is this coord NOT completely surrounded by coords claimed by the same faction? diff --git a/src/main/java/com/massivecraft/factions/entity/BoardColl.java b/src/main/java/com/massivecraft/factions/entity/BoardColl.java index fd714f31..eacdb7d8 100644 --- a/src/main/java/com/massivecraft/factions/entity/BoardColl.java +++ b/src/main/java/com/massivecraft/factions/entity/BoardColl.java @@ -6,12 +6,14 @@ import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import com.massivecraft.factions.Const; import com.massivecraft.factions.Factions; import com.massivecraft.factions.RelationParticipator; import com.massivecraft.factions.TerritoryAccess; +import com.massivecraft.massivecore.collections.MassiveMap; import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.store.Coll; import com.massivecraft.massivecore.store.MStore; @@ -128,6 +130,51 @@ public class BoardColl extends Coll implements BoardInterface return ret; } + @Override + public Set getChunks(String factionId) + { + Set ret = new HashSet(); + for (Board board : this.getAll()) + { + ret.addAll(board.getChunks(factionId)); + } + return ret; + } + + @Override + public Map> getFactionToChunks() + { + Map> ret = null; + for (Board board : this.getAll()) + { + // Use the first board directly + Map> factionToChunks = board.getFactionToChunks(); + if (ret == null) + { + ret = factionToChunks; + continue; + } + + // Merge the following boards + for (Entry> entry : factionToChunks.entrySet()) + { + Faction faction = entry.getKey(); + Set chunks = ret.get(faction); + if (chunks == null) + { + ret.put(faction, entry.getValue()); + } + else + { + chunks.addAll(entry.getValue()); + } + } + } + + if (ret == null) ret = new MassiveMap<>(); + return ret; + } + // COUNT @Override @@ -147,6 +194,40 @@ public class BoardColl extends Coll implements BoardInterface return ret; } + @Override + public Map getFactionToCount() + { + Map ret = null; + for (Board board : this.getAll()) + { + // Use the first board directly + Map factionToCount = board.getFactionToCount(); + if (ret == null) + { + ret = factionToCount; + continue; + } + + // Merge the following boards + for (Entry entry : factionToCount.entrySet()) + { + Faction faction = entry.getKey(); + Integer count = ret.get(faction); + if (count == null) + { + ret.put(faction, entry.getValue()); + } + else + { + ret.put(faction, count + entry.getValue()); + } + } + } + + if (ret == null) ret = new MassiveMap<>(); + return ret; + } + // NEARBY DETECTION @Override diff --git a/src/main/java/com/massivecraft/factions/entity/BoardInterface.java b/src/main/java/com/massivecraft/factions/entity/BoardInterface.java index bd5a197f..79daf440 100644 --- a/src/main/java/com/massivecraft/factions/entity/BoardInterface.java +++ b/src/main/java/com/massivecraft/factions/entity/BoardInterface.java @@ -1,6 +1,7 @@ package com.massivecraft.factions.entity; import java.util.ArrayList; +import java.util.Map; import java.util.Set; import com.massivecraft.factions.RelationParticipator; @@ -24,10 +25,13 @@ public interface BoardInterface // CHUNKS public Set getChunks(Faction faction); + public Set getChunks(String factionId); + public Map> getFactionToChunks(); // COUNT public int getCount(Faction faction); public int getCount(String factionId); + public Map getFactionToCount(); // NEARBY DETECTION public boolean isBorderPs(PS ps); diff --git a/src/main/java/com/massivecraft/factions/entity/MPlayer.java b/src/main/java/com/massivecraft/factions/entity/MPlayer.java index cfc3efba..e76882ab 100644 --- a/src/main/java/com/massivecraft/factions/entity/MPlayer.java +++ b/src/main/java/com/massivecraft/factions/entity/MPlayer.java @@ -804,6 +804,7 @@ public class MPlayer extends SenderEntity implements EconomyParticipato { return this.tryClaim(newFaction, pss, null, null); } + public boolean tryClaim(Faction newFaction, Collection pss, String formatOne, String formatMany) { // Args @@ -875,14 +876,13 @@ public class MPlayer extends SenderEntity implements EconomyParticipato { Set ret = new HashSet(); - ret.add(msender); + if (msender != null) ret.add(msender); for (Faction faction : factions) { - if (faction.isNormal()) - { - ret.addAll(faction.getMPlayers()); - } + if (faction == null) continue; + if (faction.isNone()) continue; + ret.addAll(faction.getMPlayers()); } if (MConf.get().logLandClaims)