Solved Max numbers of player

Discussion in 'Plugin Development' started by StatywPlay, Aug 25, 2014.

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

    StatywPlay

    Code:
    Code:
    if (cmd.getName().equalsIgnoreCase("join")) {
                if (sender instanceof Player) {
                    Player player = (Player) sender;
                    if (!(player.hasPermission("event.join") || player.hasPermission("event.*") || player.isOp())) {
                        plugin.send(player, "no-permission");
                        return true;
                    } else {
                        if (args.length >= 0) {
                            if (plugin.getInfo().inevent.containsKey(player.getName())) {
                                plugin.send(player, "already-in-event");
                                return true;
                            }
                            if (!plugin.getInfo().eventstarting) {
                                plugin.send(player, "no-events");
                                return true;
                            } else {
                                plugin.getInfo().inevent.put(player.getName(), plugin.getEventName());
                                plugin.send(player, "joined-event", Integer.toString(plugin.getInfo().inevent.size()));
                                Bukkit.getServer().getPluginManager().callEvent(new MiniEventsJoinEvent(player, plugin.getEventName(),
                                        plugin.getInfo().inevent.size(), plugin.getTimerMain().getTimeLeft(), plugin.getInfo().inevent));
                            }
                        }
                    }
                }
            }
    how to do that examined the quantity of people who joined and if there is more than x people is blocking further joining
    I am weak in this
     
  2. Offline

    Konkz

    I'm guessing you have an ArrayList of people playing.
    PHP:
    if (participants.getSize() >= 5) {
    Bukkit.broadcastMessage("Lol, nope.");
    } else {
    Bukkit.broadcastMessage("Welcome!");
    }
     
  3. Offline

    StatywPlay

    I imported the hashmap which contains the number of players

    Code:java
    1. public class MiniEventsJoinEvent extends Event {
    2. private static final HandlerList handlers = new HandlerList();
    3.  
    4. Player player;
    5. String string;
    6. Integer newsize;
    7. Integer getTimeLeft;
    8. HashMap<String, String> players;
    9.  
    10. public MiniEventsJoinEvent(Player player, String string, Integer newsize
    11. , Integer getTimeLeft, HashMap<String, String> players) {
    12. this.player = player;
    13. this.string = string;
    14. this.newsize = newsize;
    15. this.getTimeLeft = getTimeLeft;
    16. this.players = players;
    17. }
    18.  
    19. /**
    20. * @return the name of the event.
    21. */
    22. public String getEventName() {
    23. return this.string;
    24. }
    25.  
    26. /**
    27. * @return the player who joined the event.
    28. */
    29. public Player getPlayer() {
    30. return this.player;
    31. }
    32.  
    33. /**
    34. * @return the number of players in the event.
    35. */
    36. public int getAmountOfPlayersInEvent() {
    37. return newsize;
    38. }
    39. ...


    How to load amount of players placed in the newsize to
    Code:java
    1. if (!plugin.HERE >= 5) {
    2. plugin.send(player, "full-event");
    3. return true;
     
Thread Status:
Not open for further replies.

Share This Page