How can i disable ArmorStand breaking?

Discussion in 'Plugin Development' started by {dev. Thom}, Feb 23, 2021.

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

    {dev. Thom}

    Hi guys,
    i need disable armorstand breaking for lobby designing, here is my code:
    Code:
    @EventHandler
    public void onPlayerDamageByPlayer(EntityDamageByEntityEvent e) {
         Player p = (Player) e.getEntity();      
         if (p.getWorld().getName().equalsIgnoreCase("Lobby1") ||
              p.getWorld().getName().equalsIgnoreCase("Lobby2") ||
              p.getWorld().getName().equalsIgnoreCase("Lobby3") ||
              p.getWorld().getName().equalsIgnoreCase("VipLobby")) {
              if (e.getDamager() instanceof Player) {
                   e.setCancelled(true);                      
               }
         }
    }
    
    Please help me...
     
  2. Offline

    CraftCreeper6

    @{dev. Thom}
    The problem is?
    Does anything happen?
    You're checking if both the entity and the damager are player? Shouldn't one be an armour stand?
     
  3. Offline

    {dev. Thom}

    [QUOTE = "CraftCreeper6, příspěvek: 3633086, člen: 90914763"] [USER = 91359080] @ {dev. Thom} [/ UŽIVATEL]
    Problém je?
    Stává se něco?
    Zkontrolujete, zda jsou entita i poškozený hráč? Nemělo by to být brnění? [/ QUOTE]

    OK, i will try it...
     
    Last edited: Feb 24, 2021
  4. Offline

    Strahan

    Also if you want to make this a little easier to cover future expansion (if you add more lobbies for example), just check if the world name contains lobby. Be sure to remember to convert the world name to lowercase before you check the contents.

    Though my preferred method is to leverage the config system. I hate hardcoding anything if I can avoid it.
     
  5. Offline

    {dev. Thom}

    So. I tried your tip, but it not working, code looking like this:
    Code:
    @EventHandler
        public void onPlayerDamageByPlayer(EntityDamageByEntityEvent e) {
            Player p = (Player) e.getEntity();       
            if (p.getWorld().getName().equalsIgnoreCase("Lobby1") ||
                    p.getWorld().getName().equalsIgnoreCase("Lobby2") ||
                    p.getWorld().getName().equalsIgnoreCase("Lobby3") ||
                    p.getWorld().getName().equalsIgnoreCase("VipLobby")) {
                if (e.getDamager() instanceof Player) {
                    e.setCancelled(true);                       
                    if (e.getEntityType() == EntityType.ARMOR_STAND) {
                        e.setCancelled(true);
                    }
                }
            }
        }
    
    (I don't know if I understood you correctly...)
     
  6. Offline

    CraftCreeper6

    @{dev. Thom}
    When you cast player to p you should be using e#getDamager() not e#getEntity(), it should work after that.
     
  7. Offline

    I_Eat_Crayons

    Is it just me... Or is there a double tab (line 5-7)
     
  8. Offline

    timtower Administrator Administrator Moderator

    And that is bad why?
     
  9. Offline

    {dev. Thom}

    [QUOTE = "CraftCreeper6, příspěvek: 3633209, člen: 90914763"] [USER = 91359080] @ {dev. Thom} [/ UŽIVATEL]
    Když sesíláte hráče do p, měli byste používat e # getDamager (), nikoli e # getEntity (), mělo by to fungovat potom. [/ QUOTE]
    Thanks, i will try it...
     
Thread Status:
Not open for further replies.

Share This Page