I just would like to know an example of say a player right clciking another player with a certain item and how to get the player clicked, the player and the item
Try that (The code is not tested :/): Code (Text): @EventHandler public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) { if (event.getRightClicked().getType().equals(EntityType.PLAYER)) { //Do somethings } }
^ Don't try use that, along the right lines but almost all the names are wrong (guessing it was done outside of an ide, so no worries . Use PlayerInteractEntityEvent, then check if e.getEntity is instanceof Player. I personally would avoid using entity types.
Code (Text): public void onEnable() { getConfig().options().copyDefaults(true); saveConfig(); getServer().getPluginManager().registerEvents(this, this); hoeMeta.setDisplayName(ChatColor.BLUE + "Freeze"); ArrayList<String> lores = new ArrayList<String>(); lores.add(ChatColor.AQUA + "Right click a player to freeze them!"); hoeMeta.setLore(lores); hoe.setItemMeta(hoeMeta); } public void onInventory(PlayerInteractEntityEvent e) { Player p = e.getPlayer(); p.sendMessage("DEBUG"); if (e.getRightClicked().getType().equals(EntityType.PLAYER) && p.getItemInHand().isSimilar(hoe)) { if (!frozen.contains(e.getRightClicked().getName())) { String name = e.getRightClicked().getName(); Player freeze = Bukkit.getPlayerExact(name); freeze.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,10000,10000)); freeze.sendMessage(colorize("&cYou have been frozen! Please join our teamspeak within 5 minutes or you will be banned! IP: Coming Soon!")); frozen.add(name); } else if (frozen.contains(e.getRightClicked().getName())) { Player freeze = (Player) e.getRightClicked(); freeze.removePotionEffect(PotionEffectType.SLOW); frozen.remove(freeze.getName()); freeze.sendMessage(colorize("&aYou have been unfrozen! Thank you for your compliance!")); } } } The DEBUG message is never set yet I have registered events
@EventHandler Your if-else statement is also busted in that if it returns false for the first check (e.g. if the entity is actually a player (And, you really should use instanceof for safety)), you'll be casting the clicked entity to Player, which might not be the case.
Ma ybe wrong, but didn´t you just forget the @EventHandler Annotation? (I never used Listeners in my Main class, so i´m not sure.) //Edit: Oh wow... i just see now that the above post tells you the same thing... I didn´t read the @-Mark as i thought he was linking a user..xD