blob: 3d10ae198f9b31c1e268ce9158aec1b6d9f6eaba (
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
|
package com.earth2me.essentials.commands;
import org.bukkit.Server;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public class Commanditem extends EssentialsCommand
{
public Commanditem()
{
super("item");
}
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
final ItemStack stack = ess.getItemDb().get(args[0]);
final String itemname = stack.getType().toString().toLowerCase().replace("_", "");
if (ess.getSettings().permissionBasedItemSpawn()
? (!user.isAuthorized("essentials.itemspawn.item-all")
&& !user.isAuthorized("essentials.itemspawn.item-" + itemname)
&& !user.isAuthorized("essentials.itemspawn.item-" + stack.getTypeId()))
: (!user.isAuthorized("essentials.itemspawn.exempt")
&& !user.canSpawnItem(stack.getTypeId())))
{
throw new Exception(Util.format("cantSpawnItem", itemname));
}
if (args.length > 1 && Integer.parseInt(args[1]) > 0)
{
stack.setAmount(Integer.parseInt(args[1]));
}
if (stack.getType() == Material.AIR)
{
throw new Exception(Util.format("cantSpawnItem", "Air"));
}
final String displayName = stack.getType().toString().toLowerCase().replace('_', ' ');
user.sendMessage(Util.format("itemSpawn", stack.getAmount(), displayName));
user.getInventory().addItem(stack);
user.updateInventory();
}
}
|