Solved Help with constructors in plugins!

Discussion in 'Plugin Development' started by Chaseg23, May 6, 2014.

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

    Chaseg23

    Okay, so constructors have failed to work in any way for me. I'm sure I'm doing them wrong, but I truly cant see how. I've made an incredibly simple program that doesn't even need a constructor or multiple classes to make to test this.

    Main class:

    Code:java
    1. package me.chaseg23.src;
    2.  
    3. import java.util.logging.Logger;
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class Test extends JavaPlugin{
    11. public static final Logger log = Logger.getLogger("Minecraft");
    12. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    13. Player player = (Player) sender;
    14. if(label.equalsIgnoreCase("Test")){
    15. Bukkit.broadcastMessage("Broadcast");
    16. Message messageobject = new Message(player);
    17. }
    18. return false;
    19. }
    20. }
    21.  


    Second Class:

    Code:java
    1. package me.chaseg23.src;
    2.  
    3. import org.bukkit.entity.Player;
    4.  
    5. public class Message {
    6.  
    7. public Message(Player player) {
    8. player.sendMessage("Message");
    9. }
    10.  
    11. }
    12.  


    When I run this I get an error telling me that "The constructor Message(Player) is undefined". Is it not clearly defined? What am I doing wrong? Thanks in advance. BTW, I'm using Eclipse.
     
  2. It doesn't look like you imported your second class. After you do, try
    Code:
    Message(Your player here)
     
  3. Offline

    Chaseg23


    Huh.. Yup. I didn't think that i needed to do that. Part of me is thankful that there's an easy solution and part of me is mad that it was such an obvious mistake. Thank you!
     
  4. No Problem! Glad I could help!
     
Thread Status:
Not open for further replies.

Share This Page