Can someone tell me what errors I have here?
dressme.ext.jar:
dressme.ext.jar:
JavaScript:
package services;
import l2.gameserver.listener.actor.player.OnPlayerEnterListener;
import l2.gameserver.listener.inventory.OnEquipListener;
import l2.gameserver.model.Player;
import l2.gameserver.model.Playable;
import l2.gameserver.model.items.ItemInstance;
import l2.gameserver.templates.item.ItemTemplate;
import l2.gameserver.scripts.ScriptFile;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
public class SkinSystem implements ScriptFile, OnPlayerEnterListener {
private static final File SKINS_XML = new File("data/weapon_skins.xml");
private static final Map<String, Map<Integer, String>> WEAPON_SKINS = new HashMap<>();
private static final Map<Integer, String> ARMOR_SKINS = new HashMap<>(); // Skins completas de armadura.
public SkinSystem() {}
@Override
public void onLoad() {
loadSkinsFromXml();
PlayerListenerList.addGlobal(this);
System.out.println("SkinSystem: Loaded " + WEAPON_SKINS.size() + " weapon types and " + ARMOR_SKINS.size() + " armor skins.");
}
@Override
public void onReload() {
WEAPON_SKINS.clear();
ARMOR_SKINS.clear();
onLoad();
}
@Override
public void onShutdown() {}
@Override
public void onPlayerEnter(Player player) {
player.getInventory().addListener(new SkinListener());
}
// Carga las configuraciones desde el archivo XML.
private void loadSkinsFromXml() {
try {
SAXReader reader = new SAXReader();
Document document = reader.read(SKINS_XML);
Element root = document.getRootElement();
if (!Boolean.parseBoolean(root.attributeValue("enabled", "false"))) {
System.out.println("SkinSystem is disabled in XML.");
return;
}
for (Element weaponType : root.elements("weaponType")) {
String type = weaponType.attributeValue("type");
Map<Integer, String> availableSkins = new HashMap<>();
for (Element skin : weaponType.elements("skin")) {
int skinId = Integer.parseInt(skin.attributeValue("id"));
String skinName = skin.attributeValue("name");
availableSkins.put(skinId, skinName);
}
WEAPON_SKINS.put(type, availableSkins);
}
for (Element armorSkin : root.elements("armorSkin")) {
for (Element skin : armorSkin.elements("skin")) {
int skinId = Integer.parseInt(skin.attributeValue("id"));
String skinName = skin.attributeValue("name");
ARMOR_SKINS.put(skinId, skinName);
}
}
} catch (Exception e) {
System.out.println("Error loading skins from XML.");
e.printStackTrace();
}
}
public static Map<Integer, String> getSkinsForWeaponType(String type) {
return WEAPON_SKINS.getOrDefault(type, new HashMap<>());
}
public static Map<Integer, String> getArmorSkins() {
return ARMOR_SKINS;
}
private static class SkinListener implements OnEquipListener {
@Override
public void onEquip(int slot, ItemInstance item, Playable playable) {
if (!(playable instanceof Player)) return;
Player player = (Player) playable;
ItemTemplate template = item.getTemplate();
if (template.getType2() == ItemTemplate.TYPE2_WEAPON) {
// Identificar el tipo de arma y aplicar su skin.
String weaponType = getWeaponType(template);
Map<Integer, String> availableSkins = getSkinsForWeaponType(weaponType);
if (!availableSkins.isEmpty()) {
player.sendMessage("Skin aplicada para arma: " + availableSkins.values().iterator().next());
}
} else if (template.getType2() == ItemTemplate.TYPE2_ARMOR) {
// Aplicar una skin completa de armadura.
if (!ARMOR_SKINS.isEmpty()) {
player.sendMessage("Skin de armadura visual aplicada: " + ARMOR_SKINS.values().iterator().next());
}
}
}
@Override
public void onUnequip(int slot, ItemInstance item, Playable playable) {
if (!(playable instanceof Player)) return;
Player player = (Player) playable;
player.sendMessage("Item desequipado: skin visual removida.");
}
// Método auxiliar para detectar el tipo de arma.
private String getWeaponType(ItemTemplate item) {
if (item.isBow()) return "bow";
if (item.isDual()) return "dual";
if (item.isDagger()) return "dagger";
if (item.isTwoHandSword()) return "two_handed_sword";
return "unknown";
}
}
}