Solved Comparing Username to Config?

Discussion in 'Plugin Development' started by AXCoding, Jul 14, 2014.

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

    AXCoding

    Hi, I'm making a plugin that protects someone's op status by checking if there name is in the config to be protected. For some reason when I call targetPlayer.getName() and I check it against getConfig().getString("protectedplayer") it returns false when they are the same. In this case the target player will be me JasonBourne685.
    Code:java
    1. package me.JasonBourne685.opProtect;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.plugin.PluginDescriptionFile;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class opProtect extends JavaPlugin {
    13. public final Logger logger = Logger.getLogger("Minecraft");
    14. public static opProtect plugin;
    15.  
    16. @Override
    17. public void onDisable() {
    18. PluginDescriptionFile pdfFile = this.getDescription();
    19. this.logger.info(pdfFile.getName() + " has been DISABLED!");
    20. }
    21.  
    22. @Override
    23. public void onEnable() {
    24. PluginDescriptionFile pdfFile = this.getDescription();
    25. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " has been ENABLED!");
    26. getConfig().options().copyDefaults(true);
    27. saveConfig();
    28. }
    29. public boolean onCommand(CommandSender sender,Command cmd,String commandLabel,String[] args){
    30. Player player = (Player) sender;
    31. if(commandLabel.equalsIgnoreCase("deop")){
    32. if (player.hasPermission("bukkit.command.deop")){
    33. if (args.length == 0){
    34. player.sendMessage(ChatColor.RED + "Usage /deop (player)");
    35. }
    36. else if(args.length > 1) {
    37. player.sendMessage(ChatColor.RED + "Cannot DEOP multiple people at the same time!");
    38. }
    39. else if(args.length == 1){
    40. Player targetPlayer = player.getServer().getPlayer(args[0]);
    41. if(targetPlayer.getName() == getConfig().getString("protectedplayer")){
    42. targetPlayer.sendMessage(ChatColor.DARK_RED + "You were protected by OP Protect, " + player.getName() + " just tried to DEOP you!");
    43. }
    44. else if(targetPlayer.getName() != getConfig().getString("protectedplayer")){
    45. targetPlayer.setOp(false);
    46. player.sendMessage(ChatColor.DARK_RED + "You were deoped");
    47. }
    48. }
    49. } else{
    50. player.sendMessage(ChatColor.DARK_RED + "No Permission");
    51.  
    52. }
    53. }
    54. return false;
    55. }
    56.  
    57. }
    58.  

    config.yml is
    protectedplayer: JasonBourne685
     
  2. Offline

    Gater12

    AXCoding
    Use equals or equalsIgnoreCase instead of == when comparing Strings.
     
  3. Offline

    AXCoding

    OMG thank you so much Gater12 It Works! :)
     
Thread Status:
Not open for further replies.

Share This Page