mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 12:42:22 -04:00
Integrate pervisitmax/perbuildmax commands into pervisit/perbuild
This commit is contained in:
parent
9e2ca5e683
commit
f3b0915e33
@ -24,38 +24,51 @@ namespace MCGalaxy.Commands.World {
|
||||
public override bool museumUsable { get { return false; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
|
||||
|
||||
protected Level GetArgs(Player p, string[] args, ref Group grp) {
|
||||
if (args.Length == 1 && Player.IsSuper(p)) {
|
||||
SuperRequiresArgs(p, "level name"); return null;
|
||||
protected static void Do(Player p, string[] args, int offset, bool max, AccessController access) {
|
||||
for (int i = offset; i < args.Length; i++) {
|
||||
string arg = args[i];
|
||||
if (arg[0] == '+' || arg[0] == '-') {
|
||||
SetList(p, access, arg);
|
||||
} else if (max) {
|
||||
Group grp = Matcher.FindRanks(p, arg);
|
||||
if (grp != null) access.SetMax(p, grp);
|
||||
} else {
|
||||
Group grp = Matcher.FindRanks(p, arg);
|
||||
if (grp != null) access.SetMin(p, grp);
|
||||
}
|
||||
}
|
||||
Level level = args.Length == 1 ? p.level : Matcher.FindLevels(p, args[0]);
|
||||
if (level == null) return null;
|
||||
|
||||
string rank = args.Length == 1 ? args[0] : args[1];
|
||||
grp = Matcher.FindRanks(p, rank);
|
||||
return grp != null ? level : null;
|
||||
}
|
||||
|
||||
protected void UseList(Player p, string[] args, bool isVisit) {
|
||||
string target = isVisit ? "pervisit" : "perbuild";
|
||||
protected void DoLevel(Player p, string message, bool visit) {
|
||||
const string maxPrefix = "-max ";
|
||||
bool max = message.CaselessStarts(maxPrefix);
|
||||
if (max) message = message.Substring(maxPrefix.Length);
|
||||
|
||||
string[] args = message.SplitSpaces();
|
||||
if (message.Length == 0 || args.Length > 2) { Help(p); return; }
|
||||
if (args.Length == 1 && Player.IsSuper(p)) {
|
||||
Command.SuperRequiresArgs(target, p, "level"); return;
|
||||
Command.SuperRequiresArgs(name, p, "level"); return;
|
||||
}
|
||||
|
||||
Level level = args.Length == 1 ? p.level : Matcher.FindLevels(p, args[0]);
|
||||
if (level == null) return;
|
||||
LevelAccessController access = isVisit ? level.VisitAccess : level.BuildAccess;
|
||||
|
||||
string name = args.Length == 1 ? args[0] : args[1];
|
||||
int offset = args.Length == 1 ? 0 : 1;
|
||||
AccessController access = visit ? level.VisitAccess : level.BuildAccess;
|
||||
Do(p, args, offset, max, access);
|
||||
}
|
||||
|
||||
static void SetList(Player p, AccessController access, string name) {
|
||||
bool include = name[0] == '+';
|
||||
string mode = include ? "whitelist" : "blacklist";
|
||||
name = name.Substring(1);
|
||||
|
||||
if (name.Length == 0) {
|
||||
Player.Message(p, "You must provide a player name to {0}.", mode); return;
|
||||
}
|
||||
|
||||
if (!Formatter.ValidName(p, name, "player")) return;
|
||||
name = PlayerInfo.FindMatchesPreferOnline(p, name);
|
||||
if (name == null) return;
|
||||
if (name == null) return;
|
||||
|
||||
if (p != null && name.CaselessEq(p.name)) {
|
||||
Player.Message(p, "You cannot {0} yourself.", mode); return;
|
||||
@ -68,18 +81,44 @@ namespace MCGalaxy.Commands.World {
|
||||
}
|
||||
}
|
||||
|
||||
protected void MaxHelp(Player p, string action) {
|
||||
Player.Message(p, "%T/{0} [Level] [Rank]", name);
|
||||
Player.Message(p, "%HSets the highest rank able to {0} the given level.", action);
|
||||
}
|
||||
|
||||
protected void NormalHelp(Player p, string action, string action2) {
|
||||
|
||||
protected void ShowHelp(Player p, string action, string action2) {
|
||||
Player.Message(p, "%T/{0} [level] [rank]", name);
|
||||
Player.Message(p, "%HSets the lowest rank able to {0} the given level.", action);
|
||||
Player.Message(p, "%T/{0} -max [Level] [Rank]", name);
|
||||
Player.Message(p, "%HSets the highest rank able to {0} the given level.", action);
|
||||
Player.Message(p, "%T/{0} [level] +[name]", name);
|
||||
Player.Message(p, "%HAllows [name] to {0}, even if their rank cannot.", action2);
|
||||
Player.Message(p, "%T/{0} [level] -[name]", name);
|
||||
Player.Message(p, "%HPrevents [name] from {0}ing, even if their rank can.", action2);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class CmdPermissionBuild : PermissionCmd {
|
||||
public override string name { get { return "PerBuild"; } }
|
||||
public override CommandAlias[] Aliases {
|
||||
get { return new[] { new CommandAlias("WBuild"), new CommandAlias("WorldBuild"),
|
||||
new CommandAlias("PerBuildMax", "-max") }; }
|
||||
}
|
||||
public override CommandPerm[] ExtraPerms {
|
||||
get { return new[] { new CommandPerm(LevelPermission.Operator, "+ bypasses max build rank restriction") }; }
|
||||
}
|
||||
|
||||
public override void Use(Player p, string message) { DoLevel(p, message, false); }
|
||||
public override void Help(Player p) { ShowHelp(p, "build on", "build"); }
|
||||
}
|
||||
|
||||
public sealed class CmdPermissionVisit : PermissionCmd {
|
||||
public override string name { get { return "PerVisit"; } }
|
||||
public override CommandAlias[] Aliases {
|
||||
get { return new[] { new CommandAlias("WAccess"), new CommandAlias("WorldAccess"),
|
||||
new CommandAlias("PerVisitMax", "-max") }; }
|
||||
}
|
||||
public override CommandPerm[] ExtraPerms {
|
||||
get { return new[] { new CommandPerm(LevelPermission.Operator, "+ bypasses max visit rank restriction") }; }
|
||||
}
|
||||
|
||||
public override void Use(Player p, string message) { DoLevel(p, message, true); }
|
||||
public override void Help(Player p) { ShowHelp(p, "visit", "visit"); }
|
||||
}
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
/*
|
||||
Copyright 2015 MCGalaxy
|
||||
|
||||
Dual-licensed under the Educational Community License, Version 2.0 and
|
||||
the GNU General Public License, Version 3 (the "Licenses"); you may
|
||||
not use this file except in compliance with the Licenses. You may
|
||||
obtain a copy of the Licenses at
|
||||
|
||||
http://www.opensource.org/licenses/ecl2.php
|
||||
http://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the Licenses are distributed on an "AS IS"
|
||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
or implied. See the Licenses for the specific language governing
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MCGalaxy.Commands.World {
|
||||
public sealed class CmdPerbuildMax : PermissionCmd {
|
||||
public override string name { get { return "PerBuildMax"; } }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
string[] args = message.SplitSpaces();
|
||||
if (args.Length < 1 || args.Length > 2) { Help(p); return; }
|
||||
|
||||
Group grp = null;
|
||||
Level lvl = GetArgs(p, args, ref grp);
|
||||
if (lvl != null) lvl.BuildAccess.SetMax(p, grp);
|
||||
}
|
||||
|
||||
public override void Help(Player p) { MaxHelp(p, "build on"); }
|
||||
}
|
||||
|
||||
public sealed class CmdPermissionBuild : PermissionCmd {
|
||||
public override string name { get { return "PerBuild"; } }
|
||||
public override CommandAlias[] Aliases {
|
||||
get { return new[] { new CommandAlias("WBuild"), new CommandAlias("WorldBuild") }; }
|
||||
}
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
string[] args = message.SplitSpaces();
|
||||
if (args.Length < 1 || args.Length > 2) { Help(p); return; }
|
||||
|
||||
string name = args[args.Length - 1];
|
||||
if (name.Length > 0 && (name[0] == '+' || name[0] == '-')) {
|
||||
UseList(p, args, false); return;
|
||||
}
|
||||
|
||||
Group grp = null;
|
||||
Level lvl = GetArgs(p, args, ref grp);
|
||||
if (lvl != null) lvl.BuildAccess.SetMin(p, grp);
|
||||
}
|
||||
|
||||
public override void Help(Player p) { NormalHelp(p, "build on", "build"); }
|
||||
}
|
||||
|
||||
public sealed class CmdPervisitMax : PermissionCmd {
|
||||
public override string name { get { return "PerVisitMax"; } }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
string[] args = message.SplitSpaces();
|
||||
if (args.Length < 1 || args.Length > 2) { Help(p); return; }
|
||||
|
||||
Group grp = null;
|
||||
Level lvl = GetArgs(p, args, ref grp);
|
||||
if (lvl != null) lvl.VisitAccess.SetMax(p, grp);
|
||||
}
|
||||
|
||||
public override void Help(Player p) { MaxHelp(p, "visit"); }
|
||||
}
|
||||
|
||||
public sealed class CmdPermissionVisit : PermissionCmd {
|
||||
public override string name { get { return "PerVisit"; } }
|
||||
public override CommandAlias[] Aliases {
|
||||
get { return new[] { new CommandAlias("WAccess"), new CommandAlias("WorldAccess") }; }
|
||||
}
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
string[] args = message.SplitSpaces();
|
||||
if (args.Length < 1 || args.Length > 2) { Help(p); return; }
|
||||
|
||||
string name = args[args.Length - 1];
|
||||
if (name.Length > 0 && (name[0] == '+' || name[0] == '-')) {
|
||||
UseList(p, args, true); return;
|
||||
}
|
||||
|
||||
Group grp = null;
|
||||
Level lvl = GetArgs(p, args, ref grp);
|
||||
if (lvl != null) lvl.VisitAccess.SetMin(p, grp);
|
||||
}
|
||||
|
||||
public override void Help(Player p) { NormalHelp(p, "visit", "visit"); }
|
||||
}
|
||||
}
|
@ -17,23 +17,18 @@
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MCGalaxy.Commands;
|
||||
|
||||
namespace MCGalaxy {
|
||||
|
||||
|
||||
/// <summary> Encapuslates access permissions (visit or build) for a level/zone. </summary>
|
||||
public abstract class AccessController {
|
||||
|
||||
/// <summary> Lowest allowed rank. </summary>
|
||||
public abstract LevelPermission Min { get; set; }
|
||||
/// <summary> Highest allowed rank. </summary>
|
||||
public abstract LevelPermission Max { get; set; }
|
||||
/// <summary> List of always allowed players, overrides rank allowances. </summary>
|
||||
public abstract LevelPermission Min { get; set; }
|
||||
public abstract LevelPermission Max { get; set; }
|
||||
public abstract List<string> Whitelisted { get; }
|
||||
/// <summary> List of never allowed players, ignores rank allowances. </summary>
|
||||
public abstract List<string> Blacklisted { get; }
|
||||
|
||||
/// <summary> Returns the formatted name for the level/zone containing these access permissions. </summary>
|
||||
protected abstract string ColoredName { get; }
|
||||
protected abstract string Action { get; }
|
||||
protected abstract string ActionIng { get; }
|
||||
@ -52,14 +47,12 @@ namespace MCGalaxy {
|
||||
return AccessResult.Whitelisted;
|
||||
|
||||
if (rank.Permission < Min) return AccessResult.BelowMinRank;
|
||||
if (rank.Permission > Max && MaxCmd != null && !rank.CanExecute(MaxCmd))
|
||||
if (rank.Permission > Max && MaxCmd != null && rank.Permission < CommandExtraPerms.MinPerm(MaxCmd)) {
|
||||
return AccessResult.AboveMaxRank;
|
||||
}
|
||||
return AccessResult.Allowed;
|
||||
}
|
||||
|
||||
/// <summary> Returns whether the given player is allowed for these access permissions. </summary>
|
||||
/// <remarks> If the player is not allowed by these access permissions,
|
||||
/// sends a message to the player describing why they are not. </remarks>
|
||||
|
||||
public bool CheckDetailed(Player p, bool ignoreRankPerm = false) {
|
||||
AccessResult result = Check(p);
|
||||
if (result == AccessResult.Allowed) return true;
|
||||
@ -87,10 +80,7 @@ namespace MCGalaxy {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary> Sets the minimum rank allowed to access these permissions. </summary>
|
||||
/// <returns> true if the minimum rank was changed, false if the given player
|
||||
/// had insufficient permission to change the minimum rank. </returns>
|
||||
|
||||
public bool SetMin(Player p, Group grp) {
|
||||
string minType = "Min " + Type;
|
||||
if (!CheckRank(p, Min, minType, false)) return false;
|
||||
@ -100,10 +90,7 @@ namespace MCGalaxy {
|
||||
OnPermissionChanged(p, grp, minType);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary> Sets the minimum rank allowed to access these permissions. </summary>
|
||||
/// <returns> true if the minimum rank was changed, false if the given player
|
||||
/// had insufficient permission to change the minimum rank. </returns>
|
||||
|
||||
public bool SetMax(Player p, Group grp) {
|
||||
string maxType = "Max " + Type;
|
||||
const LevelPermission ignore = LevelPermission.Nobody;
|
||||
@ -114,10 +101,7 @@ namespace MCGalaxy {
|
||||
OnPermissionChanged(p, grp, maxType);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary> Allows a player to access these permissions. </summary>
|
||||
/// <returns> true if the target is whitelisted, false if the given player
|
||||
/// had insufficient permission to whitelist the target. </returns>
|
||||
|
||||
public bool Whitelist(Player p, string target) {
|
||||
if (!CheckList(p, target, true)) return false;
|
||||
if (Whitelisted.CaselessContains(target)) {
|
||||
@ -134,9 +118,6 @@ namespace MCGalaxy {
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary> Prevents a player from acessing these permissions. </summary>
|
||||
/// <returns> true if the target is blacklisted, false if the given player
|
||||
/// had insufficient permission to blacklist the target. </returns>
|
||||
public bool Blacklist(Player p, string target) {
|
||||
if (!CheckList(p, target, false)) return false;
|
||||
if (Blacklisted.CaselessContains(target)) {
|
||||
@ -154,10 +135,7 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
|
||||
/// <summary> Called when min or max rank is changed. </summary>
|
||||
public abstract void OnPermissionChanged(Player p, Group grp, string type);
|
||||
|
||||
/// <summary> Called when a whitelist or blacklist is changed. </summary>
|
||||
public abstract void OnListChanged(Player p, string name, bool whitelist, bool removedFromOpposite);
|
||||
|
||||
bool CheckRank(Player p, LevelPermission perm, string type, bool newPerm) {
|
||||
@ -196,8 +174,6 @@ namespace MCGalaxy {
|
||||
/// <summary> Encapuslates access permissions (visit or build) for a level. </summary>
|
||||
public sealed class LevelAccessController : AccessController {
|
||||
|
||||
/// <summary> Whether these access permissions apply to
|
||||
/// visit (true) or build (false) permission for the level. </summary>
|
||||
public readonly bool IsVisit;
|
||||
readonly Level lvl;
|
||||
readonly LevelConfig cfg;
|
||||
@ -245,12 +221,9 @@ namespace MCGalaxy {
|
||||
protected override string Action { get { return IsVisit ? "go to" : "build in"; } }
|
||||
protected override string ActionIng { get { return IsVisit ? "going to" : "building in"; } }
|
||||
protected override string Type { get { return IsVisit ? "visit" : "build"; } }
|
||||
protected override string MaxCmd { get { return IsVisit ? "pervisitmax" : "perbuildmax"; } }
|
||||
protected override string MaxCmd { get { return IsVisit ? "PerVisit" : "PerBuild"; } }
|
||||
|
||||
|
||||
/// <summary> Messages all player on the level (and source player) notifying them that the
|
||||
/// min or max rank changed, rechecks access permissions for all players on the level,
|
||||
/// and finally saves the level properties file. </summary>
|
||||
|
||||
public override void OnPermissionChanged(Player p, Group grp, string type) {
|
||||
Update();
|
||||
Logger.Log(LogType.UserActivity, "{0} rank changed to {1} on {2}.", type, grp.Name, lvl.name);
|
||||
@ -258,10 +231,7 @@ namespace MCGalaxy {
|
||||
if (p != null && p.level != lvl)
|
||||
Player.Message(p, "{0} rank changed to {1} %Son {2}%S.", type, grp.ColoredName, ColoredName);
|
||||
}
|
||||
|
||||
/// <summary> Messages all player on the level (and source player) notifying them that the
|
||||
/// target player was whitelisted or blacklisted, rechecks access permissions
|
||||
/// for all players on the level, and finally saves the level properties file. </summary>
|
||||
|
||||
public override void OnListChanged(Player p, string name, bool whitelist, bool removedFromOpposite) {
|
||||
string type = IsVisit ? "visit" : "build";
|
||||
string msg = PlayerInfo.GetColoredName(p, name);
|
||||
|
@ -41,7 +41,7 @@ namespace MCGalaxy {
|
||||
internal static void LoadZones(Level level, string name) {
|
||||
if (!Database.TableExists("Zone" + name)) return;
|
||||
int id = 0;
|
||||
object ; // add to map perbuild.combine and modularise perbuild cmds
|
||||
object ; // add to map perbuild.
|
||||
using (DataTable table = Database.Backend.GetRows("Zone" + name, "*")) {
|
||||
foreach (DataRow row in table.Rows) {
|
||||
Zone z = Zone.Create();
|
||||
|
@ -371,7 +371,6 @@
|
||||
<Compile Include="Commands\World\CmdPause.cs" />
|
||||
<Compile Include="Commands\World\CmdWarp.cs" />
|
||||
<Compile Include="Commands\World\CmdWaypoint.cs" />
|
||||
<Compile Include="Commands\World\PermissionCmds.cs" />
|
||||
<Compile Include="Commands\World\CmdPhysics.cs" />
|
||||
<Compile Include="Commands\World\CmdRenameLvl.cs" />
|
||||
<Compile Include="Commands\World\CmdResizeLvl.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user