mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-26 04:25:15 +01:00
Deprecating points methods and moving everything into player object
This commit is contained in:
parent
28a8d28818
commit
c343407223
@ -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:
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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<UUID, PlayerPoints> Pointbase = new HashMap<>();
|
||||
|
||||
public PointsData() {
|
||||
}
|
||||
|
||||
public HashMap<UUID, PlayerPoints> 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();
|
||||
// }
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user