Solved Deop a player from the server?

Discussion in 'Plugin Development' started by mrdude123, Jun 10, 2015.

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

    mrdude123

    So I'm making this plugin where if a player has a certain permission, they are automatically deopped upon being opped.

    Code:
    package me.thecerealkill3r.suspend;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener {
    public void onEnable(){
    
        Bukkit.getServer().getPluginManager().registerEvents(this, this);
    }
        public boolean onCommand(CommandSender sender, Command cmd, String lbl, String[] args){
            if ((sender instanceof Player));
            Player player = (Player)sender;
            Bukkit.getServer().getOnlinePlayers();
        
                if(player.hasPermission("player.is_suspended")){
                    if(player.isOp()){
                        /*/ Player becomes deopped here /*/
                    }
                }
        
            return false;
        }
    }
    
    EDIT:

    Would this be good?
    Code:
    package me.thecerealkill3r.suspend;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener {
    public void onEnable(){
     
        Bukkit.getServer().getPluginManager().registerEvents(this, this);
    }
        public boolean onCommand(CommandSender sender, Command cmd, String lbl, String[] args){
            if ((sender instanceof Player));
            Player player = (Player)sender;
            Bukkit.getServer().getOnlinePlayers();
         
                if(player.hasPermission("player.is_suspended")){
                    if(player.isOp()){
                        Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "deop " + player);
                    }
                }
         
            return false;
        }
    }
    
     
  2. Offline

    MrBlackIsBack

    Use .setOp()
     
  3. Offline

    VG.Developments

    Few errors;
    - You would need to use player.getName() for the dispatch command.
    - Also whats the point in your line "Bukkit.getServer().getOnlinePlayers();"? If your trying to get all the online players you would want to use a for loop, like;
    For(Player online : Bukkit.getOnlinePlayers()) {
    - also when your checking if the sender is an instanceof a player, you need a { at the end, not ; . All if statements you need those!
     
  4. Offline

    mrdude123

    @VG.Developments I know about all of those, I leave the ugfixing to the end. :)
     
  5. Offline

    VG.Developments

    Well thats how you fix your code like you asked so i answered the question
     
  6. Offline

    mrdude123

Thread Status:
Not open for further replies.

Share This Page