From 4e5348ce4500b44595736c711c1c7f29f7efa5a3 Mon Sep 17 00:00:00 2001 From: fullwall Date: Fri, 12 Sep 2014 21:40:11 +0800 Subject: [PATCH] Fix some reported issues --- src/main/java/net/citizensnpcs/PaymentListener.java | 5 ++--- .../java/net/citizensnpcs/commands/NPCCommands.java | 12 +++++++----- .../net/citizensnpcs/npc/entity/EntityHumanNPC.java | 7 ++++--- .../java/net/citizensnpcs/util/PlayerAnimation.java | 5 +++++ 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/citizensnpcs/PaymentListener.java b/src/main/java/net/citizensnpcs/PaymentListener.java index 4c3b35a46..d237dabb9 100644 --- a/src/main/java/net/citizensnpcs/PaymentListener.java +++ b/src/main/java/net/citizensnpcs/PaymentListener.java @@ -22,12 +22,11 @@ public class PaymentListener implements Listener { @EventHandler(ignoreCancelled = true) public void onPlayerCreateNPC(PlayerCreateNPCEvent event) { - String name = event.getCreator().getName(); - boolean hasAccount = provider.hasAccount(name); + boolean hasAccount = provider.hasAccount(event.getCreator()); if (!hasAccount || event.getCreator().hasPermission("citizens.npc.ignore-cost")) return; double cost = Setting.NPC_COST.asDouble(); - EconomyResponse response = provider.withdrawPlayer(name, cost); + EconomyResponse response = provider.withdrawPlayer(event.getCreator(), cost); if (!response.transactionSuccess()) { event.setCancelled(true); event.setCancelReason(response.errorMessage); diff --git a/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/src/main/java/net/citizensnpcs/commands/NPCCommands.java index 473d8c206..33063ec5c 100644 --- a/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -267,7 +267,7 @@ public class NPCCommands { } CommandSenderCreateNPCEvent event = sender instanceof Player ? new PlayerCreateNPCEvent((Player) sender, copy) - : new CommandSenderCreateNPCEvent(sender, copy); + : new CommandSenderCreateNPCEvent(sender, copy); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { event.getNPC().destroy(); @@ -343,7 +343,7 @@ public class NPCCommands { spawnLoc = args.getSenderLocation(); } CommandSenderCreateNPCEvent event = sender instanceof Player ? new PlayerCreateNPCEvent((Player) sender, npc) - : new CommandSenderCreateNPCEvent(sender, npc); + : new CommandSenderCreateNPCEvent(sender, npc); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { npc.destroy(); @@ -915,13 +915,15 @@ public class NPCCommands { min = 1, max = 1, permission = "citizens.npc.pathfindingoptions") - public void pathfindingOptions(CommandContext args, CommandSender sender, NPC npc) { + public void pathfindingOptions(CommandContext args, CommandSender sender, NPC npc) throws CommandException { if (args.hasValueFlag("avoid-water") || args.hasValueFlag("aw")) { String raw = args.getFlag("avoid-water", args.getFlag("aw")); boolean avoid = Boolean.parseBoolean(raw); npc.getNavigator().getDefaultParameters().avoidWater(avoid); Messaging.sendTr(sender, avoid ? Messages.PATHFINDING_OPTIONS_AVOID_WATER_SET : Messages.PATHFINDING_OPTIONS_AVOID_WATER_UNSET, npc.getName()); + } else { + throw new CommandException(); } } @@ -1018,7 +1020,7 @@ public class NPCCommands { @Requirements(selected = true, ownership = true, types = { EntityType.CREEPER }) public void power(CommandContext args, CommandSender sender, NPC npc) { Messaging - .sendTr(sender, npc.getTrait(Powered.class).toggle() ? Messages.POWERED_SET : Messages.POWERED_STOPPED); + .sendTr(sender, npc.getTrait(Powered.class).toggle() ? Messages.POWERED_SET : Messages.POWERED_STOPPED); } @Command( @@ -1041,7 +1043,7 @@ public class NPCCommands { } @Command(aliases = { "npc" }, usage = "remove|rem (all|id|name)", desc = "Remove a NPC", modifiers = { "remove", - "rem" }, min = 1, max = 2) + "rem" }, min = 1, max = 2) @Requirements public void remove(final CommandContext args, final CommandSender sender, NPC npc) throws CommandException { if (args.argsLength() == 2) { diff --git a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java index 3552dbad5..23f4eec93 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java @@ -31,7 +31,6 @@ import net.minecraft.server.v1_7_R4.NetworkManager; import net.minecraft.server.v1_7_R4.Packet; import net.minecraft.server.v1_7_R4.PacketPlayOutEntityEquipment; import net.minecraft.server.v1_7_R4.PacketPlayOutEntityHeadRotation; -import net.minecraft.server.v1_7_R4.PacketPlayOutPlayerInfo; import net.minecraft.server.v1_7_R4.PlayerInteractManager; import net.minecraft.server.v1_7_R4.WorldServer; import net.minecraft.util.com.mojang.authlib.GameProfile; @@ -274,8 +273,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder { int useListName = removeFromPlayerList ? 0 : 1; if (useListName != this.useListName || this.useListName == -1) { this.useListName = useListName; - //packets[5] = new PacketPlayOutPlayerInfo(getBukkitEntity().getPlayerListName(), !removeFromPlayerList, - // removeFromPlayerList ? 9999 : ping); + // packets[5] = new + // PacketPlayOutPlayerInfo(getBukkitEntity().getPlayerListName(), + // !removeFromPlayerList, + // removeFromPlayerList ? 9999 : ping); } NMS.sendPacketsNearby(getBukkitEntity(), current, packets); } diff --git a/src/main/java/net/citizensnpcs/util/PlayerAnimation.java b/src/main/java/net/citizensnpcs/util/PlayerAnimation.java index c42e1d746..4ce738884 100644 --- a/src/main/java/net/citizensnpcs/util/PlayerAnimation.java +++ b/src/main/java/net/citizensnpcs/util/PlayerAnimation.java @@ -3,6 +3,7 @@ package net.citizensnpcs.util; import java.util.Arrays; import net.citizensnpcs.api.CitizensAPI; +import net.citizensnpcs.npc.ai.NPCHolder; import net.minecraft.server.v1_7_R4.EntityPlayer; import net.minecraft.server.v1_7_R4.Packet; import net.minecraft.server.v1_7_R4.PacketPlayOutAnimation; @@ -58,6 +59,10 @@ public enum PlayerAnimation { cancel(); return; } + if (player instanceof NPCHolder && !((NPCHolder) player).getNPC().isSpawned()) { + cancel(); + return; + } if (player.passenger != player) { player.mount(player); }