Hi! I was wondering how I could pop players: when you punch a player they dissapear. I just need an event, I know the rest of the code. I tried EntityDamageByEntityEvent, but pvp had to be on. If anyone has an idea for a better event, please let me know Thanks!
You need VanishNoPacket. When you hit the player, make the player invisible to the hitter and then do the particle effects
No you don't. player.hidePlayer(); or something along that lines. sgavster You can try PlayerInteractEvent and check if a player is in line of sight. Also, you can make PvP on and listen for EntityDamageByEntity event. Then cancel the event when you are done.
mattrick16 How would I do that? And yes; I could, but this is for a public plugin (SimplyHub) I also tried PlayerInteractEntityEvent but you can only use 1 action; which is right_click
sgavster Why dont you try a PlayerInteractEntityEvent? http://jd.bukkit.org/rb/apidocs/org/bukkit/event/player/PlayerInteractEntityEvent.html
sgavster You need to use PlayerInteractEvent and guess the entity the player might have hit based on where they're looking. However, the better way to do it is to enable PVP, listen for EntityDamageByEntityEvent, and cancel damage.
The_Doctor_123 How would I check for players though? nearbyEntities? And yes, but it causes problems, because of world-guard regions and things, it was a 'complaint' on my plugin, so I'm doing my best to fix it
The projectile hit would make things a lot simpler, and wouldn't have to allow pvp etc. on your server
sgavster I'm letting you do the code on your own. You should get the player's line of sight and check if there's any extremely close entities by the first few blocks in sight. But like I said, turning on PVP would make this way more accurate and easier to code.
The_Doctor_123 I was thinking this: Code:java BlockIterator blocksToAdd = new BlockIterator(d.getLocation(), 0.0D, 3); Location blockToAdd; while(blocksToAdd.hasNext()) { blockToAdd = blocksToAdd.next().getLocation(); } But I can't figure out how to get nearbyEntities from a location, so I'm sorta stuck
sgavster Iterate through all the players in the world and check the distance between the Location and all the players' Locations.
The_Doctor_123 How?.. I know to loop all of the players, but I can't figure out how to get the distance
The_Doctor_123 Okay, I tried this: Code:java for(Player o : Bukkit.getOnlinePlayers()){if(o.getLocation().distance(d.getLocation()) <= 3){//my code}} But it doesn't work
sgavster Well, it's probably the code you're not showing that's the issue. But seriously.... just turn PVP on..
That ought to work (I think)- what is "d" though? (one-character variable names for the lose!) If d is within 3 blocks of a player (including vertically!) I think that should be working... One note, though, since you're looping through all players and potentially doing this a lot (if someone is punching over and over)- use distanceSquared instead of distance. E.g. if (o.getLocation().distanceSquared(d.getLocation()) <= 9) - you have to also square your target distance, but it's much more efficient this way.
NathanWolf d = a player variable The_Doctor_123 PVP: This is all my code, I don't think it's my code cause this worked with EntityDamageByEntityEvent. Code:java package me.sgavster.SimplyHub.listeners; import java.util.List;import java.util.logging.Level; import me.sgavster.SimplyHub.FireworkEffectPlayer;import me.sgavster.SimplyHub.SimplyHub; import org.bukkit.Bukkit;import org.bukkit.ChatColor;import org.bukkit.Color;import org.bukkit.Effect;import org.bukkit.FireworkEffect;import org.bukkit.FireworkEffect.Type;import org.bukkit.Sound;import org.bukkit.World;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.Action;import org.bukkit.event.player.PlayerInteractEvent;import org.bukkit.event.player.PlayerJoinEvent; public class PopHandler implements Listener{ public static SimplyHub plugin; public PopHandler(SimplyHub instance) { plugin = instance; } FireworkEffectPlayer f = new FireworkEffectPlayer(); @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onDamage(PlayerInteractEvent e) { if(plugin.getConfig().getBoolean("allow_player_pop")) { if(e.getAction() == Action.LEFT_CLICK_AIR) { List<String> list = plugin.getConfig().getStringList("Enabled_Worlds"); for(String s : list) { try { World w = Bukkit.getWorld(s); Player d = e.getPlayer(); if(d.getWorld().equals(w)) { try { for(Player o : Bukkit.getOnlinePlayers()) { if(o.getLocation().distance(d.getLocation()) <= 3) { if(o.hasPermission("simplyhub.hide.exempt")) { d.sendMessage("You can't pop that player!"); } else { f.playFirework(d.getWorld(), o.getLocation(), FireworkEffect.builder().flicker(false).trail(false).with(Type.BURST).withColor(Color.ORANGE).withFade(Color.GREEN).build()); d.getWorld().playEffect(o.getLocation(), Effect.ENDER_SIGNAL, 1); d.getWorld().playEffect(o.getLocation(), Effect.MOBSPAWNER_FLAMES, 1); d.getWorld().playEffect(o.getLocation(), Effect.SMOKE, 1); d.getWorld().playSound(o.getLocation(), Sound.CHICKEN_EGG_POP, 1, 10); d.hidePlayer(o); d.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("pop_player_message").replace("%p%", o.getName()))); } } } } catch (Exception ex) { Bukkit.getLogger().log(Level.SEVERE, "§c[SimplyHub] Could not play firework!"); } } } catch (Exception ex) { Bukkit.getLogger().log(Level.SEVERE, "§c[SimplyHub] the config list Enabled_Worlds is wrong!"); } } } } } @EventHandler public void onJoin(PlayerJoinEvent e) { for(Player p : Bukkit.getOnlinePlayers()) { e.getPlayer().showPlayer(p); } }}
In all seriousness, those variable names make it much harder to understand what's going on there. That said- are you sure this is making it past your Enabled_Worlds check? Stick a log print in there (this is always a good idea if you're not sure how far your code is getting- trace and find out!) Otherwise, I can see a problem with this, but not a "it won't work" problem. You should make sure that the player and the target player are both in the same world... meaning I don't think you need to loop through worlds at all. Get the world the player is in, make sure it's in your list of enabled worlds- and then only do the distance check for other players that are in that world. (And really do use distanceSquared)
NathanWolf The world works. I know it does (I have it in other methods, and this worked before with EntityDamageByEntityEvent) How would I do distanceSquared?.
sgavster distanceSquared() returns a raw distance that hasn't been square rooted. This increases performance.
Hrm- well, I guess I'd suggest you start by refactoring a bit as in my last post. You don't need to loop over worlds, just check for players in the same world as the current player. If it's still broken after that, add some log prints and find out where it's failing- if you're still stuck, post the code and log output. When using distanceSquared, make sure to also square your target distance (e.g. 3 blocks == 9)