Skip to content

Commit

Permalink
Fixes death counts for new islands.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jul 6, 2019
1 parent 908027e commit 5adf2a3
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 89 deletions.
9 changes: 8 additions & 1 deletion src/main/java/world/bentobox/level/TopTen.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,14 @@ public TopTenData getTopTenList(World world) {
*/
private void loadTopTen() {
topTenList = new HashMap<>();
handler.loadObjects().forEach(tt -> topTenList.put(Bukkit.getWorld(tt.getUniqueId()), tt));
handler.loadObjects().forEach(tt -> {
World world = Bukkit.getWorld(tt.getUniqueId());
if (world != null) {
topTenList.put(world, tt);
} else {
addon.logError("TopTen world " + tt.getUniqueId() + " is not known on server. Skipping...");
}
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,6 @@ private void tidyUp() {
this.addon.getPlayers().getDeaths(this.world, this.island.getOwner());
}

// Just lazy check for min death count.
this.result.deathHandicap = Math.min(this.result.deathHandicap, this.addon.getSettings().getMaxDeaths());

long blockAndDeathPoints = this.result.rawBlockCount;

if (this.addon.getSettings().getDeathPenalty() > 0)
Expand Down
46 changes: 1 addition & 45 deletions src/main/java/world/bentobox/level/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ public class Settings {
private int deathpenalty;
private long levelCost;
private int levelWait;
private int maxDeaths;
private boolean islandResetDeathReset;
private boolean teamJoinDeathReset;
private List<String> gameModes = new ArrayList<>();

public Settings(Level level) {
Expand All @@ -40,9 +37,6 @@ public Settings(Level level) {
}
setDeathpenalty(level.getConfig().getInt("deathpenalty", 0));
setSumTeamDeaths(level.getConfig().getBoolean("sumteamdeaths"));
setMaxDeaths(level.getConfig().getInt("maxdeaths", 10));
setIslandResetDeathReset(level.getConfig().getBoolean("islandresetdeathreset", true));
setTeamJoinDeathReset(level.getConfig().getBoolean("teamjoindeathreset", true));
setUnderWaterMultiplier(level.getConfig().getDouble("underwater", 1D));
setLevelCost(level.getConfig().getInt("levelcost", 100));
if (getLevelCost() < 1) {
Expand Down Expand Up @@ -91,7 +85,7 @@ public Settings(Level level) {
worldBlockValues.put(bWorld, values);
}
} else {
level.getLogger().severe(() -> "Level Addon: No such world : " + world);
level.getLogger().severe(() -> "Level Addon: No such world in config.yml : " + world);
}
}
}
Expand Down Expand Up @@ -182,44 +176,6 @@ public final int getLevelWait() {
private void setLevelWait(int levelWait) {
this.levelWait = levelWait;
}
/**
* TODO: Use max deaths
* @return the maxDeaths
*/
public final int getMaxDeaths() {
return maxDeaths;
}
/**
* @param maxDeaths the maxDeaths to set
*/
private void setMaxDeaths(int maxDeaths) {
this.maxDeaths = maxDeaths;
}
/**
* @return the islandResetDeathReset
*/
public final boolean isIslandResetDeathReset() {
return islandResetDeathReset;
}
/**
* @param islandResetDeathReset the islandResetDeathReset to set
*/
private void setIslandResetDeathReset(boolean islandResetDeathReset) {
this.islandResetDeathReset = islandResetDeathReset;
}
/**
* @return the teamJoinDeathReset
*/
public final boolean isTeamJoinDeathReset() {
return teamJoinDeathReset;
}
/**
* @param teamJoinDeathReset the teamJoinDeathReset to set
*/
private void setTeamJoinDeathReset(boolean teamJoinDeathReset) {
this.teamJoinDeathReset = teamJoinDeathReset;
}

/**
* @return the worldBlockValues
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ public void onIsland(TeamKickEvent e) {
private void zeroLevel(Island island) {
if (cil.containsKey(island)) {
long level = cil.get(island).getResult().getLevel();
// Get deaths
int deaths = addon.getPlayers().getDeaths(island.getWorld(), island.getOwner());
// Death penalty calculation.
if (addon.getSettings().getLevelCost() != 0) {
// Add the deaths because this makes the original island that much "bigger"
level += deaths * addon.getSettings().getDeathPenalty() / addon.getSettings().getLevelCost();
}
addon.setInitialIslandLevel(island, level);
cil.remove(island);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/world/bentobox/level/objects/TopTenData.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ public void setTopTen(Map<UUID, Long> topTen) {

@Override
public String getUniqueId() {
// This is the world name
return uniqueId;
}

@Override
public void setUniqueId(String uniqueId) {
this.uniqueId = uniqueId;
// This is the world name - make it always lowercase
this.uniqueId = uniqueId.toLowerCase();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@
*/
public class TopTenRequestHandler extends AddonRequestHandler {

/**
* The level addon field.
*/
private Level addon;

/**
* This constructor creates a new TopTenRequestHandler instance.
*
* @param addon of type Level
*/
public TopTenRequestHandler(Level addon) {
super("top-ten-level");
this.addon = addon;
}

/**
* @see AddonRequestHandler#handle(Map<String, Object>)
*/
@Override
public Object handle(Map<String, Object> map) {
/**
* The level addon field.
*/
private Level addon;

/**
* This constructor creates a new TopTenRequestHandler instance.
*
* @param addon of type Level
*/
public TopTenRequestHandler(Level addon) {
super("top-ten-level");
this.addon = addon;
}

/**
* @see {@link AddonRequestHandler#handle(Map)}
*/
@Override
public Object handle(Map<String, Object> map) {
/*
What we need in the map:
Expand All @@ -47,14 +47,14 @@ public Object handle(Map<String, Object> map) {
- the map of top ten player UUIDs and their island levels. Can be less then 10.
*/

if (map == null || map.isEmpty()
|| map.get("world-name") == null || !(map.get("world-name") instanceof String)
|| Bukkit.getWorld((String) map.get("world-name")) == null) {
return Collections.emptyMap();
}
if (map == null || map.isEmpty()
|| map.get("world-name") == null || !(map.get("world-name") instanceof String)
|| Bukkit.getWorld((String) map.get("world-name")) == null) {
return Collections.emptyMap();
}

// Null-point check.
TopTenData data = addon.getTopTen().getTopTenList(Bukkit.getWorld((String) map.get("world-name")));
return data != null ? data.getTopTen() : Collections.emptyMap();
}
// Null-point check.
TopTenData data = addon.getTopTen().getTopTenList(Bukkit.getWorld((String) map.get("world-name")));
return data != null ? data.getTopTen() : Collections.emptyMap();
}
}
12 changes: 2 additions & 10 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,7 @@ deathpenalty: 100
# Sum team deaths - if true, all the teams deaths are summed
# If false, only the leader's deaths counts
sumteamdeaths: false
# Max deaths
# If player dies more than this, it doesn't count anymore
# Stops players from getting into an impossible situation
maxdeaths: 10
# Reset deaths on island reset
islandresetdeathreset: true
# Reset deaths on team join
teamjoindeathreset: true

# For other death related settings, see the GameModeAddon's config.yml settings.

# This section lists the limits for any particular block. Blocks over this amount
# are not counted.
Expand Down Expand Up @@ -651,7 +643,7 @@ blocks:
# If a block is not listed, the default value will be used
# Prefix with world name
worlds:
AcidIsland_world:
acidisland_world:
SAND: 0
SANDSTONE: 0
ICE: 0
Expand Down

0 comments on commit 5adf2a3

Please sign in to comment.