public override void StartServerSide(ICoreServerAPI sapi) { this.sapi = sapi; exportFolderPath = sapi.GetOrCreateDataPath("WorldEdit"); sapi.Permissions.RegisterPrivilege("worldedit", "Ability to use world edit tools"); sapi.RegisterCommand("we", "World edit tools", "[ms|me|mc|mex|clear|mdelete|mfill|imp|impr|blu|brs|brm|ers|range|tool|on|off|undo|redo|sovp|block|...]", CmdEditServer, "worldedit"); sapi.Event.PlayerJoin += OnPlayerJoin; sapi.Event.PlayerSwitchGameMode += OnSwitchedGameMode; sapi.Event.BreakBlock += OnBreakBlock; sapi.Event.DidPlaceBlock += OnDidBuildBlock; sapi.Event.SaveGameLoaded += OnLoad; sapi.Event.GameWorldSave += OnSave; serverChannel = sapi.Network.RegisterChannel("worldedit") .RegisterMessageType(typeof(RequestWorkSpacePacket)) .RegisterMessageType(typeof(WorldEditWorkspace)) .RegisterMessageType(typeof(ChangePlayerModePacket)) .RegisterMessageType(typeof(CopyToClipboardPacket)) .RegisterMessageType(typeof(SchematicJsonPacket)) .SetMessageHandler <RequestWorkSpacePacket>(OnRequestWorkSpaceMessage) .SetMessageHandler <ChangePlayerModePacket>(OnChangePlayerModeMessage) .SetMessageHandler <SchematicJsonPacket>(OnReceivedSchematic) ; }
public WorldMap(ICoreServerAPI api) { this.api = api; string mapFolder = api.GetOrCreateDataPath("Maps"); string landformPath = mapFolder + @"/landforms.png"; if (File.Exists(landformPath)) { this.landformMap = new Bitmap(landformPath); } string climatePath = mapFolder + @"/climate.png"; if (File.Exists(climatePath)) { this.climateMap = new Bitmap(climatePath); } api.RegisterCommand("getpixelinfo", "gets pixel values on maps", "", (IServerPlayer player, int i, CmdArgs args) => { int chunkx = player.Entity.ServerPos.AsBlockPos.X / 32; int chunkz = player.Entity.ServerPos.AsBlockPos.Z / 32; player.SendMessage(0, "landform:" + ChunkToPixel(chunkx, chunkz, landformMap).R.ToString() + " temp:" + ChunkToPixel(chunkx, chunkz, climateMap).R.ToString() + " humid:" + ChunkToPixel(chunkx, chunkz, landformMap).R.ToString(), EnumChatType.Notification); }); }
public override void StartServerSide(ICoreServerAPI api) { this.api = api; exportFolderPath = api.GetOrCreateDataPath("WorldEdit"); api.RegisterPrivilege("worldedit", "Ability to use world edit tools"); api.RegisterCommand("wo", "World edit tools (Old Version)", "[ms|me|mc|mex|cla|clm|fillm|blu]", CmdEdit, "worldedit"); }
public void TryLoadHeightMap(string filename) { string folderPath = sapi.GetOrCreateDataPath("Heightmaps"); string filePath = Path.Combine(folderPath, filename); if (!File.Exists(filePath)) { return; } Bitmap bmp = new Bitmap(filePath); BitmapData bData1 = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, bmp.PixelFormat); heights = new ushort[bmp.Width * bmp.Height]; unsafe { byte *bData1Scan0Ptr = (byte *)bData1.Scan0.ToPointer(); byte *nextBase = bData1Scan0Ptr + bData1.Stride; for (int y = 0; y < bData1.Height; ++y) { ushort *pRow = (ushort *)bData1Scan0Ptr; for (int x = 0; x < bData1.Width; ++x) { heights[y * bData1.Width + x] = pRow[2]; //var red = pRow[2]; //var green = pRow[1]; //var blue = pRow[0]; pRow += 4; } bData1Scan0Ptr = nextBase; nextBase += bData1.Stride; } } bmp.Dispose(); }
public void LoadBlockdatas(ICoreServerAPI api, WorldEdit worldEdit = null) { this.blockDatas = new BlockSchematic[0]; if (BlockDataFilenames == null) { return; } string[] filenames = BlockDataFilenames.Split(','); List <BlockSchematic> blockDatas = new List <BlockSchematic>(); string exportFolderPath = api.GetOrCreateDataPath("WorldEdit"); int failed = 0; for (int i = 0; i < filenames.Length; i++) { string infilepath = Path.Combine(exportFolderPath, filenames[i]); string error = ""; BlockSchematic blockData = BlockSchematic.LoadFromFile(infilepath, ref error); if (blockData == null) { worldEdit?.Bad(error); failed++; } else { blockDatas.Add(blockData); } } if (failed > 0) { worldEdit?.Bad(failed + " schematics couldn't be loaded."); } this.blockDatas = blockDatas.ToArray(); }
public override void StartServerSide(ICoreServerAPI api) { string returnthings_help = "/returnthings [from player] [to player] [index] or /returnthings [from player] list"; api.RegisterCommand("returnthings", ConstantsCore.ModPrefix + "Returns things losing on last death", returnthings_help, (IServerPlayer byPlayer, int groupId, CmdArgs args) => { if (args.Length < 2) { byPlayer.SendMessage(returnthings_help); return; } IPlayer fromPlayer = api.World.AllPlayers.FirstOrDefault(p => p.PlayerName.ToLower() == args[0].ToLower()); if (fromPlayer == null) { byPlayer.SendMessage(Lang.Get("Player {0} not found", args[0])); return; } string datapath = api.GetOrCreateDataPath($"ModData/{api.GetWorldId()}/{ConstantsCore.ModId}/{fromPlayer.PlayerUID}"); string[] files = Directory.GetFiles(datapath).OrderByDescending(f => new FileInfo(f).Name).ToArray(); if (args[1] == "list") { if (files.Length == 0) { byPlayer.SendMessage(Lang.Get("No data saved")); return; } StringBuilder str = new StringBuilder(); for (int i = 0; i < files.Length; i++) { str.AppendLine($"{i}. {Path.GetFileName(files[i])}"); } byPlayer.SendMessage(str.ToString()); return; } IPlayer toPlayer = api.World.AllPlayers.FirstOrDefault(p => p.PlayerName.ToLower() == args[1].ToLower()); if (toPlayer == null) { byPlayer.SendMessage(Lang.Get("Player {0} not found", args[1])); return; } if (!api.World.AllOnlinePlayers.Contains(toPlayer) || toPlayer.Entity == null) { byPlayer.SendMessage(Lang.Get("Player {0} is offline or not fully loaded.", args[1])); return; } int offset = args.Length > 2 ? args[2].ToInt(-1) : 0; if (offset == -1 || files.Length <= offset) { byPlayer.SendMessage(Lang.Get("Index {0} not found", args.Length > 2 ? args[2] : offset.ToString())); return; } InventoryGeneric inventory = LoadLastDeathContent(fromPlayer, offset); foreach (var slot in inventory) { if (slot.Empty) { continue; } if (!toPlayer.InventoryManager.TryGiveItemstack(slot.Itemstack)) { api.World.SpawnItemEntity(slot.Itemstack, toPlayer.Entity.ServerPos.XYZ.AddCopy(0, 1, 0)); } slot.Itemstack = null; slot.MarkDirty(); } byPlayer.SendMessage(Lang.Get("Returned things from {0} to {1} with index {2}", fromPlayer.PlayerName, toPlayer.PlayerName, offset)); }, Config.Current.NeedPrivilegeForReturnThings.Val ); }
private void ReturnThingsCommand(IServerPlayer player, int groupId, CmdArgs args) { if (args.Length < 2) { player.SendMessage(ReturnThingsHelp); return; } IPlayer fromPlayer = api.World.AllPlayers.FirstOrDefault(p => p.PlayerName.ToLower() == args[0].ToLower()); if (fromPlayer == null) { player.SendMessage(Lang.Get("Player {0} not found", args[0])); return; } string localPath = "ModData/" + api.GetWorldId() + "/" + Mod.Info.ModID + "/" + fromPlayer.PlayerUID; string path = api.GetOrCreateDataPath(localPath); string[] files = Directory.GetFiles(path).OrderByDescending(f => new FileInfo(f).Name).ToArray(); if (args[1] == "list") { if (files.Length == 0) { player.SendMessage(Lang.Get("No data saved")); return; } StringBuilder str = new StringBuilder(); for (int i = 0; i < files.Length; i++) { str.AppendLine(i + ". " + Path.GetFileName(files[i])); } player.SendMessage(str.ToString()); return; } IPlayer toPlayer = api.World.AllPlayers.FirstOrDefault(p => p.PlayerName.ToLower() == args[1].ToLower()); if (toPlayer == null) { player.SendMessage(Lang.Get("Player {0} not found", args[1])); return; } if (!api.World.AllOnlinePlayers.Contains(toPlayer) || toPlayer.Entity == null) { player.SendMessage(Lang.Get("Player {0} is offline or not fully loaded.", args[1])); return; } int offset = args.Length > 2 ? args[2].ToInt(-1) : 0; if (offset == -1 || files.Length <= offset) { player.SendMessage(Lang.Get("Index {0} not found", args.Length > 2 ? args[2] : offset.ToString())); return; } var dcm = api.ModLoader.GetModSystem <DeathContentManager>(); InventoryGeneric inventory = dcm.LoadLastDeathContent(fromPlayer, offset); foreach (var slot in inventory) { if (slot.Empty) { continue; } if (!toPlayer.InventoryManager.TryGiveItemstack(slot.Itemstack)) { api.World.SpawnItemEntity(slot.Itemstack, toPlayer.Entity.ServerPos.XYZ.AddCopy(0, 1, 0)); } slot.Itemstack = null; slot.MarkDirty(); } player.SendMessage(Lang.Get("Returned things from {0} to {1} with index {2}", fromPlayer.PlayerName, toPlayer.PlayerName, offset)); }