Skip to content

Commit

Permalink
Add a way for specific players to bypass model size limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Goodlyay committed Sep 26, 2023
1 parent 3d22638 commit 02a820a
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CustomModels/BlockBench.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static bool IsValid(string json, Player p, string modelName) {
}

// only do size check if they can't upload global models
if (!CommandExtraPerms.Find("CustomModel", 1).UsableBy(p.Rank)) {
if (!CmdBypassModelSizeLimit.CanBypassSizeLimit(p)) {
for (int i = 0; i < parts.Length; i++) {
// Models can be 1 block bigger if they aren't a purely personal model
bool purePersonal = new StoredCustomModel(modelName).IsPersonalPrimary();
Expand Down
85 changes: 85 additions & 0 deletions CustomModels/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -868,5 +868,90 @@ void Wear(Player p, string modelName, CommandData data) {
}
}


public sealed class CmdBypassModelSizeLimit : CmdManageList {
public override string name { get { return "Cheater"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return "fun"; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
protected override string ListName { get { return "bypass model size limit"; } }
protected override PlayerList list { get { return CustomModelsPlugin.bypassMaxSize; } }

public static bool CanBypassSizeLimit(Player p) {
if (CommandExtraPerms.Find("CustomModel", 1).UsableBy(p.Rank)) { return true; }
return bypassMaxSize.Contains(p.name);
}
}


/// <summary>
/// What a nice reusable template... too bad it's tucked away into this plugin lmao
/// </summary>
public abstract class CmdManageList : Command2 {
public override bool museumUsable { get { return true; } }
protected virtual string AddArg { get { return "add"; } }
protected virtual string RemoveArg { get { return "remove"; } }
protected abstract string ListName { get; }
protected abstract PlayerList list { get; }

public override void Use(Player p, string message, CommandData data) {
if (message.Length == 0) { Help(p); return; }
if (message.CaselessEq("list")) { UseList(p); return; }
string[] args = message.SplitSpaces(2);
if (args.Length == 1) { p.Message("You need to provide a player name."); return; }
string func = args[0];
string arg = args[1];
if (func.CaselessEq("check")) { UseCheck(p, arg); return; }
if (func.CaselessEq(AddArg)) { UseAdd(p, arg); return; }
if (func.CaselessEq(RemoveArg)) { UseRemove(p, arg); return; }
p.Message("Unknown argument \"{0}\"", func);
}
void UseCheck(Player p, string message) {
string whoName = PlayerInfo.FindMatchesPreferOnline(p, message);
if (whoName == null) { return; }

if (list.Contains(whoName)) {
p.Message("{0}&S is in the {0} list.", p.FormatNick(whoName), ListName);
} else {
p.Message("{0}&S is not in the {1) list.", p.FormatNick(whoName), ListName);
}
}
void UseAdd(Player p, string message) {
string whoName = PlayerInfo.FindMatchesPreferOnline(p, message);
if (whoName == null) { return; }

if (list.Add(whoName)) {
list.Save();
p.Message("Successfully added {0}&S to the {1} list.", p.FormatNick(whoName), ListName);
} else {
p.Message("{0}&S is already in the {1} list.", p.FormatNick(whoName), ListName);
p.Message("Use &b/{0} {1}&S to remove.", name, RemoveArg);

}
}
void UseRemove(Player p, string message) {
string whoName = PlayerInfo.FindMatchesPreferOnline(p, message);
if (whoName == null) { return; }

if (list.Remove(whoName)) {
list.Save();
p.Message("Successfully removed {0}&S from the {1} list.", p.FormatNick(whoName), ListName);
} else {
p.Message("{0}&S was not in the {1} list to begin with.", p.FormatNick(whoName), ListName);
}
}
void UseList(Player p) {
//public void Output(Player p, string group, string listCmd, string modifier)
list.Output(p, "Players in the "+ListName+" list", name+" check -all", "all");
return;
}

public override void Help(Player p) {
p.Message("&T/{0} {1} [name] &H- adds to the {2} list.", name, AddArg, ListName);
p.Message("&T/{0} {1} [name]", name, RemoveArg);
p.Message("&T/{0} check [name] &H- find out if [name] is in the {1} list.", name, ListName);
p.Message("&T/{0} list &H- display players in the {1} list.", name, ListName);
}
}
} // class CustomModelsPlugin
} // namespace MCGalaxy
4 changes: 3 additions & 1 deletion CustomModels/CustomModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static int CheckFolder(string folderPath) {

//------------------------------------------------------------------ plugin interface


internal static PlayerList bypassMaxSize;
CmdCustomModel command = null;
public override void Load(bool startup) {
command = new CmdCustomModel();
Expand Down Expand Up @@ -150,6 +150,8 @@ public override void Load(bool startup) {
SentCustomModels.TryAdd(p, new HashSet<string>(StringComparer.OrdinalIgnoreCase));
ModelNameToIdForPlayer.TryAdd(p, new ConcurrentDictionary<string, byte>(StringComparer.OrdinalIgnoreCase));
}

bypassMaxSize = PlayerList.Load(PublicModelsDirectory + "bypass_max_size.txt");
}

public override void Unload(bool shutdown) {
Expand Down

0 comments on commit 02a820a

Please sign in to comment.