@Override
 public void click(Player player, ClickType clickType, int i, ItemStack itemStack) {
   if (i < itemList.size()) {
     RewardItem item = itemList.get(i);
     if (item.hasPermission(this.player)) {
       if (item.canUseReward(this.player)) {
         player.playSound(player.getLocation(), Sound.LEVEL_UP, 1f, 1f);
         item.use(this.player);
         item.giveReward(this.player, player);
         update();
       } else {
         player.playSound(player.getLocation(), Sound.BLAZE_HIT, 1f, 1f);
         player.sendMessage(
             ChatColor.BLUE
                 + "You need to wait "
                 + ChatColor.AQUA
                 + this.player.getWaitTime(item.getBlankname(), item.getTime())
                 + ChatColor.BLUE
                 + " till you can use this");
       }
     } else {
       player.playSound(player.getLocation(), Sound.BLAZE_DEATH, 1f, 1f);
       player.sendMessage(ChatColor.RED + item.getDenymsg());
     }
   }
 }
 @Override
 public ItemStack[] generate() {
   ItemStack[] itemStacks = new ItemStack[getInventory().getSize()];
   int i = 0;
   for (RewardItem item : itemList) {
     ItemStackBuilder builder = new ItemStackBuilder();
     if (item.hasPermission(player)) {
       if (item.canUseReward(player)) {
         builder.withType(Material.EMERALD);
         builder.withName(ChatColor.GREEN + "Click to redeem");
       } else {
         builder.withType(Material.WATCH);
         builder.withName(
             ChatColor.RED + "Wait " + player.getWaitTime(item.getBlankname(), item.getTime()));
       }
     } else {
       builder.withType(Material.BARRIER);
       builder.withName(ChatColor.DARK_RED + item.getDenymsg());
     }
     builder.withLore("", ChatColor.AQUA + item.getName(), "");
     for (String s : item.getDescription()) {
       builder.withLore(ChatColor.GRAY + s);
     }
     itemStacks[i] = builder.build();
     i++;
   }
   return itemStacks;
 }
예제 #3
0
 /**
  * Method roll.
  *
  * @param rate double
  * @return List<RewardItem>
  */
 public List<RewardItem> roll(double rate) {
   double mult = Math.ceil(rate);
   List<RewardItem> ret = new ArrayList<>(1);
   RewardItem t = null;
   long count;
   for (int n = 0; n < mult; n++) {
     if (Rnd.get(RewardList.MAX_CHANCE) <= (_chance * Math.min(rate - n, 1.0))) {
       if (getMinDrop() >= getMaxDrop()) {
         count = getMinDrop();
       } else {
         count = Rnd.get(getMinDrop(), getMaxDrop());
       }
       if (t == null) {
         ret.add(t = new RewardItem(_item.getItemId()));
         t.count = count;
       } else {
         t.count = SafeMath.addAndLimit(t.count, count);
       }
     }
   }
   return ret;
 }