HUGE BUG! Anyone know a fix?

Discussion in 'Plugin Development' started by TeddyDev, Oct 28, 2014.

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

    TeddyDev

    Okay so i am in the making of a plugin that updates lore's when you add an enchantment an item, in my case a Diamond_Sword.
    Sometimes my enchantments will switch places with the enchantment above it. and then switch back. But this happens very fast, Example: The inventory checker is 1 second. every half of second (10 ticks) the enchantment will switch place's with the other enchantments... Please help

    So i will post a few little screen shots and my code so its easyer to figure out what im talking about.

    Screenshot 1 : http://i.imgur.com/dYJgup9.png
    Then half a second later the sword will look like 'Screenshot 2'
    Screenshot 2 : http://i.imgur.com/CHbyePI.png
    And it keeps looping through :(

    Code:
    I wont paste the 'Strings' in the code because there too big.

    Code:java
    1. @Override
    2. public void onEnable() {
    3.  
    4. getConfig().options().copyDefaults(true);
    5. saveConfig();
    6.  
    7. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    8. @SuppressWarnings("deprecation")
    9. public void run() {
    10. for(Player all : Bukkit.getOnlinePlayers()) {
    11. for(ItemStack i : all.getInventory().getContents()) {
    12. if(i != null) {
    13. if(i.getType() == Material.DIAMOND_SWORD) {
    14. ItemMeta m = i.getItemMeta();
    15.  
    16. m.setLore(getLore(i));
    17. i.setItemMeta(m);
    18. }
    19. }
    20. }
    21. }
    22. }
    23. }, 25, 25);
    24. }
    25.  
    26. public List<String> getLore(ItemStack item) {
    27. List<String> lore = new ArrayList<String>();
    28.  
    29. lore.add(" ");
    30. lore.add(info);
    31.  
    32. if(item.getEnchantments().containsKey(Enchantment.DAMAGE_ALL)) {
    33. if(item.getEnchantmentLevel(Enchantment.DAMAGE_ALL) == 1) {
    34. lore.add(sharpness1);
    35.  
    36. } else if(item.getEnchantmentLevel(Enchantment.DAMAGE_ALL) == 2) {
    37. lore.add(sharpness2);
    38.  
    39. } else if(item.getEnchantmentLevel(Enchantment.DAMAGE_ALL) == 3) {
    40. lore.add(sharpness3);
    41.  
    42. } else if(item.getEnchantmentLevel(Enchantment.DAMAGE_ALL) == 4) {
    43. lore.add(sharpness4);
    44.  
    45. } else {
    46. lore.add(sharpness5);
    47. }
    48. }
    49. //Yeah that isnt a problem :) also take alook at this that someguy sent me
    50. if(item.getEnchantments().containsKey(Enchantment.DAMAGE_UNDEAD)) {
    51. if(item.getEnchantmentLevel(Enchantment.DAMAGE_UNDEAD) == 1) {
    52. lore.add(smite1);
    53.  
    54. } else if(item.getEnchantmentLevel(Enchantment.DAMAGE_UNDEAD) == 2) {
    55. lore.add(smite2);
    56.  
    57. } else if(item.getEnchantmentLevel(Enchantment.DAMAGE_UNDEAD) == 3) {
    58. lore.add(smite3);
    59.  
    60. } else if(item.getEnchantmentLevel(Enchantment.DAMAGE_UNDEAD) == 4) {
    61. lore.add(smite4);
    62.  
    63. } else {
    64. lore.add(smite5);
    65. }
    66. }
    67.  
    68. if(item.getEnchantments().containsKey(Enchantment.DAMAGE_ARTHROPODS)) {
    69. if(item.getEnchantmentLevel(Enchantment.DAMAGE_ARTHROPODS) == 1) {
    70. lore.add(baneofarthropods1);
    71.  
    72. } else if(item.getEnchantmentLevel(Enchantment.DAMAGE_ARTHROPODS) == 2) {
    73. lore.add(baneofarthropods2);
    74.  
    75. } else if(item.getEnchantmentLevel(Enchantment.DAMAGE_ARTHROPODS) == 3) {
    76. lore.add(baneofarthropods3);
    77.  
    78. } else if(item.getEnchantmentLevel(Enchantment.DAMAGE_ARTHROPODS) == 4) {
    79. lore.add(baneofarthropods4);
    80.  
    81. } else {
    82. lore.add(baneofarthropods5);
    83. }
    84. }
    85.  
    86. if(item.getEnchantments().containsKey(Enchantment.FIRE_ASPECT)) {
    87. if(item.getEnchantmentLevel(Enchantment.FIRE_ASPECT) == 1) {
    88. lore.add(fireaspect1);
    89.  
    90. } else {
    91. lore.add(fireaspect2);
    92. }
    93. }
    94.  
    95. if(item.getEnchantments().containsKey(Enchantment.DURABILITY)) {
    96. if(item.getEnchantmentLevel(Enchantment.DURABILITY) == 1) {
    97. lore.add(unbreaking1);
    98.  
    99. } else if(item.getEnchantmentLevel(Enchantment.DURABILITY) == 2) {
    100. lore.add(unbreaking2);
    101.  
    102. } else {
    103. lore.add(unbreaking3);
    104. }
    105. }
    106.  
    107. return lore;
    108. }
    109. }


    Hopefully someone there is a fix to the buggy enchants. Please let me know if there is anything that can be done to prevent this
     
  2. Offline

    mine-care

    hmm. why you do alllllll that code every so even if the players swords have the lore you set to it already?
    You can use the EnchantItemEvent and then get the item do your if's and then set its lore, once.
    also it would help you to use swich statements :)
    Hope i kinda helped :3
     
  3. Offline

    CraftCreeper6

    mine-care
    I don't think Switch statements are supported in Java 8.
    EDIT: Typo
     
  4. Offline

    mine-care

    CraftCreeper6 you mean, you don't think they ARE supported?
    I think they are but what I know =]
     
  5. Offline

    CraftCreeper6

    mine-care likes this.
  6. Offline

    Abs0rbed

    really? Switches are not in java 8? Haven't played around with the new jdk much... do you have anything that can definitely confirm it?
     
  7. Offline

    korikisulda

    Worry not. It was but a mere typographical misfortune ^.^
     
  8. Offline

    CraftCreeper6

  9. Offline

    fireblast709

    CraftCreeper6 you find a lot about Java 7 because that's when Strings in switches were introduced. The tutorial page doesn't mention anything about it being removed in Java 8 (which would be quite strange if they did remove it).
     
  10. Offline

    CraftCreeper6

    fireblast709
    I am sure I saw something about it, can't remember where though :(
     
  11. Offline

    Abs0rbed

    I hope not, they add so much functionality, especially with the addition of String switch statements in jdk7
     
  12. Offline

    Rocoty

    The lack of people actually downloading JDK 8 to check if they still are there worries me a bit. Anyway, I use Java 8 all the time and I can definitely confirm that switch statements are NOT removed...really why would they be?
     
  13. Offline

    CraftCreeper6

    Rocoty
    Must've misread something.
     
Thread Status:
Not open for further replies.

Share This Page