summaryrefslogtreecommitdiffstats
path: root/Essentials/src/com/earth2me/essentials/commands/Commandunban.java
blob: b4cb70bf5e9619ecc8154dc1a321b7d3eb833cac (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
package com.earth2me.essentials.commands;

import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.Console;
import static com.earth2me.essentials.I18n.tl;
import com.earth2me.essentials.User;
import java.util.logging.Level;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;


public class Commandunban extends EssentialsCommand
{
	public Commandunban()
	{
		super("unban");
	}

	@Override
	public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception
	{
		if (args.length < 1)
		{
			throw new NotEnoughArgumentsException();
		}
		String name;
		try
		{
			final User user = getPlayer(server, args, 0, true, true);
			name = user.getName();
			ess.getServer().getBanList(BanList.Type.NAME).pardon(name);
		}
		catch (NoSuchFieldException e)
		{
			final OfflinePlayer player = server.getOfflinePlayer(args[0]);
			name = player.getName();
			if (!player.isBanned())
			{
				throw new Exception(tl("playerNotFound"), e);
			}
			ess.getServer().getBanList(BanList.Type.NAME).pardon(name);
		}

		final String senderName = sender.isPlayer() ? sender.getPlayer().getDisplayName() : Console.NAME;
		server.getLogger().log(Level.INFO, tl("playerUnbanned", senderName, name));

		ess.broadcastMessage("essentials.ban.notify", tl("playerUnbanned", senderName, name));
	}
}