Skip to content

Commit

Permalink
Stability changes after Talabrek PR
Browse files Browse the repository at this point in the history
  • Loading branch information
rlf committed Feb 26, 2017
1 parent 1977fe5 commit 1622625
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* @since v2.1.2
*/
public interface BlockScore {

/**
* The type of block.
*
Expand Down Expand Up @@ -66,8 +65,14 @@ public interface BlockScore {
*
* @since v2.1.2
*/
public enum State {
NORMAL(ChatColor.AQUA), DIMINISHING(ChatColor.YELLOW), LIMIT(ChatColor.RED), NEGATIVE(ChatColor.DARK_PURPLE);
enum State {
NORMAL(ChatColor.AQUA),
DIMINISHING(ChatColor.YELLOW),
LIMIT(ChatColor.RED),
/**
* @since v2.7.4
*/
NEGATIVE(ChatColor.DARK_PURPLE);
private final ChatColor color;

State(ChatColor color) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public class Challenge {
public static final int MAX_DETAILS = 11;
public static final int MAX_LINE = 30;

public enum Type { PLAYER, ISLAND, ISLAND_LEVEL;
public enum Type {
PLAYER, ISLAND, ISLAND_LEVEL;

static Type from(String s) {
if (s == null || s.trim().isEmpty() || s.trim().toLowerCase().equals("onplayer")) {
return PLAYER;
Expand All @@ -37,6 +39,7 @@ static Type from(String s) {
return ISLAND;
}
}

private final String name;
private final String description;
private final String displayName;
Expand Down Expand Up @@ -163,10 +166,8 @@ public ItemStack getDisplayItem(ChallengeCompletion completion, boolean withCurr
currentChallengeItem.setAmount(completion.getTimesCompleted() < currentChallengeItem.getMaxStackSize() ? completion.getTimesCompleted() : currentChallengeItem.getMaxStackSize());
if (completion.isOnCooldown()) {
long cooldown = completion.getCooldownInMillis();
if (timesCompleted < getRepeatLimit() || getRepeatLimit() <= 0)
{
if (getRepeatLimit() > 0)
{
if (timesCompleted < getRepeatLimit() || getRepeatLimit() <= 0) {
if (getRepeatLimit() > 0) {
lores.add(tr("\u00a74You can complete this {0} more time(s).", getRepeatLimit() - timesCompleted));
}
if (cooldown >= ChallengeLogic.MS_DAY) {
Expand All @@ -179,8 +180,7 @@ public ItemStack getDisplayItem(ChallengeCompletion completion, boolean withCurr
final int minutes = Math.round(cooldown / ChallengeLogic.MS_MIN);
lores.add(tr("\u00a74Requirements will reset in {0} minutes.", minutes));
}
}else
{
} else {
lores.add(tr("\u00a74This challenge is currently unavailable."));
if (cooldown >= ChallengeLogic.MS_DAY) {
final int days = (int) (cooldown / ChallengeLogic.MS_DAY);
Expand Down Expand Up @@ -278,7 +278,7 @@ public Reward getReward() {
public Reward getRepeatReward() {
return repeatReward;
}

public int getRepeatLimit() {
return repeatLimit;
}
Expand All @@ -301,7 +301,7 @@ public List<String> getMissingRequirements(PlayerInfo playerInfo) {
return Collections.emptyList();
}
String missingList = "" + missing;
missingList = missingList.substring(1, missingList.length()-1);
missingList = missingList.substring(1, missingList.length() - 1);
return wordWrap(tr("\u00a77Requires {0}", missingList), MAX_LINE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,14 @@ public void load() {
}

ConfigurationSection negativeReturnSection = config.getConfigurationSection("negativeReturns");
for (String blockKey : negativeReturnSection.getKeys(false)){
int[] blockIds = getBlockIds(blockKey);
int value = negativeReturnSection.getInt(blockKey, 0);
for (int blockId: blockIds) {
blockNV[blockId] = value;
}
if (negativeReturnSection != null) {
for (String blockKey : negativeReturnSection.getKeys(false)) {
int[] blockIds = getBlockIds(blockKey);
int value = negativeReturnSection.getInt(blockKey, 0);
for (int blockId : blockIds) {
blockNV[blockId] = value;
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
import us.talabrek.ultimateskyblock.util.ServerUtil;
import dk.lockfuglsang.minecraft.util.TimeUtil;
import us.talabrek.ultimateskyblock.util.VersionUtil;
import us.talabrek.ultimateskyblock.uuid.BukkitPlayerDB;
import us.talabrek.ultimateskyblock.uuid.FilePlayerDB;
import us.talabrek.ultimateskyblock.uuid.MemoryPlayerDB;
import us.talabrek.ultimateskyblock.uuid.PlayerDB;
Expand Down Expand Up @@ -996,9 +997,12 @@ private void reloadConfigs() {
String playerDbStorage = getConfig().getString("options.advanced.playerdb.storage", "yml");
if (playerDbStorage.equalsIgnoreCase("yml")) {
playerDB = new FilePlayerDB(this);
} else {
} else if (playerDbStorage.equalsIgnoreCase("memory")) {
playerDB = new MemoryPlayerDB(getConfig());
} else {
playerDB = new BukkitPlayerDB();
}

getServer().getPluginManager().registerEvents(playerDB, this);
teleportLogic = new TeleportLogic(this);
PlayerUtil.loadConfig(playerDB, getConfig());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package us.talabrek.ultimateskyblock.uuid;

import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

/**
* Non performing PlayerDB that goes directly to the Bukkit implementation
*/
public class BukkitPlayerDB implements PlayerDB {
@Override
public UUID getUUIDFromName(String name) {
if (UNKNOWN_PLAYER_NAME.equalsIgnoreCase(name)) {
return UNKNOWN_PLAYER_UUID;
}
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name);
return offlinePlayer != null ? offlinePlayer.getUniqueId() : null;
}

@Override
public UUID getUUIDFromName(String name, boolean lookup) {
return getUUIDFromName(name);
}

@Override
public String getName(UUID uuid) {
if (UNKNOWN_PLAYER_UUID.equals(uuid)) {
return UNKNOWN_PLAYER_NAME;
}
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
return offlinePlayer != null ? offlinePlayer.getName() : null;
}

@Override
public String getDisplayName(UUID uuid) {
Player player = Bukkit.getPlayer(uuid);
return player != null ? player.getDisplayName() : null;
}

@Override
public String getDisplayName(String playerName) {
Player player = Bukkit.getPlayer(playerName);
return player != null ? player.getDisplayName() : null;
}

@Override
public Set<String> getNames(String search) {
Set<String> names = new HashSet<>();
Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
for (Player player : onlinePlayers) {
if (player != null && player.isOnline() && player.getName() != null) {
names.add(player.getName());
}
}
return names;
}

@Override
public void updatePlayer(UUID uuid, String name, String displayName) {
// Do nothing
}

@Override
public Player getPlayer(UUID uuid) {
return Bukkit.getPlayer(uuid);
}

@Override
public Player getPlayer(String name) {
return Bukkit.getPlayer(name);
}

@Override
public void shutdown() {
// Do nothing
}
}
6 changes: 3 additions & 3 deletions uSkyBlock-Core/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ options:

# Controls advanced behaviour reg. the internal playerdb
playerdb:
# valid values are: yml, memory
storage: memory
# valid values are: yml, memory, bukkit
storage: bukkit

# Section about restarting your island (or accepting an invite).
restart:
Expand Down Expand Up @@ -435,7 +435,7 @@ placeholder:
servercommandplaceholder: false

# DO NOT TOUCH THE FIELDS BELOW
version: 60
version: 61
force-replace:
options.party.invite-timeout: 100
options.island.islandTeleportDelay: 5
Expand Down
2 changes: 1 addition & 1 deletion uSkyBlock-Core/src/main/resources/levelConfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,4 @@ diminishingReturns:
'192': 5000
negativeReturns:
'154': 5
version: 8
version: 9

0 comments on commit 1622625

Please sign in to comment.