Example #1
0
 /// <summary>
 /// this is the execution method which gets executed later
 /// to get more arguments use the internal regArgs variable
 /// </summary>
 /// <param name="arg1">first argument after the command in the string</param>
 /// <param name="arg2">second argument after the command in the string</param>
 /// <param name="arg3">third argument after the command in the string</param>
 /// <param name="arg4">fourth argument after the command in the string</param>
 /// <returns>remember to set the command result in every return case</returns>
 public override CommandResult Execute(String arg1, String arg2, String arg3, String arg4)
 {
     if (!String.IsNullOrEmpty(arg1))
     {
         IMinecraftHandler mc    = MinecraftHandler;
         String            match = EasyGuess.GetMatchedString(mc.Player, arg1);
         if (!String.IsNullOrEmpty(match))
         {
             UserCollectionSingletone userCollection = UserCollectionSingletone.GetInstance();
             User matchedPlayer = userCollection.GetUserByName(match);
             if (matchedPlayer != null)
             {
                 GroupCollectionSingletone groups = GroupCollectionSingletone.GetInstance();
                 Group group = EasyGuess.GetMatchedGroup(groups, arg2);
                 if (group != null)
                 {
                     if (ClientUser.LevelID >= matchedPlayer.LevelID && ClientUser.LevelID >= group.Id) // checks if the triggered user has a higher group level
                     {
                         matchedPlayer.LevelID = group.Id;                                              // sets the rank to the user :)
                         if (matchedPlayer.Generated)
                         {
                             matchedPlayer.Name = match;
                             if (!userCollection.IsInlist(match))
                             {
                                 userCollection.Add(matchedPlayer);
                                 userCollection.Save();
                             }
                         }
                         return(new CommandResult(true, string.Format("player {0} set to group {1}", matchedPlayer.Name, group.Name)));
                     }
                     else
                     {
                         return(new CommandResult(true, string.Format("group level is too low {0} ID:{1}", ClientUser.Level.Name, ClientUser.LevelID)));
                     }
                 }
                 else
                 {
                     return(new CommandResult(true, string.Format("couldn't find group {0}", arg2))); // give as much informations as you can
                 }
             }
             else
             {
                 return(new CommandResult(true, string.Format("couldn't find the user {0}", match))); // give as much informations as you can
             }
         }
         else
         {
             return(new CommandResult(true, string.Format("couldn't find the user {0}", match))); // give as much informations as you can
         }
     }
     else
     {
         return(new CommandResult(true, string.Format("couldn't find player {0}", arg1)));
     }
 }
Example #2
0
 public override CommandResult Execute(String arg1, String arg2, String arg3, String arg4)
 {
     if (!String.IsNullOrEmpty(arg1))
     {
         UserCollectionSingletone userlist = UserCollectionSingletone.GetInstance();
         if (arg1[0] == '*')
         {
             if (arg1 == "*true")
             {
                 foreach (User u in userlist.Items)
                 {
                     if (ClientUser != u)
                     {
                         u.AllowChat = false;
                     }
                 }
                 Server.SendServerMessage(String.Format("Every player has been muted except {0}", TriggerPlayer));
             }
             if (arg1 == "*false")
             {
                 foreach (User u in userlist.Items)
                 {
                     if (ClientUser != u)
                     {
                         u.AllowChat = true;
                     }
                 }
                 Server.SendServerMessage(String.Format("Every player has been unmuted except {0}", TriggerPlayer));
             }
         }
         else
         {
             List <String> playerlist = MinecraftHandler.Player;
             string        match      = EasyGuess.GetMatchedString(playerlist, arg1);
             if (!String.IsNullOrEmpty(match))
             {
                 User user = userlist.GetUserByName(match);
                 if (user.Generated)
                 {
                     user.Generated = false;
                     userlist.Add(user);
                     user.AllowChat = false;
                     userlist.Save();
                     return(new CommandResult(true, string.Format("{0} has muted {1}", TriggerPlayer, match)));
                 }
                 else
                 {
                     user.AllowChat = !user.AllowChat;
                     userlist.Save();
                     if (user.AllowChat)
                     {
                         return(new CommandResult(true, string.Format("{0} has unmuted {1}", TriggerPlayer, match)));
                     }
                     else
                     {
                         return(new CommandResult(true, string.Format("{0} has muted {1}", TriggerPlayer, match)));
                     }
                 }
             }
         }
     }
     return(new CommandResult(true, string.Format("user not found {0}", arg1)));
 }