CreepersGamingMc

Untitled

Jun 9th, 2017
40
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.CreepersGamingMc.motd;
  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.entity.Player;
  8. import org.bukkit.event.EventHandler;
  9. import org.bukkit.event.Listener;
  10. import org.bukkit.event.player.PlayerJoinEvent;
  11. import org.bukkit.event.server.ServerListPingEvent;
  12. import org.bukkit.plugin.java.JavaPlugin;
  13.  
  14. public class main extends JavaPlugin implements Listener {
  15.  
  16. @EventHandler
  17. public void onPlayerJoin(PlayerJoinEvent e) {
  18. Player p = e.getPlayer();
  19. p.sendMessage(ChatColor.GREEN + getConfig().getString("message"));
  20. }
  21. @EventHandler
  22. public void ping(ServerListPingEvent e) {
  23. e.setMotd(getConfig().getString("message").replaceAll("%newline%", "\\n"));
  24. }
  25. public void onEnable() {
  26. getConfig().options().copyDefaults(true);
  27. Bukkit.getServer().getPluginManager().registerEvents(this, this);
  28. }
  29. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
  30. if (cmd.getName().equalsIgnoreCase("motd")) {
  31. sender.sendMessage(getConfig().getString("message"));
  32. return true;
  33. }
  34.  
  35. if (cmd.getName().equalsIgnoreCase("setmotd")) {
  36. if (!sender.hasPermission("creepermotd.set")) {
  37. sender.sendMessage(ChatColor.DARK_RED + "You are not permitted to set the motd!");
  38. return true; }
  39. if (args.length == 0) {
  40. sender.sendMessage(ChatColor.RED + "Please specify a MOTD");
  41. return true;
  42. }
  43. StringBuilder str = new StringBuilder();
  44. for (int i = 0; i < args.length; i++ ) {
  45. str.append(args[i] + " ");
  46. }
  47. String motd = str.toString();
  48. getConfig().set("message", motd);
  49. saveConfig();
  50. sender.sendMessage(ChatColor.GREEN + "Motd set to: " + motd);
  51. return true;
  52. }
  53. return true;
  54. }
  55. }
RAW Paste Data