Horsing Around! :D

Discussion in 'Plugin Development' started by chasertw123, Jul 10, 2014.

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

    chasertw123

    For some reason when I spawn a horse using the code below it does work.

    Code:java
    1. public void spawnHorse(Player p, Location l) {
    2.  
    3. Horse h = (Horse) l.getWorld().spawnEntity(l, EntityType.HORSE);
    4.  
    5. h.setAdult();
    6. h.setColor(this.getHorseColor(p));
    7. h.setVariant(this.getHosreVariant(p));
    8. h.getInventory().setSaddle(new ItemStack(Material.SADDLE));
    9. h.setTamed(true);
    10. h.setOwner(p);
    11. h.setPassenger(p);
    12. h.setHealth(2);
    13. }


    I have never worked with horses before so I have no idea what I am doing wrongs. I get no errors. Also I have done quite a bit of goggling but no luck.

    BUMP
     
  2. Offline

    TheMrGong

    Line 7, Misspelled horse, you put, "hosre", instead of, "horse"
     
  3. Offline

    chasertw123

    TheMrGong


    That doesn't matter the method I made using that still works! XD
     
  4. Offline

    TheMrGong

    What do you mean by it doesn't work?
     
  5. Offline

    chasertw123

    TheMrGong
    Its spawns a horse but doesn't apply the rest of the code. Like sometimes its a donkey or a baby.
     
  6. Offline

    TheMrGong

    Could you show me the "getHosreVariant" method?
     
  7. Offline

    chasertw123

    @TheMrGong
    Code:java
    1. public class HorseHandler {
    2.  
    3. private Main plugin;
    4.  
    5. public HorseHandler(Main plugin) {
    6. this.plugin = plugin;
    7. }
    8.  
    9. public void spawnHorse(Player p, Location l) {
    10.  
    11. Horse h = (Horse) l.getWorld().spawnEntity(l, EntityType.HORSE);
    12.  
    13. h.setVariant(this.getHorseVariant(p));
    14. h.setColor(this.getHorseColor(p));
    15. h.setAdult();
    16. h.getInventory().setSaddle(new ItemStack(Material.SADDLE));
    17. h.setTamed(true);
    18. h.setOwner(p);
    19. h.setPassenger(p);
    20. h.setHealth(2);
    21. }
    22.  
    23. public Variant getHorseVariant(Player p) {
    24.  
    25. Yaml yaml = plugin.getFh().getPlayerYaml(p);
    26. String s = yaml.getString("Horse.Variant");
    27.  
    28. if (s.equals("regular"))
    29. return Variant.HORSE;
    30. if (s.equals("zombie"))
    31. return Variant.UNDEAD_HORSE;
    32. if (s.equals("skeleton"))
    33. return Variant.SKELETON_HORSE;
    34.  
    35. return null;
    36. }
    37.  
    38. public void setHorseVariant(Player p, String variant) {
    39.  
    40. Yaml yaml = plugin.getFh().getPlayerYaml(p);
    41.  
    42. if (variant.equals( "regular"))
    43. yaml.set("Hosre.Variant", "regular");
    44. if (variant.equals("zombie"))
    45. yaml.set("Horse.Variant", "zombie");
    46. if (variant.equals("skeleton"))
    47. yaml.set("Hosre.Variant", "skeleton");
    48. }
    49.  
    50. public Color getHorseColor(Player p) {
    51.  
    52. Yaml yaml = plugin.getFh().getPlayerYaml(p);
    53. String s = yaml.getString("Horse.Color");
    54.  
    55. if (s.equals("black"))
    56. return Color.BLACK;
    57. if (s.equals("brown"))
    58. return Color.BROWN;
    59. if (s.equals("chestnut"))
    60. return Color.CHESTNUT;
    61. if (s.equals("creamy"))
    62. return Color.CREAMY;
    63. if (s.equals("darkbrown"))
    64. return Color.DARK_BROWN;
    65. if (s.equals("gray"))
    66. return Color.GRAY;
    67. if (s.equals("white"))
    68. return Color.WHITE;
    69.  
    70. return null;
    71. }
    72.  
    73. public void setHorseColor(Player p, String color) {
    74.  
    75. Yaml yaml = plugin.getFh().getPlayerYaml(p);
    76.  
    77. if (color.equals("black"))
    78. yaml.set("Horse.Color", "black");
    79. if (color.equals("brown"))
    80. yaml.set("Horse.Color", "brown");
    81. if (color.equals("chestnut"))
    82. yaml.set("Horse.Color", "chestnut");
    83. if (color.equals("creamy"))
    84. yaml.set("Horse.Color", "creamy");
    85. if (color.equals("darkbrown"))
    86. yaml.set("Horse.Color", "darkbrown");
    87. if (color.equals("gray"))
    88. yaml.set("Horse.Color", "gray");
    89. if (color.equals("white"))
    90. yaml.set("Horse.Color", "white");
    91. }
    92. }


    Thats all my horse stuff.

    EDIT: Bukkit messed up the formatting.

    EDIT: BUMP!
     
Thread Status:
Not open for further replies.

Share This Page