From 8d31a0d4a0afe7fd49f5d6522e02e00f20b9cbe7 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Mon, 13 Oct 2014 15:14:34 +0200 Subject: [PATCH] New command structure. Todo fix broken circle claim. --- .../java/com/massivecraft/factions/Perm.java | 12 +- .../factions/cmd/CmdFactions.java | 10 +- .../factions/cmd/CmdFactionsClaim.java | 96 ---------------- .../factions/cmd/CmdFactionsSet.java | 43 +++++++ ...AutoClaim.java => CmdFactionsSetAuto.java} | 34 +++--- .../factions/cmd/CmdFactionsSetCircle.java | 66 +++++++++++ .../factions/cmd/CmdFactionsSetFill.java | 107 ++++++++++++++++++ ...onsUnclaim.java => CmdFactionsSetOne.java} | 29 ++--- .../factions/cmd/CmdFactionsSetSquare.java | 60 ++++++++++ .../factions/cmd/CmdFactionsSetTransfer.java | 76 +++++++++++++ .../factions/cmd/CmdFactionsSetX.java | 47 ++++++++ .../factions/cmd/CmdFactionsSetXRadius.java | 63 +++++++++++ .../factions/cmd/CmdFactionsSetXSimple.java | 25 ++++ .../factions/cmd/CmdFactionsSetXTransfer.java | 39 +++++++ .../factions/cmd/CmdFactionsUnclaimall.java | 81 ------------- .../massivecraft/factions/entity/MConf.java | 6 +- src/main/resources/plugin.yml | 36 +++--- 17 files changed, 592 insertions(+), 238 deletions(-) delete mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdFactionsClaim.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdFactionsSet.java rename src/main/java/com/massivecraft/factions/cmd/{CmdFactionsAutoClaim.java => CmdFactionsSetAuto.java} (52%) create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetCircle.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetFill.java rename src/main/java/com/massivecraft/factions/cmd/{CmdFactionsUnclaim.java => CmdFactionsSetOne.java} (50%) create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetSquare.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetTransfer.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetX.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetXRadius.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetXSimple.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetXTransfer.java delete mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java diff --git a/src/main/java/com/massivecraft/factions/Perm.java b/src/main/java/com/massivecraft/factions/Perm.java index c954d78b..54dfadc0 100644 --- a/src/main/java/com/massivecraft/factions/Perm.java +++ b/src/main/java/com/massivecraft/factions/Perm.java @@ -15,9 +15,6 @@ public enum Perm ACCESS_PLAYER("access.player"), ACCESS_FACTION("access.faction"), ADMIN("admin"), - AUTOCLAIM("autoclaim"), - CLAIM("claim"), - CLAIM_RADIUS("claim.radius"), CREATE("create"), DEMOTE("demote"), DESCRIPTION("description"), @@ -54,12 +51,17 @@ public enum Perm RELATION("relation"), SEECHUNK("seechunk"), SEECHUNKOLD("seechunkold"), + SET("set"), + SET_ONE("set.one"), + SET_AUTO("set.auto"), + SET_FILL("set.fill"), + SET_SQUARE("set.square"), + SET_CIRCLE("set.circle"), + SET_TRANSFER("set.transfer"), SETHOME("sethome"), NAME("name"), TITLE("title"), TITLE_COLOR("title.color"), - UNCLAIM("unclaim"), - UNCLAIM_ALL("unclaimall"), UNSETHOME("unsethome"), VERSION("version"), diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactions.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactions.java index 21a3839d..97f2ec32 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactions.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactions.java @@ -25,6 +25,7 @@ public class CmdFactions extends FactionsCommand public CmdFactionsName cmdFactionsName = new CmdFactionsName(); public CmdFactionsDescription cmdFactionsDescription = new CmdFactionsDescription(); public CmdFactionsMotd cmdFactionsMotd = new CmdFactionsMotd(); + public CmdFactionsSet cmdFactionsSet = new CmdFactionsSet(); public CmdFactionsSethome cmdFactionsSethome = new CmdFactionsSethome(); public CmdFactionsUnsethome cmdFactionsUnsethome = new CmdFactionsUnsethome(); public CmdFactionsInvite cmdFactionsInvite = new CmdFactionsInvite(); @@ -37,10 +38,6 @@ public class CmdFactions extends FactionsCommand public CmdFactionsMoney cmdFactionsMoney = new CmdFactionsMoney(); public CmdFactionsSeeChunk cmdFactionsSeeChunk = new CmdFactionsSeeChunk(); public CmdFactionsSeeChunkOld cmdFactionsSeeChunkOld = new CmdFactionsSeeChunkOld(); - public CmdFactionsClaim cmdFactionsClaim = new CmdFactionsClaim(); - public CmdFactionsAutoClaim cmdFactionsAutoClaim = new CmdFactionsAutoClaim(); - public CmdFactionsUnclaim cmdFactionsUnclaim = new CmdFactionsUnclaim(); - public CmdFactionsUnclaimall cmdFactionsUnclaimall = new CmdFactionsUnclaimall(); public CmdFactionsAccess cmdFactionsAccess = new CmdFactionsAccess(); public CmdFactionsRelationAlly cmdFactionsRelationAlly = new CmdFactionsRelationAlly(); public CmdFactionsRelationTruce cmdFactionsRelationTruce = new CmdFactionsRelationTruce(); @@ -72,6 +69,7 @@ public class CmdFactions extends FactionsCommand this.addSubCommand(this.cmdFactionsName); this.addSubCommand(this.cmdFactionsDescription); this.addSubCommand(this.cmdFactionsMotd); + this.addSubCommand(this.cmdFactionsSet); this.addSubCommand(this.cmdFactionsSethome); this.addSubCommand(this.cmdFactionsUnsethome); this.addSubCommand(this.cmdFactionsInvite); @@ -84,10 +82,6 @@ public class CmdFactions extends FactionsCommand this.addSubCommand(this.cmdFactionsMoney); this.addSubCommand(this.cmdFactionsSeeChunk); this.addSubCommand(this.cmdFactionsSeeChunkOld); - this.addSubCommand(this.cmdFactionsClaim); - this.addSubCommand(this.cmdFactionsAutoClaim); - this.addSubCommand(this.cmdFactionsUnclaim); - this.addSubCommand(this.cmdFactionsUnclaimall); this.addSubCommand(this.cmdFactionsAccess); this.addSubCommand(this.cmdFactionsRelationAlly); this.addSubCommand(this.cmdFactionsRelationTruce); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsClaim.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsClaim.java deleted file mode 100644 index 4376ec67..00000000 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsClaim.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.massivecraft.factions.cmd; - -import java.util.LinkedHashSet; -import java.util.Set; - -import com.massivecraft.factions.Perm; -import com.massivecraft.factions.cmd.arg.ARFaction; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.massivecore.cmd.arg.ARInteger; -import com.massivecraft.massivecore.cmd.req.ReqHasPerm; -import com.massivecraft.massivecore.cmd.req.ReqIsPlayer; -import com.massivecraft.massivecore.ps.PS; - - -public class CmdFactionsClaim extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsClaim() - { - // Aliases - this.addAliases("claim"); - - // Args - this.addOptionalArg("radius", "1"); - this.addOptionalArg("faction", "you"); - - // Requirements - this.addRequirements(ReqIsPlayer.get()); - this.addRequirements(ReqHasPerm.get(Perm.CLAIM.node)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() - { - // Args - Integer radius = this.arg(0, ARInteger.get(), 1); - if (radius == null) return; - - final Faction newFaction = this.arg(1, ARFaction.get(), msenderFaction); - if (newFaction == null) return; - - // MPerm - if (newFaction.isNormal() && ! MPerm.getPermTerritory().has(msender, newFaction, true)) return; - - // Radius Claim Min - if (radius < 1) - { - msg("If you specify a radius, it must be at least 1."); - return; - } - - // Radius Claim Perm - if (radius > 1 && ! Perm.CLAIM_RADIUS.has(sender, false)) - { - msg("You do not have permission to claim in a radius."); - return; - } - - // Radius Claim Max - if (radius > MConf.get().radiusClaimRadiusLimit && ! msender.isUsingAdminMode()) - { - msg("The maximum radius allowed is %s.", MConf.get().radiusClaimRadiusLimit); - return; - } - - // Get Chunks - final int radiusZero = radius -1; - final PS chunk = PS.valueOf(me).getChunk(true); - final int xmin = chunk.getChunkX() - radiusZero; - final int xmax = chunk.getChunkX() + radiusZero; - final int zmin = chunk.getChunkZ() - radiusZero; - final int zmax = chunk.getChunkZ() + radiusZero; - Set chunks = new LinkedHashSet(); - chunks.add(chunk); // The center should come first for pretty messages - for (int x = xmin; x <= xmax; x++) - { - for (int z = zmin; z <= zmax; z++) - { - chunks.add(chunk.withChunkX(x).withChunkZ(z)); - } - } - - // Apply / Inform - msender.tryClaim(newFaction, chunks); - } - -} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSet.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSet.java new file mode 100644 index 00000000..f103e4b1 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSet.java @@ -0,0 +1,43 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Perm; +import com.massivecraft.massivecore.cmd.req.ReqHasPerm; +import com.massivecraft.massivecore.cmd.req.ReqIsPlayer; + + +public class CmdFactionsSet extends FactionsCommand +{ + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public CmdFactionsSetOne cmdFactionsSetOne = new CmdFactionsSetOne(); + public CmdFactionsSetAuto cmdFactionsSetAuto = new CmdFactionsSetAuto(); + public CmdFactionsSetFill cmdFactionsSetFill = new CmdFactionsSetFill(); + public CmdFactionsSetSquare cmdFactionsSetSquare = new CmdFactionsSetSquare(); + public CmdFactionsSetCircle cmdFactionsSetCircle = new CmdFactionsSetCircle(); + public CmdFactionsSetTransfer cmdFactionsSetTransfer = new CmdFactionsSetTransfer(); + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsSet() + { + // Aliases + this.addAliases("s", "set"); + + // Add SubCommands + this.addSubCommand(this.cmdFactionsSetOne); + this.addSubCommand(this.cmdFactionsSetAuto); + this.addSubCommand(this.cmdFactionsSetFill); + this.addSubCommand(this.cmdFactionsSetSquare); + this.addSubCommand(this.cmdFactionsSetCircle); + this.addSubCommand(this.cmdFactionsSetTransfer); + + // Requirements + this.addRequirements(ReqIsPlayer.get()); + this.addRequirements(ReqHasPerm.get(Perm.SET.node)); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetAuto.java similarity index 52% rename from src/main/java/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java rename to src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetAuto.java index 55375bc5..0d679fd6 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetAuto.java @@ -1,6 +1,7 @@ package com.massivecraft.factions.cmd; import java.util.Collections; +import java.util.Set; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARFaction; @@ -10,23 +11,24 @@ import com.massivecraft.massivecore.cmd.req.ReqHasPerm; import com.massivecraft.massivecore.cmd.req.ReqIsPlayer; import com.massivecraft.massivecore.ps.PS; -public class CmdFactionsAutoClaim extends FactionsCommand + +public class CmdFactionsSetAuto extends FactionsCommand { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // - public CmdFactionsAutoClaim() + public CmdFactionsSetAuto() { // Aliases - this.addAliases("autoclaim"); + this.addAliases("a", "auto"); // Args this.addOptionalArg("faction", "you"); // Requirements - this.addRequirements(ReqHasPerm.get(Perm.AUTOCLAIM.node)); this.addRequirements(ReqIsPlayer.get()); + this.addRequirements(ReqHasPerm.get(Perm.SET_AUTO.node)); } // -------------------------------------------- // @@ -37,23 +39,29 @@ public class CmdFactionsAutoClaim extends FactionsCommand public void perform() { // Args - Faction forFaction = this.arg(0, ARFaction.get(), msenderFaction); + final Faction newFaction = this.arg(0, ARFaction.get(), msenderFaction); - if (forFaction == null || forFaction == msender.getAutoClaimFaction()) + // Disable? + if (newFaction == null || newFaction == msender.getAutoClaimFaction()) { msender.setAutoClaimFaction(null); - msg("Auto-claiming of land disabled."); + msg("Disabled auto-setting as you walk around."); return; } - // MPerm - if (forFaction.isNormal() && !MPerm.getPermTerritory().has(msender, forFaction, true)) return; + // MPerm Preemptive Check + if (newFaction.isNormal() && ! MPerm.getPermTerritory().has(msender, newFaction, true)) return; - msender.setAutoClaimFaction(forFaction); + // Apply / Inform + msender.setAutoClaimFaction(newFaction); + msg("Now auto-setting %s land.", newFaction.describeTo(msender)); - msg("Now auto-claiming land for %s.", forFaction.describeTo(msender)); + // Chunks + final PS chunk = PS.valueOf(me).getChunk(true); + Set chunks = Collections.singleton(chunk); - msender.tryClaim(forFaction, Collections.singletonList(PS.valueOf(me).getChunk(true))); + // Apply / Inform + msender.tryClaim(newFaction, chunks); } -} \ No newline at end of file +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetCircle.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetCircle.java new file mode 100644 index 00000000..aa1f457e --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetCircle.java @@ -0,0 +1,66 @@ +package com.massivecraft.factions.cmd; + +import java.util.LinkedHashSet; +import java.util.Set; + +import com.massivecraft.factions.Perm; +import com.massivecraft.massivecore.cmd.req.ReqHasPerm; +import com.massivecraft.massivecore.cmd.req.ReqIsPlayer; +import com.massivecraft.massivecore.ps.PS; + + +public class CmdFactionsSetCircle extends CmdFactionsSetXRadius +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsSetCircle() + { + // Aliases + this.addAliases("c", "circle"); + + // Requirements + this.addRequirements(ReqIsPlayer.get()); + this.addRequirements(ReqHasPerm.get(Perm.SET_CIRCLE.node)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Set getChunks() + { + // Common Startup + final PS chunk = PS.valueOf(me).getChunk(true); + final Set chunks = new LinkedHashSet(); + + Integer radiusZero = this.getRadiusZero(); + if (radiusZero == null) return null; + + double radius = radiusZero + 1.5; // Tweak ze magic constant to get ze requested behavior. + double radiusSquared = radius * radius; + + chunks.add(chunk); // The center should come first for pretty messages + + final int xmin = chunk.getChunkX() - radiusZero; + final int xmax = chunk.getChunkX() + radiusZero; + final int zmin = chunk.getChunkZ() - radiusZero; + final int zmax = chunk.getChunkZ() + radiusZero; + + for (int x = xmin; x <= xmax; x++) + { + for (int z = zmin; z <= zmax; z++) + { + double dx = x - chunk.getChunkX(); + double dz = z - chunk.getChunkZ(); + if (dx*dx + dz*dz > radiusSquared) continue; + chunks.add(chunk.withChunkX(x).withChunkZ(z)); + } + } + + return chunks; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetFill.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetFill.java new file mode 100644 index 00000000..24a84350 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetFill.java @@ -0,0 +1,107 @@ +package com.massivecraft.factions.cmd; + +import java.util.LinkedHashSet; +import java.util.Set; + +import com.massivecraft.factions.Perm; +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.massivecore.cmd.req.ReqHasPerm; +import com.massivecraft.massivecore.cmd.req.ReqIsPlayer; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.MUtil; + + +public class CmdFactionsSetFill extends CmdFactionsSetXSimple +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsSetFill() + { + // Aliases + this.addAliases("f", "fill"); + + // Requirements + this.addRequirements(ReqIsPlayer.get()); + this.addRequirements(ReqHasPerm.get(Perm.SET_FILL.node)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Set getChunks() + { + // Common Startup + final PS chunk = PS.valueOf(me).getChunk(true); + final Set chunks = new LinkedHashSet(); + + // What faction (aka color) resides there? + // NOTE: Wilderness/None is valid. + final Faction color = BoardColl.get().getFactionAt(chunk); + + // We start where we are! + chunks.add(chunk); + + // Flood! + int max = MConf.get().setFillMax; + floodSearch(chunks, color, max); + + // Limit Reached? + if (chunks.size() >= max) + { + msg("Fill limit of %d reached.", max); + return null; + } + + // OK! + return chunks; + } + + // -------------------------------------------- // + // FLOOD FILL + // -------------------------------------------- // + + public static void floodSearch(Set set, Faction color, int max) + { + // Clean + if (set == null) throw new NullPointerException("set"); + if (color == null) throw new NullPointerException("color"); + + // Expand + Set expansion = new LinkedHashSet(); + for (PS chunk : set) + { + Set neighbours = MUtil.set( + chunk.withChunkX(chunk.getChunkX() + 1), + chunk.withChunkX(chunk.getChunkX() - 1), + chunk.withChunkZ(chunk.getChunkZ() + 1), + chunk.withChunkZ(chunk.getChunkZ() - 1) + ); + + for (PS neighbour : neighbours) + { + if (set.contains(neighbour)) continue; + Faction faction = BoardColl.get().getFactionAt(neighbour); + if (faction == null) continue; + if (faction != color) continue; + expansion.add(neighbour); + } + } + set.addAll(expansion); + + // No Expansion? + if (expansion.isEmpty()) return; + + // Reached Max? + if (set.size() >= max) return; + + // Recurse + floodSearch(set, color, max); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetOne.java similarity index 50% rename from src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java rename to src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetOne.java index 38e3d073..669259e7 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetOne.java @@ -1,45 +1,40 @@ package com.massivecraft.factions.cmd; import java.util.Collections; +import java.util.Set; -import com.massivecraft.factions.cmd.req.ReqHasFaction; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; import com.massivecraft.factions.Perm; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; import com.massivecraft.massivecore.cmd.req.ReqIsPlayer; import com.massivecraft.massivecore.ps.PS; -public class CmdFactionsUnclaim extends FactionsCommand + +public class CmdFactionsSetOne extends CmdFactionsSetXSimple { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // - public CmdFactionsUnclaim() + public CmdFactionsSetOne() { // Aliases - this.addAliases("unclaim"); + this.addAliases("o", "one"); // Requirements - this.addRequirements(ReqHasPerm.get(Perm.UNCLAIM.node)); - this.addRequirements(ReqHasFaction.get()); this.addRequirements(ReqIsPlayer.get()); + this.addRequirements(ReqHasPerm.get(Perm.SET_ONE.node)); } // -------------------------------------------- // // OVERRIDE // -------------------------------------------- // - - @Override - public void perform() - { - // Args - PS chunk = PS.valueOf(me).getChunk(true); - Faction newFaction = FactionColl.get().getNone(); - // Apply - if (msender.tryClaim(newFaction, Collections.singletonList(chunk))) return; + @Override + public Set getChunks() + { + final PS chunk = PS.valueOf(me).getChunk(true); + final Set chunks = Collections.singleton(chunk); + return chunks; } } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetSquare.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetSquare.java new file mode 100644 index 00000000..ac8e64ab --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetSquare.java @@ -0,0 +1,60 @@ +package com.massivecraft.factions.cmd; + +import java.util.LinkedHashSet; +import java.util.Set; + +import com.massivecraft.factions.Perm; +import com.massivecraft.massivecore.cmd.req.ReqHasPerm; +import com.massivecraft.massivecore.cmd.req.ReqIsPlayer; +import com.massivecraft.massivecore.ps.PS; + + +public class CmdFactionsSetSquare extends CmdFactionsSetXRadius +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsSetSquare() + { + // Aliases + this.addAliases("s", "square"); + + // Requirements + this.addRequirements(ReqIsPlayer.get()); + this.addRequirements(ReqHasPerm.get(Perm.SET_SQUARE.node)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Set getChunks() + { + // Common Startup + final PS chunk = PS.valueOf(me).getChunk(true); + final Set chunks = new LinkedHashSet(); + + Integer radiusZero = this.getRadiusZero(); + if (radiusZero == null) return null; + + chunks.add(chunk); // The center should come first for pretty messages + + final int xmin = chunk.getChunkX() - radiusZero; + final int xmax = chunk.getChunkX() + radiusZero; + final int zmin = chunk.getChunkZ() - radiusZero; + final int zmax = chunk.getChunkZ() + radiusZero; + + for (int x = xmin; x <= xmax; x++) + { + for (int z = zmin; z <= zmax; z++) + { + chunks.add(chunk.withChunkX(x).withChunkZ(z)); + } + } + + return chunks; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetTransfer.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetTransfer.java new file mode 100644 index 00000000..9581f45d --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetTransfer.java @@ -0,0 +1,76 @@ +package com.massivecraft.factions.cmd; + +import java.util.Set; + +import com.massivecraft.factions.Perm; +import com.massivecraft.factions.entity.Board; +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.massivecore.cmd.arg.ARWorldId; +import com.massivecraft.massivecore.cmd.req.ReqHasPerm; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.MUtil; + + +public class CmdFactionsSetTransfer extends CmdFactionsSetXTransfer +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsSetTransfer() + { + // Aliases + this.addAliases("t", "transfer"); + + // Requirements + this.addRequirements(ReqHasPerm.get(Perm.SET_TRANSFER.node)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Set getChunks() + { + // Create Ret + Set chunks = null; + + // Args + Faction oldFaction = this.getOldFaction(); + if (oldFaction == null) return null; + + if (MUtil.list("a", "al", "all").contains(this.arg(0).toLowerCase())) + { + chunks = BoardColl.get().getChunks(oldFaction); + } + else + { + String worldId = null; + if (MUtil.list("map").contains(this.arg(0).toLowerCase())) + { + if (me != null) + { + worldId = me.getWorld().getName(); + } + else + { + msg("You must specify which map from console."); + return null; + } + } + else + { + worldId = this.arg(0, ARWorldId.get()); + if (worldId == null) return null; + } + Board board = BoardColl.get().get(worldId); + chunks = board.getChunks(oldFaction); + } + + // Return Ret + return chunks; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetX.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetX.java new file mode 100644 index 00000000..b23a3d7a --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetX.java @@ -0,0 +1,47 @@ +package com.massivecraft.factions.cmd; + +import java.util.Set; + +import com.massivecraft.factions.cmd.arg.ARFaction; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.massivecore.ps.PS; + + +public abstract class CmdFactionsSetX extends FactionsCommand +{ + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() + { + // Args + final Faction newFaction = this.getNewFaction(); + if (newFaction == null) return; + + final Set chunks = this.getChunks(); + if (chunks == null) return; + + // Apply / Inform + msender.tryClaim(newFaction, chunks); + } + + // -------------------------------------------- // + // ABSTRACT + // -------------------------------------------- // + + public abstract int getFactionArgIndex(); + + public abstract Set getChunks(); + + // -------------------------------------------- // + // EXTRAS + // -------------------------------------------- // + + public Faction getNewFaction() + { + return this.arg(this.getFactionArgIndex(), ARFaction.get(), msenderFaction); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetXRadius.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetXRadius.java new file mode 100644 index 00000000..2b668792 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetXRadius.java @@ -0,0 +1,63 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.massivecore.cmd.arg.ARInteger; + + +public abstract class CmdFactionsSetXRadius extends CmdFactionsSetX +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsSetXRadius() + { + // Args + this.addOptionalArg("radius", "1"); + this.addOptionalArg("faction", "you"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public int getFactionArgIndex() + { + return 1; + } + + // -------------------------------------------- // + // EXTRAS + // -------------------------------------------- // + + public Integer getRadius() + { + Integer radius = this.arg(0, ARInteger.get(), 1); + if (radius == null) return radius; + + // Radius Claim Min + if (radius < 1) + { + msg("If you specify a radius, it must be at least 1."); + return null; + } + + // Radius Claim Max + if (radius > MConf.get().setRadiusMax && ! msender.isUsingAdminMode()) + { + msg("The maximum radius allowed is %s.", MConf.get().setRadiusMax); + return null; + } + + return radius; + } + + public Integer getRadiusZero() + { + Integer ret = this.getRadius(); + if (ret == null) return ret; + return ret - 1; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetXSimple.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetXSimple.java new file mode 100644 index 00000000..590bebd0 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetXSimple.java @@ -0,0 +1,25 @@ +package com.massivecraft.factions.cmd; + +public abstract class CmdFactionsSetXSimple extends CmdFactionsSetX +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsSetXSimple() + { + // Args + this.addOptionalArg("faction", "you"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public int getFactionArgIndex() + { + return 0; + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetXTransfer.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetXTransfer.java new file mode 100644 index 00000000..fb791ad7 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetXTransfer.java @@ -0,0 +1,39 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.arg.ARFaction; +import com.massivecraft.factions.entity.Faction; + +public abstract class CmdFactionsSetXTransfer extends CmdFactionsSetX +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsSetXTransfer() + { + // Args + this.addRequiredArg("all|map"); + this.addRequiredArg("old"); + this.addRequiredArg("new"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public int getFactionArgIndex() + { + return 2; + } + + // -------------------------------------------- // + // EXTRAS + // -------------------------------------------- // + + public Faction getOldFaction() + { + return this.arg(1, ARFaction.get()); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java deleted file mode 100644 index 1eae1db3..00000000 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.massivecraft.factions.cmd; - -import java.util.Set; - -import com.massivecraft.factions.Perm; -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.cmd.req.ReqHasFaction; -import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.massivecore.cmd.req.ReqHasPerm; -import com.massivecraft.massivecore.ps.PS; - -public class CmdFactionsUnclaimall extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsUnclaimall() - { - // Aliases - this.addAliases("unclaimall"); - - // Requirements - this.addRequirements(ReqHasPerm.get(Perm.UNCLAIM_ALL.node)); - this.addRequirements(ReqHasFaction.get()); - this.addRequirements(ReqRoleIsAtLeast.get(Rel.OFFICER)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() - { - // Args - Faction faction = msenderFaction; - Faction newFaction = FactionColl.get().getNone(); - - // MPerm - if ( ! MPerm.getPermTerritory().has(msender, faction, true)) return; - - // Apply - Set chunks = BoardColl.get().getChunks(faction); - msender.tryClaim(newFaction, chunks); - - /* - int countTotal = chunks.size(); - int countSuccess = 0; - int countFail = 0; - for (PS chunk : chunks) - { - EventFactionsChunksChange event = new EventFactionsChunksChange(sender, chunk, newFaction); - event.run(); - if (event.isCancelled()) - { - countFail++; - } - else - { - countSuccess++; - BoardColl.get().setFactionAt(chunk, newFaction); - } - } - - // Inform - msenderFaction.msg("%s unclaimed %d of your %d faction land. You now have %d land claimed.", msender.describeTo(msenderFaction, true), countSuccess, countTotal, countFail); - - // Log - if (MConf.get().logLandUnclaims) - { - Factions.get().log(msender.getName()+" unclaimed everything for the faction: "+msenderFaction.getName()); - }*/ - - } - -} diff --git a/src/main/java/com/massivecraft/factions/entity/MConf.java b/src/main/java/com/massivecraft/factions/entity/MConf.java index e2294783..ebd5fb0a 100644 --- a/src/main/java/com/massivecraft/factions/entity/MConf.java +++ b/src/main/java/com/massivecraft/factions/entity/MConf.java @@ -148,11 +148,11 @@ public class MConf extends Entity public boolean factionNameForceUpperCase = false; // -------------------------------------------- // - // CLAIM LIMITS + // SET LIMITS // -------------------------------------------- // - // the maximum radius allowed when using the claim command. - public int radiusClaimRadiusLimit = 5; + public int setRadiusMax = 5; + public int setFillMax = 1000; // -------------------------------------------- // // CLAIMS diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 186388c2..66ec783b 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -15,9 +15,6 @@ permissions: factions.access.player: {description: grant player access, with the proper fperm, default: false} factions.access.view: {description: view access, default: false} factions.admin: {description: enable adminmode, default: false} - factions.autoclaim: {description: autoclaim when walking, default: false} - factions.claim: {description: claim land where you stand, default: false} - factions.claim.radius: {description: claim land with radius, default: false} factions.create: {description: create new faction, default: false} factions.demote: {description: demote lesser members in your faction, default: false} factions.description: {description: change faction description, default: false} @@ -54,12 +51,17 @@ permissions: factions.relation: {description: set relation wish to another faction, default: false} factions.seechunk: {description: see the chunk you stand in, default: false} factions.seechunkold: {description: see the chunk you stand in, default: false} + factions.set: {description: set faction territory, default: false} + factions.set.one: {description: set faction for a single chunk, default: false} + factions.set.auto: {description: set faction as you walk around, default: false} + factions.set.fill: {description: set faction by filling, default: false} + factions.set.square: {description: set faction by square and radius, default: false} + factions.set.circle: {description: set faction by circle and radius, default: false} + factions.set.transfer: {description: set faction by transfer, default: false} factions.sethome: {description: set the faction home, default: false} factions.name: {description: set faction name, default: false} factions.title: {description: set player title, default: false} factions.title.color: {description: set player title with color, default: false} - factions.unclaim: {description: unclaim land where you stand, default: false} - factions.unclaimall: {description: unclaim all land, default: false} factions.unsethome: {description: unset faction home, default: false} factions.version: {description: see plugin version, default: false} # -------------------------------------------- # @@ -72,9 +74,6 @@ permissions: factions.access.player: true factions.access.view: true factions.admin: true - factions.autoclaim: true - factions.claim: true - factions.claim.radius: true factions.create: true factions.demote: true factions.description: true @@ -111,12 +110,17 @@ permissions: factions.relation: true factions.seechunk: true factions.seechunkold: true + factions.set: true + factions.set.one: true + factions.set.auto: true + factions.set.fill: true + factions.set.square: true + factions.set.circle: true + factions.set.transfer: true factions.sethome: true factions.name: true factions.title: true factions.title.color: true - factions.unclaim: true - factions.unclaimall: true factions.unsethome: true factions.version: true # -------------------------------------------- # @@ -152,9 +156,6 @@ permissions: factions.access.faction: true factions.access.player: true factions.access.view: true - factions.autoclaim: true - factions.claim: true - factions.claim.radius: true factions.create: true factions.demote: true factions.description: true @@ -186,12 +187,17 @@ permissions: factions.relation: true factions.seechunk: true factions.seechunkold: true + factions.set: true + factions.set.one: true + factions.set.auto: true + factions.set.fill: true + factions.set.square: true + factions.set.circle: true + factions.set.transfer: true factions.sethome: true factions.name: true factions.title: true factions.title.color: true - factions.unclaim: true - factions.unclaimall: true factions.unsethome: true factions.version: true factions.kit.default: