diff --git a/Commands/Bots/CmdBotSet.cs b/Commands/Bots/CmdBotSet.cs index 41c1909d9..26c5ad007 100644 --- a/Commands/Bots/CmdBotSet.cs +++ b/Commands/Bots/CmdBotSet.cs @@ -26,7 +26,7 @@ namespace MCGalaxy.Commands { public override string type { get { return CommandTypes.Other; } } public override bool museumUsable { get { return false; } } public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can set bots to be killer") }; } } diff --git a/Commands/CPE/CmdModel.cs b/Commands/CPE/CmdModel.cs index 0f22da5f0..70c28bb06 100644 --- a/Commands/CPE/CmdModel.cs +++ b/Commands/CPE/CmdModel.cs @@ -27,7 +27,7 @@ namespace MCGalaxy.Commands.CPE { public override string type { get { return CommandTypes.Other; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the model of others") }; } } public override CommandAlias[] Aliases { diff --git a/Commands/CPE/CmdSkin.cs b/Commands/CPE/CmdSkin.cs index 685922c27..912c030b7 100644 --- a/Commands/CPE/CmdSkin.cs +++ b/Commands/CPE/CmdSkin.cs @@ -27,7 +27,7 @@ namespace MCGalaxy.Commands.CPE { public override string type { get { return CommandTypes.Other; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the skin of others") }; } } diff --git a/Commands/Chat/CmdChatRoom.cs b/Commands/Chat/CmdChatRoom.cs index 9b6e1fcae..b0f53f526 100644 --- a/Commands/Chat/CmdChatRoom.cs +++ b/Commands/Chat/CmdChatRoom.cs @@ -25,7 +25,7 @@ namespace MCGalaxy.Commands { public override string type { get { return CommandTypes.Chat; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Banned; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.AdvBuilder, "+ can create chatrooms"), new CommandPerm(LevelPermission.AdvBuilder, "+ can delete an empty chatroom"), diff --git a/Commands/Chat/CmdColor.cs b/Commands/Chat/CmdColor.cs index dab5ae045..bf4586315 100644 --- a/Commands/Chat/CmdColor.cs +++ b/Commands/Chat/CmdColor.cs @@ -25,7 +25,7 @@ namespace MCGalaxy.Commands { public override string type { get { return CommandTypes.Chat; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the color of others") }; } } public override CommandAlias[] Aliases { diff --git a/Commands/Chat/CmdNick.cs b/Commands/Chat/CmdNick.cs index 7e2bdf298..1e28a5c6c 100644 --- a/Commands/Chat/CmdNick.cs +++ b/Commands/Chat/CmdNick.cs @@ -26,7 +26,7 @@ namespace MCGalaxy.Commands { public override string type { get { return CommandTypes.Chat; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the nick of other players") }; } } public override CommandAlias[] Aliases { diff --git a/Commands/Chat/CmdTColor.cs b/Commands/Chat/CmdTColor.cs index 75ca2b5b0..72d549c39 100644 --- a/Commands/Chat/CmdTColor.cs +++ b/Commands/Chat/CmdTColor.cs @@ -24,7 +24,7 @@ namespace MCGalaxy.Commands { public override string type { get { return CommandTypes.Chat; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Admin; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the title color of others") }; } } public override CommandAlias[] Aliases { diff --git a/Commands/Chat/CmdTitle.cs b/Commands/Chat/CmdTitle.cs index ab169c1ac..7eaf0d854 100644 --- a/Commands/Chat/CmdTitle.cs +++ b/Commands/Chat/CmdTitle.cs @@ -25,7 +25,7 @@ namespace MCGalaxy.Commands { public override string type { get { return CommandTypes.Chat; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Admin; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Admin, "+ can change the title of others") }; } } public override CommandAlias[] Aliases { diff --git a/Commands/Command.cs b/Commands/Command.cs index bc30b3471..d00f74396 100644 --- a/Commands/Command.cs +++ b/Commands/Command.cs @@ -32,7 +32,7 @@ namespace MCGalaxy { public abstract void Use(Player p, string message); public abstract void Help(Player p); public virtual void Help(Player p, string message) { Help(p); Formatter.PrintCommandInfo(p, this); } - public virtual CommandPerm[] AdditionalPerms { get { return null; } } + public virtual CommandPerm[] ExtraPerms { get { return null; } } public virtual CommandEnable Enabled { get { return CommandEnable.Always; } } public virtual CommandAlias[] Aliases { get { return null; } } diff --git a/Commands/CommandList.cs b/Commands/CommandList.cs index cfe4edc4d..58e5f4485 100644 --- a/Commands/CommandList.cs +++ b/Commands/CommandList.cs @@ -26,7 +26,7 @@ namespace MCGalaxy public void Add(Command cmd) { commands.Add(cmd); - CommandPerm[] perms = cmd.AdditionalPerms; + CommandPerm[] perms = cmd.ExtraPerms; if (!AddOtherPerms || perms == null) return; for (int i = 0; i < perms.Length; i++) diff --git a/Commands/Economy/CmdEconomy.cs b/Commands/Economy/CmdEconomy.cs index 2ded301fb..4039a8c7b 100644 --- a/Commands/Economy/CmdEconomy.cs +++ b/Commands/Economy/CmdEconomy.cs @@ -29,7 +29,7 @@ namespace MCGalaxy.Commands { public override string type { get { return CommandTypes.Economy; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can setup the economy") }; } } diff --git a/Commands/Fun/CmdCountdown.cs b/Commands/Fun/CmdCountdown.cs index abea1ab25..fd32d3d9a 100644 --- a/Commands/Fun/CmdCountdown.cs +++ b/Commands/Fun/CmdCountdown.cs @@ -33,7 +33,7 @@ namespace MCGalaxy.Commands { public override string type { get { return CommandTypes.Games; } } public override bool museumUsable { get { return false; } } public override LevelPermission defaultRank { get { return LevelPermission.Banned; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can send the countdown rules to everybody"), new CommandPerm(LevelPermission.Operator, "+ can setup countdown (download/start/restart/enable/disable/cancel)"), diff --git a/Commands/Fun/CmdTeam.cs b/Commands/Fun/CmdTeam.cs index 8f170308f..9960f7ad8 100644 --- a/Commands/Fun/CmdTeam.cs +++ b/Commands/Fun/CmdTeam.cs @@ -26,7 +26,7 @@ namespace MCGalaxy.Commands { public override string type { get { return CommandTypes.Games; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.AdvBuilder, "+ can create teams") }; } } diff --git a/Commands/Fun/CmdTntWars.cs b/Commands/Fun/CmdTntWars.cs index 002e8a0c0..ca2a11289 100644 --- a/Commands/Fun/CmdTntWars.cs +++ b/Commands/Fun/CmdTntWars.cs @@ -27,7 +27,7 @@ namespace MCGalaxy.Commands { public override string type { get { return CommandTypes.Games; } } public override bool museumUsable { get { return false; } } public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can use admin commands for tntwars") }; } } bool DeleteZone = false, CheckZone = false, NoTntZone = false; diff --git a/Commands/Information/CmdRankReqs.cs b/Commands/Information/CmdRankReqs.cs index ddd22e171..a37530b53 100644 --- a/Commands/Information/CmdRankReqs.cs +++ b/Commands/Information/CmdRankReqs.cs @@ -29,7 +29,7 @@ namespace MCGalaxy.Commands { public override string type { get { return CommandTypes.Information; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can set rank requirements."), }; } diff --git a/Commands/Information/CmdRules.cs b/Commands/Information/CmdRules.cs index 3b73fb60f..de9d3a700 100644 --- a/Commands/Information/CmdRules.cs +++ b/Commands/Information/CmdRules.cs @@ -27,7 +27,7 @@ namespace MCGalaxy.Commands public override string type { get { return CommandTypes.Information; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Banned; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Builder, "can send rules to other players") }; } } diff --git a/Commands/Information/CmdServerInfo.cs b/Commands/Information/CmdServerInfo.cs index cbd88a0fc..8fbb448c5 100644 --- a/Commands/Information/CmdServerInfo.cs +++ b/Commands/Information/CmdServerInfo.cs @@ -31,7 +31,7 @@ namespace MCGalaxy.Commands { public override CommandAlias[] Aliases { get { return new[] { new CommandAlias("host"), new CommandAlias("zall") }; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Admin, "+ can see server CPU and memory usage") }; } } diff --git a/Commands/Information/CmdWhois.cs b/Commands/Information/CmdWhois.cs index 2985bcbfc..465920050 100644 --- a/Commands/Information/CmdWhois.cs +++ b/Commands/Information/CmdWhois.cs @@ -27,7 +27,7 @@ namespace MCGalaxy.Commands { public override string type { get { return CommandTypes.Information; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Banned; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.AdvBuilder, "+ can see IPs and if a player is whitelisted") }; } } public override CommandAlias[] Aliases { diff --git a/Commands/Moderation/CmdHide.cs b/Commands/Moderation/CmdHide.cs index a6990171d..bb5acf04e 100644 --- a/Commands/Moderation/CmdHide.cs +++ b/Commands/Moderation/CmdHide.cs @@ -25,7 +25,7 @@ namespace MCGalaxy.Commands public override string type { get { return CommandTypes.Moderation; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Admin, "+ can hide/unhide without showing a message to ops") }; } } public override CommandAlias[] Aliases { diff --git a/Commands/Moderation/CmdPatrol.cs b/Commands/Moderation/CmdPatrol.cs index bdbb3ee13..7c8b7409c 100644 --- a/Commands/Moderation/CmdPatrol.cs +++ b/Commands/Moderation/CmdPatrol.cs @@ -29,7 +29,7 @@ namespace MCGalaxy.Commands public override string type { get { return CommandTypes.Moderation; } } public override bool museumUsable { get { return false; } } public override LevelPermission defaultRank { get { return LevelPermission.Builder; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Guest, " and below are patrolled") }; } } diff --git a/Commands/Moderation/CmdReview.cs b/Commands/Moderation/CmdReview.cs index f1014195b..fdbd16480 100644 --- a/Commands/Moderation/CmdReview.cs +++ b/Commands/Moderation/CmdReview.cs @@ -27,7 +27,7 @@ namespace MCGalaxy.Commands { public override string type { get { return CommandTypes.Moderation; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can see the review queue"), new CommandPerm(LevelPermission.Operator, "+ can teleport to next in review queue"), diff --git a/Commands/Moderation/CmdZone.cs b/Commands/Moderation/CmdZone.cs index f1dceb160..5a81b756c 100644 --- a/Commands/Moderation/CmdZone.cs +++ b/Commands/Moderation/CmdZone.cs @@ -24,7 +24,7 @@ namespace MCGalaxy.Commands { public override string type { get { return CommandTypes.Moderation; } } public override bool museumUsable { get { return false; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can delete zones"), new CommandPerm(LevelPermission.Operator, "+ can delete all zones"), diff --git a/Commands/World/CmdMain.cs b/Commands/World/CmdMain.cs index 8f088989f..16ae1092a 100644 --- a/Commands/World/CmdMain.cs +++ b/Commands/World/CmdMain.cs @@ -23,7 +23,7 @@ namespace MCGalaxy.Commands.World { public override string type { get { return CommandTypes.World; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Banned; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Admin, "+ can change the main level") }; } } public CmdMain() { } diff --git a/Commands/World/CmdMap.cs b/Commands/World/CmdMap.cs index 367568389..68d7749c9 100644 --- a/Commands/World/CmdMap.cs +++ b/Commands/World/CmdMap.cs @@ -24,7 +24,7 @@ namespace MCGalaxy.Commands.World { public override string type { get { return CommandTypes.World; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can edit map options"), new CommandPerm(LevelPermission.Admin, "+ can set realm owners") }; } } diff --git a/Commands/World/CmdNewLvl.cs b/Commands/World/CmdNewLvl.cs index 20d5a4a4b..47c8874fc 100644 --- a/Commands/World/CmdNewLvl.cs +++ b/Commands/World/CmdNewLvl.cs @@ -26,6 +26,9 @@ namespace MCGalaxy.Commands.World { public override string type { get { return CommandTypes.World; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Admin; } } + public override CommandPerm[] ExtraPerms { + get { return new[] { new CommandPerm(LevelPermission.Admin, "+ can generate maps with advanced themes") }; } + } public CmdNewLvl() { } public override void Use(Player p, string message) { @@ -48,7 +51,10 @@ namespace MCGalaxy.Commands.World { if (!ValidName(p, name, "level")) return; if (LevelInfo.ExistsOffline(name)) { Player.Message(p, "Level \"{0}\" already exists", name); return; - } + } + if (!MapGen.IsSimpleTheme(args[4]) && !CheckExtraPerm(p)) { + MessageNeedExtra(p, "can generate maps with advanced themes."); return; + } try { using (Level lvl = new Level(name, x, y, z)) { diff --git a/Commands/World/CmdReload.cs b/Commands/World/CmdReload.cs index f67bb6aba..78477b1f1 100644 --- a/Commands/World/CmdReload.cs +++ b/Commands/World/CmdReload.cs @@ -26,7 +26,7 @@ namespace MCGalaxy.Commands { public override CommandAlias[] Aliases { get { return new [] { new CommandAlias("rejoin"), new CommandAlias("rd") }; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can reload for other players") }; } } diff --git a/Commands/building/CmdImageprint.cs b/Commands/building/CmdImageprint.cs index 74ebcb7ac..6e6560bf7 100644 --- a/Commands/building/CmdImageprint.cs +++ b/Commands/building/CmdImageprint.cs @@ -71,7 +71,7 @@ namespace MCGalaxy.Commands.Building { DrawArgs dArgs = default(DrawArgs); dArgs.layer = layer; - dArgs.bitmapLoc = bitmapLoc; + dArgs.name = bitmapLoc; dArgs.popType = popType; Player.Message(p, "Place two blocks to determine direction."); p.MakeSelection(2, dArgs, DoImage); @@ -97,15 +97,13 @@ namespace MCGalaxy.Commands.Building { } void DoDrawImage(Player p, Vec3S32 p0, DrawArgs dArgs, int direction) { - Bitmap bmp = null; + Bitmap bmp = HeightmapGen.ReadBitmap(dArgs.name, "extra/images/", p); + if (bmp == null) return; try { - bmp = new Bitmap("extra/images/" + dArgs.bitmapLoc + ".bmp"); bmp.RotateFlip(RotateFlipType.RotateNoneFlipY); } catch (Exception ex) { Server.ErrorLog(ex); - if (bmp != null) bmp.Dispose(); - Player.Message(p, "&cThere was an error reading the downloaded image."); - Player.Message(p, "&cThe url may need to end with its extension (such as .jpg)."); + bmp.Dispose(); return; } @@ -171,7 +169,7 @@ namespace MCGalaxy.Commands.Building { p.level.UpdateBlock(p, (ushort)P.X, (ushort)P.Y, (ushort)P.Z, cur.type, 0); } - if (dArgs.bitmapLoc == "tempImage_" + p.name) + if (dArgs.name == "tempImage_" + p.name) File.Delete("extra/images/tempImage_" + p.name + ".bmp"); Player.Message(p, "Finished printing image using " + ImagePalette.Names[popType]); } @@ -186,7 +184,7 @@ namespace MCGalaxy.Commands.Building { Player.Message(p, "Use switch (&flayer%S) or (&fl%S) to print horizontally."); } - struct DrawArgs { public bool layer; public byte popType; public string bitmapLoc; } + struct DrawArgs { public bool layer; public byte popType; public string name; } } } diff --git a/Commands/building/CmdMessageBlock.cs b/Commands/building/CmdMessageBlock.cs index e0efb4e23..baf6d14a1 100644 --- a/Commands/building/CmdMessageBlock.cs +++ b/Commands/building/CmdMessageBlock.cs @@ -29,7 +29,7 @@ namespace MCGalaxy.Commands.Building { public override bool museumUsable { get { return false; } } public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } } public CmdMessageBlock() { } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Nobody, "+ can use moderation commands in MBs") }; } } diff --git a/Commands/building/CmdUndo.cs b/Commands/building/CmdUndo.cs index f5c9bf15b..1470a6303 100644 --- a/Commands/building/CmdUndo.cs +++ b/Commands/building/CmdUndo.cs @@ -26,7 +26,7 @@ namespace MCGalaxy.Commands.Building { public override string type { get { return CommandTypes.Building; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can undo other players"), new CommandPerm(LevelPermission.AdvBuilder, "+ can undo physics"), diff --git a/Commands/other/CmdReport.cs b/Commands/other/CmdReport.cs index 303cff45c..8f40b1715 100644 --- a/Commands/other/CmdReport.cs +++ b/Commands/other/CmdReport.cs @@ -28,7 +28,7 @@ namespace MCGalaxy.Commands { public override string type { get { return CommandTypes.Other; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can check, view and delete reports") }; } } public override CommandAlias[] Aliases { diff --git a/Commands/other/CmdTnt.cs b/Commands/other/CmdTnt.cs index f328d627e..275c23989 100644 --- a/Commands/other/CmdTnt.cs +++ b/Commands/other/CmdTnt.cs @@ -24,7 +24,7 @@ namespace MCGalaxy.Commands public override string type { get { return CommandTypes.Other; } } public override bool museumUsable { get { return false; } } public override LevelPermission defaultRank { get { return LevelPermission.Builder; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can use big TNT"), new CommandPerm(LevelPermission.Operator, "+ can allow/disallow tnt"), diff --git a/Commands/other/CmdWarp.cs b/Commands/other/CmdWarp.cs index fc20ef5ba..9a612d7e2 100644 --- a/Commands/other/CmdWarp.cs +++ b/Commands/other/CmdWarp.cs @@ -25,7 +25,7 @@ namespace MCGalaxy.Commands { public override string type { get { return CommandTypes.Other; } } public override bool museumUsable { get { return false; } } public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } - public override CommandPerm[] AdditionalPerms { + public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can create warps"), new CommandPerm(LevelPermission.Operator, "+ can delete warps"), diff --git a/Generator/HeightmapGen.cs b/Generator/HeightmapGen.cs index ef2d0fce4..0e35a5dab 100644 --- a/Generator/HeightmapGen.cs +++ b/Generator/HeightmapGen.cs @@ -14,14 +14,18 @@ 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.Drawing; +using System.IO; using System.Net; namespace MCGalaxy.Generator { public static class HeightmapGen { public static bool DownloadImage(string url, string dir, Player p) { + if (!Directory.Exists(dir)) + Directory.CreateDirectory(dir); if (!url.StartsWith("http://") && !url.StartsWith("https://")) url = "http://" + url; @@ -39,5 +43,50 @@ namespace MCGalaxy.Generator { return false; } } + + public static Bitmap ReadBitmap(string name, string dir, Player p) { + Bitmap bmp = null; + try { + bmp = new Bitmap(dir + name + ".bmp"); + int width = bmp.Width; + // sometimes Mono will return an invalid bitmap instance that throws ArgumentNullException, + // so we make sure to check for that here rather than later. + return bmp; + } catch (Exception ex) { + Server.ErrorLog(ex); + if (bmp != null) bmp.Dispose(); + Player.Message(p, "&cThere was an error reading the downloaded image."); + Player.Message(p, "&cThe url may need to end with its extension (such as .jpg)."); + return null; + } + } + + public static bool Generate(MapGenArgs args) { + Player p = args.Player; + Level lvl = args.Level; + if (args.Args == "") { Player.Message(p, "You need to provide a url for the image."); return false; } + + if (!DownloadImage(args.Args, "extra/heightmap/", p )) return false; + Bitmap bmp = ReadBitmap("tempImage_" + p.name, "extra/heightmap/", p); + if (bmp == null) return false; + if (lvl.Width != bmp.Width || lvl.Length != bmp.Height) { + Player.Message(p, "The size of the heightmap is {0} by {1}.", bmp.Width, bmp.Height); + Player.Message(p, "The width and length of the new level must match that size."); + return false; + } + + int index = 0, oneY = lvl.Width * lvl.Height; + using (bmp) { + for (int z = 0; z < bmp.Height; z++) + for (int x = 0; x < bmp.Width; x++) + { + int height = bmp.GetPixel(x, z).R * lvl.Height / 255; + for (int y = 0; y < height; y++) + lvl.blocks[index + oneY * y] = Block.stone; + index++; + } + } + return true; + } } } diff --git a/Generator/MapGen.cs b/Generator/MapGen.cs index d0c89a1d4..bcfb08aff 100644 --- a/Generator/MapGen.cs +++ b/Generator/MapGen.cs @@ -23,7 +23,7 @@ namespace MCGalaxy.Generator { public struct MapGenArgs { public Player Player; public Level Level; - public string Theme, RawArgs; + public string Theme, Args; public bool UseSeed; public int Seed; } @@ -35,6 +35,10 @@ namespace MCGalaxy.Generator { return simpleGens.ContainsKey(s) || advGens.ContainsKey(s); } + public static bool IsSimpleTheme(string s) { + return simpleGens.ContainsKey(s.ToLower()); + } + public static void PrintThemes(Player p) { Player.Message(p, "Simple themes: " + simpleGens.Keys.Concatenate(", ")); Player.Message(p, "Advanced themes: " + advGens.Keys.Concatenate(", ")); @@ -47,7 +51,7 @@ namespace MCGalaxy.Generator { public static bool Generate(Level lvl, string theme, string args, Player p) { MapGenArgs genArgs = new MapGenArgs(); genArgs.Level = lvl; genArgs.Player = p; - genArgs.Theme = theme; genArgs.RawArgs = args; + genArgs.Theme = theme; genArgs.Args = args; genArgs.UseSeed = args != ""; if (genArgs.UseSeed && !int.TryParse(args, out genArgs.Seed)) @@ -76,6 +80,7 @@ namespace MCGalaxy.Generator { advGens = new Dictionary>(); SimpleGen.RegisterGenerators(); AdvNoiseGen.RegisterGenerators(); + RegisterAdvancedGen("heightmap", HeightmapGen.Generate); } } } diff --git a/util/Formatter.cs b/util/Formatter.cs index 748379a87..b9e436d37 100644 --- a/util/Formatter.cs +++ b/util/Formatter.cs @@ -51,7 +51,7 @@ namespace MCGalaxy { Player.Message(p, builder.ToString()); PrintAliases(p, cmd); - CommandPerm[] addPerms = cmd.AdditionalPerms; + CommandPerm[] addPerms = cmd.ExtraPerms; if (addPerms == null) return; Player.Message(p, "%TExtra permissions:");