void Init() { CheckCfg <string>("User - Permission", ref cfg_map_user_permission); CheckCfg <string>("Admin - Permission", ref cfg_map_admin_permission); CheckCfg <int>("User - Max saveable map per user", ref cfg_map_user_max); CheckCfg <bool>("User - Allow to set an auto map", ref cfg_map_user_auto); CheckCfg <bool>("Announce message when crafting a Paper map", ref cfg_auto_message); CheckCfg <bool>("Default - Use default map", ref cfg_auto_default_map); CheckCfg <string>("Default - Map (DO NOT EDIT HERE)", ref cfg_default_map); if (cfg_auto_default_map) { default_map = cfg_default_map == string.Empty ? null : JsonConvert.DeserializeObject <PaperMap>(cfg_default_map); } SaveConfig(); InitializeLang(); }
void cmdPersonnalMap(BasePlayer player, string command, string[] args) { using (TimeWarning.New("Personnal Map Command", 0.01f)) { string reason = string.Empty; MapEntity map = null; var steamid = player.userID.ToString(); if (!hasPermission(player, cfg_map_user_permission)) { SendReply(player, GetMsg("You are not allowed to use this command.", steamid)); return; } if (args.Length == 0) { SendReply(player, GetHelp(player)); return; } var name = args.Length > 1 ? args[1].ToLower() : string.Empty; var PlayerData = new Dictionary <string, PaperMap>(); var success = PlayerDatabase.Call("GetPlayerDataRaw", steamid, "PersonnalMap"); if (success is string) { PlayerData = JsonConvert.DeserializeObject <Dictionary <string, PaperMap> >((string)success); } switch (args[0].ToLower()) { case "admin": if (!hasPermission(player, cfg_map_admin_permission)) { SendReply(player, GetMsg("You are not allowed to use this command.", steamid)); return; } if (args.Length == 1) { SendReply(player, GetHelp(player)); return; } switch (args[1].ToLower()) { case "reset": var knownPlayers = (HashSet <string>)PlayerDatabase.Call("GetAllKnownPlayers"); if (knownPlayers == null) { SendReply(player, "Couldn't get all known players out of PlayerDatabase."); return; } foreach (var userid in knownPlayers) { PlayerDatabase?.Call("SetPlayerData", userid, "PersonnalMap", new Dictionary <string, PaperMap>()); } cfg_default_map = string.Empty; Config["Default - Map (DO NOT EDIT HERE)"] = cfg_default_map; default_map = null; SaveConfig(); SendReply(player, "All personnal map data has been reset."); return; break; case "default": if (args.Length > 2 && (args[2].ToLower() == "false" || args[2].ToLower() == "null")) { cfg_default_map = string.Empty; Config["Default - Map (DO NOT EDIT HERE)"] = cfg_default_map; default_map = cfg_default_map == string.Empty ? null : JsonConvert.DeserializeObject <PaperMap>(cfg_default_map); SaveConfig(); SendReply(player, "You've removed the default map."); return; } break; default: SendReply(player, GetHelp(player)); return; break; } break; case "save": case "load": break; case "list": string l = GetMsg("List of saved maps:\n", steamid); foreach (var n in PlayerData.Keys) { l += n + "\n"; } SendReply(player, l); return; break; case "remove": if (name == string.Empty) { SendReply(player, GetMsg("usage: /pmap remove mapname.", steamid)); return; } if (!PlayerData.ContainsKey(name)) { SendReply(player, GetMsg("You don't have any map named like that.", steamid)); return; } PlayerData.Remove(name); PlayerDatabase?.Call("SetPlayerData", steamid, "PersonnalMap", PlayerData); SendReply(player, string.Format(GetMsg("You have successfully removed your map: {0}.", steamid), name)); return; break; default: SendReply(player, GetHelp(player)); return; break; } var inv = player.inventory; if (inv == null) { SendReply(player, GetMsg("Couldn't find your inventory.", steamid)); return; } var target = inv.containerBelt.FindItemByItemID(papermapdef.itemid); if (target == null) { SendReply(player, GetMsg("You need to place the Paper Map in your Belt.", steamid)); return; } reason = GetMapEntity(target, out map); if (reason != string.Empty) { SendReply(player, reason); return; } switch (args[0].ToLower()) { case "admin": switch (args[1].ToLower()) { case "default": var d = new PaperMap(map.fogImages, map.paintImages); cfg_default_map = JsonConvert.SerializeObject(d); Config["Default - Map (DO NOT EDIT HERE)"] = cfg_default_map; default_map = cfg_default_map == string.Empty ? null : JsonConvert.DeserializeObject <PaperMap>(cfg_default_map); SaveConfig(); SendReply(player, "You have set your current map as the default crafting map."); return; break; default: break; } break; case "save": if (name == string.Empty) { SendReply(player, GetMsg("usage: /pmap save mapname.", steamid)); return; } if (!PlayerData.ContainsKey(name) && PlayerData.Count >= cfg_map_user_max) { SendReply(player, "You have reached the limit of maps your can save."); return; } if (PlayerData.ContainsKey(name)) { PlayerData.Remove(name); } PlayerData.Add(name, new PaperMap(map.fogImages, map.paintImages)); PlayerDatabase?.Call("SetPlayerData", steamid, "PersonnalMap", PlayerData); SendReply(player, string.Format(GetMsg("Your map has been saved to: {0}", steamid), name)); return; break; case "load": if (name == string.Empty) { SendReply(player, GetMsg("usage: /pmap load mapname.", steamid)); return; } if (!PlayerData.ContainsKey(name)) { SendReply(player, GetMsg("You don't have any map named like that.", steamid)); return; } map.fogImages = PlayerData[name].ImageFog; map.paintImages = PlayerData[name].ImagePaint; target.RemoveFromContainer(); target.MoveToContainer(inv.containerBelt, -1, false); SendReply(player, string.Format(GetMsg("You have successfully loaded your map: {0}", steamid), name)); return; break; default: break; } } }