Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8516355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:24:14+00:00 2026-06-11T05:24:14+00:00

I’ve been programming a Bukkit plugin for a while now, and this one issue

  • 0

I’ve been programming a Bukkit plugin for a while now, and this one issue has me stumped. I’m trying to read a line from a file using a Scanner, and add everything on the line before “: ” to a HashSet. Every time I try, I get a NoSuchElementException, looking like this:

21:01:01 [SEVERE] Could not pass event PlayerLoginEvent to ServerProtect
org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
va:341)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
a:62)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
ava:477)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
ava:462)
        at net.minecraft.server.ServerConfigurationManagerAbstract.attemptLogin(
ServerConfigurationManagerAbstract.java:273)
        at net.minecraft.server.NetLoginHandler.d(NetLoginHandler.java:112)
        at net.minecraft.server.NetLoginHandler.c(NetLoginHandler.java:41)
        at net.minecraft.server.DedicatedServerConnectionThread.a(DedicatedServe
rConnectionThread.java:44)
        at net.minecraft.server.DedicatedServerConnection.b(SourceFile:29)
        at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:578)
        at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:213)
        at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:474)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:406)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
Caused by: java.util.NoSuchElementException: No line found
        at java.util.Scanner.nextLine(Unknown Source)
        at com.gmail.thecotlsdragon98.ServerProtect.AltAccounts.CheckForUsedIP(A
ltAccounts.java:49)
        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.ja
va:339)
        ... 13 more

This is the class where I try to do what I explained above.

package com.gmail.thecotlsdragon98.ServerProtect;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;

public class AltAccounts implements Listener
{
    ServerProtect plugin;
    public AltAccounts(ServerProtect instance){
        plugin = instance;
    }
    File usersFile;
    FileWriter outputFile;
    PrintWriter out;
    Scanner in;
    HashSet<String> players = new HashSet<String>();
    StringBuffer buffer = new StringBuffer();
    @EventHandler
    public void newUsersFile(PluginEnableEvent event) throws IOException{
        if(event.getPlugin() == plugin){
            usersFile = new File("plugins\\ServerProtect\\users.yml");
            if(!usersFile.exists()){
                usersFile.createNewFile();
            }
        }
    }
    @EventHandler
    public void CheckForUsedIP(PlayerLoginEvent event) throws IOException{
        outputFile = new FileWriter(usersFile, true);
        out = new PrintWriter(outputFile);
        in = new Scanner(new FileReader(usersFile));
        String[] nameandIP;
        String name;
        String IP;
        String line = in.nextLine();
        while(in.hasNextLine() && !in.nextLine().isEmpty()){
            players.add(line.split(": ")[0]);
            if(!players.contains(event.getPlayer().getName())){
                out.println(event.getPlayer().getName() + ": " + event.getAddress().getHostAddress());
                out.close();
            }
        }
        if(!in.hasNextLine() || in.nextLine().isEmpty()){
            if(!players.contains(event.getPlayer().getName())){
                out.println(event.getPlayer().getName() + ": " + event.getAddress().getHostAddress());
                out.close();
                players.clear();
            }
        }
        if(!plugin.getConfig().getBoolean("alts.kick-on-login")){
            while(in.hasNextLine()){
                nameandIP = in.nextLine().split(": ");
                name = nameandIP[0];
                IP = nameandIP[1];
                if(event.getAddress().getHostAddress().equals(IP) && !event.getPlayer().getName().equals(name)){
                    for(final Player player : plugin.getServer().getOnlinePlayers()){
                        if(player.hasPermission("serverprotect.alts.notify")){
                            player.sendMessage(ChatColor.RED + event.getPlayer().getName() + " has the same IP as " + name + " (" + event.getAddress().getHostAddress() + ")");
                        }
                    }
                }
            }
        }
        else if(plugin.getConfig().getBoolean("alts.kick-on-login")){
            while(in.hasNextLine()){
                nameandIP = in.nextLine().split(": ");
                name = nameandIP[0];
                IP = nameandIP[1];
                if(event.getAddress().getHostAddress().equalsIgnoreCase(IP)){
                    event.setKickMessage("The IP address you've logged in with is used. Alternate account?");
                    event.setResult(Result.KICK_OTHER);
                }
            }
        }
    }
    public void Disable(PluginDisableEvent event)throws IOException{
        if(event.getPlugin() == plugin){
            in.close();
        }
    }
}

I’ve been told that I’m calling in.nextLine() twice, and when I asked for advice on how to fix it he just ignored me. Any help is greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:24:16+00:00Added an answer on June 11, 2026 at 5:24 am

    try this:

    import java.io.*;
    import java.lang.*;
    import java.util.*;
    public class test {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            while(in.hasNextLine()) {
                String line = in.nextLine();
                String parse = line.substring(0, line.lastIndexOf(':'));
                System.out.println(parse);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.