1.5.6 p1
This commit is contained in:
parent
1e6d0506f3
commit
a554309aa7
23 changed files with 1024 additions and 51 deletions
Binary file not shown.
Binary file not shown.
1
.idea/dictionaries/project.xml
generated
1
.idea/dictionaries/project.xml
generated
|
|
@ -2,6 +2,7 @@
|
|||
<dictionary name="project">
|
||||
<words>
|
||||
<w>grimms</w>
|
||||
<w>soulbound</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
</component>
|
||||
Binary file not shown.
|
|
@ -0,0 +1,170 @@
|
|||
package org.gsdistance.grimmsServer.Commands.GUtilCommand;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.gsdistance.grimmsServer.Constructable.Item.CustomEnchantmentHandler;
|
||||
import org.gsdistance.grimmsServer.Data.CustomEnchantments;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class Enchant {
|
||||
|
||||
public Enchant() {
|
||||
}
|
||||
|
||||
public static boolean subCommand(Player player, String[] args) {
|
||||
// Guard: Permission Check
|
||||
if (!player.hasPermission("grimmsserver.util.admin")) {
|
||||
player.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Guard: Minimum arguments requirement
|
||||
if (args.length < 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case "add" -> {
|
||||
if (args.length < 4) {
|
||||
player.sendMessage(ChatColor.RED + "Usage: /gutil enchant add <enchantment> [level]");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
CustomEnchantments enchantment = CustomEnchantments.valueOf(args[2].toUpperCase());
|
||||
int level = args.length >= 4 ? Integer.parseInt(args[3]) : 1;
|
||||
|
||||
CustomEnchantmentHandler handler = CustomEnchantmentHandler.getHandler(item);
|
||||
if (handler.addEnchantment(enchantment, level)) {
|
||||
player.sendMessage(ChatColor.GREEN + "Added " + ChatColor.GOLD + enchantment.enchantmentName +
|
||||
ChatColor.GREEN + " level " + ChatColor.YELLOW + level + ChatColor.GREEN + " to " + item.getType());
|
||||
return true;
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "Failed to add enchantment. Check if level exceeds maximum or enchantment already exists.");
|
||||
return false;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
player.sendMessage(ChatColor.RED + "Invalid level: " + args[3]);
|
||||
return false;
|
||||
} catch (IllegalArgumentException e) {
|
||||
player.sendMessage(ChatColor.RED + "Invalid enchantment: " + args[2]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
case "remove" -> {
|
||||
if (args.length < 3) {
|
||||
player.sendMessage(ChatColor.RED + "Usage: /gutil enchant remove <enchantment>");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
CustomEnchantments enchantment = CustomEnchantments.valueOf(args[2].toUpperCase());
|
||||
|
||||
CustomEnchantmentHandler handler = CustomEnchantmentHandler.getHandler(item);
|
||||
if (handler.removeEnchantment(enchantment)) {
|
||||
player.sendMessage(ChatColor.GREEN + "Removed " + ChatColor.GOLD + enchantment.enchantmentName + ChatColor.GREEN + " from " + item.getType());
|
||||
return true;
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "Item does not have that enchantment.");
|
||||
return false;
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
player.sendMessage(ChatColor.RED + "Invalid enchantment: " + args[2]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
case "set" -> {
|
||||
if (args.length < 4) {
|
||||
player.sendMessage(ChatColor.RED + "Usage: /gutil enchant set <enchantment> <level>");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
CustomEnchantments enchantment = CustomEnchantments.valueOf(args[2].toUpperCase());
|
||||
int level = Integer.parseInt(args[3]);
|
||||
|
||||
CustomEnchantmentHandler handler = CustomEnchantmentHandler.getHandler(item);
|
||||
if (handler.setEnchantmentLevel(enchantment, level)) {
|
||||
player.sendMessage(ChatColor.GREEN + "Set " + ChatColor.GOLD + enchantment.enchantmentName +
|
||||
ChatColor.GREEN + " to level " + ChatColor.YELLOW + level + ChatColor.GREEN + " on " + item.getType());
|
||||
return true;
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "Failed to set enchantment level. Check if level is valid.");
|
||||
return false;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
player.sendMessage(ChatColor.RED + "Invalid level: " + args[3]);
|
||||
return false;
|
||||
} catch (IllegalArgumentException e) {
|
||||
player.sendMessage(ChatColor.RED + "Invalid enchantment: " + args[2]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
case "list" -> {
|
||||
CustomEnchantmentHandler handler = CustomEnchantmentHandler.getHandler(item);
|
||||
Map<CustomEnchantments, Integer> enchantments = handler.getAllEnchantments();
|
||||
|
||||
if (enchantments.isEmpty()) {
|
||||
player.sendMessage(ChatColor.GRAY + "Item has no custom enchantments.");
|
||||
return true;
|
||||
}
|
||||
|
||||
player.sendMessage(ChatColor.GOLD + "Custom Enchantments on " + item.getType() + ":");
|
||||
for (Map.Entry<CustomEnchantments, Integer> entry : enchantments.entrySet()) {
|
||||
player.sendMessage(ChatColor.YELLOW + "- " + entry.getKey().enchantmentName +
|
||||
ChatColor.GRAY + " (Level " + entry.getValue() + "/" + entry.getKey().maxLevel + ")");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
case "clear" -> {
|
||||
CustomEnchantmentHandler handler = CustomEnchantmentHandler.getHandler(item);
|
||||
handler.clearAllEnchantments();
|
||||
player.sendMessage(ChatColor.GREEN + "Cleared all custom enchantments from " + item.getType());
|
||||
return true;
|
||||
}
|
||||
|
||||
case "has" -> {
|
||||
if (args.length < 3) {
|
||||
player.sendMessage(ChatColor.RED + "Usage: /gutil enchant has <enchantment>");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
CustomEnchantments enchantment = CustomEnchantments.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 +
|
||||
ChatColor.GREEN + " at level " + ChatColor.YELLOW + level);
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + "Item does not have " + enchantment.enchantmentName);
|
||||
}
|
||||
return true;
|
||||
} catch (IllegalArgumentException e) {
|
||||
player.sendMessage(ChatColor.RED + "Invalid enchantment: " + args[2]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
default -> {
|
||||
player.sendMessage(ChatColor.RED + "Unknown enchant command: " + action);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -24,6 +24,12 @@ public class GUtilBaseCommand implements CommandExecutor {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
case "enchant" -> {
|
||||
if (sender instanceof Player player) {
|
||||
return Enchant.subCommand(player, args);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case "capability" -> {
|
||||
if (sender instanceof Player player) {
|
||||
return Capability.subCommand(player, args);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import org.bukkit.command.CommandSender;
|
|||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Constructable.Player.PlayerMetadata;
|
||||
import org.gsdistance.grimmsServer.Data.CustomEnchantments;
|
||||
import org.gsdistance.grimmsServer.Data.Player.PlayerInventoryData;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerTitles;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
|
@ -20,16 +21,22 @@ 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", "capability", "broadcast", "inventoryrestore", "fly", "god", "heal", "speed", "enderchest", "invsee", "addtitle", "removetitle", "unlevelentity", "sudo", "levelentity");
|
||||
public static final List<String> adminSubCommands = List.of("relic", "enchant", "capability", "broadcast", "inventoryrestore", "fly", "god", "heal", "speed", "enderchest", "invsee", "addtitle", "removetitle", "unlevelentity", "sudo", "levelentity");
|
||||
|
||||
private CommandMap cachedCommandMap;
|
||||
|
||||
public GUtilTabCompleter() {
|
||||
}
|
||||
|
||||
private CommandMap getCommandMap() {
|
||||
if (cachedCommandMap != null) {
|
||||
return cachedCommandMap;
|
||||
}
|
||||
try {
|
||||
Field commandMapField = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
||||
commandMapField.setAccessible(true);
|
||||
return (CommandMap) commandMapField.get(Bukkit.getServer());
|
||||
cachedCommandMap = (CommandMap) commandMapField.get(Bukkit.getServer());
|
||||
return cachedCommandMap;
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
throw new RuntimeException("Failed to get command map", e);
|
||||
}
|
||||
|
|
@ -73,13 +80,16 @@ public class GUtilTabCompleter implements TabCompleter {
|
|||
case "relic" -> {
|
||||
return List.of("make", "set", "recalc", "reroll");
|
||||
}
|
||||
case "enchant" -> {
|
||||
return List.of("add", "remove", "set", "list", "clear", "has");
|
||||
}
|
||||
case "version" -> {
|
||||
return List.of("check", "update");
|
||||
}
|
||||
case "setting" -> {
|
||||
return PlayerMetadata.getPlayerMetadata(player).settings.stream().toList();
|
||||
}
|
||||
case "inventoryrestore", "heal", "spawn", "enderchest", "invsee", "addtitle", "removetitle", "sudo", "unlevelentity", "levelentity" -> {
|
||||
case "inventoryrestore", "heal", "spawn", "enderchest", "invsee", "addtitle", "removetitle", "sudo" -> {
|
||||
return Bukkit.getOnlinePlayers().stream()
|
||||
.map(Player::getName)
|
||||
.filter(name -> name.toLowerCase().startsWith(args[1].toLowerCase()))
|
||||
|
|
@ -95,12 +105,54 @@ public class GUtilTabCompleter implements TabCompleter {
|
|||
.filter(type -> type.startsWith(args[1].toLowerCase()))
|
||||
.toList();
|
||||
}
|
||||
case "levelentity", "unlevelentity" -> {
|
||||
return player.getWorld().getEntities().stream()
|
||||
.map(entity -> entity.getUniqueId().toString())
|
||||
.filter(uuid -> uuid.toLowerCase().startsWith(args[1].toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
default -> {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
} else if (args.length > 3 && args[0].equalsIgnoreCase("sudo")) {
|
||||
// Handle nested tab completion for sudo command
|
||||
String commandName = args[2];
|
||||
org.bukkit.command.Command targetCommand = getCommandMap().getCommand(commandName);
|
||||
if (targetCommand != null) {
|
||||
TabCompleter tabCompleter = getTabCompleter(targetCommand);
|
||||
if (tabCompleter != null) {
|
||||
// Build the args array for the target command
|
||||
String[] targetArgs = new String[args.length - 3];
|
||||
System.arraycopy(args, 3, targetArgs, 0, targetArgs.length);
|
||||
return tabCompleter.onTabComplete(sender, targetCommand, commandName, targetArgs);
|
||||
}
|
||||
}
|
||||
return List.of();
|
||||
} 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")) {
|
||||
return java.util.Arrays.stream(CustomEnchantments.values())
|
||||
.map(enchant -> enchant.name().toLowerCase())
|
||||
.filter(name -> name.startsWith(args[2].toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
case "relic" -> {
|
||||
if (args[1].equalsIgnoreCase("set")) {
|
||||
List<String> tiers = new ArrayList<>();
|
||||
for (int i = 1; i <= 10; i++) {
|
||||
tiers.add(String.valueOf(i));
|
||||
}
|
||||
return tiers.stream()
|
||||
.filter(tier -> tier.startsWith(args[2]))
|
||||
.toList();
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
case "speed" -> {
|
||||
List<String> speeds = new ArrayList<>();
|
||||
for (int i = 1; i <= 10; i++) {
|
||||
|
|
@ -149,20 +201,59 @@ public class GUtilTabCompleter implements TabCompleter {
|
|||
return List.of();
|
||||
}
|
||||
}
|
||||
} else if (args.length >= 3 && args[0].equalsIgnoreCase("sudo")) {
|
||||
// Handle nested tab completion for sudo command
|
||||
String commandName = args[2];
|
||||
org.bukkit.command.Command targetCommand = getCommandMap().getCommand(commandName);
|
||||
if (targetCommand != null) {
|
||||
TabCompleter tabCompleter = getTabCompleter(targetCommand);
|
||||
if (tabCompleter != null) {
|
||||
// Build the args array for the target command
|
||||
String[] targetArgs = new String[args.length - 3];
|
||||
System.arraycopy(args, 3, targetArgs, 0, targetArgs.length);
|
||||
return tabCompleter.onTabComplete(sender, targetCommand, commandName, targetArgs);
|
||||
} else if (args.length == 4) {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "enchant" -> {
|
||||
if (args[1].equalsIgnoreCase("add") || args[1].equalsIgnoreCase("set")) {
|
||||
try {
|
||||
CustomEnchantments enchantment = CustomEnchantments.valueOf(args[2].toUpperCase());
|
||||
List<String> levels = new ArrayList<>();
|
||||
for (int i = 1; i <= enchantment.maxLevel; i++) {
|
||||
levels.add(String.valueOf(i));
|
||||
}
|
||||
return levels.stream()
|
||||
.filter(level -> level.startsWith(args[3]))
|
||||
.collect(Collectors.toList());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
case "relic" -> {
|
||||
if (args[1].equalsIgnoreCase("set")) {
|
||||
List<String> grades = new ArrayList<>();
|
||||
for (int i = 1; i <= 10; i++) {
|
||||
grades.add(String.valueOf(i));
|
||||
}
|
||||
return grades.stream()
|
||||
.filter(grade -> grade.startsWith(args[3]))
|
||||
.toList();
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
default -> {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
} else if (args.length == 5) {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "relic" -> {
|
||||
if (args[1].equalsIgnoreCase("set")) {
|
||||
List<String> resistances = new ArrayList<>();
|
||||
for (int i = 1; i <= 100; i++) {
|
||||
resistances.add(String.valueOf(i));
|
||||
}
|
||||
return resistances.stream()
|
||||
.filter(res -> res.startsWith(args[4]))
|
||||
.toList();
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
default -> {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return List.of();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,131 @@
|
|||
package org.gsdistance.grimmsServer.Constructable.Item;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.gsdistance.grimmsServer.Data.CustomEnchantments;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CustomEnchantmentHandler {
|
||||
private final ItemStack item;
|
||||
private final ItemDataHandler dataHandler;
|
||||
private static final String ENCHANTMENT_PREFIX = "custom_enchant_";
|
||||
|
||||
public CustomEnchantmentHandler(ItemStack item) {
|
||||
this.item = item;
|
||||
this.dataHandler = ItemDataHandler.getItemDataHandler(item);
|
||||
}
|
||||
|
||||
public static CustomEnchantmentHandler getHandler(ItemStack item) {
|
||||
return new CustomEnchantmentHandler(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a custom enchantment to the item
|
||||
* @param enchantment The enchantment to add
|
||||
* @param level The level of the enchantment
|
||||
* @return true if successful, false if level exceeds max or enchantment already exists
|
||||
*/
|
||||
public boolean addEnchantment(CustomEnchantments enchantment, int level) {
|
||||
if (level < 1 || level > enchantment.maxLevel) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hasEnchantment(enchantment)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String key = ENCHANTMENT_PREFIX + enchantment.name();
|
||||
dataHandler.setItemNBTData(key, level, PersistentDataType.INTEGER);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public boolean removeEnchantment(CustomEnchantments enchantment) {
|
||||
if (!hasEnchantment(enchantment)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String key = ENCHANTMENT_PREFIX + enchantment.name();
|
||||
// To remove, we set it to null or use a different approach
|
||||
// Since ItemDataHandler doesn't have a remove method, we'll need to handle this
|
||||
// For now, let's implement a workaround by setting to 0
|
||||
dataHandler.setItemNBTData(key, 0, PersistentDataType.INTEGER);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public boolean hasEnchantment(CustomEnchantments enchantment) {
|
||||
return getEnchantmentLevel(enchantment) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public int getEnchantmentLevel(CustomEnchantments enchantment) {
|
||||
String key = ENCHANTMENT_PREFIX + enchantment.name();
|
||||
Integer level = dataHandler.getItemNBTData(key, PersistentDataType.INTEGER);
|
||||
return level != null ? level : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all custom enchantments on the item
|
||||
* @return A map of enchantments to their levels
|
||||
*/
|
||||
public Map<CustomEnchantments, Integer> getAllEnchantments() {
|
||||
Map<CustomEnchantments, Integer> enchantments = new HashMap<>();
|
||||
|
||||
for (CustomEnchantments enchantment : CustomEnchantments.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
|
||||
* @return true if successful, false if level is invalid
|
||||
*/
|
||||
public boolean setEnchantmentLevel(CustomEnchantments enchantment, int level) {
|
||||
if (level < 0 || level > enchantment.maxLevel) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String key = ENCHANTMENT_PREFIX + enchantment.name();
|
||||
dataHandler.setItemNBTData(key, level, PersistentDataType.INTEGER);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all custom enchantments from the item
|
||||
*/
|
||||
public void clearAllEnchantments() {
|
||||
for (CustomEnchantments enchantment : CustomEnchantments.values()) {
|
||||
setEnchantmentLevel(enchantment, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the item has any custom enchantments
|
||||
* @return true if the item has at least one custom enchantment
|
||||
*/
|
||||
public boolean hasAnyEnchantments() {
|
||||
return !getAllEnchantments().isEmpty();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package org.gsdistance.grimmsServer.Constructable.Item;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public abstract class CustomItem {
|
||||
private final String itemId;
|
||||
private final ItemStack itemStack;
|
||||
private final CustomItemHandler handler;
|
||||
|
||||
public CustomItem(String itemId, ItemStack itemStack) {
|
||||
this.itemId = itemId;
|
||||
this.itemStack = itemStack;
|
||||
this.handler = CustomItemHandler.getHandler(itemStack);
|
||||
if (this.handler == null) {
|
||||
throw new IllegalArgumentException("ItemStack must be initialized with CustomItemHandler first");
|
||||
}
|
||||
this.handler.setCustomItemId(itemId);
|
||||
this.initializeItem();
|
||||
}
|
||||
|
||||
protected abstract void initializeItem();
|
||||
|
||||
public String getItemId() {
|
||||
return itemId;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public CustomItemHandler getHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
public Material getMaterial() {
|
||||
return itemStack.getType();
|
||||
}
|
||||
|
||||
public ItemMeta getItemMeta() {
|
||||
return itemStack.getItemMeta();
|
||||
}
|
||||
|
||||
public void setItemMeta(ItemMeta meta) {
|
||||
itemStack.setItemMeta(meta);
|
||||
}
|
||||
|
||||
public abstract String getDisplayName();
|
||||
|
||||
public abstract String getDescription();
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
package org.gsdistance.grimmsServer.Constructable.Item;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
/**
|
||||
* Example custom item implementation showing how to create and register custom items.
|
||||
* This is a template for creating your own custom items.
|
||||
*/
|
||||
public class CustomItemExample extends CustomItem {
|
||||
|
||||
public CustomItemExample(String itemId, ItemStack itemStack) {
|
||||
super(itemId, itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initializeItem() {
|
||||
// Set up the item's initial properties
|
||||
ItemMeta meta = getItemMeta();
|
||||
if (meta != null) {
|
||||
meta.setDisplayName(ChatColor.GOLD + "Custom Example Item");
|
||||
meta.setCustomModelData(1001); // Optional: Set custom model data for resource packs
|
||||
setItemMeta(meta);
|
||||
}
|
||||
|
||||
// Store custom data specific to this item type
|
||||
getHandler().setCustomData("exampleValue", 42, org.bukkit.persistence.PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return ChatColor.GOLD + "Custom Example Item";
|
||||
}
|
||||
|
||||
@Override
|
||||
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.
|
||||
*/
|
||||
public static void register() {
|
||||
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.
|
||||
*/
|
||||
public static ItemStack create() {
|
||||
ItemStack stack = new ItemStack(Material.DIAMOND_SWORD);
|
||||
CustomItemHandler.createHandler(stack);
|
||||
return CustomItemRegistry.createCustomItem("custom_example", stack).getItemStack();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
package org.gsdistance.grimmsServer.Constructable.Item;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class CustomItemHandler {
|
||||
private final ItemStack item;
|
||||
private final ItemDataHandler dataHandler;
|
||||
private static final String CUSTOM_ITEM_KEY = "customItemId";
|
||||
private static final String IS_CUSTOM_ITEM_KEY = "isCustomItem";
|
||||
|
||||
public CustomItemHandler(ItemStack item, @Nullable JavaPlugin plugin) {
|
||||
this.item = item;
|
||||
this.dataHandler = new ItemDataHandler(item, plugin);
|
||||
}
|
||||
|
||||
public static CustomItemHandler getHandler(ItemStack item) {
|
||||
if (item == null || !item.hasItemMeta()) {
|
||||
return null;
|
||||
}
|
||||
return new CustomItemHandler(item, GrimmsServer.instance);
|
||||
}
|
||||
|
||||
public static CustomItemHandler createHandler(ItemStack item) {
|
||||
CustomItemHandler handler = new CustomItemHandler(item, GrimmsServer.instance);
|
||||
handler.initializeCustomItem();
|
||||
return handler;
|
||||
}
|
||||
|
||||
private void initializeCustomItem() {
|
||||
if (!isCustomItem(this.item)) {
|
||||
this.dataHandler.setItemNBTData(IS_CUSTOM_ITEM_KEY, true, PersistentDataType.BOOLEAN);
|
||||
// Set default item ID to vanilla material name
|
||||
String vanillaId = CustomItemRegistry.getVanillaItemId(this.item.getType());
|
||||
this.dataHandler.setItemNBTData(CUSTOM_ITEM_KEY, vanillaId, PersistentDataType.STRING);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isCustomItem(ItemStack item) {
|
||||
if (item == null || !item.hasItemMeta()) {
|
||||
return false;
|
||||
}
|
||||
ItemDataHandler dataHandler = new ItemDataHandler(item, GrimmsServer.instance);
|
||||
Boolean isCustom = dataHandler.getItemNBTData(IS_CUSTOM_ITEM_KEY, PersistentDataType.BOOLEAN);
|
||||
return isCustom != null && isCustom;
|
||||
}
|
||||
|
||||
public String getCustomItemId() {
|
||||
return this.dataHandler.getItemNBTData(CUSTOM_ITEM_KEY, PersistentDataType.STRING);
|
||||
}
|
||||
|
||||
public void setCustomItemId(String itemId) {
|
||||
this.dataHandler.setItemNBTData(CUSTOM_ITEM_KEY, itemId, PersistentDataType.STRING);
|
||||
}
|
||||
|
||||
public <T> T getCustomData(String key, PersistentDataType<?, T> type) {
|
||||
return this.dataHandler.getItemNBTData("custom_" + key, type);
|
||||
}
|
||||
|
||||
public <T> void setCustomData(String key, T value, PersistentDataType<?, T> type) {
|
||||
this.dataHandler.setItemNBTData("custom_" + key, value, type);
|
||||
}
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public ItemDataHandler getDataHandler() {
|
||||
return dataHandler;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
package org.gsdistance.grimmsServer.Constructable.Item;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class CustomItemRegistry {
|
||||
private static final Map<String, CustomItem> customItems = new HashMap<>();
|
||||
private static final Map<String, Function<ItemStack, CustomItem>> itemConstructors = new HashMap<>();
|
||||
|
||||
public static void registerCustomItem(String itemId, Function<ItemStack, CustomItem> constructor) {
|
||||
if (customItems.containsKey(itemId)) {
|
||||
throw new IllegalArgumentException("Custom item with ID " + itemId + " is already registered");
|
||||
}
|
||||
itemConstructors.put(itemId, constructor);
|
||||
}
|
||||
|
||||
public static CustomItem createCustomItem(String itemId, ItemStack itemStack) {
|
||||
Function<ItemStack, CustomItem> constructor = itemConstructors.get(itemId);
|
||||
if (constructor == null) {
|
||||
throw new IllegalArgumentException("No custom item registered with ID " + itemId);
|
||||
}
|
||||
CustomItem customItem = constructor.apply(itemStack);
|
||||
customItems.put(itemId, customItem);
|
||||
return customItem;
|
||||
}
|
||||
|
||||
public static boolean isCustomItemRegistered(String itemId) {
|
||||
return itemConstructors.containsKey(itemId);
|
||||
}
|
||||
|
||||
public static CustomItem getCustomItem(String itemId) {
|
||||
return customItems.get(itemId);
|
||||
}
|
||||
|
||||
public static String getItemId(ItemStack itemStack) {
|
||||
CustomItemHandler handler = CustomItemHandler.getHandler(itemStack);
|
||||
if (handler == null) {
|
||||
return null;
|
||||
}
|
||||
return handler.getCustomItemId();
|
||||
}
|
||||
|
||||
public static boolean isCustomItem(ItemStack itemStack) {
|
||||
return getItemId(itemStack) != null;
|
||||
}
|
||||
|
||||
public static String getVanillaItemId(Material material) {
|
||||
return material.name().toLowerCase();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
package org.gsdistance.grimmsServer.Constructable.Item;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
/**
|
||||
* Custom item implementation for relics that integrates with the new CustomItem system.
|
||||
* This wraps the existing RelicHandler functionality while providing the CustomItem interface.
|
||||
*/
|
||||
public class CustomRelicItem extends CustomItem {
|
||||
private final RelicHandler relicHandler;
|
||||
|
||||
public CustomRelicItem(String itemId, ItemStack itemStack) {
|
||||
super(itemId, itemStack);
|
||||
this.relicHandler = RelicHandler.getRelicHandler(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initializeItem() {
|
||||
// Relic initialization is handled by RelicHandler.makeRelic()
|
||||
// This method is called after the item is already set up as a relic
|
||||
updateDisplayName();
|
||||
}
|
||||
|
||||
private void updateDisplayName() {
|
||||
ItemMeta meta = getItemMeta();
|
||||
if (meta != null) {
|
||||
String relicType = relicHandler.getRelicType();
|
||||
int tier = relicHandler.getRelicTier();
|
||||
ChatColor tierColor = switch (tier) {
|
||||
case 1 -> ChatColor.GREEN;
|
||||
case 2 -> ChatColor.BLUE;
|
||||
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 + "]";
|
||||
meta.setDisplayName(displayName);
|
||||
setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
ItemMeta meta = getItemMeta();
|
||||
if (meta != null && meta.hasDisplayName()) {
|
||||
return meta.getDisplayName();
|
||||
}
|
||||
return ChatColor.GOLD + "Relic";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "A powerful relic with enhanced abilities.";
|
||||
}
|
||||
|
||||
// Delegate methods to RelicHandler for backward compatibility
|
||||
public RelicHandler getRelicHandler() {
|
||||
return relicHandler;
|
||||
}
|
||||
|
||||
public int getRelicTier() {
|
||||
return relicHandler.getRelicTier();
|
||||
}
|
||||
|
||||
public int getRelicGrade() {
|
||||
return relicHandler.getRelicGrade();
|
||||
}
|
||||
|
||||
public int getRelicDurabilityResistance() {
|
||||
return relicHandler.getRelicDurabilityResistance();
|
||||
}
|
||||
|
||||
public String getRelicType() {
|
||||
return relicHandler.getRelicType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register relic items in the CustomItemRegistry.
|
||||
* Call this during plugin startup to enable relic integration.
|
||||
*/
|
||||
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 -> {
|
||||
// This constructor is used when loading existing relics from NBT
|
||||
// The relic should already be initialized via RelicHandler
|
||||
return new CustomRelicItem(itemId, itemStack);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new relic item from a vanilla ItemStack.
|
||||
* This is the preferred way to create new relics.
|
||||
*/
|
||||
public static ItemStack createRelic(ItemStack vanillaItem) {
|
||||
RelicHandler.makeRelic(vanillaItem);
|
||||
return vanillaItem;
|
||||
}
|
||||
}
|
||||
|
|
@ -27,6 +27,23 @@ public class ItemStats {
|
|||
public List<String> getItemStats() {
|
||||
List<String> toolStats = new ArrayList<>();
|
||||
|
||||
if (CustomItemHandler.isCustomItem(this.item)) {
|
||||
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);
|
||||
if (customItem != null) {
|
||||
String description = customItem.getDescription();
|
||||
if (description != null && !description.isEmpty()) {
|
||||
toolStats.add(ChatColor.GRAY + description);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ItemLevelHandler.isItemLevelable(this.item)) {
|
||||
ItemLevelHandler levelHandler = ItemLevelHandler.getLevelHandler(this.item, null);
|
||||
toolStats.add(ChatColor.GOLD + "Level: " + ChatColor.YELLOW + Shared.formatNumber(levelHandler.getLevel()));
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import java.util.UUID;
|
|||
public class RelicHandler {
|
||||
ItemStack item;
|
||||
ItemDataHandler dataHandler;
|
||||
private static final Random RANDOM = new Random();
|
||||
|
||||
public RelicHandler(ItemStack item) {
|
||||
this.item = item;
|
||||
|
|
@ -28,11 +29,26 @@ public class RelicHandler {
|
|||
return isRelic != null && isRelic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrates existing relics to the new CustomItem system.
|
||||
* Call this during plugin startup to update legacy relics.
|
||||
*/
|
||||
public static void migrateRelicToCustomItem(ItemStack item) {
|
||||
if (isRelic(item) && !CustomItemHandler.isCustomItem(item)) {
|
||||
CustomItemHandler customHandler = CustomItemHandler.createHandler(item);
|
||||
String relicType = getRelicHandler(item).getRelicType();
|
||||
customHandler.setCustomItemId("relic_" + relicType);
|
||||
}
|
||||
}
|
||||
|
||||
public static RelicHandler getRelicHandler(ItemStack item) {
|
||||
return new RelicHandler(item);
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
@ -54,13 +70,17 @@ 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();
|
||||
}
|
||||
|
||||
public void initRandomRelicStats() {
|
||||
int tier = (new Random()).nextInt(1, 4);
|
||||
int grade = (new Random()).nextInt(1, 101);
|
||||
int durabilityResistance = (new Random()).nextInt(1, 81);
|
||||
int tier = RANDOM.nextInt(1, 4);
|
||||
int grade = RANDOM.nextInt(1, 101);
|
||||
int durabilityResistance = RANDOM.nextInt(1, 81);
|
||||
this.setRelicStats(tier, grade, durabilityResistance);
|
||||
this.recalculateBaseAttributes();
|
||||
ItemStats.getItemStats(this.item).UpdateItemStats();
|
||||
|
|
@ -97,11 +117,11 @@ public class RelicHandler {
|
|||
};
|
||||
switch (this.getRelicType()) {
|
||||
case "sword":
|
||||
this.dataHandler.setAttribute(Attribute.ATTACK_DAMAGE, new AttributeModifier(Shared.getNamespacedKey("reliic_attack_damage"), baseDamage + Math.pow(Math.max(2.0F, (double) grade / (double) 25.0F), tier), Operation.ADD_NUMBER, EquipmentSlotGroup.MAINHAND));
|
||||
this.dataHandler.setAttribute(Attribute.ATTACK_DAMAGE, new AttributeModifier(Shared.getNamespacedKey("relic_attack_damage"), baseDamage + Math.pow(Math.max(2.0F, (double) grade / (double) 25.0F), tier), Operation.ADD_NUMBER, EquipmentSlotGroup.MAINHAND));
|
||||
if (tier == 1) {
|
||||
this.dataHandler.setAttribute(Attribute.ATTACK_SPEED, new AttributeModifier(Shared.getNamespacedKey("reliic_attack_speed"), -2.4, Operation.ADD_NUMBER, EquipmentSlotGroup.MAINHAND));
|
||||
this.dataHandler.setAttribute(Attribute.ATTACK_SPEED, new AttributeModifier(Shared.getNamespacedKey("relic_attack_speed"), -2.4, Operation.ADD_NUMBER, EquipmentSlotGroup.MAINHAND));
|
||||
} else {
|
||||
this.dataHandler.setAttribute(Attribute.ATTACK_SPEED, new AttributeModifier(Shared.getNamespacedKey("reliic_attack_speed"), -(2.4 - Math.max(Math.max((Math.sqrt(grade) * (double) tier / (double) 10.0F), 2), 1)), Operation.ADD_NUMBER, EquipmentSlotGroup.MAINHAND));
|
||||
this.dataHandler.setAttribute(Attribute.ATTACK_SPEED, new AttributeModifier(Shared.getNamespacedKey("relic_attack_speed"), -(2.4 - Math.max(Math.max((Math.sqrt(grade) * (double) tier / (double) 10.0F), 2), 1)), Operation.ADD_NUMBER, EquipmentSlotGroup.MAINHAND));
|
||||
}
|
||||
break;
|
||||
case "armor":
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
package org.gsdistance.grimmsServer.Data;
|
||||
|
||||
public enum CustomEnchantments {
|
||||
TRUE_DAMAGE("True Damage", 3),
|
||||
SOULBOUND("Soulbound", 1);
|
||||
|
||||
public final String enchantmentName;
|
||||
public final int maxLevel;
|
||||
|
||||
|
||||
CustomEnchantments(String enchantmentName, int maxLevel) {
|
||||
this.enchantmentName = enchantmentName;
|
||||
this.maxLevel = maxLevel;
|
||||
}
|
||||
}
|
||||
|
|
@ -19,16 +19,6 @@ public enum FactionRank {
|
|||
return this.displayName;
|
||||
}
|
||||
|
||||
public static FactionRank fromWeight(int weight) {
|
||||
for (FactionRank rank : values()) {
|
||||
if (rank.weight == weight) {
|
||||
return rank;
|
||||
}
|
||||
}
|
||||
|
||||
return NONE;
|
||||
}
|
||||
|
||||
public static FactionRank fromString(String name) {
|
||||
for (FactionRank rank : values()) {
|
||||
if (rank.displayName.equalsIgnoreCase(name)) {
|
||||
|
|
@ -38,9 +28,4 @@ public enum FactionRank {
|
|||
|
||||
return NONE;
|
||||
}
|
||||
|
||||
// $FF: synthetic method
|
||||
private static FactionRank[] $values() {
|
||||
return new FactionRank[]{LEADER, OFFICER, MEMBER, RECRUIT, NONE};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,4 @@ public enum PlayerCapability {
|
|||
this.description = description;
|
||||
this.capabilityId = capabilityId;
|
||||
}
|
||||
|
||||
// $FF: synthetic method
|
||||
private static PlayerCapability[] $values() {
|
||||
return new PlayerCapability[]{AUTOSELL, MAGNET, VEINMINER, SATURATION_PERK};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,11 @@ public class PlayerInventoryData {
|
|||
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
|
||||
public String[] soulboundExtraContents; // Store as Base64 strings
|
||||
|
||||
public PlayerInventoryData(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
this.timestamp = LocalDateTime.now().toString();
|
||||
|
|
@ -28,6 +33,11 @@ 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];
|
||||
this.soulboundExtraContents = new String[36];
|
||||
}
|
||||
|
||||
public void addPreviousInventory(InventorySnapshot snapshot) {
|
||||
|
|
@ -139,6 +149,97 @@ public class PlayerInventoryData {
|
|||
return result;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
this.soulboundInventoryContents.put(slot, item);
|
||||
}
|
||||
} else if (itemType.equals("armor")) {
|
||||
if (slot >= 0 && slot < 4) {
|
||||
String item = this.armorContents[slot];
|
||||
if (item != null) {
|
||||
this.soulboundArmorContents[slot] = item;
|
||||
this.armorContents[slot] = null;
|
||||
}
|
||||
}
|
||||
} else if (itemType.equals("extra")) {
|
||||
if (slot >= 0 && slot < this.extraContents.length) {
|
||||
String item = this.extraContents[slot];
|
||||
if (item != null) {
|
||||
this.soulboundExtraContents[slot] = item;
|
||||
this.extraContents[slot] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
} catch (IOException e) {
|
||||
GrimmsServer.logger.warning("Failed to serialize soulbound ItemStack at slot " + slot);
|
||||
}
|
||||
}
|
||||
|
||||
// Get soulbound inventory as ItemStacks
|
||||
public Map<Integer, ItemStack> getSoulboundInventoryAsItemStacks() {
|
||||
Map<Integer, ItemStack> result = new HashMap<>();
|
||||
for (Map.Entry<Integer, String> entry : this.soulboundInventoryContents.entrySet()) {
|
||||
try {
|
||||
ItemStack itemStack = itemStackFromBase64(entry.getValue());
|
||||
if (itemStack != null) {
|
||||
result.put(entry.getKey(), itemStack);
|
||||
}
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
GrimmsServer.logger.warning("Failed to deserialize soulbound ItemStack at slot " + entry.getKey());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Get soulbound armor as ItemStack array
|
||||
public ItemStack[] getSoulboundArmorAsItemStacks() {
|
||||
ItemStack[] result = new ItemStack[4];
|
||||
for (int i = 0; i < this.soulboundArmorContents.length && i < 4; i++) {
|
||||
try {
|
||||
result[i] = itemStackFromBase64(this.soulboundArmorContents[i]);
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
GrimmsServer.logger.warning("Failed to deserialize soulbound armor slot " + i);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Get soulbound extra contents as ItemStack array
|
||||
public ItemStack[] getSoulboundExtraAsItemStacks() {
|
||||
ItemStack[] result = new ItemStack[this.soulboundExtraContents.length];
|
||||
for (int i = 0; i < this.soulboundExtraContents.length; i++) {
|
||||
try {
|
||||
result[i] = itemStackFromBase64(this.soulboundExtraContents[i]);
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
GrimmsServer.logger.warning("Failed to deserialize soulbound extra slot " + i);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Clear all soulbound items (called after restoring on respawn)
|
||||
public void clearSoulboundItems() {
|
||||
this.soulboundInventoryContents.clear();
|
||||
this.soulboundArmorContents = new String[4];
|
||||
this.soulboundExtraContents = new String[36];
|
||||
}
|
||||
|
||||
public static class InventorySnapshot {
|
||||
public final String timestamp;
|
||||
public Map<Integer, String> inventoryContents; // Store as Base64 strings
|
||||
|
|
|
|||
|
|
@ -40,8 +40,4 @@ public enum PlayerRank {
|
|||
return DEFAULT;
|
||||
}
|
||||
|
||||
// $FF: synthetic method
|
||||
private static PlayerRank[] $values() {
|
||||
return new PlayerRank[]{DEFAULT, VIP, MVP, MODERATOR, ADMIN, OWNER};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ import org.bukkit.entity.Player;
|
|||
import org.bukkit.inventory.ItemStack;
|
||||
import org.gsdistance.grimmsServer.Config.ActiveConfig;
|
||||
import org.gsdistance.grimmsServer.Config.ConfigKey;
|
||||
import org.gsdistance.grimmsServer.Constructable.Item.CustomEnchantmentHandler;
|
||||
import org.gsdistance.grimmsServer.Constructable.Player.PlayerLevelHandler;
|
||||
import org.gsdistance.grimmsServer.Data.CustomEnchantments;
|
||||
import org.gsdistance.grimmsServer.Data.Player.PlayerInventoryData;
|
||||
import org.gsdistance.grimmsServer.Data.Player.PlayerTitleChecker;
|
||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||
|
|
@ -55,7 +57,8 @@ public class EntityDeathEvent {
|
|||
|
||||
// Save inventory if keepInventory is off
|
||||
Player player = (Player) event.getEntity();
|
||||
if (!player.getWorld().getGameRuleValue(GameRule.KEEP_INVENTORY)) {
|
||||
Boolean keepInventory = player.getWorld().getGameRuleValue(GameRule.KEEP_INVENTORY);
|
||||
if (keepInventory == null || !keepInventory) {
|
||||
PlayerInventoryData inventoryData = PlayerInventoryData.getPlayerInventoryData(player.getUniqueId());
|
||||
|
||||
// Convert current inventory to Base64 for saving
|
||||
|
|
@ -85,7 +88,9 @@ public class EntityDeathEvent {
|
|||
ItemStack[] armor = player.getInventory().getArmorContents();
|
||||
for (int i = 0; i < armor.length && i < 4; i++) {
|
||||
try {
|
||||
if (armor[i] != null) {
|
||||
armorBase64[i] = PlayerInventoryData.itemStackToBase64(armor[i]);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
GrimmsServer.logger.warning("Failed to serialize armor slot " + i);
|
||||
}
|
||||
|
|
@ -95,7 +100,9 @@ public class EntityDeathEvent {
|
|||
ItemStack[] extra = player.getInventory().getExtraContents();
|
||||
for (int i = 0; i < extraBase64.length; i++) {
|
||||
try {
|
||||
if (extra[i] != null) {
|
||||
extraBase64[i] = PlayerInventoryData.itemStackToBase64(extra[i]);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
GrimmsServer.logger.warning("Failed to serialize extra slot " + i);
|
||||
}
|
||||
|
|
@ -114,8 +121,46 @@ public class EntityDeathEvent {
|
|||
inventoryData.setExtraFromItemStacks(player.getInventory().getExtraContents());
|
||||
inventoryData.saveToPDS();
|
||||
|
||||
// Mark soulbound items (items that should not drop on death)
|
||||
// Check each item for soulbound enchantment
|
||||
for (Map.Entry<Integer, ItemStack> entry : currentInventory.entrySet()) {
|
||||
ItemStack item = entry.getValue();
|
||||
if (item != null) {
|
||||
CustomEnchantmentHandler enchantHandler = CustomEnchantmentHandler.getHandler(item);
|
||||
if (enchantHandler.hasEnchantment(CustomEnchantments.SOULBOUND)) {
|
||||
inventoryData.markSoulboundItemStack(entry.getKey(), item, "inventory");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check armor for soulbound items
|
||||
for (int i = 0; i < armor.length && i < 4; i++) {
|
||||
ItemStack item = armor[i];
|
||||
if (item != null) {
|
||||
CustomEnchantmentHandler enchantHandler = CustomEnchantmentHandler.getHandler(item);
|
||||
if (enchantHandler.hasEnchantment(CustomEnchantments.SOULBOUND)) {
|
||||
inventoryData.markSoulboundItemStack(i, item, "armor");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check extra contents for soulbound items
|
||||
for (int i = 0; i < extra.length && i < 36; i++) {
|
||||
ItemStack item = extra[i];
|
||||
if (item != null) {
|
||||
CustomEnchantmentHandler enchantHandler = CustomEnchantmentHandler.getHandler(item);
|
||||
if (enchantHandler.hasEnchantment(CustomEnchantments.SOULBOUND)) {
|
||||
inventoryData.markSoulboundItemStack(i, item, "extra");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save again after marking soulbound items to update the saved data
|
||||
inventoryData.saveToPDS();
|
||||
|
||||
// Clear inventory if config allows
|
||||
boolean clearInventory = ActiveConfig.getConfigValue(ConfigKey.CLEAR_INVENTORY_ON_DEATH, Boolean.class);
|
||||
Boolean clearInventoryConfig = ActiveConfig.getConfigValue(ConfigKey.CLEAR_INVENTORY_ON_DEATH, Boolean.class);
|
||||
boolean clearInventory = clearInventoryConfig != null && clearInventoryConfig;
|
||||
if (clearInventory) {
|
||||
player.getInventory().clear();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,15 @@ package org.gsdistance.grimmsServer.Events.Listeners;
|
|||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.gsdistance.grimmsServer.Data.PerSessionDataStorage;
|
||||
import org.gsdistance.grimmsServer.Data.Player.PlayerInventoryData;
|
||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||
import org.gsdistance.grimmsServer.Indexers.DynamicDimensionGen;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class PlayerRespawnEvent {
|
||||
public PlayerRespawnEvent() {
|
||||
}
|
||||
|
|
@ -22,7 +28,43 @@ public class PlayerRespawnEvent {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Restore soulbound items on respawn
|
||||
Player player = event.getPlayer();
|
||||
PlayerInventoryData inventoryData = PlayerInventoryData.getPlayerInventoryData(player.getUniqueId());
|
||||
|
||||
// Check if there are soulbound items to restore
|
||||
if (!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()) {
|
||||
player.getInventory().setItem(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
// Restore soulbound armor
|
||||
ItemStack[] soulboundArmor = inventoryData.getSoulboundArmorAsItemStacks();
|
||||
player.getInventory().setArmorContents(soulboundArmor);
|
||||
|
||||
// Restore soulbound extra contents
|
||||
ItemStack[] soulboundExtra = inventoryData.getSoulboundExtraAsItemStacks();
|
||||
player.getInventory().setExtraContents(soulboundExtra);
|
||||
|
||||
// Clear soulbound items after restoration
|
||||
inventoryData.clearSoulboundItems();
|
||||
inventoryData.saveToPDS();
|
||||
}
|
||||
}
|
||||
|
||||
// Helper method to check if array has non-null items
|
||||
private static boolean hasNonNullItems(String[] array) {
|
||||
if (array == null) return false;
|
||||
for (String item : array) {
|
||||
if (item != null) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,8 +53,8 @@ public class TitleGenerator {
|
|||
killTitles.put(10L, "Novice Hunter");
|
||||
killTitles.put(100L, "Hunter");
|
||||
killTitles.put(1000L, "Slayer");
|
||||
killTitles.put(10000L, "Executioneer");
|
||||
killTitles.put(100000L, "Destroyer");
|
||||
killTitles.put(10000L, "Hitman");
|
||||
killTitles.put(100000L, "Mob Eater");
|
||||
killTitles.put(1000000L, "Godslayer");
|
||||
killTitles.put(10000000L, "World Ender");
|
||||
killTitles.put(100000000L, "Mass Murderer");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue