Add champion mobs
This commit is contained in:
parent
5135a0ec47
commit
fb8a41fb81
49 changed files with 762 additions and 216 deletions
Binary file not shown.
Binary file not shown.
20
build.gradle
20
build.gradle
|
|
@ -3,7 +3,7 @@ plugins {
|
|||
}
|
||||
|
||||
group = 'org.gsdistance'
|
||||
version = '1.5.6'
|
||||
version = '1.5.7'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
|
@ -50,7 +50,7 @@ processResources {
|
|||
}
|
||||
|
||||
// Custom task to clean only jar files before build
|
||||
task cleanJars(type: Delete) {
|
||||
tasks.register('cleanJars', Delete) {
|
||||
delete fileTree('build/libs') {
|
||||
include '*.jar'
|
||||
exclude "${project.name}-${version}.jar"
|
||||
|
|
@ -58,5 +58,19 @@ task cleanJars(type: Delete) {
|
|||
}
|
||||
|
||||
// Run cleanJars before every build
|
||||
build.dependsOn cleanJars
|
||||
build.dependsOn 'cleanJars'
|
||||
|
||||
// Custom task to increment build.v on every build
|
||||
tasks.register('incrementBuildVersion') {
|
||||
doLast {
|
||||
def buildFile = file('src/main/resources/build.v')
|
||||
def currentVersion = buildFile.text.trim().toInteger()
|
||||
def newVersion = currentVersion + 1
|
||||
buildFile.text = newVersion.toString()
|
||||
println "Build version incremented to: ${newVersion}"
|
||||
}
|
||||
}
|
||||
|
||||
// Run incrementBuildVersion before every build
|
||||
build.dependsOn 'incrementBuildVersion'
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -28,19 +28,19 @@ public class New {
|
|||
} else {
|
||||
String factionId = args[1];
|
||||
String factionName = args[2];
|
||||
|
||||
|
||||
// Validate faction ID length
|
||||
if (factionId.length() < 3 || factionId.length() > 16) {
|
||||
player.sendMessage(ChatColor.RED + "Faction id must be between 3 and 16 characters.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Validate faction name length
|
||||
if (factionName.length() < 2 || factionName.length() > 32) {
|
||||
player.sendMessage(ChatColor.RED + "Faction name must be between 2 and 32 characters.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Faction[] factions = GrimmsServer.pds.retrieveAllData(Faction.class, "factions");
|
||||
if (factions != null && Arrays.stream(factions).anyMatch((factionx) -> factionx.id.equalsIgnoreCase(factionId))) {
|
||||
player.sendMessage(ChatColor.RED + "Faction already exists with this id.");
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class Enchant {
|
|||
|
||||
String action = args[1].toLowerCase();
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
|
||||
|
||||
if (item == null || item.getType().isAir()) {
|
||||
player.sendMessage(ChatColor.RED + "You must hold an item in your main hand.");
|
||||
return false;
|
||||
|
|
@ -43,7 +43,7 @@ public class Enchant {
|
|||
|
||||
CustomEnchantmentHandler handler = CustomEnchantmentHandler.getHandler(item);
|
||||
if (handler.addEnchantment(enchantment, level)) {
|
||||
player.sendMessage(ChatColor.GREEN + "Added " + ChatColor.GOLD + enchantment.enchantmentName +
|
||||
player.sendMessage(ChatColor.GREEN + "Added " + ChatColor.GOLD + enchantment.enchantmentName +
|
||||
ChatColor.GREEN + " level " + ChatColor.YELLOW + level + ChatColor.GREEN + " to " + item.getType());
|
||||
return true;
|
||||
} else {
|
||||
|
|
@ -94,7 +94,7 @@ public class Enchant {
|
|||
|
||||
CustomEnchantmentHandler handler = CustomEnchantmentHandler.getHandler(item);
|
||||
if (handler.setEnchantmentLevel(enchantment, level)) {
|
||||
player.sendMessage(ChatColor.GREEN + "Set " + ChatColor.GOLD + enchantment.enchantmentName +
|
||||
player.sendMessage(ChatColor.GREEN + "Set " + ChatColor.GOLD + enchantment.enchantmentName +
|
||||
ChatColor.GREEN + " to level " + ChatColor.YELLOW + level + ChatColor.GREEN + " on " + item.getType());
|
||||
return true;
|
||||
} else {
|
||||
|
|
@ -121,7 +121,7 @@ public class Enchant {
|
|||
|
||||
player.sendMessage(ChatColor.GOLD + "Custom Enchantments on " + item.getType() + ":");
|
||||
for (Map.Entry<CustomEnchantment, Integer> entry : enchantments.entrySet()) {
|
||||
player.sendMessage(ChatColor.YELLOW + "- " + entry.getKey().enchantmentName +
|
||||
player.sendMessage(ChatColor.YELLOW + "- " + entry.getKey().enchantmentName +
|
||||
ChatColor.GRAY + " (Level " + entry.getValue() + "/" + entry.getKey().maxLevel + ")");
|
||||
}
|
||||
return true;
|
||||
|
|
@ -143,10 +143,10 @@ public class Enchant {
|
|||
try {
|
||||
CustomEnchantment enchantment = CustomEnchantment.valueOf(args[2].toUpperCase());
|
||||
CustomEnchantmentHandler handler = CustomEnchantmentHandler.getHandler(item);
|
||||
|
||||
|
||||
if (handler.hasEnchantment(enchantment)) {
|
||||
int level = handler.getEnchantmentLevel(enchantment);
|
||||
player.sendMessage(ChatColor.GREEN + "Item has " + ChatColor.GOLD + enchantment.enchantmentName +
|
||||
player.sendMessage(ChatColor.GREEN + "Item has " + ChatColor.GOLD + enchantment.enchantmentName +
|
||||
ChatColor.GREEN + " at level " + ChatColor.YELLOW + level);
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "Item does not have " + enchantment.enchantmentName);
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class Fly {
|
|||
|
||||
targetPlayer.setAllowFlight(enable);
|
||||
targetPlayer.setFlying(enable);
|
||||
|
||||
|
||||
if (targetPlayer == sender) {
|
||||
targetPlayer.sendMessage(ChatColor.GREEN + "Fly mode " + (enable ? "enabled" : "disabled") + ".");
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -115,6 +115,12 @@ public class GUtilBaseCommand implements CommandExecutor {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
case "spawnchampion" -> {
|
||||
if (sender instanceof Player player) {
|
||||
return SpawnChampion.subCommand(player, args);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case "sudo" -> {
|
||||
return Sudo.subCommand(sender, args);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import java.util.stream.Stream;
|
|||
|
||||
public class GUtilTabCompleter implements TabCompleter {
|
||||
public static final List<String> defSubCommands = List.of("version", "setting", "spawn");
|
||||
public static final List<String> adminSubCommands = List.of("relic", "enchant", "givecustomitem", "capability", "broadcast", "inventoryrestore", "fly", "god", "heal", "speed", "enderchest", "invsee", "addtitle", "removetitle", "unlevelentity", "sudo", "levelentity");
|
||||
public static final List<String> adminSubCommands = List.of("relic", "enchant", "givecustomitem", "capability", "broadcast", "inventoryrestore", "fly", "god", "heal", "speed", "enderchest", "invsee", "addtitle", "removetitle", "unlevelentity", "sudo", "levelentity", "spawnchampion");
|
||||
|
||||
private CommandMap cachedCommandMap;
|
||||
|
||||
|
|
@ -93,7 +93,8 @@ public class GUtilTabCompleter implements TabCompleter {
|
|||
case "setting" -> {
|
||||
return PlayerMetadata.getPlayerMetadata(player).settings.stream().toList();
|
||||
}
|
||||
case "inventoryrestore", "heal", "spawn", "enderchest", "invsee", "addtitle", "removetitle", "sudo", "fly", "god" -> {
|
||||
case "inventoryrestore", "heal", "spawn", "enderchest", "invsee", "addtitle", "removetitle", "sudo",
|
||||
"fly", "god" -> {
|
||||
return Bukkit.getOnlinePlayers().stream()
|
||||
.map(Player::getName)
|
||||
.filter(name -> name.toLowerCase().startsWith(args[1].toLowerCase()))
|
||||
|
|
@ -110,6 +111,13 @@ public class GUtilTabCompleter implements TabCompleter {
|
|||
.filter(uuid -> uuid.toLowerCase().startsWith(args[1].toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
case "spawnchampion" -> {
|
||||
return java.util.Arrays.stream(org.bukkit.entity.EntityType.values())
|
||||
.filter(type -> type.isSpawnable() && type.isAlive())
|
||||
.map(type -> type.name().toLowerCase())
|
||||
.filter(name -> name.startsWith(args[1].toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
default -> {
|
||||
return List.of();
|
||||
}
|
||||
|
|
@ -131,8 +139,8 @@ public class GUtilTabCompleter implements TabCompleter {
|
|||
} else if (args.length == 3) {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "enchant" -> {
|
||||
if (args[1].equalsIgnoreCase("add") || args[1].equalsIgnoreCase("remove") ||
|
||||
args[1].equalsIgnoreCase("set") || args[1].equalsIgnoreCase("has")) {
|
||||
if (args[1].equalsIgnoreCase("add") || args[1].equalsIgnoreCase("remove") ||
|
||||
args[1].equalsIgnoreCase("set") || args[1].equalsIgnoreCase("has")) {
|
||||
return java.util.Arrays.stream(CustomEnchantment.values())
|
||||
.map(enchant -> enchant.name().toLowerCase())
|
||||
.filter(name -> name.startsWith(args[2].toLowerCase()))
|
||||
|
|
@ -207,6 +215,15 @@ public class GUtilTabCompleter implements TabCompleter {
|
|||
.filter(option -> option.startsWith(args[2].toLowerCase()))
|
||||
.toList();
|
||||
}
|
||||
case "spawnchampion" -> {
|
||||
List<String> tiers = new ArrayList<>();
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
tiers.add(String.valueOf(i));
|
||||
}
|
||||
return tiers.stream()
|
||||
.filter(tier -> tier.startsWith(args[2]))
|
||||
.toList();
|
||||
}
|
||||
default -> {
|
||||
return List.of();
|
||||
}
|
||||
|
|
@ -242,12 +259,30 @@ public class GUtilTabCompleter implements TabCompleter {
|
|||
}
|
||||
return List.of();
|
||||
}
|
||||
case "spawnchampion" -> {
|
||||
List<String> levels = new ArrayList<>();
|
||||
for (int i = 1; i <= 100; i++) {
|
||||
levels.add(String.valueOf(i));
|
||||
}
|
||||
return levels.stream()
|
||||
.filter(level -> level.startsWith(args[3]))
|
||||
.toList();
|
||||
}
|
||||
default -> {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
} else if (args.length == 5) {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "spawnchampion" -> {
|
||||
List<String> prestiges = new ArrayList<>();
|
||||
for (int i = 1; i <= 10; i++) {
|
||||
prestiges.add(String.valueOf(i));
|
||||
}
|
||||
return prestiges.stream()
|
||||
.filter(prestige -> prestige.startsWith(args[4]))
|
||||
.toList();
|
||||
}
|
||||
case "relic" -> {
|
||||
if (args[1].equalsIgnoreCase("set")) {
|
||||
List<String> resistances = new ArrayList<>();
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class GiveCustomItem {
|
|||
}
|
||||
|
||||
String itemId = args[1].toLowerCase();
|
||||
|
||||
|
||||
// Check if the custom item is registered
|
||||
if (!CustomItemRegistry.isCustomItemRegistered(itemId)) {
|
||||
player.sendMessage(ChatColor.RED + "Custom item '" + itemId + "' is not registered.");
|
||||
|
|
@ -54,15 +54,15 @@ public class GiveCustomItem {
|
|||
if (itemStack.getItemMeta() == null) {
|
||||
itemStack.setItemMeta(org.bukkit.Bukkit.getItemFactory().getItemMeta(material));
|
||||
}
|
||||
|
||||
|
||||
// Initialize the item with CustomItemHandler first
|
||||
CustomItemHandler.createHandler(itemStack);
|
||||
|
||||
|
||||
CustomItemRegistry.createCustomItem(itemId, itemStack);
|
||||
|
||||
|
||||
// Update item stats to show proper display name and description
|
||||
ItemStats.getItemStats(itemStack).UpdateItemStats();
|
||||
|
||||
|
||||
// Give item to player
|
||||
player.getInventory().addItem(itemStack);
|
||||
player.sendMessage(ChatColor.GREEN + "Given custom item: " + ChatColor.GOLD + itemId);
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public class God {
|
|||
}
|
||||
|
||||
targetPlayer.setInvulnerable(enable);
|
||||
|
||||
|
||||
if (targetPlayer == sender) {
|
||||
targetPlayer.sendMessage(ChatColor.GREEN + "God mode " + (enable ? "enabled" : "disabled") + ".");
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public class InventoryRestore {
|
|||
}
|
||||
|
||||
PlayerInventoryData.InventorySnapshot snapshot = inventoryData.previousInventories.get(index);
|
||||
|
||||
|
||||
// Restore inventory to target player
|
||||
targetPlayer.getInventory().clear();
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,27 @@ public class LevelEntity {
|
|||
}
|
||||
|
||||
if (sender instanceof Player player) {
|
||||
// Parse optional level and prestige parameters
|
||||
Integer specifiedLevel = null;
|
||||
Integer specifiedPrestige = null;
|
||||
|
||||
if (args.length >= 3) {
|
||||
try {
|
||||
specifiedLevel = Integer.parseInt(args[2]);
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage(ChatColor.RED + "Invalid level: " + args[2]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (args.length >= 4) {
|
||||
try {
|
||||
specifiedPrestige = Integer.parseInt(args[3]);
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage(ChatColor.RED + "Invalid prestige: " + args[3]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length < 2) {
|
||||
// Force leveling on entity player is looking at
|
||||
RayTraceResult rayTrace = player.getWorld().rayTraceEntities(player.getEyeLocation(), player.getEyeLocation().getDirection(), 5);
|
||||
|
|
@ -26,7 +47,7 @@ public class LevelEntity {
|
|||
sender.sendMessage(ChatColor.RED + "No entity found in range (5 blocks). Specify an entity UUID or look at an entity.");
|
||||
return false;
|
||||
}
|
||||
return applyLeveling(sender, targetEntity);
|
||||
return applyLeveling(sender, targetEntity, specifiedLevel, specifiedPrestige);
|
||||
} else {
|
||||
// Force leveling by UUID
|
||||
try {
|
||||
|
|
@ -42,7 +63,7 @@ public class LevelEntity {
|
|||
sender.sendMessage(ChatColor.RED + "Entity with UUID " + args[1] + " not found in current world.");
|
||||
return false;
|
||||
}
|
||||
return applyLeveling(sender, targetEntity);
|
||||
return applyLeveling(sender, targetEntity, specifiedLevel, specifiedPrestige);
|
||||
} catch (IllegalArgumentException e) {
|
||||
sender.sendMessage(ChatColor.RED + "Invalid UUID format: " + args[1]);
|
||||
return false;
|
||||
|
|
@ -54,26 +75,35 @@ public class LevelEntity {
|
|||
}
|
||||
}
|
||||
|
||||
private static boolean applyLeveling(CommandSender sender, Entity entity) {
|
||||
private static boolean applyLeveling(CommandSender sender, Entity entity, Integer specifiedLevel, Integer specifiedPrestige) {
|
||||
// Register entity in the registry
|
||||
CustomEntityManager.registerEntity(entity);
|
||||
|
||||
|
||||
// Get or create metadata and apply leveling
|
||||
EntityMetadata metadata = EntityMetadata.getEntityMetadata(entity);
|
||||
|
||||
|
||||
// Override level/prestige if specified
|
||||
if (specifiedLevel != null) {
|
||||
metadata.level = specifiedLevel;
|
||||
}
|
||||
if (specifiedPrestige != null) {
|
||||
metadata.prestige = specifiedPrestige;
|
||||
}
|
||||
|
||||
if (entity instanceof LivingEntity livingEntity) {
|
||||
// Force re-apply leveling even if already leveled
|
||||
if (metadata.level > 1 || metadata.prestige > 1) {
|
||||
// Re-apply to refresh stats
|
||||
try {
|
||||
java.lang.reflect.Method applyLevelling = EntityMetadata.class.getDeclaredMethod("applyLevelling", LivingEntity.class, EntityMetadata.class);
|
||||
applyLevelling.setAccessible(true);
|
||||
applyLevelling.invoke(null, livingEntity, metadata);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Warning: Could not re-apply leveling via reflection.");
|
||||
}
|
||||
try {
|
||||
java.lang.reflect.Method applyLevelling = EntityMetadata.class.getDeclaredMethod("applyLevelling", LivingEntity.class, EntityMetadata.class);
|
||||
applyLevelling.setAccessible(true);
|
||||
applyLevelling.invoke(null, livingEntity, metadata);
|
||||
// Save attribute values after applying
|
||||
java.lang.reflect.Method saveAttributeValues = EntityMetadata.class.getDeclaredMethod("saveAttributeValues", LivingEntity.class, EntityMetadata.class);
|
||||
saveAttributeValues.setAccessible(true);
|
||||
saveAttributeValues.invoke(null, livingEntity, metadata);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Warning: Could not re-apply leveling via reflection.");
|
||||
}
|
||||
|
||||
|
||||
sender.sendMessage(ChatColor.GREEN + "Forced leveling on entity: " + entity.getType().name() + " (Level: " + metadata.level + ", Prestige: " + metadata.prestige + ")");
|
||||
return true;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,167 @@
|
|||
package org.gsdistance.grimmsServer.Commands.GUtilCommand;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Constructable.Data;
|
||||
import org.gsdistance.grimmsServer.Constructable.Entity.EntityAbility;
|
||||
import org.gsdistance.grimmsServer.Constructable.Entity.EntityAffix;
|
||||
import org.gsdistance.grimmsServer.Constructable.Entity.EntityMetadata;
|
||||
import org.gsdistance.grimmsServer.Manage.CustomEntityManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SpawnChampion {
|
||||
|
||||
public static boolean subCommand(CommandSender sender, String[] args) {
|
||||
if (!sender.hasPermission("grimmsserver.util.admin")) {
|
||||
sender.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sender instanceof Player player) {
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(ChatColor.RED + "Usage: /gutil spawnchampion <entity_type> [tier] [level] [prestige]");
|
||||
sender.sendMessage(ChatColor.YELLOW + "Example: /gutil spawnchampion ZOMBIE 3 50 2");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Parse entity type
|
||||
EntityType entityType;
|
||||
try {
|
||||
entityType = EntityType.valueOf(args[1].toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
sender.sendMessage(ChatColor.RED + "Invalid entity type: " + args[1]);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!entityType.isSpawnable() || !entityType.isAlive()) {
|
||||
sender.sendMessage(ChatColor.RED + "Entity type must be a living spawnable entity.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Parse optional parameters
|
||||
int tier = 1;
|
||||
int level = 1;
|
||||
int prestige = 1;
|
||||
|
||||
if (args.length >= 3) {
|
||||
try {
|
||||
tier = Integer.parseInt(args[2]);
|
||||
if (tier < 1 || tier > 5) {
|
||||
sender.sendMessage(ChatColor.RED + "Tier must be between 1 and 5.");
|
||||
return false;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage(ChatColor.RED + "Invalid tier: " + args[2]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length >= 4) {
|
||||
try {
|
||||
level = Integer.parseInt(args[3]);
|
||||
if (level < 1) {
|
||||
sender.sendMessage(ChatColor.RED + "Level must be at least 1.");
|
||||
return false;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage(ChatColor.RED + "Invalid level: " + args[3]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length >= 5) {
|
||||
try {
|
||||
prestige = Integer.parseInt(args[4]);
|
||||
if (prestige < 1) {
|
||||
sender.sendMessage(ChatColor.RED + "Prestige must be at least 1.");
|
||||
return false;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage(ChatColor.RED + "Invalid prestige: " + args[4]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Spawn the entity
|
||||
LivingEntity entity = (LivingEntity) player.getWorld().spawnEntity(player.getLocation(), entityType);
|
||||
|
||||
// Set a temporary tag to prevent EntitySpawnEvent from processing this entity
|
||||
entity.setMetadata("champion_spawn", new org.bukkit.metadata.FixedMetadataValue(org.gsdistance.grimmsServer.GrimmsServer.instance, true));
|
||||
|
||||
// Register entity
|
||||
CustomEntityManager.registerEntity(entity);
|
||||
|
||||
// Create metadata manually to bypass automatic leveling
|
||||
EntityMetadata metadata = new EntityMetadata(entity);
|
||||
|
||||
// Clear any affixes/abilities that the constructor might have set
|
||||
metadata.affixes.clear();
|
||||
metadata.abilities.clear();
|
||||
|
||||
// Override champion tier, level, and prestige
|
||||
metadata.championTier = tier;
|
||||
metadata.level = level;
|
||||
metadata.prestige = prestige;
|
||||
|
||||
// Store in session data to prevent recreation
|
||||
org.gsdistance.grimmsServer.Data.PerSessionDataStorage.dataStore.put("entityMetadata-" + entity.getUniqueId(), Data.of(metadata, EntityMetadata.class));
|
||||
|
||||
// Select affixes based on tier
|
||||
int numAffixes = Math.min(tier, org.gsdistance.grimmsServer.Constructable.Entity.EntityAffixes.affixes.size());
|
||||
List<EntityAffix> availableAffixes = new ArrayList<>(org.gsdistance.grimmsServer.Constructable.Entity.EntityAffixes.affixes.keySet());
|
||||
Collections.shuffle(availableAffixes);
|
||||
|
||||
for (int i = 0; i < numAffixes; i++) {
|
||||
metadata.affixes.add(availableAffixes.get(i));
|
||||
}
|
||||
|
||||
// Select abilities based on tier
|
||||
metadata.abilities.clear();
|
||||
int numAbilities = Math.max(0, tier - 1);
|
||||
if (numAbilities > 0) {
|
||||
List<EntityAbility> availableAbilities = new ArrayList<>(org.gsdistance.grimmsServer.Constructable.Entity.EntityAbilities.abilities.keySet());
|
||||
Collections.shuffle(availableAbilities);
|
||||
|
||||
for (int i = 0; i < Math.min(numAbilities, availableAbilities.size()); i++) {
|
||||
metadata.abilities.add(availableAbilities.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Apply leveling and champion effects
|
||||
try {
|
||||
// Use applyAttributeModifiers directly to avoid recalculation of level/prestige
|
||||
java.lang.reflect.Method applyAttributeModifiers = EntityMetadata.class.getDeclaredMethod("applyAttributeModifiers", LivingEntity.class, EntityMetadata.class);
|
||||
applyAttributeModifiers.setAccessible(true);
|
||||
applyAttributeModifiers.invoke(null, entity, metadata);
|
||||
|
||||
java.lang.reflect.Method saveAttributeValues = EntityMetadata.class.getDeclaredMethod("saveAttributeValues", LivingEntity.class, EntityMetadata.class);
|
||||
saveAttributeValues.setAccessible(true);
|
||||
saveAttributeValues.invoke(null, entity, metadata);
|
||||
|
||||
java.lang.reflect.Method applyChampionAffixes = EntityMetadata.class.getDeclaredMethod("applyChampionAffixes", LivingEntity.class, EntityMetadata.class);
|
||||
applyChampionAffixes.setAccessible(true);
|
||||
applyChampionAffixes.invoke(null, entity, metadata);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Warning: Could not apply effects via reflection.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Save metadata
|
||||
metadata.saveToFile();
|
||||
|
||||
sender.sendMessage(ChatColor.GREEN + "Spawned champion " + entityType.name() + " (Tier: " + tier + ", Level: " + level + ", Prestige: " + prestige + ")");
|
||||
sender.sendMessage(ChatColor.YELLOW + "Affixes: " + metadata.affixes.size() + ", Abilities: " + metadata.abilities.size());
|
||||
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "You must be a player to use this command.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ public class Sudo {
|
|||
}
|
||||
|
||||
String command = commandBuilder.toString();
|
||||
|
||||
|
||||
try {
|
||||
boolean success = target.performCommand(command);
|
||||
if (success) {
|
||||
|
|
|
|||
|
|
@ -58,12 +58,12 @@ public class UnlevelEntity {
|
|||
private static boolean removeLeveling(CommandSender sender, Entity entity) {
|
||||
// Remove from registry
|
||||
CustomEntityManager.unregisterEntity(entity);
|
||||
|
||||
|
||||
// Remove metadata file
|
||||
try {
|
||||
java.io.File metadataFile = new java.io.File(
|
||||
org.gsdistance.grimmsServer.GrimmsServer.instance.getDataFolder(),
|
||||
"entityMetadata/" + entity.getUniqueId() + ".json"
|
||||
org.gsdistance.grimmsServer.GrimmsServer.instance.getDataFolder(),
|
||||
"entityMetadata/" + entity.getUniqueId() + ".json"
|
||||
);
|
||||
if (metadataFile.exists()) {
|
||||
metadataFile.delete();
|
||||
|
|
|
|||
|
|
@ -3,11 +3,30 @@ package org.gsdistance.grimmsServer.Commands.GUtilCommand;
|
|||
import org.bukkit.command.CommandSender;
|
||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public class Version {
|
||||
|
||||
private static String cachedBuildVersion = null;
|
||||
|
||||
private static String getBuildVersion() {
|
||||
if (cachedBuildVersion == null) {
|
||||
try (InputStream is = GrimmsServer.instance.getResource("build.v")) {
|
||||
if (is != null) {
|
||||
cachedBuildVersion = new String(is.readAllBytes()).trim();
|
||||
} else {
|
||||
cachedBuildVersion = "unknown";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
cachedBuildVersion = "error";
|
||||
}
|
||||
}
|
||||
return cachedBuildVersion;
|
||||
}
|
||||
|
||||
public static boolean subCommand(CommandSender sender, String[] args) {
|
||||
String name = GrimmsServer.instance.getDescription().getPrefix();
|
||||
sender.sendMessage(name + " v" + GrimmsServer.instance.getDescription().getVersion());
|
||||
sender.sendMessage(name + " v" + GrimmsServer.instance.getDescription().getVersion() + " (build " + getBuildVersion() + ")");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class BuyCustomEnchantment {
|
|||
|
||||
ItemLevelHandler itemLevelHandler = ItemLevelHandler.getLevelHandler(itemToApply, player.getPlayer());
|
||||
double itemLevel = itemLevelHandler.getLevel();
|
||||
|
||||
|
||||
// Respect the hard max level from CustomEnchantment
|
||||
if (currentLevel >= enchantment.maxLevel || Math.sqrt(itemLevel) / 2 < currentLevel + 1) {
|
||||
sender.sendMessage(ChatColor.RED + "Enchantment already at maximum level (" + enchantment.maxLevel + ").");
|
||||
|
|
@ -41,22 +41,22 @@ public class BuyCustomEnchantment {
|
|||
}
|
||||
|
||||
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
|
||||
|
||||
|
||||
// Simple cost calculation based on current level
|
||||
double cost = EnchantBaseValues.customEnchantBaseValues.get(enchantment) * (currentLevel + 1);
|
||||
|
||||
|
||||
if (playerStats.getStat("money", Double.class) < cost) {
|
||||
sender.sendMessage(ChatColor.RED + "Not enough money. Cost: " + ChatColor.GOLD + Shared.formatNumber(cost));
|
||||
return false;
|
||||
} else {
|
||||
int oldLevel = currentLevel;
|
||||
int newLevel = oldLevel + 1;
|
||||
|
||||
|
||||
if (enchantHandler.setEnchantmentLevel(enchantment, newLevel)) {
|
||||
playerStats.setStat("money", playerStats.getStat("money", Double.class) - cost);
|
||||
sender.sendMessage(ChatColor.GREEN + "Upgraded the custom enchantment " + ChatColor.GOLD + enchantment.enchantmentName +
|
||||
ChatColor.GREEN + " from level " + ChatColor.YELLOW + oldLevel +
|
||||
ChatColor.GREEN + " to level " + ChatColor.YELLOW + newLevel +
|
||||
sender.sendMessage(ChatColor.GREEN + "Upgraded the custom enchantment " + ChatColor.GOLD + enchantment.enchantmentName +
|
||||
ChatColor.GREEN + " from level " + ChatColor.YELLOW + oldLevel +
|
||||
ChatColor.GREEN + " to level " + ChatColor.YELLOW + newLevel +
|
||||
ChatColor.GREEN + " for " + ChatColor.GOLD + Shared.formatNumber(cost) + ChatColor.GREEN + " money.");
|
||||
return true;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -43,7 +43,10 @@ public enum ConfigKey {
|
|||
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>());
|
||||
LEVELLED_MOBS_BLACKLIST("levelled_mobs_blacklist", new ArrayList<String>()),
|
||||
CHAMPION_MOBS_ENABLED("champion_mobs_enabled", true),
|
||||
CHAMPION_MOBS_CHANCE("champion_mobs_chance", 0.01),
|
||||
CHAMPION_MOBS_BOSSBAR_RADIUS("champion_mobs_bossbar_radius", 50);
|
||||
|
||||
private final String key;
|
||||
private final Object defaultValue;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,70 @@
|
|||
package org.gsdistance.grimmsServer.Constructable.Entity;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class EntityAbilities {
|
||||
// Key - Ability
|
||||
// Value - Tier
|
||||
// Value - Tier (higher tier = stronger effect)
|
||||
public static final Map<EntityAbility, Integer> abilities = Map.ofEntries(
|
||||
Map.entry(new EntityAbility("test", Integer.MAX_VALUE, (entity) -> null), 99)
|
||||
// Heal self - heals 20% of max health every 10 seconds
|
||||
Map.entry(new EntityAbility("heal_self", 200, (entity) -> {
|
||||
double maxHealth = entity.getAttribute(org.bukkit.attribute.Attribute.MAX_HEALTH).getValue();
|
||||
double healAmount = maxHealth * 0.2;
|
||||
entity.setHealth(Math.min(maxHealth, entity.getHealth() + healAmount));
|
||||
return null;
|
||||
}), 1),
|
||||
|
||||
// Reflect damage - reflects 50% of damage taken (handled in damage event)
|
||||
Map.entry(new EntityAbility("reflect_damage", 0, (entity) -> {
|
||||
// This is a passive ability handled in damage events
|
||||
return null;
|
||||
}), 1),
|
||||
|
||||
// Summon reinforcements - summons 2 mobs of same type every 30 seconds
|
||||
Map.entry(new EntityAbility("summon_reinforcements", 600, (entity) -> {
|
||||
Location loc = entity.getLocation();
|
||||
for (int i = 0; i < 2; i++) {
|
||||
LivingEntity reinforcement = (LivingEntity) loc.getWorld().spawnEntity(loc, entity.getType());
|
||||
reinforcement.setCustomName("Reinforcement");
|
||||
}
|
||||
return null;
|
||||
}), 1),
|
||||
|
||||
// Teleport - teleports to random nearby location every 15 seconds
|
||||
Map.entry(new EntityAbility("teleport", 900, (entity) -> {
|
||||
Location loc = entity.getLocation();
|
||||
Location newLoc = new Location(
|
||||
loc.getWorld(),
|
||||
loc.getX() + (Math.random() - 0.5) * 10,
|
||||
loc.getY(),
|
||||
loc.getZ() + (Math.random() - 0.5) * 10
|
||||
);
|
||||
entity.teleport(newLoc);
|
||||
return null;
|
||||
}), 1),
|
||||
|
||||
// Rage - increases attack speed and damage when low health
|
||||
Map.entry(new EntityAbility("rage", 100, (entity) -> {
|
||||
if (entity.getHealth() < entity.getAttribute(org.bukkit.attribute.Attribute.MAX_HEALTH).getValue() * 0.3) {
|
||||
entity.addPotionEffect(new PotionEffect(PotionEffectType.STRENGTH, 100, 1));
|
||||
entity.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 100, 2));
|
||||
}
|
||||
return null;
|
||||
}), 1),
|
||||
|
||||
// Fire burst - ignites nearby enemies every 20 seconds
|
||||
Map.entry(new EntityAbility("fire_burst", 400, (entity) -> {
|
||||
entity.getNearbyEntities(5, 5, 5).forEach(nearby -> {
|
||||
if (nearby instanceof LivingEntity && nearby != entity) {
|
||||
nearby.setFireTicks(60);
|
||||
}
|
||||
});
|
||||
return null;
|
||||
}), 1)
|
||||
);
|
||||
// Could add abilities such as heal self, reflect damage, summon reinforcements etc.
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,62 @@
|
|||
package org.gsdistance.grimmsServer.Constructable.Entity;
|
||||
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class EntityAffixes {
|
||||
// Key - Affix
|
||||
// Value - Tier
|
||||
// Value - Tier (higher tier = stronger effect)
|
||||
public static final Map<EntityAffix, Integer> affixes = Map.ofEntries(
|
||||
Map.entry(new EntityAffix("test", (entity) -> null), 99)
|
||||
);
|
||||
// Health bonus - increases max health by tier * 50%
|
||||
Map.entry(new EntityAffix("healthy", (entity) -> {
|
||||
if (entity.getAttribute(Attribute.MAX_HEALTH) != null) {
|
||||
double base = entity.getAttribute(Attribute.MAX_HEALTH).getBaseValue();
|
||||
entity.getAttribute(Attribute.MAX_HEALTH).setBaseValue(base * 1.5);
|
||||
entity.setHealth(entity.getAttribute(Attribute.MAX_HEALTH).getValue());
|
||||
}
|
||||
return null;
|
||||
}), 1),
|
||||
|
||||
// Could add affixes such as health bonus, armor bonus and damage bonus
|
||||
// Armor bonus - increases armor by tier * 5
|
||||
Map.entry(new EntityAffix("armored", (entity) -> {
|
||||
if (entity.getAttribute(Attribute.ARMOR) != null) {
|
||||
double base = entity.getAttribute(Attribute.ARMOR).getBaseValue();
|
||||
entity.getAttribute(Attribute.ARMOR).setBaseValue(base + 5);
|
||||
}
|
||||
return null;
|
||||
}), 1),
|
||||
|
||||
// Damage bonus - increases attack damage by tier * 20%
|
||||
Map.entry(new EntityAffix("strong", (entity) -> {
|
||||
if (entity.getAttribute(Attribute.ATTACK_DAMAGE) != null) {
|
||||
double base = entity.getAttribute(Attribute.ATTACK_DAMAGE).getBaseValue();
|
||||
entity.getAttribute(Attribute.ATTACK_DAMAGE).setBaseValue(base * 1.2);
|
||||
}
|
||||
return null;
|
||||
}), 1),
|
||||
|
||||
// Speed bonus - gives speed effect
|
||||
Map.entry(new EntityAffix("swift", (entity) -> {
|
||||
entity.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1));
|
||||
return null;
|
||||
}), 1),
|
||||
|
||||
// Fire resistance
|
||||
Map.entry(new EntityAffix("fiery", (entity) -> {
|
||||
entity.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, Integer.MAX_VALUE, 0));
|
||||
return null;
|
||||
}), 1),
|
||||
|
||||
// Knockback resistance
|
||||
Map.entry(new EntityAffix("heavy", (entity) -> {
|
||||
entity.addPotionEffect(new PotionEffect(PotionEffectType.SLOWNESS, Integer.MAX_VALUE, 0));
|
||||
if (entity.getAttribute(Attribute.KNOCKBACK_RESISTANCE) != null) {
|
||||
entity.getAttribute(Attribute.KNOCKBACK_RESISTANCE).setBaseValue(0.5);
|
||||
}
|
||||
return null;
|
||||
}), 1)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,24 +28,53 @@ public class EntityMetadata {
|
|||
public int prestige = 1;
|
||||
public String originalName;
|
||||
public List<EntityAffix> affixes = new ArrayList<>();
|
||||
public List<EntityAbility> abilities = new ArrayList<>();
|
||||
public int championTier = 0;
|
||||
// Store base values after first leveling to prevent snowballing on chunk reload
|
||||
public double maxHealth = 0;
|
||||
public double armor = 0;
|
||||
public double armorToughness = 0;
|
||||
public double attackDamage = 0;
|
||||
// Bossbar for champion mobs
|
||||
public transient org.bukkit.boss.BossBar bossBar;
|
||||
// Ability cooldown tracking (ability UUID -> last execution time in ticks)
|
||||
public transient java.util.Map<UUID, Long> abilityCooldowns = new java.util.HashMap<>();
|
||||
|
||||
public EntityMetadata(Entity entity) {
|
||||
this.uuid = entity.getUniqueId();
|
||||
this.timestamp = LocalDateTime.now().toString();
|
||||
this.originalName = entity.getName();
|
||||
while(Math.random() < 0.01){
|
||||
this.championTier++;
|
||||
}
|
||||
if(championTier > 0){
|
||||
while(Math.random() < 0.5){
|
||||
// TODO - Add a random affix with tier equal to or less than the champion tier
|
||||
|
||||
// Determine if this entity becomes a champion
|
||||
Boolean championEnabled = ActiveConfig.getConfigValue(ConfigKey.CHAMPION_MOBS_ENABLED, Boolean.class);
|
||||
Double championChance = ActiveConfig.getConfigValue(ConfigKey.CHAMPION_MOBS_CHANCE, Double.class);
|
||||
|
||||
if (championEnabled != null && championEnabled && championChance != null && Math.random() < championChance) {
|
||||
// Roll for champion tier (1-5)
|
||||
while (Math.random() < 0.5 && this.championTier < 5) {
|
||||
this.championTier++;
|
||||
}
|
||||
|
||||
// Select random affixes based on champion tier
|
||||
if (this.championTier > 0) {
|
||||
int numAffixes = Math.min(this.championTier, EntityAffixes.affixes.size());
|
||||
List<EntityAffix> availableAffixes = new ArrayList<>(EntityAffixes.affixes.keySet());
|
||||
java.util.Collections.shuffle(availableAffixes);
|
||||
|
||||
for (int i = 0; i < numAffixes; i++) {
|
||||
this.affixes.add(availableAffixes.get(i));
|
||||
}
|
||||
|
||||
// Select random abilities based on champion tier (higher tiers get more abilities)
|
||||
int numAbilities = Math.max(0, this.championTier - 1);
|
||||
if (numAbilities > 0) {
|
||||
List<EntityAbility> availableAbilities = new ArrayList<>(EntityAbilities.abilities.keySet());
|
||||
java.util.Collections.shuffle(availableAbilities);
|
||||
|
||||
for (int i = 0; i < Math.min(numAbilities, availableAbilities.size()); i++) {
|
||||
this.abilities.add(availableAbilities.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -69,6 +98,11 @@ public class EntityMetadata {
|
|||
}
|
||||
|
||||
public void deleteFromFile() {
|
||||
// Remove bossbar if present
|
||||
if (this.bossBar != null) {
|
||||
this.bossBar.removeAll();
|
||||
this.bossBar = null;
|
||||
}
|
||||
GrimmsServer.pds.deleteData(this.uuid.toString() + ".json", "entityMetadata");
|
||||
PerSessionDataStorage.dataStore.remove("entityMetadata-" + this.uuid);
|
||||
}
|
||||
|
|
@ -87,6 +121,7 @@ public class EntityMetadata {
|
|||
// Apply levelling when metadata is first created
|
||||
if (entity instanceof LivingEntity && entity.getType() != EntityType.PLAYER) {
|
||||
applyLevelling((LivingEntity) entity, metadata);
|
||||
applyChampionAffixes((LivingEntity) entity, metadata);
|
||||
}
|
||||
metadata.saveToFile();
|
||||
} else {
|
||||
|
|
@ -97,6 +132,7 @@ public class EntityMetadata {
|
|||
// Re-apply levelling based on saved level/prestige when loading from disk (chunk reload)
|
||||
if (entity instanceof LivingEntity && entity.getType() != EntityType.PLAYER) {
|
||||
applyAttributeModifiers((LivingEntity) entity, metadata);
|
||||
applyChampionAffixes((LivingEntity) entity, metadata);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -178,6 +214,60 @@ public class EntityMetadata {
|
|||
}
|
||||
}
|
||||
|
||||
private static void applyChampionAffixes(LivingEntity livingEntity, EntityMetadata metadata) {
|
||||
// Apply all champion affixes to the entity
|
||||
for (EntityAffix affix : metadata.affixes) {
|
||||
affix.effect().apply(livingEntity);
|
||||
}
|
||||
|
||||
// Create bossbar for champion mobs
|
||||
if (metadata.championTier > 0) {
|
||||
createBossBar(livingEntity, metadata);
|
||||
}
|
||||
}
|
||||
|
||||
private static void createBossBar(LivingEntity livingEntity, EntityMetadata metadata) {
|
||||
// Remove existing bossbar if present
|
||||
if (metadata.bossBar != null) {
|
||||
metadata.bossBar.removeAll();
|
||||
}
|
||||
|
||||
// Create new bossbar
|
||||
String title = ChatColor.GOLD + "★ Champion " + metadata.championTier + " ★ " + ChatColor.WHITE + livingEntity.getName();
|
||||
metadata.bossBar = org.bukkit.Bukkit.createBossBar(title, org.bukkit.boss.BarColor.RED, org.bukkit.boss.BarStyle.SEGMENTED_10);
|
||||
updateBossBarHealth(livingEntity, metadata);
|
||||
|
||||
// Add nearby players to bossbar
|
||||
Integer radius = ActiveConfig.getConfigValue(ConfigKey.CHAMPION_MOBS_BOSSBAR_RADIUS, Integer.class);
|
||||
if (radius == null) radius = 50;
|
||||
|
||||
for (org.bukkit.entity.Player player : livingEntity.getWorld().getPlayers()) {
|
||||
if (player.getLocation().distance(livingEntity.getLocation()) <= radius) {
|
||||
metadata.bossBar.addPlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateBossBarHealth(LivingEntity livingEntity, EntityMetadata metadata) {
|
||||
if (metadata.bossBar != null && livingEntity.getAttribute(Attribute.MAX_HEALTH) != null) {
|
||||
double maxHealth = livingEntity.getAttribute(Attribute.MAX_HEALTH).getValue();
|
||||
double currentHealth = livingEntity.getHealth();
|
||||
metadata.bossBar.setProgress(Math.max(0, Math.min(1, currentHealth / maxHealth)));
|
||||
}
|
||||
}
|
||||
|
||||
public void executeAbilities(LivingEntity livingEntity, EntityMetadata metadata, long currentTick) {
|
||||
for (EntityAbility ability : metadata.abilities) {
|
||||
UUID abilityId = java.util.UUID.nameUUIDFromBytes(ability.id().getBytes());
|
||||
Long lastExecution = metadata.abilityCooldowns.get(abilityId);
|
||||
|
||||
if (lastExecution == null || currentTick - lastExecution >= ability.cooldownTicks()) {
|
||||
ability.effect().apply(livingEntity);
|
||||
metadata.abilityCooldowns.put(abilityId, currentTick);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void applyAttributeModifiers(LivingEntity livingEntity, EntityMetadata metadata) {
|
||||
Boolean enabled = ActiveConfig.getConfigValue(ConfigKey.LEVELLED_MOBS_ENABLED, Boolean.class);
|
||||
if (enabled == null || !enabled) {
|
||||
|
|
@ -263,7 +353,11 @@ public class EntityMetadata {
|
|||
}
|
||||
}
|
||||
|
||||
// Set custom name with level and health bar
|
||||
// Set custom name with level and health bar (skip for champion mobs)
|
||||
if (metadata.championTier > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
ChatColor levelColor = getLevelColor(finalLevel);
|
||||
|
||||
double maxHealth = livingEntity.getAttribute(Attribute.MAX_HEALTH).getValue();
|
||||
|
|
|
|||
|
|
@ -23,15 +23,16 @@ public class CustomEnchantmentHandler {
|
|||
|
||||
/**
|
||||
* Add a custom enchantment to the item
|
||||
*
|
||||
* @param enchantment The enchantment to add
|
||||
* @param level The level of the enchantment
|
||||
* @param level The level of the enchantment
|
||||
* @return true if successful, false if level exceeds max or enchantment already exists
|
||||
*/
|
||||
public boolean addEnchantment(CustomEnchantment enchantment, int level) {
|
||||
if (level < 1 || level > enchantment.maxLevel) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (hasEnchantment(enchantment)) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -43,6 +44,7 @@ public class CustomEnchantmentHandler {
|
|||
|
||||
/**
|
||||
* Remove a custom enchantment from the item
|
||||
*
|
||||
* @param enchantment The enchantment to remove
|
||||
* @return true if the enchantment was removed, false if it didn't exist
|
||||
*/
|
||||
|
|
@ -61,6 +63,7 @@ public class CustomEnchantmentHandler {
|
|||
|
||||
/**
|
||||
* Check if the item has a specific custom enchantment
|
||||
*
|
||||
* @param enchantment The enchantment to check for
|
||||
* @return true if the item has the enchantment with level > 0
|
||||
*/
|
||||
|
|
@ -70,6 +73,7 @@ public class CustomEnchantmentHandler {
|
|||
|
||||
/**
|
||||
* Get the level of a custom enchantment on the item
|
||||
*
|
||||
* @param enchantment The enchantment to check
|
||||
* @return The level of the enchantment, or 0 if not present
|
||||
*/
|
||||
|
|
@ -81,25 +85,27 @@ public class CustomEnchantmentHandler {
|
|||
|
||||
/**
|
||||
* Get all custom enchantments on the item
|
||||
*
|
||||
* @return A map of enchantments to their levels
|
||||
*/
|
||||
public Map<CustomEnchantment, Integer> getAllEnchantments() {
|
||||
Map<CustomEnchantment, Integer> enchantments = new HashMap<>();
|
||||
|
||||
|
||||
for (CustomEnchantment enchantment : CustomEnchantment.values()) {
|
||||
int level = getEnchantmentLevel(enchantment);
|
||||
if (level > 0) {
|
||||
enchantments.put(enchantment, level);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return enchantments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the level of an enchantment (overwrites existing)
|
||||
*
|
||||
* @param enchantment The enchantment to set
|
||||
* @param level The level to set
|
||||
* @param level The level to set
|
||||
* @return true if successful, false if level is invalid
|
||||
*/
|
||||
public boolean setEnchantmentLevel(CustomEnchantment enchantment, int level) {
|
||||
|
|
@ -123,6 +129,7 @@ public class CustomEnchantmentHandler {
|
|||
|
||||
/**
|
||||
* Check if the item has any custom enchantments
|
||||
*
|
||||
* @return true if the item has at least one custom enchantment
|
||||
*/
|
||||
public boolean hasAnyEnchantments() {
|
||||
|
|
|
|||
|
|
@ -60,30 +60,30 @@ public class CustomItemRegistry {
|
|||
|
||||
public static void registerGunTypes() {
|
||||
// Register pistol
|
||||
registerCustomItem("gun_pistol", (itemStack) ->
|
||||
new GunItem("gun_pistol", itemStack, "Pistol", 5.0, 2.0, 12, Material.IRON_NUGGET));
|
||||
|
||||
registerCustomItem("gun_pistol", (itemStack) ->
|
||||
new GunItem("gun_pistol", itemStack, "Pistol", 5.0, 2.0, 12, Material.IRON_NUGGET));
|
||||
|
||||
// Register rifle
|
||||
registerCustomItem("gun_rifle", (itemStack) ->
|
||||
new GunItem("gun_rifle", itemStack, "Rifle", 8.0, 4.0, 30, Material.GOLD_NUGGET));
|
||||
|
||||
registerCustomItem("gun_rifle", (itemStack) ->
|
||||
new GunItem("gun_rifle", itemStack, "Rifle", 8.0, 4.0, 30, Material.GOLD_NUGGET));
|
||||
|
||||
// Register shotgun
|
||||
registerCustomItem("gun_shotgun", (itemStack) ->
|
||||
new GunItem("gun_shotgun", itemStack, "Shotgun", 15.0, 1.0, 8, Material.IRON_INGOT));
|
||||
registerCustomItem("gun_shotgun", (itemStack) ->
|
||||
new GunItem("gun_shotgun", itemStack, "Shotgun", 15.0, 1.0, 8, Material.IRON_INGOT));
|
||||
}
|
||||
|
||||
public static void registerAmmoTypes() {
|
||||
// Register pistol ammo
|
||||
registerCustomItem("ammo_pistol", (itemStack) ->
|
||||
new AmmoItem("ammo_pistol", itemStack, "Pistol", 30, Material.IRON_NUGGET));
|
||||
|
||||
registerCustomItem("ammo_pistol", (itemStack) ->
|
||||
new AmmoItem("ammo_pistol", itemStack, "Pistol", 30, Material.IRON_NUGGET));
|
||||
|
||||
// Register rifle ammo
|
||||
registerCustomItem("ammo_rifle", (itemStack) ->
|
||||
new AmmoItem("ammo_rifle", itemStack, "Rifle", 60, Material.GOLD_NUGGET));
|
||||
|
||||
registerCustomItem("ammo_rifle", (itemStack) ->
|
||||
new AmmoItem("ammo_rifle", itemStack, "Rifle", 60, Material.GOLD_NUGGET));
|
||||
|
||||
// Register shotgun ammo
|
||||
registerCustomItem("ammo_shotgun", (itemStack) ->
|
||||
new AmmoItem("ammo_shotgun", itemStack, "Shotgun", 16, Material.IRON_INGOT));
|
||||
registerCustomItem("ammo_shotgun", (itemStack) ->
|
||||
new AmmoItem("ammo_shotgun", itemStack, "Shotgun", 16, Material.IRON_INGOT));
|
||||
}
|
||||
|
||||
public static Set<String> getRegisteredItemIds() {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class AmmoItem extends CustomItem {
|
|||
@Override
|
||||
protected void initializeItem() {
|
||||
CustomItemHandler handler = CustomItemHandler.getHandler(this.getItemStack());
|
||||
|
||||
|
||||
// Initialize ammo-specific NBT data
|
||||
handler.setCustomData("ammo_type", this.ammoType, PersistentDataType.STRING);
|
||||
handler.setCustomData("ammo_amount", this.ammoAmount, PersistentDataType.INTEGER);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import org.gsdistance.grimmsServer.Constructable.Item.CustomItemRegistry;
|
|||
* This is a template for creating your own custom items.
|
||||
*/
|
||||
public class CustomItemExample extends CustomItem {
|
||||
|
||||
|
||||
public CustomItemExample(String itemId, ItemStack itemStack) {
|
||||
super(itemId, itemStack);
|
||||
}
|
||||
|
|
@ -30,7 +30,7 @@ public class CustomItemExample extends CustomItem {
|
|||
meta.setCustomModelDataComponent(component);
|
||||
setItemMeta(meta);
|
||||
}
|
||||
|
||||
|
||||
// Store custom data specific to this item type
|
||||
getHandler().setCustomData("exampleValue", 42, org.bukkit.persistence.PersistentDataType.INTEGER);
|
||||
}
|
||||
|
|
@ -44,7 +44,7 @@ public class CustomItemExample extends CustomItem {
|
|||
public String getDescription() {
|
||||
return "An example custom item with special properties.";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Example method to register this custom item.
|
||||
* Call this during your plugin's onEnable() method.
|
||||
|
|
@ -53,15 +53,15 @@ public class CustomItemExample extends CustomItem {
|
|||
CustomItemRegistry.registerCustomItem("custom_example", itemStack -> {
|
||||
// Create the ItemStack (can be any material)
|
||||
ItemStack stack = new ItemStack(Material.DIAMOND_SWORD);
|
||||
|
||||
|
||||
// Initialize it as a custom item
|
||||
CustomItemHandler.createHandler(stack);
|
||||
|
||||
|
||||
// Create and return the custom item instance
|
||||
return new CustomItemExample("custom_example", stack);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Example method to create an instance of this custom item.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class GunItem extends CustomItem {
|
|||
@Override
|
||||
protected void initializeItem() {
|
||||
CustomItemHandler handler = CustomItemHandler.getHandler(this.getItemStack());
|
||||
|
||||
|
||||
// Initialize gun-specific NBT data
|
||||
handler.setCustomData("gun_type", this.gunType, PersistentDataType.STRING);
|
||||
handler.setCustomData("damage", this.damage, PersistentDataType.DOUBLE);
|
||||
|
|
@ -44,9 +44,9 @@ public class GunItem extends CustomItem {
|
|||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return ChatColor.GRAY + "Damage: " + ChatColor.RED + this.damage +
|
||||
ChatColor.GRAY + " | Fire Rate: " + ChatColor.YELLOW + this.fireRate + "/s" +
|
||||
ChatColor.GRAY + " | Ammo: " + ChatColor.AQUA + this.maxAmmo;
|
||||
return ChatColor.GRAY + "Damage: " + ChatColor.RED + this.damage +
|
||||
ChatColor.GRAY + " | Fire Rate: " + ChatColor.YELLOW + this.fireRate + "/s" +
|
||||
ChatColor.GRAY + " | Ammo: " + ChatColor.AQUA + this.maxAmmo;
|
||||
}
|
||||
|
||||
// Getters for gun properties
|
||||
|
|
|
|||
|
|
@ -34,9 +34,9 @@ public class CustomRelicItem extends CustomItem {
|
|||
case 3 -> ChatColor.DARK_PURPLE;
|
||||
default -> ChatColor.WHITE;
|
||||
};
|
||||
|
||||
String displayName = tierColor + (relicType.isEmpty() ? "" : relicType.substring(0, 1).toUpperCase() + relicType.substring(1)) +
|
||||
" Relic " + ChatColor.GRAY + "[" + tierColor + "Tier " + tier + ChatColor.GRAY + "]";
|
||||
|
||||
String displayName = tierColor + (relicType.isEmpty() ? "" : relicType.substring(0, 1).toUpperCase() + relicType.substring(1)) +
|
||||
" Relic " + ChatColor.GRAY + "[" + tierColor + "Tier " + tier + ChatColor.GRAY + "]";
|
||||
meta.setDisplayName(displayName);
|
||||
setItemMeta(meta);
|
||||
}
|
||||
|
|
@ -84,7 +84,7 @@ public class CustomRelicItem extends CustomItem {
|
|||
public static void registerRelicTypes() {
|
||||
// Register each relic type as a custom item
|
||||
String[] relicTypes = {"sword", "pickaxe", "axe", "shovel", "hoe", "armor"};
|
||||
|
||||
|
||||
for (String type : relicTypes) {
|
||||
String itemId = "relic_" + type;
|
||||
CustomItemRegistry.registerCustomItem(itemId, itemStack -> {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class ItemStats {
|
|||
CustomItemHandler customItemHandler = CustomItemHandler.getHandler(this.item);
|
||||
String customItemId = customItemHandler.getCustomItemId();
|
||||
toolStats.add(ChatColor.BOLD + "Item: " + ChatColor.RESET + ChatColor.WHITE + customItemId);
|
||||
|
||||
|
||||
// Check if this is a registered custom item with additional info
|
||||
if (CustomItemRegistry.isCustomItemRegistered(customItemId)) {
|
||||
CustomItem customItem = CustomItemRegistry.getCustomItem(customItemId);
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ public class RelicHandler {
|
|||
public static void makeRelic(ItemStack item) {
|
||||
// Initialize as a custom item first
|
||||
CustomItemHandler customHandler = CustomItemHandler.createHandler(item);
|
||||
|
||||
|
||||
RelicHandler relicHandler = new RelicHandler(item);
|
||||
relicHandler.dataHandler.setItemNBTData("isRelic", true, PersistentDataType.BOOLEAN);
|
||||
relicHandler.dataHandler.setItemNBTData("relicUUID", UUID.randomUUID().toString(), PersistentDataType.STRING);
|
||||
|
|
@ -58,10 +58,10 @@ public class RelicHandler {
|
|||
}
|
||||
|
||||
relicHandler.dataHandler.setItemNBTData("relicType", relicType, PersistentDataType.STRING);
|
||||
|
||||
|
||||
// Set custom item ID to relic type for identification
|
||||
customHandler.setCustomItemId("relic_" + relicType);
|
||||
|
||||
|
||||
relicHandler.initRandomRelicStats();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public class PlayerInventoryData {
|
|||
public String[] armorContents; // Store as Base64 strings
|
||||
public String[] extraContents; // Store as Base64 strings
|
||||
public List<InventorySnapshot> previousInventories;
|
||||
|
||||
|
||||
// Soulbound items - these items are kept on death and restored on respawn
|
||||
public Map<Integer, String> soulboundInventoryContents; // Store as Base64 strings
|
||||
public String[] soulboundArmorContents; // Store as Base64 strings
|
||||
|
|
@ -33,7 +33,7 @@ public class PlayerInventoryData {
|
|||
this.armorContents = new String[4];
|
||||
this.extraContents = new String[36];
|
||||
this.previousInventories = new ArrayList<>();
|
||||
|
||||
|
||||
// Initialize soulbound storage
|
||||
this.soulboundInventoryContents = new HashMap<>();
|
||||
this.soulboundArmorContents = new String[4];
|
||||
|
|
@ -150,11 +150,11 @@ public class PlayerInventoryData {
|
|||
}
|
||||
|
||||
// Soulbound item management methods
|
||||
|
||||
|
||||
// Mark an item as soulbound by slot (removes from saved inventory, adds to soulbound storage)
|
||||
public void markSoulboundItem(int slot, String itemType) {
|
||||
if (itemType == null) return;
|
||||
|
||||
|
||||
if (itemType.equals("inventory")) {
|
||||
String item = this.inventoryContents.remove(slot);
|
||||
if (item != null) {
|
||||
|
|
@ -182,7 +182,7 @@ public class PlayerInventoryData {
|
|||
// Mark an ItemStack as soulbound (converts to Base64 and marks)
|
||||
public void markSoulboundItemStack(int slot, ItemStack itemStack, String itemType) {
|
||||
if (itemStack == null) return;
|
||||
|
||||
|
||||
try {
|
||||
String base64 = itemStackToBase64(itemStack);
|
||||
markSoulboundItem(slot, itemType);
|
||||
|
|
|
|||
|
|
@ -65,14 +65,14 @@ public class PlayerTitleChecker {
|
|||
private static void checkAllTitles(Player player) {
|
||||
PlayerTitles playerTitles = PlayerTitles.getPlayerTitles(player);
|
||||
PlayerStats playerStats = PlayerStats.getPlayerStats(player);
|
||||
|
||||
|
||||
// Check static criteria titles
|
||||
for (TitleCriteria criteria : TitleCriteria.values()) {
|
||||
if (!playerTitles.hasTitle(criteria.getTitleId()) && criteria.test(player)) {
|
||||
playerTitles.addTitle(criteria.getTitleId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check dynamic money titles (all qualifying titles like achievements)
|
||||
double money = playerStats.getStat("money", Double.class);
|
||||
List<String> moneyTitles = TitleGenerator.getMoneyTitles(money);
|
||||
|
|
@ -81,7 +81,7 @@ public class PlayerTitleChecker {
|
|||
playerTitles.addTitle(title);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check dynamic block break titles (all qualifying titles like achievements)
|
||||
long blockBreaks = playerStats.getStat("block_break_count", Long.class);
|
||||
List<String> blockBreakTitles = TitleGenerator.getBlockBreakTitles(blockBreaks);
|
||||
|
|
@ -90,7 +90,7 @@ public class PlayerTitleChecker {
|
|||
playerTitles.addTitle(title);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check dynamic kill titles (all qualifying titles like achievements)
|
||||
long totalKills = getTotalKills(player);
|
||||
List<String> killTitles = TitleGenerator.getKillTitles(totalKills);
|
||||
|
|
@ -100,7 +100,7 @@ public class PlayerTitleChecker {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static long getTotalKills(Player player) {
|
||||
Object totalKillsObj = PlayerStats.getPlayerStats(player).getStat("total_kill_count", Object.class);
|
||||
if (totalKillsObj instanceof Integer) {
|
||||
|
|
|
|||
|
|
@ -26,27 +26,27 @@ public class PluginDataStorage {
|
|||
|
||||
private Gson createGson() {
|
||||
return new GsonBuilder()
|
||||
.disableInnerClassSerialization()
|
||||
.excludeFieldsWithModifiers(java.lang.reflect.Modifier.STATIC, java.lang.reflect.Modifier.TRANSIENT)
|
||||
.setExclusionStrategies(new ExclusionStrategy() {
|
||||
@Override
|
||||
public boolean shouldSkipField(FieldAttributes f) {
|
||||
// Skip fields that contain Optional or other problematic types
|
||||
String typeName = f.getDeclaredType().getTypeName();
|
||||
return typeName.contains("java.util.Optional") ||
|
||||
typeName.contains("java.lang.reflect") ||
|
||||
typeName.contains("java.security") ||
|
||||
typeName.contains("java.util.concurrent") ||
|
||||
typeName.contains("org.bukkit");
|
||||
}
|
||||
.disableInnerClassSerialization()
|
||||
.excludeFieldsWithModifiers(java.lang.reflect.Modifier.STATIC, java.lang.reflect.Modifier.TRANSIENT)
|
||||
.setExclusionStrategies(new ExclusionStrategy() {
|
||||
@Override
|
||||
public boolean shouldSkipField(FieldAttributes f) {
|
||||
// Skip fields that contain Optional or other problematic types
|
||||
String typeName = f.getDeclaredType().getTypeName();
|
||||
return typeName.contains("java.util.Optional") ||
|
||||
typeName.contains("java.lang.reflect") ||
|
||||
typeName.contains("java.security") ||
|
||||
typeName.contains("java.util.concurrent") ||
|
||||
typeName.contains("org.bukkit");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSkipClass(Class<?> clazz) {
|
||||
// Skip all Bukkit classes from reflection
|
||||
return clazz.getName().startsWith("org.bukkit");
|
||||
}
|
||||
})
|
||||
.create();
|
||||
@Override
|
||||
public boolean shouldSkipClass(Class<?> clazz) {
|
||||
// Skip all Bukkit classes from reflection
|
||||
return clazz.getName().startsWith("org.bukkit");
|
||||
}
|
||||
})
|
||||
.create();
|
||||
}
|
||||
|
||||
public boolean exists(String fileName, String addedPath) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
package org.gsdistance.grimmsServer.Events.Listeners;
|
||||
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.gsdistance.grimmsServer.Constructable.Entity.EntityMetadata;
|
||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||
import org.gsdistance.grimmsServer.Manage.CustomEntityManager;
|
||||
|
||||
public class ChampionTickEvent {
|
||||
public ChampionTickEvent() {
|
||||
}
|
||||
|
||||
public static void Event() {
|
||||
// Only process entities in loaded chunks to avoid unnecessary processing
|
||||
for (java.util.UUID entityUuid : CustomEntityManager.currentRegistry) {
|
||||
org.bukkit.entity.Entity entity = GrimmsServer.instance.getServer().getEntity(entityUuid);
|
||||
if (entity instanceof LivingEntity && entity.isValid()) {
|
||||
EntityMetadata metadata = EntityMetadata.getEntityMetadata(entity);
|
||||
if (metadata != null && metadata.championTier > 0 && !metadata.abilities.isEmpty()) {
|
||||
metadata.executeAbilities((LivingEntity) entity, metadata, ServerTickEvent.ticks);
|
||||
// Update bossbar health
|
||||
EntityMetadata.updateBossBarHealth((LivingEntity) entity, metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,8 @@ package org.gsdistance.grimmsServer.Events.Listeners;
|
|||
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Constructable.Entity.EntityAbility;
|
||||
import org.gsdistance.grimmsServer.Constructable.Entity.EntityMetadata;
|
||||
import org.gsdistance.grimmsServer.Constructable.Item.ItemLevelHandler;
|
||||
import org.gsdistance.grimmsServer.Data.StaticLists;
|
||||
import org.gsdistance.grimmsServer.Events.Registers.CustomEntityDamageByEntityRegister;
|
||||
|
|
@ -14,6 +16,23 @@ public class CustomEntityDamageByEntityEvent {
|
|||
// This event is only called for non-player entities being damaged
|
||||
org.bukkit.event.entity.EntityDamageByEntityEvent originalEvent = event.getOriginalEvent();
|
||||
|
||||
// Handle champion abilities
|
||||
EntityMetadata metadata = EntityMetadata.getEntityMetadata(originalEvent.getEntity());
|
||||
if (metadata != null && metadata.championTier > 0) {
|
||||
// Check for reflect_damage ability
|
||||
for (EntityAbility ability : metadata.abilities) {
|
||||
if (ability.id().equals("reflect_damage") && originalEvent.getDamager() instanceof org.bukkit.entity.LivingEntity) {
|
||||
// Reflect 50% of damage back to the damager
|
||||
double reflectedDamage = originalEvent.getDamage() * 0.5;
|
||||
((org.bukkit.entity.LivingEntity) originalEvent.getDamager()).damage(reflectedDamage, originalEvent.getEntity());
|
||||
}
|
||||
}
|
||||
// Update bossbar health when entity takes damage
|
||||
if (originalEvent.getEntity() instanceof org.bukkit.entity.LivingEntity) {
|
||||
EntityMetadata.updateBossBarHealth((org.bukkit.entity.LivingEntity) originalEvent.getEntity(), metadata);
|
||||
}
|
||||
}
|
||||
|
||||
// Item XP logic for damaging non-player entities
|
||||
if (originalEvent.getDamager().getType() == EntityType.PLAYER && !StaticLists.xpBlacklist.contains(originalEvent.getEntityType()) && ItemLevelHandler.isItemLevelable(((Player) originalEvent.getDamager()).getInventory().getItemInMainHand())) {
|
||||
ItemLevelHandler.getLevelHandler((Player) originalEvent.getDamager()).addXp(originalEvent.getDamage());
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ public class EntityDamageByEntityEvent {
|
|||
if (!GAuthBaseCommand.isLoggedIn(player)) {
|
||||
player.sendMessage(ChatColor.RED + "You must login with /gAuth login <password> to perform this action.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,10 @@ public class EntityDamageEvent {
|
|||
|
||||
if (var2 instanceof LivingEntity livingEntity) {
|
||||
EntityMetadata metadata = EntityMetadata.getEntityMetadata(livingEntity);
|
||||
// Don't set custom name for champion mobs (they have bossbar instead)
|
||||
if (metadata.championTier > 0) {
|
||||
return;
|
||||
}
|
||||
if (metadata.level > 1 || metadata.prestige > 1) {
|
||||
ChatColor levelColor = EntityMetadata.getLevelColor(metadata.level);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package org.gsdistance.grimmsServer.Events.Listeners;
|
||||
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.gsdistance.grimmsServer.Constructable.Entity.EntityMetadata;
|
||||
import org.gsdistance.grimmsServer.Manage.CustomEntityManager;
|
||||
|
||||
public class EntityRemoveEvent {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,12 @@ public class EntitySpawnEvent {
|
|||
|
||||
public static void Event(org.bukkit.event.entity.EntitySpawnEvent event) {
|
||||
if (event.getEntity().getType() != EntityType.PLAYER) {
|
||||
// Skip if this is a champion spawn (handled by SpawnChampion command)
|
||||
if (event.getEntity().hasMetadata("champion_spawn")) {
|
||||
event.getEntity().removeMetadata("champion_spawn", org.gsdistance.grimmsServer.GrimmsServer.instance);
|
||||
return;
|
||||
}
|
||||
|
||||
CustomEntityManager.registerEntity(event.getEntity());
|
||||
// getEntityMetadata handles both new entities (creates & levels) and chunk reloads (loads from disk without releveling)
|
||||
EntityMetadata.getEntityMetadata(event.getEntity());
|
||||
|
|
|
|||
|
|
@ -11,65 +11,65 @@ import org.gsdistance.grimmsServer.Constructable.Item.CustomItemHandler;
|
|||
import org.gsdistance.grimmsServer.Constructable.Item.ItemStats;
|
||||
|
||||
public class GunFireEvent {
|
||||
|
||||
|
||||
public static void Event(PlayerInteractEvent event) {
|
||||
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Player player = event.getPlayer();
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
|
||||
if (item == null || !CustomItemHandler.isCustomItem(item)) {
|
||||
|
||||
if (!CustomItemHandler.isCustomItem(item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
CustomItemHandler handler = CustomItemHandler.getHandler(item);
|
||||
String itemId = handler.getCustomItemId();
|
||||
|
||||
|
||||
// Handle ammo reloading
|
||||
if (itemId.startsWith("ammo_")) {
|
||||
handleReloading(player, handler, itemId);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Handle gun firing
|
||||
if (!itemId.startsWith("gun_")) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Get gun properties from NBT
|
||||
String gunType = handler.getCustomData("gun_type", PersistentDataType.STRING);
|
||||
Double damage = handler.getCustomData("damage", PersistentDataType.DOUBLE);
|
||||
Integer currentAmmo = handler.getCustomData("current_ammo", PersistentDataType.INTEGER);
|
||||
Integer maxAmmo = handler.getCustomData("max_ammo", PersistentDataType.INTEGER);
|
||||
String projectileType = handler.getCustomData("projectile_type", PersistentDataType.STRING);
|
||||
|
||||
|
||||
if (currentAmmo == null || currentAmmo <= 0) {
|
||||
player.sendMessage(ChatColor.RED + "Out of ammo! Right-click with ammo to reload.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Fire the gun
|
||||
fireProjectile(player, damage, projectileType);
|
||||
|
||||
|
||||
// Decrease ammo
|
||||
handler.setCustomData("current_ammo", currentAmmo - 1, PersistentDataType.INTEGER);
|
||||
|
||||
|
||||
// Update item stats to show new ammo count
|
||||
ItemStats.getItemStats(item).UpdateItemStats();
|
||||
|
||||
|
||||
player.sendMessage(ChatColor.GREEN + "Fired " + ChatColor.GOLD + gunType + ChatColor.GREEN + "! Ammo: " + ChatColor.YELLOW + (currentAmmo - 1) + "/" + maxAmmo);
|
||||
}
|
||||
|
||||
|
||||
private static void handleReloading(Player player, CustomItemHandler ammoHandler, String ammoId) {
|
||||
// Extract gun type from ammo ID (e.g., "ammo_pistol" -> "pistol")
|
||||
String gunType = ammoId.replace("ammo_", "");
|
||||
|
||||
|
||||
// Find gun in player's inventory
|
||||
ItemStack gunItem = null;
|
||||
for (ItemStack item : player.getInventory().getContents()) {
|
||||
if (item != null && CustomItemHandler.isCustomItem(item)) {
|
||||
if (CustomItemHandler.isCustomItem(item)) {
|
||||
CustomItemHandler gunHandler = CustomItemHandler.getHandler(item);
|
||||
String gunItemId = gunHandler.getCustomItemId();
|
||||
if (gunItemId.startsWith("gun_")) {
|
||||
|
|
@ -81,34 +81,34 @@ public class GunFireEvent {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (gunItem == null) {
|
||||
player.sendMessage(ChatColor.RED + "No matching gun found for this ammo!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
CustomItemHandler gunHandler = CustomItemHandler.getHandler(gunItem);
|
||||
Integer currentAmmo = gunHandler.getCustomData("current_ammo", PersistentDataType.INTEGER);
|
||||
Integer maxAmmo = gunHandler.getCustomData("max_ammo", PersistentDataType.INTEGER);
|
||||
Integer ammoAmount = ammoHandler.getCustomData("ammo_amount", PersistentDataType.INTEGER);
|
||||
|
||||
|
||||
if (currentAmmo == null || maxAmmo == null || ammoAmount == null) {
|
||||
player.sendMessage(ChatColor.RED + "Failed to reload: Invalid item data.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Calculate how much ammo to add
|
||||
int ammoNeeded = maxAmmo - currentAmmo;
|
||||
int ammoToAdd = Math.min(ammoNeeded, ammoAmount);
|
||||
|
||||
|
||||
if (ammoToAdd <= 0) {
|
||||
player.sendMessage(ChatColor.YELLOW + "Gun is already fully loaded!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Add ammo to gun
|
||||
gunHandler.setCustomData("current_ammo", currentAmmo + ammoToAdd, PersistentDataType.INTEGER);
|
||||
|
||||
|
||||
// Consume ammo from ammo item
|
||||
int remainingAmmo = ammoAmount - ammoToAdd;
|
||||
if (remainingAmmo <= 0) {
|
||||
|
|
@ -120,20 +120,20 @@ public class GunFireEvent {
|
|||
ammoHandler.setCustomData("ammo_amount", remainingAmmo, PersistentDataType.INTEGER);
|
||||
player.sendMessage(ChatColor.GREEN + "Reloaded " + ChatColor.GOLD + gunType + ChatColor.GREEN + " with " + ChatColor.YELLOW + ammoToAdd + ChatColor.GREEN + " rounds. Remaining ammo: " + ChatColor.YELLOW + remainingAmmo);
|
||||
}
|
||||
|
||||
|
||||
// Update gun item stats
|
||||
ItemStats.getItemStats(gunItem).UpdateItemStats();
|
||||
}
|
||||
|
||||
|
||||
private static void fireProjectile(Player player, Double damage, String projectileType) {
|
||||
// Spawn projectile entity and set its damage
|
||||
// Using snowball as a basic projectile for now
|
||||
Snowball projectile = player.launchProjectile(Snowball.class);
|
||||
|
||||
|
||||
// Set custom damage on the projectile (you may need a custom entity system for this)
|
||||
// For now, we'll store the damage in the projectile's metadata
|
||||
projectile.setCustomName("gun_projectile_" + damage);
|
||||
|
||||
|
||||
// You can extend this with different projectile types based on projectileType
|
||||
// For example: arrows, fireballs, or custom entities
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,10 +34,10 @@ public class PlayerRespawnEvent {
|
|||
PlayerInventoryData inventoryData = PlayerInventoryData.getPlayerInventoryData(player.getUniqueId());
|
||||
|
||||
// Check if there are soulbound items to restore
|
||||
if ((inventoryData.soulboundInventoryContents != null && !inventoryData.soulboundInventoryContents.isEmpty()) ||
|
||||
hasNonNullItems(inventoryData.soulboundArmorContents) ||
|
||||
hasNonNullItems(inventoryData.soulboundExtraContents)) {
|
||||
|
||||
if ((inventoryData.soulboundInventoryContents != null && !inventoryData.soulboundInventoryContents.isEmpty()) ||
|
||||
hasNonNullItems(inventoryData.soulboundArmorContents) ||
|
||||
hasNonNullItems(inventoryData.soulboundExtraContents)) {
|
||||
|
||||
// Restore soulbound inventory items
|
||||
Map<Integer, ItemStack> soulboundInventory = inventoryData.getSoulboundInventoryAsItemStacks();
|
||||
for (Map.Entry<Integer, ItemStack> entry : soulboundInventory.entrySet()) {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,12 @@ public class ServerTickEvent {
|
|||
}
|
||||
|
||||
PlayerTickEvent.processMagnets();
|
||||
|
||||
// Execute champion mob abilities every 20 ticks (1 second) to reduce load
|
||||
if (ticks % 20L == 0L) {
|
||||
ChampionTickEvent.Event();
|
||||
}
|
||||
|
||||
++ticks;
|
||||
if (ticks % 1000L == 0L) {
|
||||
Market market = Market.getMarket();
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ public final class GrimmsServer extends JavaPlugin {
|
|||
return rt;
|
||||
}
|
||||
|
||||
public void registerCustomItems(){
|
||||
public void registerCustomItems() {
|
||||
CustomItemRegistry.registerGunTypes();
|
||||
CustomItemRegistry.registerAmmoTypes();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
package org.gsdistance.grimmsServer.Manage;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
|
@ -26,7 +28,9 @@ public class CustomEntityManager {
|
|||
}
|
||||
|
||||
public static void loadFromFile() {
|
||||
List<UUID> loaded = GrimmsServer.pds.retrieveData("entityRegistry.json", "customEntities", List.class);
|
||||
Type listType = new TypeToken<List<UUID>>() {
|
||||
}.getType();
|
||||
List<UUID> loaded = GrimmsServer.pds.retrieveData("entityRegistry.json", "customEntities", listType);
|
||||
if (loaded != null) {
|
||||
currentRegistry.clear();
|
||||
currentRegistry.addAll(loaded);
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class Shared {
|
|||
public static void updateResource(String resourcePath, boolean isDirectory) {
|
||||
GrimmsServer.logger.info("Updating resource: " + resourcePath);
|
||||
File targetFolder = new File(GrimmsServer.instance.getDataFolder(), resourcePath);
|
||||
|
||||
|
||||
if (isDirectory) {
|
||||
// Get list of files in JAR for this resource path
|
||||
java.util.Set<String> jarFiles = new java.util.HashSet<>();
|
||||
|
|
@ -67,7 +67,7 @@ public class Shared {
|
|||
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();
|
||||
|
|
@ -85,7 +85,7 @@ public class Shared {
|
|||
targetFolder.delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
saveResourceIfNotExists(resourcePath, isDirectory);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,27 +12,27 @@ import java.util.UUID;
|
|||
public class PlayerTitles {
|
||||
// Static titles (manually awarded or event-based)
|
||||
private static final Map<String, String> staticTitles = Map.ofEntries(
|
||||
Map.entry("Dictator", "The title of a dictator, not to be messed with."),
|
||||
Map.entry("Executioner", "The title and power of execution."),
|
||||
Map.entry("Murderer", "Someone whose crimes follow him till death."),
|
||||
Map.entry("Victim", "Got murdered, unfortunate."),
|
||||
Map.entry("DragonSlayer", "The fabled warrior to defeat the fabled dragon or something like that."),
|
||||
Map.entry("Newbie", "Wowie! Joining the game gives a title!"),
|
||||
Map.entry("Titlemaxxer", "Get more than 5 titles"),
|
||||
Map.entry("Leader", "You got on the leaderboard."),
|
||||
Map.entry("Null", "Not a title bro."),
|
||||
Map.entry("BugSlayer", "Reported a bug."),
|
||||
Map.entry("ExploitDestroyer", "Reported an exploit."),
|
||||
Map.entry("Disgrace.", "Abused an exploit.")
|
||||
Map.entry("Dictator", "The title of a dictator, not to be messed with."),
|
||||
Map.entry("Executioner", "The title and power of execution."),
|
||||
Map.entry("Murderer", "Someone whose crimes follow him till death."),
|
||||
Map.entry("Victim", "Got murdered, unfortunate."),
|
||||
Map.entry("DragonSlayer", "The fabled warrior to defeat the fabled dragon or something like that."),
|
||||
Map.entry("Newbie", "Wowie! Joining the game gives a title!"),
|
||||
Map.entry("Titlemaxxer", "Get more than 5 titles"),
|
||||
Map.entry("Leader", "You got on the leaderboard."),
|
||||
Map.entry("Null", "Not a title bro."),
|
||||
Map.entry("BugSlayer", "Reported a bug."),
|
||||
Map.entry("ExploitDestroyer", "Reported an exploit."),
|
||||
Map.entry("Disgrace.", "Abused an exploit.")
|
||||
);
|
||||
|
||||
|
||||
// Dynamic titles (based on stats) - populated on-demand
|
||||
public static Map<String, String> titles = new HashMap<>();
|
||||
|
||||
|
||||
static {
|
||||
titles.putAll(staticTitles);
|
||||
}
|
||||
|
||||
|
||||
private final Player player;
|
||||
|
||||
public PlayerTitles(Player player) {
|
||||
|
|
@ -50,7 +50,7 @@ public class PlayerTitles {
|
|||
}
|
||||
return new OfflinePlayerTitles(metadata);
|
||||
}
|
||||
|
||||
|
||||
// Populate dynamic titles from TitleGenerator
|
||||
public static void populateDynamicTitles() {
|
||||
titles.putAll(TitleGenerator.getAllMoneyTitles());
|
||||
|
|
|
|||
|
|
@ -8,44 +8,44 @@ public enum TitleCriteria {
|
|||
NEWBIE("Newbie", "Wowie! Joining the game gives a title!", player -> true),
|
||||
|
||||
MURDERER("Murderer", "Someone whose crimes follow him till death.", player ->
|
||||
PlayerStats.getPlayerStats(player).getStat("total_kill_count", Integer.class) > 0),
|
||||
PlayerStats.getPlayerStats(player).getStat("total_kill_count", Integer.class) > 0),
|
||||
|
||||
VICTIM("Victim", "Got murdered, unfortunate.", player ->
|
||||
PlayerStats.getPlayerStats(player).getStat("death_count", Integer.class) > 0),
|
||||
PlayerStats.getPlayerStats(player).getStat("death_count", Integer.class) > 0),
|
||||
|
||||
DRAGON_SLAYER("DragonSlayer", "The fabled warrior to defeat the fabled dragon or something like that.", player ->
|
||||
false), // Dragon kills not tracked in persistent stats
|
||||
false), // Dragon kills not tracked in persistent stats
|
||||
|
||||
LEADER("Leader", "You got on the leaderboard.", player ->
|
||||
false), // Leaderboard status not tracked in persistent stats
|
||||
false), // Leaderboard status not tracked in persistent stats
|
||||
|
||||
TITLEMAXXER("Titlemaxxer", "Get more than 5 titles", player ->
|
||||
PlayerTitles.getPlayerTitles(player).getTitles().size() > 5);
|
||||
|
||||
PlayerTitles.getPlayerTitles(player).getTitles().size() > 5);
|
||||
|
||||
private final String titleId;
|
||||
private final String description;
|
||||
private final Predicate<Player> condition;
|
||||
|
||||
|
||||
TitleCriteria(String titleId, String description, Predicate<Player> condition) {
|
||||
this.titleId = titleId;
|
||||
this.description = description;
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
|
||||
public String getTitleId() {
|
||||
return titleId;
|
||||
}
|
||||
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
|
||||
public boolean test(Player player) {
|
||||
return condition.test(player);
|
||||
}
|
||||
|
||||
|
||||
// Special titles that are manually awarded (not auto-checked)
|
||||
public static final String[] MANUAL_TITLES = {
|
||||
"Dictator", "Executioner", "BugSlayer", "ExploitDestroyer", "Disgrace."
|
||||
"Dictator", "Executioner", "BugSlayer", "ExploitDestroyer", "Disgrace."
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ public class TitleGenerator {
|
|||
private static final Map<Long, String> blockBreakTitles = new HashMap<>();
|
||||
private static final Map<Long, String> killTitles = new HashMap<>();
|
||||
private static final Map<String, String> titleDescriptions = new HashMap<>();
|
||||
|
||||
|
||||
static {
|
||||
// Money titles (powers of 10)
|
||||
moneyTitles.put("10", "Pocket Change");
|
||||
|
|
@ -31,7 +31,7 @@ public class TitleGenerator {
|
|||
moneyTitles.put("10000000000000000", "Multi-Quadrillionaire");
|
||||
moneyTitles.put("100000000000000000", "Hundred-Quadrillionaire");
|
||||
moneyTitles.put("1000000000000000000", "Quintillionaire");
|
||||
|
||||
|
||||
// Block break titles (powers of 10)
|
||||
blockBreakTitles.put(10L, "Novice Miner");
|
||||
blockBreakTitles.put(100L, "Apprentice Miner");
|
||||
|
|
@ -48,7 +48,7 @@ public class TitleGenerator {
|
|||
blockBreakTitles.put(10000000000000L, "Cosmic Miner");
|
||||
blockBreakTitles.put(100000000000000L, "Galaxy Breaker");
|
||||
blockBreakTitles.put(1000000000000000L, "Universal Miner");
|
||||
|
||||
|
||||
// Kill titles (powers of 10)
|
||||
killTitles.put(10L, "Novice Hunter");
|
||||
killTitles.put(100L, "Hunter");
|
||||
|
|
@ -65,7 +65,7 @@ public class TitleGenerator {
|
|||
killTitles.put(10000000000000L, "Reality Destroyer");
|
||||
killTitles.put(100000000000000L, "Void Consumer");
|
||||
killTitles.put(1000000000000000L, "Oblivion");
|
||||
|
||||
|
||||
// Money title descriptions
|
||||
titleDescriptions.put("Pocket Change", "A small amount of money, but it's a start.");
|
||||
titleDescriptions.put("Coin Collector", "Starting to accumulate some wealth.");
|
||||
|
|
@ -85,7 +85,7 @@ public class TitleGenerator {
|
|||
titleDescriptions.put("Multi-Quadrillionaire", "Wealth that defies comprehension.");
|
||||
titleDescriptions.put("Hundred-Quadrillionaire", "You possess more than can be counted.");
|
||||
titleDescriptions.put("Quintillionaire", "The pinnacle of financial achievement.");
|
||||
|
||||
|
||||
// Block break title descriptions
|
||||
titleDescriptions.put("Novice Miner", "Just starting to break blocks.");
|
||||
titleDescriptions.put("Apprentice Miner", "Learning the ways of the mine.");
|
||||
|
|
@ -102,7 +102,7 @@ public class TitleGenerator {
|
|||
titleDescriptions.put("Cosmic Miner", "You mine among the stars themselves.");
|
||||
titleDescriptions.put("Galaxy Breaker", "You break through entire galaxies.");
|
||||
titleDescriptions.put("Universal Miner", "You mine across all of existence.");
|
||||
|
||||
|
||||
// Kill title descriptions
|
||||
titleDescriptions.put("Novice Hunter", "Just starting your hunting journey.");
|
||||
titleDescriptions.put("Hunter", "You've proven yourself as a capable hunter.");
|
||||
|
|
@ -120,7 +120,7 @@ public class TitleGenerator {
|
|||
titleDescriptions.put("Void Consumer", "You consume all in your path, even the void.");
|
||||
titleDescriptions.put("Oblivion", "You are the end of all things.");
|
||||
}
|
||||
|
||||
|
||||
public static List<String> getMoneyTitles(double money) {
|
||||
List<String> earnedTitles = new ArrayList<>();
|
||||
// Check all money titles from lowest to highest
|
||||
|
|
@ -132,7 +132,7 @@ public class TitleGenerator {
|
|||
}
|
||||
return earnedTitles;
|
||||
}
|
||||
|
||||
|
||||
public static List<String> getBlockBreakTitles(long blockBreaks) {
|
||||
List<String> earnedTitles = new ArrayList<>();
|
||||
// Check all block break titles from lowest to highest
|
||||
|
|
@ -143,7 +143,7 @@ public class TitleGenerator {
|
|||
}
|
||||
return earnedTitles;
|
||||
}
|
||||
|
||||
|
||||
public static List<String> getKillTitles(long kills) {
|
||||
List<String> earnedTitles = new ArrayList<>();
|
||||
// Check all kill titles from lowest to highest
|
||||
|
|
@ -154,23 +154,23 @@ public class TitleGenerator {
|
|||
}
|
||||
return earnedTitles;
|
||||
}
|
||||
|
||||
|
||||
public static Map<String, String> getAllMoneyTitles() {
|
||||
return new HashMap<>(moneyTitles);
|
||||
}
|
||||
|
||||
|
||||
public static Map<Long, String> getAllBlockBreakTitles() {
|
||||
return new HashMap<>(blockBreakTitles);
|
||||
}
|
||||
|
||||
|
||||
public static Map<Long, String> getAllKillTitles() {
|
||||
return new HashMap<>(killTitles);
|
||||
}
|
||||
|
||||
|
||||
public static Map<String, String> getAllTitleDescriptions() {
|
||||
return new HashMap<>(titleDescriptions);
|
||||
}
|
||||
|
||||
|
||||
public static String getTitleDescription(String title) {
|
||||
return titleDescriptions.get(title);
|
||||
}
|
||||
|
|
|
|||
1
src/main/resources/build.v
Normal file
1
src/main/resources/build.v
Normal file
|
|
@ -0,0 +1 @@
|
|||
7
|
||||
Loading…
Add table
Add a link
Reference in a new issue