Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. package me.leontss1.an;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.command.Command;
  6. import org.bukkit.command.CommandSender;
  7. import org.bukkit.plugin.java.JavaPlugin;
  8.  
  9. public class Main extends JavaPlugin {
  10.  
  11. // A simple onEnable() logger! You can also use System.out.
  12. public void onEnable() {
  13. Bukkit.getServer().getLogger().info("Announcements> Enabled! Thanks for using.");
  14. }
  15.  
  16. // My command setup without a command Executor
  17. public boolean onCommand(CommandSender sender, Command command, String cmd, String[] args) {
  18. if (cmd.equalsIgnoreCase("announce")) {
  19. // Checking for a permission
  20. if (!sender.hasPermission("announce.use")) {
  21. sender.sendMessage(ChatColor.DARK_RED + "You do not have access to that command!");
  22. // Checking of the sender specified a message instead of }else you can use args.length == 1
  23. } else if (args.length == 0) {
  24. sender.sendMessage(ChatColor.RED + "Please specify a message");
  25. } else {
  26. // Sending a message to the server
  27. getServer().broadcastMessage(ChatColor.AQUA + "Announcement> " + ChatColor.RED + message(args));
  28. }
  29.  
  30. }
  31. return false;
  32. }
  33. // A Simple Builder so the message wont only be 4 leters long.
  34. public String message(String[] args) {
  35. StringBuilder b = new StringBuilder();
  36. for (int i = 0; i < args.length; i++) {
  37. b.append(args[i]);
  38. b.append(" ");
  39. }
  40. return b.toString().trim();
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement