Tutorial Make a minigame plugin!

Discussion in 'Resources' started by xTrollxDudex, Aug 15, 2013.

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

    xTrollxDudex

    Wait whut?
     
  2. Offline

    DrMedia

    I'm being a little optimistic ;)
     
  3. Offline

    xTrollxDudex

    Okay... Not sure if a good or bad thing...
     
  4. Offline

    DrMedia

    Good :p
     
  5. Offline

    Philitup321

    Great tutorial, but I just had a few questions.
    How would I make a minimum and maximum amount of player, and then checking if the arena has the max players? And how could I send a message to all the players in an arena?
     
  6. Offline

    xTrollxDudex

    Philitup321
    When you call the addPlayer(Player, int) method, go through the list if players (List#size() returns the size of the list, not the amount of elements in it) in the arena which you are adding the player to:
    PHP:
    // this goes under ArenaManager#addPlayer(Player, int)
    int total 0;
    for(
    String s a.getPlayers()) {
        
    total++;
    }

    //if it is more or equal to your total, broadcast a message
    if(total >= /* max player amount */) {
        for(
    String s a.getPlayers) {
            
    Player p Bukkit.getServer().getPlayerExact(s);
            if(
    != null)
                
    p.sendMessage(/* your message here */);
        }
    }
     
  7. Offline

    Philitup321

    xTrollxDudex
    Ok, thanks!
    And just a quick note, shouldn't there be another ( ) after .getPlayers?
     
  8. Offline

    xTrollxDudex

    Philitup321
    Oh yeah, i was typing on a phone sorry :p
     
  9. Offline

    BotLover

    How would I teleport all the players in the arena at once
     
  10. Offline

    xTrollxDudex

    BotLover
    PHP:
    for(Player player Bukkit.getServer().getOnlinePlayers()) {
        
    ArenaManager.getManager().addPlayer(player/* The ID of the arena */);
    }
     
  11. Offline

    BotLover

    I mean the players that already joined the game.
     
  12. Offline

    jusjus112

    xTrollxDudex
    I have an command called /gunmaster join <arena>
    But i have this code:
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("join")){
    2. if(args.length != 1){
    3. p.sendMessage("Insuffcient arguments!");
    4. return true;
    5. }
    6. int num = 0;
    7. try{
    8. num = Integer.parseInt(args[0]);
    9. p.sendMessage("Invalid arena ID");
    10. }
    11. ArenaManager.getManager().addPlayer(p, num);
    12.  
    13. return true;
    14. }

    How do i put in the code what the arguments is for the <arena> ?
    i tried args[1] or something, but it dont let me do it?
     
  13. Offline

    xTrollxDudex

    jusjus112
    Like this:
    PHP:
    if(cmd,getName().equalsIgnoreCase("gunmaster") && args.length == && args[0].equalsIgnoreCase("join")) {
        
    int num 0;
            try{
                    
    num Integer.parseInt(args[1]);
                }catch(
    NumberFormatException e){
                    
    p.sendMessage("Invalid arena ID");
                }
                
    ArenaManager.getManager().addPlayer(pnum);
     
                return 
    true;
            }
    BotLover
    What? When you join a game, you're supposed to be auto tp'd to spawn...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Dec 6, 2015
  14. Offline

    jusjus112

    xTrollxDudex
    And BTW, i have figured out ho to add multiple spawn!
    But i dont know if i doing right?
    Can you tell me if this is right?
    My arena class:
    Code:java
    1. //you want some info about the arena stored here
    2. public int id = 0;//the arena id
    3. Location lobby = null;//spawn location for the arena
    4. Location spawn1 = null;//spawn location for the arena
    5. Location spawn2 = null;//spawn location for the arena
    6. List<String> players = new ArrayList<String>();//list of players
    7.  
    8. //now let's make a few getters/setters, and a constructor
    9. public Arena(Location loc, int id){
    10. this.lobby = loc;
    11. this.spawn1 = loc;
    12. this.spawn2 = loc;
    13. this.id = id;
    14. }
    15.  
    16. public int getId(){
    17. return this.id;
    18. }
    19.  
    20. public List<String> getPlayers(){
    21. return this.players;
    22. }
    23. }

    And if an player adds to the arena and tps to the lobby:
    Code:java
    1. public void addPlayerlobby(Player p, int i){
    2. Arena a = getArena(i);//get the arena you want to join
    3. if(a == null){//make sure it is not null
    4. p.sendMessage("Invalid arena!");
    5. return;
    6. }
    7.  
    8. a.getPlayers().add(p.getName());//add them to the arena list of players
    9. inv.put(p.getName(), p.getInventory().getContents());//save inventory
    10. armor.put(p.getName(), p.getInventory().getArmorContents());
    11.  
    12. p.getInventory().setArmorContents(null);
    13. p.getInventory().clear();
    14.  
    15. p.teleport(a.lobby);//teleport to the arena spawn
    16. }
    17.  
    18. public void addPlayerspawn1(Player p, int i){
    19. Arena a = getArena(i);//get the arena you want to join
    20. if(a == null){//make sure it is not null
    21. p.sendMessage("Invalid arena!");
    22. return;
    23. }
    24.  
    25. a.getPlayers().add(p.getName());//add them to the arena list of players
    26. inv.put(p.getName(), p.getInventory().getContents());//save inventory
    27. armor.put(p.getName(), p.getInventory().getArmorContents());
    28.  
    29. p.teleport(a.spawn1);//teleport to the arena spawn
    30. }
    31. public void addPlayerspawn2(Player p, int i){
    32. Arena a = getArena(i);//get the arena you want to join
    33. if(a == null){//make sure it is not null
    34. p.sendMessage("Invalid arena!");
    35. return;
    36. }
    37.  
    38. a.getPlayers().add(p.getName());//add them to the arena list of players
    39.  
    40. p.teleport(a.spawn2);//teleport to the arena spawn
    41. }

    If this is right, could you tell me how do i set the spawns for spawn1 and spawn2 with an command?
     
  15. Offline

    BotLover

    No, I mean when there's a certain amount of players it tps all of them to the arena
     
  16. Offline

    xTrollxDudex

    BotLover
    Like on the server? You could check on PlayerJoinEvent and see if Bukkit.getOnlinePlayers().length is the amount you want and then loop through Bukkit.getOnlinPlayers() and teleport each player to the arena. You could also schedule a repeating task.

    jusjus112
    You could see if the 2nd argument is a specific value like
    /gunmaster join <something> <arena id>
    And call a specific method accordingly.
     
  17. Offline

    Littledaddychop

    How could you make payers join through signs

    xTrollxDudex
     
  18. Offline

    jusjus112

    xTrollxDudex
    But did you see my code for more arena spawns?
    And mybe you know how to set those spawns?
     
  19. Offline

    xTrollxDudex

    Littledaddychop
    Listen to PlayerInteractEvent, check if the block is a sign, the cast the block's state to org.bukkit.block.Sign, and you can use Sign#getLine(int) to see which lines are which. int starts at 0.

    jusjus112
    Ah. Well you could do it the same way:
    /gunmaster set <spawn number> <arena>
    PHP:
    if(args[0].equals("1")) {
        
    ArenaManager.getManager().getArena(Integer.parseInt(args[1])).spawn1 = ((Playersender).getLocation();
    //ect...
     
  20. Offline

    jusjus112

    xTrollxDudex
    This sets the config automaticly right?
    Or must i set it?
     
  21. Offline

    xTrollxDudex

  22. Offline

    jusjus112

    xTrollxDudex
    Could you tell me how to set DeathMessages or Leavemessage for the arena?
     
  23. Offline

    Littledaddychop

    Wait, how you make it so that a player can click a sign and it would bring up a menu?
    xTrollxDudex
     
  24. Offline

    xTrollxDudex

    jusjus112
    PlayerDeathEvent#setDeathMessage(String)
    You can loop through the players in the arena the player left from in ArenaManager#removePlayer(Player) and send them a message that the player left the arena.

    Littledaddychop
    -_________________________-
    How does this have anything to do with the thread at all?

    Nevertheless, check this out:
    https://gist.github.com/AgentTroll/640cb8dd9a17ee0de57f
     
  25. Offline

    jusjus112

    xTrollxDudex
    Iwill the deathmessages, for an specify arena where the player is!
    I have now an bukkitBroadcastMessage but thats for all of the arenas!

    And BTW i have an erorror on the Inventory save if an player has nothing in their hand, it will return null and get an error
     
  26. Offline

    xTrollxDudex

    jusjus112
    I'm cringing right now at how little you comprehend what this tutorial is for:
    I meant to write this tutorial so people can learn how to manage arenas and stuff, the finer details can be implemented from the comments on each method.

    Again,
    When a player dies, he is still in the list for the arena, so
    PHP:
    for(Arena a arenas) {
        for(
    String s a.getPlayers()) {
            if(
    s.equals(event.getEntity().getName()) 
                
    //broadcast message
        

    }
     
  27. Offline

    Kyozum0

    Hey, how do i make so people spawn in different places, im making a free for ll plugin, i want them to spawn in setted locations on the map! can you give me an idea on how to do it? xTrollxDudex
     
  28. Offline

    xTrollxDudex

    Kyozum0
    Instead of a single location, you can have a List of Locations, you can serialize each of them by using a for loop, similarly for deserializing and use a different method to set the spawns, for example adding the player's location each time, say /spawn set was executed to the arena.

    You get increment the amount of players in the game and use the get(int) to grab a specifc Location from the int index. Make sure the value is less than the suze of the list or an IndexOutOfBounds exception will be thrown.
     
  29. Offline

    Littledaddychop

  30. Offline

    Littledaddychop

    xTrollxDudex
    Hi, sorry I am asking this but in my minigame plugin, I want it to spawn a world that is stored in the jar file. Sorry this is in this thread but I don't know anyone else to go to.
     
Thread Status:
Not open for further replies.

Share This Page