Skip to content

Commit

Permalink
Issue #676: Allow for individual challenge to challenge requirements …
Browse files Browse the repository at this point in the history
…`requiredChallenges`
  • Loading branch information
rlf committed Jul 2, 2016
1 parent 1307c49 commit 6de6f3b
Show file tree
Hide file tree
Showing 23 changed files with 156 additions and 294 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import us.talabrek.ultimateskyblock.handler.VaultHandler;
import us.talabrek.ultimateskyblock.player.PlayerInfo;
import us.talabrek.ultimateskyblock.uSkyBlock;
import us.talabrek.ultimateskyblock.util.FormatUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static dk.lockfuglsang.minecraft.po.I18nUtil.tr;
import static us.talabrek.ultimateskyblock.util.FormatUtil.*;
import static us.talabrek.ultimateskyblock.util.MetaUtil.createMap;

/**
* The data-object for a challenge
Expand All @@ -41,6 +40,7 @@ static Type from(String s) {
private final Type type;
private final List<String> requiredItems;
private final List<EntityMatch> requiredEntities;
private final List<String> requiredChallenges;
private final Rank rank;
private final int resetInHours;
private final ItemStack displayItem;
Expand All @@ -51,12 +51,13 @@ static Type from(String s) {
private final Reward reward;
private final Reward repeatReward;

public Challenge(String name, String displayName, String description, Type type, List<String> requiredItems, List<EntityMatch> requiredEntities, Rank rank, int resetInHours, ItemStack displayItem, String tool, ItemStack lockedItem, boolean takeItems, int radius, Reward reward, Reward repeatReward) {
public Challenge(String name, String displayName, String description, Type type, List<String> requiredItems, List<EntityMatch> requiredEntities, List<String> requiredChallenges, Rank rank, int resetInHours, ItemStack displayItem, String tool, ItemStack lockedItem, boolean takeItems, int radius, Reward reward, Reward repeatReward) {
this.name = name;
this.displayName = displayName;
this.type = type;
this.requiredItems = requiredItems;
this.requiredEntities = requiredEntities;
this.requiredChallenges = requiredChallenges;
this.rank = rank;
this.resetInHours = resetInHours;
this.displayItem = displayItem;
Expand Down Expand Up @@ -125,6 +126,10 @@ public List<EntityMatch> getRequiredEntities() {
return requiredEntities;
}

public List<String> getRequiredChallenges() {
return requiredChallenges;
}

public Rank getRank() {
return rank;
}
Expand Down Expand Up @@ -204,7 +209,6 @@ private List<String> wrappedDetails(List<String> details) {
}

public ItemStack getDisplayItem() {
// TODO: 10/12/2014 - R4zorax: Incorporate all the other goodies here...
return new ItemStack(displayItem); // Copy
}

Expand All @@ -228,6 +232,28 @@ public Reward getRepeatReward() {
return repeatReward;
}

public List<String> getMissingRequirements(PlayerInfo playerInfo) {
List<String> missing = new ArrayList<>();
for (String challengeName : requiredChallenges) {
ChallengeCompletion completion = playerInfo.getChallenge(challengeName);
if (completion != null && completion.getTimesCompleted() <= 0) {
String name = completion.getName();
Challenge challenge = uSkyBlock.getInstance().getChallengeLogic().getChallenge(name);
if (challenge != null) {
missing.add(challenge.getDisplayName());
} else {
missing.add(name);
}
}
}
if (missing.isEmpty()) {
return Collections.emptyList();
}
String missingList = "" + missing;
missingList = missingList.substring(1, missingList.length()-1);
return Collections.singletonList(tr("\u00a77Requires {0}\u00a77 to unlock", missingList));
}

@Override
public String toString() {
return "Challenge{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static us.talabrek.ultimateskyblock.util.FormatUtil.normalize;
import static us.talabrek.ultimateskyblock.util.ItemStackUtil.createItemStack;

/**
Expand All @@ -34,9 +35,9 @@ public static ChallengeDefaults createDefaults(ConfigurationSection section) {
return new ChallengeDefaults(
section.getInt("defaultResetInHours", 144),
section.getBoolean("requiresPreviousRank", true),
section.getString("repeatableColor", "\u00a7a"),
section.getString("finishedColor", "\u00a72"),
section.getString("challengeColor", "\u00a7e"),
normalize(section.getString("repeatableColor", "&a")),
normalize(section.getString("finishedColor", "&2")),
normalize(section.getString("challengeColor", "&e")),
section.getInt("rankLeeway", 1),
section.getBoolean("enableEconomyPlugin", true),
section.getBoolean("broadcastCompletion", true),
Expand All @@ -56,13 +57,20 @@ public static Challenge createChallenge(Rank rank, ConfigurationSection section,
String description = section.getString("description");
ItemStack displayItem = createItemStack(
section.getString("displayItem", defaults.displayItem),
FormatUtil.normalize(displayName), description);
normalize(displayName), description);
ItemStack lockedItem = section.isString("lockedDisplayItem") ? createItemStack(section.getString("lockedDisplayItem", "BARRIER"), displayName, description) : null;
boolean takeItems = section.getBoolean("takeItems", true);
int radius = section.getInt("radius", 10);
Reward reward = createReward(section.getConfigurationSection("reward"));
Reward repeatReward = createReward(section.getConfigurationSection("repeatReward"));
return new Challenge(name, displayName, description, type, requiredItems, requiredEntities, rank, resetInHours, displayItem, section.getString("tool", null), lockedItem, takeItems, radius, reward, repeatReward);
if (repeatReward == null && section.getBoolean("repeatable", false)) {
repeatReward = reward;
}
List<String> requiredChallenges = section.getStringList("requiredChallenges");
return new Challenge(name, displayName, description, type,
requiredItems, requiredEntities, requiredChallenges, rank,
resetInHours, displayItem, section.getString("tool", null), lockedItem, takeItems,
radius, reward, repeatReward);
}

private static List<EntityMatch> createEntities(List<String> requiredEntities) {
Expand All @@ -75,7 +83,7 @@ private static List<EntityMatch> createEntities(List<String> requiredEntities) {
String countStr = m.group("count");
int count = countStr != null ? Integer.parseInt(countStr, 10) : 1;
EntityType entityType = EntityType.fromName(type);
Map<String,Object> map = meta != null ? MetaUtil.createMap(meta.substring(1)) : new HashMap<String,Object>(); // skip the leading ':'
Map<String, Object> map = meta != null ? MetaUtil.createMap(meta.substring(1)) : new HashMap<String, Object>(); // skip the leading ':'
if (entityType != null && map != null) {
entities.add(new EntityMatch(entityType, map, count));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ public int populateChallengeRank(Inventory menu, final Rank rank, int location,
meta4.setLore(lores);
currentChallengeItem.setItemMeta(meta4);
menu.setItem(location++, currentChallengeItem);
List<String> missingRequirements = rank.getMissingRequirements(playerInfo);
List<String> missingRankRequirements = rank.getMissingRequirements(playerInfo);
for (Challenge challenge : rank.getChallenges()) {
if ((location % 9) == 0) {
location++; // Skip rank-row
Expand All @@ -485,7 +485,8 @@ public int populateChallengeRank(Inventory menu, final Rank rank, int location,
String challengeName = challenge.getName();
try {
currentChallengeItem = getItemStack(playerInfo, challengeName);
if (!missingRequirements.isEmpty()) {
List<String> missingReqs = challenge.getMissingRequirements(playerInfo);
if (!missingRankRequirements.isEmpty() || !missingReqs.isEmpty()) {
ItemStack locked = challenge.getLockedDisplayItem();
if (locked != null) {
currentChallengeItem.setType(locked.getType());
Expand All @@ -496,7 +497,8 @@ public int populateChallengeRank(Inventory menu, final Rank rank, int location,
}
meta4 = currentChallengeItem.getItemMeta();
meta4.setDisplayName(tr("\u00a74\u00a7lLocked Challenge"));
lores.addAll(missingRequirements);
lores.addAll(missingReqs);
lores.addAll(missingRankRequirements);
meta4.setLore(lores);
currentChallengeItem.setItemMeta(meta4);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ public NBTCommand() {
@Override
public boolean execute(CommandSender sender, String alias, Map<String, Object> data, String... args) {
if (sender instanceof Player) {
Player player = (Player)sender;
Player player = (Player) sender;
ItemStack itemStack = player.getInventory().getItemInMainHand();
if (itemStack != null) {
String msg = "";
msg += tr("\u00a7eInfo for \u00a79{0}", ItemStackUtil.asString(itemStack)) + "\n";
msg += tr("\u00a77 - name: \u00a79{0}", VaultHandler.getItemName(itemStack)) + "\n";
msg += tr("\u00a77 - nbttag: \u00a79{0}", NBTUtil.getNBTTag(itemStack)) + "\n";
player.sendMessage(msg.trim().split("\n"));
String[] msgs = new String[]{
tr("\u00a7eInfo for \u00a79{0}", ItemStackUtil.asString(itemStack)),
tr("\u00a77 - name: \u00a79{0}", VaultHandler.getItemName(itemStack)),
tr("\u00a77 - nbttag: \u00a79{0}", NBTUtil.getNBTTag(itemStack))
};
player.sendMessage(msgs);
} else {
player.sendMessage(tr("\u00a7cNo item in hand!"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,6 @@ private Inventory createInitMenu(Player player) {
addLore(lores, "\u00a7f", tr("Want to join another player's\nisland instead of starting\nyour own? If another player\ninvites you to their island\nyou can click here or use\n\u00a7e/island accept\u00a7f to join them.\n\u00a7e\u00a7lClick here to accept an invite!\n\u00a7e\u00a7l(You must be invited first)"));
meta2.setLore(lores);
menuItem.setItemMeta(meta2);
menu.setItem(menuSize-2, menuItem);
lores.clear();
menuItem = new ItemStack(Material.SIGN, 1);
meta = menuItem.getItemMeta();
meta.setDisplayName(tr("\u00a7a\u00a7lIsland Help"));
addLore(lores, "\u00a7f", tr("Need help with skyblock\nconcepts or commands? View\ndetails about them here.\n\u00a7e\u00a7lClick here for help!"));
meta.setLore(lores);
menuItem.setItemMeta(meta);
menu.setItem(menuSize-1, menuItem);
lores.clear();
return menu;
Expand Down Expand Up @@ -753,12 +745,9 @@ private void onClickCreateMenu(InventoryClickEvent event, Player p, ItemMeta met
if (slotIndex == 0) {
p.closeInventory();
p.performCommand("island create");
} else if (slotIndex == menuSize-2) {
p.closeInventory();
p.performCommand("island accept");
} else if (slotIndex == menuSize-1) {
p.closeInventory();
p.performCommand("chestcommands open island_help");
p.performCommand("island accept");
} else if (meta != null && meta.getDisplayName() != null) {
String schemeName = stripFormatting(meta.getDisplayName());
if (plugin.getPerkLogic().getSchemes(p).contains(schemeName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ private void updateSignAsync(final Location loc) {
PlayerInfo playerInfo = plugin.getPlayerInfo(islandInfo.getLeaderUniqueId());
if (playerInfo != null) {
isChallengeAvailable = challenge.getRank().isAvailable(playerInfo);
isChallengeAvailable &= challenge.getMissingRequirements(playerInfo).isEmpty();
}
}
}
Expand Down
14 changes: 4 additions & 10 deletions uSkyBlock-Core/src/main/po/cs.po
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ msgstr "§6Získáte XP: §a{0}"
msgid "§dTotal times completed: §f{0}"
msgstr "§dCelkově splněno: §f{0}"

#, java-format
msgid "§7Requires {0} to unlock"
msgstr ""

#, java-format
msgid "§4No challenge named {0} found"
msgstr "§4Nebylo nalezeno jméno úkolu {0}"
Expand Down Expand Up @@ -1973,16 +1977,6 @@ msgid ""
"§e§l(You must be invited first)"
msgstr ""

msgid "§a§lIsland Help"
msgstr "§a§lPotřebuji pomoc"

msgid ""
"Need help with skyblock\n"
"concepts or commands? View\n"
"details about them here.\n"
"§e§lClick here for help!"
msgstr ""

msgid "Island Menu"
msgstr "Ostrovní menu"

Expand Down
19 changes: 4 additions & 15 deletions uSkyBlock-Core/src/main/po/da.po
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ msgstr "§6Erfaring: §a{0}"
msgid "§dTotal times completed: §f{0}"
msgstr "§dTotalt antal aflevering: §f{0}"

#, java-format
msgid "§7Requires {0} to unlock"
msgstr ""

#, java-format
msgid "§4No challenge named {0} found"
msgstr "§4Ingen udfordringer med navn {0} fundet!"
Expand Down Expand Up @@ -2118,21 +2122,6 @@ msgstr ""
"eller bruge §e/island accept§f for at\n"
"blive medlem af deres ø."

msgid "§a§lIsland Help"
msgstr "§a§lØ Hjælp"

msgid ""
"Need help with skyblock\n"
"concepts or commands? View\n"
"details about them here.\n"
"§e§lClick here for help!"
msgstr ""
"Har du brug for hjælp\n"
"til skyblock koncepter\n"
"eller kommandoer?\n"
"Se detaljer her.\n"
"§e§lKlik for at se hjælp."

msgid "Island Menu"
msgstr "Hoved menu"

Expand Down
17 changes: 4 additions & 13 deletions uSkyBlock-Core/src/main/po/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ msgstr "§6Erfahrungsbelohnung: §a{0}"
msgid "§dTotal times completed: §f{0}"
msgstr "§dSchon §f{0} §dmal abgeschlossen."

#, java-format
msgid "§7Requires {0} to unlock"
msgstr ""

#, java-format
msgid "§4No challenge named {0} found"
msgstr "§4Keine Aufgabe namens {0} gefunden."
Expand Down Expand Up @@ -2145,19 +2149,6 @@ msgstr ""
"§e§lKlick hier um eine Einladung anzunehmen!\n"
"§e§l(Du musst zuerst eingeladen werden)"

msgid "§a§lIsland Help"
msgstr "§a§lInsel Hilfe"

msgid ""
"Need help with skyblock\n"
"concepts or commands? View\n"
"details about them here.\n"
"§e§lClick here for help!"
msgstr ""
"Brauchst Du Hilfe über Skyblock\n"
"oder Skyblock Befehle?\n"
"§e§lKlick hier für mehr Infos"

msgid "Island Menu"
msgstr "Insel Menü"

Expand Down
18 changes: 4 additions & 14 deletions uSkyBlock-Core/src/main/po/en_GB.po
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ msgstr "§6Exp Reward: §a{0}"
msgid "§dTotal times completed: §f{0}"
msgstr "§dTotal times completed: §f{0}"

#, java-format
msgid "§7Requires {0} to unlock"
msgstr ""

#, java-format
msgid "§4No challenge named {0} found"
msgstr "§4* §7No challenge named §4{0} §7found"
Expand Down Expand Up @@ -2143,20 +2147,6 @@ msgstr ""
"§e§lClick here to accept an invite!\n"
"§e§l(You must be invited first)"

msgid "§a§lIsland Help"
msgstr "§a§lIsland Help"

msgid ""
"Need help with skyblock\n"
"concepts or commands? View\n"
"details about them here.\n"
"§e§lClick here for help!"
msgstr ""
"Need help with skyblock\n"
"concepts or commands? View\n"
"details about them here.\n"
"§e§lClick here for help!"

msgid "Island Menu"
msgstr "Island Menu"

Expand Down
18 changes: 4 additions & 14 deletions uSkyBlock-Core/src/main/po/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ msgstr "§6Recompensa de XP: §a{0}"
msgid "§dTotal times completed: §f{0}"
msgstr "§dCantidad de veces completado: §f{0}"

#, java-format
msgid "§7Requires {0} to unlock"
msgstr ""

#, java-format
msgid "§4No challenge named {0} found"
msgstr "§4¡Ningún reto llamado {0} fue encontrado!"
Expand Down Expand Up @@ -2144,20 +2148,6 @@ msgstr ""
"§e§l¡Click aquí para aceptar una invitación!\n"
"§e§o(Tienes que ser invitado primero)"

msgid "§a§lIsland Help"
msgstr "§a§lAyuda de la Isla"

msgid ""
"Need help with skyblock\n"
"concepts or commands? View\n"
"details about them here.\n"
"§e§lClick here for help!"
msgstr ""
"Necesitas ayuda con comandos\n"
"o conceptos de skyblock? Mira\n"
"detalles sobre ellos aquí.\n"
"§e§l¡Click aquí para ayuda!"

msgid "Island Menu"
msgstr "Menú de Isla"

Expand Down
Loading

0 comments on commit 6de6f3b

Please sign in to comment.