Random Enchantments

Discussion in 'Plugin Development' started by 99storm2, Jun 8, 2014.

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

    99storm2

    I am making a plugin that will add random enchantments to the item in your hand when you right click a sign.
    I have gotten the plugin to work but at the moment i can only add 1 enchantment when you right click the sign.
    This plugin basically just makes a sign act as a enchantment table for a op server.
    Currently this is how i am enchanting the item:
    Code:java
    1. int swordench = r.nextInt(15) +1;
    2. int enchlev = r.nextInt(30) +1;
    3.  
    4. if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
    5.  
    6. if(e.getClickedBlock().getType() == Material.WALL_SIGN) {
    7.  
    8. Sign sign = (Sign) b.getState();
    9.  
    10. if(sign.getLine(0).equalsIgnoreCase("[DazeEnchant]") && sign.getLine(1).equalsIgnoreCase("Sword")){
    11.  
    12. if(player.getInventory().getItemInHand().getType().equals(Material.DIAMOND_SWORD)){
    13.  
    14. if(player.getInventory().getItemInHand().getEnchantments().size() == 0) {
    15. ItemMeta im = player.getItemInHand().getItemMeta();
    16.  
    17. if(swordench == 1){
    18.  
    19. im.addEnchant(Enchantment.DAMAGE_ALL, enchlev, true);
    20. player.getItemInHand().setItemMeta(im);
    21.  
    22. }else if(swordench == 2){
    23.  
    24. im.addEnchant(Enchantment.KNOCKBACK, enchlev, true);
    25. player.getItemInHand().setItemMeta(im);
    26.  
    27.  
    28. }else if(swordench == 3){
    29.  
    30. im.addEnchant(Enchantment.FIRE_ASPECT, enchlev, true);
    31. player.getItemInHand().setItemMeta(im);
    32.  
    33. }else if(swordench == 4){
    34.  
    35. im.addEnchant(Enchantment.DAMAGE_ARTHROPODS, enchlev, true);
    36. player.getItemInHand().setItemMeta(im);
    37.  
    38. }else if(swordench == 5){
    39.  
    40. im.addEnchant(Enchantment.DAMAGE_UNDEAD, enchlev, true);
    41. player.getItemInHand().setItemMeta(im);
    42.  
    43. }else if(swordench == 6){
    44.  
    45. im.addEnchant(Enchantment.LOOT_BONUS_MOBS, enchlev, true);
    46. player.getItemInHand().setItemMeta(im);
    47.  
    48. }else if(swordench == 7){
    49.  
    50. im.addEnchant(Enchantment.KNOCKBACK, enchlev, true);
    51. player.getItemInHand().setItemMeta(im);
    52.  
    53. }


    I need a more effective way of choosing the random enchantment but i dont know how to do this.
    I want a way of randomizing how many lines of enchantments will be put on the item too.
     
  2. Offline

    fireblast709

  3. Offline

    99storm2

    Alright thanks that link should help ill figure it out fireblast709
     
Thread Status:
Not open for further replies.

Share This Page