From abe20df16a8cecac713c057221cae1d8bebe25fc Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 6 Jan 2017 07:49:57 +1100 Subject: [PATCH] less reliant on core ranks existing --- MCGalaxy/Commands/Information/CmdBlocks.cs | 4 +- MCGalaxy/Commands/Information/CmdHelp.cs | 3 +- MCGalaxy/Commands/Information/CmdUnloaded.cs | 8 ++-- MCGalaxy/Commands/other/CmdAscend.cs | 2 +- MCGalaxy/Commands/other/CmdDescend.cs | 2 +- MCGalaxy/Commands/other/CmdFly.cs | 2 +- MCGalaxy/Database/BlockDB/BlockDBCache.cs | 41 ++++++++++++++++++++ MCGalaxy/Economy/Item.cs | 3 +- MCGalaxy/Levels/Level.Fields.cs | 9 ++--- MCGalaxy/Player/Group/Group.cs | 8 +++- 10 files changed, 60 insertions(+), 22 deletions(-) create mode 100644 MCGalaxy/Database/BlockDB/BlockDBCache.cs diff --git a/MCGalaxy/Commands/Information/CmdBlocks.cs b/MCGalaxy/Commands/Information/CmdBlocks.cs index c984ce261..69e256e05 100644 --- a/MCGalaxy/Commands/Information/CmdBlocks.cs +++ b/MCGalaxy/Commands/Information/CmdBlocks.cs @@ -88,9 +88,7 @@ namespace MCGalaxy.Commands internal static string FormatBlockName(string block, int i) { Block.Blocks perms = Block.BlockList[Block.Byte(block)]; - Group grp = Group.findPerm(perms.lowestRank); - string col = grp == null ? "&f" : grp.color; - return col + block; + return Group.GetColor(perms.lowestRank) + block; } static void OutputBlockData(Player p, string block) { diff --git a/MCGalaxy/Commands/Information/CmdHelp.cs b/MCGalaxy/Commands/Information/CmdHelp.cs index 869e1a4a9..2bd01c2fe 100644 --- a/MCGalaxy/Commands/Information/CmdHelp.cs +++ b/MCGalaxy/Commands/Information/CmdHelp.cs @@ -182,8 +182,7 @@ namespace MCGalaxy.Commands { internal static string GetColor(Command cmd) { LevelPermission perm = GrpCommands.MinPerm(cmd); - Group grp = Group.findPerm(perm); - return grp == null ? "&f" : grp.color; + return Group.GetColor(perm); } public override void Help(Player p) { diff --git a/MCGalaxy/Commands/Information/CmdUnloaded.cs b/MCGalaxy/Commands/Information/CmdUnloaded.cs index 63b78f6bc..94a37e694 100644 --- a/MCGalaxy/Commands/Information/CmdUnloaded.cs +++ b/MCGalaxy/Commands/Information/CmdUnloaded.cs @@ -54,13 +54,11 @@ namespace MCGalaxy.Commands { bool loadOnGoto; RetrieveProps(map, out visitP, out buildP, out loadOnGoto); - LevelPermission perm = visitP; - if (perm < buildP) perm = buildP; - Group grp = Group.findPerm(perm); + LevelPermission maxPerm = visitP; + if (maxPerm < buildP) maxPerm = buildP; - string color = grp == null ? "&f" : grp.color; string visit = loadOnGoto && (p == null || p.Rank >= visitP) ? "" : " &c[no]"; - return color + map + visit; + return Group.GetColor(maxPerm) + map + visit; } static bool IsLoaded(Level[] loaded, string level) { diff --git a/MCGalaxy/Commands/other/CmdAscend.cs b/MCGalaxy/Commands/other/CmdAscend.cs index fffffe9a5..ea5f252dd 100644 --- a/MCGalaxy/Commands/other/CmdAscend.cs +++ b/MCGalaxy/Commands/other/CmdAscend.cs @@ -56,7 +56,7 @@ namespace MCGalaxy.Commands { } public override void Help(Player p) { - string name = Group.findPerm(LevelPermission.Operator).ColoredName; + string name = Group.GetColoredName(LevelPermission.Operator); Player.Message(p, "%T/ascend"); Player.Message(p, "%HTeleports you to the first free space above you."); Player.Message(p, "%H Does not work on maps which have -hax in their motd. " + diff --git a/MCGalaxy/Commands/other/CmdDescend.cs b/MCGalaxy/Commands/other/CmdDescend.cs index 79dc9c0cc..23984b026 100644 --- a/MCGalaxy/Commands/other/CmdDescend.cs +++ b/MCGalaxy/Commands/other/CmdDescend.cs @@ -56,7 +56,7 @@ namespace MCGalaxy.Commands { } public override void Help(Player p) { - string name = Group.findPerm(LevelPermission.Operator).ColoredName; + string name = Group.GetColoredName(LevelPermission.Operator); Player.Message(p, "%T/descend"); Player.Message(p, "%HTeleports you to the first free space below you."); Player.Message(p, "%H Does not work on maps which have -hax in their motd. " + diff --git a/MCGalaxy/Commands/other/CmdFly.cs b/MCGalaxy/Commands/other/CmdFly.cs index eff6e969e..0cfe4dd1d 100644 --- a/MCGalaxy/Commands/other/CmdFly.cs +++ b/MCGalaxy/Commands/other/CmdFly.cs @@ -93,7 +93,7 @@ namespace MCGalaxy.Commands { } public override void Help(Player p) { - string name = Group.findPerm(LevelPermission.Operator).ColoredName; + string name = Group.GetColoredName(LevelPermission.Operator); Player.Message(p, "%T/fly"); Player.Message(p, "%HThe old method of flight before custom clients."); Player.Message(p, "%HMay not work at all depending on your connection."); diff --git a/MCGalaxy/Database/BlockDB/BlockDBCache.cs b/MCGalaxy/Database/BlockDB/BlockDBCache.cs new file mode 100644 index 000000000..27ccf1f09 --- /dev/null +++ b/MCGalaxy/Database/BlockDB/BlockDBCache.cs @@ -0,0 +1,41 @@ +/* + Copyright 2015 MCGalaxy + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. + */ +using System; +using System.Data; +using MCGalaxy.SQL; + +namespace MCGalaxy.DB { + + /// Optimised in-memory BlockDB cache. + public sealed class BlockDBCache { + + public BlockDBCacheNode Head, Tail; + + int nextSize = 10000; + } + + // TODO: track start time so we can use int16 instead of int32 time delta + public sealed class BlockDBCacheNode { + + public BlockDBCacheNode Prev, Next; + + public int Count; + + public BlockDBEntry[] Entries; + } +} diff --git a/MCGalaxy/Economy/Item.cs b/MCGalaxy/Economy/Item.cs index 4914c5e8a..3042f6fa1 100644 --- a/MCGalaxy/Economy/Item.cs +++ b/MCGalaxy/Economy/Item.cs @@ -147,8 +147,7 @@ namespace MCGalaxy.Eco { if (p == null || p.Rank >= PurchaseRank) { Player.Message(p, "&6{0} %S- &a{1} %S{2}", Name, Price, Server.moneys); } else { - Group grp = Group.findPerm(PurchaseRank); - string grpName = grp == null ? ((int)PurchaseRank).ToString() : grp.ColoredName; + string grpName = Group.GetColoredName(PurchaseRank); Player.Message(p, "&6{0} %S({3}%S+) - &a{1} %S{2}", Name, Price, Server.moneys, grpName); } } diff --git a/MCGalaxy/Levels/Level.Fields.cs b/MCGalaxy/Levels/Level.Fields.cs index 42385029f..bd6a749a0 100644 --- a/MCGalaxy/Levels/Level.Fields.cs +++ b/MCGalaxy/Levels/Level.Fields.cs @@ -34,12 +34,9 @@ namespace MCGalaxy { public string ColoredName { get { - LevelPermission perm = permissionvisit; - if (perm < permissionbuild) perm = permissionbuild; - - Group grp = Group.findPerm(perm); - string col = grp == null ? "&f" : grp.color; - return col + name; + LevelPermission maxPerm = permissionvisit; + if (maxPerm < permissionbuild) maxPerm = permissionbuild; + return Group.GetColoredName(maxPerm) + name; } } diff --git a/MCGalaxy/Player/Group/Group.cs b/MCGalaxy/Player/Group/Group.cs index f4e0ca828..9b8b49d06 100644 --- a/MCGalaxy/Player/Group/Group.cs +++ b/MCGalaxy/Player/Group/Group.cs @@ -247,7 +247,13 @@ namespace MCGalaxy { public static string GetColoredName(LevelPermission perm) { Group grp = findPerm(perm); if (grp != null) return grp.ColoredName; - return "&f" + ((int)perm); + return Colors.white + ((int)perm); + } + + public static string GetColor(LevelPermission perm) { + Group grp = findPerm(perm); + if (grp != null) return grp.color; + return Colors.white; } } }