nI put my command it just says the command?

Discussion in 'Plugin Development' started by jasonderlo22, Jul 16, 2013.

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

    jasonderlo22

    I have a plugin that tell you your killer.

    When I type killer in my server it just comes up in the chat bar /killer


    Code:java
    1. name: GetYoKiller
    2. version: 0.1
    3. main: me.jasonderlo22.PotWars.main
    4. commands:
    5. killer:
    6. description: Tells killer
    7. usage: /killer
    8.  


    And my code:

    Code:java
    1. package me.jasonderlo22.PotWars;
    2.  
    3.  
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.entity.PlayerDeathEvent;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10. import org.bukkit.scheduler.BukkitRunnable;
    11. import org.bukkit.command.Command;
    12. import org.bukkit.command.CommandSender;
    13.  
    14. public class main extends JavaPlugin {
    15.  
    16. public void OnEnable(){
    17. getLogger().info("Has been Enabled");
    18.  
    19. }
    20.  
    21. public void OnDisable(){
    22.  
    23. getLogger().info("Has been Disabled");
    24.  
    25.  
    26. }
    27.  
    28. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args, Player ply){
    29. if(cmd.getName().equalsIgnoreCase("killer")){
    30.  
    31. Player s = (Player) sender;
    32.  
    33. s.sendMessage( ChatColor.BLUE + "Player" + ChatColor.RED + "{Killer}" + " Killed you!".replace("{Killer}",(CharSequence)s.getKiller() ));
    34.  
    35.  
    36.  
    37. return true;
    38.  
    39. }
    40.  
    41.  
    42. return false;
    43. }
    44.  
    45.  
    46.  
    47.  
    48.  
    49.  
    50.  
    51. @EventHandler
    52. public void onPlayerDeath(PlayerDeathEvent event)
    53. {
    54. if(event.getEntity().getKiller() instanceof Player)
    55. {
    56. Player died = (Player) event.getEntity();
    57. Player killer = (Player) died.getKiller();
    58.  
    59. event.setDeathMessage(ChatColor.RED + "Player {PlayerName} was killed by {Killer} ".replace("{PlayerName}", died.getName()).replace("{Killer}", killer.getName()) + ChatColor.RED + ".");
    60.  
    61.  
    62.  
    63.  
    64. }
    65.  
    66.  
    67.  
    68.  
    69.  
    70. }
    71.  
    72.  
    73.  
    74.  
    75. }
    76.  
    77.  
    78.  
    79.  
    80.  
    81.  
    82.  
    83.  
    84. package me.jasonderlo22.PotWars;
    85.  
    86.  
    87.  
    88. import org.bukkit.ChatColor;
    89. import org.bukkit.entity.Player;
    90. import org.bukkit.event.EventHandler;
    91. import org.bukkit.event.entity.PlayerDeathEvent;
    92. import org.bukkit.plugin.java.JavaPlugin;
    93. import org.bukkit.scheduler.BukkitRunnable;
    94. import org.bukkit.command.Command;
    95. import org.bukkit.command.CommandSender;
    96.  
    97. public class main extends JavaPlugin {
    98.  
    99. public void OnEnable(){
    100. getLogger().info("Has been Enabled");
    101.  
    102. }
    103.  
    104. public void OnDisable(){
    105.  
    106. getLogger().info("Has been Disabled");
    107.  
    108.  
    109. }
    110.  
    111. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args, Player ply){
    112. if(cmd.getName().equalsIgnoreCase("killer")){
    113.  
    114. Player s = (Player) sender;
    115.  
    116. s.sendMessage( ChatColor.BLUE + "Player" + ChatColor.RED + "{Killer}" + " Killed you!".replace("{Killer}",(CharSequence)s.getKiller() ));
    117.  
    118.  
    119.  
    120. return true;
    121.  
    122. }
    123.  
    124.  
    125. return false;
    126. }
    127.  
    128.  
    129.  
    130.  
    131.  
    132.  
    133.  
    134. @EventHandler
    135. public void onPlayerDeath(PlayerDeathEvent event)
    136. {
    137. if(event.getEntity().getKiller() instanceof Player)
    138. {
    139. Player died = (Player) event.getEntity();
    140. Player killer = (Player) died.getKiller();
    141.  
    142. event.setDeathMessage(ChatColor.RED + "Player {PlayerName} was killed by {Killer} ".replace("{PlayerName}", died.getName()).replace("{Killer}", killer.getName()) + ChatColor.RED + ".");
    143.  
    144.  
    145.  
    146.  
    147. }
    148.  
    149.  
    150.  
    151.  
    152.  
    153. }
    154.  
    155.  
    156.  
    157.  
    158. }
    159.  
    160.  
    161.  
    162.  
    163.  
    164.  
    165.  
    166.  


    Thanks, Jasonderlo22
     
  2. The string that shows up in teh chatbar is the usage message you defined in the plugin.yml, the usage and description stuff is not necessary, the command probably doesn't work because there is an error. Take a look at your console or add debug messages.

    Also where do you store the killers? Make something like a Map or so and store the name of the player + killer in it. Then when the player types the command then just get his name from the map and voila, you are done.
     
  3. Offline

    jasonderlo22

    CaptainBern

    How would I do that as in the hashmap if that is what you meant by Map? There is no error and everything is fine
     
  4. Offline

    Bammerbom

    spideynn likes this.
  5. Offline

    jasonderlo22

  6. Jhtzb already gave the answer. When you return false it will send the player the usage message you defined in the plugin. yml
    You should return false when the player didn't use the command correctly (missing args), otherwise return true
     
Thread Status:
Not open for further replies.

Share This Page