Sub Routines

Discussion in 'Plugin Development' started by JooshYT, Mar 5, 2015.

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

    JooshYT

    Is there anything like Sub Routines for a java plugin, e.g Create a subroutine and then i call like checkScore() it will run that code?
     
  2. Offline

    mine-care

    What you mean sub routine?
    You mean a method?
    You mean a thread?
     
  3. Offline

    JooshYT

    Method, so i can say Call that method to check a players score
     
  4. Offline

    Konato_K

    @JooshYT Yes, they exist, and you can call them as much as you want
     
  5. Offline

    JooshYT

    Would i just do
    public static void checkPoints {

    }
    then how would i call it?
     
  6. Offline

    timtower Administrator Administrator Moderator

    @JooshYT Try to avoid static. And a method is a basic java thing.
     
  7. Offline

    JooshYT

    I tried public static void essentials() {

    }
    but that dosnt work, what would i need to do instead?
     
  8. Offline

    Konato_K

  9. Offline

    JooshYT

    Code:
         //Inventory sorter
         public void inventory(){
             for(Player player: getServer().getOnlinePlayers()) {
                 //------------------------
                 //Set players inventory up
                 //------------------------
                 //Set armour
                 ItemStack chestplate = new ItemStack(Material.LEATHER_CHESTPLATE);
                 player.getInventory().setChestplate(chestplate);
                 ItemStack boots = new ItemStack(Material.GOLD_BOOTS);
                 player.getInventory().setBoots(boots);
                 ItemStack hat = new ItemStack(Material.SKULL_ITEM);
                 player.getInventory().setHelmet(hat);
                 //------------------------
                 ItemStack woodSword = new ItemStack(Material.WOOD_SWORD);
                 player.getInventory().setItem(0, woodSword);
                 ItemStack infiniBow = new ItemStack(Material.BOW);
                 player.getInventory().setItem(1, infiniBow);
             }
         }
         
    This works here, is there any way i could add an envhantment to the item stacks?
     
  10. Offline

    Konato_K

  11. Offline

    JooshYT

    ok, thanks. So i dont have to create a new post is there a way to create a variable that includes their name e.g.
    String score + player.getName() = "500";

    then i can change their score by doing like

    score + player.getName() =+ 10;

    so i can set a player to have a individual score?
     
    Last edited: Mar 5, 2015
  12. Offline

    Konato_K

    @JooshYT Mmmmm your question is hard to understand, but if it is what I think you may want to take a look at Maps
     
  13. Offline

    JooshYT

    i dont know what i should look for in there.
    I need like it to store players scores on the server but its only emp so im not storing to a config. And as the variable to keep their score number in i want the variable to be "scoreTheirName" as a string.
     
  14. Offline

    Konato_K

    @JooshYT A String it's expensive if you want to modify it

    Use a Map<UUID, Integer>, store the UUID of the player (or you can even store their name, since you're going to use it and you say it's only temporal) and the score as the Integer
     
  15. Offline

    JooshYT

    Im not sure how i would set that as a variable. would it be like
    int scoreMap<p.getName(), Integer> = 500;
     
  16. Offline

    mine-care

    I will agree with @timtower, before you start bukkit API that is based on java, learn java! Or at least the basics! What you are asking here is a java 101 basic, one of the first things you learn,
    So spend some time N effort to learn java, it will make things much easier to understand and process.
    Cheers!
     
Thread Status:
Not open for further replies.

Share This Page