Now i know there are many gun plugins out there but I have been trying to create one myself. At first I was making it complicated and using ammo and stuff but I had so much trouble so I just ignored it. I have striped my code down but snowballs still will not launch while right clicking with an iron hoe. Code: public class IronHoeListener { @EventHandler public void IronHoe(PlayerInteractEvent evt) { if (evt.getAction() == Action.RIGHT_CLICK_AIR) { Player p3 = evt.getPlayer(); ItemStack it1 = p3.getItemInHand(); int item1 = it1.getTypeId(); if (item1 == 292) { p3.launchProjectile(Snowball.class); } } } }
33pwnt33 In your onEnable(): Code:java PluginManager pm = this.getServer().getPluginManager();pm.registerEvents(new IronHoeListener(), this);
Because this guy wants to make his own plugin, and your plugin is something completely different anyways.
Code: @EventHandler public void onInteract2434(PlayerInteractEvent event ) { Player p = event.getPlayer(); Inventory pi = p.getInventory(); ItemStack ammo = new ItemStack(Material.SEEDS); if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { if(p.getItemInHand().getType() == Material.STONE_HOE && pi.containsAtLeast(ammo, 1) && p.getItemInHand().getDurability() <= 131 && tc.cod.containsKey(p.getName())) { event.setCancelled(true); p.getItemInHand().setDurability((short) (p.getItemInHand().getDurability() + 25)); pi.removeItem(new ItemStack (Material.SEEDS, 1)); p.updateInventory(); p.playEffect(p.getEyeLocation(), Effect.SMOKE, 1); p.playSound(p.getLocation(), Sound.LAVA_POP, 1, 1); p.launchProjectile(Snowball.class);
I see you have fixed it, but i also coded guns, ill just post the code here, i hope it might help you (diam hoe = rocket launcher, gold hoe = gun) @EventHandler(priority = EventPriority.LOWEST) public void onPlayerInteractEvent(PlayerInteractEvent event){ Player player = event.getPlayer(); if (event.getAction().equals(Action.RIGHT_CLICK_AIR)){ if (player.getItemInHand().toString().contains("GOLD_HOE")){ if (cg == true){ cg = false; player.getInventory().remove(Material.SULPHUR); Arrow a = player.launchProjectile(Arrow.class); a.setVelocity(a.getVelocity().multiply(3)); player.setVelocity(player.getVelocity().multiply(-0.3)); a.getLocation().getWorld().playEffect(a.getLocation(), Effect.SMOKE, a.getLocation().getDirection().hashCode() , 10); a.getLocation().getWorld().playEffect(a.getLocation(), Effect.SMOKE, a.getLocation().getDirection().hashCode() , 10); player.getWorld().playSound(player.getLocation(),Sound.ITEM_BREAK,5, 0); player.setVelocity(player.getLocation().getDirection().multiply(-0.4)); }else{ cg = true; } }else if (player.getItemInHand().toString().contains("DIAMOND_HOE")){ if (cs <= 1){ cs = 4; player.getInventory().remove(Material.SULPHUR); Arrow a = player.launchProjectile(Arrow.class); diamond.add(a.getUniqueId()); a.setVelocity(a.getVelocity().multiply(0.6)); a.getLocation().getWorld().playEffect(a.getLocation(), Effect.SMOKE, a.getLocation().getDirection().hashCode() , 20); a.getLocation().getWorld().playEffect(a.getLocation(), Effect.MOBSPAWNER_FLAMES, a.getLocation().getDirection().hashCode() , 10); player.getWorld().playSound(player.getLocation(),Sound.FIZZ,5, 0); player.setVelocity(player.getLocation().getDirection().multiply(-0.6)); }else{ cs--; } } } //}else{ //if (said == false){ //said = true; //Bukkit.getServer().broadcastMessage(ChatColor.GREEN + "[Guns] Whoa, lots of gun usage here, why dont you cool it down a bit?"); //Bukkit.getServer().broadcastMessage(ChatColor.GREEN + "Whoa, lots of gun usage here, why dont you cool it down a bit?"); //} //} } @EventHandler(priority = EventPriority.LOWEST) public void onProjectileHitEvent(ProjectileHitEvent event){ Entity ent = event.getEntity(); if (ent instanceof Arrow){ Arrow arrow = (Arrow) ent; if (diamond.contains(arrow.getUniqueId())){ arrow.getWorld().createExplosion(arrow.getLocation(), 3.5F); diamond.remove(arrow.getUniqueId()); ent.remove(); } } So, for gold hoe, it shoots arrow and gives it lots of velocity, then for diamond, it stores the UUID in an arraylist, then gets the arrow onProjectileHitEvent, and makes it explode (made seperate plugin where ALL arrows explode, so the arrows would explode on impact)