Fix empty bot nametags being lost on server restart (Thanks goodlyay), also fix empty bot nametags crashing WoM.

This commit is contained in:
UnknownShadow200 2016-08-07 15:53:12 +10:00
parent 0690333259
commit 2b7a097e70
6 changed files with 24 additions and 20 deletions

View File

@ -62,9 +62,9 @@ namespace MCGalaxy.Commands {
pBot.DisplayName = pBot.name;
Player.GlobalMessage("Bot " + pBot.ColoredName + "'s %Sreverted to their original name.");
} else {
if (newName.CaselessEq("empty")) newName = "";
string nameTag = newName.CaselessEq("empty") ? "" : newName;
if (newName.Length >= 30) { Player.Message(p, "Name must be under 30 letters."); return; }
Player.GlobalMessage("Bot " + pBot.ColoredName + "'s %Sname was set to " + newName + "%S.");
Player.GlobalMessage("Bot " + pBot.ColoredName + "'s %Sname was set to " + nameTag + "%S.");
pBot.DisplayName = newName;
}

View File

@ -87,8 +87,8 @@ namespace MCGalaxy.Commands.Building {
p.ClearBlockchange();
CatchPos cpos = (CatchPos)p.blockchangeObject;
byte b = p.level.GetTile(x, y, z);
if (p.level.CheckAffectPermissions(p, x, y, z, b, cpos.type, 0)) {
byte old = p.level.GetTile(x, y, z);
if (p.level.CheckAffectPermissions(p, x, y, z, old, cpos.type, 0)) {
p.level.Blockchange(p, x, y, z, cpos.type, 0);
p.SendBlockchange(x, y, z, cpos.type, 0); // for when same block type but different message
UpdateDatabase(p, cpos, x, y, z);

View File

@ -60,7 +60,8 @@ namespace MCGalaxy.Commands.Building {
void EntryChange(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
PortalData bp = (PortalData)p.blockchangeObject;
if (!p.level.CheckAffectPermissions(p, x, y, z, type, extType)) {
byte old = p.level.GetTile(x, y, z);
if (!p.level.CheckAffectPermissions(p, x, y, z, old, type, extType)) {
p.RevertBlock(x, y, z); return;
}
p.ClearBlockchange();

View File

@ -133,7 +133,7 @@ namespace MCGalaxy.Drawing.Ops {
foreach (var b in item.Op.Perform(item.Marks, p, lvl, item.Brush)) {
if (b.Block == Block.Zero) continue;
byte old = lvl.GetTile(b.X, b.Y, b.Z);
if (old == Block.Zero || !lvl.CheckAffectPermissions(p, b.X, b.Y, b.Z, old, b.Block))
if (old == Block.Zero || !lvl.CheckAffectPermissions(p, b.X, b.Y, b.Z, old, b.Block, b.ExtBlock))
continue;
lvl.SetTile(b.X, b.Y, b.Z, b.Block, p, b.ExtBlock);

View File

@ -239,7 +239,8 @@ namespace MCGalaxy {
return true;
}
public bool CheckAffectPermissions(Player p, ushort x, ushort y, ushort z, byte b, byte type, byte extType = 0) {
public bool CheckAffectPermissions(Player p, ushort x, ushort y, ushort z,
byte b, byte type, byte extType = 0) {
if (!Block.AllowBreak(b) && !Block.canPlace(p, b) && !Block.BuildIn(b)) return false;
if (p.PlayingTntWars && !CheckTNTWarsChange(p, x, y, z, ref type)) return false;
@ -266,24 +267,24 @@ namespace MCGalaxy {
{
//if (x < 0 || y < 0 || z < 0) return;
if (x >= Width || y >= Height || z >= Length) return false;
byte b = GetTile(x, y, z), extB = 0;
if (b == Block.custom_block) extB = GetExtTile(x, y, z);
byte old = GetTile(x, y, z), extOld = 0;
if (old == Block.custom_block) extOld = GetExtTile(x, y, z);
errorLocation = "Permission checking";
if (!CheckAffectPermissions(p, x, y, z, b, block, extBlock)) {
if (!CheckAffectPermissions(p, x, y, z, old, block, extBlock)) {
p.RevertBlock(x, y, z); return false;
}
if (b == Block.sponge && physics > 0 && block != Block.sponge)
if (old == Block.sponge && physics > 0 && block != Block.sponge)
OtherPhysics.DoSpongeRemoved(this, PosToInt(x, y, z));
if (b == Block.lava_sponge && physics > 0 && block != Block.lava_sponge)
if (old == Block.lava_sponge && physics > 0 && block != Block.lava_sponge)
OtherPhysics.DoSpongeRemoved(this, PosToInt(x, y, z), true);
errorLocation = "Undo buffer filling";
Player.UndoPos Pos;
Pos.x = x; Pos.y = y; Pos.z = z;
Pos.mapName = name;
Pos.type = b; Pos.extType = extB;
Pos.type = old; Pos.extType = extOld;
Pos.newtype = block; Pos.newExtType = extBlock;
Pos.timeDelta = (int)DateTime.UtcNow.Subtract(Server.StartTime).TotalSeconds;
p.UndoBuffer.Add(this, Pos);
@ -292,7 +293,7 @@ namespace MCGalaxy {
p.IncrementBlockStats(block, drawn);
SetTile(x, y, z, block);
if (b == Block.custom_block && block != Block.custom_block)
if (old == Block.custom_block && block != Block.custom_block)
RevertExtTileNoCheck(x, y, z);
if (block == Block.custom_block)
SetExtTileNoCheck(x, y, z, extBlock);
@ -303,8 +304,8 @@ namespace MCGalaxy {
changed = true;
backedup = false;
bool diffBlock = b == Block.custom_block ? extB != extBlock :
Block.Convert(b) != Block.Convert(block);
bool diffBlock = old == Block.custom_block ? extOld != extBlock :
Block.Convert(old) != Block.Convert(block);
return diffBlock;
} catch (OutOfMemoryException) {
Player.Message(p, "Undo buffer too big! Cleared!");

View File

@ -137,12 +137,14 @@ namespace MCGalaxy {
internal static void Spawn(Player dst, PlayerBot b) {
string name = Chat.ApplyTokens(b.DisplayName, dst);
if (name.CaselessEq("empty")) name = "";
else name = b.color + name;
string skin = Chat.ApplyTokens(b.SkinName, dst);
if (dst.hasExtList) {
dst.SendExtAddEntity2(b.id, skin, b.color + name, b.pos[0], b.pos[1], b.pos[2], b.rot[0], b.rot[1]);
dst.SendExtAddEntity2(b.id, skin, name, b.pos[0], b.pos[1], b.pos[2], b.rot[0], b.rot[1]);
} else {
dst.SendSpawn(b.id, b.color + name, b.pos[0], b.pos[1], b.pos[2], b.rot[0], b.rot[1]);
dst.SendSpawn(b.id, name, b.pos[0], b.pos[1], b.pos[2], b.rot[0], b.rot[1]);
}
if (Server.TablistBots)
TabList.Add(dst, b);