Adding denyCommandsDistance

This commit is contained in:
Mark Hughes 2016-09-13 11:54:20 +10:00 committed by Olof Larsson
parent 4c5eacec38
commit 8c72b5e734
No known key found for this signature in database
GPG Key ID: BBEF14F97DA52474
2 changed files with 53 additions and 7 deletions

View File

@ -889,20 +889,46 @@ public class EngineMain extends Engine
return; 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); PS ps = PS.valueOf(player.getLocation()).getChunk(true);
Faction factionAtPs = BoardColl.get().getFactionAt(ps); Faction factionAtPs = BoardColl.get().getFactionAt(ps);
if (factionAtPs == null) return; Rel factionAtRel = null;
if (factionAtPs.isNone()) return;
// ... the command may be denied in the territory of this relation type ... if (factionAtPs != null && ! factionAtPs.isNone())
Rel rel = factionAtPs.getRelationTo(mplayer); {
factionAtRel = factionAtPs.getRelationTo(mplayer);
}
List<String> 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("<b>You can't use \"<h>/%s<b>\" as there is <h>%s<b> nearby.", command, desc);
event.setCancelled(true);
return;
}
}
// ... if there is no relation here then there are no further checks ...
if (factionAtRel == null) return;
List<String> deniedCommands = MConf.get().denyCommandsTerritoryRelation.get(factionAtRel);
if (deniedCommands == null) return; if (deniedCommands == null) return;
if ( ! MUtil.containsCommand(command, deniedCommands)) return; if ( ! MUtil.containsCommand(command, deniedCommands)) return;
mplayer.msg("<b>You can't use \"<h>/%s<b>\" in %s territory.", command, Txt.getNicedEnum(rel)); mplayer.msg("<b>You can't use \"<h>/%s<b>\" in %s territory.", command, Txt.getNicedEnum(factionAtRel));
event.setCancelled(true); event.setCancelled(true);
} }

View File

@ -395,6 +395,26 @@ public class MConf extends Entity<MConf>
Rel.MEMBER, new ArrayList<String>() Rel.MEMBER, new ArrayList<String>()
); );
// 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<Rel, List<String>> denyCommandsDistanceRelation = MUtil.map(
Rel.ENEMY, MUtil.list(
"home"
),
Rel.NEUTRAL, new ArrayList<String>(),
Rel.TRUCE, new ArrayList<String>(),
Rel.ALLY, new ArrayList<String>(),
Rel.MEMBER, new ArrayList<String>()
);
// Allow bypassing the above setting when in these territories.
public List<Rel> denyCommandsDistanceBypassIn = MUtil.list(
Rel.MEMBER,
Rel.ALLY
);
// -------------------------------------------- // // -------------------------------------------- //
// CHAT // CHAT
// -------------------------------------------- // // -------------------------------------------- //