mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-09-09 22:38:04 +02:00
Add 'offhand' for setting the NPC's offhand item
This commit is contained in:
parent
2e41832873
commit
4bb29894bd
@ -44,25 +44,43 @@ public class EquipmentEditor extends Editor {
|
|||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onPlayerChat(final AsyncPlayerChatEvent event) {
|
public void onPlayerChat(final AsyncPlayerChatEvent event) {
|
||||||
if (!event.getMessage().equals("helmet")
|
if (event.getMessage().equals("helmet")
|
||||||
|| !event.getPlayer().hasPermission("citizens.npc.edit.equip.any-helmet"))
|
&& !event.getPlayer().hasPermission("citizens.npc.edit.equip.any-helmet")) {
|
||||||
return;
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!event.getPlayer().isValid())
|
if (!event.getPlayer().isValid())
|
||||||
return;
|
return;
|
||||||
ItemStack hand = event.getPlayer().getItemInHand();
|
ItemStack hand = event.getPlayer().getInventory().getItemInMainHand();
|
||||||
if (hand.getType() == Material.AIR || hand.getAmount() <= 0) {
|
if (hand.getType() == Material.AIR || hand.getAmount() <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
npc.getTrait(Equipment.class).set(EquipmentSlot.HELMET,
|
npc.getTrait(Equipment.class).set(EquipmentSlot.HELMET,
|
||||||
new ItemStack(event.getPlayer().getItemInHand().getType(), 1));
|
new ItemStack(event.getPlayer().getInventory().getItemInMainHand().getType(), 1));
|
||||||
hand.setAmount(hand.getAmount() - 1);
|
hand.setAmount(hand.getAmount() - 1);
|
||||||
event.getPlayer().setItemInHand(hand);
|
event.getPlayer().getInventory().setItemInMainHand(hand);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (event.getMessage().equals("offhand")
|
||||||
|
&& !event.getPlayer().hasPermission("citizens.npc.edit.equip.offhand")) {
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (!event.getPlayer().isValid())
|
||||||
|
return;
|
||||||
|
ItemStack hand = event.getPlayer().getInventory().getItemInMainHand();
|
||||||
|
if (hand.getType() == Material.AIR || hand.getAmount() <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
npc.getTrait(Equipment.class).set(EquipmentSlot.OFF_HAND,
|
||||||
|
new ItemStack(event.getPlayer().getInventory().getItemInMainHand().getType(), 1));
|
||||||
|
hand.setAmount(hand.getAmount() - 1);
|
||||||
|
event.getPlayer().getInventory().setItemInMainHand(hand);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
|
Loading…
Reference in New Issue
Block a user