Xp Booster

Discussion in 'Plugin Development' started by GodzillaFlame42, Aug 19, 2016.

Thread Status:
Not open for further replies.
  1. So i am coding a XP Booster GUI and when someone activates it goes on for 1 hour. I dont know if this is the right way to make the xp booster and how do i add a timer for 1 hour everytime someone clicks it and when someone trys to click it again it stops them because a timer is already activated?

    GUI Code:
    Code:
    package me.godzilla;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class GUI implements Listener {
    
        private static ItemStack xp;
       
        public static Inventory GUI = Bukkit.createInventory(null, 27, ChatColor.GOLD + ChatColor.BOLD.toString() + "Boosters");
       
        static
        {
           
            xp = xpbottle(ChatColor.YELLOW + "XP Booster");
            GUI.setItem(13, xp);
       
    }
        private static ItemStack xpbottle(String name){
            ItemStack i = new ItemStack(new ItemStack(Material.EXP_BOTTLE, 1));
            ItemMeta im = i.getItemMeta();
            im.setDisplayName(name);
            i.setItemMeta(im);
                return i;
       
            }
       
            @EventHandler
            public void onInventoryClick(InventoryClickEvent e) {
                if(e.getInventory().getName().equalsIgnoreCase("xpboost")) return;
                if(e.getCurrentItem().getItemMeta() == null) return;
                if(e.getCurrentItem().getItemMeta().getDisplayName().contains("XP Booster")) {
                    e.setCancelled(true);
                    e.getWhoClicked().sendMessage(ChatColor.YELLOW + ChatColor.BOLD.toString() + "(!) " + ChatColor.GRAY + "You have activated a booster for 1 hour!");
                }
            }
        }
    XP Booster Code:
    Code:
    package me.godzilla;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerExpChangeEvent;
    
    public class XP implements CommandExecutor, Listener {
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            Player player = (Player) sender;
            if (cmd.getName().equalsIgnoreCase("xpboost")){
            }
            return false;
            }
        @EventHandler(priority=EventPriority.HIGH, ignoreCancelled=false)
          public void onXpPickup(PlayerExpChangeEvent event)
          {
            int amount = event.getAmount();
            if (amount < 0) {
              return;
            }
            Player p = event.getPlayer();
            int multiplier;
            if (p.hasPermission("XPBoost.Allow")) {
                {
                  multiplier = 2;
                }
            }
        }
    }
     
  2. Offline

    HeartandSoul

    YAY! Finally, a post that doesn't ask for code! I've been searching far and wide xD

    ...What? If it's not doing anything, remove it.

    All you're doing is setting the int to 2. If its a multiplier, use this integer to multiply the amount picked up / changed.

    The name of the inventory you're checking for does not match this one:
    And does not need to be static.... Don't abuse static...

    Tell me if I have mistaken any of these.
    EDIT: Quoted your code. whoops
     
Thread Status:
Not open for further replies.

Share This Page