Exemplo n.º 1
0
        protected void Place(IClient client, string[] tokens)
        {
            string schematicName = tokens[1];
            Schematic schematic = new Schematic(schematicName);

            bool loaded;
            try
            {
                loaded = schematic.LoadFromFile();
            }
            catch (FileNotFoundException)
            {
                client.SendMessage(string.Format("Schematic file is not found: {0}", schematicName));
                return;
            }
            catch (Exception ex)
            {
                loaded = false;
                var sb = new StringBuilder();
                sb.Append("Schematics: error has occured while loading schematic file ");
                sb.Append(schematicName);
                sb.Append(Environment.NewLine);
                sb.Append(ex.ToString());
                client.GetServer().GetLogger().Log(LogLevel.Warning, sb.ToString());
            }

            if (!loaded)
            {
                client.SendMessage("Can not load schematic file");
                return;
            }

            bool rotateByX = false;
            bool rotateByZ = false;
            bool rotateByXZ = false;

            if (tokens.Length >= 3)
            {
                string rotation = tokens[2].Trim().ToLower();
                if (rotation == "x")
                    rotateByX = true;
                else if (rotation == "z")
                    rotateByZ = true;
                else if (rotation == "xz")
                    rotateByXZ = true;
            }

            UniversalCoords coords = UniversalCoords.FromAbsWorld(client.GetOwner().Position);
            int width = ((rotateByX || rotateByXZ) ? -1 * schematic.Width : schematic.Width);
            int length = ((rotateByZ || rotateByXZ) ? -1 * schematic.Length : schematic.Length);

            if (!RequiredChunksExist(client.GetOwner().GetWorld(), coords, width, schematic.Height, length))
            {
                client.SendMessage("The schematic is too big - required chunks are not loaded/created yet");
                return;
            }

            int blockAmount = schematic.Width * schematic.Height * schematic.Length;
            byte[] blockIds = new byte[blockAmount];
            byte[] blockMetas = new byte[blockAmount];
            UniversalCoords blockCoords;
            IChunk chunk;
            int index;

            for (int dx = 0; dx < schematic.Width; dx++)
                for (int dy = 0; dy < schematic.Height; dy++)
                    for (int dz = 0; dz < schematic.Length; dz++)
                    {
                        int x = coords.WorldX + ((rotateByX || rotateByXZ) ? -dx : dx);
                        int y = coords.WorldY + dy;
                        int z = coords.WorldZ + ((rotateByZ || rotateByXZ) ? -dz : dz);
                        blockCoords = UniversalCoords.FromWorld(x, y, z);
                        chunk = client.GetOwner().GetWorld().GetChunk(blockCoords, false, false);
                        if (chunk == null)
                            continue;
                        index = schematic.ToIndex(dx, dy, dz);
                        blockIds[index] = (byte)chunk.GetType(blockCoords);
                        blockMetas[index] = chunk.GetData(blockCoords);
                        chunk.SetBlockAndData(blockCoords, schematic.BlockIds[index], schematic.BlockMetas[index]);
                    }

            SchematicAction action;
            if (_plugin.Actions.ContainsKey(client.Username))
                _plugin.Actions.TryRemove(client.Username, out action);

            action = new SchematicAction
                         {
                             StartingPoint = coords,
                             BlockIds = blockIds,
                             BlockMetas = blockMetas,
                             RotateByX = rotateByX,
                             RotateByZ = rotateByZ,
                             RotateByXZ = rotateByXZ,
                             Width = schematic.Width,
                             Height = schematic.Height,
                             Length = schematic.Length
                         };
            _plugin.Actions.TryAdd(client.Username, action);
            client.SendMessage(string.Format("Schematic {0} ({1} blocks) has been placed", schematic.SchematicName, blockAmount));
        }
Exemplo n.º 2
0
        protected void Info(IClient client, string schematicName)
        {
            Schematic schematic = new Schematic(schematicName);

            bool loaded;
            try
            {
                loaded = schematic.LoadFromFile(true);
            }
            catch (FileNotFoundException)
            {
                client.SendMessage(string.Format("Schematic file is not found: {0}", schematicName));
                return;
            }
            catch (Exception ex)
            {
                loaded = false;
                var sb = new StringBuilder();
                sb.Append("Schematics: error has occured while loading schematic file ");
                sb.Append(schematicName);
                sb.Append(Environment.NewLine);
                sb.Append(ex.ToString());
                client.GetServer().GetLogger().Log(LogLevel.Warning, sb.ToString());
            }

            if (!loaded)
            {
                client.SendMessage("Can not load schematic file");
                return;
            }

            client.SendMessage(string.Format("Width(X) x Height(Y) x Length(Z): {0} x {1} x {2} ({3} blocks)", schematic.Width, schematic.Height, schematic.Length, (schematic.Width * schematic.Height * schematic.Length)));
        }