From 8c72b5e734b2cc71f8c1a8e4b921b9c47a5ba809 Mon Sep 17 00:00:00 2001 From: Mark Hughes Date: Tue, 13 Sep 2016 11:54:20 +1000 Subject: [PATCH] Adding denyCommandsDistance --- .../factions/engine/EngineMain.java | 40 +++++++++++++++---- .../massivecraft/factions/entity/MConf.java | 20 ++++++++++ 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/com/massivecraft/factions/engine/EngineMain.java b/src/com/massivecraft/factions/engine/EngineMain.java index 6a30f409..cf511b13 100644 --- a/src/com/massivecraft/factions/engine/EngineMain.java +++ b/src/com/massivecraft/factions/engine/EngineMain.java @@ -889,20 +889,46 @@ public class EngineMain extends Engine return; } - // ... if there is a faction at the players location ... + // ... if there is a faction at the players location we fetch the relation now ... PS ps = PS.valueOf(player.getLocation()).getChunk(true); Faction factionAtPs = BoardColl.get().getFactionAt(ps); - if (factionAtPs == null) return; - if (factionAtPs.isNone()) return; + Rel factionAtRel = null; - // ... the command may be denied in the territory of this relation type ... - Rel rel = factionAtPs.getRelationTo(mplayer); + if (factionAtPs != null && ! factionAtPs.isNone()) + { + factionAtRel = factionAtPs.getRelationTo(mplayer); + } - List deniedCommands = MConf.get().denyCommandsTerritoryRelation.get(rel); + // ... there maybe be a player in the distance that denies the command ... + if (MConf.get().denyCommandsDistance > -1 && ! MConf.get().denyCommandsDistanceBypassIn.contains(factionAtRel)) + { + for (Player otherplayer : player.getWorld().getPlayers()) + { + MPlayer othermplayer = MPlayer.get(otherplayer); + if (othermplayer == mplayer) continue; + + double distance = player.getLocation().distance(otherplayer.getLocation()); + if (MConf.get().denyCommandsDistance > distance) continue; + + Rel playerRel = mplayer.getRelationTo(othermplayer); + if ( ! MConf.get().denyCommandsDistanceRelation.containsKey(playerRel)) continue; + + String desc = playerRel.getDescPlayerOne(); + + mplayer.msg("You can't use \"/%s\" as there is %s nearby.", command, desc); + event.setCancelled(true); + return; + } + } + + // ... if there is no relation here then there are no further checks ... + if (factionAtRel == null) return; + + List deniedCommands = MConf.get().denyCommandsTerritoryRelation.get(factionAtRel); if (deniedCommands == null) return; if ( ! MUtil.containsCommand(command, deniedCommands)) return; - mplayer.msg("You can't use \"/%s\" in %s territory.", command, Txt.getNicedEnum(rel)); + mplayer.msg("You can't use \"/%s\" in %s territory.", command, Txt.getNicedEnum(factionAtRel)); event.setCancelled(true); } diff --git a/src/com/massivecraft/factions/entity/MConf.java b/src/com/massivecraft/factions/entity/MConf.java index 8bab3c95..012100a6 100644 --- a/src/com/massivecraft/factions/entity/MConf.java +++ b/src/com/massivecraft/factions/entity/MConf.java @@ -395,6 +395,26 @@ public class MConf extends Entity Rel.MEMBER, new ArrayList() ); + // The distance for denying the following commands. Set to -1 to disable. + public double denyCommandsDistance = -1; + + // Lists of commands to deny depending on your relation to a nearby enemy in the above distance. + public Map> denyCommandsDistanceRelation = MUtil.map( + Rel.ENEMY, MUtil.list( + "home" + ), + Rel.NEUTRAL, new ArrayList(), + Rel.TRUCE, new ArrayList(), + Rel.ALLY, new ArrayList(), + Rel.MEMBER, new ArrayList() + ); + + // Allow bypassing the above setting when in these territories. + public List denyCommandsDistanceBypassIn = MUtil.list( + Rel.MEMBER, + Rel.ALLY + ); + // -------------------------------------------- // // CHAT // -------------------------------------------- //