Help with static keyword

Discussion in 'Plugin Development' started by bobthefish, Jun 2, 2014.

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

    bobthefish

    Hi, Im making a plugin that does a number of things, this part dealing with inventories.

    This is my inventory class:
    Code:java
    1. public void onInventoryClick(InventoryClickEvent event) {
    2. Player player = (Player) event.getWhoClicked();
    3. Inventory inventory = event.getInventory();
    4.  
    5. if (inventory.getName().equals(myInventory.getName()))
    6. {
    7. if (event.getSlot() == 0) {
    8. event.setCancelled(true);
    9. player.closeInventory();
    10. Join.Dynasty(player);
    11. }
    12. else if (event.getSlot() == 1) {
    13. event.setCancelled(true);
    14. player.closeInventory();
    15. Join.Eldin(player);
    16. }


    and here is the Join class:

    Code:java
    1. import org.bukkit.Bukkit;
    2. import org.bukkit.ChatColor;
    3. import org.bukkit.entity.Player;
    4.  
    5. public class Join {
    6.  
    7. public String team;
    8.  
    9. public void Dynasty(Player p){
    10. team = "d";
    11.  
    12. if(p.getName().contains("[")&&p.getName().contains("]"))
    13. p.setDisplayName(p.getDisplayName().substring(p.getDisplayName().length()-10,p.getDisplayName().length()));
    14. else
    15. p.setDisplayName(p.getDisplayName() + ChatColor.DARK_PURPLE + " [" + ChatColor.GOLD + "DY" + ChatColor.DARK_PURPLE + "]");
    16. Bukkit.broadcastMessage(ChatColor.DARK_GRAY + p.getName() + ChatColor.RESET + " has joined Dynasty!!! (This is just a Alpha setting, more will follow in future updates)");
    17. }


    Im getting an error in the inventory class at Join.*(player), it says that


    Cannot make a static reference to the non-static method Dynasty(Player) from the type Join

    I have no idea what this means, can you help me?
     
  2. Offline

    CraftCreeper6

    bobthefish
    In your Join class just before the void put static
    Code:java
    1. public static void Dynasty(Player p){
     
  3. Offline

    fireblast709

    Please, refrain from using static relentlessly without actually knowing the extends of what it does.
     
    xTrollxDudex and L33m4n123 like this.
  4. Offline

    xTrollxDudex

    Please take a moment to think through what it means to use static. And learn OOP.

    TL;DR to statics
     
    CoderMusgrove and Garris0n like this.
Thread Status:
Not open for further replies.

Share This Page