0

Using pIRCBot.

Class: pIRC.java
protected void onJoin(String channeljoined, String sender, String login, String hostname) {
    Bukkit.getLogger().log(Level.INFO, "Channel joined: " + channeljoined + ". IRC channel: " + IRC.channel + "." );
    if(channeljoined == IRC.channel)
    {
        Bukkit.getLogger().log(Level.INFO, "--");
        for (Player player : Bukkit.getOnlinePlayers()) {
            player.sendMessage(ChatColor.translateAlternateColorCodes('&',"&c[IRC]&e " + sender + "&f has joined the IRC channel."));
        }
    }
}

My IRC class has this:

Class: IRC.java
public static String channel;

Then I change the channel to a String got from a config file:

Class: IRC.java
channel = this.getConfig().getString("publicchannel");

And now whenever a user joins the IRC channel it prints:

[11:03:53 INFO]: Channel joined: #MoMoMC. IRC channel: #MoMoMC.

But it won't proceed to the next if statement. Am I doing something wrong?

neo73
  • 434
  • 5
  • 20
  • use equals not == – johnII Dec 27 '17 at 06:14
  • as both are String try with equals methods. hope that will work. – Nidhi257 Dec 27 '17 at 06:14
  • `if` statements, if they execute, execute once and only once. For repeated execution, you need some sort of loop (`do`, `while`, or `for`). But your bigger problem is that you are trying to compare strings using `==`. Don't do that. Use `String#equals` instead (and read the duplicate link). – Tim Biegeleisen Dec 27 '17 at 06:14

1 Answers1

0

You are comparing String with ==, Always comare String with .equals method. String is a class. The function checks the actual contents of the string, the == operator checks whether the references to the objects are equal. Please change condition like this:

if(channeljoined.equals(IRC.channel))
Sandeep Kokate
  • 825
  • 4
  • 16