Set a player's PvP true

Discussion in 'Plugin Development' started by krazyswaggaO, Aug 21, 2012.

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

    krazyswaggaO

    So yea,as the tittle suggest,I want help on this.Basically,if the PvP boolean is true(boolean PvP = true;),it would override any protection plugin(for example,If you are in a protected area in Towny,you would override the plugin and you can be hit).
    Any help?
     
  2. Offline

    kyle1320

    I think doing
    Code:
    event.setCancelled(false);
    will override anything else, so just use a listener then check if PvP is on for them and use that to make sure they're damaged. I could be (entirely) wrong on this, though.
     
  3. Offline

    krazyswaggaO

    kyle1320
    Alright,so here's my code basically:
    public void onEntityDamage(EntityDamageByEntityEvent e){
    Player d2 = (Player)e.getDamager();
    if(e.getCause() == DamageCause.ENTITY_ATTACK){
    if(e.getEntity() instanceof Player){
    d2.sendMessage(ChatColor.BLUE + "[PvPFlagger] You are now flagged!");
    e.setCancelled(false);

    If this doesn't turn out to work,will changing the Priority matter?
    Also,here's another question, every-time the event is triggered,it spams my chat.I tried doing a return; but it didn't work.
     
  4. Offline

    kyle1320

    krazyswaggaO
    You should be checking that they're both players (especially before using (Player)e.getDamager(); ) , and I'm not sure why if(e.getCause() == DamageCause.ENTITY_ATTACK) is necessary since you've got an entityDamageByEntityEvent where they're both players (in what case would it not be an entity attack? :)). This should work fine:
    Code:
    public void onEntityDamage(EntityDamageByEntityEvent e){
        if (e.getDamager() instanceof Player && e.getEntity() instanceof Player){
            Player d2 = (Player)e.getDamager();
            d2.sendMessage(ChatColor.BLUE + "[PvPFlagger] You are now flagged!");
            e.setCancelled(false);
        }
    }
    Usually I wouldn't mess with the priority, normal should work just fine for something like this. As for it spamming your chat, I don't know. Try the code above and see if it still spams you.
     
  5. Offline

    krazyswaggaO

    Nope,still spams it:
    http://gyazo.com/a61a4556aaed3242aad9f01890d25fff
    I tried a few things:
    @EventHandler(ignoreCancelled = true)
    after I did e.setCancelled(true);
    I did return.
    I even tried doing a break; in there,but no result.I've seen it done somewhere too,so it's possible
     
  6. Offline

    nicho96

    I assume you have your @EventHandler in there?

    Edit: nvm, previous post answers this xD
     
  7. Offline

    kyle1320

    Weird, it's working fine for me. Try disabling any other plugins and make sure you're running only on the latest recommended build of Bukkit.
     
  8. Offline

    krazyswaggaO

    Nope,same issue.

    Anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  9. Offline

    kyle1320

    It spams you like that even if you only hit a player once? I tried it out and it seemed fairly easy to get tons of messages if you were spam clicking.
     
  10. Offline

    krazyswaggaO

    Yes,it does (I forgot to mention that,didn't I?).I basically want it to send a message once,if I hit you every 2 minutes.I did a scheduler and everytime I hit you in between those 2 minutes,I would do sendRawMessage(null) but it seems I still get the messages.
    Any other way?
     
Thread Status:
Not open for further replies.

Share This Page