Calling Method?

Discussion in 'Plugin Development' started by WALK2222, Feb 25, 2013.

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

    WALK2222

    Hi there, I am trying to create a simple plugin that returns a lot of information on a certain player selected. I currently have two classes (as I don't have much done yet). I want to call the method "getlocation" from my PlayerLocation class. Although, I don't know how I would go about doing this, any tips?


    Here is my main class
    Code:
    package com.github.walk2222;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.*;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public final class Main extends JavaPlugin {
       
        //Enabling plugin message
        @Override
        public void onEnable(){
            getLogger().info("[Player info] has been enabled");
        }
       
        //Player info command
        public boolean onCommand(CommandSender sender, Command cmd, String label, String [] args){
            if(cmd.getName().equalsIgnoreCase("playerinfo")){
                Player target = sender.getServer().getPlayer(args[0]);
                //Call getlocation method here!
            }
            return false;
        }
       
        //Disabling plugin message
        @Override
        public void onDisable(){
            getLogger().info("[PlayerInfo] has been disabled");
        }
    }
     
    

    And here is my PlayerLocation class

    Code:
    package com.github.walk2222;
    import org.bukkit.ChatColor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    public class PlayerLocation {
       
        @SuppressWarnings("null")
        public static boolean getlocation(Player playerloc) {
            int px = (int) playerloc.getLocation().getX();
            int py = (int) playerloc.getLocation().getY();
            int pz = (int) playerloc.getLocation().getZ();
     
            CommandSender player = null;
            player.sendMessage(ChatColor.AQUA + "X: "+px+" Y: "+py+" Z: "+pz);
            return false;
        }
    }
    
     
  2. Offline

    Tirelessly

    PlayerLocation.getLocation(target)
    Make it also take an argument of CommandSender so that it isn't null.
     
  3. Offline

    WALK2222

    what argument would you suggest adding?
     
  4. Offline

    CubixCoders

    getLocation(CommandSender sender, Player target){
     
  5. Offline

    Technius

    Instead of CommandSender player, use what CubixCoders posted above so it looks like this:
    Code:
    sender.sendMessage("Your message here");
    
     
  6. Offline

    WALK2222

    I'm sorry I'm a major newbie at this. Could someone change some things in the code I provided so it is correct?

    Thanks for all your help so far by the way
     
  7. Offline

    Tirelessly

    Code:java
    1.  
    2. public static void getlocation(Player playerloc, CommandSender player) {
    3. int px = (int) playerloc.getLocation().getX();
    4. int py = (int) playerloc.getLocation().getY();
    5. int pz = (int) playerloc.getLocation().getZ();
    6.  
    7. player.sendMessage(ChatColor.AQUA + "X: "+px+" Y: "+py+" Z: "+pz);
    8. }
    9. public boolean onCommand(CommandSender sender, Command cmd, String label, String [] args){
    10. if(cmd.getName().equalsIgnoreCase("playerinfo")){
    11. Player target = sender.getServer().getPlayer(args[0]);
    12. PlayerLocation.getLocation(target, sender);
    13. }
    14. return false;
    15. }
    16.  


    Please don't just copy and paste and actually attempt to understand what is going on.
     
  8. Offline

    WALK2222

    Aha! Thank you so much!
     
Thread Status:
Not open for further replies.

Share This Page