Fixes death counts for new islands.

Relates to https://github.com/BentoBoxWorld/Level/issues/63
and
https://github.com/BentoBoxWorld/BentoBox/pull/817
This commit is contained in:
tastybento 2019-07-06 11:45:58 -07:00
parent 908027e6ba
commit 5adf2a3ef9
7 changed files with 48 additions and 87 deletions

View File

@ -140,7 +140,14 @@ public class TopTen implements Listener {
*/
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...");
}
});
}
/**

View File

@ -232,9 +232,6 @@ public class CalcIslandLevel {
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)

View File

@ -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) {
@ -40,9 +37,6 @@ public class Settings {
}
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) {
@ -91,7 +85,7 @@ public class Settings {
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);
}
}
}
@ -182,44 +176,6 @@ public class Settings {
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
*/

View File

@ -100,6 +100,13 @@ public class IslandTeamListeners implements Listener {
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);
}

View File

@ -36,12 +36,14 @@ public class TopTenData implements DataObject {
@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();
}
/**

View File

@ -16,26 +16,26 @@ import world.bentobox.level.objects.TopTenData;
*/
public class TopTenRequestHandler extends AddonRequestHandler {
/**
* The level addon field.
*/
private Level addon;
/**
* 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;
}
/**
* 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) {
/**
* @see {@link AddonRequestHandler#handle(Map)}
*/
@Override
public Object handle(Map<String, Object> map) {
/*
What we need in the map:
@ -47,14 +47,14 @@ public class TopTenRequestHandler extends AddonRequestHandler {
- 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();
}
}

View File

@ -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.
@ -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