From c2cba14fba51cb38df4443c1d5cd5c26949f1971 Mon Sep 17 00:00:00 2001 From: Pepich Date: Thu, 2 Feb 2017 19:18:24 +0100 Subject: [PATCH] Added motd module --- src/com/redstoner/misc/Main.java | 6 ++- src/motd/Motd.java | 82 ++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 src/motd/Motd.java diff --git a/src/com/redstoner/misc/Main.java b/src/com/redstoner/misc/Main.java index 3ab50c1..6d52c3a 100644 --- a/src/com/redstoner/misc/Main.java +++ b/src/com/redstoner/misc/Main.java @@ -16,10 +16,12 @@ import com.redstoner.modules.scriptutils.Scriptutils; import com.redstoner.modules.skullclick.SkullClick; import com.redstoner.modules.warn.Warn; +import motd.Motd; + /** Main class. Duh. * * @author Pepich */ -@Version(major = 1, minor = 2, revision = 2, compatible = -1) +@Version(major = 1, minor = 2, revision = 3, compatible = -1) public class Main extends JavaPlugin { public static JavaPlugin plugin; @@ -47,7 +49,7 @@ public class Main extends JavaPlugin ModuleLoader.addModule(LagChunks.class); // TODO: ModuleLoader.addModule(Mentio.class); // TODO: ModuleLoader.addModule(Misc.class); - // TODO: ModuleLoader.addModule(Motd.class); + ModuleLoader.addModule(Motd.class); // TODO: ModuleLoader.addModule(Nametags.class); // TODO: ModuleLoader.addModule(Pmtoggle.class); // TODO: ModuleLoader.addModule(Punishments.class); // Remove? diff --git a/src/motd/Motd.java b/src/motd/Motd.java new file mode 100644 index 0000000..3c4ba8e --- /dev/null +++ b/src/motd/Motd.java @@ -0,0 +1,82 @@ +package motd; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.event.EventHandler; +import org.bukkit.event.server.ServerListPingEvent; + +import com.nemez.cmdmgr.Command; +import com.redstoner.annotations.AutoRegisterListener; +import com.redstoner.annotations.Version; +import com.redstoner.misc.Utils; +import com.redstoner.modules.Module; + +@AutoRegisterListener +@Version(major = 1, minor = 0, revision = 0, compatible = 1) +public class Motd implements Module +{ + private boolean enabled = false; + private String default_motd, motd; + + @Command(hook = "setmotd") + public boolean setMotd(CommandSender sender, String motd) + { + if (motd.equals("--reset")) + this.motd = default_motd; + else + this.motd = motd; + Utils.sendMessage(sender, null, "The new motd is:\n" + this.motd, '&'); + return true; + } + + @Command(hook = "getmotd") + public boolean getMotd(CommandSender sender) + { + Utils.sendMessage(sender, null, motd, '&'); + return true; + } + + @EventHandler + public void onServerPing(ServerListPingEvent event) + { + event.setMotd(motd); + } + + @Override + public void onEnable() + { + default_motd = Bukkit.getMotd(); + enabled = true; + } + + @Override + public void onDisable() + { + enabled = false; + } + + @Override + public boolean enabled() + { + return enabled; + } + + // @noformat + @Override + public String getCommandString() + { + return "command setmotd {\n" + + " [string:motd...] {\n" + + " help Sets the motd. Use --reset to reset to default;\n" + + " run setmotd motd;\n" + + " }\n" + + "}\n" + + "command getmotd {\n" + + " [empty] {\n" + + " help Returns the motd;\n" + + " run getmotd;\n" + + " }\n" + + "}"; + } + // @format +}