What I want: Plugin that makes sticks when right clicked shoot fireballs/ fire charges. Ammo can be gunpowder. 2 second delay between each shot please... Why I want this: Pirate class for my kit pvp server. Permissions: Stick.fire Names for plugin: Pirate gun. -- Got this done, here it is <Edit by Moderator: Redacted mediafire url>
I coded one, it uses gunpowder for ammo and currently shoots Ghast fireballs. I am considering making it consume a gunpowder for a more "fire charge" shot, and consume a TNT for 2 Ghast fireballs.
RumbleIV Worked for me, should work for you. <Edit by Moderator: Redacted mediafire url> Vandrake Jesus god its 7 lines of actual code, pls dont punch me Code: @EventHandler public void onInteract(PlayerInteractEvent e){ if(e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){ if(e.getPlayer().getItemInHand().getType() == (Material.STICK)){ Fireball fireball = e.getPlayer().launchProjectile(Fireball.class); fireball.setShooter(e.getPlayer()); fireball.setYield(7.5f); 36 lines total. EDIT: Do you still want the delay on it? EDIT2: Just saw that you edited your post.. ill add the gunpowder thing
[quote uid=90712918 name="Woobie" post=1380102]RumbleIV Worked for me, should work for you. <Edit by Moderator: Redacted mediafire url> Vandrake Jesus god its 7 lines of actual code, pls dont punch me Code: @EventHandler public void onInteract(PlayerInteractEvent e){ if(e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){ if(e.getPlayer().getItemInHand().getType() == (Material.STICK)){ Fireball fireball = e.getPlayer().launchProjectile(Fireball.class); fireball.setShooter(e.getPlayer()); fireball.setYield(7.5f); 36 lines total. EDIT: Do you still want the delay on it?[/quote] I won't lol. It's just when people say under 10 lines I find that curious xD Coz I always count the imports and stuff. Guess others don't x.x
Well I always count just the actual code, and looks like this isnt even done yet, since he wants the delay and gunpowder for ammo.
Yeah I saw them after I made the plugin, having slight problems with removing only 1 gunpowder from inventory.
I had that problem as well. Perhaps I could give you my code and you could add what is missing (A delay is all)
https://github.com/herpingdo/GunStick Here's what I've got so far, it shoots a ghast fireball, consuming 1 gunpowder, and it needs no ammo if you are op, but it will still try and take the ammo out, which I need to fix.
Hashmaps. Insert the player into a hashmap after shooting it once . Then remove it after a certain amount of time. If they player tries to fire while in the hashmap tell him to wait. if he is not in the hashmap put it back and fire. Repeat for profit
I'm already working with a list of players with infinite ammo, so I'll just make a second list of players who need to wait. But I am not 100% sure how to wait for an amount of time before removing the player (Without pausing the whole plugin) Edit: Changed from a list to a permission.
I got this done too, except the delay, not sure why it isnt working. My current code: Code: package me.woobie.piratestick; import java.util.ArrayList; import org.bukkit.ChatColor; 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.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; public class Main extends JavaPlugin implements Listener { public ArrayList <String> ps = new ArrayList <String> (); public void onEnable(){ System.out.println("[Piratestick] Plugin Enabled"); getServer().getPluginManager().registerEvents(this, this); } public void onDisable(){ System.out.println("[Piratestick] Plugin Disabled"); } @SuppressWarnings("deprecation") @EventHandler public void onInteract(final PlayerInteractEvent e){ final Player p = e.getPlayer(); if(e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){ if(e.getPlayer().getItemInHand().getType() == (Material.STICK)){ if(e.getPlayer().getInventory().contains(Material.SULPHUR)){ if(p.hasPermission("stick.fire")){ ps.add(p.getName()); Fireball fireball = e.getPlayer().launchProjectile(Fireball.class); fireball.setShooter(e.getPlayer()); fireball.setYield(7.5f); e.getPlayer().getInventory().removeItem(new ItemStack(Material.SULPHUR, 1)); e.getPlayer().updateInventory(); ps.remove(p); this.getServer().getScheduler().scheduleAsyncDelayedTask(this, new Runnable() { public void run() { ps.add(p.getName()); } }, 100L); } else { p.sendMessage(ChatColor.RED+ "You dont have permission to perform this action!"); } } else { e.getPlayer().sendMessage(ChatColor.RED+ "You need 1 gunpowder to shoot fireballs"); } } } } public void onInteract2(PlayerInteractEvent e){ Player p = e.getPlayer(); if(e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){ if(e.getPlayer().getItemInHand().getType() == (Material.STICK)){ if(!(ps.contains(p))){ p.sendMessage(ChatColor.RED+"The cooldown is on, please try again in 5 seconds!"); } } } } } I hope you didnt die while reading this. This Code: if(!(ps.contains(p))){ p.sendMessage(ChatColor.RED+"The cooldown is on, please try again in 5 etc... Didnt really make any sense, ill try to figure out something EDIT: Yes it did.. my brain is not working.
Bukkit.getScheduler().schedule asynched task (forgot the exact name) make the delay 20*(number of seconds you want). the delayed task is the remove from hashmap wait theres 2 making this? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Not sure why the other guy started doing this... Looks like my code has some problems.. when I shoot with bow & arrow, or snowball, or egg, it sends a message "You need 1 gunpowder to shoot fireballs" Not sure why... but maybe i'll let herpingdo do this. EDIT: Nevermind.. my minecraft is glitching, its working again, except the delay o.o EDIT by Moderator: merged posts, please use the edit button instead of double posting.
ntory(); ps.remove(p); you are removing the player from the hashmap right after you added him into it xD
hm.. is there any way to check if the task is still running? That would fix the problem, becouse atm, it doesnt do anything What about this: Code: @EventHandler public void onJoin(final PlayerJoinEvent e){ Player p = e.getPlayer(); if(p.hasPermission("stick.fire")){ ps.add(p.getName()); Player joins, has permission, gets added to list, and then Code: if(e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){ if(e.getPlayer().getItemInHand().getType() == (Material.STICK)){ if(e.getPlayer().getInventory().contains(Material.SULPHUR)){ if(p.hasPermission("stick.fire")){ if(ps.contains(p.getName())){ Fireball fireball = e.getPlayer().launchProjectile(Fireball.class);