1.3r1
This commit is contained in:
parent
10c011ede1
commit
c45cec156d
31 changed files with 422 additions and 41 deletions
|
|
@ -0,0 +1,19 @@
|
|||
package org.gsdistance.grimmsServer.Commands.GHelpCommand;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.gsdistance.grimmsServer.Data.HelpStrings;
|
||||
|
||||
public class GHelp implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(args.length < 1){
|
||||
return false;
|
||||
}
|
||||
sender.sendMessage("Help string for command " + args[0] + ":");
|
||||
sender.sendMessage(HelpStrings.getHelpString(args[0]));
|
||||
sender.sendMessage(HelpStrings.getHelpUsage(args[0]));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package org.gsdistance.grimmsServer.Commands.GHelpCommand;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.command.defaults.BukkitCommand;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GHelpTabCompleter implements TabCompleter {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length == 1) {
|
||||
String partial = args[0].toLowerCase();
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
|
||||
// Dynamically fetch all commands from the plugin
|
||||
for (String cmdName : GrimmsServer.instance.getDescription().getCommands().keySet()) {
|
||||
if (cmdName.toLowerCase().startsWith(partial)) {
|
||||
suggestions.add(cmdName);
|
||||
}
|
||||
}
|
||||
|
||||
return suggestions;
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
package org.gsdistance.grimmsServer.Commands.MarketComand;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.gsdistance.grimmsServer.Data.Market.PotionEffectBaseValues;
|
||||
import org.gsdistance.grimmsServer.Shared;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
||||
|
||||
public class BuyPotionEffect {
|
||||
public static boolean SubCommand(CommandSender sender, String[] args) {
|
||||
if (sender instanceof Player player) {
|
||||
if (args.length < 4) {
|
||||
sender.sendMessage("Usage: /market buyPotionEffect <effect> <duration> <level>");
|
||||
return false;
|
||||
}
|
||||
|
||||
PotionEffectType effectType = PotionEffectType.getByName(args[1].toUpperCase());
|
||||
if (effectType == null || !PotionEffectBaseValues.potionEffectBaseValues.containsKey(effectType)) {
|
||||
sender.sendMessage("Potion effect not listed or nonexistent.");
|
||||
return false;
|
||||
}
|
||||
|
||||
int duration;
|
||||
int amplifier;
|
||||
|
||||
try {
|
||||
duration = Integer.parseInt(args[2]);
|
||||
if (duration <= 0) {
|
||||
sender.sendMessage("Duration must be a positive number.");
|
||||
return false;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage("Invalid duration. Must be a positive number.");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
amplifier = Integer.parseInt(args[3]);
|
||||
if (amplifier < 1) {
|
||||
sender.sendMessage("Level must be at least 1.");
|
||||
return false;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage("Invalid level. Must be a positive number.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the effect has an amplitude limit and if the requested level exceeds it
|
||||
if (PotionEffectBaseValues.potionEffectAmplitudeLimits.containsKey(effectType)) {
|
||||
int maxAmplifier = PotionEffectBaseValues.potionEffectAmplitudeLimits.get(effectType);
|
||||
if (amplifier > maxAmplifier) {
|
||||
sender.sendMessage("Level " + amplifier + " exceeds the maximum allowed level of " + maxAmplifier + " for " + effectType.getName() + ".");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
|
||||
|
||||
double cost = PotionEffectBaseValues.getPotionEffectBaseValue(effectType, duration, amplifier);
|
||||
|
||||
if (cost == Double.MAX_VALUE) {
|
||||
sender.sendMessage("Level exceeds maximum allowed for this potion effect.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (playerStats.getStat("money", Double.class) < cost) {
|
||||
sender.sendMessage("Not enough money. Cost: " + Shared.formatNumber(cost) + " money.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Apply the potion effect
|
||||
PotionEffect potionEffect = new PotionEffect(effectType, duration * 20, amplifier - 1); // Convert seconds to ticks, amplifier is 0-based
|
||||
player.addPotionEffect(potionEffect);
|
||||
|
||||
// Deduct cost
|
||||
playerStats.setStat("money", playerStats.getStat("money", Double.class) - cost);
|
||||
|
||||
sender.sendMessage("Purchased " + effectType.getName() + " level " + amplifier + " for " + duration + " seconds for " + Shared.formatNumber(cost) + " money.");
|
||||
return true;
|
||||
|
||||
} else {
|
||||
sender.sendMessage("This command can only be run by a player.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,7 @@ public class MarketBaseCommand implements CommandExecutor {
|
|||
case "stock" -> Stock.SubCommand(sender, args);
|
||||
case "ripoff" -> Ripoff.SubCommand(sender, args);
|
||||
case "enchant" -> BuyEnchantment.SubCommand(sender, args);
|
||||
case "potioneffect" -> BuyPotionEffect.SubCommand(sender, args);
|
||||
case "tp" -> Tp.SubCommand(sender, args);
|
||||
case "sell" -> Sell.SubCommand(sender, args);
|
||||
case "sellall" -> SellAll.SubCommand(sender, args);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import org.bukkit.entity.Player;
|
|||
import org.gsdistance.grimmsServer.Constructable.Market;
|
||||
import org.gsdistance.grimmsServer.Data.Market.EnchantBaseValues;
|
||||
import org.gsdistance.grimmsServer.Data.Market.MarketBaseValues;
|
||||
import org.gsdistance.grimmsServer.Data.Market.PotionEffectBaseValues;
|
||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -27,6 +28,7 @@ public class MarketTabCompleter implements TabCompleter {
|
|||
subs.add("stock");
|
||||
subs.add("ripoff");
|
||||
subs.add("enchant");
|
||||
subs.add("potioneffect");
|
||||
subs.add("tp");
|
||||
subs.add("buy");
|
||||
subs.add("sell");
|
||||
|
|
@ -41,15 +43,21 @@ public class MarketTabCompleter implements TabCompleter {
|
|||
Market marketStock = Market.getMarket();
|
||||
yield marketStock.items.keySet().stream().filter(name -> name.toLowerCase().contains(args[1].toLowerCase())).toList();
|
||||
}
|
||||
case "ripoff" -> MarketBaseValues.marketBaseValues.keySet().stream()
|
||||
case "ripoff" -> {
|
||||
yield MarketBaseValues.marketBaseValues.keySet().stream()
|
||||
.map(Material::name)
|
||||
.filter(name -> name.toLowerCase().startsWith(args[1].toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
case "enchant" -> EnchantBaseValues.enchantBaseValues.keySet().stream()
|
||||
.map(Enchantment::getName)
|
||||
.map(Object::toString)
|
||||
.filter(name -> name.toLowerCase().startsWith(args[1].toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
case "potioneffect" -> PotionEffectBaseValues.potionEffectBaseValues.keySet().stream()
|
||||
.map(org.bukkit.potion.PotionEffectType::getName)
|
||||
.filter(name -> name.toLowerCase().startsWith(args[1].toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
case "tp" -> GrimmsServer.instance.getServer().getOnlinePlayers().stream()
|
||||
.map(Player::getName)
|
||||
.filter(name -> name.toLowerCase().startsWith(args[1].toLowerCase()))
|
||||
|
|
@ -60,6 +68,12 @@ public class MarketTabCompleter implements TabCompleter {
|
|||
if (args.length == 3 && (args[0].equalsIgnoreCase("buy") || args[0].equalsIgnoreCase("ripoff"))) {
|
||||
return Collections.singletonList("<amount>");
|
||||
}
|
||||
if (args.length == 3 && args[0].equalsIgnoreCase("potioneffect")) {
|
||||
return Collections.singletonList("<duration>");
|
||||
}
|
||||
if (args.length == 4 && args[0].equalsIgnoreCase("potioneffect")) {
|
||||
return Collections.singletonList("<level>");
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
package org.gsdistance.grimmsServer.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class HelpStrings {
|
||||
public static final Map<String, String> helpStrings = Map.ofEntries(
|
||||
Map.entry("sendmoney", "Send money to another player"),
|
||||
Map.entry("makeitemlevelable", "Make the item in your hand levelable (costs 3500 money, requires level 10+)"),
|
||||
Map.entry("setplayerstat", "Set a specific stat for a player"),
|
||||
Map.entry("addtitle", "Add a title to a player"),
|
||||
Map.entry("executeplayer", "Execute a player (requires Executioner title)"),
|
||||
Map.entry("grimsservercommands", "List all available GrimmsServer commands"),
|
||||
Map.entry("withdrawmoney", "Withdraw money as physical banknotes (minimum 25 money)"),
|
||||
Map.entry("depositmoney", "Deposit banknotes by holding them in your main hand"),
|
||||
Map.entry("acceptrequest", "Accept a pending request by ID"),
|
||||
Map.entry("removetitle", "Remove a title from a player"),
|
||||
Map.entry("home", "Manage your homes - set, teleport, list, or delete"),
|
||||
Map.entry("nick", "Set your nickname or another player's nickname"),
|
||||
Map.entry("market", "Access the market system for buying, selling, and enchanting"),
|
||||
Map.entry("gutil", "Utility commands for version info, relics, capabilities, and settings"),
|
||||
Map.entry("glog", "View logs for stats, titles, world info, leaderboards, and chunk data"),
|
||||
Map.entry("gdim", "Dimension management - create, delete, teleport, list, and get info"),
|
||||
Map.entry("gfaction", "Faction management - invite, join, leave, kick, claim, and manage ranks"),
|
||||
Map.entry("gconfig", "Configuration management - dump config or reload settings"),
|
||||
Map.entry("job", "Job system - log jobs, take jobs, or buy education"),
|
||||
Map.entry("ghelp", "Get help for GrimmsServer commands")
|
||||
);
|
||||
public static final Map<String, String> helpUsages = Map.ofEntries(
|
||||
Map.entry("sendmoney", "/sendmoney <player> <amount>"),
|
||||
Map.entry("makeitemlevelable", "/makeitemlevelable"),
|
||||
Map.entry("setplayerstat", "/setplayerstat <player> <stat> <value>"),
|
||||
Map.entry("addtitle", "/addtitle <player> <title>"),
|
||||
Map.entry("executeplayer", "/executeplayer <player>"),
|
||||
Map.entry("grimsservercommands", "/grimsservercommands"),
|
||||
Map.entry("withdrawmoney", "/withdrawmoney <amount> [count]"),
|
||||
Map.entry("depositmoney", "/depositmoney"),
|
||||
Map.entry("acceptrequest", "/acceptrequest <request_id>"),
|
||||
Map.entry("removetitle", "/removetitle <player> <title>"),
|
||||
Map.entry("home", "/home <sethome|tp|homes|delhome> [args...]"),
|
||||
Map.entry("nick", "/nick <nickname> OR /nick <player> <nickname>"),
|
||||
Map.entry("market", "/market <get|stock|ripoff|enchant|tp|sell|sellall|buy|enchcosts|info> [args...]"),
|
||||
Map.entry("gutil", "/gutil <version|relic|capability|setting> [args...]"),
|
||||
Map.entry("glog", "/glog <self_stats|other_stats|self_titles|other_titles|world|leaderboard|commands|chunk> [args...]"),
|
||||
Map.entry("gdim", "/gdim <create|delete|tp|list|info> [args...]"),
|
||||
Map.entry("gfaction", "/gfaction <invite|join|leave|kick|info|new|claim|unclaim|setrank|unclaimall> [args...]"),
|
||||
Map.entry("gconfig", "/gconfig <dump|reload>"),
|
||||
Map.entry("job", "/job <log|take|buyedu> [args...]"),
|
||||
Map.entry("ghelp", "/ghelp <command>")
|
||||
);
|
||||
public static String getHelpString(String commandName) {
|
||||
return helpStrings.getOrDefault(commandName.toLowerCase(), "Not found.");
|
||||
}
|
||||
public static String getHelpUsage(String commandName) {
|
||||
return helpUsages.getOrDefault(commandName.toLowerCase(), "Not found.");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package org.gsdistance.grimmsServer.Data.Market;
|
||||
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class PotionEffectBaseValues {
|
||||
public static final Map<PotionEffectType, Double> potionEffectBaseValues = Map.ofEntries(
|
||||
Map.entry(PotionEffectType.SPEED, 5.0),
|
||||
Map.entry(PotionEffectType.SLOWNESS, 3.0),
|
||||
Map.entry(PotionEffectType.HASTE, 8.0),
|
||||
Map.entry(PotionEffectType.MINING_FATIGUE, 2.0),
|
||||
Map.entry(PotionEffectType.STRENGTH, 10.0),
|
||||
Map.entry(PotionEffectType.INSTANT_HEALTH, 50.0),
|
||||
Map.entry(PotionEffectType.INSTANT_DAMAGE, 45.0),
|
||||
Map.entry(PotionEffectType.JUMP_BOOST, 4.0),
|
||||
Map.entry(PotionEffectType.NAUSEA, 1.0),
|
||||
Map.entry(PotionEffectType.REGENERATION, 12.0),
|
||||
Map.entry(PotionEffectType.RESISTANCE, 15.0),
|
||||
Map.entry(PotionEffectType.FIRE_RESISTANCE, 6.0),
|
||||
Map.entry(PotionEffectType.WATER_BREATHING, 4.0),
|
||||
Map.entry(PotionEffectType.INVISIBILITY, 20.0),
|
||||
Map.entry(PotionEffectType.BLINDNESS, 2.0),
|
||||
Map.entry(PotionEffectType.NIGHT_VISION, 3.0),
|
||||
Map.entry(PotionEffectType.HUNGER, 1.0),
|
||||
Map.entry(PotionEffectType.WEAKNESS, 2.0),
|
||||
Map.entry(PotionEffectType.POISON, 8.0),
|
||||
Map.entry(PotionEffectType.WITHER, 18.0),
|
||||
Map.entry(PotionEffectType.HEALTH_BOOST, 150.0),
|
||||
Map.entry(PotionEffectType.ABSORPTION, 20.0),
|
||||
Map.entry(PotionEffectType.GLOWING, 1.0),
|
||||
Map.entry(PotionEffectType.LEVITATION, 12.0),
|
||||
Map.entry(PotionEffectType.LUCK, 30.0),
|
||||
Map.entry(PotionEffectType.UNLUCK, 2.0),
|
||||
Map.entry(PotionEffectType.SLOW_FALLING, 5.0),
|
||||
Map.entry(PotionEffectType.CONDUIT_POWER, 14.0),
|
||||
Map.entry(PotionEffectType.DOLPHINS_GRACE, 3.0),
|
||||
Map.entry(PotionEffectType.BAD_OMEN, 8.0),
|
||||
Map.entry(PotionEffectType.HERO_OF_THE_VILLAGE, 25.0),
|
||||
Map.entry(PotionEffectType.DARKNESS, 2.0),
|
||||
Map.entry(PotionEffectType.TRIAL_OMEN, 10.0),
|
||||
Map.entry(PotionEffectType.WIND_CHARGED, 7.0),
|
||||
Map.entry(PotionEffectType.WEAVING, 6.0),
|
||||
Map.entry(PotionEffectType.OOZING, 5.0),
|
||||
Map.entry(PotionEffectType.INFESTED, 4.0)
|
||||
);
|
||||
|
||||
public static final Map<PotionEffectType, Integer> potionEffectAmplitudeLimits = Map.ofEntries(
|
||||
Map.entry(PotionEffectType.REGENERATION, 2),
|
||||
Map.entry(PotionEffectType.RESISTANCE, 1),
|
||||
Map.entry(PotionEffectType.HASTE, 3)
|
||||
);
|
||||
|
||||
public static double getPotionEffectBaseValue(PotionEffectType potionEffectType, int time, int amplifier) {
|
||||
Integer limit = potionEffectAmplitudeLimits.get(potionEffectType);
|
||||
if(limit != null && amplifier > limit) {
|
||||
return Double.MAX_VALUE;
|
||||
}
|
||||
return potionEffectBaseValues.get(potionEffectType) * time * Math.pow(amplifier,2);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
package org.gsdistance.grimmsServer.Data.Player;
|
||||
|
||||
public enum PlayerCapability {
|
||||
AUTOSELL("Auto Sell", "Allows the player to automatically sell items in their inventory when they reach a certain threshold.", "autosell");
|
||||
AUTOSELL("Auto Sell", "Allows the player to automatically sell items in their inventory when they reach a certain threshold.", "autosell"),
|
||||
MAGNET("Magnet","Magnetises items in a 10 block radius", "magnet");
|
||||
|
||||
public final String displayName;
|
||||
public final String description;
|
||||
|
|
|
|||
|
|
@ -47,6 +47,9 @@ public class PlayerTitleChecker {
|
|||
if (money > 1000000000000.0) {
|
||||
playerTitles.addTitle("Trillionaire");
|
||||
}
|
||||
if (money > 1000000000000000.0) {
|
||||
playerTitles.addTitle("Trillionaire");
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkForBlockBreaks(Player player) {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ public class EntityPickupItemEvent {
|
|||
public static void Event(org.bukkit.event.entity.EntityPickupItemEvent event) {
|
||||
if (event.getEntity() instanceof Player player){
|
||||
PlayerMetadata playerMetadata = PlayerMetadata.getPlayerMetadata(player);
|
||||
if(playerMetadata.capabilities.containsKey(PlayerCapability.AUTOSELL) && playerMetadata.settings.contains("autosell")){
|
||||
if(playerMetadata.capabilities.containsKey(PlayerCapability.AUTOSELL) && playerMetadata.settings.contains(PlayerCapability.AUTOSELL.capabilityId)){
|
||||
Market market = Market.getMarket();
|
||||
market.unsafeSell(event.getItem().getItemStack(), player);
|
||||
market.saveMarket();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
package org.gsdistance.grimmsServer.Events.Listeners;
|
||||
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Constructable.Player.PlayerMetadata;
|
||||
import org.gsdistance.grimmsServer.Data.Player.PlayerCapability;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PlayerTickEvent {
|
||||
private static final List<Player> magnetPlayers = new ArrayList<>();
|
||||
|
||||
public static void Event(Player player){
|
||||
PlayerMetadata playerMetadata = PlayerMetadata.getPlayerMetadata(player);
|
||||
// Check for magnet capability and add to list if enabled
|
||||
if(playerMetadata.capabilities.containsKey(PlayerCapability.MAGNET) && playerMetadata.settings.contains(PlayerCapability.MAGNET.capabilityId)){
|
||||
magnetPlayers.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
public static void processMagnets() {
|
||||
if (magnetPlayers.isEmpty()) return;
|
||||
|
||||
// Process all items once, check against all magnet players
|
||||
for (Player magnetPlayer : magnetPlayers) {
|
||||
for (Item item : magnetPlayer.getWorld().getEntitiesByClass(Item.class)) {
|
||||
if (item.getLocation().distance(magnetPlayer.getLocation()) <= 10) {
|
||||
item.teleport(magnetPlayer.getLocation());
|
||||
break; // Item teleported, no need to check other players
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
magnetPlayers.clear();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
package org.gsdistance.grimmsServer.Events.Listeners;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Constructable.Player.PlayerMetadata;
|
||||
import org.gsdistance.grimmsServer.Data.JobTitlesBaseValues;
|
||||
import org.gsdistance.grimmsServer.Data.Player.PlayerCapability;
|
||||
import org.gsdistance.grimmsServer.Data.Player.PlayerTitleChecker;
|
||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||
import org.gsdistance.grimmsServer.Shared;
|
||||
|
|
@ -12,7 +14,12 @@ public class ServerTickEvent {
|
|||
public static long ticks = 0;
|
||||
|
||||
public static void Event() {
|
||||
for(Player player : GrimmsServer.instance.getServer().getOnlinePlayers()) {
|
||||
PlayerTickEvent.Event(player);
|
||||
}
|
||||
PlayerTickEvent.processMagnets();
|
||||
ticks++;
|
||||
//Player tick
|
||||
if (ticks % 1000 == 0) {
|
||||
for (Player player : GrimmsServer.instance.getServer().getOnlinePlayers()) {
|
||||
PlayerStatLeaderBoard.getPlayerStatLeaderBoard().checkPlayer(player);
|
||||
|
|
@ -22,6 +29,7 @@ public class ServerTickEvent {
|
|||
PlayerTitleChecker.checkForTotalKills(player);
|
||||
}
|
||||
}
|
||||
// Paycheck
|
||||
if (ticks % 24000 == 0) {
|
||||
for (Player player : GrimmsServer.instance.getServer().getOnlinePlayers()) {
|
||||
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
|
||||
|
|
|
|||
|
|
@ -10,10 +10,12 @@ import org.gsdistance.grimmsServer.GrimmsServer;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ItemIndexer {
|
||||
private static final Map<Material, Double> calculatedMarketValues = new HashMap<>();
|
||||
private static final List<Material> skippedMarketValues = new ArrayList<>();
|
||||
private static final Set<Material> skippedMarketValues = new HashSet<>();
|
||||
private static final Map<Material, List<Recipe>> recipeCache = new HashMap<>();
|
||||
public static boolean loggingEnabled = true;
|
||||
|
||||
public static void indexWholeRegistry(){
|
||||
|
|
@ -22,6 +24,11 @@ public class ItemIndexer {
|
|||
// Clear previous values
|
||||
calculatedMarketValues.clear();
|
||||
skippedMarketValues.clear();
|
||||
recipeCache.clear();
|
||||
|
||||
// Pre-cache all recipes to avoid repeated Bukkit calls
|
||||
cacheAllRecipes();
|
||||
|
||||
// Check the cache first
|
||||
Map<Material, Double> tmp;
|
||||
try {
|
||||
|
|
@ -37,41 +44,52 @@ public class ItemIndexer {
|
|||
calculatedMarketValues.putAll(tmp);
|
||||
cacheExists = true;
|
||||
}
|
||||
// Iterate through all materials and calculate market values
|
||||
for (Material material : Material.values()) {
|
||||
if (material.isItem() && material != Material.AIR && !MarketBaseValues.marketBaseValues.containsKey(material) && !calculatedMarketValues.containsKey(material)) {
|
||||
double marketValue = calculateMarketValue(material);
|
||||
if (marketValue > 0) {
|
||||
calculatedMarketValues.put(material, Math.floor(marketValue));
|
||||
if (loggingEnabled) {
|
||||
GrimmsServer.logger.info("Calculated market value for " + material + ": " + Math.floor(marketValue));
|
||||
}
|
||||
}
|
||||
else{
|
||||
skippedMarketValues.add(material);
|
||||
|
||||
// Process only items that need calculation
|
||||
Set<Material> materialsToProcess = Arrays.stream(Material.values())
|
||||
.filter(material -> material.isItem() && material != Material.AIR)
|
||||
.filter(material -> !MarketBaseValues.marketBaseValues.containsKey(material))
|
||||
.filter(material -> !calculatedMarketValues.containsKey(material))
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// First pass calculation
|
||||
Set<Material> firstPassSkipped = new HashSet<>();
|
||||
for (Material material : materialsToProcess) {
|
||||
double marketValue = calculateMarketValue(material);
|
||||
if (marketValue > 0) {
|
||||
calculatedMarketValues.put(material, Math.floor(marketValue));
|
||||
if (loggingEnabled) {
|
||||
GrimmsServer.logger.info("Calculated market value for " + material + ": " + Math.floor(marketValue));
|
||||
}
|
||||
} else {
|
||||
firstPassSkipped.add(material);
|
||||
}
|
||||
}
|
||||
// Retry calculating market values for skipped items
|
||||
if(!cacheExists){
|
||||
|
||||
// Retry logic for skipped items (only if no cache existed)
|
||||
if (!cacheExists && !firstPassSkipped.isEmpty()) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (loggingEnabled) {
|
||||
GrimmsServer.logger.info("Recalculating skipped market values, attempt " + (i + 1));
|
||||
}
|
||||
for (Material material : skippedMarketValues) {
|
||||
if (material.isItem() && material != Material.AIR && !MarketBaseValues.marketBaseValues.containsKey(material)) {
|
||||
double marketValue = calculateMarketValue(material);
|
||||
if (marketValue > 0) {
|
||||
calculatedMarketValues.put(material, marketValue);
|
||||
skippedMarketValues.remove(material);
|
||||
if (loggingEnabled) {
|
||||
GrimmsServer.logger.info("Calculated market value for " + material + ": " + marketValue);
|
||||
}
|
||||
Set<Material> stillSkipped = new HashSet<>();
|
||||
for (Material material : firstPassSkipped) {
|
||||
double marketValue = calculateMarketValue(material);
|
||||
if (marketValue > 0) {
|
||||
calculatedMarketValues.put(material, marketValue);
|
||||
if (loggingEnabled) {
|
||||
GrimmsServer.logger.info("Calculated market value for " + material + ": " + marketValue);
|
||||
}
|
||||
} else {
|
||||
stillSkipped.add(material);
|
||||
}
|
||||
}
|
||||
firstPassSkipped = stillSkipped;
|
||||
if (firstPassSkipped.isEmpty()) break;
|
||||
}
|
||||
skippedMarketValues.addAll(firstPassSkipped);
|
||||
}
|
||||
|
||||
GrimmsServer.logger.info("Indexed " + calculatedMarketValues.size() + " items in (" + stopwatch.stop() + ").");
|
||||
GrimmsServer.logger.info("Skipped " + skippedMarketValues.size() + " items that could not be calculated.");
|
||||
|
||||
|
|
@ -82,10 +100,23 @@ public class ItemIndexer {
|
|||
MarketBaseValues.marketBaseValues.putAll(calculatedMarketValues);
|
||||
}
|
||||
|
||||
private static void cacheAllRecipes() {
|
||||
for (Material material : Material.values()) {
|
||||
if (material.isItem() && material != Material.AIR) {
|
||||
List<Recipe> recipes = Bukkit.getServer().getRecipesFor(new ItemStack(material));
|
||||
if (recipes != null && !recipes.isEmpty()) {
|
||||
recipeCache.put(material, recipes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final ThreadLocal<Set<Material>> processingMaterials = ThreadLocal.withInitial(HashSet::new);
|
||||
|
||||
public static Double calculateMarketValue(@Nullable Material item) {
|
||||
// Track materials being processed to prevent infinite recursion
|
||||
Set<Material> processingMaterials = new HashSet<>();
|
||||
return calculateMarketValueInternal(item, processingMaterials);
|
||||
Set<Material> processingSet = processingMaterials.get();
|
||||
processingSet.clear();
|
||||
return calculateMarketValueInternal(item, processingSet);
|
||||
}
|
||||
|
||||
private static Double calculateMarketValueInternal(@Nullable Material item, Set<Material> processingMaterials) {
|
||||
|
|
@ -106,9 +137,14 @@ public class ItemIndexer {
|
|||
}
|
||||
|
||||
processingMaterials.add(item);
|
||||
double marketValue = 0.0;
|
||||
double marketValue = Double.MAX_VALUE;
|
||||
|
||||
for (Recipe recipe : Bukkit.getServer().getRecipesFor(new ItemStack(item))) {
|
||||
List<Recipe> recipes = recipeCache.get(item);
|
||||
if (recipes == null || recipes.isEmpty()) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
for (Recipe recipe : recipes) {
|
||||
if (recipe == null || recipe.getResult().getType() == Material.AIR) {
|
||||
continue; // Skip invalid recipes
|
||||
}
|
||||
|
|
@ -136,21 +172,21 @@ public class ItemIndexer {
|
|||
ItemStack result = furnaceRecipe.getResult();
|
||||
if (result.getType() == item) {
|
||||
double ingredientValue = calculateMarketValueInternal(furnaceRecipe.getInput().getType(), processingMaterials);
|
||||
recipeValue = ingredientValue * result.getAmount();
|
||||
recipeValue = ingredientValue / result.getAmount();
|
||||
}
|
||||
}
|
||||
case org.bukkit.inventory.StonecuttingRecipe stonecuttingRecipe -> {
|
||||
ItemStack result = stonecuttingRecipe.getResult();
|
||||
if (result.getType() == item) {
|
||||
double ingredientValue = calculateMarketValueInternal(stonecuttingRecipe.getInput().getType(), processingMaterials);
|
||||
recipeValue = ingredientValue * result.getAmount();
|
||||
recipeValue = ingredientValue / result.getAmount();
|
||||
}
|
||||
}
|
||||
case org.bukkit.inventory.BlastingRecipe blastingRecipe -> {
|
||||
ItemStack result = blastingRecipe.getResult();
|
||||
if (result.getType() == item) {
|
||||
double ingredientValue = calculateMarketValueInternal(blastingRecipe.getInput().getType(), processingMaterials);
|
||||
recipeValue = ingredientValue * result.getAmount();
|
||||
recipeValue = ingredientValue / result.getAmount();
|
||||
}
|
||||
}
|
||||
case org.bukkit.inventory.SmithingRecipe smithingRecipe -> {
|
||||
|
|
@ -163,20 +199,21 @@ public class ItemIndexer {
|
|||
ItemStack addition = smithingRecipe.getAddition().getItemStack();
|
||||
double baseValue = calculateMarketValueInternal(base.getType(), processingMaterials);
|
||||
double additionValue = calculateMarketValueInternal(addition.getType(), processingMaterials);
|
||||
recipeValue = (baseValue + additionValue) * result.getAmount();
|
||||
recipeValue = (baseValue + additionValue) / result.getAmount();
|
||||
}
|
||||
}
|
||||
default -> {
|
||||
return 0.0; // Unsupported recipe type
|
||||
}
|
||||
}
|
||||
recipeValue = recipeValue / recipe.getResult().getAmount(); // Normalize by result amount
|
||||
if (recipeValue > marketValue) {
|
||||
// No normalization needed for shaped/shapeless recipes as they already account for ingredient amounts
|
||||
// For single-input recipes, we already divided by result amount above
|
||||
if (recipeValue > 0 && recipeValue < marketValue) {
|
||||
marketValue = recipeValue;
|
||||
}
|
||||
}
|
||||
|
||||
processingMaterials.remove(item);
|
||||
return marketValue;
|
||||
return marketValue == Double.MAX_VALUE ? 0.0 : marketValue;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import org.gsdistance.grimmsServer.Commands.GDimensionCommand.GDimBaseCommand;
|
|||
import org.gsdistance.grimmsServer.Commands.GDimensionCommand.GDimTabCompleter;
|
||||
import org.gsdistance.grimmsServer.Commands.GFactionCommand.GFactionBaseCommand;
|
||||
import org.gsdistance.grimmsServer.Commands.GFactionCommand.GFactionTabCompleter;
|
||||
import org.gsdistance.grimmsServer.Commands.GHelpCommand.GHelp;
|
||||
import org.gsdistance.grimmsServer.Commands.GHelpCommand.GHelpTabCompleter;
|
||||
import org.gsdistance.grimmsServer.Commands.GLogCommand.GLogBaseCommand;
|
||||
import org.gsdistance.grimmsServer.Commands.GLogCommand.GLogTabCompleter;
|
||||
import org.gsdistance.grimmsServer.Commands.GUtilCommand.GUtilBaseCommand;
|
||||
|
|
@ -59,6 +61,9 @@ public class CommandRegistry {
|
|||
GrimmsServer.instance.getCommand("gConfig").setTabCompleter(new GConfigTabCompleter());
|
||||
GrimmsServer.instance.getCommand("job").setExecutor(new JobBaseCommand());
|
||||
GrimmsServer.instance.getCommand("job").setTabCompleter(new JobTabCompleter());
|
||||
GrimmsServer.instance.getCommand("gHelp").setExecutor(new GHelp());
|
||||
GrimmsServer.instance.getCommand("gHelp").setTabCompleter(new GHelpTabCompleter());
|
||||
|
||||
}
|
||||
|
||||
public static boolean CanExecute(String command) {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ public class PlayerTitles {
|
|||
Map.entry("Millionaire", "Wow, that's quite a lot ya' know!"),
|
||||
Map.entry("Billionaire", "Capitalism at it's finest."),
|
||||
Map.entry("Trillionaire", "Literally insane, no comment."),
|
||||
Map.entry("Quadrillionaire", "Why?"),
|
||||
Map.entry("Miner", "Minin' to the earths core."),
|
||||
Map.entry("Anti-block", "DEMOLISH 10000 blocks"),
|
||||
Map.entry("UltimateMiner", "Mine 100000 blocks"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue