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

import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import java.util.Arrays;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;


public class Commandinvsee extends EssentialsCommand
{
	public Commandinvsee()
	{
		super("invsee");
	}

	@Override
	protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
	{

		if (args.length < 1 && user.getSavedInventory() == null)
		{
			throw new NotEnoughArgumentsException();
		}
		User invUser = user;
		if (args.length == 1)
		{
			invUser = getPlayer(server, args, 0);
		}
		if (invUser == user && user.getSavedInventory() != null)
		{
			invUser.getInventory().setContents(user.getSavedInventory());
			user.setSavedInventory(null);
			user.sendMessage(Util.i18n("invRestored"));
			throw new NoChargeException();
		}

		if (user.getSavedInventory() == null)
		{
			user.setSavedInventory(user.getInventory().getContents());
		}
		ItemStack[] invUserStack = invUser.getInventory().getContents();
		int userStackLength = user.getInventory().getContents().length;
		if (invUserStack.length < userStackLength) {
			invUserStack = Arrays.copyOf(invUserStack, userStackLength);
		}
		if (invUserStack.length > userStackLength) {
			throw new Exception(Util.i18n("invBigger"));
		}
		user.getInventory().setContents(invUserStack);
		user.sendMessage(Util.format("invSee", invUser.getDisplayName()));
		user.sendMessage(Util.i18n("invSeeHelp"));
		throw new NoChargeException();
	}
}