Skip to content

Commit

Permalink
Introduces world-guard flags in config (Fixes #11) and the facing of …
Browse files Browse the repository at this point in the history
…chest
  • Loading branch information
rlf committed Dec 8, 2014
1 parent 6ad1c72 commit 0eb10a5
Show file tree
Hide file tree
Showing 6 changed files with 282 additions and 276 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ public boolean onCommand(final CommandSender sender, final Command command, fina
return true;
}
if (!uSkyBlock.getInstance().onRestartCooldown(player) || Settings.general_cooldownRestart == 0) {
uSkyBlock.getInstance().restartPlayerIsland(player, pi.getIslandLocation());
uSkyBlock.getInstance().setRestartCooldown(player);
return true;
return uSkyBlock.getInstance().restartPlayerIsland(player, pi.getIslandLocation());
}
player.sendMessage(ChatColor.YELLOW + "You can restart your island in " + uSkyBlock.getInstance().getRestartCooldownTime(player) / 1000L + " seconds.");
return true;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/us/talabrek/ultimateskyblock/PlayerJoin.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public void onPlayerJoin(final PlayerJoinEvent event) {
uSkyBlock.getInstance().createIslandConfig(pi.locationForParty(), event.getPlayer().getName());
}
uSkyBlock.getInstance().clearIslandConfig(pi.locationForParty(), event.getPlayer().getName());
if (Settings.island_protectWithWorldGuard && Bukkit.getServer().getPluginManager().isPluginEnabled("WorldGuard")) {
WorldGuardHandler.protectIsland(event.getPlayer(), event.getPlayer().getName(), pi);
}
}
f.delete();
}
if (Settings.island_protectWithWorldGuard && Bukkit.getServer().getPluginManager().isPluginEnabled("WorldGuard")) {
WorldGuardHandler.protectIsland(event.getPlayer(), event.getPlayer().getName(), pi);
}
uSkyBlock.getInstance().addActivePlayer(event.getPlayer().getName(), pi);
if (pi.getHasIsland() && !uSkyBlock.getInstance().getTempIslandConfig(pi.locationForParty()).contains("general.level")) {
uSkyBlock.getInstance().createIslandConfig(pi.locationForParty(), event.getPlayer().getName());
Expand Down
85 changes: 37 additions & 48 deletions src/main/java/us/talabrek/ultimateskyblock/SkyBlockMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

// TODO: Move all the texts to resource-files (translatable).
/**
Expand Down Expand Up @@ -880,53 +882,7 @@ public void populateChallengeRank(Inventory menu, final Player player, final int
meta4 = currentChallengeItem.getItemMeta();
meta4.setDisplayName(challenge);
}
lores.add("\u00a77" + config.getString("options.challenges.challengeList." + challengeName + ".description"));
lores.add("\u00a7eThis challenge requires the following:");
final String[] reqList = config.getString("options.challenges.challengeList." + challengeName + ".requiredItems").split(" ");
int reqItem = 0;
int reqAmount = 0;
int reqMod = -1;
String[] array;
for (int length = (array = reqList).length, j = 0; j < length; ++j) {
final String s = array[j];
final String[] sPart = s.split(":");
if (sPart.length == 2) {
reqItem = Integer.parseInt(sPart[0]);
final String[] sScale = sPart[1].split(";");
if (sScale.length == 1) {
reqAmount = Integer.parseInt(sPart[1]);
} else if (sScale.length == 2) {
if (sScale[1].charAt(0) == '+') {
reqAmount = Integer.parseInt(sScale[0]) + Integer.parseInt(sScale[1].substring(1)) * skyBlock.getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challengeName);
} else if (sScale[1].charAt(0) == '*') {
reqAmount = Integer.parseInt(sScale[0]) * (Integer.parseInt(sScale[1].substring(1)) * skyBlock.getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challengeName));
} else if (sScale[1].charAt(0) == '-') {
reqAmount = Integer.parseInt(sScale[0]) - Integer.parseInt(sScale[1].substring(1)) * skyBlock.getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challengeName);
} else if (sScale[1].charAt(0) == '/') {
reqAmount = Integer.parseInt(sScale[0]) / (Integer.parseInt(sScale[1].substring(1)) * skyBlock.getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challengeName));
}
}
} else if (sPart.length == 3) {
reqItem = Integer.parseInt(sPart[0]);
final String[] sScale = sPart[2].split(";");
if (sScale.length == 1) {
reqAmount = Integer.parseInt(sPart[2]);
} else if (sScale.length == 2) {
if (sScale[1].charAt(0) == '+') {
reqAmount = Integer.parseInt(sScale[0]) + Integer.parseInt(sScale[1].substring(1)) * skyBlock.getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challengeName);
} else if (sScale[1].charAt(0) == '*') {
reqAmount = Integer.parseInt(sScale[0]) * (Integer.parseInt(sScale[1].substring(1)) * skyBlock.getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challengeName));
} else if (sScale[1].charAt(0) == '-') {
reqAmount = Integer.parseInt(sScale[0]) - Integer.parseInt(sScale[1].substring(1)) * skyBlock.getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challengeName);
} else if (sScale[1].charAt(0) == '/') {
reqAmount = Integer.parseInt(sScale[0]) / (Integer.parseInt(sScale[1].substring(1)) * skyBlock.getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challengeName));
}
}
reqMod = Integer.parseInt(sPart[1]);
}
final ItemStack newItem = new ItemStack(reqItem, reqAmount, (short) reqMod);
lores.add("\u00a7f" + newItem.getAmount() + " " + newItem.getType().toString());
}
addRequiredItems(player, lores, challengeName, config);
if (pi.checkChallenge(challengeName) > 0 && config.getBoolean("options.challenges.challengeList." + challengeName + ".repeatable")) {
if (pi.onChallengeCooldown(challengeName)) {
if (pi.getChallengeCooldownTime(challengeName) / 86400000L >= 1L) {
Expand Down Expand Up @@ -957,11 +913,44 @@ public void populateChallengeRank(Inventory menu, final Player player, final int
menu.setItem(++location, currentChallengeItem);
lores.clear();
} catch (NullPointerException e) {
skyBlock.getLogger().log(Level.SEVERE, "Mis-configured challenge " + challenge, e);
skyBlock.getLogger().log(Level.SEVERE, "Misconfigured challenge " + challenge, e);
}
}
}

private void addRequiredItems(Player player, List<String> lores, String challengeName, FileConfiguration config) {
lores.add("\u00a77" + config.getString("options.challenges.challengeList." + challengeName + ".description"));
lores.add("\u00a7eThis challenge requires the following:");
String reqItems = config.getString("options.challenges.challengeList." + challengeName + ".requiredItems");
int timesCompleted = skyBlock.getPlayerInfo(player).checkChallengeSinceTimer(challengeName);
if (reqItems != null) {
Pattern reqPattern = Pattern.compile("(?<type>[0-9]+)(:(?<subtype>[0-9]+))?:(?<amount>[0-9]+)(;(?<op>[+\\-*])(?<inc>[0-9]+))?");
for (String item : reqItems.split(" ")) {
Matcher m = reqPattern.matcher(item);
if (m.matches()) {
int reqItem = Integer.parseInt(m.group("type"));
int subType = m.group("subtype") != null ? Integer.parseInt(m.group("subtype")) : 0;
int amount = Integer.parseInt(m.group("amount"));
char op = m.group("op") != null ? m.group("op").charAt(0) : 0;
int inc = m.group("inc") != null ? Integer.parseInt(m.group("inc")) : 0;
amount = calcAmount(amount, op, inc, timesCompleted);
Material mat = Material.getMaterial(reqItem); // Deprecated my ass
lores.add("\u00a7f" + amount + " " + mat.name());
}
}
}
}

private int calcAmount(int amount, char op, int inc, int timesCompleted) {
switch (op) {
case '+': return amount + inc*timesCompleted;
case '-': return amount - inc*timesCompleted; // Why?
case '*': return amount * inc * timesCompleted; // Oh, my god! Just do the time m8!
case '/': return amount / (inc * timesCompleted); // Yay! Free stuff!!!
}
return amount;
}

private boolean isCompletedChallenge(String challengeName) {
return challengeName.charAt(1) == '2';
}
Expand Down
Loading

0 comments on commit 0eb10a5

Please sign in to comment.