Bug Closed · Resolved

MythicMobs bukkit item deserialize missing lore on 1.12.2

#2036 opened by Unknown 5 years ago

Unknownreported this bug

Summary
Server Version: 1.12.2
MythicMobs item manager doesnt deserialize bukkit item properly
(Not using the mythicmobs format, i mean the Bukkit item deserialized with using /mm i import <itemid>)
Even the item data yml saves the lore data correctly, mythicmobs fail to read it back with /mm i get <itemid>

Steps to reproduce

  1. /mm i get SkeletonKingSword
  2. hold the item in hand (the example item should have lore)
  3. /mm i import Test
  4. /mm i get Test

Current behavior
The item lore is gone. but it does save correctly when u check the imported yml.

Intended correct behavior
The lore should be there

Proposed fixes
This is weird as i suppose MythicMob use internal spigot api to deserialize bukkit item
It might be a incompatibility with the lastest version
In this case, mm should let user to choose that if they want to convert the the item into
MythicMobs mythic items's format (warn them that it might lost some details tho)

Unknowncommented

Tested with MythicMobs-4.4.1 on 1.12.2
Function normally.

Tested with MythicMobs lastest on 1.16.5
Function normally.

Yep, it should be a compatibility issue, should let user choose to save in Mythic Items format or not

Unknowncommented

If something like this can be implemented into MythicMobs (ofc, let player choose the import method in command)
Would solve the problem
While warn the player it may lost the attribute modifiers for items in older version as they require NBT in 1.12.2

Usage /mm4lts i import <name> [fileName] [-hj] - Save item as MythicItems format, -hj for directly inject into mm folder

Player player = (Player) sender;
			
if(args[0].equalsIgnoreCase("items") || args[0].equalsIgnoreCase("i")) {
	
	if(args[1].equalsIgnoreCase("import")) {
		
		String id = args[2];
		String fileName = id;
		
		if(args.length >= 4 && !args[3].equals("-hj")) {
			fileName = args[3];
		}
		
		File saveFolder = null;
		
		if(!Arrays.asList(args).contains("-hj")) {

			saveFolder = new File(MythicMobs4LTS.getInstance().getDataFolder() + File.separator + "Items");
			
			//Create if not exist
			if(!saveFolder.exists()) {
				saveFolder.mkdir();
			}
			
		}else {
			
			saveFolder = new File(MythicMobs4LTS.getInstance().getDataFolder() + File.separator + ".." + File.separator + "MythicMobs" + File.separator + "Items");
			
			//Terminate command if folder not exist, as it indicate mm not working properly
			if(!saveFolder.exists()) {
				player.sendMessage(ChatColor.RED + "MythicMobs Items folder not exist, check if you MythicMobs enabled correctly.");
				return true;
			}else {
				player.sendMessage(ChatColor.GREEN + "Hijacking MythicMobs plugin data folder to save items...");
			}
			
		}
		
		File file = new File(saveFolder + File.separator + fileName + ".yml");
		
		if(!file.exists()) {
			FilesManager.createYamlFile(file);
		}
		
		YamlConfiguration yaml = FilesManager.getLoadedYaml(file);
		ConfigurationSection section = yaml.createSection(id);
		
		ItemStack item = player.getInventory().getItemInMainHand();
		
		String mmif_id = item.getType().name();
		section.set("Id", mmif_id);
		
		int mmif_data = item.getDurability();
		if(mmif_data != 0) {
			section.set("Data", mmif_data);
		}
		
		if(item.hasItemMeta()) {
			
			ItemMeta itemMeta = item.getItemMeta();
			
			if(itemMeta.hasDisplayName()) {
				String mmif_display = itemMeta.getDisplayName();
				section.set("Display", mmif_display);
			}
			
			if(itemMeta.hasLore()) {
				List<String> loreList = itemMeta.getLore();
				section.set("Lore", loreList);
			}
			
			if(itemMeta.hasEnchants()) {
				
				Map<Enchantment, Integer> enchantList = itemMeta.getEnchants();
				List<String> mmif_enchantments = new ArrayList<String>();
				
				for(Entry<Enchantment, Integer> entry : enchantList.entrySet()) {
					mmif_enchantments.add(entry.getKey().getName() + ":" + entry.getValue());
				}
				
				section.set("Enchantments", mmif_enchantments);
				
			}
			
			//NBT needed
			/*if(item.getItemMeta().get) {
				
				Multimap<Attribute, AttributeModifier> modifiers = itemMeta
				List<String> mmif_attributes = new ArrayList<String>();
				
				for(Entry<Attribute, AttributeModifier> entry : modifiers.entries()) {
					
					Bukkit.broadcastMessage(entry.getKey().name() + ": " + entry.getValue().getSlot());
					
				}
				
				
			}*/
			
		}
		
		//Finally save yaml
		FilesManager.saveYamlFile(yaml, file);
		
		player.sendMessage(ChatColor.GREEN + "Item imported in " + file.getPath() + " successfully");
		
		
	}
	
}

Temporary solution: [Legacy attachment omitted]

Sign in to join the discussion.