Quick Plugin Help

Discussion in 'Plugin Development' started by ColbyHep55, Sep 8, 2011.

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

    ColbyHep55

    I get one error and I don't know what I need to do.

    Area the error is located.
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
                if(cmd.getName().equalsIgnoreCase("L")){ // If the player typed /l then do the following...
     
                        Player player = Event.getPlayer();
                        Location playerLoc = player.getLocation();
    
                        player.sendMessage("Your X Coordinates : " + playerLoc.getX());
                        player.sendMessage("Your Y Coordinates : " + playerLoc.getX());
                        player.sendMessage("Your Z Coordinates : " + playerLoc.getX());
                    return true;
                }
                return false;
            }       
    That's where the error is.
    Code:
    player.get

    Full code
    Code:
    package me.colby.Basic;
    
    import java.util.logging.Logger;
    
    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Basic extends JavaPlugin {
    
            public static final Logger log = Logger.getLogger("Minecraft");
    
            public static Basic plugin;
    
            private Listener playerListener;
    
            Plugin BasicPlayerListener(Basic instance) {           return plugin = instance;
            }
     
            public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
                if(cmd.getName().equalsIgnoreCase("L")){ // If the player typed /l then do the following...
     
                        Player player = Event.getPlayer();
                        Location playerLoc = player.getLocation();
    
                        player.sendMessage("Your X Coordinates : " + playerLoc.getX());
                        player.sendMessage("Your Y Coordinates : " + playerLoc.getX());
                        player.sendMessage("Your Z Coordinates : " + playerLoc.getX());
                    return true;
                }
                return false;
            }
        
    @Override
    public void onDisable(){
    
    }
     
    @Override
    public void onEnable(){
    PluginManager pm = this.getServer().getPluginManager();
    log.info("Plugin enabled");
    pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, this.playerListener, Event.Priority.Normal, this);
    pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Event.Priority.Normal, this);
    PluginDescriptionFile pdfFile = this.getDescription();
    System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + "is enabled!" );
      }
    
                Plugin instance;
    }
     
  2. Offline

    nisovin

    You can't use event.getPlayer() because there is no event. You'd want to have something like this:
    Code:
    if (sender instanceof Player) {
        Player player = (Player)sender;
    
     
  3. Offline

    ColbyHep55

    Where would I put that?
     
  4. Offline

    nisovin

    A command isn't an event, so no. Notice that the onCommand method has no event parameter? You can't just try to access an event object when one doesn't exist. Programming isn't magical.
     
  5. Offline

    ColbyHep55

    I edited,the post right before you posted. Also I just started programming Java so i'm still confused on a few things.

    Thanks, I got it. How would I make it where it doesn't show decimals?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  6. playerLoc.getBlockX();
    playerLoc.getBlockY();
    etc.
     
Thread Status:
Not open for further replies.

Share This Page