Same code doing two different things?

Discussion in 'Plugin Development' started by Razorcane, Dec 27, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Razorcane

    I have this management plugin that I made. However, I just noticed a serious problem. First thing's first, the code.

    Code:
    
    package org.razorcane.origins.commands;
    
    import java.util.List;
    import org.bukkit.ChatColor;
    import org.bukkit.Server;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.razorcane.origins.Origins;
    
    
    public class OBan implements CommandExecutor{
        private Origins plugin;
        private Server s;
        public OBan(Origins plugin){
            this.plugin = plugin;
        }
    
        @Override
        public boolean onCommand(CommandSender cs, Command cmnd, String label, String[] args) {
            s = plugin.getServer();
            if(cmnd.getName().equalsIgnoreCase("oban")) {
                if(plugin.admins.contains(cs.getName()) || plugin.mods.add(cs.getName())) {
                    if(args == null || args.length < 1){
                        cs.sendMessage(ChatColor.BLUE + "There have been " + ChatColor.YELLOW + plugin.banned + ChatColor.BLUE + " banned this session.");
                        return true;
                    }
                    List<Player> l = s.matchPlayer(args[0]);
                    String reason = "";
                    if(args.length > 1){
                        for(int i = 1; i < args.length; i++){
                            reason += args[i] + " ";
                        }
                    }
                    if(l.size() > 1){
                        cs.sendMessage(ChatColor.RED + "Partial Match.");
                    }
                    else if(l.isEmpty()) {
                        cs.sendMessage(ChatColor.RED + "No player to match.");
                    }
                    else {
                       if(args.length < 2){
                           l.get(0).kickPlayer(null);
                           l.get(0).setBanned(true);
                           plugin.banned++;
                           s.broadcastMessage(ChatColor.BLUE + "Player " + ChatColor.YELLOW + l.get(0).getName() + ChatColor.BLUE + " has been banned by " + ChatColor.YELLOW + cs.getName());
                       }
                       else {
                           l.get(0).kickPlayer(reason);
                           l.get(0).setBanned(true);
                           plugin.banned++;
                           s.broadcastMessage(ChatColor.BLUE + "Player " + ChatColor.YELLOW + l.get(0).getName() + ChatColor.BLUE + " has been banned by " + ChatColor.YELLOW + cs.getName() + ChatColor.BLUE + " for:");
                           s.broadcastMessage(ChatColor.BLUE + reason);
                       }
                    }
                }
                else{
                    cs.sendMessage(ChatColor.RED + "You do not have access to this command!");
                }
            }
            return true;
        }
    }
    ]
    That's my ban command. It works fine, except for the fact that it isn't limited to only admins/mods, which it is supposed to be. Now, this command shares the same code(well, some string changes, but that doesn't count) as my kick command, which does only allow admins/mods to use it. Is there anything here that might make it completely IGNORE the permissions I had set for it?[/code]
     
  2. Offline

    Darkman2412

    Uh: plugin.mods.add(cs.getName()) at you second if statement?
    Epic :D
     
Thread Status:
Not open for further replies.

Share This Page