Guest User

ArmorCreator

a guest
Jul 29th, 2021
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 20.27 KB | None | 0 0
  1. class Attribute:
  2.     attribute: str
  3.     attribute_name: str
  4.     amount: int
  5.     operation: str
  6.  
  7.     def __init__(self, attribute, attribute_name, amount, operation):
  8.         self.attribute = attribute
  9.         self.attribute_name = attribute_name
  10.         self.amount = amount
  11.         self.operation = operation
  12.  
  13.     def toString(self, meta_obj_name, equipmentSlot):
  14.         return f"            {meta_obj_name}.addAttributeModifier(Attribute.{self.attribute}, new org.bukkit.attribute.AttributeModifier(UUID.randomUUID(), \"{self.attribute_name}\", {str(self.amount)}, Operation.{self.operation}, EquipmentSlot.{equipmentSlot}));"
  15.  
  16.  
  17. class Enchant:
  18.     level: int
  19.     name: str
  20.  
  21.     def __init__(self, name, level):
  22.         self.name = name
  23.         self.level = level
  24.  
  25.     def getName(self):
  26.         return self.name
  27.  
  28.     def getLevel(self):
  29.         return self.level
  30.  
  31.     def toString(self, meta_obj_name):
  32.         return f"            {meta_obj_name}.addEnchant(Enchantment.{self.name}, {str(self.level)}, true);"
  33.  
  34.  
  35. def save_ability(content):
  36.     file = open(ability_path, 'w+')
  37.     file.write(content)
  38.     file.close()
  39.     print('Ability successfully created')
  40.  
  41.  
  42. def fix(armor_name):
  43.     newarmorname = armor_name.lower().title().replace(" ", "")
  44.     return newarmorname[:1].lower() + newarmorname[1:]
  45.  
  46.  
  47. def exitP():
  48.     input('Done! Press enter to exit.\n')
  49.     exit(0)
  50.  
  51.  
  52. def effect(armor_id, armor_name):
  53.     print('Running: Effects')
  54.     print('''---- POTION EFFECTS ----
  55.  
  56.    SPEED, SLOW, FAST_DIGGING, SLOW_DIGGING, INCREASE_DAMAGE, HEAL,
  57.    HARM, JUMP, CONFUSION, REGENERATION, DAMAGE_RESISTANCE, FIRE_RESISTANCE,
  58.    WATER_BREATHING, INVISIBILITY, BLINDNESS, NIGHT_VISION, HUNGER,
  59.    WEAKNESS, POISON, WITHER, HEALTH_BOOST, ABSORPTION, SATURATION,
  60.    GLOWING, LEVITATION, LUCK, UNLUCK, SLOW_FALLING, CONDUIT_POWER,
  61.    DOLPHINS_GRACE, BAD_OMEN, HERO_OF_THE_VILLAGE
  62.  
  63.    ---- POTION EFFECTS ----
  64.    ''')
  65.     potion_effect = input('Potion Effect: ').upper()
  66.     amplifier = int(input('Potion Amplifier (starts with 0, 0 = Level 1): '))
  67.     ability = '''        @ArmorEquip
  68.        @EventHandler
  69.        public void <ana>Armor(ArmorEquipEvent e) {
  70.            try {
  71.                for(String dis : plugin.disabledArmors)
  72.                    if(dis.equalsIgnoreCase("{armor_id}"))
  73.                        return;
  74.            }catch(Exception ignored) {}
  75.            try {
  76.                Player p = e.getPlayer();
  77.                if(ifWearing(getNew(p, e.getNewArmorPiece()), "{armor_id}")) {
  78.                    armorInfo.remove(p.getUniqueId());
  79.                    armorInfo.put(p.getUniqueId(), "{armor_id}");
  80.                    p.addPotionEffect(new PotionEffect(PotionEffectType.{effect}, Integer.MAX_VALUE, {amplifier}));
  81.                }else if(get(p).equalsIgnoreCase("{armor_id}")) {
  82.                    armorInfo.remove(p.getUniqueId());
  83.                    p.removePotionEffect(PotionEffectType.{effect});
  84.                }
  85.            }catch(Exception ignored) {}
  86.        }
  87.    '''.replace('<ana>', fix(armor_name)).replace('{effect}', potion_effect).replace('{armor_id}', armor_id).replace(
  88.         '{amplifier}', str(amplifier))
  89.     save_ability(ability)
  90.     exitP()
  91.  
  92.  
  93. def everyXTicks(armor_id, armor_name):
  94.     print('Running: Every X ticks')
  95.     ability = '''        public void {fix(armor_name)}Armor(Player p) {
  96.            try {
  97.                for(String dis : disabledArmors)
  98.                    if(dis.equalsIgnoreCase("{armor_id}")) return;
  99.            }catch(Exception ignored) {}
  100.            try {
  101.                if(!ifWearing(p, "{armor_id}")) return;
  102.                // TODO
  103.            }catch(Exception ignored) {}
  104.        }'''.replace("{armor_id}", armor_id).replace("{fix(armor_name)}", fix(armor_name))
  105.     save_ability(ability)
  106.     exitP()
  107.  
  108.  
  109. def armorChange(armor_id, armor_name, item_code):
  110.     print('Running: ArmorChange (enchants/attributes)')
  111.     enchants = []
  112.     attributes = []
  113.     if input("Put enchants (Y/N)? ").lower() == 'y':
  114.         print('''--- ENCHANTS ---
  115.         PROTECTION_ENVIRONMENTAL, PROTECTION_FIRE, PROTECTION_FALL, PROTECTION_EXPLOSIONS,
  116.         PROTECTION_PROJECTILE, OXYGEN, WATER_WORKER, THORNS, DEPTH_STRIDER, BINDING_CURSE,
  117.         DAMAGE_ALL, DAMAGE_UNDEAD, DAMAGE_ARTHROPODS, KNOCKBACK, FIRE_ASPECT, LOOT_BONUS_MOBS,
  118.         SWEEPING_EDGE, DIG_SPEED, SILK_TOUCH, DURABILITY, LOOT_BONUS_BLOCKS, ARROW_DAMAGE,
  119.         ARROW_FIRE, ARROW_INFINITE, LUCK, LURE, LOYALTY, IMPALING, RIPTIDE, CHANNELING,
  120.         MULTISHOT, QUICK_CHARGE, PIERCING, MENDING, VANISHING_CURSE, SOUL_SPEED
  121.         --- ENCHANTS ---''')
  122.         while True:
  123.             name = input('Enchant name: ').upper()
  124.             level = int(input('Enchant level: '))
  125.             enchants.append(Enchant(name, level))
  126.             s = input('Input \'s\' to stop. ').lower()
  127.             if s == 's':
  128.                 break
  129.     if input('Put attributes (Y/N)? ').lower() == 'y':
  130.         print('''--- ATTRIBUTES ---        
  131.         On 1.15 and below, _ are not in attributes. the letter after the supposed _ is capitalized follow_range -> followRange
  132.         GENERIC_MAX_HEALTH("generic.max_health")
  133.         GENERIC_FOLLOW_RANGE("generic.follow_range")
  134.         GENERIC_KNOCKBACK_RESISTANCE("generic.knockback_resistance")
  135.         GENERIC_MOVEMENT_SPEED("generic.movement_speed")
  136.         GENERIC_FLYING_SPEED("generic.flying_speed")
  137.         GENERIC_ATTACK_DAMAGE("generic.attack_damage")
  138.         GENERIC_ATTACK_KNOCKBACK("generic.attack_knockback")
  139.         GENERIC_ATTACK_SPEED("generic.attack_speed")
  140.         GENERIC_ARMOR("generic.armor")
  141.         GENERIC_ARMOR_TOUGHNESS("generic.armor_toughness")
  142.         GENERIC_LUCK("generic.luck")
  143.         HORSE_JUMP_STRENGTH("horse.jump_strength")
  144.         ZOMBIE_SPAWN_REINFORCEMENTS("zombie.spawn_reinforcements")
  145.         --- ATTRIBUTES ---''')
  146.         while True:
  147.             attribute = input('Attribute (GENERIC_ARMOR): ').upper()
  148.             attribute_name = input('Attribute string name (generic.armor): ')
  149.             operation = input('Operation (ADD_NUMBER): ').upper()
  150.             amount = int(input('Amount: '))
  151.             # attribute, attributename, operation, amount
  152.             attributes.append(Attribute(attribute, attribute_name, amount, operation))
  153.             s = input('Input \'s\' to stop. ').lower()
  154.             if s == 's':
  155.                 break
  156.     enchants_str = ""
  157.     attribute_str = ""
  158.     first = None
  159.     for en in enchants:
  160.         if first is None:
  161.             first = "Enchantment." + en.name.upper()
  162.         enchants_str = enchants_str + en.toString("m1") + "\n"
  163.         enchants_str = enchants_str + en.toString("m2") + "\n"
  164.         enchants_str = enchants_str + en.toString("m3") + "\n"
  165.         enchants_str = enchants_str + en.toString("m4") + "\n"
  166.     for attr in attributes:
  167.         if first is None:
  168.             first = "Attribute." + attr.attribute.upper()
  169.         attribute_str = attribute_str + attr.toString("m1", "HEAD") + "\n"
  170.         attribute_str = attribute_str + attr.toString("m2", "CHEST") + "\n"
  171.         attribute_str = attribute_str + attr.toString("m3", "LEGS") + "\n"
  172.         attribute_str = attribute_str + attr.toString("m4", "FEET") + "\n"
  173.     new_item_code = item_code.replace("{MetaAdd}", f'''
  174. {enchants_str}{attribute_str}''')
  175.     item_code = item_code.replace("{MetaAdd}", "")
  176.     ability = '''   public void {fix(armor_name)}Armor(Player p) {
  177.        try {
  178.            for(String dis : plugin.disabledArmors)
  179.                if(dis.equalsIgnoreCase("{armor_id}")) return;
  180.            if(ifWearing(p, "{armor_id}")) {
  181.                {new_item_code}
  182.                changeArmorInArmorSlot(p, array[0], array[1], array[2], array[3]);
  183.            }else {
  184.                {item_code}
  185.                replaceArmorInInventory(p, "{armor_id}", array, true, {first});
  186.            }
  187.        }catch(Exception ignored) {}
  188.    }'''.replace("{armor_id}", armor_id).replace("{fix(armor_name)}", fix(armor_name)).replace("{new_item_code}",
  189.                                                                                                new_item_code).replace(
  190.         "{item_code}", item_code).replace("{first}", first)
  191.     save_ability(ability)
  192.     exitP()
  193.  
  194.  
  195. def sneakEvent(armor_id, armor_name):
  196.     print('Running: SneakEvent (PlayerToggleSneakEvent)')
  197.     ability = '''        @EventHandler
  198.        public void {fix(armor_name)}Armor(PlayerToggleSneakEvent e) {
  199.            try {
  200.                for(String dis : disabledArmors)
  201.                    if(dis.equalsIgnoreCase("{armor_id}")) return;
  202.            }catch(Exception ignored) {}
  203.            try {
  204.                if(e.isSneaking() && ifWearing(p, "{armor_id}")) {
  205.                    // TODO
  206.                }
  207.            }catch(Exception ignored) {}
  208.        }'''.replace("{fix(armor_name)}", fix(armor_name)).replace("{armor_id}", armor_id)
  209.     save_ability(ability)
  210.     exitP()
  211.  
  212.  
  213. def customEvent(armor_id, armor_name):
  214.     print('Running: CustomEvent (BlockBreakEvent)')
  215.     event = input('Event Class Name: ')
  216.     code = input('Code to check if player is wearing (enter BLANK if not possible): ')
  217.     ability = '''        @EventHandler
  218.        public void {fix(armor_name)}Armor({event} e) {
  219.            try {
  220.                for(String dis : plugin.disabledArmors)
  221.                    if(dis.equalsIgnoreCase("{armor_id}")) return;
  222.            }catch(Exception ignored) {}
  223.            try {
  224.                <code_check>
  225.                // TODO
  226.            }catch(Exception ignored) {}
  227.        }'''.replace("{armor_id}", armor_id).replace("{fix(armor_name)}", fix(armor_name)).replace("<code_check>",
  228.                                                                                                    code).replace(
  229.         "{event}", event)
  230.     save_ability(ability)
  231.     exitP()
  232.  
  233.  
  234. def main():
  235.     armor_id = input('Armor ID: ').upper()
  236.     armor_name = input('Armor Name (without Helmet...): ')
  237.     armor_lore1 = input('Armor Lore #1 (''no'' to cancel) (ChatColor with ''&''): ')
  238.     armor_lore2 = input('Armor Lore #2 (''no'' to cancel) (ChatColor with ''&''): ')
  239.     slot = int(input('Slot (needed for recipe): '))
  240.     recipe_mat = input('Recipe material (stone): ').upper()
  241.     armor_mat = input('Armor material (netherite): ').upper()
  242.     armor_lore = ""
  243.     if not armor_lore1.lower() == 'no':
  244.         armor_lore = armor_lore1
  245.     if not armor_lore2.lower() == 'no':
  246.         if not armor_lore1.lower() == 'no':
  247.             armor_lore = armor_lore + '\\n'
  248.         armor_lore = armor_lore + armor_lore2
  249.  
  250.     lang = open(language_path, 'w+')
  251.     lang.write(f'''names: {armor_id}: "{armor_name}"
  252. lores: {armor_id}: "{armor_lore}"''')
  253.     lang.close()
  254.     print('Versions:')
  255.     print('1 > Effects (strength,etc)')
  256.     print('2 > Every X Ticks (give food level every tick)')
  257.     print('3 > ArmorChange (change when full armor, enchants/attributes')
  258.     print('4 > Sneaking event')
  259.     print('5 > Custom event')
  260.     i = input('Select: ')
  261.     io = int(i)
  262.     print('Making recipe')
  263.     #
  264.     recipe = '''public void {fix(armor_name)}Armor() {
  265.            ItemStack[] array = getArmor(null, {slot});
  266.              
  267.            ShapedRecipe r1 = new ShapedRecipe(new NamespacedKey(plugin, "{fix(armor_name)}_helmet"), array[0]);
  268.            ShapedRecipe r2 = new ShapedRecipe(new NamespacedKey(plugin, "{fix(armor_name)}_chestplate"), array[1]);
  269.            ShapedRecipe r3 = new ShapedRecipe(new NamespacedKey(plugin, "{fix(armor_name)}_leggings"), array[2]);
  270.            ShapedRecipe r4 = new ShapedRecipe(new NamespacedKey(plugin, "{fix(armor_name)}_boots"), array[3]);
  271.            r1.shape("***", "* *");
  272.            r2.shape("* *", "***", "***");
  273.            r3.shape("***", "* *", "* *");
  274.            r4.shape("* *", "* *");
  275.            
  276.            r1.setIngredient('*', Material.<recipe_mat>);
  277.            r2.setIngredient('*', Material.<recipe_mat>);
  278.            r3.setIngredient('*', Material.<recipe_mat>);
  279.            r4.setIngredient('*', Material.<recipe_mat>);
  280.            
  281.            server.addRecipe(r1);
  282.            server.addRecipe(r2);
  283.            server.addRecipe(r3);
  284.            server.addRecipe(r4);
  285.            
  286.            if(!activeRecipes.contains(r1)) activeRecipes.add(r1);
  287.            if(!activeRecipes.contains(r2)) activeRecipes.add(r2);
  288.            if(!activeRecipes.contains(r3)) activeRecipes.add(r3);
  289.            if(!activeRecipes.contains(r4)) activeRecipes.add(r4);
  290. }'''.replace("{fix(armor_name)}", fix(armor_name)).replace("<recipe_mat>", recipe_mat).replace("{slot}", str(slot))
  291.  
  292.     rf = open(recipe_path, 'w+')
  293.     rf.write(recipe)
  294.     rf.close()
  295.     print('Recipe successfully loaded')
  296.     print('Making item')
  297.     # inventoryevents item
  298.     ue = input('Use ''if'' (0) or ''else if'' (1)? ')
  299.     ues = "else if"
  300.     if ue == '0':
  301.         ues = "if"
  302.  
  303.     item = '''{ues}(slot == {slot}) {
  304.                        ItemStack armor1 = new ItemStack(Material.{armor_mat}_HELMET);
  305.                        ItemStack armor2 = new ItemStack(Material.{armor_mat}_CHESTPLATE);
  306.                        ItemStack armor3 = new ItemStack(Material.{armor_mat}_LEGGINGS);
  307.                        ItemStack armor4 = new ItemStack(Material.{armor_mat}_BOOTS);
  308.                        
  309.                        {PutMetaHere}
  310.                        
  311.                        String id = Method.getArmorIds().get(slot);
  312.                        String separator = plugin.lang.getSeparator();
  313.                        
  314.                        m1.setDisplayName(plugin.lang.getName(id) + separator + plugin.lang.getHelmet());
  315.                        m2.setDisplayName(plugin.lang.getName(id) + separator + plugin.lang.getChestplate());
  316.                        m3.setDisplayName(plugin.lang.getName(id) + separator + plugin.lang.getLeggings());
  317.                        m4.setDisplayName(plugin.lang.getName(id) + separator + plugin.lang.getBoots());
  318.  
  319.                        List<String> lore = new ArrayList<>();
  320.                        lore.add(plugin.lang.getLore(id));
  321.                        lore.add(plugin.lang.getAllPieces());
  322.                        m1.setLore(lore);
  323.                        m2.setLore(lore);
  324.                        m3.setLore(lore);
  325.                        m4.setLore(lore);
  326.                        
  327.                        NamespacedKey key = new NamespacedKey(plugin, plugin.tag);
  328.                        {v3}
  329.                        m1.getPersistentDataContainer().set(tag, PersistentDataType.STRING, "{armor_id}");
  330.                        m2.getPersistentDataContainer().set(tag, PersistentDataType.STRING, "{armor_id}");
  331.                        m3.getPersistentDataContainer().set(tag, PersistentDataType.STRING, "{armor_id}");
  332.                        m4.getPersistentDataContainer().set(tag, PersistentDataType.STRING, "{armor_id}");
  333.                        {ChangeArmorAttribute}
  334.                        if(plugin.getConfig().getBoolean("glowing-armor")) m1.addEnchant(Method.GLOWING, 0, true);
  335.                        if(plugin.getConfig().getBoolean("glowing-armor")) m2.addEnchant(Method.GLOWING, 0, true);
  336.                        if(plugin.getConfig().getBoolean("glowing-armor")) m3.addEnchant(Method.GLOWING, 0, true);
  337.                        if(plugin.getConfig().getBoolean("glowing-armor")) m4.addEnchant(Method.GLOWING, 0, true);
  338.                        armor1.setItemMeta(m1);
  339.                        armor2.setItemMeta(m2);
  340.                        armor3.setItemMeta(m3);
  341.                        armor4.setItemMeta(m4);
  342.                    
  343.                        if(p != null) p.getInventory().addItem(armor1);
  344.                        if(p != null) p.getInventory().addItem(armor2);
  345.                        if(p != null) p.getInventory().addItem(armor3);
  346.                        if(p != null) p.getInventory().addItem(armor4);
  347.                    
  348. return new ItemStack[] {armor1,armor2,armor3,armor4};
  349. }
  350. '''.replace("{armor_id}", armor_id).replace("{armor_mat}", armor_mat).replace("{slot}", str(slot)).replace("{ues}", ues)
  351.     item_code = '''ItemStack[] array = plugin.invevents.getArmor(null, {slot});{MetaAdd}'''.replace("{slot}", str(slot))
  352.     if io == 3:
  353.         item = item.replace("{v3}",
  354.                             f'''m1.getPersistentDataContainer().set(new NamespacedKey(plugin, "{fix(armor_name)}Helm"), PersistentDataType.BYTE, (byte) 1);
  355.                        m2.getPersistentDataContainer().set(new NamespacedKey(plugin, "{fix(armor_name)}Chest"), PersistentDataType.BYTE, (byte) 1");
  356.                        m3.getPersistentDataContainer().set(new NamespacedKey(plugin, "{fix(armor_name)}Legs"), PersistentDataType.BYTE, (byte) 1);
  357.                        m4.getPersistentDataContainer().set(new NamespacedKey(plugin, "{fix(armor_name)}Feet"), PersistentDataType.BYTE, (byte) 1);''')
  358.     else:
  359.         item = item.replace("{v3}", "")
  360.  
  361.     if armor_mat == 'LEATHER':
  362.         colored = input('Leather Color Armor (Y/N)? ').lower()
  363.         if colored == 'y':
  364.             r = input('(Leather-Color) Red (1-255): ')
  365.             g = input('(Leather-Color) Green (1-255): ')
  366.             b = input('(Leather-Color) Blue (1-255): ')
  367.             item = item.replace("{PutMetaHere}", f'''LeatherArmorMeta m1 = (LeatherArmorMeta) armor1.getItemMeta();
  368.                        LeatherArmorMeta m2 = (LeatherArmorMeta) armor2.getItemMeta();
  369.                        LeatherArmorMeta m3 = (LeatherArmorMeta) armor3.getItemMeta();
  370.                        LeatherArmorMeta m4 = (LeatherArmorMeta) armor4.getItemMeta();
  371.        
  372.                        m1.setColor(Color.fromRGB({r},{g},{b}));
  373.                        m2.setColor(Color.fromRGB({r},{g},{b}));
  374.                        m3.setColor(Color.fromRGB({r},{g},{b}));
  375.                        m4.setColor(Color.fromRGB({r},{g},{b}));''')
  376.         else:
  377.             item = item.replace("{PutMetaHere}", '''ItemMeta m1 = armor1.getItemMeta();
  378.                ItemMeta m2 = armor2.getItemMeta();
  379.                ItemMeta m3 = armor3.getItemMeta();
  380.                ItemMeta m4 = armor4.getItemMeta();''')
  381.     # Change armor attribute
  382.     change = input('Change armor attribute (Y/N) ?').lower()
  383.     if change == 'y':
  384.         a1 = input('Helmet armor attribute: ')
  385.         a2 = input('Chestplate armor attribute: ')
  386.         a3 = input('Leggings armor attribute: ')
  387.         a4 = input('Boots armor attribute: ')
  388.         item = item.replace("{ChangeArmorAttribute}", f'''
  389.                        m1.removeAttributeModifier(Attribute.GENERIC_ARMOR);
  390.                        m2.removeAttributeModifier(Attribute.GENERIC_ARMOR);
  391.                        m3.removeAttributeModifier(Attribute.GENERIC_ARMOR);
  392.                        m4.removeAttributeModifier(Attribute.GENERIC_ARMOR);
  393.            
  394.                        m1.addAttributeModifier(Attribute.GENERIC_ARMOR, new org.bukkit.attribute.AttributeModifier(UUID.randomUUID(), "generic.armor", {a1}, Operation.ADD_NUMBER, EquipmentSlot.HEAD));
  395.                        m2.addAttributeModifier(Attribute.GENERIC_ARMOR, new org.bukkit.attribute.AttributeModifier(UUID.randomUUID(), "generic.armor", {a2}, Operation.ADD_NUMBER, EquipmentSlot.CHEST));
  396.                        m3.addAttributeModifier(Attribute.GENERIC_ARMOR, new org.bukkit.attribute.AttributeModifier(UUID.randomUUID(), "generic.armor", {a3}, Operation.ADD_NUMBER, EquipmentSlot.LEGS));
  397.                        m4.addAttributeModifier(Attribute.GENERIC_ARMOR, new org.bukkit.attribute.AttributeModifier(UUID.randomUUID(), "generic.armor", {a4}, Operation.ADD_NUMBER, EquipmentSlot.FEET));
  398.                ''')
  399.     else:
  400.         item = item.replace("{ChangeArmorAttribute}", "")
  401.         item_code = item_code.replace("{ChangeArmorAttribute}", "")
  402.     item_file = open(item_path, "w+")
  403.     item_file.write(item)
  404.     item_file.close()
  405.     #
  406.     try:
  407.         if io == 1:
  408.             effect(armor_id, armor_name)
  409.         elif io == 2:
  410.             everyXTicks(armor_id, armor_name)
  411.         elif io == 3:
  412.             armorChange(armor_id, armor_name, item_code)
  413.         elif io == 4:
  414.             sneakEvent(armor_id, armor_name)
  415.         elif io == 5:
  416.             customEvent(armor_id, armor_name)
  417.         else:
  418.             exit(-1)
  419.     except ValueError:
  420.         exit(-1)
  421.  
  422.  
  423. # File paths
  424. recipe_path = "recipe.txt"
  425. item_path = "item.txt"
  426. ability_path = "ability.txt"
  427. language_path = "language.txt"
  428.  
  429. main()
  430.  
Advertisement
Add Comment
Please, Sign In to add comment