Hi guys Ive been working on my 1st Java plugin, however I dont really know how to code.... I watched a video to do this, but I dont undertsand how it works, so I dont know how to do more: Code:java package me.simplerocks.uhs; import org.bukkit.Bukkit;import org.bukkit.Material;import org.bukkit.entity.Fireball;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.EntityDamageByEntityEvent;import org.bukkit.event.player.PlayerInteractEvent;import org.bukkit.plugin.java.JavaPlugin; public class UHS extends JavaPlugin implements Listener { public void onEnable() { Bukkit.getServer().getPluginManager().registerEvents(this, this); } @EventHandler public void onPlayerInteract(PlayerInteractEvent e) { if (!(e.getAction() == Action.RIGHT_CLICK_AIR)) return; if (!(e.getItem().getType() == Material.FURNACE)) return; Fireball f = e.getPlayer().launchProjectile(Fireball.class); f.setIsIncendiary(false); f.setYield(0); } @EventHandler public void onEntityDamage(EntityDamageByEntityEvent e) { if (e.getDamager() instanceof Fireball) { Fireball f = (Fireball) e.getDamager(); if (f.getShooter() instanceof Player) { Player shooter = (Player) f.getShooter(); if (shooter.getItemInHand().getType() == Material.FURNACE) { e.setDamage(10.0); } } } }} I know that that this shoots a fireball from a dispenser, ddoes 10 hearts nad dosent damage the environment, but can someone explain how it does this specifically. As well as this if I wanted to another gun underneath this, how would i do it. And how would I make it run of ammo with slight cooldowns. If possible, could you explain this like im an idiot as Im quite a java noob.
You can use http://jd.bukkit.org/rb/apidocs/ to read up on all of the code you used. For example to read about your onPlayerInteract method ctrl+f for PlayerInteractEvent. Code:java @EventHandlerpublic void onPlayerInteract(PlayerInteractEvent e) {//called every time a player interactsif (!(e.getAction() == Action.RIGHT_CLICK_AIR)) return;//checks if the player right clicked airif (!(e.getItem().getType() == Material.FURNACE)) return;//checks if the player holds a furnaceFireball f = e.getPlayer().launchProjectile(Fireball.class);//creates a fireballf.setIsIncendiary(false);//sets the fireball to not cause firef.setYield(0);//sets the fireball to have no explosion} @EventHandlerpublic void onEntityDamage(EntityDamageByEntityEvent e) {//called every time something takes damageif (e.getDamager() instanceof Fireball) {//checks if the damage is from a fireballFireball f = (Fireball) e.getDamager();//sets a variable equal to the entity that caused the damageif (f.getShooter() instanceof Player) {//checks if the damager is a playerPlayer shooter = (Player) f.getShooter();//sets a variable equal to the causer of damage playerif (shooter.getItemInHand().getType() == Material.FURNACE) {//checks if that player holds a furnacee.setDamage(10.0);//sets damage received to 10}}}}}
beaudigi The Bukkit API is hard to learn if you don't have an understanding of Java. I would spend time learning Java first, THEN learning the Bukkit API and coding. But the easiest way to learn HOW something does what it does is to follow skilcox instructions
Thankyou for all ypur support guys, I will use your methods Um but how do I Say start a new gun underneath the one posted above,, as it always comes up with an error..when I just copy paste that gun below it Code:java package me.simplerocks.uhs; import org.bukkit.Bukkit;import org.bukkit.Material;import org.bukkit.entity.Fireball;import org.bukkit.entity.Player;import org.bukkit.entity.Snowball;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.block.Action;import org.bukkit.event.entity.EntityDamageByEntityEvent;import org.bukkit.event.player.PlayerInteractEvent;import org.bukkit.plugin.java.JavaPlugin; public class UHS extends JavaPlugin implements Listener { public void onEnable() { Bukkit.getServer().getPluginManager().registerEvents(this, this); } @EventHandler public void onPlayerInteract(PlayerInteractEvent e) { //called every time a player interacts if (!(e.getAction() == Action.RIGHT_CLICK_AIR)) return; //checks if the player right clicked air if (!(e.getItem().getType() == Material.FURNACE)) return; //checks if the player holds a furnace Fireball f = e.getPlayer().launchProjectile(Fireball.class); //creates a Verbal f.setIsIncendiary(false); //sets the Verbal to not cause fire f.setYield(0); //sets the Verbal to have no explosion } @EventHandler public void onEntityDamage(EntityDamageByEntityEvent e) { //called every time something takes damage if (e.getDamager() instanceof Fireball) { //checks if the damage is from a verbal Fireball f = (Fireball) e.getDamager(); //sets a variable equal to the entity that caused the damage if (f.getShooter() instanceof Player) { //checks if the damager is a player Player shooter = (Player) f.getShooter(); //sets a variable equal to the causer of damage player if (shooter.getItemInHand().getType() == Material.FURNACE) { //checks if that player holds a furnace e.setDamage(10.0); [SIZE=5][FONT=arial black] (im Getting an error here: it says wrong syntax }. I have replaced it but it still comes up with this issue)[/FONT][/SIZE] //sets damage received to 10 @EventHandler public void onPlayerInteract1(PlayerInteractEvent e) { //called every time a player interacts if (!(e.getAction() == Action.RIGHT_CLICK_AIR)) return; //checks if the player right clicked air if (!(e.getItem().getType() == Material.INK_SACK)) return; //checks if the player holds a furnace Snowball s = e.getPlayer().launchProjectile(Snowball.class); } @EventHandler public void onEntityDamage1(EntityDamageByEntityEvent e) { //called every time something takes damage if (e.getDamager() instanceof Snowball) { //checks if the damage is from a verbal Snowball s = (Snowball) e.getDamager(); //sets a variable equal to the entity that caused the damage if (s.getShooter() instanceof Player) { //checks if the damager is a player Player shooter = (Player) s.getShooter(); //sets a variable equal to the causer of damage player if (shooter.getItemInHand().getType() == Material.INK_SACK) { //checks if that player holds a furnace e.setDamage(2.0); //sets damage received to 10 } } } }} ' Btw How do I add ammo and a cooldown, ive been watching some more vids, but I think its easier when you guys explain it EDIT by Moderator: merged posts, please use the edit button instead of double posting.
It's great that your learning how to code but, you also need to learn to be self sufficient. So asking whenever you get stuck isn't going to be so great in the future. Just saying.
Ok im still learning the lingo of the forums. i wish to be an active member Ive fixed the problem ive been having and added a pistol type weapon. Although it is very similar Im going to only post when needed now, as ill try watch a video on how to do it first.
Thanks! Sorry if I sound like a jerk, I'm not trying to be. Just trying to keep peopling from getting bugged and hopefully this will help you learn to be self sufficient.
you could also do an else if in the same method, or make a method that takes input from the listener method to clean up and keep it small