Solved Faltal error in my plugin!

Discussion in 'Spigot Plugin Development' started by Deitog, Jul 4, 2019.

  1. Hi everyone.

    I have a very serious problem and I need your help.
    I was solving an error in #Material for version compatibility and something happened to me when I opened the menu, I saw the console and it gave me an error in the part where the menu of my plugin was updated: SimplePing, And it turns out that the #PluginBase is not compatible with versions under 1.12 and is only compatible with high versions at 1.13
    The console error is repeated because it is a repeating task

    Code (Text):
    [14:12:08] [Server thread/WARN]: [SimplePing] Task #32 for SimplePing v1.6.1 generated an exception
    java.lang.ClassCastException: org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryCrafting cannot be cast to org.bukkit.plugin.PluginBase
        at net.deitog.spp.plugin.util.PingMenu$1.run(PingMenu.java:91) ~[?:?]
        at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:723) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_51]
    [14:12:08] [Server thread/WARN]: [SimplePing] Task #32 for SimplePing v1.6.1 generated an exception
    java.lang.ClassCastException: org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryCrafting cannot be cast to org.bukkit.plugin.PluginBase
        at net.deitog.spp.plugin.util.PingMenu$1.run(PingMenu.java:91) ~[?:?]
        at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:723) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_51]
    [14:12:08] [Server thread/WARN]: [SimplePing] Task #32 for SimplePing v1.6.1 generated an exception
    java.lang.ClassCastException: org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryCrafting cannot be cast to org.bukkit.plugin.PluginBase
        at net.deitog.spp.plugin.util.PingMenu$1.run(PingMenu.java:91) ~[?:?]
        at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:723) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_51]
    [14:12:08] [Server thread/WARN]: [SimplePing] Task #32 for SimplePing v1.6.1 generated an exception
    java.lang.ClassCastException: org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryCrafting cannot be cast to org.bukkit.plugin.PluginBase
        at net.deitog.spp.plugin.util.PingMenu$1.run(PingMenu.java:91) ~[?:?]
        at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:723) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_51]
    [14:12:08] [Server thread/WARN]: [SimplePing] Task #32 for SimplePing v1.6.1 generated an exception
    java.lang.ClassCastException: org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryCrafting cannot be cast to org.bukkit.plugin.PluginBase
        at net.deitog.spp.plugin.util.PingMenu$1.run(PingMenu.java:91) ~[?:?]
        at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:723) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_51]
    [14:12:08] [Server thread/WARN]: [SimplePing] Task #32 for SimplePing v1.6.1 generated an exception
    java.lang.ClassCastException: org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryCrafting cannot be cast to org.bukkit.plugin.PluginBase
        at net.deitog.spp.plugin.util.PingMenu$1.run(PingMenu.java:91) ~[?:?]
        at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:723) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_51]
    [14:12:08] [Async Chat Thread - #3/ERROR]: Could not pass event AsyncPlayerChatEvent to DTChatManager v0.0.1BETA
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:484) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnection.chat(PlayerConnection.java:1084) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1022) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat$1.run(PacketPlayInChat.java:39) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_51]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_51]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_51]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_51]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_51]
    Caused by: java.util.UnknownFormatConversionException: Conversion = 'm'
        at org.bukkit.event.player.AsyncPlayerChatEvent.setFormat(AsyncPlayerChatEvent.java:100) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        at net.deitog.cmp.plugin.listeners.Manager.chatFormat(Manager.java:140) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_51]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
        ... 11 more
    [14:12:08] [Async Chat Thread - #3/INFO]: <RicardoGuerrerox> a[m
    ]
    As the error repeats I do not show it completely
    Code (Text):
    public void updateInventory(final Player p){
            new BukkitRunnable(){
               
                @SuppressWarnings("deprecation")
                @Override
                public void run(){
                    Inventory invs = p.getOpenInventory().getTopInventory();
                   
                    if(((PluginBase) invs).getName().equalsIgnoreCase("LATENCY") ||
                            ((PluginBase) invs).getName().equalsIgnoreCase("PING")){
                            if(pl.getConfig().getInt("inventory-model")==1){
                                ItemStack item = new ItemStack(Material.IRON_BLOCK,1);
                                ItemMeta meta = item.getItemMeta();
                                meta.setDisplayName(API.color(pl.getConfig().getString("items.ping-iron-block-name")
                                        .replace("%ping%", ""+getCurrentPing(p))));
                                List<String> lore = new ArrayList<String>();
                                for(String s : pl.getConfig().getStringList("items.ping-iron-block-name-lore")){
                                    lore.add(API.color(s).replace("%ping%", ""+getCurrentPing(p)));
                                }
                                meta.setLore(lore);
                               
                                ItemStack dec = new ItemStack(panel,1,(short)11);
                                ItemMeta dmeta = dec.getItemMeta();
                                dmeta.setDisplayName(API.color("&7"));
                                dec.setItemMeta(dmeta);
                               
                                ItemStack dec2 = new ItemStack(panel,1,(short)9);
                                ItemMeta dec2m = dec2.getItemMeta();
                                dec2m.setDisplayName(API.color("&7"));
                                dec2.setItemMeta(dec2m);
                               
                                ItemStack dec3 = new ItemStack(panel,1,(short)3);
                                ItemMeta dec3m = dec3.getItemMeta();
                                dec3m.setDisplayName(API.color("&7"));
                                dec3.setItemMeta(dec3m);
                               
                                invs.setItem(0, dec);
                                invs.setItem(1, dec);
                                invs.setItem(2, dec);
                                invs.setItem(3, dec);
                                invs.setItem(4, dec);
                                invs.setItem(5, dec);
                                invs.setItem(6, dec);
                                invs.setItem(7, dec);
                                invs.setItem(8, dec);
                                invs.setItem(9, dec);
                                invs.setItem(18, dec);
                                invs.setItem(27, dec);
                                invs.setItem(17, dec);
                                invs.setItem(26, dec);
                                invs.setItem(35, dec);
                                invs.setItem(36, dec);
                                invs.setItem(37, dec);
                                invs.setItem(38, dec);
                                invs.setItem(39, dec);
                                invs.setItem(40, dec);
                                invs.setItem(41, dec);
                                invs.setItem(42, dec);
                                invs.setItem(43, dec);
                                invs.setItem(44, dec);
                               
                                for(int i=10;i<17;i++){
                                    invs.setItem(i, dec2);
                                }
                                for(int i=28;i<35;i++){
                                    invs.setItem(i, dec2);
                                }
                                invs.setItem(19, dec2);
                                invs.setItem(25, dec2);
                               
                                invs.setItem(23, dec3);
                                invs.setItem(24, dec3);
                                invs.setItem(20, dec3);
                                invs.setItem(21, dec3);
                               
                                item.setItemMeta(meta);
                                invs.setItem(22, item);
                               
                            }
                           
                    }
                }  
            }.runTaskTimer(pl, 0L, 5L);
        }
       
     
  2. Hello,

    The error clearly explain.. the error:
    That mean, you can not do this ((PluginBase) invs), as the Inventory can not be casted to PluginBase.
    I'll just recommand to remove the cast.
     
  3. If I remove it the external jar of 1.13 and 1.14 will give me error
     
  4. Then you should post the error.
     
  5. The error is this:
    upload_2019-7-4_15-28-44.png
     
  6. That is because Inventory#getName() should not be used in 1.13, and do not even exists in 1.14.

    You have to check the Bukkit version, and adapt your code.
    Something like:
    Code (Java):
    String inventoryName;
    if (BukkitVersion >= 1.13) {
        inventoryName = p.getOpenInventory().getTitle();
    } else {
        inventoryName = p.getOpenInventory().getTopInventory().getName();
    }
    But this mean you'll have to use the spigot-api for 1.13 (to have both methods valid in your ide)
     
  7. So if I use the api of 1.13 it will be compatible with that of 1.14?
     
  8. This should be compatible, yes;
    Theoretically, you should not be able to achieve what you want to do as Inventory metods are differents from 1.7 to 1.14.
    But i gave you a "glitch": by setting your spigot-api to 1.13 in your IDE, you'll can use the little code that I wrote, because both metods still exists in 1.13.
     
    • Agree Agree x 1
  9. I think I gave him a solution
    Code (Text):
    private static String getInvName1_14(Player p) {
            if(Version.is1_13() || Version.is1_14()){
                Inventory inv = p.getOpenInventory().getTopInventory();
                String invName = inv.getTitle();
                return invName;
            }else{
                return null;
            }
        }
     
    And this I put in the if
    Code (Text):
    getInvName1_14(p)=="PING"
     
  10. You should never compare Strings with ==, but only with .equals()
     
  11. But it works the same if I use it with = that with #equals() or #equalsIgnoreCase()
     
  12. == checks for object equality, while equals() checks for determined equality(which was implemented in the String class so it's 100% safe)
    String comparison works differently; Your method's result instead of always being false, would actually always be undeterminable due to how the JVM handles Strings.

    If you wanna know why, read: https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java
     
    • Informative Informative x 1
  13. Comparing objects with == checks if they are pointing to the same memory location rather than the value (basically a reference comparison). Using #equals() allow you to compare the actual value.

    Code (Text):
            String str1 = new String("dank memes");
            String str2 = new String("dank memes");
         
            System.out.println(str1 == str2);
    If you try to run that code above, I'm pretty sure that prints out false (bear with the new String() for now).
     
    • Informative Informative x 1
  14. I don't know exactly what you are doing but the error line tells you a lot about the actual problem

    Code (Text):
    org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryCrafting cannot be cast to org.bukkit.plugin.PluginBase
    This one tells you that you cant cast that object!


    Similar thing would look like this


    Code (Text):
    String test = "hello";
    Integer i = (int) test
     
    Would not work as well because you cant cast String to int!
     
  15. Already solved
     
  16. Mark the thread as solved then.