OR operator not registering command aliases

Discussion in 'Plugin Development' started by lorddominayte, May 8, 2014.

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

    lorddominayte

    Hi,
    I'm trying to give certain commands aliases since the original commands were rather long. I used the code below and when I try to use one of the aliases for the commands the server outputs "Command not recognized. Type /help for a list of commands". They are all listed as aliases in the plugin.yml and they show up when I type /help (command name). Anyone got any tips?


    Code:java
    1. package me.lorddominayte.serverutils;
    2.  
    3.  
    4.  
    5. import java.util.logging.Logger;
    6.  
    7.  
    8.  
    9. import org.bukkit.ChatColor;
    10.  
    11. import org.bukkit.command.Command;
    12.  
    13. import org.bukkit.command.CommandSender;
    14.  
    15. import org.bukkit.entity.Player;
    16.  
    17. import org.bukkit.plugin.PluginDescriptionFile;
    18.  
    19. import org.bukkit.plugin.java.JavaPlugin;
    20.  
    21.  
    22.  
    23. public class ServerUtils extends JavaPlugin{
    24.  
    25. public final Logger logger = Logger.getLogger("Minecraft");
    26.  
    27. public static ServerUtils plugin;
    28.  
    29.  
    30.  
    31. @Override
    32.  
    33. public void onDisable() {
    34.  
    35. PluginDescriptionFile pdfFile = this.getDescription();
    36.  
    37. this.logger.info(pdfFile.getName() + " has been disabled");
    38.  
    39. }
    40.  
    41. @Override
    42.  
    43. public void onEnable() {
    44.  
    45. PluginDescriptionFile pdfFile = this.getDescription();
    46.  
    47. this.logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " has been enabled");
    48.  
    49. getConfig().options().copyDefaults(true);
    50.  
    51. saveConfig();
    52.  
    53. }
    54.  
    55. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    56.  
    57. Player player = (Player) sender;
    58.  
    59. if(commandLabel.equalsIgnoreCase("syscheck")) {
    60.  
    61. sender.sendMessage(ChatColor.BLUE + "Everything's working fine.");
    62.  
    63. }
    64.  
    65. if(commandLabel.equalsIgnoreCase("healme") || commandLabel.equalsIgnoreCase("hm")) {
    66.  
    67. if(player.hasPermission("su.healself")) {
    68.  
    69. player.setHealth(20D);
    70.  
    71. player.sendMessage(ChatColor.GREEN + "You healed yourself.");
    72.  
    73. }
    74.  
    75. else {
    76.  
    77. player.sendMessage(ChatColor.RED + "You do not have permission to use that command.");
    78.  
    79. }
    80.  
    81. }
    82.  
    83. if(commandLabel.equalsIgnoreCase("healother") || commandLabel.equalsIgnoreCase("ho")) {
    84.  
    85. if(args.length == 0) {
    86.  
    87. player.sendMessage(ChatColor.RED + "Incorrect usage. Type /help healother for usage.");
    88.  
    89. }
    90.  
    91. else if(args.length == 1) {
    92.  
    93. Player targetPlayer = player.getServer().getPlayer(args[0]);
    94.  
    95. targetPlayer.setHealth(20D);
    96.  
    97. player.sendMessage(ChatColor.GREEN + "You healed " + targetPlayer.getName() + ".");
    98.  
    99. targetPlayer.sendMessage(ChatColor.GREEN + "You were healed.");
    100.  
    101. }
    102.  
    103. }
    104.  
    105. if(commandLabel.equalsIgnoreCase("tellplayer") || commandLabel.equalsIgnoreCase("tplr")) {
    106.  
    107. if(args.length == 0) {
    108.  
    109. player.sendMessage(ChatColor.RED + "Incorrect usage. Type /help tellplayer for usage.");
    110.  
    111. }
    112.  
    113. else if(args.length == 1) {
    114.  
    115. player.sendMessage(ChatColor.RED + "Incorrect usage. Type /help tellplayer for usage.");
    116.  
    117. }
    118.  
    119. else if(args.length == 2) {
    120.  
    121. Player targetPlayer = player.getServer().getPlayer(args[0]);
    122.  
    123. String msg = args[1];
    124.  
    125. targetPlayer.sendMessage(ChatColor.BLUE + player.getName() + " tells you: " + msg);
    126.  
    127. }
    128.  
    129. }
    130.  
    131. if(commandLabel.equalsIgnoreCase("getmotd") || commandLabel.equalsIgnoreCase("messageoftheday")) {
    132.  
    133. if(player.hasPermission("su.get.motd")) {
    134.  
    135. player.sendMessage(ChatColor.GOLD + "MOTD: " + getConfig().getString("serverinfo.motd"));
    136.  
    137. }
    138.  
    139. }
    140.  
    141. if(commandLabel.equalsIgnoreCase("getsn") || commandLabel.equalsIgnoreCase("servername")) {
    142.  
    143. if(player.hasPermission("su.get.servername")) {
    144.  
    145. player.sendMessage(ChatColor.GOLD + "Server Name: " + getConfig().getString("serverinfo.name"));
    146.  
    147. }
    148.  
    149. }
    150.  
    151. if(commandLabel.equalsIgnoreCase("gettype") || commandLabel.equalsIgnoreCase("servertype")) {
    152.  
    153. if(player.hasPermission("su.get.servertype")) {
    154.  
    155. player.sendMessage(ChatColor.GOLD + "Server Type: " + getConfig().getString("serverinfo.type"));
    156.  
    157. }
    158.  
    159. }
    160.  
    161. if(commandLabel.equalsIgnoreCase("getowner") || commandLabel.equalsIgnoreCase("serverowner")) {
    162.  
    163. if(player.hasPermission("su.get.serverowner")) {
    164.  
    165. player.sendMessage(ChatColor.GOLD + "Server Owner: " + getConfig().getString("serverinfo.owner"));
    166.  
    167. }
    168.  
    169. }
    170.  
    171. return false;
    172.  
    173. }
    174.  
    175. }

     
  2. Offline

    JungleSociety

    lorddominayte
    I'll be honest with you, I never use command aliases in the plugin.yml. I just register it as a completely new command. But anyways, I recommend that you post your plugin.yml so we can take a look at that :).
     
  3. Offline

    werter318

    If you use cmd.getName() you don't have to check both the normal command name and the aliases.
     
    evilmidget38 likes this.
  4. Offline

    rsod

    well, also a little offtopic advice. Not
    Code:
    player.setHealth(20D);
    but
    Code:
    player.setHealth(player.getMaxHealth());
     
  5. Offline

    lorddominayte

    Hi, this is my plugin.yml:
    Code:java
    1. name: ServerUtils
    2. main: me.lorddominayte.serverutils.ServerUtils
    3. version: 2.7
    4. website: [url]http://www.jhboyd.com/[/url]
    5. author: lorddominayte
    6. description: Basic commands and utilities for your server.
    7. commands:
    8. syscheck:
    9. description: Checks if the plugin is active.
    10. healme:
    11. description: Heals the player.
    12. aliases: /hm
    13. healother:
    14. description: Heals another player.
    15. usage: /healother <player>
    16. aliases: /ho
    17. usage: /healother <player>
    18. tellplayer:
    19. description: Tells a player something.
    20. aliases: /tplr
    21. usage: /tellplayer <message>
    22. messageoftheday:
    23. description: Gets the Message of the Day.
    24. aliases: /getmotd
    25. servername:
    26. description: Gets the server name.
    27. aliases: /getsn
    28. servertype:
    29. description: Gets the server type.
    30. aliases: /gettype
    31. serverowner:
    32. description: Tells you the server's owner's name.
    33. aliases: /getowner

     
  6. Offline

    1Achmed1

    HA! One of your aliases is "ho" :D
     
  7. Offline

    rsod

    You should not put "/" before command name
    Code:
    
    commands:
       mmocore:
          description: main command
          usage: /<command>
          aliases: [mmo, core]
     
  8. Offline

    lorddominayte


    rsod That doesn't work. The message "The method getMaxHealth() is ambiguous for the type Player" appears. Also, I will try out your suggestion for the plugin.yml.
     
  9. Offline

    rsod

Thread Status:
Not open for further replies.

Share This Page