Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. package me.funnycube.testplugin;
  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. public class Main extends JavaPlugin implements CommandExecutor {
  11.  
  12. //so step 1
  13. //onEnable must be overriden
  14. //this is called an annotation
  15. //tells the compiler that we need to override the method in the JavaPlugin class
  16. //since this class extends JavaPlugin
  17. //means that is "extends" it or makes it more I guess
  18. //only 1 class will extend javaplugin and that is the class that has the onEnable and onDisable methods
  19.  
  20. private String commandMessage = "&bYou typed a command";
  21.  
  22. private int amountOfTimesCommandWasUsed = 0;
  23.  
  24. private char colorcode = '&';
  25.  
  26. @Override
  27. public void onEnable() {
  28. //you usually don't have to do this as onEnable already prints a message saying
  29. // <plugin> enabled
  30. //but what the hell, lets say it
  31.  
  32. //now since we have a command below. We need to tell the server to register our command
  33. //we only need to do this 1 time, and only onEnable
  34. getCommand("test").setExecutor(this);
  35. //you see how this code didn't throw an error when all we typed was getCommand
  36.  
  37. getLogger().info("Enabled funnycubes sick plugin!");
  38. }
  39.  
  40. @Override
  41. public void onDisable() {
  42. getLogger().info("OMG Funnycubes plugin has been disabled");
  43. }
  44.  
  45. //commandexecutor is an interface
  46. //it also needs to be overriden
  47. @Override
  48. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  49.  
  50. if (!(sender instanceof Player)) {
  51. sender.sendMessage("You are not a player");
  52. return true;
  53. }
  54.  
  55. Player player = (Player) sender;
  56.  
  57. player.sendMessage(ChatColor.translateAlternateColorCodes(colorcode, commandMessage));
  58.  
  59. amountOfTimesCommandWasUsed = amountOfTimesCommandWasUsed+1;
  60.  
  61. player.sendMessage("Command was used "+amountOfTimesCommandWasUsed+" times");
  62.  
  63. return true;
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement