My plugin is acting different on my servers

Discussion in 'General Help' started by Pacothegint, Dec 10, 2014.

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

    Pacothegint

    My plugin acts differently on both of my servers
    one my own personal and the other my official server on server one it works fine and does what it is supposed to do on the other one it loops and just stops. I know it has something to do with the amount of players and how I get them but I do not know how to stop it.

    what gets called and is supposed to do stuff

    Code:java
    1. public void onSignchange(SignChangeEvent event){
    2. int lineCount = 1;
    3. String linetwo = event.getLine(1);
    4. Player placer = event.getPlayer();
    5. console.sendMessage(placer.getName()+" has created a sign");
    6. for(OfflinePlayer offlineplayer:Bukkit.getOfflinePlayers()){
    7. Player player =offlineplayer.getPlayer();;
    8. if(event.getLine(0).equalsIgnoreCase("[RankSign]"))
    9. if(placer.hasPermission("ranksign.create")){
    10. if(Main.permission.playerInGroup(player, linetwo)){
    11. if (lineCount > 3)
    12. break; // Break out of the loop so you don't get an exception if you try setting line 5 (line 4, in terms of arrays), since that line won't exist on the sign.
    13.  
    14. event.setLine(lineCount, player.getName());
    15. String prefix = Main.chat.getPlayerPrefix(player);
    16. lineCount++;
    17. //It never gets here
    18.  
    19. event.setLine(0,ChatColor.translateAlternateColorCodes('&',prefix));
    20. placer.sendMessage(ChatColor.GREEN+ "RankSign Created successfully for group"+event.getLine(0));
    21. }
    22. else{
    23. placer.sendMessage(ChatColor.RED+"No player in Group: "+ChatColor.BLACK+"["+ChatColor.RESET+event.getLine(1)+ChatColor.RED+ChatColor.BLACK+ "]"+ChatColor.RED+ " could be found!!");
    24. console.sendMessage("Sign has failed");
    25. }
    26. }
    27. else{
    28. //Does Send this a million times but I know why
    29.  
    30. placer.sendMessage(ChatColor.RED+"You Do NOT have the right permissions!!!");
    31. console.sendMessage("Sign has failed");
    32. }
    33. }
    34. }

    If the sign is
    [ranksign]
    owner

    on server one it will set the sign to
    [owner]
    (player)
    (player)
    (player)

    On server two it will sit there and set the sign to
    [ranksign]
    owner


    Any ideas?
     
  2. Offline

    Rocoty

    Get any errors in the console?
     
  3. Offline

    Pacothegint

  4. Offline

    Tehmaker

    @Pacothegint
    So it works on one server, but not the other? If it is the same exact version of the plugin, it might be incompatible with another plugin on that server.
     
  5. Offline

    Skionz

    @Pacothegint Are you using the same server software? Is it an official craftbukkit build?
     
  6. Offline

    Pacothegint

    @Skionz
    Both servers are a 1.8 spigot build that I compiled

    @Tehmaker
    It's not my plugins just checked them.
    Also not sure why this was moved as this is a development problem?

    @Skionz @Tehmaker

    Hold it I just found this error message

    caused by: java.lang.NullPointerException
    at net.milkbowl.vault.permission.Permission.playerInGroup(Permission.java:560) ~[?:?]
    at percycraft.fluctis.com.PlayerListener.onSignchange(PlayerListener.java:32) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_03]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_03]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1


    that means
    Code:java
    1. if(Main.permission.playerInGroup(player, linetwo)){
    2. //Do stuff
    3. }
    4.  

    is causing the error but that makes no since because it does not on my personal server

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
  7. Offline

    Skionz

    @Pacothegint Post both of the relevant classes in their entirety.
     
  8. Offline

    Pacothegint

    @Skionz
    Code:java
    1.  
    2. package percycraft.fluctis.com;
    3.  
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.OfflinePlayer;
    7. import org.bukkit.command.ConsoleCommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.EventPriority;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.block.SignChangeEvent;
    13.  
    14. public class PlayerListener
    15. implements Listener
    16. {
    17. public PlayerListener(Main plugin)
    18.  
    19. {
    20. }
    21. ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
    22.  
    23. @EventHandler(priority=EventPriority.NORMAL, ignoreCancelled=true)
    24. public void onSignchange(SignChangeEvent event){
    25. int lineCount = 1;
    26. String linetwo = event.getLine(1);
    27. Player placer = event.getPlayer();
    28. console.sendMessage(placer.getName()+" has created a sign");
    29. for(OfflinePlayer offlineplayer:Bukkit.getOfflinePlayers()){
    30. Player player =offlineplayer.getPlayer();;
    31. if(event.getLine(0).equalsIgnoreCase("[RankSign]"))
    32. if(placer.hasPermission("ranksign.create")){
    33. if(Main.permission.playerInGroup(player, linetwo)){
    34. if (lineCount > 3)
    35. break; // Break out of the loop so you don't get an exception if you try setting line 5 (line 4, in terms of arrays), since that line won't exist on the sign.
    36.  
    37. event.setLine(lineCount, player.getName());
    38. String prefix = Main.chat.getPlayerPrefix(player);
    39. lineCount++;
    40. event.setLine(0,ChatColor.translateAlternateColorCodes('&',prefix));
    41. placer.sendMessage(ChatColor.GREEN+ "RankSign Created successfully for group"+event.getLine(0));
    42. }
    43. else{
    44. placer.sendMessage(ChatColor.RED+"No player in Group: "+ChatColor.BLACK+"["+ChatColor.RESET+event.getLine(1)+ChatColor.RED+ChatColor.BLACK+ "]"+ChatColor.RED+ " could be found!!");
    45. console.sendMessage("Sign has failed");
    46. }
    47. }
    48. else{
    49. placer.sendMessage(ChatColor.RED+"You Do NOT have the right permissions!!!");
    50. console.sendMessage("Sign has failed");
    51. }
    52. }
    53. }
    54. }
    55.  

    this is the only class that has the error

    But here is the main
    Code:java
    1.  
    2. package percycraft.fluctis.com;
    3.  
    4. import net.milkbowl.vault.chat.Chat;
    5. import net.milkbowl.vault.permission.Permission;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.ChatColor;
    9. import org.bukkit.command.ConsoleCommandSender;
    10. import org.bukkit.plugin.RegisteredServiceProvider;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class Main extends JavaPlugin
    14. {
    15. public static Permission permission = null;
    16. public static Chat chat = null;
    17. ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
    18. public void onEnable()
    19. {
    20. setupPermissions();
    21. setupChat();
    22. Bukkit.getPluginManager().registerEvents(new PlayerListener(this), this);
    23. console.sendMessage(ChatColor.AQUA+"["+getName()+"]" + " version" + getDescription().getVersion() + " by paocthegint"+ChatColor.GREEN+ " enabled!");
    24. }
    25.  
    26. public void onDisable()
    27. {
    28.  
    29. console.sendMessage(ChatColor.GREEN+"["+getName()+"]" +ChatColor.RED + " Disabled.");
    30. }
    31. private boolean setupPermissions()
    32. {
    33. RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager().getRegistration(Permission.class);
    34. if (permissionProvider != null) {
    35. permission = (Permission)permissionProvider.getProvider();
    36. }
    37. return permission != null;
    38. }
    39.  
    40. private boolean setupChat()
    41. {
    42. RegisteredServiceProvider<Chat> rsp = getServer().getServicesManager().getRegistration(Chat.class);
    43. chat = (Chat)rsp.getProvider();
    44. return chat != null;
    45. }
    46. }
    47.  
     
    Last edited: Dec 10, 2014
  9. at net.milkbowl.vault.permission.Permission.playerInGroup(Permission.java:560) ~[?:?]

    means that the NPE is thrown from Vault code, so i suggest digging up the arguments.

    if(Main.permission.playerInGroup(player, linetwo)

    suggests that player or linetwo would be null - in a SignChangeEvent the player should not be null (some events can return null on some retrievel methods, but not for players causing the event). I used to check lines for null which i get from events/signs always - strong suggestion: check lines for null before using them. If you use getLines, check that for null too.

    Another thing is to log a warning in onEnable, if permissions (or chat) can't be set up, but that doesn't seem to be the problem here.

    Edit: And check if your version of Vault is not buggy, if you don't have null lines.
     
  10. Offline

    Pacothegint

    @asofold
    Its not vault as i used the jar from my official server on my personal one and it works fine

    @Skionz
    any ideas?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
  11. Offline

    Skionz

    @Pacothegint Your spacing could be incorrect above the package, so it is either line 1 that is null, or 2.
     
  12. Offline

    Pacothegint

    @Skionz
    nope works just fine on my personal server with all plugins from my production one
     
  13. Check the arguments you are passing to Vault for null, specifically if you get lines from signs.
     
Thread Status:
Not open for further replies.

Share This Page