Fix guardian update method

This commit is contained in:
fullwall 2015-05-26 19:30:58 +08:00
parent c2416d989e
commit 0fa1dff4d6
64 changed files with 409 additions and 375 deletions

View File

@ -6,6 +6,16 @@ import java.util.Iterator;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import net.citizensnpcs.Settings.Setting; import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.CitizensPlugin; import net.citizensnpcs.api.CitizensPlugin;
@ -51,16 +61,6 @@ import net.citizensnpcs.util.StringHelper;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
public class Citizens extends JavaPlugin implements CitizensPlugin { public class Citizens extends JavaPlugin implements CitizensPlugin {
private final CommandManager commands = new CommandManager(); private final CommandManager commands = new CommandManager();
private boolean compatible; private boolean compatible;
@ -134,8 +134,8 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
Messaging.logTr(Messages.LOADING_SUB_PLUGIN, plugin.getDescription().getFullName()); Messaging.logTr(Messages.LOADING_SUB_PLUGIN, plugin.getDescription().getFullName());
plugin.onLoad(); plugin.onLoad();
} catch (Throwable ex) { } catch (Throwable ex) {
Messaging.severeTr(Messages.ERROR_INITALISING_SUB_PLUGIN, ex.getMessage(), plugin.getDescription() Messaging.severeTr(Messages.ERROR_INITALISING_SUB_PLUGIN, ex.getMessage(),
.getFullName()); plugin.getDescription().getFullName());
ex.printStackTrace(); ex.printStackTrace();
} }
} }

View File

