[SOLVED] One IP

Discussion in 'Plugin Development' started by Accelerator74, May 27, 2012.

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

    Accelerator74

    Code:
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class DoubleIP extends JavaPlugin implements Listener 
    {
    	 private static final Logger log = Logger.getLogger("minecraft");
    	 
    	  public void onEnable()
    	  {
    			PluginDescriptionFile pdfFile = getDescription();
    			log.info(pdfFile.getName() + " (ver " + pdfFile.getVersion() +") enable");
    	  }
    	  
    	  @EventHandler(priority=EventPriority.NORMAL)
    	  public void onPlayerLogin(PlayerLoginEvent event) 
    	  {
    			Player[] Players = Bukkit.getServer().getPlayersOnline();
    			
    			for (int i = 0; i < Players.length; i++)
    			{
    				if (!event.getPlayer().hasPermission("doubleip.ignore") && Players[i].getAddress().getHostString().equals(event.getPlayer().getAddress().getHostString())) 
    				{
    					event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Only one IP!");
    				}
    			}
    	  }
    }
    This code checks whether there is a player on the server with the same IP. And if the IP match, connecting player is disconnect. But the code does not work. What is the problem?
     
  2. Offline

    SirTyler

    You don't register the listener.
     
  3. Offline

    Accelerator74

    Code:
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class DoubleIP extends JavaPlugin
    {
    	 private static final Logger log = Logger.getLogger("minecraft");
    	 
    	  public void onEnable()
    	  {
    			PluginDescriptionFile pdfFile = getDescription();
    			log.info(pdfFile.getName() + " (ver " + pdfFile.getVersion() +") enable");
    	  }
    	  
    	  @EventHandler(priority=EventPriority.NORMAL)
    	  public void onPlayerLogin(PlayerLoginEvent event) 
    	  {
    			Player[] Players = Bukkit.getServer().getOnlinePlayers();
    			
    			for (int i = 0; i < Players.length; i++)
    			{
    				if (!event.getPlayer().hasPermission("doubleip.ignore") && Players[i].getAddress().getHostString().equals(event.getPlayer().getAddress().getHostString())) 
    				{
    					event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Only one IP!");
    				}
    			}
    	  }
    }
    Still does not work.
     
  4. Did you actually changed the code at any point? still don't see the registration of the event...
     
  5. Offline

    Accelerator74

    Did so
    Code:
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class DoubleIP extends JavaPlugin implements Listener
    {
    	 private static final Logger log = Logger.getLogger("minecraft");
    	 
    	  public void onEnable()
    	  {
    			PluginDescriptionFile pdfFile = getDescription();
    			log.info(pdfFile.getName() + " (ver " + pdfFile.getVersion() +") enable");
    			
    			getServer().getPluginManager().registerEvents(this, this);
    	  }
    	  
    	  @EventHandler
    	  public void onPlayerLogin(PlayerLoginEvent event) 
    	  {	
    			for (Player Players : Bukkit.getServer().getOnlinePlayers())
    			{
    				if (!event.getPlayer().hasPermission("doubleip.ignore") && Players.getAddress().getHostString().equals(event.getPlayer().getAddress().getHostString()))
    				{
    					event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Only one IP!");
    				}
    			}
    	  }
    }
    Error:
    Code:
    2012-05-27 22:43:21 [SEVERE] Could not pass event PlayerLoginEvent to Protect Double IP
    org.bukkit.event.EventException
    	at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:304)
    	at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    	at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:459)
    	at net.minecraft.server.ServerConfigurationManager.attemptLogin(ServerConfigurationManager.java:227)
    	at net.minecraft.server.NetLoginHandler.b(NetLoginHandler.java:102)
    	at net.minecraft.server.NetLoginHandler.a(NetLoginHandler.java:94)
    	at net.minecraft.server.Packet1Login.handle(SourceFile:68)
    	at net.minecraft.server.NetworkManager.b(NetworkManager.java:229)
    	at net.minecraft.server.NetLoginHandler.a(NetLoginHandler.java:48)
    	at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:61)
    	at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:567)
    	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459)
    	at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.NullPointerException
    	at Accelerator.DoubleIP.DoubleIP.onPlayerLogin(DoubleIP.java:29)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302)
    	... 12 more
     
  6. Which line is line 29 of the file DoubeIP.java? there the problem occurs...
    read: http://forums.bukkit.org/threads/ho...ubleshoot-your-own-plugins-by-yourself.32457/
    greetz blackwolf12333
     
  7. Offline

    Accelerator74

    Code:
    if (!event.getPlayer().hasPermission("doubleip.ignore") && Players.getAddress().getHostString().equals(event.getPlayer().getAddress().getHostString()))
     
  8. Try to check first if Players is null or not, and then use it, otherwise you get a npe.
    greetz blackwolf12333
     
  9. Offline

    Accelerator74

    Code:
    if (!event.getPlayer().hasPermission("doubleip.ignore") && (Players != null) && Players.getAddress().getHostString().equals(event.getPlayer().getAddress().getHostString()))
    An error has remained.

    Problem solved! It was necessary to use PlayerJoinEvent

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  10. Oh, yeah, didn't look at that:p
     
Thread Status:
Not open for further replies.

Share This Page