This commit is contained in:
tyuXX 2026-07-17 00:05:31 +03:00
parent da48cc9d9e
commit 8c573b12a2
28 changed files with 42 additions and 210 deletions

View file

@ -33,7 +33,7 @@ public enum ConfigKey {
PRESTIGE_CAPABILITY_AUTOSELL_PRICE("prestige_capability_autosell_price", 4),
PRESTIGE_CAPABILITY_MAGNET_PRICE("prestige_capability_magnet_price", 2),
PRESTIGE_CAPABILITY_VEINMINER_PRICE("prestige_capability_veinminer_price", 3),
PRESTIGE_CAPABILITY_SATURATION_PERK_PRICE("prestige_capability_saturation_perk_price", 4);
PRESTIGE_CAPABILITY_SATURATION_PERK_PRICE("prestige_capability_saturation_perk_price", 10);
private final String key;
private final Object defaultValue;

View file

@ -11,19 +11,49 @@ import java.io.IOException;
public class ConfigLoader {
private static FileConfiguration config;
private static File configFile;
public ConfigLoader() {
}
public static void initialize(JavaPlugin plugin) {
File configFile = new File(plugin.getDataFolder(), "config.yml");
configFile = new File(plugin.getDataFolder(), "config.yml");
if (!configFile.exists()) {
generateDefaultConfig(configFile);
} else {
migrateConfig();
}
config = YamlConfiguration.loadConfiguration(configFile);
}
private static void migrateConfig() {
YamlConfiguration existingConfig = YamlConfiguration.loadConfiguration(configFile);
String currentVersion = GrimmsServer.instance.getDescription().getVersion();
String configVersion = existingConfig.getString(ConfigKey.CONFIG_VERSION.getKey());
if (configVersion == null || !configVersion.equals(currentVersion)) {
boolean needsUpdate = false;
for (ConfigKey key : ConfigKey.values()) {
if (!existingConfig.contains(key.getKey())) {
existingConfig.set(key.getKey(), key.getDefaultValue());
needsUpdate = true;
GrimmsServer.logger.info("Added missing config field: " + key.getKey());
}
}
existingConfig.set(ConfigKey.CONFIG_VERSION.getKey(), currentVersion);
if (needsUpdate) {
try {
existingConfig.save(configFile);
GrimmsServer.logger.info("Config migrated to version " + currentVersion);
} catch (IOException e) {
GrimmsServer.logger.severe("Failed to migrate config: " + e.getMessage());
}
}
}
}
private static void generateDefaultConfig(File configFile) {
YamlConfiguration yamlConfig = new YamlConfiguration();
for (ConfigKey key : ConfigKey.values()) {
@ -40,9 +70,10 @@ public class ConfigLoader {
public static void loadConfigFromFile() {
Stopwatch sw = Stopwatch.createStarted();
GrimmsServer.logger.info("Loading GrimmsServer config...");
if (config == null) {
GrimmsServer.logger.warning("Config somehow not initialized. (" + sw.stop() + ")");
if (configFile == null) {
GrimmsServer.logger.warning("Config file not initialized. (" + sw.stop() + ")");
} else {
config = YamlConfiguration.loadConfiguration(configFile);
for (ConfigKey key : ConfigKey.values()) {
Object value = config.get(key.getKey(), key.getDefaultValue());
ActiveConfig.setConfigValue(key, value);

View file

@ -1,5 +1,6 @@
package org.gsdistance.grimmsServer.Events.Listeners;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.gsdistance.grimmsServer.Constructable.Player.PlayerLevelHandler;
@ -19,7 +20,7 @@ public class EntityDeathEvent {
event.getEntity().setCustomName(null);
}
if (event.getEntity().getKiller() != null && event.getEntity().getKiller().getType() == EntityType.PLAYER) {
if (event.getEntity().getKiller() != null && event.getEntity().getAttribute(Attribute.MAX_HEALTH) != null && event.getEntity().getAttribute(Attribute.MAX_HEALTH).getValue() > 0 && event.getEntity().getKiller().getType() == EntityType.PLAYER) {
PlayerStats playerStats = PlayerStats.getPlayerStats(event.getEntity().getKiller());
WorldStats worldStats = WorldStats.getWorldStats(event.getEntity().getWorld());
playerStats.changeStat("total_kill_count", 1);

View file

@ -89,8 +89,8 @@ public class PlayerTickEvent {
double money = playerStats.getStat("money", Double.class);
if(playerStats.getStat("maximum_balance", Double.class) < money + payCheck){
playerStats.setStat("money", money + payCheck);
player.sendMessage(ChatColor.GREEN + "You have received your paycheck: " + ChatColor.GOLD + Shared.formatNumber(payCheck));
}
player.sendMessage(ChatColor.GREEN + "You have received your paycheck: " + ChatColor.GOLD + Shared.formatNumber(payCheck));
lastPaycheckTimes.put(playerId, currentTime);
}
}