Solved Check For Helmet

Discussion in 'Plugin Development' started by tkuiyeager1, Oct 2, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    tkuiyeager1

    Ok so i am making a plugin for someone who asked for this plugin in the plugin request.
    i want to know if there is a way to check what is the player helmet all the time, i mean i dont want it to be only in a command or in lets say Player Move Event. is there a way to check it always?
     
  2. Offline

    RoboticPlayer

    Just use a BukkitRunnable then.
     
  3. Offline

    DoggyCode™

    On the plugin enable run a repeating task every 10 milliseconds or something looping through all online players checking if they're wearing a helmet, and if they do, do something.
     
  4. Offline

    tkuiyeager1

    thank you @DoggyCode™ but i just figured out i can do it in the events i need

    @DoggyCode™ i cant get the player name on OnEnable what should i do?
    EDIT:
    solved it.

    @DoggyCode™ I have an error please look at this or anyone else if you can help please reply.
    Code:
    Code:
        @EventHandler
        public void Check(AsyncPlayerChatEvent e) {
            Player p = e.getPlayer();
            String redprefix = "§4[Red] §r";
            String blueprefix = "§1[Blue] §r";
            ItemStack redwool = new ItemStack(Material.WOOL, 1, (short) 14);
            ItemStack bluewool = new ItemStack(Material.WOOL, 1, (short) 11);
            TagPlayer tagplayer = new TagPlayer(p);
            TagManager tagmanager = new TagManager(tagplayer);
            if(p.getInventory().getHelmet().equals(null)) return;
            if(p.getInventory().getHelmet().hasItemMeta()) return;
            if(!(p.getInventory().getHelmet().isSimilar(redwool)) || !(p.getInventory().getHelmet().isSimilar(bluewool))) return;
            if (p.getInventory().getHelmet().isSimilar(redwool)) {
                e.setFormat(redprefix + "§4" + p.getName() + "§7: §r"
                        + e.getMessage());
                tagmanager.setTag(ChatColor.RED + p.getName());
    
            }
            if (p.getInventory().getHelmet().isSimilar(bluewool)) {
                e.setFormat(blueprefix + "§1" + p.getName() + "§7: §r"
                        + e.getMessage());
                tagmanager.setTag(ChatColor.BLUE + p.getName());
            }
        }
    Error:
    Code:
    [19:36:16 ERROR]: Could not pass event AsyncPlayerChatEvent to EzTeams v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:310) ~[spigot.jar:git-Spigot-f928e7a-f27339c]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[spigot.jar:git-Spigot-f928e7a-f27339c]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:502) [spigot.jar:git-Spigot-f928e7a-f27339c]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:484) [spigot.jar:git-Spigot-f928e7a-f27339c]
            at net.minecraft.server.v1_8_R3.PlayerConnection.chat(PlayerConnection.j
    ava:1057) [spigot.jar:git-Spigot-f928e7a-f27339c]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java
    :995) [spigot.jar:git-Spigot-f928e7a-f27339c]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat$1.run(PacketPlayInChat.
    java:39) [spigot.jar:git-Spigot-f928e7a-f27339c]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_60]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_60]
            at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:
    1.8.0_60]
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?
    :1.8.0_60]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_60]
    Caused by: java.lang.NullPointerException
            at me.tkuiyeager1.ezteams.Main.Check(Main.java:32) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0
    _60]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0
    _60]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .8.0_60]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_60]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:306) ~[spigot.jar:git-Spigot-f928e7a-f27339c]
            ... 11 more
    Line 32:
    Code:
    if(p.getInventory().getHelmet().equals(null)) return;
    Edit:
    also how do i get the player name on the OnEnable?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 30, 2015
  5. Offline

    RoboticPlayer

    Use == instead of .equals, it's null-safe. It will just return false instead of null.
    Java Naming Conventions: method names should be lowercase with internal words capitalized
    Use the ChatColor enum instead of §[number]
    Why are you defining the red & blue prefix variables if you only use them once?
     
  6. Offline

    tkuiyeager1

    @henderry2019 idk but it think it works fine now.
    Thread Marked As Solved
     
Thread Status:
Not open for further replies.

Share This Page