mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
After rank change, resend block permissions, and reset mode types and block bindings if no longer permitted to place those blocks, fixes #303 and fixes #297
This commit is contained in:
parent
66b2c113ce
commit
69a109f830
@ -151,7 +151,7 @@ namespace MCGalaxy.Commands {
|
||||
public static bool GetBlockIfAllowed(Player p, string input, out ExtBlock block, bool allowSkip = false) {
|
||||
if (!GetBlock(p, input, out block, allowSkip)) return false;
|
||||
if (allowSkip && block == ExtBlock.Invalid) return true;
|
||||
return IsBlockAllowed(p, "draw with ", block);
|
||||
return IsBlockAllowed(p, "draw with", block);
|
||||
}
|
||||
|
||||
/// <summary> Returns whether the player is allowed to place/modify/delete the given block. </summary>
|
||||
|
@ -202,11 +202,6 @@ namespace MCGalaxy.Commands.Fun {
|
||||
if (!CmdNewLvl.CheckMapVolume(p, width, height, length)) return;
|
||||
|
||||
Level lvl = CountdownMapGen.Generate(width, height, length);
|
||||
lvl.Deletable = false;
|
||||
lvl.Buildable = false;
|
||||
lvl.permissionbuild = LevelPermission.Nobody;
|
||||
lvl.motd = "Welcome to the Countdown map! -hax";
|
||||
|
||||
Level oldLvl = LevelInfo.FindExact("countdown");
|
||||
if (oldLvl != null) LevelActions.Replace(oldLvl, lvl);
|
||||
else LevelInfo.Loaded.Add(lvl);
|
||||
|
@ -27,7 +27,7 @@ namespace MCGalaxy.Commands.Fun {
|
||||
|
||||
protected override void PlacedMark(Player p, ushort x, ushort y, ushort z, ExtBlock block) {
|
||||
p.RevertBlock(x, y, z);
|
||||
if (!CommandParser.IsBlockAllowed(p, "place ", block)) return;
|
||||
if (!CommandParser.IsBlockAllowed(p, "place", block)) return;
|
||||
|
||||
Thread gunThread = new Thread(() => DoShoot(p, block));
|
||||
gunThread.Name = "MCG_Gun";
|
||||
|
@ -33,7 +33,7 @@ namespace MCGalaxy.Commands.Fun {
|
||||
p.aiming = false;
|
||||
}
|
||||
p.RevertBlock(x, y, z);
|
||||
if (!CommandParser.IsBlockAllowed(p, "place ", block)) return;
|
||||
if (!CommandParser.IsBlockAllowed(p, "place", block)) return;
|
||||
|
||||
MissileArgs args = new MissileArgs();
|
||||
args.player = p;
|
||||
|
@ -165,7 +165,7 @@ namespace MCGalaxy.Commands.Info {
|
||||
default:
|
||||
Player.Message(p, "Block \"" + message + "\" appears as &b" + Block.Name(Block.Convert(b))); break;
|
||||
}
|
||||
Formatter.MessageBlock(p, "use ", b);
|
||||
Formatter.MessageBlock(p, "use", b);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
|
||||
byte block = Block.Byte(args[0]);
|
||||
if (block == Block.Invalid) { Player.Message(p, "Could not find block entered"); return; }
|
||||
if (!CommandParser.IsBlockAllowed(p, "change permissions of ", (ExtBlock)block)) return;
|
||||
if (!CommandParser.IsBlockAllowed(p, "change permissions of", (ExtBlock)block)) return;
|
||||
|
||||
if (args.Length == 2 && args[1][0] == '+') {
|
||||
Group grp = GetGroup(p, args[1].Substring(1));
|
||||
|
@ -109,7 +109,30 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
|
||||
who.SetPrefix();
|
||||
who.Send(Packet.UserType(who));
|
||||
who.SendCurrentBlockPermissions();
|
||||
Entities.SpawnEntities(who, false);
|
||||
CheckBlockBindings(who);
|
||||
}
|
||||
|
||||
static void CheckBlockBindings(Player who) {
|
||||
ExtBlock block = who.ModeBlock;
|
||||
if (block != ExtBlock.Air && !CommandParser.IsBlockAllowed(who, "place", block)) {
|
||||
who.ModeBlock = ExtBlock.Air;
|
||||
Player.Message(who, " Hence, &b{0} %Smode was turned &cOFF",
|
||||
who.level.BlockName(block));
|
||||
}
|
||||
|
||||
for (int i = 0; i < who.BlockBindings.Length; i++) {
|
||||
block = who.BlockBindings[i];
|
||||
ExtBlock defaultBinding = ExtBlock.FromRaw((byte)i);
|
||||
if (block == defaultBinding) continue;
|
||||
|
||||
if (!CommandParser.IsBlockAllowed(who, "place", block)) {
|
||||
who.BlockBindings[i] = defaultBinding;
|
||||
Player.Message(who, " Hence, binding for &b{0} %Swas unbound",
|
||||
who.level.BlockName(defaultBinding));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,7 +40,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
ExtBlock src, dst;
|
||||
if (!CommandParser.GetBlock(p, args[0], out src)) return;
|
||||
if (!CommandParser.GetBlock(p, args[1], out dst)) return;
|
||||
if (!CommandParser.IsBlockAllowed(p, "bind a block to ", dst)) return;
|
||||
if (!CommandParser.IsBlockAllowed(p, "bind a block to", dst)) return;
|
||||
if (src.IsPhysicsType) {
|
||||
Player.Message(p, "Physics blocks cannot be bound to another block."); return;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
string block = args[0].ToLower();
|
||||
data.Block = GetBlock(p, block, ref allMessage);
|
||||
if (data.Block.IsInvalid) return;
|
||||
if (!CommandParser.IsBlockAllowed(p, "place a message block of ", data.Block)) return;
|
||||
if (!CommandParser.IsBlockAllowed(p, "place a message block of", data.Block)) return;
|
||||
|
||||
if (allMessage) {
|
||||
data.Message = message;
|
||||
|
@ -54,7 +54,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
ExtBlock block;
|
||||
if (!CommandParser.GetBlock(p, message, out block)) return;
|
||||
if (block == ExtBlock.Air) { Player.Message(p, "Cannot use Air Mode."); return; }
|
||||
if (!CommandParser.IsBlockAllowed(p, "place ", (ExtBlock)block)) return;
|
||||
if (!CommandParser.IsBlockAllowed(p, "place", block)) return;
|
||||
|
||||
if (p.ModeBlock == block) {
|
||||
Player.Message(p, "&b{0} %Smode: &cOFF", p.level.BlockName(p.ModeBlock));
|
||||
|
@ -55,7 +55,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
Player.Message(p, "Invalid parameters"); return;
|
||||
}
|
||||
|
||||
if (!CommandParser.IsBlockAllowed(p, "place ", block)) return;
|
||||
if (!CommandParser.IsBlockAllowed(p, "place", block)) return;
|
||||
|
||||
x = Clamp(x, p.level.Width);
|
||||
y = Clamp(y, p.level.Height);
|
||||
|
@ -45,7 +45,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
|
||||
data.Block = GetBlock(p, block);
|
||||
if (data.Block == ExtBlock.Invalid) return;
|
||||
if (!CommandParser.IsBlockAllowed(p, "place a portal of ", data.Block)) return;
|
||||
if (!CommandParser.IsBlockAllowed(p, "place a portal of", data.Block)) return;
|
||||
|
||||
Player.Message(p, "Place an &aEntry block %Sfor the portal");
|
||||
p.ClearBlockchange();
|
||||
|
@ -33,7 +33,7 @@ namespace MCGalaxy.Drawing.Brushes {
|
||||
GetRaw(parts, filter, args, out blocks, out count);
|
||||
|
||||
// check if we're allowed to place the held block
|
||||
if (blocks[0].IsInvalid && !CommandParser.IsBlockAllowed(p, "draw with ", blocks[0])) return null;
|
||||
if (blocks[0].IsInvalid && !CommandParser.IsBlockAllowed(p, "draw with", blocks[0])) return null;
|
||||
|
||||
for (int i = 0, j = 0; i < parts.Length; i++ ) {
|
||||
if (parts[i] == "") continue;
|
||||
|
@ -66,7 +66,7 @@ namespace MCGalaxy.Drawing.Brushes {
|
||||
static bool GetTargetBlock(BrushArgs args, string[] parts, out ExtBlock target) {
|
||||
target = default(ExtBlock);
|
||||
if (parts.Length == 1) {
|
||||
if (!CommandParser.IsBlockAllowed(args.Player, "draw with ", args.Block)) return false;
|
||||
if (!CommandParser.IsBlockAllowed(args.Player, "draw with", args.Block)) return false;
|
||||
|
||||
target = args.Block; return true;
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ namespace MCGalaxy.Drawing.Brushes {
|
||||
|
||||
public override Brush Construct(BrushArgs args) {
|
||||
if (args.Message == "") {
|
||||
if (!CommandParser.IsBlockAllowed(args.Player, "draw with ", args.Block)) return null;
|
||||
if (!CommandParser.IsBlockAllowed(args.Player, "draw with", args.Block)) return null;
|
||||
return new SolidBrush(args.Block);
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ namespace MCGalaxy.Drawing.Brushes {
|
||||
|
||||
public override Brush Construct(BrushArgs args) {
|
||||
if (args.Message == "") {
|
||||
if (!CommandParser.IsBlockAllowed(args.Player, "draw with ", args.Block)) return null;
|
||||
if (!CommandParser.IsBlockAllowed(args.Player, "draw with", args.Block)) return null;
|
||||
return new CheckeredBrush(args.Block, ExtBlock.Air);
|
||||
}
|
||||
string[] parts = args.Message.SplitSpaces();
|
||||
@ -125,7 +125,7 @@ namespace MCGalaxy.Drawing.Brushes {
|
||||
|
||||
public override Brush Construct(BrushArgs args) {
|
||||
if (args.Message == "") {
|
||||
if (!CommandParser.IsBlockAllowed(args.Player, "draw with ", args.Block)) return null;
|
||||
if (!CommandParser.IsBlockAllowed(args.Player, "draw with", args.Block)) return null;
|
||||
return new StripedBrush(args.Block, ExtBlock.Air);
|
||||
}
|
||||
string[] parts = args.Message.SplitSpaces();
|
||||
|
@ -19,6 +19,7 @@ using System;
|
||||
|
||||
namespace MCGalaxy.Games {
|
||||
|
||||
/// <summary> Generates a map for countdown. </summary>
|
||||
public static class CountdownMapGen {
|
||||
|
||||
public static Level Generate(int width, int height, int length) {
|
||||
@ -31,7 +32,11 @@ namespace MCGalaxy.Games {
|
||||
MakeSquares(lvl);
|
||||
|
||||
lvl.permissionvisit = LevelPermission.Guest;
|
||||
lvl.permissionbuild = LevelPermission.Admin;
|
||||
lvl.permissionbuild = LevelPermission.Nobody;
|
||||
lvl.Deletable = false;
|
||||
lvl.Buildable = false;
|
||||
lvl.motd = "Welcome to the Countdown map! -hax";
|
||||
|
||||
lvl.spawnx = (ushort)(lvl.Width / 2);
|
||||
lvl.spawny = (ushort)(lvl.Height / 2 + 4);
|
||||
lvl.spawnz = (ushort)(lvl.Length / 2);
|
||||
|
@ -107,13 +107,12 @@ namespace MCGalaxy {
|
||||
}
|
||||
}
|
||||
|
||||
byte blockRaw = block.BlockID;
|
||||
block = BlockBindings[block.RawID];
|
||||
if (!CheckManualChange(oldB, block, doDelete)) {
|
||||
RevertBlock(x, y, z); return;
|
||||
}
|
||||
|
||||
byte blockRaw = block.BlockID;
|
||||
block = BlockBindings[block.RawID];
|
||||
|
||||
//Ignores updating blocks that are the same and send block only to the player
|
||||
byte newB = (painting || action == 1) ? block.BlockID : Block.air;
|
||||
if (oldB == newB && (painting || blockRaw != block.BlockID)) {
|
||||
@ -135,10 +134,10 @@ namespace MCGalaxy {
|
||||
|
||||
internal bool CheckManualChange(byte old, ExtBlock block, bool replaceMode) {
|
||||
if (!BlockPerms.CanModify(this, old) && !Block.BuildIn(old) && !Block.AllowBreak(old)) {
|
||||
Formatter.MessageBlock(this, replaceMode ? "replace " : "delete ", old);
|
||||
Formatter.MessageBlock(this, replaceMode ? "replace" : "delete", old);
|
||||
return false;
|
||||
}
|
||||
return CommandParser.IsBlockAllowed(this, "place ", block);
|
||||
return CommandParser.IsBlockAllowed(this, "place", block);
|
||||
}
|
||||
|
||||
bool DeleteBlock(byte old, ushort x, ushort y, ushort z, ExtBlock block) {
|
||||
|
@ -330,7 +330,7 @@ namespace MCGalaxy {
|
||||
OnPlayerDisconnectEvent.Call(this, discMsg);
|
||||
if (PlayerDisconnect != null) PlayerDisconnect(this, discMsg);
|
||||
|
||||
if (Server.AutoLoad && level.unload && !level.IsMuseum && IsAloneOnCurrentLevel())
|
||||
if (Server.AutoLoad && level.unload && !level.IsMuseum && !level.HasPlayers())
|
||||
level.Unload(true);
|
||||
Dispose();
|
||||
} catch ( Exception e ) {
|
||||
@ -356,9 +356,6 @@ namespace MCGalaxy {
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public static void SaveUndo(Player p) { }
|
||||
|
||||
public void Dispose() {
|
||||
connections.Remove(this);
|
||||
RemoveFromPending();
|
||||
@ -371,16 +368,6 @@ namespace MCGalaxy {
|
||||
spyChatRooms.Clear();
|
||||
}
|
||||
|
||||
public bool IsAloneOnCurrentLevel() {
|
||||
lock (PlayerInfo.Online.locker) {
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player p in players) {
|
||||
if (p != this && p.level == level) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region == OTHER ==
|
||||
|
||||
|
@ -96,7 +96,7 @@ namespace MCGalaxy {
|
||||
BlockPerms perms = BlockPerms.List[block];
|
||||
PrintRanks(perms.MinRank, perms.Allowed, perms.Disallowed, builder);
|
||||
|
||||
builder.Append( " %Scan ").Append(action);
|
||||
builder.Append( " %Scan ").Append(action).Append(' ');
|
||||
builder.Append(Block.Name(block)).Append(".");
|
||||
Player.Message(p, builder.ToString());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user