Solved XML Parsing GOLDEN_SWORD as LEGACY_GOLDEN_SWORD

Discussion in 'Spigot Plugin Development' started by Pyronucleic, Feb 20, 2020.

  1. I have an XML file being parsed using the SAX method.

    One of the values parsed for is a material, and for testing sake I set it to golden sword. This is the specific chunk of code parsing my information:
    Code (Text):

    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
        System.out.println(data);
        if (bSharp) {
            stat.setSharpness((byte) Integer.parseInt(data.toString()));
            bSharp = false;
        } else if (bWeight) {
            stat.setWeight((byte) Integer.parseInt(data.toString()));
            bWeight = false;
        }else if (bAero) {
            stat.setAerodynamics((byte) Integer.parseInt(data.toString()));
            bAero = false;
        }else if (bLore) {
            stat.setLore(data.toString());
            bLore = false;
        }else if (bRarity) {
            stat.setRarity(ItemRarity.valueOf(data.toString()));
            bRarity = false;
        }else if (bMaterial) {

            //TODO: For some reason it thinks GOLDEN_SWORD is LEGACY_GOLDEN_SWORD, find why it's changing that.
            stat.setItemMaterial(Material.valueOf(data.toString()));
            bMaterial = false;
        }
     
    Log:
    Code (Text):

    [00:05:33 INFO]: 1
    [00:05:33 INFO]: 1
    [00:05:33 INFO]: 1
    [00:05:33 INFO]: A stick
    [00:05:33 INFO]: COMMON
    [00:05:33 INFO]: STICK
    [00:05:33 INFO]: STICK
     
    [00:05:33 INFO]: 5
    [00:05:33 INFO]: 10
    [00:05:33 INFO]: 3
    [00:05:33 INFO]: A pretty nice looking sword.
    [00:05:33 INFO]: RARE
    [00:05:33 INFO]: GOLDEN_SWORD
    [00:05:33 ERROR]: Error occurred while enabling GravityCraftCore v0.02 (Is it up to date?)
    java.lang.IllegalArgumentException: No enum constant org.bukkit.Material.LEGACY_GOLDEN_SWORD
        at java.lang.Enum.valueOf(Unknown Source) ~[?:1.8.0_211]
        at org.bukkit.Material.valueOf(Material.java:1) ~[spigot.jar:git-Spigot-800b93f-8160e29]
        at org.bukkit.craftbukkit.v1_15_R1.util.CraftLegacy.valueOf(CraftLegacy.java:221) ~[spigot.jar:git-Spigot-800b93f-8160e29]
        at io.pyronucleic.gravitycore.xml.ItemXMLHandler.endElement(ItemXMLHandler.java:77) ~[?:?]
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown Source) ~[?:1.8.0_211]
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source) ~[?:1.8.0_211]
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source) ~[?:1.8.0_211]
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source) ~[?:1.8.0_211]
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) ~[?:1.8.0_211]
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) ~[?:1.8.0_211]
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) ~[?:1.8.0_211]
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source) ~[?:1.8.0_211]
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source) ~[?:1.8.0_211]
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) ~[?:1.8.0_211]
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source) ~[?:1.8.0_211]
        at javax.xml.parsers.SAXParser.parse(Unknown Source) ~[?:1.8.0_211]
        at io.pyronucleic.gravitycore.xml.ItemXMLParser.parseXMLItems(ItemXMLParser.java:21) ~[?:?]
        at io.pyronucleic.gravitycore.main.Main.onEnable(Main.java:24) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[spigot.jar:git-Spigot-800b93f-8160e29]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:352) [spigot.jar:git-Spigot-800b93f-8160e29]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:417) [spigot.jar:git-Spigot-800b93f-8160e29]
        at org.bukkit.craftbukkit.v1_15_R1.CraftServer.enablePlugin(CraftServer.java:462) [spigot.jar:git-Spigot-800b93f-8160e29]
        at org.bukkit.craftbukkit.v1_15_R1.CraftServer.enablePlugins(CraftServer.java:376) [spigot.jar:git-Spigot-800b93f-8160e29]
        at net.minecraft.server.v1_15_R1.MinecraftServer.a(MinecraftServer.java:457) [spigot.jar:git-Spigot-800b93f-8160e29]
        at net.minecraft.server.v1_15_R1.DedicatedServer.init(DedicatedServer.java:267) [spigot.jar:git-Spigot-800b93f-8160e29]
        at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:784) [spigot.jar:git-Spigot-800b93f-8160e29]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_211]
     
    It also repeats that specific task twice, which I'll need to figure out. But for now there is a potential issue with parsing that must be solved.

    I shows the previous parsed object to show that for materials without legacy duplicates do not have this issue.

    SOLVED: Some looking around found out that I'm supposed to include the API version in plugin.yml. Hadnt coded in spigot for some time and didn't check whats new
     
    #1 Pyronucleic, Feb 20, 2020
    Last edited: Feb 20, 2020