-
-
Notifications
You must be signed in to change notification settings - Fork 294
/
EquipmentEditor.java
66 lines (54 loc) · 2.07 KB
/
EquipmentEditor.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
package net.citizensnpcs.editor;
import java.util.Map;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Result;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import com.google.common.collect.Maps;
public class EquipmentEditor extends Editor {
private final NPC npc;
private final Player player;
public EquipmentEditor(Player player, NPC npc) {
this.player = player;
this.npc = npc;
}
@Override
public void begin() {
Messaging.sendTr(player, Messages.EQUIPMENT_EDITOR_BEGIN);
}
@Override
public void end() {
Messaging.sendTr(player, Messages.EQUIPMENT_EDITOR_END);
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() == Action.RIGHT_CLICK_AIR && Editor.hasEditor(event.getPlayer())) {
event.setUseItemInHand(Result.DENY);
}
}
@EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (!npc.isSpawned() || !event.getPlayer().equals(player)
|| !npc.equals(CitizensAPI.getNPCRegistry().getNPC(event.getRightClicked())))
return;
Equipper equipper = EQUIPPERS.get(npc.getEntity().getType());
if (equipper == null)
equipper = new GenericEquipper();
equipper.equip(event.getPlayer(), npc);
event.setCancelled(true);
}
private static final Map<EntityType, Equipper> EQUIPPERS = Maps.newEnumMap(EntityType.class);
static {
EQUIPPERS.put(EntityType.PIG, new PigEquipper());
EQUIPPERS.put(EntityType.SHEEP, new SheepEquipper());
EQUIPPERS.put(EntityType.ENDERMAN, new EndermanEquipper());
EQUIPPERS.put(EntityType.HORSE, new HorseEquipper());
}
}