What i will is, if you kill 100 zombies your getting an item in your inventory. and 200 anothere item and remove the first item? can someone help me with this?
jusjus112 Code:java public Map<String, Integer> kills = new HashMap<String, Integer>(); @EventHandler public void kill(EntityDeathEvent e) { Entity zombie = e.getEntity(); if (zombie instanceof Zombie) { if (((Zombie) zombie).getKiller() instanceof Player) { Player p = ((Zombie) zombie).getKiller(); if (kills.containsKey(p.getName())) { kills.put(p.getName(), kills.get(p.getName()) + 1); } else { kills.put(p.getName(), 1); } if(kills.get(p.getName()) == 100) { p.getInventory().addItem(new ItemStack(Material.DIAMOND_ORE)); } if(kills.get(p.getName()) == 200) { p.getInventory().contains(Material.DIAMOND_ORE); p.getInventory().remove(new ItemStack(Material.DIAMOND_ORE)); //Add new } } } }
DreTaX Nice, but what must i do if is saves. If the player leaves, ands again joins, then hes lost. What must i do so that e remember that every player has there own items if they killed 100 zombies. Example: a player kills 100 zombies, they get an diamond in there inventory. if an player leaves, then must remember it and getting him the item thats getting a player if they reached 100 kills
You could do a config. public FileConfiguration config; config = getConfig(); If player joins do: Main.config.set("Players.Kills." + p.getName(), kills.get(p.getName())) Later you can get it from the config. Or just what ever you would like to
This should work. Code:java private FileConfiguration config; public Map<String, Integer> kills = new HashMap<String, Integer>(); public void onEnable(){ config = this.getConfig(); saveConfig(); } @EventHandler public void join(PlayerJoinEvent e) { Player p = e.getPlayer(); if (!config.contains(p.getName() + ".Kills")) { config.set(p.getName() + ".Kills", 0); saveConfig(); kills.put(p.getName(), 0); } else { kills.put(p.getName(), config.getInt(p.getName() + ".Kills")); } } @EventHandler public void kill(EntityDeathEvent e) { Entity zombie = e.getEntity(); if (zombie instanceof Zombie) { if (((Zombie) zombie).getKiller() instanceof Player) { Player p = ((Zombie) zombie).getKiller(); if (kills.containsKey(p.getName())) { kills.put(p.getName(), kills.get(p.getName()) + 1); } if(kills.get(p.getName()) == 100) { p.getInventory().addItem(new ItemStack(Material.DIAMOND_ORE)); } else if(kills.get(p.getName()) == 200) { p.getInventory().contains(Material.DIAMOND_ORE); p.getInventory().remove(new ItemStack(Material.DIAMOND_ORE)); //Add new } } } } @EventHandler public void leave(PlayerQuitEvent e) { Player p = e.getPlayer(); config.set(p.getName() + ".Kills", kills.get(p.getName()) + 1); saveConfig(); }} Also on leave event remove the player from the kills. I guess like this: @EventHandler public void leave(PlayerQuitEvent e) { Player p = e.getPlayer(); config.set(p.getName() + ".Kills", kills.get(p.getName()) + 1); saveConfig(); kills.remove(p.getName()); } EDIT by Moderator: merged posts, please use the edit button instead of double posting.
xD np Oh shit. On leave event i made a mistake. Remove the +1 config.set(p.getName()+".Kills", kills.get(p.getName())+1); So it will be: config.set(p.getName()+".Kills", kills.get(p.getName()); EDIT by Moderator: merged posts, please use the edit button instead of double posting.
DreTaX i am usign 3 classes, but how to do the onEnable in my main class, and the itemlores e.t.c in my other class?
DreTaX Can i use your system for xp. so that players getting xp. And how do i make an command, that you see how many kills you have?
DreTaX Now if a player types /kills they see how many zombies they have killed! use the code that you have send above!
DreTaX no, i ask you him to do this? with your code? Or make an scoreboard were they can see how many kills they have
DreTaX Yes, i think you getting the player from the config, or maybe im wrong? But i dont no how to do this?
Code:java getCommand("stats").setExecutor(this); public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (args.length > 0) { if (!(sender instanceof Player)) { sender.sendMessage("You aren't a player"); return false; } else { Player p = (sender); String name = p.getName(); if (args[0].equalsIgnoreCase("kills")) { int pkills = kills.get(name); p.sendMessage(ChatColor.GREEN + "You have killed sofar: " + ChatColor.RED + pkills + ChatColor.GREEN + " zombies"; } } }return false;}
DreTaX Very thanks , my problem is now gone if this dont work! You will hear from me. DreTaX Hes is giving my this error: PHP: 21.11 19:23:58 [Multicraft] jusjus112 ran command Bericht van de dag21.11 19:23:58 [Server] INFO ... 14 more21.11 19:23:58 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)21.11 19:23:58 [Server] INFO at java.lang.reflect.Method.invoke(Method.java:601)21.11 19:23:58 [Server] INFO at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)21.11 19:23:58 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)21.11 19:23:58 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)21.11 19:23:58 [Server] INFO at Ranks.TestInventory.onPlayerJoin(TestInventory.java:53)21.11 19:23:58 [Server] INFO Caused by: java.lang.NullPointerException21.11 19:23:58 [Server] INFO at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)21.11 19:23:58 [Server] INFO at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)21.11 19:23:58 [Server] INFO at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)21.11 19:23:58 [Server] INFO at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)21.11 19:23:58 [Server] INFO at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:590)21.11 19:23:58 [Server] INFO at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:29)21.11 19:23:58 [Server] INFO at net.minecraft.server.v1_6_R2.DedicatedServerConnectionThread.a(DedicatedServerConnectionThread.java:41)21.11 19:23:58 [Server] INFO at net.minecraft.server.v1_6_R2.PendingConnection.d(PendingConnection.java:43)21.11 19:23:58 [Server] INFO at net.minecraft.server.v1_6_R2.PendingConnection.e(PendingConnection.java:133)21.11 19:23:58 [Server] INFO at net.minecraft.server.v1_6_R2.PlayerList.a(PlayerList.java:103)21.11 19:23:58 [Server] INFO at net.minecraft.server.v1_6_R2.PlayerList.c(PlayerList.java:207)21.11 19:23:58 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)21.11 19:23:58 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)21.11 19:23:58 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)21.11 19:23:58 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)21.11 19:23:58 [Server] INFO org.bukkit.event.EventException21.11 19:23:58 [Server] SEVERE Could not pass event PlayerJoinEvent to zombieRanks v0.121.11 19:23:58 [Connect] User jusjus112, IP 85.150.161.21421.11 19:23:55 [Server] INFO §ejusjus112 left the game.21.11 19:23:55 [Server] INFO ... 14 more21.11 19:23:55 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)21.11 19:23:55 [Server] INFO at java.lang.reflect.Method.invoke(Method.java:601)21.11 19:23:55 [Server] INFO at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)21.11 19:23:55 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)21.11 19:23:55 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)21.11 19:23:55 [Server] INFO at Ranks.TestInventory.leave(TestInventory.java:423)21.11 19:23:55 [Server] INFO Caused by: java.lang.NullPointerException21.11 19:23:55 [Server] INFO at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)21.11 19:23:55 [Server] INFO at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)21.11 19:23:55 [Server] INFO at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)21.11 19:23:55 [Server] INFO at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)21.11 19:23:55 [Server] INFO at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:590)21.11 19:23:55 [Server] INFO at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:30)21.11 19:23:55 [Server] INFO at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)21.11 19:23:55 [Server] INFO at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java:116)21.11 19:23:55 [Server] INFO at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:302)21.11 19:23:55 [Server] INFO at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java:688)21.11 19:23:55 [Server] INFO at net.minecraft.server.v1_6_R2.PlayerList.disconnect(PlayerList.java:259)21.11 19:23:55 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)21.11 19:23:55 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)21.11 19:23:55 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)21.11 19:23:55 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)21.11 19:23:55 [Server] INFO org.bukkit.event.EventException21.11 19:23:55 [Server] SEVERE Could not pass event PlayerQuitEvent to zombieRanks v0.1 And this is my line 423: Code:java config.set(p.getName() + ".kills", kills.get(p.getName())); And my code for line 53: Code:java if (!config.contains(p.getName() + ".kills")) { I hope you can fiks this! EDIT by Moderator: merged posts, please use the edit button instead of double posting.