Force player to send command as OP

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

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

    AbeJ

    (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.
     
  2. Offline

    Ne0nx3r0

    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

    You can make the server send the command (the server is practically OP):

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

    AbeJ

    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

    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 :)

    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. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  6. Offline

    AbeJ

    Because I need to set the player as a baby animal, which the API doesn't support.
     
  7. Offline

    nala3

    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 :)
     
  8. Offline

    AbeJ

    I don't want to link against CB.jar, which MobDisguise needs to do what it does. I might have to, though.
     
  9. Offline

    iMine101

    Wait how do you make a player say a command? or say something? Is there a plugin for it?
     
  10. Offline

    LucasEmanuel

    Create a new PlayerChatEvent with the player and the message.
     
  11. thats the wrong way, use Player.chat()
     
Thread Status:
Not open for further replies.

Share This Page