@ -131,8 +131,8 @@ public class EventListen implements Listener {
} }
toRespawn.put(coord, npc); toRespawn.put(coord, npc);
if (Messaging.isDebugging()) { if (Messaging.isDebugging()) {
Messaging Messaging.debug("Despawned id", npc.getId(),
.debug("Despawned id", npc.getId(), "due to chunk unload at [" + coord.x + "," + coord.z + "]"); "due to chunk unload at [" + coord.x + "," + coord.z + "]");
} }
} }
} }
@ -228,8 +228,8 @@ public class EventListen implements Listener {
NPC npc = npcRegistry.getNPC(event.getTarget()); NPC npc = npcRegistry.getNPC(event.getTarget());
if (npc == null) if (npc == null)
return; return;
event.setCancelled(!npc.data().get(NPC.TARGETABLE_METADATA, event.setCancelled(
!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))); !npc.data().get(NPC.TARGETABLE_METADATA, !npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)));
Bukkit.getPluginManager().callEvent(new EntityTargetNPCEvent(event, npc)); Bukkit.getPluginManager().callEvent(new EntityTargetNPCEvent(event, npc));
} }
@ -405,8 +405,8 @@ public class EventListen implements Listener {
boolean success = spawn(npc); boolean success = spawn(npc);
if (!success) { if (!success) {
if (Messaging.isDebugging()) { if (Messaging.isDebugging()) {
Messaging.debug("Couldn't respawn id", npc.getId(), "during chunk event at [" + coord.x + "," Messaging.debug("Couldn't respawn id", npc.getId(),
+ coord.z + "]"); "during chunk event at [" + coord.x + "," + coord.z + "]");
} }
continue; continue;
} }

View File

@ -129,8 +129,7 @@ public class Metrics {
} }
/** /**
* Add a Graph object to BukkitMetrics that represents data for the plugin * Add a Graph object to BukkitMetrics that represents data for the plugin that should be sent to the backend
* that should be sent to the backend
* *
* @param graph * @param graph
* The name of the graph * The name of the graph
@ -144,14 +143,12 @@ public class Metrics {
} }
/** /**
* Construct and create a Graph that can be used to separate specific * Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics
* plotters to their own graphs on the metrics website. Plotters can be * website. Plotters can be added to the graph object returned.
* added to the graph object returned.
* *
* @param name * @param name
* The name of the graph * The name of the graph
* @return Graph object created. Will never return NULL under normal * @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given
* circumstances unless bad parameters are given
*/ */
public Graph createGraph(final String name) { public Graph createGraph(final String name) {
if (name == null) { if (name == null) {
@ -169,8 +166,7 @@ public class Metrics {
} }
/** /**
* Disables metrics for the server by setting "opt-out" to true in the * Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task.
* config file and canceling the metrics task.
* *
* @throws java.io.IOException * @throws java.io.IOException
*/ */
@ -194,8 +190,7 @@ public class Metrics {
} }
/** /**
* Enables metrics for the server by setting "opt-out" to false in the * Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
* config file and starting the metrics task.
* *
* @throws java.io.IOException * @throws java.io.IOException
*/ */
@ -218,8 +213,7 @@ public class Metrics {
} }
/** /**
* Gets the File object of the config file that should be used to store data * Gets the File object of the config file that should be used to store data such as the GUID and opt-out status
* such as the GUID and opt-out status
* *
* @return the File object for the config file * @return the File object for the config file
*/ */
@ -237,8 +231,7 @@ public class Metrics {
} }
/** /**
* Check if mineshafter is present. If it is, we need to bypass it to send * Check if mineshafter is present. If it is, we need to bypass it to send POST requests
* POST requests
* *
* @return true if mineshafter is installed on the server * @return true if mineshafter is installed on the server
*/ */
@ -443,10 +436,9 @@ public class Metrics {
} }
/** /**
* Start measuring statistics. This will immediately create an async * Start measuring statistics. This will immediately create an async repeating task as the plugin and send the
* repeating task as the plugin and send the initial data to the metrics * initial data to the metrics backend, and then after that it will post in increments of PING_INTERVAL * 1200
* backend, and then after that it will post in increments of PING_INTERVAL * ticks.
* * 1200 ticks.
* *
* @return True if statistics measuring is running, otherwise false. * @return True if statistics measuring is running, otherwise false.
*/ */
@ -514,8 +506,8 @@ public class Metrics {
public static class Graph { public static class Graph {
/** /**
* The graph's name, alphanumeric and spaces only :) If it does not * The graph's name, alphanumeric and spaces only :) If it does not comply to the above when submitted, it is
* comply to the above when submitted, it is rejected * rejected
*/ */
private final String name; private final String name;
@ -572,8 +564,7 @@ public class Metrics {
} }
/** /**
* Called when the server owner decides to opt-out of BukkitMetrics * Called when the server owner decides to opt-out of BukkitMetrics while the server is running.
* while the server is running.
*/ */
protected void onOptOut() { protected void onOptOut() {
} }
@ -610,8 +601,7 @@ public class Metrics {
* Construct a plotter with a specific plot name * Construct a plotter with a specific plot name
* *
* @param name * @param name
* the name of the plotter to use, which will show up on the * the name of the plotter to use, which will show up on the website
* website
*/ */
public Plotter(final String name) { public Plotter(final String name) {
this.name = name; this.name = name;
@ -637,11 +627,9 @@ public class Metrics {
} }
/** /**
* Get the current value for the plotted point. Since this function * Get the current value for the plotted point. Since this function defers to an external function it may or may
* defers to an external function it may or may not return immediately * not return immediately thus cannot be guaranteed to be thread friendly or safe. This function can be called
* thus cannot be guaranteed to be thread friendly or safe. This * from any thread so care should be taken when accessing resources that need to be synchronized.
* function can be called from any thread so care should be taken when
* accessing resources that need to be synchronized.
* *
* @return the current value for the point to be plotted. * @return the current value for the point to be plotted.
*/ */

View File

@ -104,10 +104,8 @@ public class NPCCommandSelector extends NumericPrompt {
} }
for (NPC test : npcRegistry) { for (NPC test : npcRegistry) {
if (test.getName().equalsIgnoreCase(name)) { if (test.getName().equalsIgnoreCase(name)) {
if (range > 0 if (range > 0 && test.isSpawned() && !Util.locationWithinRange(args.getSenderLocation(),
&& test.isSpawned() test.getEntity().getLocation(), range))
&& !Util.locationWithinRange(args.getSenderLocation(), test.getEntity().getLocation(),
range))
continue; continue;
possible.add(test); possible.add(test);
} }

View File

@ -227,8 +227,8 @@ public class NPCCommands {
max = 1, max = 1,
flags = "myno") flags = "myno")
public void controllable(CommandContext args, CommandSender sender, NPC npc) throws CommandException { public void controllable(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if ((npc.isSpawned() && !sender.hasPermission("citizens.npc.controllable." if ((npc.isSpawned() && !sender.hasPermission(
+ npc.getEntity().getType().name().toLowerCase().replace("_", ""))) "citizens.npc.controllable." + npc.getEntity().getType().name().toLowerCase().replace("_", "")))
|| !sender.hasPermission("citizens.npc.controllable")) || !sender.hasPermission("citizens.npc.controllable"))
throw new NoPermissionsException(); throw new NoPermissionsException();
if (!npc.hasTrait(Controllable.class)) { if (!npc.hasTrait(Controllable.class)) {
@ -448,8 +448,11 @@ public class NPCCommands {
min = 1, min = 1,
max = 2, max = 2,
permission = "citizens.npc.flyable") permission = "citizens.npc.flyable")
@Requirements(selected = true, ownership = true, excludedTypes = { EntityType.BAT, EntityType.BLAZE, @Requirements(
EntityType.ENDER_DRAGON, EntityType.GHAST, EntityType.WITHER }) selected = true,
ownership = true,
excludedTypes = { EntityType.BAT, EntityType.BLAZE, EntityType.ENDER_DRAGON, EntityType.GHAST,
EntityType.WITHER })
public void flyable(CommandContext args, CommandSender sender, NPC npc) throws CommandException { public void flyable(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
boolean flyable = args.argsLength() == 2 ? args.getString(1).equals("true") : !npc.isFlyable(); boolean flyable = args.argsLength() == 2 ? args.getString(1).equals("true") : !npc.isFlyable();
npc.setFlyable(flyable); npc.setFlyable(flyable);
@ -470,8 +473,8 @@ public class NPCCommands {
public void gamemode(CommandContext args, CommandSender sender, NPC npc) { public void gamemode(CommandContext args, CommandSender sender, NPC npc) {
Player player = (Player) npc.getEntity(); Player player = (Player) npc.getEntity();
if (args.argsLength() == 1) { if (args.argsLength() == 1) {
Messaging.sendTr(sender, Messages.GAMEMODE_DESCRIBE, npc.getName(), player.getGameMode().name() Messaging.sendTr(sender, Messages.GAMEMODE_DESCRIBE, npc.getName(),
.toLowerCase()); player.getGameMode().name().toLowerCase());
return; return;
} }
GameMode mode = null; GameMode mode = null;
@ -584,8 +587,10 @@ public class NPCCommands {
max = 3, max = 3,
flags = "", flags = "",
permission = "citizens.npc.item") permission = "citizens.npc.item")
@Requirements(selected = true, ownership = true, types = { EntityType.DROPPED_ITEM, EntityType.ITEM_FRAME, @Requirements(
EntityType.FALLING_BLOCK }) selected = true,
ownership = true,
types = { EntityType.DROPPED_ITEM, EntityType.ITEM_FRAME, EntityType.FALLING_BLOCK })
public void item(CommandContext args, CommandSender sender, NPC npc) throws CommandException { public void item(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
Material mat = Material.matchMaterial(args.getString(1)); Material mat = Material.matchMaterial(args.getString(1));
if (mat == null) if (mat == null)
@ -702,8 +707,9 @@ public class NPCCommands {
max = 1, max = 1,
permission = "citizens.npc.lookclose") permission = "citizens.npc.lookclose")
public void lookClose(CommandContext args, CommandSender sender, NPC npc) { public void lookClose(CommandContext args, CommandSender sender, NPC npc) {
Messaging.sendTr(sender, npc.getTrait(LookClose.class).toggle() ? Messages.LOOKCLOSE_SET Messaging.sendTr(sender,
: Messages.LOOKCLOSE_STOPPED, npc.getName()); npc.getTrait(LookClose.class).toggle() ? Messages.LOOKCLOSE_SET : Messages.LOOKCLOSE_STOPPED,
npc.getName());
} }
@Command( @Command(
@ -715,9 +721,12 @@ public class NPCCommands {
max = 1, max = 1,
flags = "", flags = "",
permission = "citizens.npc.minecart") permission = "citizens.npc.minecart")
@Requirements(selected = true, ownership = true, types = { EntityType.MINECART, EntityType.MINECART_CHEST, @Requirements(
EntityType.MINECART_COMMAND, EntityType.MINECART_FURNACE, EntityType.MINECART_HOPPER, selected = true,
EntityType.MINECART_MOB_SPAWNER, EntityType.MINECART_TNT }) ownership = true,
types = { EntityType.MINECART, EntityType.MINECART_CHEST, EntityType.MINECART_COMMAND,
EntityType.MINECART_FURNACE, EntityType.MINECART_HOPPER, EntityType.MINECART_MOB_SPAWNER,
EntityType.MINECART_TNT })
public void minecart(CommandContext args, CommandSender sender, NPC npc) throws CommandException { public void minecart(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if (args.hasValueFlag("item")) { if (args.hasValueFlag("item")) {
String raw = args.getFlag("item"); String raw = args.getFlag("item");
@ -906,8 +915,8 @@ public class NPCCommands {
max = 1, max = 1,
permission = "citizens.npc.passive") permission = "citizens.npc.passive")
public void passive(CommandContext args, CommandSender sender, NPC npc) throws CommandException { public void passive(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
boolean passive = args.hasValueFlag("set") ? Boolean.parseBoolean(args.getFlag("set")) : npc.data().get( boolean passive = args.hasValueFlag("set") ? Boolean.parseBoolean(args.getFlag("set"))
NPC.DAMAGE_OTHERS_METADATA, true); : npc.data().get(NPC.DAMAGE_OTHERS_METADATA, true);
npc.data().setPersistent(NPC.DAMAGE_OTHERS_METADATA, !passive); npc.data().setPersistent(NPC.DAMAGE_OTHERS_METADATA, !passive);
Messaging.sendTr(sender, passive ? Messages.PASSIVE_SET : Messages.PASSIVE_UNSET, npc.getName()); Messaging.sendTr(sender, passive ? Messages.PASSIVE_SET : Messages.PASSIVE_UNSET, npc.getName());
} }
@ -932,8 +941,14 @@ public class NPCCommands {
} }
} }
@Command(aliases = { "npc" }, usage = "pathrange [range]", desc = "Sets an NPC's pathfinding range", modifiers = { @Command(
"pathrange", "pathfindingrange", "prange" }, min = 2, max = 2, permission = "citizens.npc.pathfindingrange") aliases = { "npc" },
usage = "pathrange [range]",
desc = "Sets an NPC's pathfinding range",
modifiers = { "pathrange", "pathfindingrange", "prange" },
min = 2,
max = 2,
permission = "citizens.npc.pathfindingrange")
public void pathfindingRange(CommandContext args, CommandSender sender, NPC npc) { public void pathfindingRange(CommandContext args, CommandSender sender, NPC npc) {
double range = Math.max(1, args.getDouble(1)); double range = Math.max(1, args.getDouble(1));
npc.getNavigator().getDefaultParameters().range((float) range); npc.getNavigator().getDefaultParameters().range((float) range);
@ -1024,8 +1039,8 @@ public class NPCCommands {
permission = "citizens.npc.power") permission = "citizens.npc.power")
@Requirements(selected = true, ownership = true, types = { EntityType.CREEPER }) @Requirements(selected = true, ownership = true, types = { EntityType.CREEPER })
public void power(CommandContext args, CommandSender sender, NPC npc) { public void power(CommandContext args, CommandSender sender, NPC npc) {
Messaging Messaging.sendTr(sender,
.sendTr(sender, npc.getTrait(Powered.class).toggle() ? Messages.POWERED_SET : Messages.POWERED_STOPPED); npc.getTrait(Powered.class).toggle() ? Messages.POWERED_SET : Messages.POWERED_STOPPED);
} }
@Command( @Command(
@ -1041,15 +1056,20 @@ public class NPCCommands {
String profession = args.getString(1); String profession = args.getString(1);
Profession parsed = Util.matchEnum(Profession.values(), profession.toUpperCase()); Profession parsed = Util.matchEnum(Profession.values(), profession.toUpperCase());
if (parsed == null) { if (parsed == null) {
throw new CommandException(Messages.INVALID_PROFESSION, args.getString(1), StringUtils.join( throw new CommandException(Messages.INVALID_PROFESSION, args.getString(1),
Profession.values(), ",")); StringUtils.join(Profession.values(), ","));
} }
npc.getTrait(VillagerProfession.class).setProfession(parsed); npc.getTrait(VillagerProfession.class).setProfession(parsed);
Messaging.sendTr(sender, Messages.PROFESSION_SET, npc.getName(), profession); Messaging.sendTr(sender, Messages.PROFESSION_SET, npc.getName(), profession);
} }
@Command(aliases = { "npc" }, usage = "rabbittype [type]", desc = "Set the Type of a Rabbit NPC", modifiers = { @Command(
"rabbittype", "rbtype" }, min = 2, permission = "citizens.npc.rabbittype") aliases = { "npc" },
usage = "rabbittype [type]",
desc = "Set the Type of a Rabbit NPC",
modifiers = { "rabbittype", "rbtype" },
min = 2,
permission = "citizens.npc.rabbittype")
@Requirements(selected = true, ownership = true, types = { EntityType.RABBIT }) @Requirements(selected = true, ownership = true, types = { EntityType.RABBIT })
public void rabbitType(CommandContext args, CommandSender sender, NPC npc) throws CommandException { public void rabbitType(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
RabbitTypes type; RabbitTypes type;
@ -1062,8 +1082,13 @@ public class NPCCommands {
Messaging.sendTr(sender, Messages.RABBIT_TYPE_SET, npc.getName(), type.name()); Messaging.sendTr(sender, Messages.RABBIT_TYPE_SET, npc.getName(), type.name());
} }
@Command(aliases = { "npc" }, usage = "remove|rem (all|id|name)", desc = "Remove a NPC", modifiers = { "remove", @Command(
"rem" }, min = 1, max = 2) aliases = { "npc" },
usage = "remove|rem (all|id|name)",
desc = "Remove a NPC",
modifiers = { "remove", "rem" },
min = 1,
max = 2)
@Requirements @Requirements
public void remove(final CommandContext args, final CommandSender sender, NPC npc) throws CommandException { public void remove(final CommandContext args, final CommandSender sender, NPC npc) throws CommandException {
if (args.argsLength() == 2) { if (args.argsLength() == 2) {
@ -1222,8 +1247,14 @@ public class NPCCommands {
} }
} }
@Command(aliases = { "npc" }, usage = "skeletontype [type]", desc = "Sets the NPC's skeleton type", modifiers = { @Command(
"skeletontype", "sktype" }, min = 2, max = 2, permission = "citizens.npc.skeletontype") aliases = { "npc" },
usage = "skeletontype [type]",
desc = "Sets the NPC's skeleton type",
modifiers = { "skeletontype", "sktype" },
min = 2,
max = 2,
permission = "citizens.npc.skeletontype")
@Requirements(selected = true, ownership = true, types = EntityType.SKELETON) @Requirements(selected = true, ownership = true, types = EntityType.SKELETON)
public void skeletonType(CommandContext args, CommandSender sender, NPC npc) throws CommandException { public void skeletonType(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
SkeletonType type; SkeletonType type;
@ -1450,8 +1481,8 @@ public class NPCCommands {
max = 1, max = 1,
permission = "citizens.npc.swim") permission = "citizens.npc.swim")
public void swim(CommandContext args, CommandSender sender, NPC npc) throws CommandException { public void swim(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
boolean swim = args.hasValueFlag("set") ? Boolean.parseBoolean(args.getFlag("set")) : !npc.data().get( boolean swim = args.hasValueFlag("set") ? Boolean.parseBoolean(args.getFlag("set"))
NPC.SWIMMING_METADATA, true); : !npc.data().get(NPC.SWIMMING_METADATA, true);
npc.data().setPersistent(NPC.SWIMMING_METADATA, swim); npc.data().setPersistent(NPC.SWIMMING_METADATA, swim);
Messaging.sendTr(sender, swim ? Messages.SWIMMING_SET : Messages.SWIMMING_UNSET, npc.getName()); Messaging.sendTr(sender, swim ? Messages.SWIMMING_SET : Messages.SWIMMING_UNSET, npc.getName());
} }
@ -1493,8 +1524,14 @@ public class NPCCommands {
Messaging.sendTr(player, Messages.TELEPORTED_TO_NPC, npc.getName()); Messaging.sendTr(player, Messages.TELEPORTED_TO_NPC, npc.getName());
} }
@Command(aliases = { "npc" }, usage = "tphere", desc = "Teleport a NPC to your location", modifiers = { "tphere", @Command(
"tph", "move" }, min = 1, max = 1, permission = "citizens.npc.tphere") aliases = { "npc" },
usage = "tphere",
desc = "Teleport a NPC to your location",
modifiers = { "tphere", "tph", "move" },
min = 1,
max = 1,
permission = "citizens.npc.tphere")
public void tphere(CommandContext args, CommandSender sender, NPC npc) throws CommandException { public void tphere(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if (args.getSenderLocation() == null) if (args.getSenderLocation() == null)
throw new ServerCommandException(); throw new ServerCommandException();

View File

@ -25,8 +25,13 @@ import com.google.common.collect.Lists;
@Requirements(selected = true, ownership = true) @Requirements(selected = true, ownership = true)
public class TraitCommands { public class TraitCommands {
@Command(aliases = { "trait", "tr" }, usage = "add [trait name]...", desc = "Adds traits to the NPC", modifiers = { @Command(
"add", "a" }, min = 1, permission = "citizens.npc.trait") aliases = { "trait", "tr" },
usage = "add [trait name]...",
desc = "Adds traits to the NPC",
modifiers = { "add", "a" },
min = 1,
permission = "citizens.npc.trait")
public void add(CommandContext args, CommandSender sender, NPC npc) throws CommandException { public void add(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
List<String> added = Lists.newArrayList(); List<String> added = Lists.newArrayList();
List<String> failed = Lists.newArrayList(); List<String> failed = Lists.newArrayList();

View File

@ -20,8 +20,8 @@ public abstract class Editor implements Listener {
private static void enter(Player player, Editor editor) { private static void enter(Player player, Editor editor) {
editor.begin(); editor.begin();
player.getServer().getPluginManager() player.getServer().getPluginManager().registerEvents(editor,
.registerEvents(editor, player.getServer().getPluginManager().getPlugin("Citizens")); player.getServer().getPluginManager().getPlugin("Citizens"));
EDITING.put(player.getName(), editor); EDITING.put(player.getName(), editor);
} }

View File

@ -57,6 +57,7 @@ public class EquipmentEditor extends Editor {
} }
private static final Map<EntityType, Equipper> EQUIPPERS = Maps.newEnumMap(EntityType.class); private static final Map<EntityType, Equipper> EQUIPPERS = Maps.newEnumMap(EntityType.class);
static { static {
EQUIPPERS.put(EntityType.PIG, new PigEquipper()); EQUIPPERS.put(EntityType.PIG, new PigEquipper());
EQUIPPERS.put(EntityType.SHEEP, new SheepEquipper()); EQUIPPERS.put(EntityType.SHEEP, new SheepEquipper());

View File

@ -27,8 +27,8 @@ public class SheepEquipper implements Equipper {
return; return;
DyeColor color = dye.getColor(); DyeColor color = dye.getColor();
toEquip.getTrait(WoolColor.class).setColor(color); toEquip.getTrait(WoolColor.class).setColor(color);
Messaging.sendTr(equipper, Messages.EQUIPMENT_EDITOR_SHEEP_COLOURED, toEquip.getName(), color.name() Messaging.sendTr(equipper, Messages.EQUIPMENT_EDITOR_SHEEP_COLOURED, toEquip.getName(),
.toLowerCase().replace("_", " ")); color.name().toLowerCase().replace("_", " "));
hand.setAmount(hand.getAmount() - 1); hand.setAmount(hand.getAmount() - 1);
} else { } else {

View File

@ -4,6 +4,22 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.scheduler.BukkitRunnable;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import net.citizensnpcs.NPCNeedsRespawnEvent; import net.citizensnpcs.NPCNeedsRespawnEvent;
import net.citizensnpcs.Settings.Setting; import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.CitizensAPI;
@ -26,23 +42,7 @@ import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util; import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_8_R3.Packet; import net.minecraft.server.v1_8_R3.Packet;
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport; import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport;
import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo; import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.metadata.FixedMetadataValue;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import org.bukkit.scheduler.BukkitRunnable;
public class CitizensNPC extends AbstractNPC { public class CitizensNPC extends AbstractNPC {
private EntityController entityController; private EntityController entityController;
@ -224,15 +224,21 @@ public class CitizensNPC extends AbstractNPC {
final CraftPlayer player = (CraftPlayer) getEntity(); final CraftPlayer player = (CraftPlayer) getEntity();
NMS.replaceTrackerEntry(player); NMS.replaceTrackerEntry(player);
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
NMS.sendPacketsNearby(player, player.getLocation(), Arrays.asList((Packet) new PacketPlayOutPlayerInfo( NMS.sendPacketsNearby(player, player.getLocation(),
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, player.getHandle())), 200.0); Arrays.asList((Packet) new PacketPlayOutPlayerInfo(
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, player.getHandle())),
200.0);
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
NMS.sendPacketsNearby(player, player.getLocation(), Arrays.asList((Packet) new PacketPlayOutPlayerInfo( NMS.sendPacketsNearby(player, player.getLocation(),
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, player.getHandle())), 200.0); Arrays.asList((Packet) new PacketPlayOutPlayerInfo(
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER,
player.getHandle())),
200.0);
} }
}.runTaskLater(CitizensAPI.getPlugin(), 2); }.runTaskLater(CitizensAPI.getPlugin(), 2);
} }

View File

@ -236,6 +236,7 @@ public class CitizensNPCRegistry implements NPCRegistry {
}; };
private static boolean TROVE_EXISTS = false; private static boolean TROVE_EXISTS = false;
static { static {
// allow trove dependency to be optional for debugging purposes // allow trove dependency to be optional for debugging purposes
try { try {

View File

@ -32,8 +32,9 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
this.npc = npc; this.npc = npc;
Location location = Util.getEyeLocation(npc.getEntity()); Location location = Util.getEyeLocation(npc.getEntity());
VectorGoal goal = new VectorGoal(dest, (float) params.pathDistanceMargin()); VectorGoal goal = new VectorGoal(dest, (float) params.pathDistanceMargin());
plan = ASTAR.runFully(goal, new VectorNode(goal, location, new ChunkBlockSource(location, params.range()), plan = ASTAR.runFully(goal,
params.examiners()), 50000); new VectorNode(goal, location, new ChunkBlockSource(location, params.range()), params.examiners()),
50000);
if (plan == null || plan.isComplete()) { if (plan == null || plan.isComplete()) {
setCancelReason(CancelReason.STUCK); setCancelReason(CancelReason.STUCK);
} else { } else {
@ -76,8 +77,8 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
double xzDistance = dX * dX + dZ * dZ; double xzDistance = dX * dX + dZ * dZ;
double distance = xzDistance + dY * dY; double distance = xzDistance + dY * dY;
if (Setting.DEBUG_PATHFINDING.asBoolean()) { if (Setting.DEBUG_PATHFINDING.asBoolean()) {
npc.getEntity().getWorld() npc.getEntity().getWorld().playEffect(vector.toLocation(npc.getEntity().getWorld()), Effect.ENDER_SIGNAL,
.playEffect(vector.toLocation(npc.getEntity().getWorld()), Effect.ENDER_SIGNAL, 0); 0);
} }
if (distance > 0 && dY > 0 && dY < 1 && xzDistance <= 2.75) { if (distance > 0 && dY > 0 && dY < 1 && xzDistance <= 2.75) {
NMS.setShouldJump(npc.getEntity()); NMS.setShouldJump(npc.getEntity());

View File

@ -44,8 +44,9 @@ public class FlyingAStarNavigationStrategy extends AbstractPathStrategy {
if (!found) { if (!found) {
params.examiner(new FlyingBlockExaminer()); params.examiner(new FlyingBlockExaminer());
} }
plan = ASTAR.runFully(goal, new VectorNode(goal, location, new ChunkBlockSource(location, params.range()), plan = ASTAR.runFully(goal,
params.examiners()), 50000); new VectorNode(goal, location, new ChunkBlockSource(location, params.range()), params.examiners()),
50000);
if (plan == null || plan.isComplete()) { if (plan == null || plan.isComplete()) {
setCancelReason(CancelReason.STUCK); setCancelReason(CancelReason.STUCK);
} else { } else {

View File

@ -67,8 +67,7 @@ public class MCNavigationStrategy extends AbstractPathStrategy {
} }
private double distanceSquared() { private double distanceSquared() {
return handle.getBukkitEntity().getLocation(HANDLE_LOCATION) return handle.getBukkitEntity().getLocation(HANDLE_LOCATION).distanceSquared(target);
.distanceSquared(target);
} }
private static final Location HANDLE_LOCATION = new Location(null, 0, 0, 0); private static final Location HANDLE_LOCATION = new Location(null, 0, 0, 0);

View File

@ -40,8 +40,9 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
private boolean canAttack() { private boolean canAttack() {
return attackTicks == 0 return attackTicks == 0
&& (handle.getBoundingBox().e > target.getBoundingBox().b && handle.getBoundingBox().b < target && (handle.getBoundingBox().e > target.getBoundingBox().b
.getBoundingBox().e) && closeEnough(distanceSquared()) && hasLineOfSight(); && handle.getBoundingBox().b < target.getBoundingBox().e)
&& closeEnough(distanceSquared()) && hasLineOfSight();
} }
@Override @Override

View File

@ -31,16 +31,16 @@ public class Chat implements VocalChord {
// chat to the world with CHAT_FORMAT and CHAT_RANGE settings // chat to the world with CHAT_FORMAT and CHAT_RANGE settings
if (!context.hasRecipients()) { if (!context.hasRecipients()) {
String text = Setting.CHAT_FORMAT.asString().replace("<npc>", npc.getName()) String text = Setting.CHAT_FORMAT.asString().replace("<npc>", npc.getName()).replace("<text>",
.replace("<text>", context.getMessage()); context.getMessage());
talkToBystanders(npc, text, context); talkToBystanders(npc, text, context);
return; return;
} }
// Assumed recipients at this point // Assumed recipients at this point
else if (context.size() <= 1) { else if (context.size() <= 1) {
String text = Setting.CHAT_FORMAT_TO_TARGET.asString().replace("<npc>", npc.getName()) String text = Setting.CHAT_FORMAT_TO_TARGET.asString().replace("<npc>", npc.getName()).replace("<text>",
.replace("<text>", context.getMessage()); context.getMessage());
String targetName = ""; String targetName = "";
// For each recipient // For each recipient
for (Talkable entity : context) { for (Talkable entity : context) {
@ -58,8 +58,8 @@ public class Chat implements VocalChord {
} }
else { // Multiple recipients else { // Multiple recipients
String text = Setting.CHAT_FORMAT_TO_TARGET.asString().replace("<npc>", npc.getName()) String text = Setting.CHAT_FORMAT_TO_TARGET.asString().replace("<npc>", npc.getName()).replace("<text>",
.replace("<text>", context.getMessage()); context.getMessage());
List<String> targetNames = new ArrayList<String>(); List<String> targetNames = new ArrayList<String>();
// Talk to each recipient // Talk to each recipient
for (Talkable entity : context) { for (Talkable entity : context) {

View File

@ -31,8 +31,7 @@ public class TalkableEntity implements Talkable {
/** /**
* Used to compare a LivingEntity to this TalkableEntity * Used to compare a LivingEntity to this TalkableEntity
* *
* @return 0 if the Entities are the same, 1 if they are not, -1 if the * @return 0 if the Entities are the same, 1 if they are not, -1 if the object compared is not a valid LivingEntity
* object compared is not a valid LivingEntity
*/ */
@Override @Override
public int compareTo(Object o) { public int compareTo(Object o) {
@ -40,8 +39,7 @@ public class TalkableEntity implements Talkable {
if (!(o instanceof Entity)) { if (!(o instanceof Entity)) {
return -1; return -1;
// If NPC and matches, return 0 // If NPC and matches, return 0
} else if (CitizensAPI.getNPCRegistry().isNPC((Entity) o) } else if (CitizensAPI.getNPCRegistry().isNPC((Entity) o) && CitizensAPI.getNPCRegistry().isNPC(entity)
&& CitizensAPI.getNPCRegistry().isNPC(entity)
&& CitizensAPI.getNPCRegistry().getNPC((Entity) o).getUniqueId() && CitizensAPI.getNPCRegistry().getNPC((Entity) o).getUniqueId()
.equals(CitizensAPI.getNPCRegistry().getNPC(entity).getUniqueId())) { .equals(CitizensAPI.getNPCRegistry().getNPC(entity).getUniqueId())) {
return 0; return 0;

View File

@ -60,14 +60,14 @@ public class BatController extends MobEntityController {
@Override @Override
protected String bo() { protected String bo() {
return npc == null || !npc.data().has(NPC.HURT_SOUND_METADATA) ? super.bo() : npc.data().get( return npc == null || !npc.data().has(NPC.HURT_SOUND_METADATA) ? super.bo()
NPC.HURT_SOUND_METADATA, super.bo()); : npc.data().get(NPC.HURT_SOUND_METADATA, super.bo());
} }
@Override @Override
protected String bp() { protected String bp() {
return npc == null || !npc.data().has(NPC.DEATH_SOUND_METADATA) ? super.bp() : npc.data().get( return npc == null || !npc.data().has(NPC.DEATH_SOUND_METADATA) ? super.bp()
NPC.DEATH_SOUND_METADATA, super.bp()); : npc.data().get(NPC.DEATH_SOUND_METADATA, super.bp());
} }
@Override @Override
@ -156,8 +156,8 @@ public class BatController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }
} }

View File

@ -145,8 +145,8 @@ public class BlazeController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }
} }

View File

@ -182,8 +182,8 @@ public class CaveSpiderController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }
} }

View File

@ -191,8 +191,8 @@ public class ChickenController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }
} }

View File

@ -192,8 +192,8 @@ public class CowController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }
} }

View File

@ -192,8 +192,8 @@ public class CreeperController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }
} }

View File

@ -162,8 +162,8 @@ public class EnderDragonController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }
} }

View File

@ -186,8 +186,8 @@ public class EndermanController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }
} }

View File

@ -178,8 +178,8 @@ public class EndermiteController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }
} }

View File

@ -157,8 +157,8 @@ public class GiantController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }

View File

@ -1,5 +1,12 @@
package net.citizensnpcs.npc.entity; package net.citizensnpcs.npc.entity;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftGuardian;
import org.bukkit.entity.Guardian;
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;
@ -13,13 +20,6 @@ import net.minecraft.server.v1_8_R3.EntityGuardian;
import net.minecraft.server.v1_8_R3.NBTTagCompound; import net.minecraft.server.v1_8_R3.NBTTagCompound;
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.CraftEntity;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftGuardian;
import org.bukkit.entity.Guardian;
import org.bukkit.util.Vector;
public class GuardianController extends MobEntityController { public class GuardianController extends MobEntityController {
public GuardianController() { public GuardianController() {
super(EntityGuardianNPC.class); super(EntityGuardianNPC.class);
@ -42,18 +42,6 @@ public class GuardianController extends MobEntityController {
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
NMS.clearGoals(goalSelector, targetSelector); NMS.clearGoals(goalSelector, targetSelector);
}
}
@Override
public void setElder(boolean flag) {
float oldw = width;
float oldl = length;
super.setElder(flag);
if (oldw != width || oldl != length) {
this.setPosition(locX - 0.01, locY, locZ - 0.01);
this.setPosition(locX + 0.01, locY, locZ + 0.01);
} }
} }
@ -116,14 +104,6 @@ public class GuardianController extends MobEntityController {
} }
} }
@Override
public void E() {
super.E();
if (npc != null) {
npc.update();
}
}
@Override @Override
public void g(double x, double y, double z) { public void g(double x, double y, double z) {
if (npc == null) { if (npc == null) {
@ -180,13 +160,26 @@ public class GuardianController extends MobEntityController {
public void m() { public void m() {
if (npc == null) { if (npc == null) {
super.m(); super.m();
} else {
npc.update();
}
}
@Override
public void setElder(boolean flag) {
float oldw = width;
float oldl = length;
super.setElder(flag);
if (oldw != width || oldl != length) {
this.setPosition(locX - 0.01, locY, locZ - 0.01);
this.setPosition(locX + 0.01, locY, locZ + 0.01);
} }
} }
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }

View File

@ -188,8 +188,8 @@ public class HorseController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }

View File

@ -102,26 +102,27 @@ public class HumanController extends AbstractEntityController {
if (skinUUID == null) { if (skinUUID == null) {
skinUUID = npc.getName(); skinUUID = npc.getName();
} }
if (npc.data().has(CACHED_SKIN_UUID_METADATA) if (npc.data().has(CACHED_SKIN_UUID_METADATA) && npc.data().has(CACHED_SKIN_UUID_NAME_METADATA)
&& npc.data().has(CACHED_SKIN_UUID_NAME_METADATA)
&& ChatColor.stripColor(skinUUID).equalsIgnoreCase( && ChatColor.stripColor(skinUUID).equalsIgnoreCase(
ChatColor.stripColor(npc.data().<String> get(CACHED_SKIN_UUID_NAME_METADATA)))) { ChatColor.stripColor(npc.data().<String> get(CACHED_SKIN_UUID_NAME_METADATA)))) {
skinUUID = npc.data().get(CACHED_SKIN_UUID_METADATA); skinUUID = npc.data().get(CACHED_SKIN_UUID_METADATA);
} }
if (npc.data().has(PLAYER_SKIN_TEXTURE_PROPERTIES)&&npc.data().<String>get(PLAYER_SKIN_TEXTURE_PROPERTIES).equals("cache")) { if (npc.data().has(PLAYER_SKIN_TEXTURE_PROPERTIES)
SKIN_THREAD.addRunnable(new SkinFetcher(new UUIDFetcher(skinUUID, npc), nmsWorld.getMinecraftServer().aD(), && npc.data().<String> get(PLAYER_SKIN_TEXTURE_PROPERTIES).equals("cache")) {
npc)); SKIN_THREAD.addRunnable(
new SkinFetcher(new UUIDFetcher(skinUUID, npc), nmsWorld.getMinecraftServer().aD(), npc));
return; return;
} }
Property cached = TEXTURE_CACHE.get(skinUUID); Property cached = TEXTURE_CACHE.get(skinUUID);
if (npc.data().has(PLAYER_SKIN_TEXTURE_PROPERTIES) && npc.data().has(PLAYER_SKIN_TEXTURE_PROPERTIES_SIGN)) { if (npc.data().has(PLAYER_SKIN_TEXTURE_PROPERTIES) && npc.data().has(PLAYER_SKIN_TEXTURE_PROPERTIES_SIGN)) {
cached = new Property("textures",npc.data().<String>get(PLAYER_SKIN_TEXTURE_PROPERTIES),npc.data().<String>get(PLAYER_SKIN_TEXTURE_PROPERTIES_SIGN)); cached = new Property("textures", npc.data().<String> get(PLAYER_SKIN_TEXTURE_PROPERTIES),
npc.data().<String> get(PLAYER_SKIN_TEXTURE_PROPERTIES_SIGN));
} }
if (cached != null) { if (cached != null) {
profile.getProperties().put("textures", cached); profile.getProperties().put("textures", cached);
} else { } else {
SKIN_THREAD.addRunnable(new SkinFetcher(new UUIDFetcher(skinUUID, npc), nmsWorld.getMinecraftServer().aD(), SKIN_THREAD.addRunnable(
npc)); new SkinFetcher(new UUIDFetcher(skinUUID, npc), nmsWorld.getMinecraftServer().aD(), npc));
} }
} }
@ -141,13 +142,13 @@ public class HumanController extends AbstractEntityController {
*/ */
private GameProfile fillProfileProperties(YggdrasilAuthenticationService auth, GameProfile profile, private GameProfile fillProfileProperties(YggdrasilAuthenticationService auth, GameProfile profile,
boolean requireSecure) throws Exception { boolean requireSecure) throws Exception {
URL url = HttpAuthenticationService.constantURL(new StringBuilder() URL url = HttpAuthenticationService.constantURL(
.append("https://sessionserver.mojang.com/session/minecraft/profile/") new StringBuilder().append("https://sessionserver.mojang.com/session/minecraft/profile/")
.append(UUIDTypeAdapter.fromUUID(profile.getId())).toString()); .append(UUIDTypeAdapter.fromUUID(profile.getId())).toString());
url = HttpAuthenticationService.concatenateURL(url, url = HttpAuthenticationService.concatenateURL(url,
new StringBuilder().append("unsigned=").append(!requireSecure).toString()); new StringBuilder().append("unsigned=").append(!requireSecure).toString());
MinecraftProfilePropertiesResponse response = (MinecraftProfilePropertiesResponse) MAKE_REQUEST.invoke( MinecraftProfilePropertiesResponse response = (MinecraftProfilePropertiesResponse) MAKE_REQUEST.invoke(auth,
auth, url, null, MinecraftProfilePropertiesResponse.class); url, null, MinecraftProfilePropertiesResponse.class);
if (response == null) { if (response == null) {
return profile; return profile;
} }
@ -167,7 +168,8 @@ public class HumanController extends AbstractEntityController {
} }
GameProfile skinProfile = null; GameProfile skinProfile = null;
Property cached = TEXTURE_CACHE.get(realUUID); Property cached = TEXTURE_CACHE.get(realUUID);
if (cached != null && !(npc.data().has(PLAYER_SKIN_TEXTURE_PROPERTIES)&&npc.data().<String>get(PLAYER_SKIN_TEXTURE_PROPERTIES).equals("cache"))) { if (cached != null && !(npc.data().has(PLAYER_SKIN_TEXTURE_PROPERTIES)
&& npc.data().<String> get(PLAYER_SKIN_TEXTURE_PROPERTIES).equals("cache"))) {
if (Messaging.isDebugging()) { if (Messaging.isDebugging()) {
Messaging Messaging
.debug("Using cached skin texture for NPC " + npc.getName() + " UUID " + npc.getUniqueId()); .debug("Using cached skin texture for NPC " + npc.getName() + " UUID " + npc.getUniqueId());
@ -181,8 +183,8 @@ public class HumanController extends AbstractEntityController {
new GameProfile(UUID.fromString(realUUID), ""), true); new GameProfile(UUID.fromString(realUUID), ""), true);
} catch (Exception e) { } catch (Exception e) {
if ((e.getMessage() != null && e.getMessage().contains("too many requests")) if ((e.getMessage() != null && e.getMessage().contains("too many requests"))
|| (e.getCause() != null && e.getCause().getMessage() != null && e.getCause().getMessage() || (e.getCause() != null && e.getCause().getMessage() != null
.contains("too many requests"))) { && e.getCause().getMessage().contains("too many requests"))) {
SKIN_THREAD.delay(); SKIN_THREAD.delay();
SKIN_THREAD.addRunnable(this); SKIN_THREAD.addRunnable(this);
} }
@ -194,13 +196,14 @@ public class HumanController extends AbstractEntityController {
Property textures = Iterables.getFirst(skinProfile.getProperties().get("textures"), null); Property textures = Iterables.getFirst(skinProfile.getProperties().get("textures"), null);
if (textures.getValue() == null || textures.getSignature() == null) if (textures.getValue() == null || textures.getSignature() == null)
return; return;
if (npc.data().has(PLAYER_SKIN_TEXTURE_PROPERTIES)&&npc.data().<String>get(PLAYER_SKIN_TEXTURE_PROPERTIES).equals("cache")) { if (npc.data().has(PLAYER_SKIN_TEXTURE_PROPERTIES)
&& npc.data().<String> get(PLAYER_SKIN_TEXTURE_PROPERTIES).equals("cache")) {
npc.data().setPersistent(PLAYER_SKIN_TEXTURE_PROPERTIES, textures.getValue()); npc.data().setPersistent(PLAYER_SKIN_TEXTURE_PROPERTIES, textures.getValue());
npc.data().setPersistent(PLAYER_SKIN_TEXTURE_PROPERTIES_SIGN, textures.getSignature()); npc.data().setPersistent(PLAYER_SKIN_TEXTURE_PROPERTIES_SIGN, textures.getSignature());
} }
if (Messaging.isDebugging()) { if (Messaging.isDebugging()) {
Messaging.debug("Fetched skin texture for UUID " + realUUID + " for NPC " + npc.getName() Messaging.debug("Fetched skin texture for UUID " + realUUID + " for NPC " + npc.getName() + " UUID "
+ " UUID " + npc.getUniqueId()); + npc.getUniqueId());
} }
TEXTURE_CACHE.put(realUUID, new Property("textures", textures.getValue(), textures.getSignature())); TEXTURE_CACHE.put(realUUID, new Property("textures", textures.getValue(), textures.getSignature()));
} }
@ -309,6 +312,7 @@ public class HumanController extends AbstractEntityController {
private static SkinThread SKIN_THREAD; private static SkinThread SKIN_THREAD;
private static final Map<String, Property> TEXTURE_CACHE = Maps.newConcurrentMap(); private static final Map<String, Property> TEXTURE_CACHE = Maps.newConcurrentMap();
private static final Map<String, String> UUID_CACHE = Maps.newConcurrentMap(); private static final Map<String, String> UUID_CACHE = Maps.newConcurrentMap();
static { static {
try { try {
MAKE_REQUEST = YggdrasilAuthenticationService.class.getDeclaredMethod("makeRequest", URL.class, MAKE_REQUEST = YggdrasilAuthenticationService.class.getDeclaredMethod("makeRequest", URL.class,

View File

@ -164,8 +164,8 @@ public class IronGolemController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }

View File

@ -165,8 +165,8 @@ public class MagmaCubeController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }

View File

@ -176,8 +176,8 @@ public class MushroomCowController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }

View File

@ -175,8 +175,8 @@ public class OcelotController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }

View File

@ -184,8 +184,8 @@ public class PigController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }

View File

@ -166,8 +166,8 @@ public class PigZombieController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }

View File

@ -175,8 +175,8 @@ public class SheepController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }

View File

@ -164,8 +164,8 @@ public class SilverfishController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }

View File

@ -165,8 +165,8 @@ public class SkeletonController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }

View File

@ -185,8 +185,8 @@ public class SlimeController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }

View File

@ -164,8 +164,8 @@ public class SnowmanController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }

View File

@ -164,8 +164,8 @@ public class SpiderController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }

View File

@ -157,8 +157,8 @@ public class SquidController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }

View File

@ -193,8 +193,8 @@ public class VillagerController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }

View File

@ -164,8 +164,8 @@ public class WitchController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }

View File

@ -140,8 +140,8 @@ public class WitherController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }

View File

@ -177,8 +177,8 @@ public class WolfController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }

View File

@ -165,8 +165,8 @@ public class ZombieController extends MobEntityController {
@Override @Override
protected String z() { protected String z() {
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get( return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z()
NPC.AMBIENT_SOUND_METADATA, super.z()); : npc.data().get(NPC.AMBIENT_SOUND_METADATA, super.z());
} }
} }

View File

@ -37,8 +37,8 @@ public class FallingBlockController extends AbstractEntityController {
Block id = Blocks.STONE; Block id = Blocks.STONE;
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0)); int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
if (npc.data().has("falling-block-id") || npc.data().has(NPC.ITEM_ID_METADATA)) { if (npc.data().has("falling-block-id") || npc.data().has(NPC.ITEM_ID_METADATA)) {
id = CraftMagicNumbers.getBlock(Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA, id = CraftMagicNumbers.getBlock(Material.getMaterial(
npc.data().<String> get("falling-block-id")))); npc.data().<String> get(NPC.ITEM_ID_METADATA, npc.data().<String> get("falling-block-id"))));
} }
final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(), final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
id.fromLegacyData(data)); id.fromLegacyData(data));

View File

@ -372,6 +372,7 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
private static final Map<EntityType, Class<? extends MovementController>> controllerTypes = Maps private static final Map<EntityType, Class<? extends MovementController>> controllerTypes = Maps
.newEnumMap(EntityType.class); .newEnumMap(EntityType.class);
static { static {
controllerTypes.put(EntityType.BAT, PlayerInputAirController.class); controllerTypes.put(EntityType.BAT, PlayerInputAirController.class);
controllerTypes.put(EntityType.BLAZE, PlayerInputAirController.class); controllerTypes.put(EntityType.BLAZE, PlayerInputAirController.class);

View File

@ -30,8 +30,8 @@ public class LookClose extends Trait implements Toggleable, CommandConfigurable
} }
private boolean canSeeTarget() { private boolean canSeeTarget() {
return realisticLooking && npc.getEntity() instanceof LivingEntity ? ((LivingEntity) npc.getEntity()) return realisticLooking && npc.getEntity() instanceof LivingEntity
.hasLineOfSight(lookingAt) : true; ? ((LivingEntity) npc.getEntity()).hasLineOfSight(lookingAt) : true;
} }
@Override @Override

View File

@ -112,8 +112,7 @@ public class GuidedWaypointProvider implements WaypointProvider {
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
if (!event.getPlayer().equals(player) || event.getAction() == Action.PHYSICAL if (!event.getPlayer().equals(player) || event.getAction() == Action.PHYSICAL
|| event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK
|| event.getAction() == Action.RIGHT_CLICK_BLOCK
|| event.getClickedBlock() == null) || event.getClickedBlock() == null)
return; return;
if (event.getPlayer().getWorld() != npc.getEntity().getWorld()) if (event.getPlayer().getWorld() != npc.getEntity().getWorld())
@ -337,10 +336,10 @@ public class GuidedWaypointProvider implements WaypointProvider {
@Override @Override
public Iterable<AStarNode> getNeighbours() { public Iterable<AStarNode> getNeighbours() {
List<DistanceResult<Region3D<Waypoint>>> res = tree.nearestNeighbour(Region3D List<DistanceResult<Region3D<Waypoint>>> res = tree.nearestNeighbour(
.<Waypoint> distanceCalculator(), Region3D.<Waypoint> alwaysAcceptNodeFilter(), 15, Region3D.<Waypoint> distanceCalculator(), Region3D.<Waypoint> alwaysAcceptNodeFilter(), 15,
new SimplePointND(waypoint.getLocation().getBlockX(), waypoint.getLocation().getBlockY(), waypoint new SimplePointND(waypoint.getLocation().getBlockX(), waypoint.getLocation().getBlockY(),
.getLocation().getBlockZ())); waypoint.getLocation().getBlockZ()));
return Iterables.transform(res, new Function<DistanceResult<Region3D<Waypoint>>, AStarNode>() { return Iterables.transform(res, new Function<DistanceResult<Region3D<Waypoint>>, AStarNode>() {
@Override @Override
public AStarNode apply(DistanceResult<Region3D<Waypoint>> arg0) { public AStarNode apply(DistanceResult<Region3D<Waypoint>> arg0) {

View File

@ -274,8 +274,8 @@ public class LinearWaypointProvider implements WaypointProvider {
markers.createWaypointMarker(element); markers.createWaypointMarker(element);
} }
editingSlot = Math.min(editingSlot + 1, waypoints.size()); editingSlot = Math.min(editingSlot + 1, waypoints.size());
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_ADDED_WAYPOINT, formatLoc(at), Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_ADDED_WAYPOINT, formatLoc(at), editingSlot + 1,
editingSlot + 1, waypoints.size()); waypoints.size());
} else if (waypoints.size() > 0) { } else if (waypoints.size() > 0) {
event.setCancelled(true); event.setCancelled(true);
normaliseEditingSlot(); normaliseEditingSlot();
@ -297,8 +297,8 @@ public class LinearWaypointProvider implements WaypointProvider {
if (!event.getRightClicked().hasMetadata("waypointindex")) if (!event.getRightClicked().hasMetadata("waypointindex"))
return; return;
editingSlot = event.getRightClicked().getMetadata("waypointindex").get(0).asInt(); editingSlot = event.getRightClicked().getMetadata("waypointindex").get(0).asInt();
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_EDIT_SLOT_SET, editingSlot, formatLoc(waypoints Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_EDIT_SLOT_SET, editingSlot,
.get(editingSlot).getLocation())); formatLoc(waypoints.get(editingSlot).getLocation()));
} }
@EventHandler @EventHandler
@ -318,8 +318,8 @@ public class LinearWaypointProvider implements WaypointProvider {
editingSlot += diff > 0 ? 1 : -1; editingSlot += diff > 0 ? 1 : -1;
} }
normaliseEditingSlot(); normaliseEditingSlot();
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_EDIT_SLOT_SET, editingSlot, formatLoc(waypoints Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_EDIT_SLOT_SET, editingSlot,
.get(editingSlot).getLocation())); formatLoc(waypoints.get(editingSlot).getLocation()));
} }
private void onWaypointsModified() { private void onWaypointsModified() {
@ -417,9 +417,8 @@ public class LinearWaypointProvider implements WaypointProvider {
this.selector = selector; this.selector = selector;
Waypoint next = itr.next(); Waypoint next = itr.next();
Location npcLoc = npc.getEntity().getLocation(cachedLocation); Location npcLoc = npc.getEntity().getLocation(cachedLocation);
if (npcLoc.getWorld() != next.getLocation().getWorld() if (npcLoc.getWorld() != next.getLocation().getWorld() || npcLoc.distanceSquared(next.getLocation()) < npc
|| npcLoc.distanceSquared(next.getLocation()) < npc.getNavigator().getLocalParameters() .getNavigator().getLocalParameters().distanceMargin()) {
.distanceMargin()) {
return false; return false;
} }
currentDestination = next; currentDestination = next;
@ -427,10 +426,8 @@ public class LinearWaypointProvider implements WaypointProvider {
getNavigator().getLocalParameters().addSingleUseCallback(new NavigatorCallback() { getNavigator().getLocalParameters().addSingleUseCallback(new NavigatorCallback() {
@Override @Override
public void onCompletion(@Nullable CancelReason cancelReason) { public void onCompletion(@Nullable CancelReason cancelReason) {
if (npc.isSpawned() if (npc.isSpawned() && currentDestination != null && Util
&& currentDestination != null .locationWithinRange(npc.getEntity().getLocation(), currentDestination.getLocation(), 4)) {
&& Util.locationWithinRange(npc.getEntity().getLocation(),
currentDestination.getLocation(), 4)) {
currentDestination.onReach(npc); currentDestination.onReach(npc);
} }
selector.finish(); selector.finish();

View File

@ -42,8 +42,7 @@ public class Waypoints extends Trait {
} }
/** /**
* Returns the current {@link WaypointProvider}. May be null during * Returns the current {@link WaypointProvider}. May be null during initialisation.
* initialisation.
* *
* @return The current provider * @return The current provider
*/ */
@ -96,8 +95,7 @@ public class Waypoints extends Trait {
* Sets the current {@link WaypointProvider} using the given name. * Sets the current {@link WaypointProvider} using the given name.
* *
* @param name * @param name
* The name of the waypoint provider, registered using * The name of the waypoint provider, registered using {@link #registerWaypointProvider(Class, String)}
* {@link #registerWaypointProvider(Class, String)}
* @return Whether the operation succeeded * @return Whether the operation succeeded
*/ */
public boolean setWaypointProvider(String name) { public boolean setWaypointProvider(String name) {
@ -116,8 +114,7 @@ public class Waypoints extends Trait {
} }
/** /**
* Registers a {@link WaypointProvider}, which can be subsequently used by * Registers a {@link WaypointProvider}, which can be subsequently used by NPCs.
* NPCs.
* *
* @param clazz * @param clazz
* The class of the waypoint provider * The class of the waypoint provider

View File

@ -29,7 +29,8 @@ public class TeleportTriggerPrompt extends RegexPrompt implements WaypointTrigge
return (Prompt) context.getSessionData("previous"); return (Prompt) context.getSessionData("previous");
if (input.equalsIgnoreCase("here")) { if (input.equalsIgnoreCase("here")) {
Player player = (Player) context.getForWhom(); Player player = (Player) context.getForWhom();
context.setSessionData(WaypointTriggerPrompt.CREATED_TRIGGER_KEY, new TeleportTrigger(player.getLocation())); context.setSessionData(WaypointTriggerPrompt.CREATED_TRIGGER_KEY,
new TeleportTrigger(player.getLocation()));
return (Prompt) context.getSessionData(WaypointTriggerPrompt.RETURN_PROMPT_KEY); return (Prompt) context.getSessionData(WaypointTriggerPrompt.RETURN_PROMPT_KEY);
} }
String[] parts = Iterables.toArray(Splitter.on(':').split(input), String.class); String[] parts = Iterables.toArray(Splitter.on(':').split(input), String.class);

View File

@ -32,8 +32,8 @@ public class TriggerRemovePrompt extends StringPrompt {
try { try {
index = Math.max(0, Integer.parseInt(input) - 1); index = Math.max(0, Integer.parseInt(input) - 1);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Messaging Messaging.sendErrorTr((CommandSender) context.getForWhom(),
.sendErrorTr((CommandSender) context.getForWhom(), Messages.WAYPOINT_TRIGGER_REMOVE_INVALID_NUMBER); Messages.WAYPOINT_TRIGGER_REMOVE_INVALID_NUMBER);
return this; return this;
} }
List<WaypointTrigger> triggers = editor.getCurrentWaypoint().getTriggers(); List<WaypointTrigger> triggers = editor.getCurrentWaypoint().getTriggers();

View File

@ -6,12 +6,11 @@ import org.bukkit.conversations.Prompt;
/** /**
* Marker interface for waypoint trigger prompts. * Marker interface for waypoint trigger prompts.
* *
* Prompts are expected to return to the prompt specified under the * Prompts are expected to return to the prompt specified under the {@link #RETURN_PROMPT_KEY} key in the
* {@link #RETURN_PROMPT_KEY} key in the {@link ConversationContext} and to set * {@link ConversationContext} and to set the specified trigger under {@link #CREATED_TRIGGER_KEY} prior to returning.
* the specified trigger under {@link #CREATED_TRIGGER_KEY} prior to returning.
* *
* If the returned trigger is <code>null</code> then the prompt is assumed to * If the returned trigger is <code>null</code> then the prompt is assumed to have failed and an error message will be
* have failed and an error message will be displayed. * displayed.
*/ */
public interface WaypointTriggerPrompt extends Prompt { public interface WaypointTriggerPrompt extends Prompt {
static final String CREATED_TRIGGER_KEY = "created-trigger"; static final String CREATED_TRIGGER_KEY = "created-trigger";

View File

@ -26,8 +26,8 @@ public class Anchor {
public Anchor(String name, Location location) { public Anchor(String name, Location location) {
this.location = location; this.location = location;
this.name = name; this.name = name;
this.unloaded_value = location.getWorld().getName() + ';' this.unloaded_value = location.getWorld().getName() + ';' + location.getX() + ';' + location.getY() + ';'
+ location.getX() + ';' + location.getY() + ';' + location.getZ(); + location.getZ();
} }
public boolean isLoaded() { public boolean isLoaded() {
@ -37,8 +37,8 @@ public class Anchor {
public boolean load() { public boolean load() {
try { try {
String[] parts = getUnloadedValue(); String[] parts = getUnloadedValue();
this.location = new Location(Bukkit.getWorld(parts[0]), this.location = new Location(Bukkit.getWorld(parts[0]), Double.valueOf(parts[1]), Double.valueOf(parts[2]),
Double.valueOf(parts[1]), Double.valueOf(parts[2]), Double.valueOf(parts[3])); Double.valueOf(parts[3]));
} catch (Exception e) { } catch (Exception e) {
// Still not able to be loaded // Still not able to be loaded
} }
@ -67,8 +67,8 @@ public class Anchor {
} }
/** /**
* Returns a String[] of the 'world_name, x, y, z' information needed to create the Location * Returns a String[] of the 'world_name, x, y, z' information needed to create the Location that is associated with
* that is associated with the Anchor, in that order. * the Anchor, in that order.
* *
* @return a String array of the anchor's location data * @return a String array of the anchor's location data
*/ */
@ -89,7 +89,8 @@ public class Anchor {
@Override @Override
public String toString() { public String toString() {
String[] parts = getUnloadedValue(); String[] parts = getUnloadedValue();
return "Anchor{Name='" + name + "';World='" + parts[0] + "';Location='" + parts[1] + ',' + parts[2] + ',' + parts[3] + "';}"; return "Anchor{Name='" + name + "';World='" + parts[0] + "';Location='" + parts[1] + ',' + parts[2] + ','
+ parts[3] + "';}";
} }
} }

View File

@ -95,8 +95,8 @@ public class NMS {
if (!flag) if (!flag)
return; return;
if (i > 0) { if (i > 0) {
target.g(-Math.sin(handle.yaw * Math.PI / 180.0F) * i * 0.5F, 0.1D, Math.cos(handle.yaw * Math.PI / 180.0F) target.g(-Math.sin(handle.yaw * Math.PI / 180.0F) * i * 0.5F, 0.1D,
* i * 0.5F); Math.cos(handle.yaw * Math.PI / 180.0F) * i * 0.5F);
handle.motX *= 0.6D; handle.motX *= 0.6D;
handle.motZ *= 0.6D; handle.motZ *= 0.6D;
} }
@ -180,8 +180,8 @@ public class NMS {
float f5 = 0.91F; float f5 = 0.91F;
if (entity.onGround) { if (entity.onGround) {
f5 = entity.world.getType( f5 = entity.world
new BlockPosition(MathHelper.floor(entity.locX), .getType(new BlockPosition(MathHelper.floor(entity.locX),
MathHelper.floor(entity.getBoundingBox().b) - 1, MathHelper.floor(entity.locZ))) MathHelper.floor(entity.getBoundingBox().b) - 1, MathHelper.floor(entity.locZ)))
.getBlock().frictionFactor * 0.91F; .getBlock().frictionFactor * 0.91F;
} }
@ -197,8 +197,8 @@ public class NMS {
entity.a(f, f1, f3); entity.a(f, f1, f3);
f5 = 0.91F; f5 = 0.91F;
if (entity.onGround) { if (entity.onGround) {
f5 = entity.world.getType( f5 = entity.world
new BlockPosition(MathHelper.floor(entity.locX), .getType(new BlockPosition(MathHelper.floor(entity.locX),
MathHelper.floor(entity.getBoundingBox().b) - 1, MathHelper.floor(entity.locZ))) MathHelper.floor(entity.getBoundingBox().b) - 1, MathHelper.floor(entity.locZ)))
.getBlock().frictionFactor * 0.91F; .getBlock().frictionFactor * 0.91F;
} }
@ -224,9 +224,11 @@ public class NMS {
entity.motY = 0.2D; entity.motY = 0.2D;
} }
if ((entity.world.isClientSide) if ((entity.world.isClientSide) && ((!entity.world
&& ((!entity.world.isLoaded(new BlockPosition((int) entity.locX, 0, (int) entity.locZ))) || (!entity.world .isLoaded(new BlockPosition((int) entity.locX, 0, (int) entity.locZ)))
.getChunkAtWorldCoords(new BlockPosition((int) entity.locX, 0, (int) entity.locZ)).o()))) { || (!entity.world
.getChunkAtWorldCoords(new BlockPosition((int) entity.locX, 0, (int) entity.locZ))
.o()))) {
if (entity.locY > 0.0D) if (entity.locY > 0.0D)
entity.motY = -0.1D; entity.motY = -0.1D;
else else
@ -255,8 +257,8 @@ public class NMS {
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private static Constructor<?> getCustomEntityConstructor(Class<?> clazz, EntityType type) throws SecurityException, private static Constructor<?> getCustomEntityConstructor(Class<?> clazz, EntityType type)
NoSuchMethodException { throws SecurityException, NoSuchMethodException {
Constructor<?> constructor = ENTITY_CONSTRUCTOR_CACHE.get(clazz); Constructor<?> constructor = ENTITY_CONSTRUCTOR_CACHE.get(clazz);
if (constructor == null) { if (constructor == null) {
constructor = clazz.getConstructor(World.class); constructor = clazz.getConstructor(World.class);
@ -485,8 +487,9 @@ public class NMS {
} }
public static void sendPlayerlistPacket(boolean showInPlayerlist, Player npc) { public static void sendPlayerlistPacket(boolean showInPlayerlist, Player npc) {
PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo(showInPlayerlist ? EnumPlayerInfoAction.ADD_PLAYER PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo(
: EnumPlayerInfoAction.REMOVE_PLAYER, ((CraftPlayer) npc).getHandle()); showInPlayerlist ? EnumPlayerInfoAction.ADD_PLAYER : EnumPlayerInfoAction.REMOVE_PLAYER,
((CraftPlayer) npc).getHandle());
sendToOnline(packet); sendToOnline(packet);
} }

View File

@ -74,8 +74,8 @@ public enum PlayerAnimation {
SLEEP { SLEEP {
@Override @Override
protected void playAnimation(EntityPlayer player, int radius) { protected void playAnimation(EntityPlayer player, int radius) {
PacketPlayOutBed packet = new PacketPlayOutBed(player, new BlockPosition((int) player.locX, PacketPlayOutBed packet = new PacketPlayOutBed(player,
(int) player.locY, (int) player.locZ)); new BlockPosition((int) player.locX, (int) player.locY, (int) player.locZ));
sendPacketNearby(packet, player, radius); sendPacketNearby(packet, player, radius);
} }
}, },

View File

@ -20,10 +20,10 @@ import java.util.concurrent.locks.ReentrantLock;
/** /**
* <p> * <p>
* Very fast pseudo random number generator. See <a href= * Very fast pseudo random number generator. See
* "http://school.anhb.uwa.edu.au/personalpages/kwessen/shared/Marsaglia03.html" * <a href= "http://school.anhb.uwa.edu.au/personalpages/kwessen/shared/Marsaglia03.html" >this page</a> for a
* >this page</a> for a description. This RNG has a period of about 2^160, which * description. This RNG has a period of about 2^160, which is not as long as the {@link MersenneTwisterRNG} but it is
* is not as long as the {@link MersenneTwisterRNG} but it is faster. * faster.
* </p> * </p>
* *
* <p> * <p>
@ -103,8 +103,8 @@ public class XORShiftRNG extends Random {
private static final long serialVersionUID = -1843001897066722618L; private static final long serialVersionUID = -1843001897066722618L;
/** /**
* Take four bytes from the specified position in the specified block and * Take four bytes from the specified position in the specified block and convert them into a 32-bit int, using the
* convert them into a 32-bit int, using the big-endian convention. * big-endian convention.
* *
* @param bytes * @param bytes
* The data to read from. * The data to read from.
@ -118,8 +118,8 @@ public class XORShiftRNG extends Random {
} }
/** /**
* Convert an array of bytes into an array of ints. 4 bytes from the input * Convert an array of bytes into an array of ints. 4 bytes from the input data map to a single int in the output
* data map to a single int in the output data. * data.
* *
* @param bytes * @param bytes
* The data to read from. * The data to read from.

View File

@ -61,8 +61,8 @@ public class PlayerNavigation extends NavigationAbstract {
BlockPosition localBlockPosition = new BlockPosition(this.b); BlockPosition localBlockPosition = new BlockPosition(this.b);
int k = (int) (f1 + 8.0F); int k = (int) (f1 + 8.0F);
ChunkCache localChunkCache = new ChunkCache(this.c, localBlockPosition.a(-k, -k, -k), localBlockPosition.a(k, ChunkCache localChunkCache = new ChunkCache(this.c, localBlockPosition.a(-k, -k, -k),
k, k), 0); localBlockPosition.a(k, k, k), 0);
PathEntity localPathEntity = this.j.a(localChunkCache, this.b, paramBlockPosition, f1); PathEntity localPathEntity = this.j.a(localChunkCache, this.b, paramBlockPosition, f1);
this.c.methodProfiler.b(); this.c.methodProfiler.b();
return localPathEntity; return localPathEntity;
@ -95,8 +95,8 @@ public class PlayerNavigation extends NavigationAbstract {
BlockPosition localBlockPosition = new BlockPosition(this.b).up(); BlockPosition localBlockPosition = new BlockPosition(this.b).up();
int k = (int) (f1 + 16.0F); int k = (int) (f1 + 16.0F);
ChunkCache localChunkCache = new ChunkCache(this.c, localBlockPosition.a(-k, -k, -k), localBlockPosition.a(k, ChunkCache localChunkCache = new ChunkCache(this.c, localBlockPosition.a(-k, -k, -k),
k, k), 0); localBlockPosition.a(k, k, k), 0);
PathEntity localPathEntity = this.j.a(localChunkCache, this.b, paramEntity, f1); PathEntity localPathEntity = this.j.a(localChunkCache, this.b, paramEntity, f1);
this.c.methodProfiler.b(); this.c.methodProfiler.b();
return localPathEntity; return localPathEntity;
@ -411,13 +411,14 @@ public class PlayerNavigation extends NavigationAbstract {
} }
int i = (int) this.b.getBoundingBox().b; int i = (int) this.b.getBoundingBox().b;
Block localBlock = this.c.getType( Block localBlock = this.c
new BlockPosition(MathHelper.floor(this.b.locX), i, MathHelper.floor(this.b.locZ))).getBlock(); .getType(new BlockPosition(MathHelper.floor(this.b.locX), i, MathHelper.floor(this.b.locZ))).getBlock();
int j = 0; int j = 0;
while ((localBlock == Blocks.FLOWING_WATER) || (localBlock == Blocks.WATER)) { while ((localBlock == Blocks.FLOWING_WATER) || (localBlock == Blocks.WATER)) {
i++; i++;
localBlock = this.c.getType( localBlock = this.c
new BlockPosition(MathHelper.floor(this.b.locX), i, MathHelper.floor(this.b.locZ))).getBlock(); .getType(new BlockPosition(MathHelper.floor(this.b.locX), i, MathHelper.floor(this.b.locZ)))
.getBlock();
j++; j++;
if (j > 16) { if (j > 16) {
return (int) this.b.getBoundingBox().b; return (int) this.b.getBoundingBox().b;

View File

@ -25,7 +25,8 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
public void updatePlayer(final EntityPlayer entityplayer) { public void updatePlayer(final EntityPlayer entityplayer) {
if (entityplayer != this.tracker && c(entityplayer)) { if (entityplayer != this.tracker && c(entityplayer)) {
if (!this.trackedPlayers.contains(entityplayer) if (!this.trackedPlayers.contains(entityplayer)
&& ((entityplayer.u().getPlayerChunkMap().a(entityplayer, this.tracker.ae, this.tracker.ag)) || (this.tracker.attachedToPlayer))) { && ((entityplayer.u().getPlayerChunkMap().a(entityplayer, this.tracker.ae, this.tracker.ag))
|| (this.tracker.attachedToPlayer))) {
if ((this.tracker instanceof EntityPlayer)) { if ((this.tracker instanceof EntityPlayer)) {
Player player = ((EntityPlayer) this.tracker).getBukkitEntity(); Player player = ((EntityPlayer) this.tracker).getBukkitEntity();
if (!entityplayer.getBukkitEntity().canSee(player)) { if (!entityplayer.getBukkitEntity().canSee(player)) {
@ -37,7 +38,8 @@ public class PlayerlistTrackerEntry extends EntityTrackerEntry {
@Override @Override
public void run() { public void run() {
entityplayer.playerConnection.sendPacket(new PacketPlayOutPlayerInfo( entityplayer.playerConnection.sendPacket(new PacketPlayOutPlayerInfo(
PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, (EntityPlayer) tracker)); PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER,
(EntityPlayer) tracker));
} }
}.runTaskLater(CitizensAPI.getPlugin(), 2); }.runTaskLater(CitizensAPI.getPlugin(), 2);
} }