Testing if a Player Chats not Working

Discussion in 'Plugin Development' started by TheDiamond06, Dec 29, 2014.

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

    TheDiamond06

    So in the onEnable it does a timer for every 10 minutes. I set that lower to test it but The timer and broadcast goes through, but if I chat the words it tells me to it doesn't work. When the broadcast is played theres an error in console also.
    TIMER:
    Code:
        @SuppressWarnings("deprecation")
        @EventHandler
        public void timer(final AsyncPlayerChatEvent e)
        {
            this.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable()
            {
                public void run()
                {
                    for(Player player : Bukkit.getServer().getOnlinePlayers())
                    {
                        double a = Math.random();
                        if(a < 0.1)
                        {
                        Bukkit.broadcastMessage("§8§l[§b§lUL§8§l] §f§lFirst one to type §e§lAlfjeAGbve%9359_V4*afh5A*tga §f§lwins a §0§lRandomCrate!");
                        if(e.getMessage() == "AlfjeAGbve%9359_V4*afh5A*tga")
                        {
                            Bukkit.broadcastMessage("§8§l[§b§lUL§8§l] §e§l" + player.getName() + " §f§lhas won a §0§lRandomCrate!");
                            ItemStack rc = new ItemStack(Material.CHEST);
                            ItemMeta mc = rc.getItemMeta();
                            mc.setDisplayName("§0§lRandomCrate");
                            List<String>a1 = new ArrayList<String>();
                            a1.add("§b§lObtained by the RandomCrate!");
                            mc.setLore(a1);
                            rc.setItemMeta(mc);
                            player.getInventory().addItem(rc);
                            player.updateInventory();
                            break;
                        }
                        }
                        else if(a < 0.2)
                        {
                            Bukkit.broadcastMessage("§8§l[§b§lUL§8§l] §f§lFirst one to type §e§lbcZyeyw!EvuvSaXZ*8&68@955 §f§lwins a §0§lRandomCrate!");
                            if(e.getMessage() == "bcZyeyw!EvuvSaXZ*8&68@955")
                            {
                                Bukkit.broadcastMessage("§8§l[§b§lUL§8§l] §e§l" + player.getName() + " §f§lhas won a §0§lRandomCrate!");
                                ItemStack rc = new ItemStack(Material.CHEST);
                                ItemMeta mc = rc.getItemMeta();
                                mc.setDisplayName("§0§lRandomCrate");
                                List<String>a1 = new ArrayList<String>();
                                a1.add("§b§lObtained by the RandomCrate!");
                                mc.setLore(a1);
                                rc.setItemMeta(mc);
                                player.getInventory().addItem(rc);
                                player.updateInventory();
                                break;
                            }
                        }
                        else if(a < 0.3)
                        {
                            Bukkit.broadcastMessage("§8§l[§b§lUL§8§l] §f§lFirst one to type §e§lALHGEzhHgaAygeJzwWcbaEit32TS3 §f§lwins a §0§lRandomCrate!");
                            if(e.getMessage() == "ALHGEzhHgaAygeJzwWcbaEit32TS3")
                            {
                                Bukkit.broadcastMessage("§8§l[§b§lUL§8§l] §e§l" + player.getName() + " §f§lhas won a §0§lRandomCrate!");
                                ItemStack rc = new ItemStack(Material.CHEST);
                                ItemMeta mc = rc.getItemMeta();
                                mc.setDisplayName("§0§lRandomCrate");
                                List<String>a1 = new ArrayList<String>();
                                a1.add("§b§lObtained by the RandomCrate!");
                                mc.setLore(a1);
                                rc.setItemMeta(mc);
                                player.getInventory().addItem(rc);
                                player.updateInventory();
                                break;
                            }
                        }
                        else
                        {
                            Bukkit.broadcastMessage("§8§l[§b§lUL§8§l] §f§lFirst one to type §e§lZYXWVUTSRQPONMLKJIHGFEDCBA#%@% §f§lwins a §0§lRandomCrate!");
                            if(e.getMessage() == "ZYXWVUTSRQPONMLKJIHGFEDCBA#%@%")
                            {
                                Bukkit.broadcastMessage("§8§l[§b§lUL§8§l] §e§l" + player.getName() + " §f§lhas won a §0§lRandomCrate!");
                                ItemStack rc = new ItemStack(Material.CHEST);
                                ItemMeta mc = rc.getItemMeta();
                                mc.setDisplayName("§0§lRandomCrate");
                                List<String>a1 = new ArrayList<String>();
                                a1.add("§b§lObtained by the RandomCrate!");
                                mc.setLore(a1);
                                rc.setItemMeta(mc);
                                player.getInventory().addItem(rc);
                                player.updateInventory();
                                break;
                            }
                        }
                    }
                }
            }
            , 500, 500);
        }
    
    OnEnable:
    Code:
    timer(null);
    
    Console Error:
    Code:
    [22:21:34] [pool-3-thread-187/INFO]: [0;30;1m[21m[[0;36;1m[21mUL[0;30;1m[21m] [0;37;1m[21mFirst one to type [0;33;1m[21mAlfjeAGbve%9359_V4*afh5A*tga [0;37;1m[21mwins a [0;30;22m[21mRandomCrate![m
    [22:21:37] [pool-3-thread-187/INFO]: [0;30;1m[21m[[0;36;1m[21mUL[0;30;1m[21m] [0;37;1m[21mFirst one to type [0;33;1m[21mZYXWVUTSRQPONMLKJIHGFEDCBA#%@% [0;37;1m[21mwins a [0;30;22m[21mRandomCrate![m
    [22:21:40] [pool-3-thread-187/INFO]: [0;30;1m[21m[[0;36;1m[21mUL[0;30;1m[21m] [0;37;1m[21mFirst one to type [0;33;1m[21mZYXWVUTSRQPONMLKJIHGFEDCBA#%@% [0;37;1m[21mwins a [0;30;22m[21mRandomCrate![m
    [22:21:40] [pool-3-thread-187/WARN]: Exception in thread "pool-3-thread-187" 
    [22:21:40] [pool-3-thread-187/WARN]: org.apache.commons.lang.UnhandledException: Plugin LightningCustom v1.0 generated an exception while executing task 71
        at org.bukkit.craftbukkit.v1_7_R3.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:56)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.NullPointerException
        at com.enjin.lightningcustom.LightningCustom$2.run(LightningCustom.java:4685)
        at org.bukkit.craftbukkit.v1_7_R3.scheduler.CraftTask.run(CraftTask.java:53)
        at org.bukkit.craftbukkit.v1_7_R3.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:53)
        ... 3 more
    
     
  2. Offline

    mythbusterma

    @TheDiamond06

    Wow. That's quite a bit of thread safety violation you've got there. I'm not sure you know what you're doing.

    How about you stop doing things on threads other than the main thread, especially things like this, which have a high chance of corrupting the server.

    Also, it's a simple NullPointerException.

    Looking at your code, the control flow really makes no sense at all, learn Java, and then read the Bukkit plugin tutorial.
     
Thread Status:
Not open for further replies.

Share This Page