Development Assistance Confused on Error

Discussion in 'Plugin Help/Development/Requests' started by Googlelover1234, Dec 6, 2014.

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

    Googlelover1234

    If you've ever looked in my signature, I have my public plugins (currently one) that are displayed. So, in version "1.0.7" of my plugin, I added a /OPList command, showing all online operators, and all operators in the operator file that comes with Bukkit. I've tested this command quite extensively, and it works perfectly on 1.7.9. I uploaded this version to BukkitDev a few days ago and it seems to have worked fine. However, I've received a ticket from a person who says it does not work (he's using Spigot 1.8). He's sent me the error (http://gyazo.com/75b4b1930af01c7aa13f4041a7f37527) and it obviously says that it cannot cast a "CraftOfflinePlayer" to a "Player". I have checked my code, however, I do not see why this would be showing up. Here's the code:

    Code:java
    1. package com.GummyPvP.AdminEssentials.Commands;
    2.  
    3. import java.util.regex.Matcher;
    4. import java.util.regex.Pattern;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.OfflinePlayer;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandExecutor;
    11. import org.bukkit.command.CommandSender;
    12. import org.bukkit.entity.Player;
    13.  
    14. public class OPList implements CommandExecutor {
    15.  
    16. @Override
    17. public boolean onCommand(CommandSender sender, Command cmd, String arg2,
    18. String[] args) {
    19. if (cmd.getName().equalsIgnoreCase("OPList")) {
    20.  
    21. StringBuilder sb = new StringBuilder();
    22. StringBuilder onlineSB = new StringBuilder();
    23.  
    24. sender.sendMessage(ChatColor.BLUE + "" + ChatColor.STRIKETHROUGH
    25. + "----" + ChatColor.GOLD + " OPList " + ChatColor.BLUE
    26. + "" + ChatColor.STRIKETHROUGH + "----");
    27. sender.sendMessage("");
    28. sender.sendMessage(ChatColor.GREEN + "Online Operators:");
    29. for (OfflinePlayer offlineops : Bukkit.getOperators()) {
    30. if (offlineops.isOnline()) {
    31. Player onlineops = (Player) offlineops;
    32. onlineSB.append(onlineops.getName() + ", ");
    33. }
    34. }
    35.  
    36. String list = onlineSB.toString();
    37. Pattern oPattern = Pattern.compile(", $");
    38. Matcher oMatcher = oPattern.matcher(list);
    39. list = oMatcher.replaceAll("");
    40.  
    41. sender.sendMessage(ChatColor.AQUA + list);
    42.  
    43. sender.sendMessage("");
    44. sender.sendMessage(ChatColor.BLUE + "" + ChatColor.STRIKETHROUGH
    45. + "----------------");
    46. sender.sendMessage("");
    47. sender.sendMessage(ChatColor.RED + "All Operators:");
    48. for (OfflinePlayer offline : Bukkit.getOperators()) {
    49. sb.append(offline.getName() + ", ");
    50. }
    51.  
    52. String playerList = sb.toString();
    53. Pattern pattern = Pattern.compile(", $");
    54. Matcher matcher = pattern.matcher(playerList);
    55. playerList = matcher.replaceAll("");
    56.  
    57. sender.sendMessage(ChatColor.GOLD + playerList);
    58.  
    59. }
    60. return true;
    61. }
    62.  
    63. }
    64.  


    The code is a bit sloppy, I do know, and I intend to recode it, however, I cannot do this until I am for sure there are no bugs in it.
     
  2. Offline

    xTrollxDudex

    Googlelover1234
    Line 31. Operators that are offline can't be cast to Player. Make sure to check if the offline player .isOnline() before casting.
     
  3. Offline

    Googlelover1234

  4. Offline

    teej107

  5. Offline

    Googlelover1234

    I'm guessing so, not sure.

    Alright, will test, thanks!
     
Thread Status:
Not open for further replies.

Share This Page