Sorry I have been asking for a lot of help lately, but I have been busy with school so I'm braindead. Anyway, I am still working on the Raid code. The first wave spawns fine, but after they all die, the second wave does not spawn. I think there is an issue I can't see in the EntityDeathEvent counter. Can anyone see the problem? Code: public Player player = null; World world = null; @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (cmd.getName().equals("raidstart")) { if (sender instanceof Player) { player = (Player) sender; world = player.getWorld(); raid(1); } } return false; } public void raid(int wave) { if (wave == 1) { player.getInventory().addItem(new ItemStack(Material.STONE_SWORD)); int x = 0; int line = -6; while (x != 10) { Zombie zomb = (Zombie) world.spawnEntity(player.getLocation().add(6, 0, line), EntityType.ZOMBIE); zomb.setCustomName("Wave 1"); x++; line++; } wave = 0; } else if (wave == 2) { player.getInventory().clear(); player.getInventory().addItem(new ItemStack(Material.STONE_SWORD)); player.getInventory().setItemInOffHand(new ItemStack(Material.SHIELD)); int x = 0; int line = -6; while (x != 10) { Zombie zomb = (Zombie) world.spawnEntity(player.getLocation().add(10, 0, line), EntityType.ZOMBIE); Skeleton skele = (Skeleton) world.spawnEntity(player.getLocation().add(12, 0, line), EntityType.SKELETON); line++; x++; } wave = 0; } } public void onDeath(EntityDeathEvent event) { Entity ent = (Entity) event.getEntity(); int x = 0; if (ent.getCustomName().equals("Wave 1")) { x++; if (x == 10) { raid(2); } }
Code:Java public Player player = null; player is now a global variable, that means only ONE person who last executes the command will get the items. Even if your intention is for only one player, pass the player variable on through parameters. Code:Java public final void raid(final int wave, final Player player) { /*Ya yeet.*/ } Code:Java public void onDeath(EntityDeathEvent event) {} You forgot the annotation EventHandler. Make sure to register the class as a listener too, if you haven't. I don't know much myself, but counting general entity names seems inefficient and inaccurate to start raids, even if you're just testing. LivingEntity(s) implements the Metadatable interface, so it would be better if you assign the mobs that are spawned on raids a fixed MetadataValue, then count deaths from mobs that have that metadata value. Code:Java int x = 0;while (x != 10) { x++; } for(int x = 0; i < 10; i++) {//Eyyy} // OrIntStream.range(0, 10).forEach(x -> { /*Same thing as for loop's body*/ }); for loops exist for this purpose, or you could use IntStream. Code:Java wave = 0; Fill me in if I'm dense as frick but what is this for? You're not going to reuse the passed variables anyway, judging from your snippet. Corrections are very much welcomed.
Thank you, I didn't notice that I forgot the Event Handler. Also, I was originally going to set a metadata, but I don't know how metadata's work yet. Are they a string or an integer?
@JavaNoob It is neither a string nor an integer. It is a metadata value, bound to a Plugin with a specified name. Basically, it's just an annotation but for entities in this case.
Code:java ItemStack item = new ItemStack(Material.STONE);ItemMeta itemMeta = item.getItemMeta();itemMeta.setEnchantment(Enchantment.DAMAGE_ALL); Gah, I haven't worked with ItemStack's in a while. ItemMeta#setEnchantment is probably wrong lmao. Anyways, Shqep is sayin' that itemMeta is neither a string or an integer, but rather an annotation that MC read's as setting lore, item/entity names, enchantments, etc. You can read it by logging it or whatever like this: Code:java ItemStack item = new ItemStack(Material.STONE);ItemMeta itemMeta = item.getItemMeta();itemMeta.setEnchantment(Enchantment.DAMAGE_ALL);...public void sendMessage(Player player) { player.sendMessage("Item data: " + itemMeta} It will print something like: PHP: { enchantments: DAMAGE_ALL; id: 3 } Or whatever idk. But all that to say, ItemMeta is not a string, more like a list or whatever. Mess around with it; hope that helped. (corrections or welcome; i prob botched it but ik enough about itemmeta to help out xD)
He said "metadata", not "itemmeta". @Shqep already linked the Javadocs. I do not think there is anything else we can do except spoonfeed.