Force player to send command as OP

Discussion in 'Plugin Development' started by AbeJ, Apr 22, 2012.

  1. Offline

    AbeJ

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    (this might have been asked already, but I can't find it if it was)

    I know how to force a player to send a command, but how can I make the command be sent as OP? I know I could just OP them temporarily, but that's a bit of an ugly solution. Is there a better way?

    Edit: For those interested, I am writing a plugin that uses MobDisguise, but MD's API is extremely basic, and doesn't support things like toggling the person as a baby, which I need. Therefore, I have to use commands.

    This post has been edited 1 time. It was last edited by AbeJ Apr 22, 2012.
  2. Offline

    Ne0nx3r0

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    It seems like the best way to do it would be to either user permissions (temporarily I guess?), do whatever you need to in your own plugin by copying the applicable methods into your plugin, or see about plugging into their API.

    I don't think it's a good idea at all to even allow the possibility of any command to be sent as an OP.
  3. Offline

    Kodlee Yin

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    You can make the server send the command (the server is practically OP):

    Code:java
    1. Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "<command here>");

    This post has been edited 8 times. It was last edited by Kodlee Yin Apr 22, 2012.
  4. Offline

    AbeJ

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Unfortunately, the MobDisguise commands only work when run by a player (it's dumb). They should really take a player as an argument, and work from the console.
  5. Offline

    nala3

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Best bet would probably be to hook into MobDisguise and just use his methods to set the players appearance. There most likely is a .setAppearance(player, type) or something along the lines of that method. I will look into if you'd like :)
  6. Offline

    nala3

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Why can't you do something like this?
    Code:java
    1.  
    2. @Override
    3. public boolean onCommand(CommandSender sender, Command command,
    4. String label, String[] args) {
    5. Player p = null;
    6. if(sender instanceof Player){
    7. p = ((Player) sender).getPlayer();
    8. } else {
    9. sender.sendMessage("Command must be run by a player");
    10. return true;
    11. }
    12. if(label.equalsIgnoreCase("hideme")){
    13. MobDisguiseAPI.disguisePlayer(p, "chicken");
    14. }
    15. if(label.equalsIgnoreCase("showme")){
    16. MobDisguiseAPI.undisguisePlayer(p);
    17. }
    18. return true;
    19. }

    This post has been edited 3 times. It was last edited by nala3 Apr 22, 2012.
  7. Offline

    AbeJ

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Because I need to set the player as a baby animal, which the API doesn't support.
  8. Offline

    nala3

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    so Don't use mob disguise, do it yourself. You can look off of MD's source to see how it changes the player to begin with as a reference. Or, you could ask the author to add support for that :)
  9. Offline

    AbeJ

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I don't want to link against CB.jar, which MobDisguise needs to do what it does. I might have to, though.
  10. Offline

    iMine101

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Wait how do you make a player say a command? or say something? Is there a plugin for it?
  11. Offline

    LucasEmanuel

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Create a new PlayerChatEvent with the player and the message.
  12. Online

    ferrybig

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    thats the wrong way, use Player.chat()

Share This Page