mirror of
https://github.com/SimplexDevelopment/FeelingLucky.git
synced 2024-11-22 01:45:02 +00:00
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:
parent
cbc57d5971
commit
d08b240ff9
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -18,5 +18,5 @@ public interface LuckContainer extends Serializable {
|
||||
|
||||
Player associatedPlayer();
|
||||
|
||||
double baseValue();
|
||||
double getValue();
|
||||
}
|
||||
|
@ -52,6 +52,6 @@ public final class FeelingLucky extends JavaPlugin {
|
||||
@Override
|
||||
public void onDisable() {
|
||||
Bukkit.getLogger().info("Saving all player configurations...");
|
||||
configMap.forEach((u, pc) -> pc.save());
|
||||
configMap.values().forEach(PlayerConfig::save);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package io.github.simplex.luck;
|
||||
import io.github.simplex.lib.Messages;
|
||||
import io.github.simplex.luck.player.Luck;
|
||||
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.TextComponent;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
@ -47,21 +46,21 @@ public class LuckCMD extends Command implements TabCompleter {
|
||||
case "set" -> {
|
||||
luck.setValue(amount);
|
||||
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."));
|
||||
return true;
|
||||
}
|
||||
case "give" -> {
|
||||
luck.addTo(amount);
|
||||
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."));
|
||||
return true;
|
||||
}
|
||||
case "take" -> {
|
||||
luck.takeFrom(amount);
|
||||
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."));
|
||||
return true;
|
||||
}
|
||||
@ -83,7 +82,7 @@ public class LuckCMD extends Command implements TabCompleter {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -99,7 +98,7 @@ public class LuckCMD extends Command implements TabCompleter {
|
||||
PlayerConfig config = FeelingLucky.getConfigMap().get(player.getUniqueId());
|
||||
luck.reset();
|
||||
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."));
|
||||
return true;
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public class Luck implements LuckContainer {
|
||||
rng = RNG().nextDouble(0.0, 1024.0);
|
||||
}
|
||||
|
||||
double actual = (rng / 1024.0) * 100;
|
||||
double actual = Math.round((rng / 1024.0) * 100);
|
||||
|
||||
return (percentage >= actual);
|
||||
}
|
||||
@ -101,7 +101,7 @@ public class Luck implements LuckContainer {
|
||||
rng = RNG().nextDouble(0.0, 1024.0);
|
||||
}
|
||||
|
||||
double actual = (rng / 1024) * 100;
|
||||
double actual = Math.round((rng / 1024) * 100);
|
||||
|
||||
if (multiplier() > 1.0) {
|
||||
return ((percentage * multiplier()) >= actual);
|
||||
@ -111,15 +111,15 @@ public class Luck implements LuckContainer {
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
setValue(defaultValue());
|
||||
setValue(getDefaultValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public double baseValue() {
|
||||
public double getValue() {
|
||||
return BASE_VALUE;
|
||||
}
|
||||
|
||||
public double defaultValue() {
|
||||
public double getDefaultValue() {
|
||||
return player.getAttribute(Attribute.GENERIC_LUCK).getDefaultValue();
|
||||
}
|
||||
|
||||
@ -130,39 +130,39 @@ public class Luck implements LuckContainer {
|
||||
}
|
||||
|
||||
public void addTo(double value) {
|
||||
if (value >= 1024.0 || (baseValue() + value) >= 1024.0) {
|
||||
if (value >= 1024.0 || (getValue() + value) >= 1024.0) {
|
||||
setValue(1024.0);
|
||||
return;
|
||||
}
|
||||
setValue(baseValue() + value);
|
||||
setValue(getValue() + 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);
|
||||
return;
|
||||
}
|
||||
setValue(baseValue() + value);
|
||||
setValue(getValue() + value);
|
||||
}
|
||||
|
||||
public double getPercentage() {
|
||||
return baseValue() - defaultValue();
|
||||
return getValue() - getDefaultValue();
|
||||
}
|
||||
|
||||
public boolean notDefault() {
|
||||
return baseValue() != defaultValue();
|
||||
return getValue() != getDefaultValue();
|
||||
}
|
||||
|
||||
public boolean lessThan(double value) {
|
||||
return baseValue() < value;
|
||||
return getValue() < value;
|
||||
}
|
||||
|
||||
public boolean greaterThan(double value) {
|
||||
return baseValue() > value;
|
||||
return getValue() > value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "" + baseValue();
|
||||
return "" + getValue();
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public class PlayerConfig {
|
||||
|
||||
if (tempUsername != null && !tempUsername.equalsIgnoreCase(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");
|
||||
save();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user