Solved Commands in external Class

Discussion in 'Plugin Development' started by L33m4n123, Sep 17, 2013.

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

    L33m4n123

    Hey!

    I am currently testing with getting commands in different classes so I get some structure in it and I can easiler find stuff within the code again and fix/change/add stuff

    This is my Code:

    -CommandCP.java-
    Show Spoiler
    Code:java
    1. package com.github.l33m4n123.chunkProtection.Commands;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandExecutor;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. import com.github.l33m4n123.chunkProtection.SimpleConfig.ConfigManager;
    11.  
    12. public class CommandCP implements CommandExecutor {
    13.  
    14. JavaPlugin plugin;
    15. private ConfigManager configManager = new ConfigManager(plugin);
    16.  
    17. public CommandCP(JavaPlugin pPlugin) {
    18. this.plugin = pPlugin;
    19. }
    20.  
    21. public boolean onCommand(CommandSender sender, Command cmd, String label,
    22. String[] args) {
    23. if (cmd.getName().equalsIgnoreCase("cp") && sender instanceof Player) {
    24. System.out.println(args.length);
    25. if (args.length == 0) {
    26. // Get the Plugin Version + Link to Wiki
    27. Player player = (Player) sender;
    28. player.sendMessage("test");
    29.  
    30. return true;
    31. } else if (args.length == 1) {
    32. if (args[0].equalsIgnoreCase("bypass")
    33. && sender.hasPermission("chunkprotection.bypass")) {
    34.  
    35. // bypass the Chunk Protection
    36.  
    37. } else if (args[0].equalsIgnoreCase("reload")
    38. && sender.hasPermission("chunkprotection.reload")) {
    39.  
    40. // Reload the configfiles
    41. }
    42. }
    43.  
    44. }
    45. return false;
    46. }
    47.  
    48. }
    49.  


    This is my main Class ChunkProtection.java
    Show Spoiler
    Code:java
    1. package com.github.l33m4n123.chunkProtection;
    2.  
    3. import org.bukkit.Location;
    4. import org.bukkit.World;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.block.Action;
    8. import org.bukkit.event.player.PlayerInteractEvent;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. import com.github.l33m4n123.chunkProtection.Commands.CommandClaim;
    12. import com.github.l33m4n123.chunkProtection.SimpleConfig.ConfigManager;
    13.  
    14. public class ChunkProtection extends JavaPlugin implements Listener {
    15.  
    16. private ConfigManager configManager = new ConfigManager(this);
    17.  
    18. @Override
    19. public void onEnable() {
    20. getServer().getPluginManager().registerEvents(this, this);
    21.  
    22. // Registering the commands
    23. getCommand("cp").setExecutor(new CommandClaim(this));
    24.  
    25. configManager.createConfig();
    26. }
    27.  
    28. @Override
    29. public void onDisable() {
    30. }
    31. }
    32.  


    My issue is following.. If I type /cp it should sent a message to the player with the Text "test" however.. It only prints /cp to the player. What am I doing wrong? I thought at least that this is the way to do it. Any Input is appreciated
     
  2. Offline

    1Rogue

    You're setting the executor of "cp" to CommandClaim, not CommandCP.
     
    L33m4n123 likes this.
  3. Offline

    L33m4n123

    Duh.. Fricking Copy and paste.. Thanks.. lol
     
Thread Status:
Not open for further replies.

Share This Page