Ejemplo n.º 1
0
        public static void Cut(User user)
        {
            try
            {
                UserSession userSession = WorldEditManager.GetUserSession(user);
                WorldRange  region      = userSession.Selection;

                WorldEditCommand command = new CopyCommand(user);
                if (command.Invoke(region))
                {
                    user.Player.MsgLoc($"Copy done in {command.ElapsedMilliseconds}ms.");
                    command = new SetCommand(user, "Empty");
                    if (command.Invoke(region))
                    {
                        user.Player.MsgLoc($"{command.BlocksChanged} blocks cleared in {command.ElapsedMilliseconds}ms.");
                    }
                }
            }
            catch (WorldEditCommandException e)
            {
                user.Player.ErrorLocStr(e.Message);
            }
            catch (Exception e)
            {
                Log.WriteError(Localizer.Do($"{e}"));
            }
        }
Ejemplo n.º 2
0
        public override InteractResult OnActRight(InteractionContext context)
        {
            try
            {
                if (context.BlockPosition == null || !context.BlockPosition.HasValue)
                {
                    return(InteractResult.Success);
                }

                Vector3i pos = context.BlockPosition.Value;

                pos.X = pos.X < 0 ? pos.X + Shared.Voxel.World.VoxelSize.X : pos.X;
                pos.Z = pos.Z < 0 ? pos.Z + Shared.Voxel.World.VoxelSize.Z : pos.Z;

                pos.X = pos.X % Shared.Voxel.World.VoxelSize.X;
                pos.Z = pos.Z % Shared.Voxel.World.VoxelSize.Z;

                UserSession userSession = WorldEditManager.GetUserSession(context.Player.User);
                userSession.SetSecondPosition(pos);

                context.Player.MsgLoc($"Second Position set to ({pos.x}, {pos.y}, {pos.z})");
            }
            catch (Exception e)
            {
                Log.WriteError(Localizer.Do($"{e}"));
            }
            return(InteractResult.NoOp);
        }
Ejemplo n.º 3
0
        public static void Undo(User user, int count = 1)
        {
            try
            {
                UserSession userSession = WorldEditManager.GetUserSession(user);
                if (userSession.ExecutingCommand != null && userSession.ExecutingCommand.IsRunning)
                {
                    throw new WorldEditCommandException("You can't use undo right now!");                                                                                                 //TODO: Probably need to rework that and impliment aborting
                }
                if (count > userSession.ExecutedCommands.Count)
                {
                    count = userSession.ExecutedCommands.Count;
                }
                if (count.Equals(0))
                {
                    throw new WorldEditCommandException("Nothing to undo");
                }

                for (int i = 1; i <= count; i++)
                {
                    if (userSession.ExecutedCommands.TryPop(out WorldEditCommand command))
                    {
                        userSession.ExecutingCommand = command;
                        if (command.Undo())
                        {
                            if (count.Equals(1))
                            {
                                user.Player.MsgLoc($"Undo done.");
                                break;
                            }
                            else
                            {
                                user.Player.MsgLoc($"Undo {i}/{count} done.");
                            }
                        }
                        userSession.ExecutingCommand = null;
                    }
                    else
                    {
                        throw new WorldEditCommandException("Nothing to undo");
                    }
                }
            }
            catch (WorldEditCommandException e)
            {
                user.Player.ErrorLocStr(e.Message);
            }
            catch (Exception e)
            {
                Log.WriteError(Localizer.Do($"{e}"));
            }
        }
Ejemplo n.º 4
0
        public static void Reset(User user)
        {
            try
            {
                UserSession session = WorldEditManager.GetUserSession(user);
                session.ResetSelection();

                user.Player.MsgLoc($"WorldEdit: Positions reset");
            }
            catch (Exception e)
            {
                Log.WriteError(Localizer.Do($"{e}"));
            }
        }
