Cancel PlayerJoinEvent?

Discussion in 'Plugin Development' started by FlareLine, Sep 30, 2013.

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

    FlareLine

    Hi. I'm making a plugin that cancels the PlayerJoinEvent for a player if that player is already online.
    I have this:
    Code:java
    1. package dev.flareline.ipcheck;
    2.  
    3. import java.io.File;
    4.  
    5. import java.util.ArrayList;
    6.  
    7. import org.bukkit.entity.Player;
    8.  
    9. import org.bukkit.event.Event;
    10.  
    11. import org.bukkit.event.Listener;
    12.  
    13. import org.bukkit.event.player.PlayerJoinEvent;
    14.  
    15. import org.bukkit.event.player.PlayerQuitEvent;
    16.  
    17. import org.bukkit.plugin.java.JavaPlugin;
    18.  
    19. public class IPCMain extends JavaPlugin implements Listener {
    20.  
    21. public static ArrayList<String> OnlinePlayers = new ArrayList<String>();
    22.  
    23. @Override
    24.  
    25. public void onEnable() {
    26.  
    27. // Start Configuration
    28.  
    29. File ConfigFile = new File("/config.yml");
    30.  
    31. if (!ConfigFile.exists()) {
    32.  
    33. this.saveDefaultConfig();
    34.  
    35. getLogger().info("Default Config Saved.");
    36.  
    37. } else {
    38.  
    39. getLogger().info("Config File Exists.");
    40.  
    41. }
    42.  
    43. // End Configuration
    44.  
    45. }
    46.  
    47. @Override
    48.  
    49. public void onDisable() {
    50.  
    51. }
    52.  
    53. public void PlayerJoin(PlayerJoinEvent e, Player player) {
    54.  
    55.  
    56.  
    57. if (OnlinePlayers.contains(player.getName())){
    58.  
    59. }
    60.  
    61. for (Player all : getServer().getOnlinePlayers()) {
    62.  
    63. OnlinePlayers.add(all.getName());
    64.  
    65. }
    66.  
    67. }
    68.  
    69.  
    70.  
    71. public void PlayerQuit(PlayerQuitEvent e, Player player) {
    72.  
    73.  
    74.  
    75. OnlinePlayers.remove(player.getName());
    76.  
    77.  
    78.  
    79. }
    80.  
    81. }

    But I don't know what to put in the JoinEvent. Cheers,
    FlareLine.
     
  2. Offline

    kreashenz

    You're not doing it correct at all...
    You'd need to make a custom PlayerJoinEvent and hook into when the player joins, ect, to be able to call it.. Also, methods are set up wrong. And you need @EventHandler.
     
  3. Offline

    autoit4you

  4. Offline

    FlareLine

    @kreashenzIf it is all wrong, don't just complain that it is not what you desire. Give me an example and be helpful rather than stating the obvious.
    autoit4you Thanks for your input. I have managed to improve it and make it work. Cheers.
    FlareLine.
     
  5. Offline

    Garris0n


    I doubt he desires much of anything in your code. The problem was it wasn't what you desired, and he told you what to fix.
     
  6. Offline

    FlareLine

    Garris0n Again, I asked him to give me an example, not to complain that my coding was wrong. Telling me it's wrong without giving me an example of how to fix it isn't helpful at all.
     
  7. Offline

    xTrollxDudex

    This is called "asking for code" around here. Events may only contain one and ONLY one parameter. If you want to prevent players from joining, use player.kickPlayer(String message);
     
Thread Status:
Not open for further replies.

Share This Page