Bukkit Hints/Tips Not Showing Up. Also, Player player = player sender.

Discussion in 'Plugin Development' started by Nerfchampion, Oct 21, 2014.

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

    Nerfchampion

    I know this might be a stupid question but IDK what is not making this work.

    In eclipse if you type something like Bukkit. or chatColor. ; It would give you a tip/hint or something that says under it in a small window possible things you might type, like... chatColor.GREEN, or chatColor.RED.
    But its not showing. I added the newest craftbukkit.jar file into my libraries.


    ALSO(SAME PLUGINF OR BOTH PROBLEMS):

    Im making a plugin that will notify operators when a trial-mod uses a command. Im trying to check it the operator that uses the code has a permission so it will figure out whether or not to notify another mod. Here is my code so far.
    \
    Code:java
    1. package me.Nerfchampion.AN;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.player.AsyncPlayerChatEvent;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class Main extends JavaPlugin implements Listener{
    10.  
    11. public void onEnable(){
    12. getLogger().info("[Admin Notifications]Enabled Successfully");
    13. getConfig().options().copyDefaults(true);
    14. saveConfig();
    15. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    16. }
    17.  
    18. public void onDisable(){
    19. getLogger().info("[Admin Notifications]Disabled Successfully");
    20. }
    21.  
    22. Player player = (Player) sender;
    23. public void onPlayerChat(AsyncPlayerChatEvent e){
    24. if(sender.hasPermission(an.check)){
    25.  
    26. }else{
    27.  
    28. }
    29. }
    30.  
    31. }
    32.  
     
  2. Offline

    ProtoTempus

    I think your looking for the Bukkit Javadocs. Make sure they're setup in eclipse.

    Ill take a look at your second issue in a second.
     
  3. Offline

    Walruski

    I'm guessing your issue is: if(sender.hasPermission(an.check)), it would instead be: if(sender.hasPermission("an.check"))
     
  4. Offline

    ProtoTempus

    Also before you cast sender to (Player) you should check that it is an instanceof Player first.
    Code:java
    1. if(sender instanceof Player)
    2. {
    3. Player player = (Player) sender;
    4. }

    These are your subinterfaces for CommandSender: BlockCommandSender, CommandMinecart, ConsoleCommandSender, Player, RemoteConsoleCommandSender

    Edit: It's so much more than that too... Your "Player player = (Player) sender;" line is outside any method. You shouldn't be using "AsyncPlayerChatEvent" for commands (if that's what you're doing), Check out this: Bukkit Commands Wiki. Good Luck!
     
  5. Offline

    xMrPoi

    You're creating a Player object and casting "sender" to a Player even though "sender" doesn't exist. Also, your event doesn't have a
    Code:java
    1. @EventHandler
    tag on it. Also, you'll have to create a Player object inside of the event and get it from the event:
    Code:java
    1. Player player = event.getPlayer();

    These are some nit picky suggestions but Bukkit automatically sends a message to console when a plugin gets enabled and disabled so your "getLogger" methods are redundant. Also, Main is not a very good class name to use. You can fix this by looking at this.

    The "hasPermission" message takes a string as a parameter. When you're typing "if(sender.hasPermission(an.check)){", it really should be
    Code:java
    1. if(player.hasPermission("an.check")){}
    (after creating your player object of course.)
     
    es359 and VG.Developments like this.
  6. Offline

    es359

    Learn Java first. Before you look into Bukkit API.
     
  7. Offline

    mythbusterma

    That's the first thing you did wrong.

    Also, why did you put enable and disable messages? Bukkit already does that....
     
Thread Status:
Not open for further replies.

Share This Page