Spam from PlayerMoveEvent

Discussion in 'Plugin Development' started by Schaakmatth, May 9, 2014.

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

    Schaakmatth

    hello this works exactly but 1 problem got spammed! with Heres your Regeneration! how to set a timer or something?
    Code:java
    1. private ArrayList<UUID> woolPlayers = new ArrayList<UUID>();
    2. @EventHandler
    3. public void woolmove (PlayerMoveEvent e) {
    4. Block under = e.getPlayer().getLocation().getBlock().getRelative(BlockFace.DOWN);
    5. if(under.getType().equals(Material.EMERALD_BLOCK)) {
    6. e.getPlayer().sendMessage(ChatColor.GREEN + "Heres your Regeneration!");
    7. e.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 300, 10));
    8. }else if (woolPlayers.contains(e.getPlayer().getUniqueId())) {
    9. woolPlayers.remove(e.getPlayer().getUniqueId());
    10. e.getPlayer().removePotionEffect(PotionEffectType.REGENERATION);
     
  2. Offline

    DxDy

    Seeing as giving him the potion-effect will hardly do anything noteworthy if he already has the effect, why don't you just check if he already has the effect?
     
  3. Offline

    Schaakmatth

    yeah but that gives none spam the spam is : Heres your regeneration! DxDy
     
  4. Offline

    RawCode

    please post javadocs from playermove event here, i will point with big red letters to words you missed.
     
  5. Offline

    JBoss925

    Add them to a "regening" array list that adds people when they get the regen and then before you send the message make sure they're not in it. Then you can use a bukkit runnable if you want to remove them so they can regen again.
     
  6. Offline

    Bobit

    I think he knows that playerMoveEvent triggers extremely often. He doesn't know how to prevent it, though.
     
  7. Offline

    RawCode

    Bobit
    In most cases such things prevented by logical expressions, that does not belong to bukkit and belong to generic (not ever coding) knowlage about boolean logic.
     
  8. Offline

    Schaakmatth

  9. Offline

    GeorgeeeHD

    Schaakmatth just put all the code in that event inside this if clause;

    Code:java
    1. if(!p.hasPotionEffect(PotionEffectType.REGENERATION)) {
    2. //All of the code for the MoveEvent here...
    3. }
     
  10. Offline

    Relicum

    @Schaakmatth

    Code:java
    1. if (e.getFrom().getBlockX() == e.getTo().getBlockX() &&
    2. e.getFrom().getBlockY() == e.getTo().getBlockY() && e.getFrom().getBlockZ() ==
    3. e.getTo().getBlockZ()) {
    4. return;
    5. }
    6.  
    7.  


    In most cases break out the method only if the player has actually moved from one block to another. This makes a massive difference. But if your case GeorgeeeHD has the perfect answer fro you.
     
  11. Offline

    Bobit

    True it may be that it doesn't belong to bukkit, he still doesn't know, and it's not easy for him to figure out...
    Personally, I think it belongs to coding though.
     
  12. Offline

    evilmidget38

Thread Status:
Not open for further replies.

Share This Page