Code: package infection; import java.util.ArrayList; import java.util.List; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.entity.EntityType; import org.bukkit.entity.LightningStrike; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; import infection.zombies; public class survivors extends JavaPlugin implements Listener{ List<Player> survivorslist = new ArrayList<Player>(); List<Player> zombieslist = new ArrayList<Player>(); @EventHandler(priority = EventPriority.NORMAL) public void join(PlayerJoinEvent event){ Player player = event.getPlayer(); if(!zombieslist.contains(player)){ //checks to see if the player is already in the list player.setDisplayName(ChatColor.GREEN + "[SURVIVOR] " + ChatColor.WHITE + player.getName() + ChatColor.WHITE); survivorslist.add(player); } } @EventHandler(priority = EventPriority.NORMAL) public void join(PlayerQuitEvent event){ Player player = event.getPlayer(); if(survivorslist.contains(player)){ //checks to see if the player is already in the list player.setDisplayName(ChatColor.RED + "[DEAD] " + ChatColor.DARK_RED + player.getName() + ChatColor.GRAY); survivorslist.remove(player); zombieslist.add(player); } } @EventHandler(priority = EventPriority.NORMAL) public void infection(PlayerDeathEvent event){ Player victim = event.getEntity().getPlayer(); Player killer = victim.getKiller(); Location location = victim.getLocation(); if(!zombieslist.contains(victim)){ //checks to see if the player is already in the list zombieslist.add(victim); //adds the player to the list Bukkit.broadcastMessage(ChatColor.DARK_RED + victim.getName() + " was slain by " + (killer).getDisplayName()); victim.setDisplayName(ChatColor.RED + "[DEAD] " + ChatColor.DARK_RED + victim.getName() + ChatColor.GRAY); } } @EventHandler(priority = EventPriority.NORMAL) public void preventPlace(BlockPlaceEvent event){ Player player = event.getPlayer(); if(zombieslist.contains(player)){ //checks to see if the player is in list event.setCancelled(true); // cancels event player.sendMessage("You are not allowed to place blocks as a Zombie!!"); } } @EventHandler(priority = EventPriority.NORMAL) public void preventBreak(BlockBreakEvent event){ Player player = event.getPlayer(); if(zombieslist.contains(player)){ //checks to see if the player is in list event.setCancelled(true); // cancels event player.sendMessage("You are not allowed to break blocks as a Zombie!!"); } } } I want it so when a player dies, they are added to the dead list. If a player is a survivor and leaves and joins back, they are also added to the dead list. (to prevent cheaters)
Use String to store player's name instead of Player object which changes and that's why you get weird results.
Code: List<String> survivorslist = new ArrayList<String>(); List<String> zombieslist = new ArrayList<String>(); And replace every code where you add, check or remove a player to player.getName()... example: Code: if(!zombieslist.contains(player.getName())){ Something unrelated tough, can a player be anything other than zombie or survivor ? If he can't, you can remove the survivorslist and check if player is not zombie where you'd check if he's survivor.
I don't know why people have this problem. I store Player objects in Lists and HashMaps all the time, and I've never encountered this issue.
Error paradise Code: [SIZE=12px][FONT=Arial][COLOR=#000000]2012-06-04 17:40:14 [SEVERE] Could not pass event PlayerDeathEvent to Zombies[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]org.bukkit.event.EventException[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:304)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:459)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerDeathEvent(CraftEventFactory.java:322)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at net.minecraft.server.EntityPlayer.die(EntityPlayer.java:173)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at net.minecraft.server.EntityLiving.damageEntity(EntityLiving.java:677)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at net.minecraft.server.EntityHuman.damageEntity(EntityHuman.java:595)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at net.minecraft.server.EntityPlayer.damageEntity(EntityPlayer.java:215)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at net.minecraft.server.EntityLiving.a(EntityLiving.java:862)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at net.minecraft.server.EntityHuman.a(EntityHuman.java:1134)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at net.minecraft.server.Entity.a(Entity.java:780)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at net.minecraft.server.EntityPlayer.b(EntityPlayer.java:467)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:414)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at net.minecraft.server.Packet10Flying.handle(SourceFile:126)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at net.minecraft.server.NetworkManager.b(NetworkManager.java:229)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:113)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:78)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:567)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]Caused by: java.lang.NullPointerException[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at infection.survivors.infection(survivors.java:78)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at java.lang.reflect.Method.invoke(Unknown Source)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302)[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000]... 19 more[/COLOR][/FONT][/SIZE] [SIZE=12px][FONT=Arial][COLOR=#000000] [/COLOR][/FONT][/SIZE]
Caused by: java.lang.NullPointerException at infection.survivors.infection(survivors.java:78) I don't know what's on line 78 that could be null.
Code: Bukkit.broadcastMessage(ChatColor.DARK_RED + victim.getName() + " was slain by " + (killer).getDisplayName()); @Digi
Could killer be null if player suicided ? If you know what in-game action triggered the error, print the values of victim and killer and see which one returns null.