blob: 28437e83582b9a2d12d2c6399950c5412df99f01 (
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
|
package net.ess3.commands;
import static net.ess3.I18n._;
import net.ess3.api.IUser;
import net.ess3.permissions.Permissions;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
public class Commandbook extends EssentialsCommand
{
//TODO: Translate this
@Override
public void run( final IUser user, final String commandLabel, final String[] args) throws Exception
{
final Player player = user.getPlayer();
final ItemStack item = player.getItemInHand();
if (item.getType() == Material.WRITTEN_BOOK)
{
BookMeta bmeta = (BookMeta)item.getItemMeta();
if (args.length > 1 && args[0].equalsIgnoreCase("author"))
{
if (Permissions.BOOK_AUTHOR.isAuthorized(user) && (isAuthor(bmeta, player.getName()) || Permissions.BOOK_OTHERS.isAuthorized(user)))
{
bmeta.setAuthor(args[1]);
item.setItemMeta(bmeta);
user.sendMessage(_("bookAuthorSet", getFinalArg(args, 1)));
}
else
{
throw new Exception(_("denyChangeAuthor"));
}
}
else if (args.length > 1 && args[0].equalsIgnoreCase("title"))
{
if (Permissions.BOOK_TITLE.isAuthorized(user) && (isAuthor(bmeta, player.getName()) || Permissions.BOOK_OTHERS.isAuthorized(user)))
{
bmeta.setTitle(args[1]);
item.setItemMeta(bmeta);
user.sendMessage(_("bookTitleSet", getFinalArg(args, 1)));
}
else
{
throw new Exception(_("denyChangeTitle"));
}
}
else
{
if (isAuthor(bmeta, player.getName()) || Permissions.BOOK_OTHERS.isAuthorized(user))
{
ItemStack newItem = new ItemStack(Material.BOOK_AND_QUILL, item.getAmount());
newItem.setItemMeta(bmeta);
user.getPlayer().setItemInHand(newItem);
user.sendMessage(_("editBookContents"));
}
else
{
throw new Exception(_("denyBookEdit"));
}
}
}
else if (item.getType() == Material.BOOK_AND_QUILL)
{
BookMeta bmeta = (BookMeta)item.getItemMeta();
if (!Permissions.BOOK_AUTHOR.isAuthorized(user))
{
bmeta.setAuthor(player.getName());
}
ItemStack newItem = new ItemStack(Material.WRITTEN_BOOK, item.getAmount());
newItem.setItemMeta(bmeta);
player.setItemInHand(newItem);
user.sendMessage(_("bookLocked"));
}
else
{
throw new Exception(_("holdBook"));
}
}
private boolean isAuthor(BookMeta bmeta, String player)
{
String author = bmeta.getAuthor();
return author != null && author.equalsIgnoreCase(player);
}
}
|