Solved "Custom" Methods not working.....

Discussion in 'Plugin Development' started by legostarwarszach, Sep 7, 2013.

Thread Status:
Not open for further replies.
  1. For my plugin, I have a method class for my commonly used things and for other devs on the server to use. The only problem is that whenever i try to use a method, it returns null / doesn't work.
    My method class
    Code:java
    1. package me.zach.invasion.api;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import me.zach.invasion.zvf.Info;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.ChatColor;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.Listener;
    11.  
    12. public class ZVF implements Listener{
    13. Info info;
    14.  
    15.  
    16. public void sendMsg(String mes){
    17. for(Player pz : Bukkit.getOnlinePlayers()){
    18. if(info.plingame.contains(pz)){
    19. pz.sendMessage(mes);
    20. }
    21. }
    22. }
    23. public ArrayList<Player> getPlayerIngame(){
    24. return info.plingame;
    25. }
    26.  
    27. public void addPlayerInGame(Player player){
    28. info.plingame.add(player);
    29. }
    30.  
    31. public void addPlayersInGame(){
    32. info.playersinarena1++;
    33. }
    34. public Integer getPlayerAInG(){
    35. return info.playersinarena1;
    36. }
    37. public void removePlayerInGame(Player player){
    38. info.plingame.remove(player);
    39. }
    40.  
    41. public void removePlayersInGame(){
    42. info.playersinarena1--;
    43. }
    44.  
    45. public void kickPlayer(Player p, String s){
    46. if(p.isOnline()){
    47. removePlayersInGame();
    48. removePlayerInGame(p);
    49. p.sendMessage(ChatColor.GOLD + "You have been kicked from the game because: " + s);
    50. }
    51. }
    52.  
    53.  
    54. }
    55.  
     
  2. Offline

    Compressions

    legostarwarszach Void methods aren't going to return null, as they don't return anything.
     
  3. The void methods don't return null, I meant the String ones
    Edit: Whenever I use any of the Methods I get the error: "Unknown exception"

    Compressions
     
  4. Offline

    Compressions

    legostarwarszach likes this.
  5. Compressions
    I had to initialized something else early todo too. I got this error but I fixed it by puting it in the onCommand. How would I fix it now though?

    Error:
    Code:
    Syntax error on token ";", = expected
     
  6. Offline

    Compressions

  7. Compressions
    I'm trying to add this on line 16 in this class:
    so I looks like this:
    Code:java
    1. package me.zach.invasion.api;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import me.zach.invasion.zvf.Info;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.ChatColor;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.Listener;
    11.  
    12. public class ZVF implements Listener{
    13. Info info; //Error! And line 16
    14. this.info = MainEnable.instance1;
    15.  
    16.  
    17. public void sendMsg(String mes){
    18. for(Player pz : Bukkit.getOnlinePlayers()){
    19. if(info.plingame.contains(pz)){
    20. pz.sendMessage(mes);
    21. }
    22. }
    23. }
    24. public ArrayList<Player> getPlayerIngame(){
    25. return info.plingame;
    26. }
    27.  
    28. public void addPlayerInGame(Player player){
    29. info.plingame.add(player);
    30. }
    31.  
    32. public void addPlayersInGame(){
    33. info.playersinarena1++;
    34. }
    35. public Integer getPlayerAInG(){
    36. return info.playersinarena1;
    37. }
    38. public void removePlayerInGame(Player player){
    39. info.plingame.remove(player);
    40. }
    41.  
    42. public void removePlayersInGame(){
    43. info.playersinarena1--;
    44. }
    45.  
    46. public void kickPlayer(Player p, String s){
    47. if(p.isOnline()){
    48. removePlayersInGame();
    49. removePlayerInGame(p);
    50. p.sendMessage(ChatColor.GOLD + "You have been kicked from the game because: " + s);
    51. }
    52. }
    53.  
    54.  
    55. }
     
  8. Offline

    chasechocolate

    legostarwarszach likes this.
  9. chasechocolate Compressions
    Either initializeing didn't work or this is being mean. When i do this method:
    Code:java
    1. private void broadcasttimeinsecs() {
    2. api.sendMsg(ChatColor.GOLD + "" + Info.timeinsecs + " seconds till the game starts!");
    3. }
    4.  


    It gives me this error:
    Code:
    14:02:04 [WARNING] [Invasion] Task #38 for Invasion vBeta1.0 generated an except
    ion
    java.lang.NullPointerException
            at me.zach.invasion.zvf.Lobby.broadcasttimeinsecs(L
    obby.java:87)
            at me.zach.invasion.zvf.Lobby.run(Lobby.java:18)
            at org.bukkit.craftbukkit.v1_5_R2.scheduler.CraftTask.run(CraftTask.java
    :53)
            at org.bukkit.craftbukkit.v1_5_R2.scheduler.CraftScheduler.mainThreadHea
    rtbeat(CraftScheduler.java:345)
            at net.minecraft.server.v1_5_R2.MinecraftServer.r(MinecraftServer.java:5
    12)
            at net.minecraft.server.v1_5_R2.DedicatedServer.r(DedicatedServer.java:2
    25)
            at net.minecraft.server.v1_5_R2.MinecraftServer.q(MinecraftServer.java:4
    76)
            at net.minecraft.server.v1_5_R2.MinecraftServer.run(MinecraftServer.java
    :409)
            at net.minecraft.server.v1_5_R2.ThreadServerApplication.run(SourceFile:5
    73)
    Yep just tested it and that didn't solve my problem
    chasechocolate Compressions

    Anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
Thread Status:
Not open for further replies.

Share This Page