RC04 - Patch 0002

Changelog:
 - Renamed LuckContainer#baseValue() to getValue()
 - Changed the way files save by using the Map#values() call instead of iterating the kvp's.
 - Made the actual percentage rng value round to the closest whole number before being checked.
 - Changed Luck#defaultValue() to getDefaultValue().
This commit is contained in:
Paldiu 2022-04-09 08:38:42 -05:00
parent cbc57d5971
commit d08b240ff9
14 changed files with 22 additions and 23 deletions

Binary file not shown.

View File

@ -18,5 +18,5 @@ public interface LuckContainer extends Serializable {
Player associatedPlayer(); Player associatedPlayer();
double baseValue(); double getValue();
} }

View File

@ -52,6 +52,6 @@ public final class FeelingLucky extends JavaPlugin {
@Override @Override
public void onDisable() { public void onDisable() {
Bukkit.getLogger().info("Saving all player configurations..."); Bukkit.getLogger().info("Saving all player configurations...");
configMap.forEach((u, pc) -> pc.save()); configMap.values().forEach(PlayerConfig::save);
} }
} }

View File

@ -3,7 +3,6 @@ package io.github.simplex.luck;
import io.github.simplex.lib.Messages; import io.github.simplex.lib.Messages;
import io.github.simplex.luck.player.Luck; import io.github.simplex.luck.player.Luck;
import io.github.simplex.luck.player.PlayerConfig; import io.github.simplex.luck.player.PlayerConfig;
import io.github.simplex.luck.player.PlayerHandler;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextColor;
@ -47,21 +46,21 @@ public class LuckCMD extends Command implements TabCompleter {
case "set" -> { case "set" -> {
luck.setValue(amount); luck.setValue(amount);
plugin.handler.updatePlayer(player, luck); plugin.handler.updatePlayer(player, luck);
config.setLuck(luck.baseValue()); config.setLuck(luck.getValue());
sender.sendMessage(Component.empty().content("Successfully reset " + args[1] + "'s Luck stat.")); sender.sendMessage(Component.empty().content("Successfully reset " + args[1] + "'s Luck stat."));
return true; return true;
} }
case "give" -> { case "give" -> {
luck.addTo(amount); luck.addTo(amount);
plugin.handler.updatePlayer(player, luck); plugin.handler.updatePlayer(player, luck);
config.setLuck(luck.baseValue()); config.setLuck(luck.getValue());
sender.sendMessage(Component.empty().content("Successfully reset " + args[1] + "'s Luck stat.")); sender.sendMessage(Component.empty().content("Successfully reset " + args[1] + "'s Luck stat."));
return true; return true;
} }
case "take" -> { case "take" -> {
luck.takeFrom(amount); luck.takeFrom(amount);
plugin.handler.updatePlayer(player, luck); plugin.handler.updatePlayer(player, luck);
config.setLuck(luck.baseValue()); config.setLuck(luck.getValue());
sender.sendMessage(Component.empty().content("Successfully reset " + args[1] + "'s Luck stat.")); sender.sendMessage(Component.empty().content("Successfully reset " + args[1] + "'s Luck stat."));
return true; return true;
} }
@ -83,7 +82,7 @@ public class LuckCMD extends Command implements TabCompleter {
} }
Luck luck = plugin.handler.getLuckContainer(player); Luck luck = plugin.handler.getLuckContainer(player);
sender.sendMessage(Component.empty().content("Luck stat for " + args[1] + ": " + luck.baseValue())); sender.sendMessage(Component.empty().content("Luck stat for " + args[1] + ": " + luck.getValue()));
return true; return true;
} }
@ -99,7 +98,7 @@ public class LuckCMD extends Command implements TabCompleter {
PlayerConfig config = FeelingLucky.getConfigMap().get(player.getUniqueId()); PlayerConfig config = FeelingLucky.getConfigMap().get(player.getUniqueId());
luck.reset(); luck.reset();
plugin.handler.updatePlayer(player, luck); plugin.handler.updatePlayer(player, luck);
config.setLuck(luck.baseValue()); config.setLuck(luck.getValue());
sender.sendMessage(Component.empty().content("Successfully reset " + args[1] + "'s Luck stat.")); sender.sendMessage(Component.empty().content("Successfully reset " + args[1] + "'s Luck stat."));
return true; return true;
} }

View File

@ -58,7 +58,7 @@ public class Luck implements LuckContainer {
rng = RNG().nextDouble(0.0, 1024.0); rng = RNG().nextDouble(0.0, 1024.0);
} }
double actual = (rng / 1024.0) * 100; double actual = Math.round((rng / 1024.0) * 100);
return (percentage >= actual); return (percentage >= actual);
} }
@ -101,7 +101,7 @@ public class Luck implements LuckContainer {
rng = RNG().nextDouble(0.0, 1024.0); rng = RNG().nextDouble(0.0, 1024.0);
} }
double actual = (rng / 1024) * 100; double actual = Math.round((rng / 1024) * 100);
if (multiplier() > 1.0) { if (multiplier() > 1.0) {
return ((percentage * multiplier()) >= actual); return ((percentage * multiplier()) >= actual);
@ -111,15 +111,15 @@ public class Luck implements LuckContainer {
} }
public void reset() { public void reset() {
setValue(defaultValue()); setValue(getDefaultValue());
} }
@Override @Override
public double baseValue() { public double getValue() {
return BASE_VALUE; return BASE_VALUE;
} }
public double defaultValue() { public double getDefaultValue() {
return player.getAttribute(Attribute.GENERIC_LUCK).getDefaultValue(); return player.getAttribute(Attribute.GENERIC_LUCK).getDefaultValue();
} }
@ -130,39 +130,39 @@ public class Luck implements LuckContainer {
} }
public void addTo(double value) { public void addTo(double value) {
if (value >= 1024.0 || (baseValue() + value) >= 1024.0) { if (value >= 1024.0 || (getValue() + value) >= 1024.0) {
setValue(1024.0); setValue(1024.0);
return; return;
} }
setValue(baseValue() + value); setValue(getValue() + value);
} }
public void takeFrom(double value) { public void takeFrom(double value) {
if (value <= -1024.0 || (baseValue() - value) <= -1024.0) { if (value <= -1024.0 || (getValue() - value) <= -1024.0) {
setValue(-1024.0); setValue(-1024.0);
return; return;
} }
setValue(baseValue() + value); setValue(getValue() + value);
} }
public double getPercentage() { public double getPercentage() {
return baseValue() - defaultValue(); return getValue() - getDefaultValue();
} }
public boolean notDefault() { public boolean notDefault() {
return baseValue() != defaultValue(); return getValue() != getDefaultValue();
} }
public boolean lessThan(double value) { public boolean lessThan(double value) {
return baseValue() < value; return getValue() < value;
} }
public boolean greaterThan(double value) { public boolean greaterThan(double value) {
return baseValue() > value; return getValue() > value;
} }
@Override @Override
public String toString() { public String toString() {
return "" + baseValue(); return "" + getValue();
} }
} }

View File

@ -47,7 +47,7 @@ public class PlayerConfig {
if (tempUsername != null && !tempUsername.equalsIgnoreCase(player.getName())) { if (tempUsername != null && !tempUsername.equalsIgnoreCase(player.getName())) {
config.set("username", player.getName()); config.set("username", player.getName());
config.set("luck", plugin.handler.getLuckContainer(player).defaultValue()); config.set("luck", plugin.handler.getLuckContainer(player).getDefaultValue());
config.set("multiplier", "1.0"); config.set("multiplier", "1.0");
save(); save();
} }