Special Skills

Discussion in 'Plugin Requests' started by JustNoHacks, Oct 23, 2016.

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

    JustNoHacks

    Plugin category: Fun/Mechanics

    Minecraft version: Spigot 1.8.8

    Suggested name: SpecialSkills

    What I would like :
    When a player gets damaged by another player and the player that got damaged has a Leather Chestplate that has a lore "&7Dodge Skill", the damaged player has a 10% chance to 'dodge' the attack which means the damaged player will take no damage and get the message "&eDodge Skill Active"

    If it's possible: you can edit the lore, the message and the percent chance to dodge.

    Ideas for commands: No commands needed

    No permissions needed,
     
  2. Offline

    Allek

    Let me know if something needs to be changed!

    I added the command /specialskills so you can give yourself the armor easily (as set by color in the config)

    Also, if this solved it for you, please mark the thread as filled, thank you.
     

    Attached Files:

  3. Offline

    I Al Istannen

    @Allek @JustNoHacks
    I made it similar. No command though and mainly to learn a bit:

    Main:
    Code:java
    1. package me.ialistannen.dogearmor
    2.  
    3. import me.ialistannen.dogearmor.listener.HitListener
    4. import org.bukkit.Bukkit
    5. import org.bukkit.plugin.java.JavaPlugin
    6.  
    7. /**
    8. * `This is code` **and I am bold**
    9. */
    10. class DogeArmor : JavaPlugin() {
    11.  
    12. companion object {
    13. lateinit var instance: DogeArmor
    14. private set
    15. }
    16.  
    17.  
    18. override fun onEnable() {
    19. instance = this
    20.  
    21. saveDefaultConfig()
    22.  
    23. Bukkit.getPluginManager().registerEvents(HitListener(), this)
    24.  
    25. logger.info("Kotlin Test Plugin has been enabled!")
    26. }
    27. }
    28.  



    Listener:
    Code:java
    1. package me.ialistannen.dogearmor.listener
    2.  
    3. import me.ialistannen.dogearmor.DogeArmor
    4. import org.bukkit.ChatColor
    5. import org.bukkit.Material
    6. import org.bukkit.entity.Player
    7. import org.bukkit.event.EventHandler
    8. import org.bukkit.event.Listener
    9. import org.bukkit.event.entity.EntityDamageByEntityEvent
    10. import java.util.concurrent.ThreadLocalRandom
    11.  
    12. class HitListener : Listener {
    13.  
    14. /**
    15.   * Colors a String
    16.   *
    17.   * **Only works on non-null strings.**
    18.   *
    19.   * Uses `ChatColor.translateAlternateColorCodes('&', String)` internally
    20.   */
    21. fun String.color(): String {
    22. return ChatColor.translateAlternateColorCodes('&', this)
    23. }
    24.  
    25. @EventHandler
    26. fun onHit(event: EntityDamageByEntityEvent) {
    27. if (event.damager !is Player || event.entity !is Player) {
    28. return
    29. }
    30.  
    31. // if he has no chestplate
    32. if ((event.entity as Player).inventory?.chestplate?.type != Material.LEATHER_CHESTPLATE) {
    33. return
    34. }
    35.  
    36. // get the name of the chestplate and the name from the config, return if null
    37. val name: String? = (event.entity as Player).inventory.chestplate?.itemMeta?.displayName?.color()
    38. val desiredName = DogeArmor.instance.config.getString("doge.chestplate.name")?.color() ?: return
    39.  
    40. // allow a blank desiredName to act as a wildcard
    41. if (!desiredName.isBlank() && name != desiredName) {
    42. return
    43. }
    44.  
    45. val dogeChance = DogeArmor.instance.config.getDouble("doge.percentage")
    46.  
    47. val random = ThreadLocalRandom.current().nextDouble(1.0)
    48.  
    49. if (random > dogeChance) {
    50. return
    51. }
    52.  
    53. event.isCancelled = true
    54.  
    55. event.entity.sendMessage(DogeArmor.instance.config.getString("doge.message").replace("{0}", event.damager.name).color())
    56. }
    57. }


    Link: Dropbox.
     
Thread Status:
Not open for further replies.

Share This Page