mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 12:42:22 -04:00
minor code cleanup, move MessageBlock and MessageCannotUse to BlockPerms and CommandPerms
This commit is contained in:
parent
545c375813
commit
73b8a0dee7
@ -18,6 +18,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using MCGalaxy.Commands;
|
||||
using MCGalaxy.Network;
|
||||
|
||||
@ -79,6 +80,15 @@ namespace MCGalaxy.Blocks {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void MessageCannotUse(Player p, string action) {
|
||||
StringBuilder builder = new StringBuilder("Only ");
|
||||
Formatter.PrintRanks(MinRank, Allowed, Disallowed, builder);
|
||||
|
||||
builder.Append( " %Scan ").Append(action).Append(' ');
|
||||
builder.Append(Block.Name(BlockID)).Append(".");
|
||||
Player.Message(p, builder.ToString());
|
||||
}
|
||||
|
||||
|
||||
static readonly object saveLock = new object();
|
||||
|
@ -79,14 +79,6 @@ namespace MCGalaxy {
|
||||
else
|
||||
Player.Message(p, "Can only {0} players ranked below {1}", action, grp.ColoredName);
|
||||
}
|
||||
|
||||
internal void MessageCannotUse(Player p) {
|
||||
CommandPerms perms = CommandPerms.Find(name);
|
||||
StringBuilder builder = new StringBuilder("Only ");
|
||||
Formatter.PrintRanks(perms.MinRank, perms.Allowed, perms.Disallowed, builder);
|
||||
builder.Append(" can use %T/" + name);
|
||||
Player.Message(p, builder.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class CommandTypes {
|
||||
|
@ -164,7 +164,7 @@ namespace MCGalaxy.Commands {
|
||||
/// <remarks> Outputs information of which ranks can modify the block if not. </remarks>
|
||||
public static bool IsBlockAllowed(Player p, string action, ExtBlock block) {
|
||||
if (p == null || BlockPerms.CanModify(p, block.BlockID)) return true;
|
||||
Formatter.MessageBlock(p, action, block.BlockID);
|
||||
BlockPerms.List[block.BlockID].MessageCannotUse(p, action);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ permissions and limitations under the Licenses.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using MCGalaxy.Blocks;
|
||||
using MCGalaxy.Commands.CPE;
|
||||
|
||||
namespace MCGalaxy.Commands.Info {
|
||||
@ -165,7 +166,8 @@ namespace MCGalaxy.Commands.Info {
|
||||
default:
|
||||
Player.Message(p, "Block \"" + message + "\" appears as &b" + Block.Name(Block.Convert(b))); break;
|
||||
}
|
||||
Formatter.MessageBlock(p, "use", b);
|
||||
|
||||
BlockPerms.List[b].MessageCannotUse(p, "use");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using MCGalaxy.Commands;
|
||||
|
||||
namespace MCGalaxy {
|
||||
@ -118,6 +119,7 @@ namespace MCGalaxy.Commands {
|
||||
return perms;
|
||||
}
|
||||
|
||||
|
||||
/// <summary> Gets the list of all loaded commands that the given rank can use. </summary>
|
||||
public static CommandList AllCommandsUsableBy(LevelPermission perm) {
|
||||
CommandList commands = new CommandList();
|
||||
@ -129,6 +131,13 @@ namespace MCGalaxy.Commands {
|
||||
}
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
|
||||
public void MessageCannotUse(Player p) {
|
||||
StringBuilder builder = new StringBuilder("Only ");
|
||||
Formatter.PrintRanks(MinRank, Allowed, Disallowed, builder);
|
||||
builder.Append(" can use %T/" + CmdName);
|
||||
Player.Message(p, builder.ToString());
|
||||
}
|
||||
|
||||
|
||||
|
@ -207,8 +207,14 @@ namespace MCGalaxy.Network {
|
||||
Logger.Log(LogType.CommandUsage, "/{0} (by {1} from IRC)", logCmd, user.Nick);
|
||||
|
||||
try {
|
||||
if (!p.group.CanExecute(cmd)) { cmd.MessageCannotUse(p); return false; }
|
||||
if (!cmd.SuperUseable) { Player.Message(p, cmd.name + " can only be used in-game."); return false; }
|
||||
if (!p.group.CanExecute(cmd)) {
|
||||
CommandPerms.Find(cmd.name).MessageCannotUse(p);
|
||||
return false;
|
||||
}
|
||||
if (!cmd.SuperUseable) {
|
||||
Player.Message(p, cmd.name + " can only be used in-game.");
|
||||
return false;
|
||||
}
|
||||
cmd.Use(p, cmdArgs);
|
||||
} catch (Exception ex) {
|
||||
Player.Message(p, "CMD Error: " + ex);
|
||||
|
@ -135,7 +135,8 @@ namespace MCGalaxy {
|
||||
|
||||
internal bool CheckManualChange(ExtBlock old, ExtBlock block, bool replaceMode) {
|
||||
if (!BlockPerms.CanModify(this, old.BlockID) && !Block.BuildIn(old.BlockID) && !Block.AllowBreak(old.BlockID)) {
|
||||
Formatter.MessageBlock(this, replaceMode ? "replace" : "delete", old.BlockID);
|
||||
string action = replaceMode ? "replace" : "delete";
|
||||
BlockPerms.List[old.BlockID].MessageCannotUse(this, action);
|
||||
return false;
|
||||
}
|
||||
return CommandParser.IsBlockAllowed(this, "place", block);
|
||||
@ -347,7 +348,7 @@ namespace MCGalaxy {
|
||||
Vec3U16 P = (Vec3U16)pos.BlockCoords;
|
||||
AABB bb = ModelBB.OffsetPosition(Pos);
|
||||
int index = level.PosToInt(P.X, P.Y, P.Z);
|
||||
|
||||
|
||||
if (level.Config.SurvivalDeath) {
|
||||
PlayerPhysics.Fall(this, bb);
|
||||
PlayerPhysics.Drown(this, bb);
|
||||
@ -702,7 +703,11 @@ namespace MCGalaxy {
|
||||
}
|
||||
}
|
||||
|
||||
if (!group.CanExecute(command)) { command.MessageCannotUse(this); return null; }
|
||||
if (!group.CanExecute(command)) {
|
||||
CommandPerms.Find(command.name).MessageCannotUse(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
string reason = Command.GetDisabledReason(command.Enabled);
|
||||
if (reason != null) {
|
||||
SendMessage("Command is disabled as " + reason); return null;
|
||||
|
@ -91,16 +91,6 @@ namespace MCGalaxy {
|
||||
}
|
||||
}
|
||||
|
||||
public static void MessageBlock(Player p, string action, byte block) {
|
||||
StringBuilder builder = new StringBuilder("Only ");
|
||||
BlockPerms perms = BlockPerms.List[block];
|
||||
PrintRanks(perms.MinRank, perms.Allowed, perms.Disallowed, builder);
|
||||
|
||||
builder.Append( " %Scan ").Append(action).Append(' ');
|
||||
builder.Append(Block.Name(block)).Append(".");
|
||||
Player.Message(p, builder.ToString());
|
||||
}
|
||||
|
||||
public static void MessageNeedMinPerm(Player p, string action, LevelPermission perm) {
|
||||
Player.Message(p, "Only {0}%S{1}", Group.GetColoredName(perm), action);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user