Пример #1
0
 private static void PlaceHandler(Player player, CommandReader cmd) {
     bool isConsole = (player == Player.Console);
     if (isConsole && cmd.Count < 6) {
         player.Message("When used by console /Place requires a world name.");
         player.Message("/Place [x] [y] [z] [block] [world]");
         return;
     }
     Block block = Block.Stone;
     if (!isConsole && player.LastUsedBlockType != Block.None)
     	block = player.LastUsedBlockType;
     Vector3I coords;
     int x, y, z;
     if (cmd.NextInt(out x) && cmd.NextInt(out y) && cmd.NextInt(out z)) {
         if (cmd.HasNext) {
             string last = cmd.Next();
             if (!Map.GetBlockByName(last, false, out block)) {
                 player.Message("\"{0}\" is not a valid block type", last);
                 return;
             }
         }
         coords = new Vector3I(x, y, z);
     } else if (isConsole) {
         player.Message("Invalid coordinates!");
         return;
     } else {
         cmd.Rewind();
         if (cmd.HasNext) {
             string last = cmd.Next();
             if (!Map.GetBlockByName(last, false, out block)) {
                 player.Message("\"{0}\" is not a valid block type", last);
                 return;
             }
         }
         coords = new Vector3I(player.Position.X / 32, player.Position.Y / 32, (player.Position.Z - 64) / 32);
     }
     World world;
     if (player == Player.Console) {
         string worldName = cmd.Next();
         if (string.IsNullOrEmpty(worldName)) {
             player.Message("Console must specify a world!");
         }
         world = WorldManager.FindWorldOrPrintMatches(player, worldName);
         if (world == null)
             return;
     } else {
         world = player.World;
     }
     bool unLoad = false;
     if (!world.IsLoaded) {
         world.LoadMap();
         unLoad = true;
     }
     coords.X = Math.Min(world.map.Width - 1, Math.Max(0, coords.X));
     coords.Y = Math.Min(world.map.Length - 1, Math.Max(0, coords.Y));
     coords.Z = Math.Min(world.map.Height - 1, Math.Max(0, coords.Z));
     
     if (player == Player.Console) {
         BlockUpdate blockUpdate = new BlockUpdate(player, coords, block);
         player.Info.ProcessBlockPlaced((byte)block);
         world.map.QueueUpdate(blockUpdate);
         player.RaisePlayerPlacedBlockEvent(player, world.map, coords, block, world.map.GetBlock(coords), BlockChangeContext.Manual, true);
     } else {
         player.SendNow(Packet.MakeSetBlock(coords, block, player));
         player.PlaceBlockWithEvents(coords, ClickAction.Build, block);
     }
     if (!isConsole) 
         player.Message("{0} placed at {1}", block.ToString(), coords.ToString());
     if (unLoad) {
         world.UnloadMap(true);
     }
 }