object variable getting set to the same values

Discussion in 'Plugin Development' started by zoominx55, May 24, 2014.

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

    zoominx55

    I've been trying to figure this out and I'm guessing there is an easy solution, although I hope not.

    My code has three classes MCPlugin, MCGames, MCGame. MCPlugin creates a MCGames objects. MCGames creates an ArrayList of MCGame objects. I create two game objects. Then for each game object I set a variable (worldedit CuboidSelection). The problem is when I set the second cuboid object the first cuboid object gets the same values and I can't figure out why.

    Everything is fine until I set the second object, then they both get set to the same values. if I do it three times for three different MCGame objects they all end up with the same values. It's like the CuboidSelection variable is being declared as static, but it's not explicitly declared that way. Can anyone give me a clue as to why this isn't working?

    Here's my code:

    Code:java
    1. public final class MCPlugin extends JavaPlugin {
    2. private MCGames _games = null;
    3.  
    4. public MCPlugin()
    5. {
    6. _games = new MCGames();
    7. }
    8. public Boolean AddNewGame(String gameName)
    9. {
    10. if (this._games.AddGame(gameName))
    11. {
    12. return true;
    13. }
    14. return false;
    15. }
    16. public MCGame GetGame(String gameName)
    17. {
    18. return this._games.GetGame(gameName);
    19. }
    20. }
    21.  
    22. @SerializableAs("MCGames")
    23. public class MCGames implements ConfigurationSerializable{
    24. private ArrayList<MCGame> _games = null;
    25.  
    26. public MCGames()
    27. {
    28. this._games = new ArrayList<MCGame>();
    29.  
    30. }
    31. public Boolean AddGame(String gameName)
    32. {
    33. if (this._games.size() == 0)
    34. {
    35. this._games.add(new MCGame(gameName));
    36. return true;
    37. }
    38.  
    39. if (this.GameExists(gameName)) { return false; }
    40.  
    41. this._games.add(new MCGame(gameName));
    42. return true;
    43.  
    44. }
    45. public MCGame GetGame(String gameName)
    46. {
    47. if (this._games.size() == 0) { return null; }
    48.  
    49. if (this.GameExists(gameName))
    50. {
    51. for (MCGame mcg : this._games)
    52. {
    53. if (mcg.Name().toLowerCase().equalsIgnoreCase(gameName))
    54. {
    55. return mcg;
    56. }
    57. }
    58. }
    59. return null;
    60. }
    61. public Boolean GameExists(String gameName)
    62. {
    63. if (this._games.size() == 0) {return false;}
    64.  
    65. for (MCGame mcg : this._games)
    66. {
    67. if (mcg.Name().equalsIgnoreCase(gameName))
    68. {
    69. return true;
    70. }
    71. }
    72.  
    73. return false;
    74. }
    75.  
    76. }
    77.  
    78. @SerializableAs("MCGame")
    79. public class MCGame implements ConfigurationSerializable{
    80. private String _gameName = null;
    81. private CuboidSelection _arenaCube = null;
    82.  
    83. public MCGame(String gameName)
    84. {
    85. this.Name(gameName);
    86. }
    87. public boolean SaveArenaSelection(CuboidSelection arenaCube)
    88. {
    89. this._arenaCube = arenaCube;
    90. return true;
    91. }
    92. }
    93.  
    94. CommandProcessor
    95. MCGame mcg = _mainPlugin.GetGame(args[1]);
    96. Selection sel = wePlugin.getSelection(player);
    97. mcg.SaveArenaSelection((CuboidSelection)sel);
    98.  
    99.  
     
Thread Status:
Not open for further replies.

Share This Page