Setting A Players Pex Groups

Discussion in 'Plugin Development' started by MrDynamo, Feb 22, 2013.

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

    MrDynamo

    I'm trying to figure out how to do this. I want a group to be able to type /demote username and have it demote that player.

    Code:JAVA
    1. package com.github.MrDynamo;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.PluginDescriptionFile;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class Demote extends JavaPlugin {
    14. // Don't use the Minecraft Logger
    15. public Logger logger;
    16. // And static is bad >:3 (well not bad, but not advised either)
    17.  
    18. @Override
    19. public void onDisable() {
    20. PluginDescriptionFile pdfFile = this.getDescription();
    21. // This message is not neccesary
    22. this.logger.info(pdfFile.getName() + " has been disabled.");
    23. }
    24.  
    25. @Override
    26. public void onEnable() {
    27. // Use the JavaPlugin Logger instead!
    28. this.logger = this.getLogger();
    29. PluginDescriptionFile pdfFile = this.getDescription();
    30. // This message is not neccesary
    31. this.logger.info(pdfFile.getName() + " v" + pdfFile.getVersion() + " has been enabled.");
    32. // Also you forgot to register your Listener
    33. Bukkit.getPluginManager().registerEvents(new MyPlayerListener(), this);
    34. }
    35.  
    36. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    37. Player player = (Player) sender;
    38. if (player.hasPermission("demote.demote")) {
    39. if (commandLabel.equalsIgnoreCase("demote")) {
    40. if (args.length == 0) {
    41. player.sendMessage("Usage: /demote 'player'");
    42. }else if (args.length == 1) {
    43. if(player.getServer().getPlayer(args[0]) != null) {
    44. Player targetPlayer = player.getServer().getPlayer(args[0]);
    45. targetPlayer.addGroup("D");
    46. }
    47. }
    48. }
    49. }
    50. return false;
    51. }
    52. }
     
  2. Offline

    Quidam

    You know PEX has a built-in demote command, right?
     
  3. Offline

    MrDynamo

    Yes, but I want to do it via this plugin. What else do I need to change in my code?
     
  4. Offline

    Quidam

    Sent code line in Skype
     
  5. Offline

    iWareWolf

  6. Offline

    MrDynamo

Thread Status:
Not open for further replies.

Share This Page