Ejemplo n.º 5
0
        public static void Selclaim(User user)
        {
            try
            {
                Vector3i    pos      = user.Position.Round;
                Vector2i    claimPos = PlotUtil.NearestPlotPosInWorld(pos.XZ);
                UserSession session  = WorldEditManager.GetUserSession(user);

                session.SetFirstPosition(claimPos.X_Z(pos.Y - 1));
                session.SetSecondPosition(WorldEditUtils.SecondPlotPos(claimPos).X_Z(pos.Y - 1));

                user.Player.MsgLoc($"First Position set to {session.Selection.min}");
                user.Player.MsgLoc($"Second Position set to {session.Selection.max}");
            }
            catch (Exception e)
            {
                Log.WriteError(Localizer.Do($"{e}"));
            }
        }
Ejemplo n.º 6
0
        public static void SetPos2(User user)
        {
            try
            {
                Vector3 pos = user.Position;
                pos.X = pos.X < 0 ? pos.X + Shared.Voxel.World.VoxelSize.X : pos.X;
                pos.Z = pos.Z < 0 ? pos.Z + Shared.Voxel.World.VoxelSize.Z : pos.Z;
                pos.X = pos.X % Shared.Voxel.World.VoxelSize.X;
                pos.Z = pos.Z % Shared.Voxel.World.VoxelSize.Z;

                UserSession session = WorldEditManager.GetUserSession(user);
                session.SetSecondPosition(pos.Round);

                user.Player.MsgLoc($"Second Position set to {pos}");
            }
            catch (Exception e)
            {
                Log.WriteError(Localizer.Do($"{e}"));
            }
        }
Ejemplo n.º 7
0
        public static void Expclaim(User user, string args = "1")
        {
            try
            {
                UserSession session = WorldEditManager.GetUserSession(user);
                if (!session.Selection.IsSet())
                {
                    throw new WorldEditCommandException("Please set both points first!");
                }
                Direction direction = WorldEditUtils.ParseDirectionAndAmountArgs(user, args, out int amount);
                if (direction == Direction.Unknown ||
                    direction == Direction.None ||
                    direction == Direction.Up ||
                    direction == Direction.Down)
                {
                    throw new WorldEditCommandException("Unable to determine direction");
                }
                WorldRange range = session.Selection;
                Vector3i   pos   = default;
                if (range.min.y <= range.max.y)
                {
                    pos.y = range.min.y;
                }
                else
                {
                    pos.y = range.max.y;
                }
                switch (direction)
                {
                case Direction.Left:
                case Direction.Back:
                    if (range.min.x <= range.max.x)
                    {
                        pos.x = range.min.x;
                    }
                    else
                    {
                        pos.x = range.max.x;
                    }
                    if (range.min.z <= range.max.z)
                    {
                        pos.z = range.min.z;
                    }
                    else
                    {
                        pos.z = range.max.z;
                    }
                    break;

                case Direction.Right:
                case Direction.Forward:
                    if (range.min.x <= range.max.x)
                    {
                        pos.x = range.max.x;
                    }
                    else
                    {
                        pos.x = range.min.x;
                    }
                    if (range.min.z <= range.max.z)
                    {
                        pos.z = range.max.z;
                    }
                    else
                    {
                        pos.z = range.min.z;
                    }
                    break;
                }
                pos += direction.ToVec() * (PlotUtil.PropertyPlotLength - 1) * amount;
                Vector2i claimPos = PlotUtil.NearestPlotPosInWorld(pos.XZ);
                range.ExtendToInclude(claimPos.X_Z(pos.Y));
                range.ExtendToInclude(WorldEditUtils.SecondPlotPos(claimPos).X_Z(pos.Y));
                session.SetSelection(range);

                user.Player.MsgLoc($"First Position now at {session.Selection.min}");
                user.Player.MsgLoc($"Second Position now at {session.Selection.max}");
            }
            catch (WorldEditCommandException e)
            {
                user.Player.ErrorLocStr(e.Message);
            }
            catch (Exception e)
            {
                Log.WriteError(Localizer.Do($"{e}"));
            }
        }