Beispiel #1
0
 public override void onPlayerCommand(PlayerCommandEvent Event)
 {
     string[] split = Event.getMessage().Split(' ');
     split[0] = split[0].ToLower().Replace("/", "");
     string command = split[0];
     Sender sender = Event.getSender();
     if (command == "kick")
     {
         Event.setCancelled(true);
         if (!PermissionManager.HasPermission(sender, "badmin.kick"))
         {
             sender.sendMessage("You don't have enough permissions!");
             return;
         }
         if (split.Length < 2)
         {
             sender.sendMessage("USAGE: " + (sender is Player ? "/" : "") + "kick [player] (reason)");
             return;
         }
         int to = FindPlayerByName(split[1]);
         if (to == -1)
         {
             sender.sendMessage("Couldn't find the player!");
         }
         string name = Program.server.getPlayerList()[to].getName();
         string message = split.Length > 2 ? split[2] : "No reason provided";
         sender.sendMessage("You kicked " + name + ". Reason: " + message);
         foreach (Player player in Program.server.getPlayerList())
         {
             player.sendMessage(name + " has been kicked. Reason: " + message);
         }
         ((Player) sender).Kick("KICKED: " + message);
         Console.WriteLine("[bAdmin] " + sender.getName() + " kicked " + name + " Reason: " + message);
         return;
     }
     /*if (command == "ban")
     {
         Event.SetCancelled(true);
         if (!PermissionManager.HasPermission(sender, "badmin.ban"))
         {
             sender.SendMessage("You don't have enough permissions!", cError);
             return;
         }
         if (split.Length < 2)
         {
             sender.SendMessage("USAGE: " + (sender is Player ? "/" : "") + "ban [player] (reason)", cError);
             return;
         }
         int to = FindPlayerByName(split[1]);
         if (to == -1)
         {
             sender.SendMessage("Couldn't find the player!", cError);
         }
         string message = split.Length > 2 ? split[2] : "No reason provided";
         sender.SendMessage("You banned " + GetPlayerName(to) + ". Reason: " + message, cInfo);
         SendAllMessage(GetPlayerName(to) + " has been banned. Reason: " + message, cInfo);
         ((Player)sender).Kick("BANNED: " + message);
         Console.WriteLine("[bAdmin] " + sender.GetName() + " banned " + GetPlayerName(to) + " Reason: " + message);
         return;
     }*/
 }
        public override void onPlayerCommand(PlayerCommandEvent Event)
        {
            int player = ((Player) Event.getSender()).whoAmi;
            string command = Event.getMessage();
            string[] split = command.Split(' ');
            split[0] = split[0].ToLower();
            var sender = Event.getSender();
            if (split[0] == "//pos1" || split[0] == "//p1")
            {
                Event.setCancelled(true);
                if (!PermissionManager.HasPermission(player, "terraedit.selection"))
                {
                    sender.sendMessage("You don't have enough permissions!");
                    return;
                }
                if (!Waiting1.ContainsKey(player)) Waiting1.Add(player, true);
                if (!Waiting2.ContainsKey(player)) Waiting2.Add(player, false);
                Waiting1[player] = true;
                Waiting2[player] = false;
                sender.sendMessage("Waiting for block place/destroy.");
                return;
            }
            if (split[0] == "//pos2" || split[0] == "//p2")
            {
                Event.setCancelled(true);
                if (!PermissionManager.HasPermission(player, "terraedit.selection"))
                {
                    sender.sendMessage("You don't have enough permissions!");
                    return;
                }
                if (!Waiting1.ContainsKey(player)) Waiting1.Add(player, false);
                if (!Waiting2.ContainsKey(player)) Waiting2.Add(player, true);
                Waiting2[player] = true;
                Waiting1[player] = false;
                sender.sendMessage("Waiting for block place/destroy.");
                return;
            }
            if (split[0] == "//set")
            {
                Event.setCancelled(true);
                if (!PermissionManager.HasPermission(player, "terraedit.set"))
                {
                    sender.sendMessage("You don't have enough permissions!");
                    return;
                }
                if (split.Length < 2)
                {
                    sender.sendMessage("USAGE: //set [block]");
                    return;
                }
                if (!SelectionMade(player))
                {
                    sender.sendMessage("You haven't made a selection!");
                    return;
                }
                int id;
                if (!Int32.TryParse(split[1], out id))
                {
                    id = TileNames.FindTileByName(split[1]);
                    if (id == -2)
                    {
                        sender.sendMessage("Invalid block name!");
                        return;
                    }
                }
                if (id < -1 || id > 79)
                {
                    sender.sendMessage("Invalid block ID!");
                    return;
                }
                //var tile = new Tile {type = Byte.Parse(split[1])};
                var action = new Action();
                int highX = Pos1[player].X > Pos2[player].X ? (int)Pos1[player].X : (int)Pos2[player].X;
                int highY = Pos1[player].Y > Pos2[player].Y ? (int)Pos1[player].Y : (int)Pos2[player].Y;
                int lowX = Pos1[player].X < Pos2[player].X ? (int)Pos1[player].X : (int)Pos2[player].X;
                int lowY = Pos1[player].Y < Pos2[player].Y ? (int)Pos1[player].Y : (int)Pos2[player].Y;
                for (int i = lowX; i <= highX; i++)
                {
                    for (int j = lowY; j <= highY; j++)
                    {
                        action.SetBlock(i,j,id);
                    }
                }
                int c = action.Do();
                if (!Actions.ContainsKey(player)) Actions.Add(player, new List<Action>());
                if (Actions[player].Count > 0) Actions[player].Insert(0, action);
                else Actions[player].Add(action);
                sender.sendMessage(c + " blocks modified.");
                return;
            }
            if (split[0] == "//disc")
            {
                Event.setCancelled(true);
                if (!PermissionManager.HasPermission(player, "terraedit.disc"))
                {
                    sender.sendMessage("You don't have enough permissions!");
                    return;
                }
                if (split.Length < 3)
                {
                    sender.sendMessage("USAGE: //disc [radius] [block]");
                    return;
                }
                if (!Pos1.ContainsKey(player) || Pos1[player] == null)
                {
                    sender.sendMessage("You must set position 1 as the circle center!");
                    return;
                }
                int radius;
                if (!Int32.TryParse(split[1], out radius))
                {
                    sender.sendMessage("Invalid radius!");
                    return;
                }
                if (radius < 1)
                {
                    sender.sendMessage("Radius must be higher than 0!");
                    return;
                }
                int id;
                if (!Int32.TryParse(split[2], out id))
                {
                    id = TileNames.FindTileByName(split[2]);
                    if (id == -2)
                    {
                        sender.sendMessage("Invalid block name!");
                        return;
                    }
                }
                if (id < -1 || id > 79)
                {
                    sender.sendMessage("Invalid block ID!");
                    return;
                }
                var action = new Action();
                int px = Convert.ToInt32(Pos1[player].X);
                int py = Convert.ToInt32(Pos1[player].Y);
                for (int i = px-radius; i <= px+radius; i++)
                {
                    for (int j = py-radius; j <= py+radius; j++)
                    {
                        if ((px-i)*(px-i) + (py-j)*(py-j) < radius*radius)
                        {
                            action.SetBlock(i,j,id);
                        }
                    }
                }
                int c = action.Do();
                if (!Actions.ContainsKey(player)) Actions.Add(player, new List<Action>());
                if (Actions[player].Count > 0) Actions[player].Insert(0, action);
                else Actions[player].Add(action);
                sender.sendMessage(c + " blocks modified.");
                return;
            }
            if (split[0] == "//replace")
            {
                Event.setCancelled(true);
                if (!PermissionManager.HasPermission(player, "terraedit.replace"))
                {
                    sender.sendMessage("You don't have enough permissions!");
                    return;
                }
                if (split.Length < 3)
                {
                    sender.sendMessage("USAGE: //replace [from] [to]");
                    return;
                }
                if (!SelectionMade(player))
                {
                    sender.sendMessage("You haven't made a selection!");
                    return;
                }
                int from;
                if (!Int32.TryParse(split[1], out from))
                {
                    from = TileNames.FindTileByName(split[1]);
                    if (from == -2)
                    {
                        sender.sendMessage("Invalid block name!");
                        return;
                    }
                }
                if (from < -1 || from > 79)
                {
                    sender.sendMessage("Invalid block ID!");
                    return;
                }
                int to;
                if (!Int32.TryParse(split[2], out to))
                {
                    to = TileNames.FindTileByName(split[2]);
                    if (to == -2)
                    {
                        sender.sendMessage("Invalid block name!");
                        return;
                    }
                }
                if (to < -1 || to > 79)
                {
                    sender.sendMessage("Invalid block ID!");
                    return;
                }
                var action = new Action();
                int highX = Pos1[player].X > Pos2[player].X ? (int)Pos1[player].X : (int)Pos2[player].X;
                int highY = Pos1[player].Y > Pos2[player].Y ? (int)Pos1[player].Y : (int)Pos2[player].Y;
                int lowX = Pos1[player].X < Pos2[player].X ? (int)Pos1[player].X : (int)Pos2[player].X;
                int lowY = Pos1[player].Y < Pos2[player].Y ? (int)Pos1[player].Y : (int)Pos2[player].Y;
                for (int i = lowX; i <= highX; i++)
                {
                    for (int j = lowY; j <= highY; j++)
                    {
                        if(Main.tile[i,j].type == from) action.SetBlock(i, j, to);
                    }
                }
                int c = action.Do();
                if (!Actions.ContainsKey(player)) Actions.Add(player, new List<Action>());
                if (Actions[player].Count > 0) Actions[player].Insert(0, action);
                else Actions[player].Add(action);
                sender.sendMessage(c + " blocks modified.");
                return;

            }
            if (split[0] == "//undo")
            {
                Event.setCancelled(true);
                if (!PermissionManager.HasPermission(player, "terraedit.undo"))
                {
                    sender.sendMessage("You don't have enough permissions!");
                    return;
                }
                if (Actions[player].Count == 0)
                {
                    sender.sendMessage("Nothing to undo!");
                    return;
                }
                foreach (KeyValuePair<Vector2, ActionBlock> kvp in Actions[player].First().changedBlocks)
                {
                    int X = Convert.ToInt32(kvp.Key.X);
                    int Y = Convert.ToInt32(kvp.Key.Y);
                    //World world = Program.server.getWorld();
                    if (kvp.Value.StartType == -1)
                    {
                        Main.tile[X, Y].active = false;
                        NetMessage.SendTileSquare(-1, X, Y, 1);
                    }
                    else
                    {
                        /*WorldGen.KillTile(X, Y, world, false, false, true);
                        WorldGen.PlaceTile(X, Y, world, kvp.Value.StartType, false, true);*/
                        Main.tile[X, Y].active = true;
                        Main.tile[X, Y].type = (byte)kvp.Value.StartType;
                        NetMessage.SendTileSquare(-1, X, Y, 1);
                    }
                }
                Actions[player].Remove(Actions[player].First());
                sender.sendMessage("Last action undone");
                return;
            }

            return;
        }
 public override void onPlayerCommand(PlayerCommandEvent Event)
 {
     int player = ((Player)Event.getSender()).whoAmi;
     string command = Event.getMessage();
     string[] split = command.Split(' ');
     split[0] = split[0].ToLower();
     var sender = Event.getSender();
     if(split.Length > 1) split[1] = split[1].ToLower();
     if (split[0] == "/region")
     {
         if(split[1] == "define")
         {
             Event.setCancelled(true);
             if (!PermissionManager.HasPermission(player, "terraguard.region.define"))
             {
                 sender.sendMessage("You don't have enough permissions!");
                 return;
             }
             if (split.Length < 4)
             {
                 sender.sendMessage("USAGE: /region define [name] [members]");
                 return;
             }
             if (RegionExists(split[2]))
             {
                 sender.sendMessage("A region with this name already exists!");
                 return;
             }
             if (!SelectionMade(player))
             {
                 sender.sendMessage("You haven't made a selection!");
                 return;
             }
             var members = new string[split.Length - 3];
             Array.Copy(split, 3, members, 0, split.Length - 3);
             var memb = String.Join(" ", members);
             Regions.Add(new Region(split[2], memb, GetPos1(player), GetPos2(player)));
             sender.sendMessage("Created region " + split[2]);
             sender.sendMessage("Members: " + memb);
             SaveRegions();
             return;
         }
     }
 }
        public override void onPlayerCommand(PlayerCommandEvent Event)
        {
            if (isEnabled == false) { return; }
            string[] commands = Event.getMessage().ToLower().Split(' ');
            string sCommand = Event.getMessage().ToLower();

            string sSenderName = ((Player)Event.getSender()).getName();

            if (commands.Length > 0)
            {
                try
                {
                    string sPlayerCmdPrivMsg = @"(/pm|/privmsg)\s+(?<flag>[on|off]+)?";
                    string sPlayerCmdHeal = @"/heal(?:\s+(?<player>.*))?";
                    string sPlayerCmdReply = @"[/reply|/r]\s(?<msg>.+)?";
                    string sPlayerCmdMessage = @"[/m|/msg]\s(?<player>[A-Z-a-z0-9]+)\s(?<msg>.+)?";

                    MyPlayer oPlayer = Utility.FindPlayer(((Player)Event.getSender()).getName());
                    Match commandMatch;

                    if (oPlayer.IsOp())
                    {
                        // Op commands
                        commandMatch = Regex.Match(sCommand, sPlayerCmdHeal, RegexOptions.IgnoreCase);
                        if (commandMatch.Success)
                        {
                            // Heal
                            string targetPlayerName = commandMatch.Groups["player"].Value;

                            Heal(oPlayer, targetPlayerName);
                            Event.setCancelled(true);
                            return;
                        }
                    }

                    commandMatch = Regex.Match(sCommand, sPlayerCmdPrivMsg, RegexOptions.IgnoreCase);
                    if (commandMatch.Success)
                    {
                        // PrivMsg On/Off
                        string flag = commandMatch.Groups["flag"].Value;

                        PrivateMessageEnableDisable(oPlayer, flag);
                        Event.setCancelled(true);
                        return;
                    }

                    commandMatch = Regex.Match(sCommand, sPlayerCmdReply, RegexOptions.IgnoreCase);
                    if (commandMatch.Success)
                    {
                        // Reply
                        string message = commandMatch.Groups["msg"].Value;

                        ReplyMessage(oPlayer, message);
                        Event.setCancelled(true);
                        return;
                    }

                    commandMatch = Regex.Match(sCommand, sPlayerCmdMessage, RegexOptions.IgnoreCase);
                    if (commandMatch.Success)
                    {
                        // Message
                        string playerName = commandMatch.Groups["player"].Value;
                        string message = commandMatch.Groups["msg"].Value;

                        PrivateMessage(oPlayer, playerName, message);

                        Event.setCancelled(true);
                        return;
                    }
                }
                catch (Exception er)
                {
                    Event.getSender().sendMessage(string.Format("Error: {0}", er.Message));
                    Console.WriteLine(string.Format("Error processing command '{0}': {1}", commands[0], er.Message));
                }
            }
        }