diff --git a/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java b/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java index 93f4835a..d30e97c1 100644 --- a/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java +++ b/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java @@ -392,13 +392,11 @@ public class Placeholder { case user_totallevels: return Integer.toString(user.getTotalLevels()); case user_points: - PlayerPoints pointInfo = Jobs.getPointsData().getPlayerPointsInfo(user.getUniqueId()); NumberFormat format = NumberFormat.getInstance(Locale.ENGLISH); - return format.format(pointInfo.getCurrentPoints()); + return format.format(user.getPointsData().getCurrentPoints()); case user_total_points: format = NumberFormat.getInstance(Locale.ENGLISH); - pointInfo = Jobs.getPointsData().getPlayerPointsInfo(user.getUniqueId()); - return format.format(pointInfo.getTotalPoints()); + return format.format(user.getPointsData().getTotalPoints()); case user_issaved: return convert(user.isSaved()); case user_displayhonorific: diff --git a/src/main/java/com/gamingmesh/jobs/PlayerManager.java b/src/main/java/com/gamingmesh/jobs/PlayerManager.java index cfc4d148..de7bf4f7 100644 --- a/src/main/java/com/gamingmesh/jobs/PlayerManager.java +++ b/src/main/java/com/gamingmesh/jobs/PlayerManager.java @@ -335,9 +335,7 @@ public class PlayerManager { } if (points != null) - Jobs.getPointsData().addPlayer(jPlayer.getUniqueId(), points); - else - Jobs.getPointsData().addPlayer(jPlayer.getUniqueId()); + jPlayer.setPoints(points); if (logs != null) jPlayer.setLog(logs); diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/editpoints.java b/src/main/java/com/gamingmesh/jobs/commands/list/editpoints.java index d93694ce..50b1d148 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/editpoints.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/editpoints.java @@ -31,7 +31,7 @@ public class editpoints implements Cmd { return true; } - PlayerPoints pointInfo = Jobs.getPointsData().getPlayerPointsInfo(jPlayer.getUniqueId()); + PlayerPoints pointInfo = jPlayer.getPointsData(); if (pointInfo == null) { sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", jPlayer.getName())); return true; diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/points.java b/src/main/java/com/gamingmesh/jobs/commands/list/points.java index c2a39119..9ed46370 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/points.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/points.java @@ -38,7 +38,7 @@ public class points implements Cmd { return true; } - PlayerPoints pointInfo = Jobs.getPointsData().getPlayerPointsInfo(jPlayer.getUniqueId()); + PlayerPoints pointInfo = jPlayer.getPointsData(); sender.sendMessage(Jobs.getLanguage().getMessage("general.info.toplineseparator", "%playername%", jPlayer.getName())); sender.sendMessage(Jobs.getLanguage().getMessage("command.points.currentpoints", "%currentpoints%", (int) (pointInfo.getCurrentPoints() * 100) / 100D)); diff --git a/src/main/java/com/gamingmesh/jobs/config/ShopManager.java b/src/main/java/com/gamingmesh/jobs/config/ShopManager.java index aea6df05..6b6874a3 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ShopManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ShopManager.java @@ -107,8 +107,11 @@ public class ShopManager { // String title = Jobs.getLanguage().getMessage("command.shop.info.title"); // if (title.length() > 32) // title = title.substring(0, 30) + ".."; + + + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); - PlayerPoints pointsInfo = Jobs.getPointsData().getPlayerPointsInfo(player.getUniqueId()); + PlayerPoints pointsInfo = jPlayer.getPointsData(); double points = 0D; if (pointsInfo != null) points = (int) (pointsInfo.getCurrentPoints() * 100.0) / 100.0; diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index 85ab3e0d..fe3e25de 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -77,10 +77,40 @@ public class JobsPlayer { private int doneQuests = 0; private int skippedQuests = 0; + private PlayerPoints pointsData = null; + public JobsPlayer(String userName) { this.userName = userName; } + public PlayerPoints getPointsData() { + if (pointsData == null) + pointsData = new PlayerPoints(); + return pointsData; + } + + public void addPoints(Double points) { + getPointsData().addPoints(points); + } + + public void takePoints(Double points) { + getPointsData().takePoints(points); + } + + public void setPoints(Double points) { + getPointsData().setPoints(points); + } + + public void setPoints(PlayerPoints points) { + getPointsData().setPoints(points.getCurrentPoints()); + getPointsData().setTotalPoints(points.getTotalPoints()); + getPointsData().setNewEntry(points.isNewEntry()); + } + + public boolean havePoints(double points) { + return getPointsData().getCurrentPoints() >= points; + } + public ArchivedJobs getArchivedJobs() { return archivedJobs; } diff --git a/src/main/java/com/gamingmesh/jobs/container/PlayerPoints.java b/src/main/java/com/gamingmesh/jobs/container/PlayerPoints.java index 624e98cf..dfe9aa46 100644 --- a/src/main/java/com/gamingmesh/jobs/container/PlayerPoints.java +++ b/src/main/java/com/gamingmesh/jobs/container/PlayerPoints.java @@ -2,9 +2,9 @@ package com.gamingmesh.jobs.container; public class PlayerPoints { - private double current = 0D; - private double total = 0D; - private boolean newEntry = false; + private double current = 0D; + private double total = 0D; + private boolean newEntry = false; public PlayerPoints() { newEntry = true; @@ -50,4 +50,8 @@ public class PlayerPoints { public void setNewEntry(boolean newEntry) { this.newEntry = newEntry; } + + public void setTotalPoints(double total) { + this.total = total; + } } diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index 9c890019..0e7daf00 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -662,7 +662,7 @@ public abstract class JobsDAO { converted = false; Job job = Jobs.getJob(jobId); if (job != null) - ls.add(new JobsDAOData(job.getName(), res.getInt(JobsTableFields.level.getCollumn()), res.getDouble(JobsTableFields.experience.getCollumn()))); + ls.add(new JobsDAOData(job.getName(), res.getInt(JobsTableFields.level.getCollumn()), res.getDouble(JobsTableFields.experience.getCollumn()))); } map.put(id, ls); @@ -2003,7 +2003,7 @@ public abstract class JobsDAO { PreparedStatement prest = null; try { - PlayerPoints pointInfo = Jobs.getPointsData().getPlayerPointsInfo(jPlayer.getUniqueId()); + PlayerPoints pointInfo = jPlayer.getPointsData(); prest = conn.prepareStatement("INSERT INTO `" + DBTables.PointsTable.getTableName() + "` (`" + PointsTableFields.totalpoints.getCollumn() + "`, `" + PointsTableFields.currentpoints.getCollumn() + "`, `" + PointsTableFields.userid.getCollumn() + "`) VALUES (?, ?, ?);"); prest.setDouble(1, pointInfo.getTotalPoints()); @@ -2030,9 +2030,8 @@ public abstract class JobsDAO { res = prest.executeQuery(); if (res.next()) { - Jobs.getPointsData().addPlayer(player.getUniqueId(), res.getDouble(PointsTableFields.currentpoints.getCollumn()), res.getDouble(PointsTableFields.totalpoints.getCollumn())); - } else { - Jobs.getPointsData().addPlayer(player.getUniqueId()); + player.getPointsData().setPoints(res.getDouble(PointsTableFields.currentpoints.getCollumn())); + player.getPointsData().setTotalPoints(res.getDouble(PointsTableFields.totalpoints.getCollumn())); } } catch (SQLException e) { e.printStackTrace(); diff --git a/src/main/java/com/gamingmesh/jobs/economy/PointsData.java b/src/main/java/com/gamingmesh/jobs/economy/PointsData.java index 57bf8055..d0ea29ca 100644 --- a/src/main/java/com/gamingmesh/jobs/economy/PointsData.java +++ b/src/main/java/com/gamingmesh/jobs/economy/PointsData.java @@ -1,6 +1,5 @@ package com.gamingmesh.jobs.economy; -import java.util.HashMap; import java.util.UUID; import com.gamingmesh.jobs.Jobs; @@ -8,44 +7,39 @@ import com.gamingmesh.jobs.container.PlayerPoints; public class PointsData { - private HashMap Pointbase = new HashMap<>(); - - public PointsData() { - } - - public HashMap getPointBase() { - return Pointbase; - } - - public void addPlayer(UUID uuid) { - addPlayer(uuid, 0D); - } - - public void addPlayer(UUID uuid, double points) { - addPlayer(uuid, points, 0D); - } - - public void addPlayer(UUID uuid, double points, double total) { - addPlayer(uuid, new PlayerPoints(points, total)); - } - - public void addPlayer(UUID uuid, PlayerPoints points) { - if (Jobs.getGCManager().MultiServerCompatability() && Pointbase.containsKey(uuid)) - Pointbase.remove(uuid); - - if (!Pointbase.containsKey(uuid)) - Pointbase.put(uuid, points); - } - - public void addPoints(UUID uuid, Double points) { - if (!Pointbase.containsKey(uuid)) - addPlayer(uuid, points); - else { - Pointbase.get(uuid).addPoints(points); - } - } - - public PlayerPoints getPlayerPointsInfo(UUID uuid) { - return Pointbase.containsKey(uuid) ? Pointbase.get(uuid) : new PlayerPoints(); - } +// @Deprecated +// public void addPlayer(UUID uuid) { +// Jobs.getPlayerManager().getJobsPlayer(uuid).getPointsData(); +// } +// +// @Deprecated +// public void addPlayer(UUID uuid, double points) { +// Jobs.getPlayerManager().getJobsPlayer(uuid).addPoints(points); +// } +// +// @Deprecated +// public void addPlayer(UUID uuid, double points, double total) { +// addPlayer(uuid, new PlayerPoints(points, total)); +// +// Jobs.getPlayerManager().getJobsPlayer(uuid).getPointsData().setPoints(points); +// Jobs.getPlayerManager().getJobsPlayer(uuid).getPointsData().setTotalPoints(total); +// } +// +// @Deprecated +// public void addPlayer(UUID uuid, PlayerPoints points) { +// PlayerPoints pi = Jobs.getPlayerManager().getJobsPlayer(uuid).getPointsData(); +// pi.setPoints(points.getCurrentPoints()); +// pi.setTotalPoints(points.getTotalPoints()); +// pi.setNewEntry(points.isNewEntry()); +// } +// +// @Deprecated +// public void addPoints(UUID uuid, Double points) { +// Jobs.getPlayerManager().getJobsPlayer(uuid).addPoints(points); +// } +// +// @Deprecated +// public PlayerPoints getPlayerPointsInfo(UUID uuid) { +// return Jobs.getPlayerManager().getJobsPlayer(uuid).getPointsData(); +// } } diff --git a/src/main/java/com/gamingmesh/jobs/tasks/BufferedPaymentTask.java b/src/main/java/com/gamingmesh/jobs/tasks/BufferedPaymentTask.java index 8613b75b..3a662af9 100644 --- a/src/main/java/com/gamingmesh/jobs/tasks/BufferedPaymentTask.java +++ b/src/main/java/com/gamingmesh/jobs/tasks/BufferedPaymentTask.java @@ -45,6 +45,6 @@ public class BufferedPaymentTask implements Runnable { } if (payment.get(CurrencyType.POINTS) != 0D) - Jobs.getPointsData().addPoints(payment.getOfflinePlayer().getUniqueId(), payment.get(CurrencyType.POINTS)); + Jobs.getPlayerManager().getJobsPlayer(payment.getOfflinePlayer().getUniqueId()).getPointsData().addPoints(payment.get(CurrencyType.POINTS)); } } \ No newline at end of file