[REQ] Pirate Stick

Discussion in 'Archived: Plugin Requests' started by RumbleIV, Oct 18, 2012.

  1. Offline

    RumbleIV

    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>
     
    Last edited by a moderator: Nov 9, 2016
    GravedigginSearchBar likes this.
  2. Offline

    Woobie

    I can do this tomorrow, this is like 5 lines of code max :D
     
  3. Offline

    RumbleIV

    Thank you, I knew it was simple but I don't know jack squat about coding plugins. :)
     
  4. Offline

    RumbleIV

    If anyone else still wants to do this, they are free to do so.
     
  5. Shouldn't you want a delay on everytime using the stick so you can't spam it and lag the server?
     
  6. Offline

    RumbleIV

    oh yeah
     
  7. Offline

    herpingdo

    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.
     
  8. Offline

    Vandrake

    *waiting for the 5 line code* definitely curious to decompile it
     
  9. Offline

    Woobie

    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
     
    Last edited by a moderator: Nov 9, 2016
  10. Offline

    Vandrake

    [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
     
    Last edited by a moderator: Nov 9, 2016
  11. Offline

    Woobie

    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.
     
  12. Offline

    Vandrake

    good luck. Did the delay fix your join problem in your other plugin?
     
  13. Offline

    Woobie

    Havent tested yet, been working on other plugins.
     
  14. Offline

    RumbleIV

    Yes please. I would like delay + gunpowder. I added those edits a while back.
     
  15. Offline

    Woobie

    Yeah I saw them after I made the plugin, having slight problems with removing only 1 gunpowder from inventory.
     
  16. Offline

    Vandrake

    player.getInventory().removeItem
     
  17. Offline

    herpingdo

    I had that problem as well. Perhaps I could give you my code and you could add what is missing (A delay is all)
     
  18. Offline

    Woobie

  19. Offline

    herpingdo

    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.
     
  20. Offline

    RumbleIV

    delay?
     
  21. Offline

    herpingdo

    That's where my only issue lies ATM.
     
  22. Offline

    Vandrake

    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
     
  23. Offline

    herpingdo

    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.
     
  24. Offline

    Woobie

    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.
     
  25. Offline

    Vandrake

    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.
     
    Last edited by a moderator: May 29, 2016
  26. Offline

    Woobie

    Not sure why the other guy started doing this... :D

    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.
     
    Last edited by a moderator: May 29, 2016
  27. Offline

    RumbleIV

    Delay is important really need that part.
     
  28. Offline

    Woobie

    I know..
    Vandrake any ideas why my delay isnt working?
     
  29. Offline

    Vandrake

    ntory();
    ps.remove(p);


    you are removing the player from the hashmap right after you added him into it xD
     
  30. Offline

    Woobie

    hm.. is there any way to check if the task is still running? That would fix the problem, becouse atm, it doesnt do anything :D

    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);
     

Share This Page