Development Assistance An Event that catches when a person gets an effect.

Discussion in 'Plugin Help/Development/Requests' started by Sheepii, Nov 17, 2014.

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

    Sheepii

    Simple says, simple does, is there an event that does this on 1.7.2?
     
  2. Offline

    timtower Moderator Moderator

    Sheepii What kind of effect? Potion effect?
     
  3. Offline

    Sheepii

    Yes. I don't really want to check OnPlayerMove, then check if they have an effect (then do code)

    Thanks btw.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  4. Offline

    timtower Moderator Moderator

    Sheepii Please don't double post.
    And there is a splash event somewhere.
    No events for when a plugin does it. And timers also work.
     
  5. Offline

    bwfcwalshy Retired Staff

    Sheepii Do not double post there is an edit button for a reason.
     
  6. Offline

    mrCookieSlime Retired Staff

    Sheepii
    Please dont double post. There is an Edit Button right next to the Date.

    Also, better use a Scheduler instead of the PlayerMoveEvent.

    EDIT:
    bwfcwalshy Ninja'd
    timtower You deserve this title :p
     
  7. Offline

    Sheepii

    I want a code to check if a player has a potion effect.
    If the player has a said type of potion effect, I want my code to execute. (I'll be running a runnable to check every second if they still have the potion effect and continously run the code). If they have the potion effect, I want to add them to an arraylist. Then every second it will run a bukkit runnable to check if the array has people on it, or it's empty.

    It's a king of the hill plugin type of thing. Increment the count every second someone is on the array.



    A runnable that loops through the entirety of the playerbase, seems kinda inefficient. =/

    I love how this is a really big deal. Thanks for contributing.
     
  8. Offline

    timtower Moderator Moderator

    Sheepii No efficient way exist from my knowing. And I doubt that you will notice any cpu loss from it.
     
  9. Offline

    Sheepii

    I just wrote this, so I don't really know if any of it will work. It looks fine, from what I can remember of bukkit programming. (I've been retired from bukkit programming for awhile)

    The only problem I have is " }, 20, 20);"
    I feel if it's a repeating task, why are there two longs?
    Code:java
    1.  
    2. public class Main extends JavaPlugin implements Listener {
    3.  
    4. //Array List of players on the hill.
    5. ArrayList<Player> plonhill = new ArrayList<Player>();
    6. //Time defenders have to hold out.
    7. int minutecount = 14;
    8. int secondcount = 60;
    9.  
    10.  
    11. //Time they can spend on the hill before they win. (3 minutes)
    12. int defensetime = 180;
    13.  
    14. //On enable
    15. public void onEnable() {
    16.  
    17. //Register events
    18. getServer().getPluginManager().registerEvents(this, this);
    19.  
    20.  
    21. //Run the bukkit runnable.
    22. enabled();
    23. }
    24.  
    25. public void onDisable() {
    26.  
    27. }
    28.  
    29. //Method
    30. public void enabled() {
    31.  
    32. //Bukkit runnable, repeating task.
    33. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    34. public void run() {
    35.  
    36. //Gets all the players currently online.
    37. Player[] allplayers = Bukkit.getOnlinePlayers();
    38.  
    39. //Iterates through the players.
    40. for (int i = 0; i < allplayers.length; i++) {
    41.  
    42. //If the player has a certain potion effect.
    43. if (allplayers[i].hasPotionEffect(PotionEffectType.DAMAGE_RESISTANCE)) {
    44. //If the array containing the players on the hill doesn't have
    45. //this player
    46. if (!plonhill.contains(allplayers[i])) {
    47. //Add that player
    48. plonhill.add(allplayers[i]);
    49. }
    50. }
    51. }
    52. //Iterate through the list of people on the hill.
    53. while (plonhill.iterator().hasNext()) {
    54. //Next player
    55. Player p = plonhill.iterator().next();
    56. //If the player doesn't have the potion effect anymore
    57. if (!p.hasPotionEffect(PotionEffectType.DAMAGE_RESISTANCE)) {
    58. //remove him (he's not on the hill)
    59. plonhill.remove(p);
    60. }
    61. }
    62. //ATTACKERS TIME - If the hill isn't empty (no one is on the hill)
    63. if(!plonhill.isEmpty()){
    64. //decriment the time on the hill.
    65. defensetime--;
    66. //Messages to inform everyone that the attackers are kicking $@#.
    67. if(defensetime == 120){
    68. Bukkit.broadcastMessage("Attackers have held the hill for 1 minute!");
    69. }
    70. if(defensetime == 60){
    71. Bukkit.broadcastMessage("Attackers have held the hill for 2 minutes!");
    72. }
    73. if(defensetime == 30){
    74. Bukkit.broadcastMessage("Attackers have 30 seconds until they win!");
    75. }
    76. }
    77.  
    78. //DEFENDERS TIME - Overall time of the battle
    79. //If the battle hasn't ended.
    80. if(minutecount != 0 && secondcount != 0 ){
    81. //decrement the amount of seconds
    82. secondcount--;
    83. //If the seconds = 0
    84. if(secondcount == 0){
    85. //Change it to 60 and broadcast the minute mark for
    86. //the entire server.
    87. secondcount = 60;
    88.  
    89. Bukkit.broadcastMessage("Defenders have " + minutecount + " left to hold out the Attackers.");
    90. //Decrement the minute amount AFTER
    91. minutecount--;
    92. }
    93.  
    94. }
    95. }
    96. //I'm kinda iffy on this part
    97. }, 20, 20);
    98. }
    99. //If the player dies in the heat of battle, whilst on the hill, it will remove their potion effects.
    100. //Just used as a failsafe.
    101. @EventHandler
    102. public void playerDeath(PlayerDeathEvent event){
    103. if(event.getEntity() instanceof Player){
    104. Player player = event.getEntity();
    105. if(player.hasPotionEffect(PotionEffectType.DAMAGE_RESISTANCE)){
    106. player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 0, 0));
    107. }
    108. }
    109. }
    110. }
    111. [/i][/i][/i]
     
  10. Offline

    xTrollxDudex

    Sheepii
    The first long is the ticks after calling the method that the repeating task starts.

    For example, if you had 20, 20, then the repeating task starts 1 second after you schedule it. Usually, you should leave it at 0 so it starts immediately.
     
    Sheepii likes this.
  11. Offline

    ColonelHedgehog

    It depends where you call it (I think). For example, if you were using a runnable to close the inventory within the click event, I think you'd want it to be set at "1".
     
    xTrollxDudex likes this.
Thread Status:
Not open for further replies.

Share This Page