1.5.4 p1 Fixes
This commit is contained in:
parent
a7358d968d
commit
942bb849f2
19 changed files with 218 additions and 170 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.
|
|
@ -3,7 +3,7 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'org.gsdistance'
|
group = 'org.gsdistance'
|
||||||
version = '1.5.3'
|
version = '1.5.4'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -13,6 +13,8 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static org.gsdistance.grimmsServer.Shared.getOnlinePlayers;
|
||||||
|
|
||||||
public class GLogTabCompleter implements TabCompleter {
|
public class GLogTabCompleter implements TabCompleter {
|
||||||
private static final List<String> SUBCOMMANDS = Arrays.asList("self_stats", "other_stats", "self_titles", "other_titles", "world", "leaderboard", "commands", "chunk");
|
private static final List<String> SUBCOMMANDS = Arrays.asList("self_stats", "other_stats", "self_titles", "other_titles", "world", "leaderboard", "commands", "chunk");
|
||||||
|
|
||||||
|
|
@ -39,25 +41,7 @@ public class GLogTabCompleter implements TabCompleter {
|
||||||
String partialPlayer = args[1].toLowerCase();
|
String partialPlayer = args[1].toLowerCase();
|
||||||
List<String> playerSuggestions = new ArrayList();
|
List<String> playerSuggestions = new ArrayList();
|
||||||
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
return getOnlinePlayers(partialPlayer, playerSuggestions);
|
||||||
if (player.getName().toLowerCase().startsWith(partialPlayer)) {
|
|
||||||
playerSuggestions.add(player.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (org.bukkit.OfflinePlayer offlinePlayer : Bukkit.getOfflinePlayers()) {
|
|
||||||
if (offlinePlayer.hasPlayedBefore() &&
|
|
||||||
offlinePlayer.getName() != null &&
|
|
||||||
offlinePlayer.getName().toLowerCase().startsWith(partialPlayer) &&
|
|
||||||
!playerSuggestions.contains(offlinePlayer.getName())) {
|
|
||||||
UUID uuid = offlinePlayer.getUniqueId();
|
|
||||||
if (org.gsdistance.grimmsServer.Constructable.Player.PlayerMetadata.getOfflinePlayerMetadata(uuid) != null) {
|
|
||||||
playerSuggestions.add(offlinePlayer.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return playerSuggestions;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static org.gsdistance.grimmsServer.Shared.getOnlinePlayers;
|
||||||
|
|
||||||
public class GStatsTabCompleter implements TabCompleter {
|
public class GStatsTabCompleter implements TabCompleter {
|
||||||
private static final List<String> SUBCOMMANDS = Arrays.asList("self_history", "others_history", "commands");
|
private static final List<String> SUBCOMMANDS = Arrays.asList("self_history", "others_history", "commands");
|
||||||
private static final List<String> TIME_RANGES = Arrays.asList("hour", "day", "week", "month", "all");
|
private static final List<String> TIME_RANGES = Arrays.asList("hour", "day", "week", "month", "all");
|
||||||
|
|
@ -26,7 +28,7 @@ public class GStatsTabCompleter implements TabCompleter {
|
||||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
String partial = args[0].toLowerCase();
|
String partial = args[0].toLowerCase();
|
||||||
List<String> suggestions = new ArrayList();
|
List<String> suggestions = new ArrayList<>();
|
||||||
|
|
||||||
for (String subcommand : SUBCOMMANDS) {
|
for (String subcommand : SUBCOMMANDS) {
|
||||||
if (subcommand.startsWith(partial) && hasPermissionForSubcommand(sender, subcommand)) {
|
if (subcommand.startsWith(partial) && hasPermissionForSubcommand(sender, subcommand)) {
|
||||||
|
|
@ -39,30 +41,12 @@ public class GStatsTabCompleter implements TabCompleter {
|
||||||
String subcommand = args[0].toLowerCase();
|
String subcommand = args[0].toLowerCase();
|
||||||
if (subcommand.equals("others_history")) {
|
if (subcommand.equals("others_history")) {
|
||||||
String partialPlayer = args[1].toLowerCase();
|
String partialPlayer = args[1].toLowerCase();
|
||||||
List<String> playerSuggestions = new ArrayList();
|
List<String> playerSuggestions = new ArrayList<>();
|
||||||
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
return getOnlinePlayers(partialPlayer, playerSuggestions);
|
||||||
if (player.getName().toLowerCase().startsWith(partialPlayer)) {
|
|
||||||
playerSuggestions.add(player.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (org.bukkit.OfflinePlayer offlinePlayer : Bukkit.getOfflinePlayers()) {
|
|
||||||
if (offlinePlayer.hasPlayedBefore() &&
|
|
||||||
offlinePlayer.getName() != null &&
|
|
||||||
offlinePlayer.getName().toLowerCase().startsWith(partialPlayer) &&
|
|
||||||
!playerSuggestions.contains(offlinePlayer.getName())) {
|
|
||||||
UUID uuid = offlinePlayer.getUniqueId();
|
|
||||||
if (org.gsdistance.grimmsServer.Constructable.Player.PlayerMetadata.getOfflinePlayerMetadata(uuid) != null) {
|
|
||||||
playerSuggestions.add(offlinePlayer.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return playerSuggestions;
|
|
||||||
} else if (subcommand.equals("self_history")) {
|
} else if (subcommand.equals("self_history")) {
|
||||||
String partialTime = args[1].toLowerCase();
|
String partialTime = args[1].toLowerCase();
|
||||||
List<String> timeSuggestions = new ArrayList();
|
List<String> timeSuggestions = new ArrayList<>();
|
||||||
|
|
||||||
for (String timeRange : TIME_RANGES) {
|
for (String timeRange : TIME_RANGES) {
|
||||||
if (timeRange.startsWith(partialTime)) {
|
if (timeRange.startsWith(partialTime)) {
|
||||||
|
|
@ -76,7 +60,7 @@ public class GStatsTabCompleter implements TabCompleter {
|
||||||
String subcommand = args[0].toLowerCase();
|
String subcommand = args[0].toLowerCase();
|
||||||
if (subcommand.equals("others_history")) {
|
if (subcommand.equals("others_history")) {
|
||||||
String partialTime = args[2].toLowerCase();
|
String partialTime = args[2].toLowerCase();
|
||||||
List<String> timeSuggestions = new ArrayList();
|
List<String> timeSuggestions = new ArrayList<>();
|
||||||
|
|
||||||
for (String timeRange : TIME_RANGES) {
|
for (String timeRange : TIME_RANGES) {
|
||||||
if (timeRange.startsWith(partialTime)) {
|
if (timeRange.startsWith(partialTime)) {
|
||||||
|
|
@ -87,7 +71,7 @@ public class GStatsTabCompleter implements TabCompleter {
|
||||||
return timeSuggestions;
|
return timeSuggestions;
|
||||||
} else if (subcommand.equals("self_history")) {
|
} else if (subcommand.equals("self_history")) {
|
||||||
String partialStat = args[2].toLowerCase();
|
String partialStat = args[2].toLowerCase();
|
||||||
List<String> statSuggestions = new ArrayList();
|
List<String> statSuggestions = new ArrayList<>();
|
||||||
|
|
||||||
for (String stat : PlayerStats.StatOrder) {
|
for (String stat : PlayerStats.StatOrder) {
|
||||||
if (stat.startsWith(partialStat)) {
|
if (stat.startsWith(partialStat)) {
|
||||||
|
|
@ -101,7 +85,7 @@ public class GStatsTabCompleter implements TabCompleter {
|
||||||
String subcommand = args[0].toLowerCase();
|
String subcommand = args[0].toLowerCase();
|
||||||
if (subcommand.equals("others_history")) {
|
if (subcommand.equals("others_history")) {
|
||||||
String partialStat = args[3].toLowerCase();
|
String partialStat = args[3].toLowerCase();
|
||||||
List<String> statSuggestions = new ArrayList();
|
List<String> statSuggestions = new ArrayList<>();
|
||||||
|
|
||||||
for (String stat : PlayerStats.StatOrder) {
|
for (String stat : PlayerStats.StatOrder) {
|
||||||
if (stat.startsWith(partialStat)) {
|
if (stat.startsWith(partialStat)) {
|
||||||
|
|
@ -111,13 +95,12 @@ public class GStatsTabCompleter implements TabCompleter {
|
||||||
|
|
||||||
return statSuggestions;
|
return statSuggestions;
|
||||||
}
|
}
|
||||||
} else if (args.length == 4 || args.length == 5) {
|
} else if (args.length == 5) {
|
||||||
String subcommand = args[0].toLowerCase();
|
String subcommand = args[0].toLowerCase();
|
||||||
if (subcommand.equals("self_history") || subcommand.equals("others_history")) {
|
if (subcommand.equals("self_history") || subcommand.equals("others_history")) {
|
||||||
int argIndex = subcommand.equals("self_history") ? 3 : 4;
|
int argIndex = subcommand.equals("self_history") ? 3 : 4;
|
||||||
if (args.length > argIndex) {
|
|
||||||
String partialGraph = args[argIndex].toLowerCase();
|
String partialGraph = args[argIndex].toLowerCase();
|
||||||
List<String> graphSuggestions = new ArrayList();
|
List<String> graphSuggestions = new ArrayList<>();
|
||||||
|
|
||||||
for (String graphOption : GRAPH_OPTIONS) {
|
for (String graphOption : GRAPH_OPTIONS) {
|
||||||
if (graphOption.startsWith(partialGraph)) {
|
if (graphOption.startsWith(partialGraph)) {
|
||||||
|
|
@ -128,7 +111,6 @@ public class GStatsTabCompleter implements TabCompleter {
|
||||||
return graphSuggestions;
|
return graphSuggestions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return List.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ public class Setting {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
SettingGUI gui = new SettingGUI(player);
|
SettingGUI gui = new SettingGUI(player);
|
||||||
gui.open();
|
gui.open();
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
String settingName = args[1].toLowerCase();
|
String settingName = args[1].toLowerCase();
|
||||||
PlayerMetadata playerMetadata = PlayerMetadata.getPlayerMetadata(player);
|
PlayerMetadata playerMetadata = PlayerMetadata.getPlayerMetadata(player);
|
||||||
|
|
@ -28,7 +27,7 @@ public class Setting {
|
||||||
}
|
}
|
||||||
|
|
||||||
playerMetadata.saveToPDS();
|
playerMetadata.saveToPDS();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,12 @@ public enum ConfigKey {
|
||||||
AFK_ANNOUNCEMENT_ENABLED("afk_announcement_enabled", true),
|
AFK_ANNOUNCEMENT_ENABLED("afk_announcement_enabled", true),
|
||||||
CLEAR_INVENTORY_ON_DEATH("clear_inventory_on_death", false),
|
CLEAR_INVENTORY_ON_DEATH("clear_inventory_on_death", false),
|
||||||
MAX_HISTORICAL_INVENTORIES("max_historical_inventories", 20),
|
MAX_HISTORICAL_INVENTORIES("max_historical_inventories", 20),
|
||||||
LOGIN_LOGGER_ENABLED("login_logger_enabled", true);
|
LOGIN_LOGGER_ENABLED("login_logger_enabled", true),
|
||||||
|
LEVELLED_MOBS_ENABLED("levelled_mobs_enabled", true),
|
||||||
|
LEVELLED_MOBS_SEARCH_RADIUS("levelled_mobs_search_radius", 50),
|
||||||
|
LEVELLED_MOBS_HEALTH_DIVISOR("levelled_mobs_health_divisor", 25.0),
|
||||||
|
LEVELLED_MOBS_ARMOR_DIVISOR("levelled_mobs_armor_divisor", 2.0),
|
||||||
|
LEVELLED_MOBS_BLACKLIST("levelled_mobs_blacklist", new ArrayList<String>());
|
||||||
|
|
||||||
private final String key;
|
private final String key;
|
||||||
private final Object defaultValue;
|
private final Object defaultValue;
|
||||||
|
|
@ -56,8 +61,4 @@ public enum ConfigKey {
|
||||||
return this.defaultValue;
|
return this.defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// $FF: synthetic method
|
|
||||||
private static ConfigKey[] $values() {
|
|
||||||
return new ConfigKey[]{MODULE_JOBS, MODULE_FACTIONS, MODULE_MARKET, MODULE_LEADERBOARD, DISABLED_COMMANDS, MODULE_CHAT, MODULE_HOMES, MODULE_LEVELING, MODULE_TITLES, MODULE_RELICS, MODULE_EVENTS, MODULE_UTILS, MODULE_RANKS, JOIN_MESSAGE, MODULE_DIMENSIONS, DISABLED_DIMENSIONS, BANNED_WORDS, FORCE_DISABLE_BC, FORCE_AUTH, MARKET_GUI_ENABLED, MARKET_RIPOFF_MULTIPLIER, MARKET_MIN_PRICE, MARKET_PRICE_REFRESH_INTERVAL, LOG_LEVEL};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,21 @@
|
||||||
package org.gsdistance.grimmsServer.Constructable.Entity;
|
package org.gsdistance.grimmsServer.Constructable.Entity;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.gsdistance.grimmsServer.Config.ActiveConfig;
|
import org.gsdistance.grimmsServer.Config.ActiveConfig;
|
||||||
import org.gsdistance.grimmsServer.Config.ConfigKey;
|
import org.gsdistance.grimmsServer.Config.ConfigKey;
|
||||||
import org.gsdistance.grimmsServer.Constructable.Data;
|
import org.gsdistance.grimmsServer.Constructable.Data;
|
||||||
|
import org.gsdistance.grimmsServer.Constructable.Player.PlayerLevelHandler;
|
||||||
import org.gsdistance.grimmsServer.Data.PerSessionDataStorage;
|
import org.gsdistance.grimmsServer.Data.PerSessionDataStorage;
|
||||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
|
@ -53,11 +60,19 @@ public class EntityMetadata {
|
||||||
if ("Verbose".equalsIgnoreCase(logLevel)) {
|
if ("Verbose".equalsIgnoreCase(logLevel)) {
|
||||||
GrimmsServer.logger.info("Created new EntityMetadata for " + entity.getUniqueId());
|
GrimmsServer.logger.info("Created new EntityMetadata for " + entity.getUniqueId());
|
||||||
}
|
}
|
||||||
|
// Apply levelling when metadata is first created
|
||||||
|
if (entity instanceof LivingEntity) {
|
||||||
|
applyLevelling((LivingEntity) entity, metadata);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
String logLevel = ActiveConfig.getConfigValue(ConfigKey.LOG_LEVEL, String.class);
|
String logLevel = ActiveConfig.getConfigValue(ConfigKey.LOG_LEVEL, String.class);
|
||||||
if ("Verbose".equalsIgnoreCase(logLevel)) {
|
if ("Verbose".equalsIgnoreCase(logLevel)) {
|
||||||
GrimmsServer.logger.info("Retrieved EntityMetadata for " + entity.getUniqueId());
|
GrimmsServer.logger.info("Retrieved EntityMetadata for " + entity.getUniqueId());
|
||||||
}
|
}
|
||||||
|
// Re-apply levelling when metadata is loaded (e.g., after chunk reload)
|
||||||
|
if (entity instanceof LivingEntity && metadata.level > 1) {
|
||||||
|
applyLevelling((LivingEntity) entity, metadata);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PerSessionDataStorage.dataStore.put("entityMetadata-" + entity.getUniqueId(), Data.of(metadata, EntityMetadata.class));
|
PerSessionDataStorage.dataStore.put("entityMetadata-" + entity.getUniqueId(), Data.of(metadata, EntityMetadata.class));
|
||||||
|
|
@ -66,4 +81,114 @@ public class EntityMetadata {
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String generateHealthBar(double currentHealth, double maxHealth) {
|
||||||
|
if (maxHealth <= 0) return "";
|
||||||
|
|
||||||
|
int bars = 10;
|
||||||
|
double healthPercent = currentHealth / maxHealth;
|
||||||
|
int filledBars = (int) Math.round(healthPercent * bars);
|
||||||
|
|
||||||
|
ChatColor barColor;
|
||||||
|
if (healthPercent > 0.6) {
|
||||||
|
barColor = ChatColor.GREEN;
|
||||||
|
} else if (healthPercent > 0.3) {
|
||||||
|
barColor = ChatColor.YELLOW;
|
||||||
|
} else {
|
||||||
|
barColor = ChatColor.RED;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder healthBar = new StringBuilder(barColor.toString());
|
||||||
|
healthBar.append("[");
|
||||||
|
for (int i = 0; i < bars; i++) {
|
||||||
|
if (i < filledBars) {
|
||||||
|
healthBar.append("|");
|
||||||
|
} else {
|
||||||
|
healthBar.append(ChatColor.GRAY).append("|").append(barColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
healthBar.append("]");
|
||||||
|
|
||||||
|
return healthBar.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void applyLevelling(LivingEntity livingEntity, EntityMetadata metadata) {
|
||||||
|
Boolean enabled = ActiveConfig.getConfigValue(ConfigKey.LEVELLED_MOBS_ENABLED, Boolean.class);
|
||||||
|
if (enabled == null || !enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check blacklist
|
||||||
|
List<String> blacklist = ActiveConfig.getConfigValue(ConfigKey.LEVELLED_MOBS_BLACKLIST, List.class);
|
||||||
|
if (blacklist != null && blacklist.contains(livingEntity.getType().name())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate level based on nearby players
|
||||||
|
int totalLevel = 0;
|
||||||
|
List<Player> nearbyPlayers = new ArrayList<>();
|
||||||
|
Integer searchRadius = ActiveConfig.getConfigValue(ConfigKey.LEVELLED_MOBS_SEARCH_RADIUS, Integer.class);
|
||||||
|
if (searchRadius == null) searchRadius = 50;
|
||||||
|
|
||||||
|
for (Entity entity : livingEntity.getNearbyEntities(searchRadius, searchRadius, searchRadius)) {
|
||||||
|
if (entity instanceof Player) {
|
||||||
|
nearbyPlayers.add((Player) entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Player player : nearbyPlayers) {
|
||||||
|
totalLevel += PlayerLevelHandler.getLevelHandler(player).getLevel();
|
||||||
|
}
|
||||||
|
|
||||||
|
double randomness = Math.sqrt(totalLevel);
|
||||||
|
double randomOffset = (Math.random() * 2 * randomness) - randomness;
|
||||||
|
int finalLevel = (int) Math.max(1, Math.round(totalLevel + randomOffset));
|
||||||
|
|
||||||
|
metadata.level = finalLevel;
|
||||||
|
|
||||||
|
// Apply attribute modifiers
|
||||||
|
if (livingEntity.getAttribute(Attribute.MAX_HEALTH) != null) {
|
||||||
|
double baseHealth = livingEntity.getAttribute(Attribute.MAX_HEALTH).getBaseValue();
|
||||||
|
Double healthDivisor = ActiveConfig.getConfigValue(ConfigKey.LEVELLED_MOBS_HEALTH_DIVISOR, Double.class);
|
||||||
|
if (healthDivisor == null) healthDivisor = 25.0;
|
||||||
|
double healthBoost = baseHealth * (finalLevel / healthDivisor);
|
||||||
|
livingEntity.getAttribute(Attribute.MAX_HEALTH).setBaseValue(baseHealth + healthBoost);
|
||||||
|
livingEntity.setHealth(livingEntity.getAttribute(Attribute.MAX_HEALTH).getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (livingEntity.getAttribute(Attribute.ARMOR) != null) {
|
||||||
|
Double armorDivisor = ActiveConfig.getConfigValue(ConfigKey.LEVELLED_MOBS_ARMOR_DIVISOR, Double.class);
|
||||||
|
if (armorDivisor == null) armorDivisor = 2.0;
|
||||||
|
double armorBoost = Math.sqrt(finalLevel) / armorDivisor;
|
||||||
|
livingEntity.getAttribute(Attribute.ARMOR).setBaseValue(armorBoost);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (livingEntity.getAttribute(Attribute.ATTACK_DAMAGE) != null) {
|
||||||
|
double damageBoost = Math.cbrt(finalLevel);
|
||||||
|
livingEntity.getAttribute(Attribute.ATTACK_DAMAGE).setBaseValue(
|
||||||
|
livingEntity.getAttribute(Attribute.ATTACK_DAMAGE).getBaseValue() + damageBoost
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set custom name with level and health bar
|
||||||
|
ChatColor levelColor;
|
||||||
|
if (finalLevel < 10) {
|
||||||
|
levelColor = ChatColor.GREEN;
|
||||||
|
} else if (finalLevel < 25) {
|
||||||
|
levelColor = ChatColor.YELLOW;
|
||||||
|
} else if (finalLevel < 50) {
|
||||||
|
levelColor = ChatColor.GOLD;
|
||||||
|
} else if (finalLevel < 75) {
|
||||||
|
levelColor = ChatColor.RED;
|
||||||
|
} else {
|
||||||
|
levelColor = ChatColor.DARK_RED;
|
||||||
|
}
|
||||||
|
|
||||||
|
double maxHealth = livingEntity.getAttribute(Attribute.MAX_HEALTH).getValue();
|
||||||
|
String healthBar = generateHealthBar(livingEntity.getHealth(), maxHealth);
|
||||||
|
|
||||||
|
metadata.originalName = livingEntity.getName();
|
||||||
|
String displayName = levelColor + "[" + finalLevel + "] " + ChatColor.WHITE + metadata.originalName + " " + healthBar;
|
||||||
|
livingEntity.setCustomName(displayName);
|
||||||
|
livingEntity.setCustomNameVisible(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,120 +1,18 @@
|
||||||
package org.gsdistance.grimmsServer.Events.Listeners;
|
package org.gsdistance.grimmsServer.Events.Listeners;
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import org.bukkit.attribute.Attribute;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.gsdistance.grimmsServer.Constructable.Entity.EntityMetadata;
|
import org.gsdistance.grimmsServer.Constructable.Entity.EntityMetadata;
|
||||||
import org.gsdistance.grimmsServer.Constructable.Player.PlayerLevelHandler;
|
|
||||||
import org.gsdistance.grimmsServer.Manage.CustomEntityManager;
|
import org.gsdistance.grimmsServer.Manage.CustomEntityManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class EntitySpawnEvent {
|
public class EntitySpawnEvent {
|
||||||
public EntitySpawnEvent() {
|
public EntitySpawnEvent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String generateHealthBar(double currentHealth, double maxHealth) {
|
|
||||||
if (maxHealth <= 0) return "";
|
|
||||||
|
|
||||||
int bars = 10;
|
|
||||||
double healthPercent = currentHealth / maxHealth;
|
|
||||||
int filledBars = (int) Math.round(healthPercent * bars);
|
|
||||||
|
|
||||||
ChatColor barColor;
|
|
||||||
if (healthPercent > 0.6) {
|
|
||||||
barColor = ChatColor.GREEN;
|
|
||||||
} else if (healthPercent > 0.3) {
|
|
||||||
barColor = ChatColor.YELLOW;
|
|
||||||
} else {
|
|
||||||
barColor = ChatColor.RED;
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder healthBar = new StringBuilder(barColor.toString());
|
|
||||||
healthBar.append("[");
|
|
||||||
for (int i = 0; i < bars; i++) {
|
|
||||||
if (i < filledBars) {
|
|
||||||
healthBar.append("|");
|
|
||||||
} else {
|
|
||||||
healthBar.append(ChatColor.GRAY).append("|").append(barColor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
healthBar.append("]");
|
|
||||||
|
|
||||||
return healthBar.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Event(org.bukkit.event.entity.EntitySpawnEvent event) {
|
public static void Event(org.bukkit.event.entity.EntitySpawnEvent event) {
|
||||||
if (event.getEntity().getType() != EntityType.PLAYER) {
|
if (event.getEntity().getType() != EntityType.PLAYER) {
|
||||||
CustomEntityManager.registerEntity(event.getEntity());
|
CustomEntityManager.registerEntity(event.getEntity());
|
||||||
EntityMetadata metadata = EntityMetadata.getEntityMetadata(event.getEntity());
|
// Leveling is now applied in EntityMetadata.getEntityMetadata()
|
||||||
|
EntityMetadata.getEntityMetadata(event.getEntity());
|
||||||
int totalLevel = 0;
|
|
||||||
List<Player> nearbyPlayers = new ArrayList<>();
|
|
||||||
for (Entity entity : event.getEntity().getNearbyEntities(50, 50, 50)) {
|
|
||||||
if (entity instanceof Player) {
|
|
||||||
nearbyPlayers.add((Player) entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (Player player : nearbyPlayers) {
|
|
||||||
totalLevel += PlayerLevelHandler.getLevelHandler(player).getLevel();
|
|
||||||
}
|
|
||||||
|
|
||||||
double randomness = Math.sqrt(totalLevel);
|
|
||||||
double randomOffset = (Math.random() * 2 * randomness) - randomness;
|
|
||||||
int finalLevel = (int) Math.max(1, Math.round(totalLevel + randomOffset));
|
|
||||||
|
|
||||||
metadata.level = finalLevel;
|
|
||||||
|
|
||||||
if (event.getEntity() instanceof LivingEntity livingEntity) {
|
|
||||||
|
|
||||||
if (livingEntity.getAttribute(Attribute.MAX_HEALTH) != null) {
|
|
||||||
double baseHealth = livingEntity.getAttribute(Attribute.MAX_HEALTH).getBaseValue();
|
|
||||||
double healthBoost = baseHealth * (finalLevel / 25.0);
|
|
||||||
livingEntity.getAttribute(Attribute.MAX_HEALTH).setBaseValue(baseHealth + healthBoost);
|
|
||||||
livingEntity.setHealth(livingEntity.getAttribute(Attribute.MAX_HEALTH).getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (livingEntity.getAttribute(Attribute.ARMOR) != null) {
|
|
||||||
double armorBoost = Math.sqrt(finalLevel) / 2.0;
|
|
||||||
livingEntity.getAttribute(Attribute.ARMOR).setBaseValue(armorBoost);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (livingEntity.getAttribute(Attribute.ATTACK_DAMAGE) != null) {
|
|
||||||
double damageBoost = Math.cbrt(finalLevel);
|
|
||||||
livingEntity.getAttribute(Attribute.ATTACK_DAMAGE).setBaseValue(
|
|
||||||
livingEntity.getAttribute(Attribute.ATTACK_DAMAGE).getBaseValue() + damageBoost
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
ChatColor levelColor;
|
|
||||||
if (finalLevel < 10) {
|
|
||||||
levelColor = ChatColor.GREEN;
|
|
||||||
} else if (finalLevel < 25) {
|
|
||||||
levelColor = ChatColor.YELLOW;
|
|
||||||
} else if (finalLevel < 50) {
|
|
||||||
levelColor = ChatColor.GOLD;
|
|
||||||
} else if (finalLevel < 75) {
|
|
||||||
levelColor = ChatColor.RED;
|
|
||||||
} else {
|
|
||||||
levelColor = ChatColor.DARK_RED;
|
|
||||||
}
|
|
||||||
|
|
||||||
double maxHealth = livingEntity.getAttribute(Attribute.MAX_HEALTH).getValue();
|
|
||||||
String healthBar = generateHealthBar(livingEntity.getHealth(), maxHealth);
|
|
||||||
|
|
||||||
livingEntity.setCustomName(null);
|
|
||||||
metadata.originalName = livingEntity.getName();
|
|
||||||
String displayName = levelColor + "[" + finalLevel + "] " + ChatColor.WHITE + metadata.originalName + " " + healthBar;
|
|
||||||
livingEntity.setCustomName(displayName);
|
|
||||||
livingEntity.setCustomNameVisible(true);
|
|
||||||
livingEntity.setPersistent(false);
|
|
||||||
|
|
||||||
livingEntity.setMetadata("customEntityLevel", new org.bukkit.metadata.FixedMetadataValue(org.gsdistance.grimmsServer.GrimmsServer.instance, finalLevel));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,12 @@ package org.gsdistance.grimmsServer.Manage;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
public class CustomEntityManager {
|
public class CustomEntityManager {
|
||||||
public static final List<UUID> currentRegistry = new ArrayList<>();
|
public static final List<UUID> currentRegistry = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
public CustomEntityManager() {
|
public CustomEntityManager() {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package org.gsdistance.grimmsServer;
|
package org.gsdistance.grimmsServer;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
|
|
@ -12,6 +13,7 @@ import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
|
@ -47,8 +49,43 @@ public class Shared {
|
||||||
|
|
||||||
public static void updateResource(String resourcePath, boolean isDirectory) {
|
public static void updateResource(String resourcePath, boolean isDirectory) {
|
||||||
GrimmsServer.logger.info("Updating resource: " + resourcePath);
|
GrimmsServer.logger.info("Updating resource: " + resourcePath);
|
||||||
File embedFolder = new File(GrimmsServer.instance.getDataFolder(), resourcePath);
|
File targetFolder = new File(GrimmsServer.instance.getDataFolder(), resourcePath);
|
||||||
deleteDirectoryRecursively(embedFolder);
|
|
||||||
|
if (isDirectory) {
|
||||||
|
// Get list of files in JAR for this resource path
|
||||||
|
java.util.Set<String> jarFiles = new java.util.HashSet<>();
|
||||||
|
try {
|
||||||
|
String jarPath = GrimmsServer.instance.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
|
||||||
|
try (JarFile jarFile = new JarFile(jarPath)) {
|
||||||
|
jarFile.stream().filter(entry -> entry.getName().startsWith(resourcePath) && !entry.isDirectory()).forEach(entry -> {
|
||||||
|
String relativePath = entry.getName().substring(resourcePath.length() + 1);
|
||||||
|
jarFiles.add(relativePath);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
GrimmsServer.logger.warning("Failed to read JAR files for update: " + resourcePath);
|
||||||
|
GrimmsServer.logger.warning("Error: " + e.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only delete files that exist in the JAR (auto-generated)
|
||||||
|
if (targetFolder.exists() && targetFolder.isDirectory()) {
|
||||||
|
File[] files = targetFolder.listFiles();
|
||||||
|
if (files != null) {
|
||||||
|
for (File file : files) {
|
||||||
|
if (jarFiles.contains(file.getName())) {
|
||||||
|
deleteDirectoryRecursively(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// For single files, delete if it exists
|
||||||
|
if (targetFolder.exists()) {
|
||||||
|
targetFolder.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
saveResourceIfNotExists(resourcePath, isDirectory);
|
saveResourceIfNotExists(resourcePath, isDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -129,4 +166,26 @@ public class Shared {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<String> getOnlinePlayers(String partialPlayer, List<String> playerSuggestions) {
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (player.getName().toLowerCase().startsWith(partialPlayer)) {
|
||||||
|
playerSuggestions.add(player.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (org.bukkit.OfflinePlayer offlinePlayer : Bukkit.getOfflinePlayers()) {
|
||||||
|
if (offlinePlayer.hasPlayedBefore() &&
|
||||||
|
offlinePlayer.getName() != null &&
|
||||||
|
offlinePlayer.getName().toLowerCase().startsWith(partialPlayer) &&
|
||||||
|
!playerSuggestions.contains(offlinePlayer.getName())) {
|
||||||
|
UUID uuid = offlinePlayer.getUniqueId();
|
||||||
|
if (org.gsdistance.grimmsServer.Constructable.Player.PlayerMetadata.getOfflinePlayerMetadata(uuid) != null) {
|
||||||
|
playerSuggestions.add(offlinePlayer.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return playerSuggestions;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue