hasPermissions (not sure) not working in Chat Event

Discussion in 'Plugin Help/Development/Requests' started by BurnyDaKath, May 7, 2015.

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

    BurnyDaKath

    Howdy, i have got error:
    Code:
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:305) ~[serverjar.jar:git-Spigot-2ec6f06-7722428]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[serverjar.jar:git-Spigot-2ec6f06-7722428]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:502) [serverjar.jar:git-Spigot-2ec6f06-7722428]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:484) [serverjar.jar:git-Spigot-2ec6f06-7722428]
            at net.minecraft.server.v1_8_R2.PlayerConnection.chat(PlayerConnection.j
    ava:1061) [serverjar.jar:git-Spigot-2ec6f06-7722428]
            at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java
    :999) [serverjar.jar:git-Spigot-2ec6f06-7722428]
            at net.minecraft.server.v1_8_R2.PacketPlayInChat$1.run(PacketPlayInChat.
    java:39) [serverjar.jar:git-Spigot-2ec6f06-7722428]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_45]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_45]
            at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:
    1.8.0_45]
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?
    :1.8.0_45]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
    Caused by: java.lang.NullPointerException
    When i do following in my Listener class code:
    Code:
    package com.gmail.BurnyDaKath.fwchat;
    
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    
    public class ChatListener implements Listener {
        public FWChat plugin;
    
        public ChatListener(FWChat instance) {
            this.plugin = instance;
        }
    
        @EventHandler(
                priority = EventPriority.MONITOR
        )
        public void onNickChat(AsyncPlayerChatEvent event) {
            Player player = event.getPlayer();
            Player player1 = (Player) player;
            }
            if (!this.plugin.config.contains("Players." + player.getName() + ".prefix")) {
                   if (player1.hasPermission("FWChat.prefixPlayer")) {
                        player.sendMessage("Debug: Player Permissions are checked");
                        String toTransPrefix = this.plugin.config.getString("Groups.Player.prefix");
                        player.sendMessage("Debug: checking toTransPrefix - " + toTransPrefix);
                        this.plugin.config.set("Players." + player.getName() + ".prefix", toTransPrefix);
                        player.sendMessage("Debug: Prefix has been set");
                        this.plugin.saveConf();
                        player.sendMessage("Debug: Config is saved");
                        player.sendMessage(ChatColor.GREEN + "The prefix has been set automatically to" + toTransPrefix);
                   } else {
                        player.sendMessage(ChatColor.DARK_RED + "Debug: Mission failed");
                }
            }
        }
    (FWChat is main class, ChatListener is listener class)
    The result is always "Debug:" sends me "Mission failed", but i added permission FWChat.prefixPlayer to player and did following in plugin.yml:
    Code:
    name: FWChatVBeta1.6
    main: com.gmail.BurnyDaKath.fwchat.FWChat
    version: "Beta-1.6"
    
    permissions:
        FWChat.prefixPlayer:
            description: Gives to player basic prefix.
            default: false
    I made new config (in main class):
    Code:
    public void onEnable() {
    if(this.conf == null) {
    this.conf = new File(this.getDataFolder(), "players.yml");}
    this.config = YamlConfiguration.loadConfiguration(this.conf);this.saveConf();
    
    I did following in my config:
    Code:
    Groups:
      Player:
        prefix: "\xa7e[PLAYER]\xa7r"
    But it isn't working. Help me pls, everything else in plugin is working, it doesn't in here.
     
  2. Offline

    Zombie_Striker

  3. Offline

    BurnyDaKath

    I found that the log is completely not helping, error is in next code, that can't get anything from config because code i sent can't add anything, permissions aren't working and nothing was added to config...

    EDIT: I //'ed lines with code that cause errors in log, now nothing is sent to log, but "Debug: Mission failed" that i used to debug my plugin is still present.
     
    Last edited: May 7, 2015
  4. Offline

    Zombie_Striker

    Did you null-check? Are you casting the right thing? Does your Error message say which line is at fault? Are there incompatibility problems?
     
  5. Offline

    BurnyDaKath

    1. Yes.
    2. Yes.
    3. No. (error message says anything but not about code i provided, so it's useless)
    4. No, i guess.
     
  6. Offline

    Zombie_Striker

    Looked at your code Again, you made an honest mistake. Line three of the onNickname method. You have a bracket that messed you up.
     
  7. Offline

    BurnyDaKath

    That's just me copying it wrongly... I have IntelliJ and there's no {} problems either.
     
  8. Offline

    BrickBoy55

    What is the point of that? Just use event.getPlayer().
     
  9. Offline

    Zombie_Striker

    If it did not say that there was any errors in the IntelliJ for Lines 25+, then you should find a new program.
     
  10. Offline

    BurnyDaKath

    I wondered if it will work like that...
    IntelliJ is much better than Eclipse or Netbeans. If i have any problems with {} then it will tell me. It says if something is useless or not.
     
  11. Offline

    Zombie_Striker

    @BurnyDaKath
    If it didn't show that what you had was the problem, then it's not better. Also, saying if its useless or not is what Eclipse has. I'm not suggesting what to get, but that seems like something really important to check for.
     
  12. Offline

    mythbusterma

    @Zombie_Striker

    He just said that he made an error when copy/pasting, IDEA is far superior to Eclipse. It has far more checks than Eclipse could ever hope to have, and yes, it will tell you if you mismatch brackets.


    @BurnyDaKath

    Do you even have a permissions plugin installed? Also, use PlayerChatEvent for this.
     
  13. Offline

    BurnyDaKath

    Yes, i do, it says that permission is granted and other plugins are working fine.
    PlayerChatEvent didn't help at all, nothing is changed.
     
  14. Offline

    MexMaster

    The file exists?
    Else file.createNewFile(); before that make sure the folder exists file.getParentFile().mkdirs();

    @BurnyDaKath
     
  15. Offline

    BurnyDaKath

    The folder and file exist, code tested.
     
  16. Offline

    mythbusterma

    @BurnyDaKath

    Anyway, you didn't post the entire stack trace, you only posted the part that isn't helpful. I was just saying use PlayerChatEvent because it's better practice in this case.
     
  17. Offline

    BurnyDaKath

    It really was what spigot was saying to me until i turned debug server on, now found out that stacktrace is useless.
     
  18. Offline

    mythbusterma

  19. Offline

    BurnyDaKath

    After i removed code causing stacktrace to appear, nothing is happening, only sendMessage:"Debug: Mission Failed" that i use for debug if player has no permissions. (In my case, player has permissions but plugin can't understand that)
     
Thread Status:
Not open for further replies.

Share This Page