forked from ChestShop-authors/ChestShop-3
-
Notifications
You must be signed in to change notification settings - Fork 2
/
RemoveAccessor.java
68 lines (57 loc) · 2.28 KB
/
RemoveAccessor.java
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
package com.Acrobot.ChestShop.Commands;
import static com.Acrobot.ChestShop.Permission.ADMIN;
import com.Acrobot.ChestShop.Configuration.Messages;
import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import java.util.UUID;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.RayTraceResult;
public class RemoveAccessor implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
return false;
}
if (!(Permission.has(sender, Permission.SHOP_CREATION_BUY) || Permission.has(sender, Permission.SHOP_CREATION_SELL))) {
sender.sendMessage(Messages.prefix(Messages.ACCESS_DENIED));
return true;
}
if (args.length < 1) {
return false;
}
Player player = (Player) sender;
RayTraceResult result = player.rayTraceBlocks(8);
Block signBlock = null;
if (result != null) {
signBlock = result.getHitBlock();
}
if (signBlock == null || !ChestShopSign.isChestShop(signBlock)) {
sender.sendMessage(Messages.MUST_LOOK_AT_SHOP_SIGN);
return true;
}
Sign sign = (Sign) signBlock.getState();
if (!ChestShopSign.isOwner(player, sign) && !Permission.has(player, ADMIN)) {
sender.sendMessage(Messages.ACCESS_DENIED);
return true;
}
String playerName = args[0];
UUID accessorToRemove = NameManager.getUUIDFor(playerName);
if (accessorToRemove == null) {
sender.sendMessage(Messages.prefix(Messages.PLAYER_NOT_FOUND));
return true;
}
if (!ChestShopSign.isAccessor(accessorToRemove, sign)) {
sender.sendMessage(Messages.prefix(Messages.ACCESSOR_NOT_ADDED));
return true;
}
ChestShopSign.removeAccessor(accessorToRemove, sign);
sender.sendMessage(Messages.prefix(Messages.ACCESSOR_REMOVED));
return true;
}
}