Fix entity armor stand right click events

This commit is contained in:
fullwall 2016-01-01 13:15:19 +08:00
parent fb2ebc0a31
commit 14081192c3
3 changed files with 30 additions and 20 deletions

View File

@ -2,11 +2,6 @@ package net.citizensnpcs.editor;
import java.util.Map; 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.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event.Result; import org.bukkit.event.Event.Result;
@ -17,6 +12,11 @@ import org.bukkit.event.player.PlayerInteractEvent;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
public class EquipmentEditor extends Editor { public class EquipmentEditor extends Editor {
private final NPC npc; private final NPC npc;
private final Player player; private final Player player;
@ -50,8 +50,9 @@ public class EquipmentEditor extends Editor {
return; return;
Equipper equipper = EQUIPPERS.get(npc.getEntity().getType()); Equipper equipper = EQUIPPERS.get(npc.getEntity().getType());
if (equipper == null) if (equipper == null) {
equipper = new GenericEquipper(); equipper = new GenericEquipper();
}
equipper.equip(event.getPlayer(), npc); equipper.equip(event.getPlayer(), npc);
event.setCancelled(true); event.setCancelled(true);
} }

View File

@ -1,14 +1,14 @@
package net.citizensnpcs.editor; package net.citizensnpcs.editor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.trait.Equipment; import net.citizensnpcs.api.trait.trait.Equipment;
import net.citizensnpcs.api.util.Messaging; import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Messages;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class GenericEquipper implements Equipper { public class GenericEquipper implements Equipper {
@Override @Override
public void equip(Player equipper, NPC toEquip) { public void equip(Player equipper, NPC toEquip) {
@ -67,8 +67,9 @@ public class GenericEquipper implements Equipper {
} }
// Drop any previous equipment on the ground // Drop any previous equipment on the ground
ItemStack equippedItem = trait.get(slot); ItemStack equippedItem = trait.get(slot);
if (equippedItem != null && equippedItem.getType() != Material.AIR) if (equippedItem != null && equippedItem.getType() != Material.AIR) {
equipper.getWorld().dropItemNaturally(toEquip.getEntity().getLocation(), equippedItem); equipper.getWorld().dropItemNaturally(toEquip.getEntity().getLocation(), equippedItem);
}
// Now edit the equipment based on the slot // Now edit the equipment based on the slot
if (type != Material.AIR) { if (type != Material.AIR) {

View File

@ -1,5 +1,14 @@
package net.citizensnpcs.npc.entity.nonliving; package net.citizensnpcs.npc.entity.nonliving;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftArmorStand;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.util.Vector;
import net.citizensnpcs.api.event.NPCPushEvent; import net.citizensnpcs.api.event.NPCPushEvent;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
@ -12,13 +21,6 @@ import net.minecraft.server.v1_8_R3.NBTTagCompound;
import net.minecraft.server.v1_8_R3.Vec3D; import net.minecraft.server.v1_8_R3.Vec3D;
import net.minecraft.server.v1_8_R3.World; import net.minecraft.server.v1_8_R3.World;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftArmorStand;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.entity.ArmorStand;
import org.bukkit.util.Vector;
public class ArmorStandController extends MobEntityController { public class ArmorStandController extends MobEntityController {
public ArmorStandController() { public ArmorStandController() {
super(EntityArmorStandNPC.class); super(EntityArmorStandNPC.class);
@ -56,8 +58,14 @@ public class ArmorStandController extends MobEntityController {
} }
@Override @Override
public boolean a(EntityHuman paramEntityHuman, Vec3D paramVec3D) { public boolean a(EntityHuman entityhuman, Vec3D vec3d) {
return true; if (npc == null) {
return super.a(entityhuman, vec3d);
}
PlayerInteractEntityEvent event = new PlayerInteractEntityEvent((Player) entityhuman.getBukkitEntity(),
getBukkitEntity());
Bukkit.getPluginManager().callEvent(event);
return !event.isCancelled();
} }
@Override @Override