mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Remove redundant code in BlockDefinitions.cs, remove hardcoded rank aliases asides from 'op
This commit is contained in:
parent
abd3bfd153
commit
a836014694
@ -104,8 +104,9 @@ namespace MCGalaxy {
|
||||
// We don't want to save global blocks in the level's custom blocks list
|
||||
if (!global) {
|
||||
BlockDefinition[] realDefs = new BlockDefinition[Block.Count];
|
||||
for (int i = 0; i < Block.Count; i++)
|
||||
for (int i = 0; i < Block.Count; i++) {
|
||||
realDefs[i] = defs[i] == GlobalDefs[i] ? null : defs[i];
|
||||
}
|
||||
defs = realDefs;
|
||||
}
|
||||
|
||||
@ -171,14 +172,7 @@ namespace MCGalaxy {
|
||||
if (!pl.hasBlockDefs) continue;
|
||||
if (global && pl.level.CustomBlockDefs[raw] != GlobalDefs[raw]) continue;
|
||||
|
||||
if (pl.HasCpeExt(CpeExt.BlockDefinitionsExt, 2) && def.Shape != 0) {
|
||||
pl.Send(Packet.DefineBlockExt(def, true, pl.hasCP437));
|
||||
} else if (pl.HasCpeExt(CpeExt.BlockDefinitionsExt) && def.Shape != 0) {
|
||||
pl.Send(Packet.DefineBlockExt(def, false, pl.hasCP437));
|
||||
} else {
|
||||
pl.Send(Packet.DefineBlock(def, pl.hasCP437));
|
||||
}
|
||||
|
||||
pl.Send(def.MakeDefinePacket(pl));
|
||||
if (pl.HasCpeExt(CpeExt.BlockPermissions))
|
||||
pl.Send(Packet.BlockPermission(def.BlockID, pl.level.CanPlace, pl.level.CanDelete));
|
||||
}
|
||||
@ -249,15 +243,17 @@ namespace MCGalaxy {
|
||||
BlockDefinition[] defs = pl.level.CustomBlockDefs;
|
||||
for (int i = 1; i < defs.Length; i++) {
|
||||
BlockDefinition def = defs[i];
|
||||
if (def == null) continue;
|
||||
|
||||
if (pl.HasCpeExt(CpeExt.BlockDefinitionsExt, 2) && def.Shape != 0) {
|
||||
pl.Send(Packet.DefineBlockExt(def, true, pl.hasCP437));
|
||||
} else if (pl.HasCpeExt(CpeExt.BlockDefinitionsExt) && def.Shape != 0) {
|
||||
pl.Send(Packet.DefineBlockExt(def, false, pl.hasCP437));
|
||||
} else {
|
||||
pl.Send(Packet.DefineBlock(def, pl.hasCP437));
|
||||
}
|
||||
if (def != null) pl.Send(def.MakeDefinePacket(pl));
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] MakeDefinePacket(Player pl) {
|
||||
if (pl.HasCpeExt(CpeExt.BlockDefinitionsExt, 2) && Shape != 0) {
|
||||
return Packet.DefineBlockExt(this, true, pl.hasCP437);
|
||||
} else if (pl.HasCpeExt(CpeExt.BlockDefinitionsExt) && Shape != 0) {
|
||||
return Packet.DefineBlockExt(this, false, pl.hasCP437);
|
||||
} else {
|
||||
return Packet.DefineBlock(this, pl.hasCP437);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,10 +237,9 @@ namespace MCGalaxy {
|
||||
|
||||
void RemoveOldLevelCustomBlocks(Level oldLevel) {
|
||||
BlockDefinition[] defs = oldLevel.CustomBlockDefs;
|
||||
for (int i = 1; i < 256; i++) {
|
||||
for (int i = 1; i < defs.Length; i++) {
|
||||
BlockDefinition def = defs[i];
|
||||
if (def == null || def == BlockDefinition.GlobalDefs[i]) continue;
|
||||
|
||||
if (def == BlockDefinition.GlobalDefs[i]) continue;
|
||||
Send(Packet.UndefineBlock((byte)i));
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ namespace MCGalaxy {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public static void AddAndLoadGroup(Group grp) {
|
||||
public static void Register(Group grp) {
|
||||
GroupList.Add(grp);
|
||||
grp.LoadPlayers();
|
||||
|
||||
@ -125,17 +125,17 @@ namespace MCGalaxy {
|
||||
GroupProperties.InitAll();
|
||||
} else {
|
||||
// Add some default ranks
|
||||
AddAndLoadGroup(new Group(LevelPermission.Builder, 400, 300, "Builder", '2', "", null));
|
||||
AddAndLoadGroup(new Group(LevelPermission.AdvBuilder, 1200, 900, "AdvBuilder", '3', "", null));
|
||||
AddAndLoadGroup(new Group(LevelPermission.Operator, 2500, 5400, "Operator", 'c', "", null));
|
||||
AddAndLoadGroup(new Group(LevelPermission.Admin, 65536, int.MaxValue, "SuperOP", 'e', "", null));
|
||||
Register(new Group(LevelPermission.Builder, 400, 300, "Builder", '2', "", null));
|
||||
Register(new Group(LevelPermission.AdvBuilder, 1200, 900, "AdvBuilder", '3', "", null));
|
||||
Register(new Group(LevelPermission.Operator, 2500, 5400, "Operator", 'c', "", null));
|
||||
Register(new Group(LevelPermission.Admin, 65536, int.MaxValue, "SuperOP", 'e', "", null));
|
||||
}
|
||||
|
||||
if (BannedRank == null)
|
||||
AddAndLoadGroup(new Group(LevelPermission.Banned, 1, 1, "Banned", '8', "", null));
|
||||
Register(new Group(LevelPermission.Banned, 1, 1, "Banned", '8', "", null));
|
||||
if (GuestRank == null)
|
||||
AddAndLoadGroup(new Group(LevelPermission.Guest, 1, 120, "Guest", '7', "", null));
|
||||
AddAndLoadGroup(new Group(LevelPermission.Nobody, 65536, -1, "Nobody", '0', "", null));
|
||||
Register(new Group(LevelPermission.Guest, 1, 120, "Guest", '7', "", null));
|
||||
Register(new Group(LevelPermission.Nobody, 65536, -1, "Nobody", '0', "", null));
|
||||
GroupList.Sort((a, b) => a.Permission.CompareTo(b.Permission));
|
||||
|
||||
if (Find(ServerConfig.DefaultRankName) != null) {
|
||||
@ -225,10 +225,7 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
internal static void MapName(ref string name) {
|
||||
if (name == "adv") name = "advbuilder";
|
||||
if (name == "op") name = "operator";
|
||||
if (name == "super" || (name == "admin" && !Exists("admin"))) name = "superop";
|
||||
if (name == "noone") name = "nobody";
|
||||
}
|
||||
|
||||
/// <summary> Finds the group which has the given permission level. </summary>
|
||||
@ -252,12 +249,6 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
|
||||
public static string GetName(LevelPermission perm) {
|
||||
Group grp = findPerm(perm);
|
||||
if (grp != null) return grp.trueName;
|
||||
return ((int)perm).ToString();
|
||||
}
|
||||
|
||||
public static string GetColoredName(LevelPermission perm) {
|
||||
Group grp = findPerm(perm);
|
||||
if (grp != null) return grp.ColoredName;
|
||||
|
@ -38,7 +38,7 @@ namespace MCGalaxy {
|
||||
value = value.Replace(" ", "");
|
||||
string name = value.ToLower();
|
||||
|
||||
if (name == "adv" || name == "op" || name == "super" || name == "nobody" || name == "noone") {
|
||||
if (name == "op" || name == "nobody") {
|
||||
Logger.Log(LogType.Warning, "Cannot have a rank named \"{0}\", this rank is hard-coded.", name);
|
||||
} else if (Group.GroupList.Find(g => g.name == name) == null) {
|
||||
grp = new Group();
|
||||
@ -111,7 +111,7 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
static void AddGroup(ref Group grp) {
|
||||
Group.AddAndLoadGroup(
|
||||
Group.Register(
|
||||
new Group(grp.Permission, grp.maxBlocks, grp.maxUndo, grp.trueName,
|
||||
grp.color[0], grp.MOTD, grp.fileName, grp.OverseerMaps, grp.prefix));
|
||||
grp = null;
|
||||
|
Loading…
x
Reference in New Issue
Block a user