1

Get Player who got hit by snowball? - Bukkit Plugin Help!

Bright_Steel's Avatar Bright_Steel3/3/15 6:34 pm
1 emeralds 1.7k 7
3/3/2015 11:10 pm
searchndstroy's Avatar searchndstroy
So I'm trying to make a bukkit plugin, and it's supposed to prevent players from getting damage when hit by snowballs. It's also supposed to spawn a snowball into a player's inventory when they get hit. Right now, all it does is prevent the player from getting damage, but doesn't spawn a snowball into the player's inventory. Anyone know what I did wrong? This is my code so far:

@EventHandler
public void onSnowballHit(EntityDamageByEntityEvent event) {
Entity thrownEntity = event.getEntity();
if (thrownEntity.getType().equals(Material.SNOW_BALL)) {
if (event.getDamager() instanceof Player) {
Player thrower = (Player) event.getDamager();
Player hitPlayer = (Player) event.getEntity();
event.setCancelled(true);
hitPlayer.getInventory().addItem(
new ItemStack(Material.SNOW_BALL, 1));
hitPlayer.sendMessage(AQUA
+ "A snowball was added to your inventory by"
+ thrower.getDisplayName());

}
}
}
Posted by Bright_Steel's Avatar
Bright_Steel
Level 33 : Artisan Architect
17

Create an account or sign in to comment.

7

1
03/03/2015 11:10 pm
Level 14 : Journeyman Modder
searchndstroy
searchndstroy's Avatar
Well whoops, I checked your code wrong.

Change 'if (thrownEntity.getType().equals(Material.SNOW_BALL))' to
'if (thrownEntity.getType() == EntityType.SNOW_BALL))'
1
03/03/2015 10:12 pm
Level 33 : Artisan Architect
Bright_Steel
Bright_Steel's Avatar
http://pastebin.com/JeLbYzS9

I changed it a bit, theres my code ^

But it still doesn't work.
1
03/03/2015 7:51 pm
Level 33 : Artisan Architect
Bright_Steel
Bright_Steel's Avatar
I tried removing the event.setCancelled(true); but it still doesn't spawn snowballs in the target's inventory. Any other suggestions?
1
03/03/2015 8:33 pm
Level 7 : Apprentice Modder
escape9179
escape9179's Avatar
Did you register the event in the event in the onEnable() method. Maybe you could put your code in hastebin so I can read it better?
1
03/03/2015 7:00 pm
Level 7 : Apprentice Modder
escape9179
escape9179's Avatar
Probably because you are cancelling the event.
1
03/03/2015 6:57 pm
Level 17 : Journeyman Miner
OfficiallBlox
OfficiallBlox's Avatar
Try asking on spigot.
1
03/03/2015 6:44 pm
Level 14 : Journeyman Modder
searchndstroy
searchndstroy's Avatar
The entity attacking can also be a snowball entity. Check for that.
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome