Update
This commit is contained in:
parent
e8a4c9f75b
commit
ddbb6d8211
39 changed files with 374 additions and 53 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.
2
.idea/gradle.xml
generated
2
.idea/gradle.xml
generated
|
|
@ -5,11 +5,13 @@
|
|||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="21" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveExternalAnnotations" value="true" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
|
|
|
|||
30
.idea/jarRepositories.xml
generated
Normal file
30
.idea/jarRepositories.xml
generated
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="MavenRepo" />
|
||||
<option name="name" value="MavenRepo" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="spigotmc-repo" />
|
||||
<option name="name" value="spigotmc-repo" />
|
||||
<option name="url" value="https://hub.spigotmc.org/nexus/content/repositories/snapshots/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="sonatype" />
|
||||
<option name="name" value="sonatype" />
|
||||
<option name="url" value="https://oss.sonatype.org/content/groups/public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
1
.idea/modules.xml
generated
1
.idea/modules.xml
generated
|
|
@ -3,6 +3,7 @@
|
|||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/GrimmsServer.main.iml" filepath="$PROJECT_DIR$/.idea/modules/GrimmsServer.main.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/org.gsdistance.GrimmsServer.main.iml" filepath="$PROJECT_DIR$/.idea/modules/org.gsdistance.GrimmsServer.main.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
4
.idea/modules/GrimmsServer.main.iml
generated
4
.idea/modules/GrimmsServer.main.iml
generated
|
|
@ -10,4 +10,8 @@
|
|||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
13
.idea/modules/org.gsdistance.GrimmsServer.main.iml
generated
Normal file
13
.idea/modules/org.gsdistance.GrimmsServer.main.iml
generated
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>SPIGOT</platformType>
|
||||
</autoDetectTypes>
|
||||
<projectReimportVersion>1</projectReimportVersion>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
</module>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -11,10 +11,6 @@ commands:
|
|||
description: Displays the world stats including total deaths, total kills, and total money.
|
||||
usage: /logworldstats
|
||||
permission: grimmsserver.logworldstats
|
||||
getMarketValue:
|
||||
description: Displays the market value of a specified item.
|
||||
usage: /getMarketValue <item>
|
||||
permission: grimmsserver.getMarketValue
|
||||
sellItem:
|
||||
description: Sells the main hand for a certain amount of money.
|
||||
usage: /sellItem
|
||||
|
|
@ -23,3 +19,15 @@ commands:
|
|||
description: Buys an item for a certain amount of money.
|
||||
usage: /buyItem <item> <amount>
|
||||
permission: grimmsserver.buyItem
|
||||
getMarketStock:
|
||||
description: Displays the market stock of a specified item.
|
||||
usage: /getMarketStock <item>
|
||||
permission: grimmsserver.getMarketStock
|
||||
getMarket:
|
||||
description: Dumps the whole market information.
|
||||
usage: /getMarket
|
||||
permission: grimmsserver.getMarket
|
||||
logLeaderboard:
|
||||
description: Displays the leaderboard of players with the most kills.
|
||||
usage: /Leaderboard
|
||||
permission: grimmsserver.logLeaderboard
|
||||
Binary file not shown.
18
src/main/java/Data/MarketBaseValues.java
Normal file
18
src/main/java/Data/MarketBaseValues.java
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package Data;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class MarketBaseValues {
|
||||
public static final Map<Material, Double> marketBaseValues = Map.of(
|
||||
Material.DIAMOND, 100.0,
|
||||
Material.GOLD_INGOT, 50.0,
|
||||
Material.IRON_INGOT, 25.0,
|
||||
Material.COAL, 10.0,
|
||||
Material.EMERALD, 200.0,
|
||||
Material.REDSTONE, 5.0,
|
||||
Material.LAPIS_LAZULI, 15.0,
|
||||
Material.NETHERITE_INGOT, 500.0
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package org.gsdistance.grimmsServer.Commands;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Constructable.Market;
|
||||
|
||||
public class BuyItem 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: /buy <item> <amount>");
|
||||
return false;
|
||||
}
|
||||
if(Material.matchMaterial(args[0].toLowerCase()) == null){
|
||||
sender.sendMessage("Invalid item id:" + args[0]);
|
||||
return false;
|
||||
}
|
||||
Market market = Market.getMarket();
|
||||
if(market.items.get(args[0]) >= Integer.parseInt(args[1])){
|
||||
sender.sendMessage("Not enough stock of " + args[0] + " in the market.");
|
||||
return false;
|
||||
}
|
||||
double bought = market.buy(Material.matchMaterial(args[0].toLowerCase()), Integer.parseInt(args[1]), (Player) sender);
|
||||
market.saveMarket();
|
||||
sender.sendMessage("You bought " + args[1] + " many of " + args[0] + " for " + Math.max(0.25D,Math.round((bought))));
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage("This command can only be run by a player.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,10 @@ public class CommandRegistry {
|
|||
// Register all commands here
|
||||
GrimmsServer.instance.getCommand("logselfstats").setExecutor(new LogSelfStatsCommand());
|
||||
GrimmsServer.instance.getCommand("logworldstats").setExecutor(new LogWorldStats());
|
||||
GrimmsServer.instance.getCommand("getMarketValue").setExecutor(new GetItemStockValue());
|
||||
GrimmsServer.instance.getCommand("sellItem").setExecutor(new SellItem());
|
||||
GrimmsServer.instance.getCommand("buyItem").setExecutor(new BuyItem());
|
||||
GrimmsServer.instance.getCommand("getMarketStock").setExecutor(new GetStockOfItem());
|
||||
GrimmsServer.instance.getCommand("getMarket").setExecutor(new LogEntireMarket());
|
||||
GrimmsServer.instance.getCommand("logLeaderboard").setExecutor(new LogLeaderBoard());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
package org.gsdistance.grimmsServer.Commands;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class GetItemStockValue implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args){
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package org.gsdistance.grimmsServer.Commands;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Constructable.Market;
|
||||
|
||||
public class GetStockOfItem implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args){
|
||||
if(args.length == 0) {
|
||||
sender.sendMessage("Please specify an item.");
|
||||
return false;
|
||||
}
|
||||
if(Material.matchMaterial(args[0]) == null) {
|
||||
sender.sendMessage("Invalid item id:" + args[0]);
|
||||
return false;
|
||||
}
|
||||
Market market = Market.getMarket();
|
||||
sender.sendMessage(args[0] + ": " + market.items.get(Material.matchMaterial(args[0]).getKey().toString()) + " with the price of " + Math.max(0.25D,Math.round((market.getPrice(Material.matchMaterial(args[0]))))));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package org.gsdistance.grimmsServer.Commands;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Constructable.Market;
|
||||
|
||||
public class LogEntireMarket implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
Market market = Market.getMarket();
|
||||
for (String item : market.items.keySet()) {
|
||||
Material material = Material.matchMaterial(item);
|
||||
if (material != null) {
|
||||
sender.sendMessage(item + ": " + market.items.get(item) + " - " + Math.max(0.25D,Math.round(market.getPrice(material))));
|
||||
} else {
|
||||
sender.sendMessage(item + ": " + market.items.get(item) + " - Error:" + item);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
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.Stats.PlayerStatLeaderBoard;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
||||
|
||||
import java.util.Enumeration;
|
||||
|
||||
public class LogLeaderBoard implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
PlayerStatLeaderBoard leaderBoard = PlayerStatLeaderBoard.getPlayerStatLeaderBoard();
|
||||
leaderBoard.checkPlayer((Player) sender);
|
||||
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());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,12 @@ public class LogSelfStatsCommand implements CommandExecutor {
|
|||
for (Enumeration<String> keys = PlayerStats.Stats.keys(); keys.hasMoreElements();) {
|
||||
String stat = keys.nextElement();
|
||||
Object value = stats.getStat(stat);
|
||||
sender.sendMessage(PlayerStats.StatNames.get(stat) + ": " + value.toString());
|
||||
if(value instanceof Double) {
|
||||
player.sendMessage(PlayerStats.StatNames.get(stat) + ": " + Math.round((Double) value));
|
||||
} else {
|
||||
player.sendMessage(PlayerStats.StatNames.get(stat) + ": " + value.toString());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import org.bukkit.command.Command;
|
|||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.gsdistance.grimmsServer.Constructable.Market;
|
||||
import org.gsdistance.grimmsServer.Stats.ServerStats;
|
||||
|
||||
|
|
@ -11,9 +12,11 @@ public class SellItem implements CommandExecutor {
|
|||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args){
|
||||
if (sender instanceof Player) {
|
||||
Market market = (Market) ServerStats.getServerStats().getStat("market");
|
||||
market.sell(((Player) sender).getInventory().getItemInMainHand(), (Player) sender);
|
||||
ServerStats.getServerStats().setStat("market", market);
|
||||
Market market = Market.getMarket();
|
||||
ItemStack iS = ((Player) sender).getInventory().getItemInMainHand();
|
||||
double sold = market.sell(iS, (Player) sender);
|
||||
market.saveMarket();
|
||||
sender.sendMessage("You sold " + iS.getAmount() + " many of " + iS.getType().getKey() + " for " + Math.max(0.25D,Math.round((sold))));
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage("This command can only be run by a player.");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
package org.gsdistance.grimmsServer.Constructable;
|
||||
|
||||
public class LeaderboardEntry {
|
||||
private String playerName;
|
||||
private Number statValue;
|
||||
|
||||
public LeaderboardEntry(String playerName, Number statValue) {
|
||||
this.playerName = playerName;
|
||||
this.statValue = statValue;
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
public void setPlayerName(String playerName) {
|
||||
this.playerName = playerName;
|
||||
}
|
||||
|
||||
public Number getStatValue() {
|
||||
return statValue;
|
||||
}
|
||||
|
||||
public void setStatValue(Number statValue) {
|
||||
this.statValue = statValue;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,57 +1,81 @@
|
|||
package org.gsdistance.grimmsServer.Constructable;
|
||||
|
||||
import Data.MarketBaseValues;
|
||||
import com.google.gson.Gson;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemRarity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
||||
import org.gsdistance.grimmsServer.Stats.ServerStats;
|
||||
|
||||
import java.util.Dictionary;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Market {
|
||||
public Dictionary<String, Long> items;
|
||||
public Map<String, Long> items;
|
||||
|
||||
public Market() {
|
||||
items = new java.util.Hashtable<>();
|
||||
items = new HashMap<>();
|
||||
}
|
||||
public boolean sell(ItemStack itemStack, Player player) {
|
||||
|
||||
public static Market getMarket() {
|
||||
return new Gson().fromJson((String) ServerStats.getServerStats().getStat("market"), Market.class);
|
||||
}
|
||||
|
||||
public void saveMarket() {
|
||||
ServerStats.getServerStats().setStat("market", new Gson().toJson(this));
|
||||
}
|
||||
|
||||
public double sell(ItemStack itemStack, Player player) {
|
||||
if (player.getInventory().contains(itemStack)) {
|
||||
items.put(itemStack.getType().getKey().toString(), 0L);
|
||||
double sold = 0;
|
||||
items.putIfAbsent(itemStack.getType().getKey().toString(), 0L);
|
||||
for (int i = 0; i < itemStack.getAmount(); i++) {
|
||||
PlayerStats.getPlayerStats(player).setStat("money", (double)PlayerStats.getPlayerStats(player).getStat("money") + getPrice(itemStack.getType()));
|
||||
Object moneyObj = PlayerStats.getPlayerStats(player).getStat("money");
|
||||
double money = moneyObj instanceof Integer ? ((Integer) moneyObj).doubleValue() : (double) moneyObj;
|
||||
sold+= getPrice(itemStack.getType());
|
||||
PlayerStats.getPlayerStats(player).setStat("money", money + getPrice(itemStack.getType()));
|
||||
items.put(itemStack.getType().getKey().toString(), items.get(itemStack.getType().getKey().toString()) + 1);
|
||||
}
|
||||
player.getInventory().removeItem(itemStack);
|
||||
return true;
|
||||
return sold;
|
||||
}
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
public boolean buy(Material item, int amount, Player player) {
|
||||
|
||||
public double buy(Material item, int amount, Player player) {
|
||||
if (items.get(item.getKey().toString()) == null) {
|
||||
return false;
|
||||
return 0;
|
||||
} else if (amount > items.get(item.getKey().toString())) {
|
||||
return 0;
|
||||
} else {
|
||||
double boughtP = 0;
|
||||
int bought = 0;
|
||||
for (int i = 0; i < amount; i++) {
|
||||
if((double)PlayerStats.getPlayerStats(player).getStat("money") >= getPrice(item)) {
|
||||
PlayerStats.getPlayerStats(player).setStat("money", (double)PlayerStats.getPlayerStats(player).getStat("money") - getPrice(item));
|
||||
Object moneyObj = PlayerStats.getPlayerStats(player).getStat("money");
|
||||
double money = moneyObj instanceof Integer ? ((Integer) moneyObj).doubleValue() : (double) moneyObj;
|
||||
if (money >= getPrice(item)) {
|
||||
PlayerStats.getPlayerStats(player).setStat("money", money - getPrice(item));
|
||||
boughtP += getPrice(item);
|
||||
items.put(item.getKey().toString(), items.get(item.getKey().toString()) - 1);
|
||||
bought++;
|
||||
}
|
||||
player.getInventory().addItem(new ItemStack(item, bought));
|
||||
}
|
||||
return true;
|
||||
return boughtP;
|
||||
}
|
||||
}
|
||||
|
||||
public double getPrice(Material item) {
|
||||
if (items.get(item.getKey().toString()) == null) {
|
||||
return 0;
|
||||
} else {
|
||||
long amount = items.get(item.getKey().toString());
|
||||
return switch (ItemRarity.valueOf(item.getKey().toString())) {
|
||||
case COMMON -> Math.max(1, 25 - Math.sqrt(amount));
|
||||
case UNCOMMON -> Math.max(1, 200 - Math.sqrt(amount));
|
||||
case RARE -> Math.max(1, 600 - Math.sqrt(amount));
|
||||
case EPIC -> Math.max(1, 1200 - Math.sqrt(amount));
|
||||
};
|
||||
if(MarketBaseValues.marketBaseValues.containsKey(item)){
|
||||
return Math.max(Math.max(0.25D,Math.floor(MarketBaseValues.marketBaseValues.get(item)/100)), MarketBaseValues.marketBaseValues.get(item) - Math.sqrt(amount));
|
||||
}
|
||||
return Math.max(0.25D, 25 - Math.sqrt(amount));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ public class BlockBreakEvent {
|
|||
if (event.getPlayer().getType() == org.bukkit.entity.EntityType.PLAYER) {
|
||||
PlayerStats.getPlayerStats(event.getPlayer()).changeStat("money", 1);
|
||||
PlayerStats.getPlayerStats(event.getPlayer()).changeStat("tPoint", 3);
|
||||
PlayerStats.getPlayerStats(event.getPlayer()).changeStat("block_break_count", 1);
|
||||
}
|
||||
WorldStats.getWorldStats(event.getBlock().getWorld()).changeStat("block_break_count", 1);
|
||||
WorldStats.getWorldStats(event.getBlock().getWorld()).changeStat("wPoint", 3);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.gsdistance.grimmsServer.Events;
|
||||
|
||||
import org.bukkit.ServerTickManager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
|
|
|
|||
|
|
@ -1,15 +1,26 @@
|
|||
package org.gsdistance.grimmsServer.Events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Commands.CommandRegistry;
|
||||
import org.gsdistance.grimmsServer.Commands.LogSelfStatsCommand;
|
||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerStatLeaderBoard;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ServerStartupEvent {
|
||||
|
||||
public static int ticks = 0;
|
||||
public static void Event() {
|
||||
CommandRegistry.registerCommands();
|
||||
GrimmsServer.instance.getServer().getScheduler().scheduleSyncRepeatingTask(GrimmsServer.instance, () -> {
|
||||
// none
|
||||
ticks++;
|
||||
if (ticks % 1000 == 0) {
|
||||
for (Player player : GrimmsServer.instance.getServer().getOnlinePlayers()) {
|
||||
PlayerStatLeaderBoard.getPlayerStatLeaderBoard().checkPlayer(player);
|
||||
}
|
||||
}
|
||||
}, 100L, 1L);
|
||||
GrimmsServer.logger.log(Level.INFO, "GrimmsServer has started successfully.");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
package org.gsdistance.grimmsServer.Stats;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Constructable.LeaderboardEntry;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
public class PlayerStatLeaderBoard {
|
||||
public static final Map<String, Type> Stats = Map.of(
|
||||
"total_kill_count", Integer.class,
|
||||
"death_count", Integer.class,
|
||||
"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"
|
||||
);
|
||||
public Map<String, LeaderboardEntry> leaderboard;
|
||||
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)
|
||||
);
|
||||
}
|
||||
public static PlayerStatLeaderBoard getPlayerStatLeaderBoard () {
|
||||
return new Gson().fromJson((String) ServerStats.getServerStats().getStat("leaderboard"),PlayerStatLeaderBoard.class);
|
||||
}
|
||||
public void savePlayerStatLeaderBoard () {
|
||||
ServerStats.getServerStats().setStat("leaderboard", new Gson().toJson(this));
|
||||
}
|
||||
public boolean checkPlayer(Player player) {
|
||||
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
|
||||
boolean pass = false;
|
||||
for (String stat : leaderboard.keySet()) {
|
||||
Number playerStatValue = (Number) playerStats.getStat(stat);
|
||||
Number leaderboardStatValue = leaderboard.get(stat).getStatValue();
|
||||
|
||||
if (playerStatValue != null && playerStatValue.doubleValue() > leaderboardStatValue.doubleValue()) {
|
||||
leaderboard.put(stat, new LeaderboardEntry(player.getName(), playerStatValue.intValue()));
|
||||
savePlayerStatLeaderBoard();
|
||||
pass = true;
|
||||
}
|
||||
}
|
||||
return pass;
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,7 @@ public class PlayerStats {
|
|||
Stats.put("total_kill_count", PersistentDataType.INTEGER);
|
||||
Stats.put("join_count", PersistentDataType.INTEGER);
|
||||
Stats.put("tPoint", PersistentDataType.DOUBLE);
|
||||
Stats.put("block_break_count", PersistentDataType.LONG);
|
||||
}
|
||||
public static final Dictionary<String,String> StatNames = new Hashtable<>();
|
||||
static {
|
||||
|
|
@ -26,6 +27,7 @@ public class PlayerStats {
|
|||
StatNames.put("total_kill_count", "Total Kill Count");
|
||||
StatNames.put("join_count", "Join Count");
|
||||
StatNames.put("tPoint", "Total Points");
|
||||
StatNames.put("block_break_count", "Block Break Count");
|
||||
}
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
|
|
|
|||
|
|
@ -22,13 +22,15 @@ public class ServerStats {
|
|||
static {
|
||||
Stats.put("death_count", Integer.class);
|
||||
Stats.put("join_count", Integer.class);
|
||||
Stats.put("market", Market.class);
|
||||
Stats.put("market", String.class);
|
||||
Stats.put("leaderboard", String.class);
|
||||
}
|
||||
public static final Dictionary<String,String> StatNames = new Hashtable<>();
|
||||
static {
|
||||
StatNames.put("death_count", "Death Count");
|
||||
StatNames.put("join_count", "Join Count");
|
||||
StatNames.put("market", "Market");
|
||||
StatNames.put("leaderboard", "Leaderboard");
|
||||
}
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
|
|
@ -47,7 +49,8 @@ public class ServerStats {
|
|||
private void loadStats() {
|
||||
if (!statsFile.exists()) {
|
||||
stats = new Hashtable<>();
|
||||
stats.put("market", new Market()); // Initialize market stat
|
||||
stats.put("market", new Gson().toJson(new Market())); // Initialize market stat
|
||||
stats.put("leaderboard", new Gson().toJson(new PlayerStatLeaderBoard())); // Initialize leaderboard stat
|
||||
saveStats();
|
||||
return;
|
||||
}
|
||||
|
|
@ -55,12 +58,16 @@ public class ServerStats {
|
|||
Type type = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
stats = new Gson().fromJson(reader, type);
|
||||
if (!stats.containsKey("market")) {
|
||||
stats.put("market", new Market()); // Ensure market stat is initialized
|
||||
stats.put("market", new Gson().toJson(new Market())); // Initialize market stat
|
||||
}
|
||||
if (!stats.containsKey("leaderboard")) {
|
||||
stats.put("leaderboard", new Gson().toJson(new PlayerStatLeaderBoard())); // Initialize leaderboard stat
|
||||
}
|
||||
} catch (IOException e) {
|
||||
GrimmsServer.logger.log(Level.WARNING, "Failed to load server stats.\n" + Arrays.toString(e.getStackTrace()));
|
||||
stats = new Hashtable<>();
|
||||
stats.put("market", new Market()); // Initialize market stat
|
||||
stats.put("market", new Gson().toJson(new Market())); // Initialize market stat
|
||||
stats.put("leaderboard", new Gson().toJson(new PlayerStatLeaderBoard())); // Initialize leaderboard stat
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,10 +11,6 @@ commands:
|
|||
description: Displays the world stats including total deaths, total kills, and total money.
|
||||
usage: /logworldstats
|
||||
permission: grimmsserver.logworldstats
|
||||
getMarketValue:
|
||||
description: Displays the market value of a specified item.
|
||||
usage: /getMarketValue <item>
|
||||
permission: grimmsserver.getMarketValue
|
||||
sellItem:
|
||||
description: Sells the main hand for a certain amount of money.
|
||||
usage: /sellItem
|
||||
|
|
@ -23,3 +19,15 @@ commands:
|
|||
description: Buys an item for a certain amount of money.
|
||||
usage: /buyItem <item> <amount>
|
||||
permission: grimmsserver.buyItem
|
||||
getMarketStock:
|
||||
description: Displays the market stock of a specified item.
|
||||
usage: /getMarketStock <item>
|
||||
permission: grimmsserver.getMarketStock
|
||||
getMarket:
|
||||
description: Dumps the whole market information.
|
||||
usage: /getMarket
|
||||
permission: grimmsserver.getMarket
|
||||
logLeaderboard:
|
||||
description: Displays the leaderboard of players with the most kills.
|
||||
usage: /Leaderboard
|
||||
permission: grimmsserver.logLeaderboard
|
||||
Loading…
Add table
Add a link
Reference in a new issue