Hey Guys! I made an event and for some reason it looks like its not running? I don't know why. There isn't any errors? Could you guys help me? Code:java @EventHandler public void onClickItem1(PlayerInteractEvent event){ Player player = event.getPlayer(); if(event.getPlayer().getItemInHand().equals(Material.NETHER_STAR)) { if(event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { player.sendMessage(ChatColor.DARK_PURPLE + "Time to assassinate!"); player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 300, 0)); player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 300, 9 )); player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 300, 0)); } } }
22vortex22 Are you registering the listener? EDIT: And check if there is an item before checking what the item is.
Code:java public class EasyPvpKits extends JavaPlugin implements Listener{ @Overridepublic void onEnable() {getServer().getPluginManager().registerEvents(this, this);} I think I did
Code:java package com.gmail.codervortex; import java.util.ArrayList;import org.bukkit.ChatColor;import org.bukkit.Color;import org.bukkit.Material;import org.bukkit.command.Command;import org.bukkit.command.CommandSender;import org.bukkit.enchantments.Enchantment;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.block.Action;import org.bukkit.event.entity.PlayerDeathEvent;import org.bukkit.event.player.PlayerInteractEvent;import org.bukkit.event.player.PlayerRespawnEvent;import org.bukkit.inventory.ItemStack;import org.bukkit.inventory.meta.LeatherArmorMeta;import org.bukkit.plugin.java.JavaPlugin;import org.bukkit.potion.PotionEffect;import org.bukkit.potion.PotionEffectType; public class EasyPvpKits extends JavaPlugin implements Listener{ @Override public void onEnable() { getServer().getPluginManager().registerEvents(this, this); } ArrayList<String> kits = new ArrayList<String>(); @EventHandler public void playerDeath(PlayerDeathEvent e) { kits.remove(e.getEntity().getName()); } @EventHandler public void potionRemove(PlayerRespawnEvent e){ Player player = e.getPlayer(); for (PotionEffect effect : player.getActivePotionEffects()) player.removePotionEffect(effect.getType()); } @EventHandler public void OnPlayerSoup(PlayerInteractEvent event){ Player player = event.getPlayer(); if (player.hasPermission("EasyPvpKits.Soup")){ if(player.getHealth() == 20){ } else{ int soup = +7; if((event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() ==Action.RIGHT_CLICK_BLOCK) && player.getItemInHand().getType() == Material.MUSHROOM_SOUP){ player.setHealth(player.getHealth() + soup > player.getMaxHealth() ? player.getMaxHealth() : player.getHealth() + soup); event.getPlayer().getItemInHand().setType(Material.BOWL); } } } } @EventHandler public void onClickItem1(PlayerInteractEvent event){ Player player = event.getPlayer(); if(event.getPlayer().getItemInHand().equals(Material.NETHER_STAR)) { if(event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { player.sendMessage(ChatColor.DARK_PURPLE + "Time to assassinate!"); player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 300, 0)); player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 300, 9 )); player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 300, 0)); } } } public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { Player player = (Player) sender; if (commandLabel.equalsIgnoreCase("Pvp") && sender instanceof Player) { if (player.hasPermission("EasyPvpKits.Pvp")) { if (!kits.contains(player.getName())) { player.sendMessage(ChatColor.GOLD + "You have been given the Pvp kit!"); kits.add(player.getName()); player.getInventory().clear(); player.getInventory().addItem(new ItemStack(Material.DIAMOND_SWORD)); player.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET)); player.getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE)); player.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS)); player.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS)); for (int i = 0; i < 35; i++){ player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP)); } } else { player.sendMessage(ChatColor.RED + "You have already picked a kit!"); } } else { player.sendMessage(ChatColor.RED + "You don't have permission to recieve this kit."); } } else if (commandLabel.equalsIgnoreCase("Archer") && sender instanceof Player){ if (player.hasPermission("EasyPvpKits.Archer")){ if (!kits.contains(player.getName())){ ItemStack ABow = new ItemStack(Material.BOW); ABow.addUnsafeEnchantment(Enchantment.ARROW_INFINITE, 2); player.sendMessage(ChatColor.GOLD + "You have been given the Archer kit!"); kits.add(player.getName()); player.getInventory().clear(); player.getInventory().addItem(new ItemStack(Material.STONE_SWORD)); player.getInventory().addItem(ABow); player.getInventory().setHelmet(new ItemStack(Material.LEATHER_HELMET)); player.getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE)); player.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS)); player.getInventory().setBoots(new ItemStack(Material.LEATHER_BOOTS)); for (int i = 0; i < 33; i++){ player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP)); } player.getInventory().addItem(new ItemStack(Material.ARROW)); } else { player.sendMessage(ChatColor.RED + "You have already picked a kit!"); } } else player.sendMessage(ChatColor.RED + "You don't have permission to recieve this kit."); } else if (commandLabel.equalsIgnoreCase("Heavy") && sender instanceof Player){ if (player.hasPermission("EasyPvpKits.Heavy")){ if (!kits.contains(player.getName())){ player.sendMessage(ChatColor.GOLD + "You have been given the Heavy kit!"); kits.add(player.getName()); player.getInventory().clear(); player.getInventory().addItem(new ItemStack(Material.DIAMOND_SWORD)); player.getInventory().setHelmet(new ItemStack(Material.DIAMOND_HELMET)); player.getInventory().setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE)); player.getInventory().setLeggings(new ItemStack(Material.DIAMOND_LEGGINGS)); player.getInventory().setBoots(new ItemStack(Material.DIAMOND_BOOTS)); for (int i = 0; i < 35; i++){ player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP)); player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 1)); } } else { player.sendMessage(ChatColor.RED + "You have already picked a kit!"); } } else player.sendMessage(ChatColor.RED + "You don't have permission to recieve this kit."); } else if(commandLabel.equalsIgnoreCase("Pyro") && sender instanceof Player){ if (player.hasPermission("EasyPvpKits.Pyro")){ if (!kits.contains(player.getName())){ ItemStack Arrow = new ItemStack(Material.ARROW, 64); ItemStack SSword = new ItemStack(Material.STONE_SWORD); SSword.addEnchantment(Enchantment.FIRE_ASPECT, 1); ItemStack FBow = new ItemStack(Material.BOW); FBow.addUnsafeEnchantment(Enchantment.ARROW_FIRE, 2); player.sendMessage(ChatColor.GOLD + "You have been given the Pyro kit!"); kits.add(player.getName()); player.getInventory().clear(); player.getInventory().setHelmet(new ItemStack(Material.CHAINMAIL_HELMET)); player.getInventory().setChestplate(new ItemStack(Material.CHAINMAIL_CHESTPLATE)); player.getInventory().setLeggings(new ItemStack(Material.CHAINMAIL_LEGGINGS)); player.getInventory().setBoots(new ItemStack(Material.CHAINMAIL_BOOTS)); player.getInventory().addItem(SSword); player.getInventory().addItem(FBow); for (int i = 0; i < 33; i++){ player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP)); } player.getInventory().addItem(Arrow); } else player.sendMessage(ChatColor.RED + "You have already picked a kit!"); } else player.sendMessage(ChatColor.RED + "You don't have permission to recieve this kit."); } else if (commandLabel.equalsIgnoreCase("Assassin")){ if (player.hasPermission("EasyPvpKits.Assassin")){ if (!kits.contains(player.getName())){ ItemStack AssassinHat = new ItemStack(Material.LEATHER_HELMET); LeatherArmorMeta AHat = (LeatherArmorMeta)AssassinHat.getItemMeta(); AHat.setColor(Color.WHITE); AssassinHat.setItemMeta(AHat); AssassinHat.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1); ItemStack AssassinChest = new ItemStack(Material.LEATHER_CHESTPLATE); LeatherArmorMeta AChest = (LeatherArmorMeta)AssassinChest.getItemMeta(); AChest.setColor(Color.WHITE); AssassinChest.setItemMeta(AChest); AssassinChest.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1); ItemStack AssassinLegs = new ItemStack(Material.LEATHER_LEGGINGS); LeatherArmorMeta ALegs = (LeatherArmorMeta)AssassinLegs.getItemMeta(); ALegs.setColor(Color.WHITE); AssassinLegs.setItemMeta(ALegs); AssassinLegs.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1); ItemStack AssassinBoots = new ItemStack(Material.LEATHER_BOOTS); LeatherArmorMeta ABoots = (LeatherArmorMeta)AssassinBoots.getItemMeta(); ABoots.setColor(Color.WHITE); AssassinBoots.setItemMeta(ABoots); AssassinBoots.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1); AssassinBoots.addEnchantment(Enchantment.PROTECTION_FALL, 4); ItemStack SSword = new ItemStack(Material.STONE_SWORD); SSword.addEnchantment(Enchantment.DAMAGE_ALL, 1); SSword.addEnchantment(Enchantment.DURABILITY, 2); player.sendMessage(ChatColor.GOLD + "You have been given the Assassin kit!"); kits.add(player.getName()); player.getInventory().clear(); player.getInventory().setHelmet(AssassinHat); player.getInventory().setBoots(AssassinBoots); player.getInventory().setChestplate(AssassinChest); player.getInventory().setLeggings(AssassinLegs); player.getInventory().addItem(SSword); player.getInventory().addItem(new ItemStack(Material.NETHER_STAR)); for (int i = 0; i < 34; i++){ player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP)); } } else player.sendMessage(ChatColor.RED + "You have already picked a kit!"); } else player.sendMessage(ChatColor.RED + "You don't have permission to recieve this kit."); } else if (commandLabel.equalsIgnoreCase("Reset")){ if (player.hasPermission("EasyPvpKits.Admin")){ if (args.length == 0){ player.sendMessage(ChatColor.RED + "Do /reset (Playername) to reset their kit."); } else if (args.length == 1){ Player target = player.getServer().getPlayer(args[0]); if (kits.contains(target.getName())){ kits.remove(target.getName()); target.getInventory().clear(); target.getInventory().setArmorContents(null); for (PotionEffect effect : target.getActivePotionEffects()) target.removePotionEffect(effect.getType()); target.sendMessage(ChatColor.RED + "Your kit has been reset by a staff member!"); player.sendMessage(ChatColor.GOLD + "The player's class has been removed!"); } else player.sendMessage(ChatColor.RED + "This person has not chosen a kit!"); } } else player.sendMessage(ChatColor.RED + "You do not have permission to excute this command."); } return false; } }
22vortex22 Can you add some debugging code in? For example, after the first if statement (Nether Star), add in Code: getLogger().info("Passed Test 1"); Then after the right click if statement, add in Code: getLogger().info("Passed Test 2");
Code: name: Easy Pvp Kits version: 1.0.5 main: com.gmail.codervortex.EasyPvpKits author: Vortex description: A simple and easy to use pvp kit plugin. commands: Pvp: description: Gives the user the default pvp kit. Pyro: description: Gives the user the pyro kit. Archer: description: Gives the user the archer kit. Heavy: description: Gives the user the heavy kit. Reset: description: Resets a player's kit. Assassin: description: Gives the user the assassin kit.
This line: if(event.getPlayer().getItemInHand().equals(Material.NETHER_STAR)) { getItemInHand() returns a itemstack, which can never be equal to a Material. Add a .getType(). Also, getItemInHand() can return null, so you should check if the player actually has a item before you use it. -> if(event.hasItem() && event.getPlayer().getItemInHand().getType().equals(Material.NETHER_STAR)) {