Fix protected NPCs being movable with fishing rods

This commit is contained in:
fullwall 2016-03-08 22:01:26 +08:00
parent 8d079659cf
commit 03c161bde2
3 changed files with 37 additions and 22 deletions

View File

@ -25,6 +25,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
@ -37,8 +38,8 @@ import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.scoreboard.Team;
import com.google.common.base.Predicates;
@ -268,6 +269,16 @@ public class EventListen implements Listener {
Bukkit.getPluginManager().callEvent(new EntityTargetNPCEvent(event, npc));
}
@EventHandler(ignoreCancelled = true)
public void onFishCaught(PlayerFishEvent event) {
if (event.getCaught() == null)
return;
NPC npc = npcRegistry.getNPC(event.getCaught());
if (npc == null)
return;
event.setCancelled(npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true));
}
@EventHandler
public void onMetaDeserialise(CitizensDeserialiseMetaEvent event) {
if (event.getKey().keyExists("skull")) {
@ -381,7 +392,6 @@ public class EventListen implements Listener {
if (npc == null || event.getHand() == EquipmentSlot.OFF_HAND) {
return;
}
Player player = event.getPlayer();
NPCRightClickEvent rightClickEvent = new NPCRightClickEvent(npc, player);
Bukkit.getPluginManager().callEvent(rightClickEvent);

View File

@ -5,8 +5,10 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.SocketAddress;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
@ -607,21 +609,27 @@ public class NMS {
}
}
public static void sendPacket(Player player, Packet packet) {
public static void sendPacket(Player player, Packet<?> packet) {
if (packet == null)
return;
((EntityPlayer) NMS.getHandle(player)).playerConnection.sendPacket(packet);
}
public static void sendPacketNearby(Player from, Location location, Packet packet) {
NMS.sendPacketsNearby(from, location, Arrays.asList(packet), 64);
public static void sendPacketNearby(Player from, Location location, Packet<?> packet) {
NMS.sendPacketNearby(from, location, packet, 64);
}
public static void sendPacketsNearby(Player from, Location location, Collection<Packet> packets) {
public static void sendPacketNearby(Player from, Location location, Packet<?> packet, double radius) {
List<Packet<?>> list = new ArrayList<Packet<?>>();
list.add(packet);
NMS.sendPacketsNearby(from, location, list, radius);
}
public static void sendPacketsNearby(Player from, Location location, Collection<Packet<?>> packets) {
NMS.sendPacketsNearby(from, location, packets, 64);
}
public static void sendPacketsNearby(Player from, Location location, Collection<Packet> packets, double radius) {
public static void sendPacketsNearby(Player from, Location location, Collection<Packet<?>> packets, double radius) {
radius *= radius;
final org.bukkit.World world = location.getWorld();
for (Player ply : Bukkit.getServer().getOnlinePlayers()) {
@ -631,13 +639,13 @@ public class NMS {
if (location.distanceSquared(ply.getLocation(PACKET_CACHE_LOCATION)) > radius) {
continue;
}
for (Packet packet : packets) {
for (Packet<?> packet : packets) {
sendPacket(ply, packet);
}
}
}
public static void sendPacketsNearby(Player from, Location location, Packet... packets) {
public static void sendPacketsNearby(Player from, Location location, Packet<?>... packets) {
NMS.sendPacketsNearby(from, location, Arrays.asList(packets), 64);
}
@ -676,12 +684,12 @@ public class NMS {
new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entity));
}
public static void sendToOnline(Packet... packets) {
public static void sendToOnline(Packet<?>... packets) {
Validate.notNull(packets, "packets cannot be null");
for (Player player : Bukkit.getOnlinePlayers()) {
if (player == null || !player.isOnline())
continue;
for (Packet packet : packets) {
for (Packet<?> packet : packets) {
sendPacket(player, packet);
}
}

View File

@ -1,7 +1,5 @@
package net.citizensnpcs.util;
import java.util.Arrays;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
@ -23,18 +21,18 @@ public enum PlayerAnimation {
playDefaultAnimation(player, radius, 0);
}
},
ARM_SWING_OFFHAND {
@Override
protected void playAnimation(EntityPlayer player, int radius) {
playDefaultAnimation(player, radius, 3);
}
},
CRIT {
@Override
protected void playAnimation(EntityPlayer player, int radius) {
playDefaultAnimation(player, radius, 4);
}
},
ARM_SWING_OFFHAND {
@Override
protected void playAnimation(EntityPlayer player, int radius) {
playDefaultAnimation(player, radius, 3);
}
},
EAT_FOOD {
@Override
protected void playAnimation(EntityPlayer player, int radius) {
@ -149,8 +147,7 @@ public enum PlayerAnimation {
sendPacketNearby(packet, player, radius);
}
protected void sendPacketNearby(Packet packet, EntityPlayer player, int radius) {
NMS.sendPacketsNearby(player.getBukkitEntity(), player.getBukkitEntity().getLocation(), Arrays.asList(packet),
radius);
protected void sendPacketNearby(Packet<?> packet, EntityPlayer player, int radius) {
NMS.sendPacketNearby(player.getBukkitEntity(), player.getBukkitEntity().getLocation(), packet, radius);
}
}