Fixed points not properly resettings to zero when they are close due to being able to flip flop between - and + near 0
This commit is contained in:
parent
0440ab102f
commit
2fcc1e4afa
|
|
@ -91,6 +91,8 @@ public class EconUser {
|
||||||
points += remove;
|
points += remove;
|
||||||
}
|
}
|
||||||
pointsMap.put(villagerType, points);
|
pointsMap.put(villagerType, points);
|
||||||
|
if (points == 0)
|
||||||
|
notifyPlayer(uuid, villagerType);
|
||||||
if (Config.DEBUG)
|
if (Config.DEBUG)
|
||||||
Logger.info("Removed % points from villagerType: % for %",
|
Logger.info("Removed % points from villagerType: % for %",
|
||||||
String.valueOf(remove), villagerType, uuid.toString());
|
String.valueOf(remove), villagerType, uuid.toString());
|
||||||
|
|
@ -100,7 +102,7 @@ public class EconUser {
|
||||||
if (pointsMap.getOrDefault(villagerType, 0) < 0)
|
if (pointsMap.getOrDefault(villagerType, 0) < 0)
|
||||||
points *= -1;
|
points *= -1;
|
||||||
if (Config.DEBUG) {
|
if (Config.DEBUG) {
|
||||||
Logger.info("Set villagerType: % to % (was %) for &",
|
Logger.info("Set villagerType: % to % (was %) for %",
|
||||||
villagerType, String.valueOf(points),
|
villagerType, String.valueOf(points),
|
||||||
String.valueOf(pointsMap.getOrDefault(villagerType, 0)), uuid.toString());
|
String.valueOf(pointsMap.getOrDefault(villagerType, 0)), uuid.toString());
|
||||||
}
|
}
|
||||||
|
|
@ -118,11 +120,21 @@ public class EconUser {
|
||||||
int remove = points;
|
int remove = points;
|
||||||
if (remove < 0)
|
if (remove < 0)
|
||||||
remove *= -1;
|
remove *= -1;
|
||||||
int i = (int) (0.93 * remove) - 30;
|
int newPoints = Math.max(0, (int) (0.93 * remove) - 30);
|
||||||
setPoints(villagerType, i < 10 && i > -10 ? 0 : i);
|
if (newPoints < 10)
|
||||||
|
newPoints = 0;
|
||||||
|
setPoints(villagerType, newPoints);
|
||||||
|
if (newPoints == 0)
|
||||||
|
notifyPlayer(uuid, villagerType);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void notifyPlayer(UUID uuid, String villagerType) {
|
||||||
|
Player player = Bukkit.getPlayer(uuid);
|
||||||
|
if (player != null && player.isOnline())
|
||||||
|
player.sendMiniMessage(Config.NOTIFY_POINTS_RESET, Placeholder.unparsed("villager_type", villagerType));
|
||||||
|
}
|
||||||
|
|
||||||
public static void tryLoadUser(UUID uuid) {
|
public static void tryLoadUser(UUID uuid) {
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user