Help with ip blacklisting

Discussion in 'Spigot Plugin Development' started by UnlimitedNinjas, Jul 17, 2018.

  1. How do i make it so when a player tries to join and if the ip starts with numbers from config list it blocks it?
    This is what i have:
    Code (Text):
        public void onPlayerJoin(PlayerJoinEvent e) {
            if (e.getPlayer().getAddress().toString().startsWith(null, getConfig().getStringList("blacklist").size())) {
                e.getPlayer().kickPlayer(ChatColor.RED + "Your IP is blacklisted!");
    Code (Text):
    #Blacklisted ips
    - 79
  2. Erm, why are you calling .startsWith(null, configString.size()?
    Surely you want a for loop on your string list from your config and just call .startsWith(configString)
  3. i tried just with the configstring but it is underlined and it asks for there to be sometihng infront of it.
    also i just found out nullpointerexeptoion on console:
    Code (Text):
    17.07 11:16:15 [Server] ERROR Could not pass event PlayerJoinEvent to UPGamers v3.0
    17.07 11:16:15 [Server] INFO org.bukkit.event.EventException: null
    17.07 11:16:15 [Server] INFO at$1.execute( ~[spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
    17.07 11:16:15 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent( ~[spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
    17.07 11:16:15 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent( [spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
    17.07 11:16:15 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent( [spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
    17.07 11:16:15 [Server] INFO at net.minecraft.server.v1_12_R1.PlayerList.onPlayerJoin( [spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
    17.07 11:16:15 [Server] INFO at net.minecraft.server.v1_12_R1.PlayerList.a( [spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
    17.07 11:16:15 [Server] INFO at net.minecraft.server.v1_12_R1.LoginListener.b( [spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
    17.07 11:16:15 [Server] INFO at net.minecraft.server.v1_12_R1.LoginListener.e( [spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
    17.07 11:16:15 [Server] INFO at net.minecraft.server.v1_12_R1.NetworkManager.a( [spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
    17.07 11:16:15 [Server] INFO at net.minecraft.server.v1_12_R1.ServerConnection.c( [spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
    17.07 11:16:15 [Server] INFO at net.minecraft.server.v1_12_R1.MinecraftServer.D( [spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
    17.07 11:16:15 [Server] INFO at net.minecraft.server.v1_12_R1.DedicatedServer.D( [spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
    17.07 11:16:15 [Server] INFO at net.minecraft.server.v1_12_R1.MinecraftServer.C( [spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
    17.07 11:16:15 [Server] INFO at [spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
    17.07 11:16:15 [Server] INFO at [?:1.8.0_171]
    17.07 11:16:15 [Server] INFO Caused by: java.lang.NullPointerException
    17.07 11:16:15 [Server] INFO at java.lang.String.startsWith( ~[?:1.8.0_171]
    17.07 11:16:15 [Server] INFO at ~[?:?]
    17.07 11:16:15 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_171]
    17.07 11:16:15 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke( ~[?:1.8.0_171]
    17.07 11:16:15 [Server] INFO at sun.reflect.DelegatingMethodAccessorImpl.invoke( ~[?:1.8.0_171]
    17.07 11:16:15 [Server] INFO at java.lang.reflect.Method.invoke( ~[?:1.8.0_171]
    17.07 11:16:15 [Server] INFO at$1.execute( ~[spigot-1.12.2.jar:git-Spigot-2086bb0-d0a3620]
    17.07 11:16:15 [Server] INFO ... 14 more
  4. Are you sure?... Have you taken a look at this link?
  5. Isn't that exactly what you're trying to do? Get a boolean based on the start of a string?
  6. I really dont see how this helps...
  7. Well... You're turning the IP into a string... And seeing if it starts with 79 right? Isn't that exactly what that link explains with different strings?
  8. But how do use the getconfig.getstringlist with starts with? Link just shows normal strings: " "
  9. Well, it's a list. Either loop through the list or get a specific string value. It literally returns a List<String>