summaryrefslogtreecommitdiffstats
path: root/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java
blob: 1fd974691a4e3c64f6444637e183f7f524215c56 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.earth2me.essentials.commands;

import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import java.util.List;
import org.bukkit.ChatColor;


public class Commandclearinventory extends EssentialsCommand
{
	public Commandclearinventory()
	{
		super("clearinventory");
	}

	@Override
	public void run(Server server, User user, String commandLabel, String[] args) throws Exception
	{
		if (args.length > 0 && user.isAuthorized("essentials.clearinventory.others"))
		{
			if (args[0].length() >= 3)
			{
				List<Player> online = server.matchPlayer(args[0]);

				if (!online.isEmpty())
				{
					charge(user);
					for (Player p : online)
					{
						p.getInventory().clear();
						user.sendMessage(Util.format("inventoryClearedOthers", p.getDisplayName()));
					}
					return;
				}
				throw new Exception(Util.i18n("playerNotFound"));
			}
			else
			{
				Player p = server.getPlayer(args[0]);
				if (p != null)
				{
					charge(user);
					p.getInventory().clear();
					user.sendMessage(Util.format("inventoryClearedOthers", p.getDisplayName()));
				}
				else
				{
					throw new Exception(Util.i18n("playerNotFound"));
				}
			}
		}
		else
		{
			charge(user);
			user.getInventory().clear();
			user.sendMessage(Util.i18n("inventoryCleared"));
		}
	}

	@Override
	protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
	{
		if (args.length < 1)
		{
			throw new NotEnoughArgumentsException();
		}

		if (args[0].length() >= 3)
		{
			List<Player> online = server.matchPlayer(args[0]);

			if (!online.isEmpty())
			{
				for (Player p : online)
				{
					p.getInventory().clear();
					sender.sendMessage(Util.format("inventoryClearedOthers", p.getDisplayName()));
				}
				return;
			}
			throw new Exception(Util.i18n("playerNotFound"));
		}
		else
		{
			Player u = server.getPlayer(args[0]);
			if (u != null)
			{
				u.getInventory().clear();
				sender.sendMessage(Util.format("inventoryClearedOthers", u.getDisplayName()));
			}
			else
			{
				throw new Exception(Util.i18n("playerNotFound"));
			}
		}
	}
}