Level Update
This commit is contained in:
parent
6b9c75353c
commit
4cf487503b
34 changed files with 178 additions and 65 deletions
|
|
@ -0,0 +1,41 @@
|
|||
package org.gsdistance.grimmsServer.Stats;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||
|
||||
public class LevelHandler {
|
||||
private final String playerName;
|
||||
private final PlayerStats playerStats;
|
||||
public LevelHandler(Player player) {
|
||||
this.playerStats = PlayerStats.getPlayerStats(player);
|
||||
this.playerName = player.getName();
|
||||
}
|
||||
public static LevelHandler getLevelHandler(Player player) {
|
||||
return new LevelHandler(player);
|
||||
}
|
||||
public int getLevel() {
|
||||
return (int) playerStats.getStat("level");
|
||||
}
|
||||
public double getXp() {
|
||||
return (Double) playerStats.getStat("xp");
|
||||
}
|
||||
public double getXpToLevel() {
|
||||
return Math.pow(getLevel(),1.7) * 100;
|
||||
}
|
||||
public int addExp(double xp){
|
||||
double exp = xp + getXp();
|
||||
int lvlups = 0;
|
||||
while(exp > getXpToLevel()){
|
||||
exp -= getXpToLevel();
|
||||
playerStats.changeStat("level",1);
|
||||
playerStats.changeStat("money", (int) Math.min(2147483645,Math.pow(getLevel(),1.5) * 10));
|
||||
lvlups++;
|
||||
}
|
||||
playerStats.setStat("xp",exp);
|
||||
playerStats.setStat("xp_required",getXpToLevel());
|
||||
if(lvlups>0){
|
||||
GrimmsServer.instance.getServer().broadcastMessage("[" + playerName + "] " + "Has leveled up to " + getLevel() + "!");
|
||||
}
|
||||
return lvlups;
|
||||
}
|
||||
}
|
||||
|
|
@ -14,33 +14,31 @@ public class PlayerStatLeaderBoard {
|
|||
"join_count", Integer.class,
|
||||
"tPoint", Double.class,
|
||||
"block_break_count", Long.class,
|
||||
"money", Double.class
|
||||
);
|
||||
public static final Map<String, String> StatNames = Map.of(
|
||||
"total_kill_count", "Kills",
|
||||
"death_count", "Deaths",
|
||||
"join_count", "Join Count",
|
||||
"tPoint", "Total Points",
|
||||
"block_break_count", "Blocks Broken",
|
||||
"money", "Money"
|
||||
"money", Double.class,
|
||||
"level", Integer.class
|
||||
);
|
||||
public Map<String, LeaderboardEntry> leaderboard;
|
||||
public PlayerStatLeaderBoard () {
|
||||
|
||||
public PlayerStatLeaderBoard() {
|
||||
this.leaderboard = Map.of(
|
||||
"total_kill_count", new LeaderboardEntry("None", 0),
|
||||
"death_count", new LeaderboardEntry("None", 0),
|
||||
"join_count", new LeaderboardEntry("None", 0),
|
||||
"tPoint", new LeaderboardEntry("None", 0),
|
||||
"block_break_count", new LeaderboardEntry("None", 0),
|
||||
"money", new LeaderboardEntry("None", 0)
|
||||
"money", new LeaderboardEntry("None", 0),
|
||||
"level", new LeaderboardEntry("None", 0)
|
||||
);
|
||||
}
|
||||
public static PlayerStatLeaderBoard getPlayerStatLeaderBoard () {
|
||||
return new Gson().fromJson((String) ServerStats.getServerStats().getStat("leaderboard"),PlayerStatLeaderBoard.class);
|
||||
|
||||
public static PlayerStatLeaderBoard getPlayerStatLeaderBoard() {
|
||||
return new Gson().fromJson((String) ServerStats.getServerStats().getStat("leaderboard"), PlayerStatLeaderBoard.class);
|
||||
}
|
||||
public void savePlayerStatLeaderBoard () {
|
||||
|
||||
public void savePlayerStatLeaderBoard() {
|
||||
ServerStats.getServerStats().setStat("leaderboard", new Gson().toJson(this));
|
||||
}
|
||||
|
||||
public boolean checkPlayer(Player player) {
|
||||
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
|
||||
boolean pass = false;
|
||||
|
|
|
|||
|
|
@ -9,9 +9,11 @@ import org.gsdistance.grimmsServer.GrimmsServer;
|
|||
|
||||
import java.util.Dictionary;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
public class PlayerStats {
|
||||
public static final Dictionary<String, PersistentDataType<?, ?>> Stats = new Hashtable<>();
|
||||
|
||||
static {
|
||||
Stats.put("death_count", PersistentDataType.INTEGER);
|
||||
Stats.put("money", PersistentDataType.DOUBLE);
|
||||
|
|
@ -19,8 +21,13 @@ public class PlayerStats {
|
|||
Stats.put("join_count", PersistentDataType.INTEGER);
|
||||
Stats.put("tPoint", PersistentDataType.DOUBLE);
|
||||
Stats.put("block_break_count", PersistentDataType.LONG);
|
||||
Stats.put("level", PersistentDataType.INTEGER);
|
||||
Stats.put("xp", PersistentDataType.DOUBLE);
|
||||
Stats.put("xp_required", PersistentDataType.DOUBLE);
|
||||
}
|
||||
public static final Dictionary<String,String> StatNames = new Hashtable<>();
|
||||
|
||||
public static final Dictionary<String, String> StatNames = new Hashtable<>();
|
||||
|
||||
static {
|
||||
StatNames.put("death_count", "Death Count");
|
||||
StatNames.put("money", "Money");
|
||||
|
|
@ -28,7 +35,21 @@ public class PlayerStats {
|
|||
StatNames.put("join_count", "Join Count");
|
||||
StatNames.put("tPoint", "Total Points");
|
||||
StatNames.put("block_break_count", "Block Break Count");
|
||||
StatNames.put("level", "Level");
|
||||
StatNames.put("xp", "Experience");
|
||||
StatNames.put("xp_required", "Experience Required");
|
||||
}
|
||||
public static final List<String> StatOrder = List.of(
|
||||
"death_count",
|
||||
"money",
|
||||
"total_kill_count",
|
||||
"join_count",
|
||||
"tPoint",
|
||||
"block_break_count",
|
||||
"level",
|
||||
"xp",
|
||||
"xp_required"
|
||||
);
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
private final PersistentDataContainer dataContainer;
|
||||
|
|
@ -78,6 +99,12 @@ public class PlayerStats {
|
|||
currentStat = 0.0;
|
||||
}
|
||||
dataContainer.set(new NamespacedKey(plugin, stat), PersistentDataType.DOUBLE, currentStat + amount);
|
||||
} else if (type == PersistentDataType.LONG) {
|
||||
Long currentStat = dataContainer.get(new NamespacedKey(plugin, stat), PersistentDataType.LONG);
|
||||
if (currentStat == null) {
|
||||
currentStat = 0L;
|
||||
}
|
||||
dataContainer.set(new NamespacedKey(plugin, stat), PersistentDataType.LONG, currentStat + amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,13 +19,16 @@ import java.util.logging.Level;
|
|||
|
||||
public class ServerStats {
|
||||
public static final Dictionary<String, Type> Stats = new Hashtable<>();
|
||||
|
||||
static {
|
||||
Stats.put("death_count", Integer.class);
|
||||
Stats.put("join_count", Integer.class);
|
||||
Stats.put("market", String.class);
|
||||
Stats.put("leaderboard", String.class);
|
||||
}
|
||||
public static final Dictionary<String,String> StatNames = new Hashtable<>();
|
||||
|
||||
public static final Dictionary<String, String> StatNames = new Hashtable<>();
|
||||
|
||||
static {
|
||||
StatNames.put("death_count", "Death Count");
|
||||
StatNames.put("join_count", "Join Count");
|
||||
|
|
@ -42,6 +45,7 @@ public class ServerStats {
|
|||
this.statsFile = new File(plugin.getDataFolder(), "server_stats.json");
|
||||
loadStats();
|
||||
}
|
||||
|
||||
public static ServerStats getServerStats() {
|
||||
return new ServerStats(GrimmsServer.instance);
|
||||
}
|
||||
|
|
@ -55,7 +59,8 @@ public class ServerStats {
|
|||
return;
|
||||
}
|
||||
try (FileReader reader = new FileReader(statsFile)) {
|
||||
Type type = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
Type type = new TypeToken<Map<String, Object>>() {
|
||||
}.getType();
|
||||
stats = new Gson().fromJson(reader, type);
|
||||
if (!stats.containsKey("market")) {
|
||||
stats.put("market", new Gson().toJson(new Market())); // Initialize market stat
|
||||
|
|
|
|||
|
|
@ -12,13 +12,16 @@ import java.util.Hashtable;
|
|||
|
||||
public class WorldStats {
|
||||
public static final Dictionary<String, PersistentDataType<?, ?>> Stats = new Hashtable<>();
|
||||
|
||||
static {
|
||||
Stats.put("death_count", PersistentDataType.INTEGER);
|
||||
Stats.put("block_break_count", PersistentDataType.LONG);
|
||||
Stats.put("wPoint", PersistentDataType.DOUBLE);
|
||||
Stats.put("join_count", PersistentDataType.INTEGER);
|
||||
}
|
||||
public static final Dictionary<String,String> StatNames = new Hashtable<>();
|
||||
|
||||
public static final Dictionary<String, String> StatNames = new Hashtable<>();
|
||||
|
||||
static {
|
||||
StatNames.put("death_count", "Death Count");
|
||||
StatNames.put("block_break_count", "Block Break Count");
|
||||
|
|
@ -34,7 +37,7 @@ public class WorldStats {
|
|||
this.dataContainer = world.getPersistentDataContainer();
|
||||
}
|
||||
|
||||
public static WorldStats getWorldStats(World world){
|
||||
public static WorldStats getWorldStats(World world) {
|
||||
return new WorldStats(GrimmsServer.instance, world);
|
||||
}
|
||||
|
||||
|
|
@ -75,11 +78,11 @@ public class WorldStats {
|
|||
}
|
||||
dataContainer.set(new NamespacedKey(plugin, stat), PersistentDataType.DOUBLE, currentStat + amount);
|
||||
} else if (type == PersistentDataType.LONG) {
|
||||
Long currentStat = dataContainer.get(new NamespacedKey(plugin, stat), PersistentDataType.LONG);
|
||||
if (currentStat == null) {
|
||||
currentStat = 0L;
|
||||
}
|
||||
dataContainer.set(new NamespacedKey(plugin, stat), PersistentDataType.LONG, currentStat + amount);
|
||||
Long currentStat = dataContainer.get(new NamespacedKey(plugin, stat), PersistentDataType.LONG);
|
||||
if (currentStat == null) {
|
||||
currentStat = 0L;
|
||||
}
|
||||
dataContainer.set(new NamespacedKey(plugin, stat), PersistentDataType.LONG, currentStat + amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue