Can't figure out what's going on

Discussion in 'Plugin Development' started by evantheis, Jul 7, 2013.

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

    evantheis

    I have a command executor class that makes when you do /event [eventname] it'll broadcast the name of the event. and say that itll start in 5 minutes and how to get to it. Here it the code for it:
    Code:java
    1. package com.EndlessWar.NightVision;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandExecutor;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9.  
    10. public class Events implements CommandExecutor{
    11.  
    12. @Override
    13. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    14. if(!(sender instanceof Player)){
    15. sender.sendMessage("This is not applicable in the console!");
    16. }
    17. if(cmd.getName().equalsIgnoreCase("Event")) {
    18. if(!(sender instanceof Player)){
    19. sender.sendMessage("This is not applicable in the console!");
    20. }
    21. else if(args[1].equalsIgnoreCase("DropParty")) {
    22. Bukkit.getServer().broadcastMessage(ChatColor.AQUA + "There will be a DropParty in 5 minutes! Do /warp DropParty to join!");
    23. }
    24. else if(args[1].equalsIgnoreCase("HideAndSeek")) {
    25. Bukkit.getServer().broadcastMessage(ChatColor.AQUA + "There will be a Hide and Seek event in 5 minutes. Do /warp HideAndSeek to join!");
    26. }
    27. else if(args [1].equalsIgnoreCase("StorageWars")) {
    28. Bukkit.getServer().broadcastMessage(ChatColor.AQUA + "There will be a Storage Wars event in 5 minutes. Do /warp StorageWar to join!");
    29. }
    30. else if(args[1].equalsIgnoreCase("Auction")) {
    31. Bukkit.getServer().broadcastMessage(ChatColor.AQUA + "There will be a Auction in 5 minutes. Do /warp Auction to join!");
    32. }
    33. else if (args[1].equalsIgnoreCase("HorseRace")) {
    34. Bukkit.getServer().broadcastMessage(ChatColor.AQUA + "There will be a horse race in 5 minutes! Do /warp horserace to join!");
    35. }
    36. else if (args [1].equalsIgnoreCase("DragRace")) {
    37. Bukkit.getServer().broadcastMessage(ChatColor.AQUA + "There is a drag race at /warp dragrace. Better join fast! Do /warp DragRace to join and watch!");
    38. }
    39. else if(cmd.getName().equalsIgnoreCase("Events")) {
    40. sender.sendMessage(ChatColor.GREEN + "There are 8 events. There is DropParty, HideAndSeek,StorageWars, Auction, HorseRace, and DragRace.");
    41. }
    42. }
    43. return false;
    44. }
    45. }
    46.  

    What's going on here? I usually don't like to post but this time I just can't figure it out :/ Sorry.
     
  2. Offline

    SnipsRevival

    Add some return true statements and that should fix your problem.
     
  3. Offline

    evantheis

    Like inside every {}?
     
  4. Offline

    SnipsRevival

  5. Offline

    evantheis

    SnipsRevival That didn't work at all. It doesn't even tell me "This is not applicable in the console". What would be going on?
     
  6. Offline

    SnipsRevival

  7. Offline

    evantheis

    Yes and in the plugin.yml
     
  8. Offline

    SnipsRevival

    evantheis Can you post your main class just in case? Also, you want to be using args[0] in your commands not args[1] because arrays start at index 0. And on that note, check if(args.length == 1) before trying to use args[0] otherwise you would be getting an ArrayIndexOutOfBoundsException if your command did work.
     
  9. Offline

    evantheis

    I did that and still nothing working at all but here
    Code:java
    1. package com.EndlessWar.NightVision;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.plugin.java.JavaPlugin;
    6.  
    7.  
    8.  
    9. public class Main extends JavaPlugin{
    10.  
    11.  
    12.  
    13.  
    14.  
    15. @Override
    16. public void onEnable() {
    17. getCommand("NightVision").setExecutor(new NightVision());
    18. getCommand("AllPotions").setExecutor(new AllPotions());
    19. getCommand("DPPHelp").setExecutor(new DPPHelp());
    20. getCommand("Events").setExecutor(new Events());
    21.  
    22. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    23. public void run() {
    24. Bukkit.getServer().broadcastMessage(ChatColor.RED + "Want an event? Speak up and ask!");
    25. }
    26. }, 1200, 24000);
    27. }
    28.  
    29. public void onDisable() {
    30. getLogger().info("Disabled DonorPerksPlus");
    31.  
    32. }
    33. }
    34.  
     
  10. Offline

    SnipsRevival

    evantheis You have getCommand("Events") but your cmd.getName().equalsIgnoreCase("Event"). Notice the additional "s" in the former.
     
  11. Offline

    evantheis

    I found out what happen thanks a ton. I didn't know you have to register each command.

    Oh and the arguments don't work. They like don't even recognize what's going on with them?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  12. Offline

    SnipsRevival

  13. Offline

    Chinwe

    Shouldn't you be using args[0] as opposed to args[1] if you want /event dropparty ?
     
  14. Offline

    SnipsRevival

    He told me he already changed that.
     
  15. Offline

    evantheis

    SnipsRevival No not any errors I have it when you do /event it say wrong usage do /events and it'll list all the events. What's going on? Events won't go at all :/ chinwe
     
Thread Status:
Not open for further replies.

Share This Page