Unlimited challenges

This commit is contained in:
Fabrizio La Rosa 2020-07-12 15:09:33 +02:00
parent 0caa61906a
commit 011f59b0c1
5 changed files with 30 additions and 10 deletions

View File

@ -11,13 +11,13 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class FabledChallenge {
private SkyBlock plugin;
private ChallengeManager challengeManager;
private PlayerManager playerManager;
private final SkyBlock plugin;
private final ChallengeManager challengeManager;
private final PlayerManager playerManager;
// I use my own inventory api bc it's hard to implement inventories with the
private InventoryManager inventoryManager;
private DefaultInventory defaultInventory;
private ChallengeInventory challengeInventory;
private final InventoryManager inventoryManager;
private final DefaultInventory defaultInventory;
private final ChallengeInventory challengeInventory;
public FabledChallenge(SkyBlock plugin) {
this.plugin = plugin;

View File

@ -38,7 +38,15 @@ public class ChallengeCategory {
String name = ChatColor.translateAlternateColorCodes('&', config.getString(key + ".name"));
List<String> require = toColor(config.getStringList(key + ".require"));
List<String> reward = toColor(config.getStringList(key + ".reward"));
int maxTimes = config.getInt(key + ".maxtimes");
int maxTimes = 0;
try {
Integer.parseInt(config.getString(key + ".maxtimes", "unlimited"));
maxTimes = config.getInt(key + ".maxtimes");
} catch(NumberFormatException ignored) {
if(config.getString(key + ".maxtimes", "unlimited").equalsIgnoreCase("unlimited")) {
maxTimes = Integer.MAX_VALUE;
}
}
boolean showInChat = config.getBoolean(key + ".showInChat");
// Item
boolean show = config.getBoolean(key + ".item.show");

View File

@ -38,14 +38,24 @@ public class ItemChallenge {
}
public ItemStack createItem(UUID player, int amount) {
FileManager.Config langConfig = SkyBlock.getInstance().getFileManager()
.getConfig(new File(SkyBlock.getInstance().getDataFolder(), "language.yml"));
FileConfiguration langConfigLoad = langConfig.getFileConfiguration();
ItemStack is = type.getItem();
is.setAmount(this.amount);
// Air
ItemMeta im = is.getItemMeta();
if (im != null) {
String maxAmount;
if(challenge.getMaxTimes() == Integer.MAX_VALUE) {
maxAmount = langConfigLoad.getString("Challenge.Inventory.Unlimited.Message");
} else {
maxAmount = String.valueOf(challenge.getMaxTimes());
}
im.setDisplayName(ChatColor.translateAlternateColorCodes('&',
itemTitle.replace("%challenge", challenge.getName()).replace("%amount", Integer.toString(amount))
.replace("%max", Integer.toString(challenge.getMaxTimes()))));
.replace("%max", maxAmount)));
im.setLore(lore);
is.setItemMeta(im);
}

View File

@ -337,8 +337,8 @@ challenges:
- 'CMD:eco give {player} 100'
- 'ITEM:iron_ingot 10'
- 'ITEM:name_tag 1'
# The maximum amount of time this challenge is repeatable
maxtimes: 5
# The maximum amount of time this challenge is repeatable. Unlimited for endless challenge
maxtimes: Unlimited
# If true, broadcast a message when this challenge is completed
showInChat: true
item:

View File

@ -3874,6 +3874,8 @@ Hologram:
Message: '%blocks: %amount'
Challenge:
Inventory:
Unlimited:
Message: 'Unlimited'
Item:
Title: '%challenge &e%amount &6/ &e%max'
Broadcast: '&bSkyBlock &8| &6%player &7has completed challenge %challenge (%amount