Discussion in 'Spigot Plugin Development' started by Bravecity, May 19, 2015.

  1. Hello im creating a gun plugin i have the gun and all made, i just need to know how to set up and ammo, delay and reload system, any help would be appreciated
  2. Well what have you got so far?
  3. This:
    Code (Text):
    package me.weefatbob.guns;

    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    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;

    public class Guns extends JavaPlugin implements Listener{
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        public void onPlayerInteract(PlayerInteractEvent e) {
            if(!(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
            if(!(e.getItem().getType() == Material.IRON_SPADE)) return;
            if (!(e.getItem().getItemMeta().getDisplayName().equals("Hi Adam"))) return;
            Snowball s = e.getPlayer().launchProjectile(Snowball.class);
            e.getPlayer().playSound(e.getPlayer().getLocation(), Sound.NOTE_BASS_DRUM, 2F, 1F);
        public void onEntityDamage(EntityDamageByEntityEvent e) {
            if (e.getDamager() instanceof Snowball) {
                Snowball s = (Snowball) e.getDamager();
                if (s.getShooter() instanceof Player) {
                    Player shooter = (Player) s.getShooter();
                    if (shooter.getItemInHand().getType()== Material.IRON_SPADE) {
                        if (shooter.getItemInHand().getItemMeta().getDisplayName().equals("Hi Adam")){
    Its ment to say "Gun" where it says "Hi Adam" i was proving to a friend i made the gun
  4. For ammo, an easy way would be doing it through Lore. By saving a string, every time a player shoots you can parse the integer and adjust accordingly. A more fun way (though requires more work) is by stacking spades and again every time a player shoots take one away (or basically remove all spades and add the amount -1). Though the second method, while visually more attractive, will require you to listen and prevent dropping the gun, as well as various other inventory events.

    Lastly there is always the writing above the actionbar which you can use to also save, and maybe add a bar which shows how much ammo you have; really depends on what you want specifically.