Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A boring update #5

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class HardcoreMetrics {
void start() {
Metrics metrics = new Metrics(plugin, 13641);

addBooleanPie(metrics, "reset_random_research_on_death", Config.INSTANCE::isResetResearchOnDeath);
addPercentChart(metrics, "chance-to-reset-random-research", 25, Config.INSTANCE::getResetResearchOnDeath);
addPercentChart(metrics, "chance_to_reset_all_researches_on_death", 25,
Config.INSTANCE::getResetAllResearchesOnDeath);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/walshy/hardcoreslimefun/events/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Events implements Listener {
public void onDeath(@Nonnull PlayerDeathEvent event) {
PlayerProfile.get(event.getEntity(), profile -> {
final boolean shouldResetAllResearches = Utils.chance(Config.INSTANCE.getResetAllResearchesOnDeath());
final boolean shouldResetOneResearch = Utils.chance(Config.INSTANCE.getResetResearchOnDeath());

// If we should reset all researches, do it
if (shouldResetAllResearches) {
Expand All @@ -30,11 +31,10 @@ public void onDeath(@Nonnull PlayerDeathEvent event) {
}
Utils.send(event.getEntity(), Config.INSTANCE.getLostAllResearch());

} else if (Config.INSTANCE.isResetResearchOnDeath()) {
} else if (shouldResetOneResearch) {
// If we should reset a random one, do it
final Research randomResearch = Utils.randomValue(profile.getResearches());
if (randomResearch == null) return;

profile.setResearched(randomResearch, false);
String message = Config.INSTANCE.getLostRandomResearch().replace("%research%", randomResearch.getName(event.getEntity()));
Utils.send(event.getEntity(), message);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/walshy/hardcoreslimefun/utils/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Config {
public static final Config INSTANCE = new Config();

// on-death.reset-random-research
private boolean resetResearchOnDeath;
private double resetResearchOnDeath;
// on-death.chance-to-reset-all-researches
private double resetAllResearchesOnDeath;

Expand All @@ -36,7 +36,7 @@ public class Config {
private String androidMalfunctioned;

public void load(@Nonnull FileConfiguration config) {
resetResearchOnDeath = config.getBoolean("on-death.reset-random-research", true);
resetResearchOnDeath = getPercent(config,"on-death.resetResearchChance",70);
wcy6457 marked this conversation as resolved.
Show resolved Hide resolved
resetAllResearchesOnDeath = getPercent(config, "on-death.chance-to-reset-all-researches", 5);

researchFailChance = getPercent(config, "on-research.chance-of-failure", 10);
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# If the plugin should auto-update
auto-update: true
on-death:
# If true, a player will lose a random research every death
reset-random-research: true
# Chance to reset one player's researches on death. Percent scale of 0 to 100.
# 100 will always fire and 0 will never fire.
chance-to-reset-random-research: 70
# Chance to reset all the player's researches on death. Percent scale of 0 to 100.
# 100 will always fire and 0 will never fire.
chance-to-reset-all-researches: 5
Expand Down