summaryrefslogtreecommitdiff
path: root/src/main/java/com/redstoner/modules/motd/Motd.java
blob: 9495b617d04748b3078a1d69c3d34e8dfea6cbdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.redstoner.modules.motd;

import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.ServerListPingEvent;

import com.nemez.cmdmgr.Command;
import com.nemez.cmdmgr.Command.AsyncType;
import com.redstoner.annotations.AutoRegisterListener;
import com.redstoner.annotations.Commands;
import com.redstoner.annotations.Version;
import com.redstoner.misc.CommandHolderType;
import com.redstoner.modules.Module;

@Commands(CommandHolderType.File)
@AutoRegisterListener
@Version(major = 5, minor = 0, revision = 0, compatible = 4)
public class Motd implements Module, Listener
{
	private String default_motd, motd;
	
	@Command(hook = "setmotd", async = AsyncType.ALWAYS)
	public boolean setMotd(CommandSender sender, String motd)
	{
		if (motd.equals("--reset"))
			this.motd = default_motd;
		else
			this.motd = motd;
		getLogger().message(sender, "The new motd is:\n" + this.motd);
		return true;
	}
	
	@Command(hook = "getmotd", async = AsyncType.ALWAYS)
	public boolean getMotd(CommandSender sender)
	{
		getLogger().message(sender, motd == null ? default_motd : motd);
		return true;
	}
	
	@EventHandler
	public void onServerPing(ServerListPingEvent event)
	{
		event.setMotd(motd);
	}
	
	@Override
	public boolean onEnable()
	{
		default_motd = Bukkit.getMotd();
		if (default_motd == null)
		{
			default_motd = "§6Sample text\n§4FIX YOUR SERVER!";
		}
		motd = default_motd;
		return true;
	}
}