Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Cancel remove effect to get pernament effect

Comments in 'Plugin Development' started by Inta, Aug 4, 2016.

  1. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    My code:
    PHP:
    public function noEffectDrop(DataPacketSendEvent $event) {
            
    $pk $event->getPacket();
            if(
    $pk instanceof MobEffectPacket){
                if(
    $pk->eventId <> MobEffectPacket::EVENT_REMOVE) return;
                
    $id 5;
                if(
    $pk->effectId === $id) {
                    
    $event->setCancelled();
                    return;
                }
            }
        }
    not working.
  2. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    https://github.com/SOF3/forums-common-sense/wiki/Terms-and-Abbreviations#non-recognized-terms

    In addition, what have you attempted to fix this problem? Have you added any code breakpoints, such as
    PHP:
    echo __FILE__ "#" __LINE__ "\n";
    lines to locate which part went wrong?
  3. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    The problem maybe not in my code. The removeAllEffects() called remove() which send packet to Player. So what i ended up not working is the code after all the condition:

    PHP:
    $event->setCancelled();
    The question say it all.
  4. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    This would merely stop the server from sending the client the packet telling them (client) that the effect has been removed. The server handles everything to do with effects it self so the client will no longer be affected by the effect, not to mention that the client probably removes effects that have timed out.
  5. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    Is that mean if i stop that packet the client will do nothing about it?
  6. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Read, stopping the server from sending the packet that notifies the player of an effect being removed does next to nothing. The server handles how long a player has effects and applies what the effects do, the packets sent to the client are merely for aesthetic proposes (particles, effect list).

    If you want to stop a player from loosing an effect then set the effect's length to PHP_INT_MAX or use a large hex number.
  7. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    But in this situation i have to deal with effects being removed when the player death, not effect timeout.
    Sorry if the infomations i provided is not enough but i thought that when the effects timeout and Player being Death is the same due to removeAllEffects() function is run on both.
  8. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Re-apply the effect when they re-spawn or prevent them from actually dying by detecting when they'll die on EntityDamageEvent and handle it however you want it.
  9. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    PlayerRespawnEvent just called before the player hit Respawn and i don't want to use EntityDamageEvent..
  10. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Schedule a task then.
  11. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    What if they decided to hit Respawn button for the different times?
  12. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    What if you were smart and used your brain, store something to represent players that are scheduled to re-spawn in an array and check the to see if they're in that array the next time they move or perform some other action?
  13. Inta
    Offline

    Inta Active Member

    Joined:
    Feb 11, 2016
    Posts:
    84
    Minecraft User:
    InstantlyTa
    Why we have to do something that unefficiency, complicated and condition-based actions like that while i'm looking for the absolute solution at the exact same time when the player hit the Respawn button?
  14. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    The server handles all the re-spawn actions when the player dies, you either do something that seems so 'inefficient' or prevent the action from happening in the first place (EntityDamageEvent).
  15. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Store the effects before player dies. Remove all effects and add effects in PlayerRespawnEvent.

    Note that PlayerRespawnEvent is also called when player joins, so you need to remove all effects first.

Share This Page

Advertisement