.getColor() not working

Discussion in 'Plugin Development' started by GreatBlitz, Apr 17, 2014.

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

    GreatBlitz

    So I have this code which makes an arena, and assigns the player to a team:-

    Code:java
    1. else if ((cmd.getName()).equalsIgnoreCase("arenacreate")){
    2. int x = Integer.parseInt(args[0]);
    3. int z = Integer.parseInt(args[1]);
    4. int xM = x + 5;
    5. int zM = z + 10;
    6. int y = Integer.parseInt(args[2]);
    7. Player player = (Player) sender;
    8. World world = player.getWorld();
    9. for (int a = x;a < xM;a++){
    10. for (int b = z;b < zM;b++){
    11. Location location = new Location(world, a, y, b);
    12. player.sendMessage("x = " + a + ", y = " + y + ", z = " + b);
    13. Block block = location.getBlock();
    14. block.setType(Material.DIAMOND_BLOCK);
    15. }
    16. }
    17.  
    18. for (int a = xM;a < (x + 10);a++){
    19. for (int b = z;b < zM;b++){
    20. Location location = new Location(world, a, y, b);
    21. player.sendMessage("x = " + a + ", y = " + y + ", z = " + b);
    22. Block block = location.getBlock();
    23. block.setType(Material.EMERALD_BLOCK);
    24. }
    25. }
    26. Random random = new Random();
    27. int i = random.nextInt(2);
    28. if (i == 0){
    29. player.sendMessage("You are in Red team!");
    30. ItemStack a = new ItemStack(Material.LEATHER_HELMET);
    31. LeatherArmorMeta lama = (LeatherArmorMeta) a.getItemMeta();
    32. lama.setColor(Color.RED);
    33. a.setItemMeta(lama);
    34.  
    35. ItemStack b = new ItemStack(Material.LEATHER_CHESTPLATE);
    36. LeatherArmorMeta lamb = (LeatherArmorMeta) b.getItemMeta();
    37. lamb.setColor(Color.RED);
    38. b.setItemMeta(lamb);
    39.  
    40. ItemStack c = new ItemStack(Material.LEATHER_LEGGINGS);
    41. LeatherArmorMeta lamc = (LeatherArmorMeta) c.getItemMeta();
    42. lamc.setColor(Color.RED);
    43. c.setItemMeta(lamc);
    44.  
    45. ItemStack d = new ItemStack(Material.LEATHER_BOOTS);
    46. LeatherArmorMeta lamd = (LeatherArmorMeta) d.getItemMeta();
    47. lamd.setColor(Color.RED);
    48. d.setItemMeta(lamd);
    49.  
    50. ItemStack[] armorArrayRed = new ItemStack[4];
    51. armorArrayRed[0] = d;
    52. armorArrayRed[1] = c;
    53. armorArrayRed[2] = b;
    54. armorArrayRed[3] = a;
    55.  
    56. player.getInventory().setArmorContents(armorArrayRed);
    57. }
    58.  
    59. else if (i == 1){
    60. player.sendMessage("You are in Blue team!");
    61. ItemStack a = new ItemStack(Material.LEATHER_HELMET);
    62. LeatherArmorMeta lama = (LeatherArmorMeta) a.getItemMeta();
    63. lama.setColor(Color.BLUE);
    64. a.setItemMeta(lama);
    65.  
    66. ItemStack b = new ItemStack(Material.LEATHER_CHESTPLATE);
    67. LeatherArmorMeta lamb = (LeatherArmorMeta) b.getItemMeta();
    68. lamb.setColor(Color.BLUE);
    69. b.setItemMeta(lamb);
    70.  
    71. ItemStack c = new ItemStack(Material.LEATHER_LEGGINGS);
    72. LeatherArmorMeta lamc = (LeatherArmorMeta) c.getItemMeta();
    73. lamc.setColor(Color.BLUE);
    74. c.setItemMeta(lamc);
    75.  
    76. ItemStack d = new ItemStack(Material.LEATHER_BOOTS);
    77. LeatherArmorMeta lamd = (LeatherArmorMeta) d.getItemMeta();
    78. lamd.setColor(Color.BLUE);
    79. d.setItemMeta(lamd);
    80.  
    81. ItemStack[] armorArrayRed = new ItemStack[4];
    82. armorArrayRed[0] = d;
    83. armorArrayRed[1] = c;
    84. armorArrayRed[2] = b;
    85. armorArrayRed[3] = a;
    86.  
    87. player.getInventory().setArmorContents(armorArrayRed);
    88. }
    89. }


    This works fine, makes a half diamond/half emerald arena and gives me a blue/red armor set.

    Emerald is for blue team, and diamond is for red.

    So red team can't place tnt in emerald zone (blue team) and blue team can't place tnt in diamond zone (red team). So I coded a BlockPlaceEvent:-

    Code:java
    1. @EventHandler
    2. public void checkForTntAndEliminate(BlockPlaceEvent event){
    3. Block block = event.getBlockPlaced();
    4.  
    5.  
    6. if (block.getType() == Material.TNT){
    7. Block placeAgainst = event.getBlockAgainst();
    8. Material materialPlaceAgainst = placeAgainst.getType();
    9. Player player = event.getPlayer();
    10. ItemStack[] a = player.getInventory().getArmorContents();
    11. ItemStack helmet = a[3];
    12. LeatherArmorMeta lamh = (LeatherArmorMeta) helmet.getItemMeta();
    13. Color color = lamh.getColor();
    14.  
    15. if ((color == Color.BLUE) && (materialPlaceAgainst == Material.DIAMOND_BLOCK)){
    16. player.sendMessage("You are not allowed to place TNT on the opposing team's field.");
    17. }
    18.  
    19. else if ((color == Color.RED) && (materialPlaceAgainst == Material.EMERALD_BLOCK)){
    20. player.sendMessage("You are not allowed to place TNT on the opposing team's field.");
    21. }
    22. }
    23. }


    But this still allows me to place tnt on the opposing field!
    Out of curiosity, as a standard debugger would do, I added a sendMessage statement in this way:-
    Code:java
    1. Color color = lamh.getColor();
    2. if (color == Color.BLUE){
    3. player.sendMessage("Blue");
    4. }
    5. else if (color == Color.RED){
    6. player.sendMessage("Blue");
    7. }


    As I expected, this sendMessage never arrived.

    Can someone help me?
     
  2. Offline

    TheMcScavenger

    Try adding another line underneath it:

    Code:
    Color colour = lamh.getColor();
    if (colour == Color.BLUE){
        player.sendMessage("Blue");
    }
    else if (colour == Color.RED){
        player.sendMessage("Blue");
    }
    else{
        player.sendMessage("Other: " + colour.toString());
    }
     
Thread Status:
Not open for further replies.

Share This Page