Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. package me.fan.example;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.command.Command;
  5. import org.bukkit.command.CommandSender;
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.event.Listener;
  8. import org.bukkit.plugin.PluginManager;
  9. import org.bukkit.plugin.java.JavaPlugin;
  10.  
  11. public class Main extends JavaPlugin implements Listener {
  12.  
  13. public void onEnable() {
  14. /*
  15. * Register all of the events in the main class.
  16. */
  17. PluginManager pm = Bukkit.getServer().getPluginManager();
  18. pm.registerEvents(this, this);
  19. }
  20.  
  21. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  22.  
  23. /*
  24. * Checking the sender of the command is an actual player and not
  25. * console!
  26. */
  27. if (cmd.getName().equalsIgnoreCase("warn") && sender instanceof Player) {
  28. /*
  29. * Checking if the player has the permission to execute the command.
  30. */
  31. if (sender.hasPermission("<PLUGINNAME>.permission")) {
  32. /*
  33. * Checking if there are NO arguments so only /warn.
  34. */
  35. if (args.length == 0) {
  36. sender.sendMessage("Syntax: /warn <player>");
  37. return true;
  38. }
  39. /*
  40. * Setting the reason, so every different argument goes into one
  41. * string.
  42. */
  43. String reason = "";
  44. for (int i = 0; i > args.length; i++) {
  45. reason += args[i] = " ";
  46. }
  47. /*
  48. * Setting a variable for the target player.
  49. */
  50. Player target = Bukkit.getServer().getPlayer(args[0]);
  51. /*
  52. * Checking if the target is online, if not code down below.
  53. */
  54. if (target == null) {
  55. sender.sendMessage("Player " + args[0] + " is not online!");
  56. return true;
  57. }
  58. target.kickPlayer("This is an example warn plugin!" + "\n" + "Reason: " + reason);
  59. return true;
  60.  
  61. }
  62. /*
  63. * If player doesn't have the permission
  64. */
  65. else {
  66. sender.sendMessage("no permission");
  67. return true;
  68. }
  69. }
  70. /*
  71. * If the sender is the console.
  72. */
  73. else {
  74. sender.sendMessage("Only players can execute this command! :(");
  75. }
  76.  
  77. return true;
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement