Level Update
This commit is contained in:
parent
6b9c75353c
commit
4cf487503b
34 changed files with 178 additions and 65 deletions
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -29,5 +29,9 @@ commands:
|
||||||
permission: grimmsserver.getMarket
|
permission: grimmsserver.getMarket
|
||||||
logLeaderboard:
|
logLeaderboard:
|
||||||
description: Displays the leaderboard of players with the most kills.
|
description: Displays the leaderboard of players with the most kills.
|
||||||
usage: /Leaderboard
|
usage: /logLeaderboard
|
||||||
permission: grimmsserver.logLeaderboard
|
permission: grimmsserver.logLeaderboard
|
||||||
|
sendMoney:
|
||||||
|
description: Sends money to another player.
|
||||||
|
usage: /sendMoney <player> <amount>
|
||||||
|
permission: grimmsserver.sendMoney
|
||||||
Binary file not shown.
|
|
@ -5,12 +5,13 @@ import org.gsdistance.grimmsServer.GrimmsServer;
|
||||||
public class CommandRegistry {
|
public class CommandRegistry {
|
||||||
public static void registerCommands() {
|
public static void registerCommands() {
|
||||||
// Register all commands here
|
// Register all commands here
|
||||||
GrimmsServer.instance.getCommand("logselfstats").setExecutor(new LogSelfStatsCommand());
|
GrimmsServer.instance.getCommand("logselfstats").setExecutor(new LogSelfStats());
|
||||||
GrimmsServer.instance.getCommand("logworldstats").setExecutor(new LogWorldStats());
|
GrimmsServer.instance.getCommand("logworldstats").setExecutor(new LogWorldStats());
|
||||||
GrimmsServer.instance.getCommand("sellItem").setExecutor(new SellItem());
|
GrimmsServer.instance.getCommand("sellItem").setExecutor(new SellItem());
|
||||||
GrimmsServer.instance.getCommand("buyItem").setExecutor(new BuyItem());
|
GrimmsServer.instance.getCommand("buyItem").setExecutor(new BuyItem());
|
||||||
GrimmsServer.instance.getCommand("getMarketStock").setExecutor(new GetStockOfItem());
|
GrimmsServer.instance.getCommand("getMarketStock").setExecutor(new GetStockOfItem());
|
||||||
GrimmsServer.instance.getCommand("getMarket").setExecutor(new LogEntireMarket());
|
GrimmsServer.instance.getCommand("getMarket").setExecutor(new LogEntireMarket());
|
||||||
GrimmsServer.instance.getCommand("logLeaderboard").setExecutor(new LogLeaderBoard());
|
GrimmsServer.instance.getCommand("logLeaderboard").setExecutor(new LogLeaderBoard());
|
||||||
|
GrimmsServer.instance.getCommand("sendMoney").setExecutor(new SendMoney());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import org.bukkit.Material;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.gsdistance.grimmsServer.Constructable.Market;
|
import org.gsdistance.grimmsServer.Constructable.Market;
|
||||||
|
|
||||||
public class GetStockOfItem implements CommandExecutor {
|
public class GetStockOfItem implements CommandExecutor {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import org.bukkit.Material;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.gsdistance.grimmsServer.Constructable.Market;
|
import org.gsdistance.grimmsServer.Constructable.Market;
|
||||||
|
|
||||||
public class LogEntireMarket implements CommandExecutor {
|
public class LogEntireMarket implements CommandExecutor {
|
||||||
|
|
|
||||||
|
|
@ -7,15 +7,13 @@ import org.bukkit.entity.Player;
|
||||||
import org.gsdistance.grimmsServer.Stats.PlayerStatLeaderBoard;
|
import org.gsdistance.grimmsServer.Stats.PlayerStatLeaderBoard;
|
||||||
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
||||||
|
|
||||||
import java.util.Enumeration;
|
|
||||||
|
|
||||||
public class LogLeaderBoard implements CommandExecutor {
|
public class LogLeaderBoard implements CommandExecutor {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
PlayerStatLeaderBoard leaderBoard = PlayerStatLeaderBoard.getPlayerStatLeaderBoard();
|
PlayerStatLeaderBoard leaderBoard = PlayerStatLeaderBoard.getPlayerStatLeaderBoard();
|
||||||
leaderBoard.checkPlayer((Player) sender);
|
leaderBoard.checkPlayer((Player) sender);
|
||||||
for (String stat : leaderBoard.leaderboard.keySet()) {
|
for (String stat : leaderBoard.leaderboard.keySet()) {
|
||||||
sender.sendMessage("Leader of stat " + PlayerStatLeaderBoard.StatNames.get(stat) + " is " + leaderBoard.leaderboard.get(stat).getPlayerName() + " with " + leaderBoard.leaderboard.get(stat).getStatValue());
|
sender.sendMessage("Leader of stat " + PlayerStats.StatNames.get(stat) + " is " + leaderBoard.leaderboard.get(stat).getPlayerName() + " with " + leaderBoard.leaderboard.get(stat).getStatValue());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,19 +8,17 @@ import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
||||||
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
|
||||||
public class LogSelfStatsCommand implements CommandExecutor {
|
public class LogSelfStats implements CommandExecutor {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if (sender instanceof Player player) {
|
if (sender instanceof Player player) {
|
||||||
PlayerStats stats = PlayerStats.getPlayerStats(player);
|
PlayerStats stats = PlayerStats.getPlayerStats(player);
|
||||||
for (Enumeration<String> keys = PlayerStats.Stats.keys(); keys.hasMoreElements();) {
|
for (String stat : PlayerStats.StatOrder) {
|
||||||
String stat = keys.nextElement();
|
|
||||||
Object value = stats.getStat(stat);
|
Object value = stats.getStat(stat);
|
||||||
if (value instanceof Double) {
|
if (value instanceof Double) {
|
||||||
player.sendMessage(PlayerStats.StatNames.get(stat) + ": " + Math.round((Double) value));
|
player.sendMessage(PlayerStats.StatNames.get(stat) + ": " + Math.round((Double) value));
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(PlayerStats.StatNames.get(stat) + ": " + value.toString());
|
player.sendMessage(PlayerStats.StatNames.get(stat) + ": " + value.toString());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4,7 +4,6 @@ import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
|
||||||
import org.gsdistance.grimmsServer.Stats.WorldStats;
|
import org.gsdistance.grimmsServer.Stats.WorldStats;
|
||||||
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.gsdistance.grimmsServer.Constructable.Market;
|
import org.gsdistance.grimmsServer.Constructable.Market;
|
||||||
import org.gsdistance.grimmsServer.Stats.ServerStats;
|
|
||||||
|
|
||||||
public class SellItem implements CommandExecutor {
|
public class SellItem implements CommandExecutor {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
package org.gsdistance.grimmsServer.Commands;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||||
|
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
||||||
|
|
||||||
|
public class SendMoney implements CommandExecutor {
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
if (args.length < 2) {
|
||||||
|
sender.sendMessage("Usage: /sendmoney <player> <amount>");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (GrimmsServer.instance.getServer().getPlayer(args[0]) == null) {
|
||||||
|
sender.sendMessage("Player not found.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
PlayerStats sending = PlayerStats.getPlayerStats((Player) sender);
|
||||||
|
if((Double) sending.getStat("money") < Double.parseDouble(args[1])) {
|
||||||
|
sender.sendMessage("You do not have enough money.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
PlayerStats receiving = PlayerStats.getPlayerStats(GrimmsServer.instance.getServer().getPlayer(args[0]));
|
||||||
|
sending.changeStat("money", -Integer.parseInt(args[1]));
|
||||||
|
receiving.changeStat("money", Integer.parseInt(args[1]));
|
||||||
|
sender.sendMessage("You have sent " + args[1] + " to " + args[0]);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
sender.sendMessage("This command can only be run by a player.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,7 +4,6 @@ import Data.MarketBaseValues;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemRarity;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
||||||
import org.gsdistance.grimmsServer.Stats.ServerStats;
|
import org.gsdistance.grimmsServer.Stats.ServerStats;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package org.gsdistance.grimmsServer.Events;
|
package org.gsdistance.grimmsServer.Events;
|
||||||
|
|
||||||
|
import org.gsdistance.grimmsServer.Stats.LevelHandler;
|
||||||
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
||||||
import org.gsdistance.grimmsServer.Stats.WorldStats;
|
import org.gsdistance.grimmsServer.Stats.WorldStats;
|
||||||
|
|
||||||
|
|
@ -9,6 +10,7 @@ public class BlockBreakEvent {
|
||||||
PlayerStats.getPlayerStats(event.getPlayer()).changeStat("money", 1);
|
PlayerStats.getPlayerStats(event.getPlayer()).changeStat("money", 1);
|
||||||
PlayerStats.getPlayerStats(event.getPlayer()).changeStat("tPoint", 3);
|
PlayerStats.getPlayerStats(event.getPlayer()).changeStat("tPoint", 3);
|
||||||
PlayerStats.getPlayerStats(event.getPlayer()).changeStat("block_break_count", 1);
|
PlayerStats.getPlayerStats(event.getPlayer()).changeStat("block_break_count", 1);
|
||||||
|
LevelHandler.getLevelHandler(event.getPlayer()).addExp(3);
|
||||||
}
|
}
|
||||||
WorldStats.getWorldStats(event.getBlock().getWorld()).changeStat("block_break_count", 1);
|
WorldStats.getWorldStats(event.getBlock().getWorld()).changeStat("block_break_count", 1);
|
||||||
WorldStats.getWorldStats(event.getBlock().getWorld()).changeStat("wPoint", 3);
|
WorldStats.getWorldStats(event.getBlock().getWorld()).changeStat("wPoint", 3);
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,11 @@
|
||||||
package org.gsdistance.grimmsServer.Events;
|
package org.gsdistance.grimmsServer.Events;
|
||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.entity.Player;
|
||||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
import org.gsdistance.grimmsServer.Stats.LevelHandler;
|
||||||
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
||||||
import org.gsdistance.grimmsServer.Stats.ServerStats;
|
import org.gsdistance.grimmsServer.Stats.ServerStats;
|
||||||
import org.gsdistance.grimmsServer.Stats.WorldStats;
|
import org.gsdistance.grimmsServer.Stats.WorldStats;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
public class EntityDeathEvent {
|
public class EntityDeathEvent {
|
||||||
public static void Event(org.bukkit.event.entity.EntityDeathEvent event) {
|
public static void Event(org.bukkit.event.entity.EntityDeathEvent event) {
|
||||||
if (event.getEntity().getKiller() != null) {
|
if (event.getEntity().getKiller() != null) {
|
||||||
|
|
@ -20,11 +17,13 @@ public class EntityDeathEvent {
|
||||||
playerStats.changeStat("money", 3);
|
playerStats.changeStat("money", 3);
|
||||||
playerStats.changeStat("tPoint", 25);
|
playerStats.changeStat("tPoint", 25);
|
||||||
worldStats.changeStat("wPoint", 40);
|
worldStats.changeStat("wPoint", 40);
|
||||||
|
LevelHandler.getLevelHandler(event.getEntity().getKiller()).addExp(50);
|
||||||
|
|
||||||
if (event.getEntity().getType() == org.bukkit.entity.EntityType.PLAYER) {
|
if (event.getEntity().getType() == org.bukkit.entity.EntityType.PLAYER) {
|
||||||
playerStats.changeStat("money", 12);
|
playerStats.changeStat("money", 12);
|
||||||
playerStats.changeStat("tPoint", 50);
|
playerStats.changeStat("tPoint", 50);
|
||||||
worldStats.changeStat("wPoint", 110);
|
worldStats.changeStat("wPoint", 110);
|
||||||
|
LevelHandler.getLevelHandler(event.getEntity().getKiller()).addExp(150);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package org.gsdistance.grimmsServer.Events;
|
package org.gsdistance.grimmsServer.Events;
|
||||||
|
|
||||||
import org.bukkit.ServerTickManager;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
|
@ -12,10 +11,12 @@ public class EventTrigger implements Listener {
|
||||||
public void onEntityDeath(EntityDeathEvent event) {
|
public void onEntityDeath(EntityDeathEvent event) {
|
||||||
org.gsdistance.grimmsServer.Events.EntityDeathEvent.Event(event);
|
org.gsdistance.grimmsServer.Events.EntityDeathEvent.Event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
org.gsdistance.grimmsServer.Events.BlockBreakEvent.Event(event);
|
org.gsdistance.grimmsServer.Events.BlockBreakEvent.Event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
org.gsdistance.grimmsServer.Events.PlayerJoinEvent.Event(event);
|
org.gsdistance.grimmsServer.Events.PlayerJoinEvent.Event(event);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package org.gsdistance.grimmsServer.Events;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.gsdistance.grimmsServer.Commands.CommandRegistry;
|
import org.gsdistance.grimmsServer.Commands.CommandRegistry;
|
||||||
import org.gsdistance.grimmsServer.Commands.LogSelfStatsCommand;
|
|
||||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||||
import org.gsdistance.grimmsServer.Stats.PlayerStatLeaderBoard;
|
import org.gsdistance.grimmsServer.Stats.PlayerStatLeaderBoard;
|
||||||
|
|
||||||
|
|
@ -10,6 +9,7 @@ import java.util.logging.Level;
|
||||||
|
|
||||||
public class ServerStartupEvent {
|
public class ServerStartupEvent {
|
||||||
public static int ticks = 0;
|
public static int ticks = 0;
|
||||||
|
|
||||||
public static void Event() {
|
public static void Event() {
|
||||||
CommandRegistry.registerCommands();
|
CommandRegistry.registerCommands();
|
||||||
GrimmsServer.instance.getServer().getScheduler().scheduleSyncRepeatingTask(GrimmsServer.instance, () -> {
|
GrimmsServer.instance.getServer().getScheduler().scheduleSyncRepeatingTask(GrimmsServer.instance, () -> {
|
||||||
|
|
|
||||||
|
|
@ -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,17 +14,11 @@ public class PlayerStatLeaderBoard {
|
||||||
"join_count", Integer.class,
|
"join_count", Integer.class,
|
||||||
"tPoint", Double.class,
|
"tPoint", Double.class,
|
||||||
"block_break_count", Long.class,
|
"block_break_count", Long.class,
|
||||||
"money", Double.class
|
"money", Double.class,
|
||||||
);
|
"level", Integer.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"
|
|
||||||
);
|
);
|
||||||
public Map<String, LeaderboardEntry> leaderboard;
|
public Map<String, LeaderboardEntry> leaderboard;
|
||||||
|
|
||||||
public PlayerStatLeaderBoard() {
|
public PlayerStatLeaderBoard() {
|
||||||
this.leaderboard = Map.of(
|
this.leaderboard = Map.of(
|
||||||
"total_kill_count", new LeaderboardEntry("None", 0),
|
"total_kill_count", new LeaderboardEntry("None", 0),
|
||||||
|
|
@ -32,15 +26,19 @@ public class PlayerStatLeaderBoard {
|
||||||
"join_count", new LeaderboardEntry("None", 0),
|
"join_count", new LeaderboardEntry("None", 0),
|
||||||
"tPoint", new LeaderboardEntry("None", 0),
|
"tPoint", new LeaderboardEntry("None", 0),
|
||||||
"block_break_count", 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() {
|
public static PlayerStatLeaderBoard getPlayerStatLeaderBoard() {
|
||||||
return new Gson().fromJson((String) ServerStats.getServerStats().getStat("leaderboard"), PlayerStatLeaderBoard.class);
|
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));
|
ServerStats.getServerStats().setStat("leaderboard", new Gson().toJson(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkPlayer(Player player) {
|
public boolean checkPlayer(Player player) {
|
||||||
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
|
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
|
||||||
boolean pass = false;
|
boolean pass = false;
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,11 @@ import org.gsdistance.grimmsServer.GrimmsServer;
|
||||||
|
|
||||||
import java.util.Dictionary;
|
import java.util.Dictionary;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class PlayerStats {
|
public class PlayerStats {
|
||||||
public static final Dictionary<String, PersistentDataType<?, ?>> Stats = new Hashtable<>();
|
public static final Dictionary<String, PersistentDataType<?, ?>> Stats = new Hashtable<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Stats.put("death_count", PersistentDataType.INTEGER);
|
Stats.put("death_count", PersistentDataType.INTEGER);
|
||||||
Stats.put("money", PersistentDataType.DOUBLE);
|
Stats.put("money", PersistentDataType.DOUBLE);
|
||||||
|
|
@ -19,8 +21,13 @@ public class PlayerStats {
|
||||||
Stats.put("join_count", PersistentDataType.INTEGER);
|
Stats.put("join_count", PersistentDataType.INTEGER);
|
||||||
Stats.put("tPoint", PersistentDataType.DOUBLE);
|
Stats.put("tPoint", PersistentDataType.DOUBLE);
|
||||||
Stats.put("block_break_count", PersistentDataType.LONG);
|
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 {
|
static {
|
||||||
StatNames.put("death_count", "Death Count");
|
StatNames.put("death_count", "Death Count");
|
||||||
StatNames.put("money", "Money");
|
StatNames.put("money", "Money");
|
||||||
|
|
@ -28,7 +35,21 @@ public class PlayerStats {
|
||||||
StatNames.put("join_count", "Join Count");
|
StatNames.put("join_count", "Join Count");
|
||||||
StatNames.put("tPoint", "Total Points");
|
StatNames.put("tPoint", "Total Points");
|
||||||
StatNames.put("block_break_count", "Block Break Count");
|
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 JavaPlugin plugin;
|
||||||
private final PersistentDataContainer dataContainer;
|
private final PersistentDataContainer dataContainer;
|
||||||
|
|
@ -78,6 +99,12 @@ public class PlayerStats {
|
||||||
currentStat = 0.0;
|
currentStat = 0.0;
|
||||||
}
|
}
|
||||||
dataContainer.set(new NamespacedKey(plugin, stat), PersistentDataType.DOUBLE, currentStat + amount);
|
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 class ServerStats {
|
||||||
public static final Dictionary<String, Type> Stats = new Hashtable<>();
|
public static final Dictionary<String, Type> Stats = new Hashtable<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Stats.put("death_count", Integer.class);
|
Stats.put("death_count", Integer.class);
|
||||||
Stats.put("join_count", Integer.class);
|
Stats.put("join_count", Integer.class);
|
||||||
Stats.put("market", String.class);
|
Stats.put("market", String.class);
|
||||||
Stats.put("leaderboard", 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 {
|
static {
|
||||||
StatNames.put("death_count", "Death Count");
|
StatNames.put("death_count", "Death Count");
|
||||||
StatNames.put("join_count", "Join Count");
|
StatNames.put("join_count", "Join Count");
|
||||||
|
|
@ -42,6 +45,7 @@ public class ServerStats {
|
||||||
this.statsFile = new File(plugin.getDataFolder(), "server_stats.json");
|
this.statsFile = new File(plugin.getDataFolder(), "server_stats.json");
|
||||||
loadStats();
|
loadStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ServerStats getServerStats() {
|
public static ServerStats getServerStats() {
|
||||||
return new ServerStats(GrimmsServer.instance);
|
return new ServerStats(GrimmsServer.instance);
|
||||||
}
|
}
|
||||||
|
|
@ -55,7 +59,8 @@ public class ServerStats {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try (FileReader reader = new FileReader(statsFile)) {
|
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);
|
stats = new Gson().fromJson(reader, type);
|
||||||
if (!stats.containsKey("market")) {
|
if (!stats.containsKey("market")) {
|
||||||
stats.put("market", new Gson().toJson(new Market())); // Initialize market stat
|
stats.put("market", new Gson().toJson(new Market())); // Initialize market stat
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,16 @@ import java.util.Hashtable;
|
||||||
|
|
||||||
public class WorldStats {
|
public class WorldStats {
|
||||||
public static final Dictionary<String, PersistentDataType<?, ?>> Stats = new Hashtable<>();
|
public static final Dictionary<String, PersistentDataType<?, ?>> Stats = new Hashtable<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Stats.put("death_count", PersistentDataType.INTEGER);
|
Stats.put("death_count", PersistentDataType.INTEGER);
|
||||||
Stats.put("block_break_count", PersistentDataType.LONG);
|
Stats.put("block_break_count", PersistentDataType.LONG);
|
||||||
Stats.put("wPoint", PersistentDataType.DOUBLE);
|
Stats.put("wPoint", PersistentDataType.DOUBLE);
|
||||||
Stats.put("join_count", PersistentDataType.INTEGER);
|
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 {
|
static {
|
||||||
StatNames.put("death_count", "Death Count");
|
StatNames.put("death_count", "Death Count");
|
||||||
StatNames.put("block_break_count", "Block Break Count");
|
StatNames.put("block_break_count", "Block Break Count");
|
||||||
|
|
|
||||||
|
|
@ -29,5 +29,9 @@ commands:
|
||||||
permission: grimmsserver.getMarket
|
permission: grimmsserver.getMarket
|
||||||
logLeaderboard:
|
logLeaderboard:
|
||||||
description: Displays the leaderboard of players with the most kills.
|
description: Displays the leaderboard of players with the most kills.
|
||||||
usage: /Leaderboard
|
usage: /logLeaderboard
|
||||||
permission: grimmsserver.logLeaderboard
|
permission: grimmsserver.logLeaderboard
|
||||||
|
sendMoney:
|
||||||
|
description: Sends money to another player.
|
||||||
|
usage: /sendMoney <player> <amount>
|
||||||
|
permission: grimmsserver.sendMoney
|
||||||
Loading…
Add table
Add a link
Reference in a new issue