I'm getting a NPE Error: Code: [14:30:16] [Server thread/ERROR]: Error occurred while enabling Servers v1.0 (Is it up to date?) java.lang.NullPointerException at net.buizelfan2dev.mobs.Mobs.spawnVillager(Mobs.java:52) ~[?:?] at net.buizelfan2dev.mobs.Mobs.onEnable(Mobs.java:43) ~[?:?] at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:250) ~[craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:350) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:389) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugin(CraftServer.java:439) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] at org.bukkit.craftbukkit.v1_7_R1.CraftServer.enablePlugins(CraftServer.java:375) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] at net.minecraft.server.v1_7_R1.MinecraftServer.m(MinecraftServer.java:342) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] at net.minecraft.server.v1_7_R1.MinecraftServer.g(MinecraftServer.java:319) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] at net.minecraft.server.v1_7_R1.MinecraftServer.a(MinecraftServer.java:275) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.java:175) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:424) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks] [14:30:16] And it's saying line 52 and 43 Here's all the code Code:java package net.buizelfan2dev.mobs; import de.kumpelblase2.remoteentities.EntityManager;import de.kumpelblase2.remoteentities.RemoteEntities;import de.kumpelblase2.remoteentities.api.EntitySound;import de.kumpelblase2.remoteentities.api.RemoteEntity;import de.kumpelblase2.remoteentities.api.RemoteEntityType;import de.kumpelblase2.remoteentities.api.events.RemoteEntityInteractEvent;import java.io.ByteArrayOutputStream;import java.io.DataOutputStream;import java.util.logging.Logger;import org.bukkit.Bukkit;import org.bukkit.ChatColor;import org.bukkit.Location;import org.bukkit.command.Command;import org.bukkit.command.CommandSender;import org.bukkit.entity.Entity;import org.bukkit.entity.EntityType;import org.bukkit.entity.Player;import org.bukkit.entity.Villager;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.entity.EntityDamageEvent;import org.bukkit.plugin.java.JavaPlugin; public class Mobs extends JavaPlugin implements Listener{ public final Logger logger = Logger.getLogger("Minecraft"); public static Mobs main; private Shop shop; public void onEnable() { this.shop = new Shop(this); getServer().getPluginManager().registerEvents(this, this); getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); for (Entity e : Bukkit.getWorld("world").getEntities()) { if ((e instanceof Villager)) { e.remove(); } } spawnVillager(); for (Entity e : Bukkit.getWorld("world").getEntities()) if ((e instanceof Villager)) ((Villager)e).setProfession(Villager.Profession.LIBRARIAN); } public void spawnVillager() { Player p = Bukkit.getPlayer(getName()); Location player = p.getLocation(); Location loc1 = new Location(Bukkit.getWorld("world"), 448.37535000000003D, 136.0D, 578.52853000000005D); Location loc2 = new Location(Bukkit.getWorld("world"), -26.21721D, 89.000D, -0.60274D); EntityManager manager = RemoteEntities.createManager(this); RemoteEntity creative = manager.createEntity(RemoteEntityType.Villager, loc1, false); RemoteEntity survival = manager.createEntity(RemoteEntityType.Villager, loc2, false); creative.setSound(EntitySound.RANDOM, null); creative.lookAt(player); creative.setPushable(false); creative.getBukkitEntity().setCustomName("§2Join Creative"); creative.getBukkitEntity().setCustomNameVisible(true); survival.setSound(EntitySound.RANDOM, null); survival.lookAt(player); survival.setPushable(false); survival.getBukkitEntity().setCustomName("§2Join Survival"); survival.getBukkitEntity().setCustomNameVisible(true); } @EventHandler public void openShop(RemoteEntityInteractEvent e) { Player p = e.getInteractor(); RemoteEntity entity = e.getRemoteEntity(); if (entity.getName() == "§2Join Survival") { e.setCancelled(true); this.shop.showS(p); } else if (entity.getName() == "§2Join Creative") { e.setCancelled(true); this.shop.showC(p); } } @EventHandler public void onDamage(EntityDamageEvent e) { Entity entity = e.getEntity(); if (entity.getType() == EntityType.VILLAGER) e.setCancelled(true); } public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { if (commandLabel.equalsIgnoreCase("Join")) { Player p = (Player)sender; if (!(sender instanceof Player)) { sender.sendMessage("Cant't Do This Command In Console"); return true; } if (args.length == 0) { p.sendMessage("Server Not Specified"); return true; } joinServer(p, args[0]); } return false; } public void joinServer(Player p, String targetServer) { ByteArrayOutputStream b = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(b); try { out.writeUTF("Connect"); out.writeUTF(targetServer); } catch (Exception e) { p.sendMessage(ChatColor.RED + "Survival Server Is Offline!"); } p.sendPluginMessage(this, "BungeeCord", b.toByteArray()); }} Thanks In advance
Buizelfan2 You are getting an NPE because, look at line 52, you are getting a player, no specific player, so the player is null. So when you do Location player = p.getLocation() - p doesn't have a location
What's the implementation of getName()? Your NPE assumes, that p is null => Bukkit.getPlayer(getName()) returns null. oO? The location isn't null. The p is null. If location would be null, you wouldn't get a NPE there, you'd get one when you call any method of that location object.
When the villager spawns it looks to the left and I want it to either look at where the player is or at the spawn location
public void spawnVillager(Player player) { //Change this and the above params Player p = player; } To spawn: spawnVillager(player);
I put it in the onEnable I mean everything works it just turns out like this http://imgur.com/myKEURt
Buizelfan2 Remove your Player p line, and in your spawnVillager() line add spawnVillager(Player p). EDIT: I Didn't see LordVakar
Buizelfan2 Why would you put it on the onEnable? When the server enables, there is no player on... EDIT: Why do you even need to get the player, you don't utilize it EDIT 2: You only use it to look at the player hm