Wolfieheart / ArmorStandEditor

Spigot/Paper etc. plugin to allow players to edit armorstands without commands.
GNU General Public License v3.0
28 stars 25 forks source link

Toggle destroying armor stands #309

Closed Folas1337 closed 1 year ago

Folas1337 commented 1 year ago

Is your feature request related to a problem?

I have a few heavy users for ASE on my creative server and they work a lot with armor stands in quite small spaces which sometimes leads to them breaking armor stands when they didn't intend to do so and some frustration from this problem.

Describe the solution you'd like.

The solution I am envisioning is a toggle in the ASE menu where you can disable breaking armor stands. That way you could still break them in creative if you wanted to but you wouldn't do so if you had it toggled off. Only issue I can see with this is that people could be confused if they rejoin and still have it on and then wonder why they can't break armor stands but for me that would be a sacrifice I'm willing to make.

I would however make it toggleable in the config and have it off by default.

Describe alternatives you've considered.

I have tried making the armor stand invulnerable but that's ignored if you're in creative mode, I have also searched for plugins that already do this but came up empty handed :(

Agreements

Other

No response

Wolfieheart commented 1 year ago

This is an interesting one, cause I do wonder if we could map it to just be behind a permission. Wouldnt be the proposed solution, but would be a start, while I work out how we can implement the toggle on this.

An idea of what this could look like is:

/* Semi-TLDR of what this does
* - Checks if we are touching ArmorStands - If not we dont care
* - Checks if the player has the permission we need
* - Checks that they are also in Creative Mode
* If all that returns true - We dont break the ArmorStand
*/
    @EventHandler(priority = EventPriority.LOWEST)
    void onArmorStandBreak (BlockBreakEvent event){
        //Disables breaking an ArmorStand in Creative Mode ?
        if (ignoreNextInteract) return;
        if (event.getBlock().getType() != Material.ARMOR_STAND) return;
        Player player = event.getPlayer();

        if(player.hasPermission("asedit.disableCreativeBreak")){
            Block block = event.getBlock();
            if(block.getType() == Material.ARMOR_STAND && player.getGameMode() == GameMode.CREATIVE){
                event.setCancelled(true);
            }
        }
    }

But im now trying to work out how to map this to the toggles like we have for Disable Slots.

Folas1337 commented 1 year ago

I can probably make a permission work as well but I would certainly like to see it implemented into the menu of the plugin.

I hope it's going to work out and I'll just patiently wait (unless you need anything else from me?)

Wolfieheart commented 1 year ago

Removed 2 comments here as they were incorrect!

Wolfieheart commented 1 year ago

Ok I have a solution.

Long STory Short: Its an Invulnerability Bug.

The Code behind it now:

    @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
    void onArmorStandBreak (EntityDamageByEntityEvent event) {
        //Disables breaking an ArmorStand in Creative Mode
        if (!(event.getDamager() instanceof Player)) return;   // If we arent a player -- Ignore
        if (!(event.getEntity() instanceof ArmorStand)) return; // If we arent an ArmorStand -- ignore

        //Get the ArmorStand
        if (event.getEntity() instanceof ArmorStand entityAS){
            //CHECK: Vulnerability State and GameMode State
            if (entityAS.isInvulnerable() && event.getDamager() instanceof Player p) {
                if(p.getGameMode() == GameMode.CREATIVE) {
                    //If the player is in Creative and the ArmorStand is Invulnerabile - Cancel the Event
                    event.setCancelled(true);
                }
            }
        }
    }

The fix:

We dont need any extra menu options for this toggle, we just need to do an extra check, if a player tries to destory an invulnerable ArmorStand while in Creative Mode. Just tested this and it appears to work.

Wolfieheart commented 1 year ago

Showing the Fix in Action:

https://github.com/Wolfieheart/ArmorStandEditor/assets/18635695/d25f8e13-8bbc-4bac-8ccb-bba73ddb9887

Folas1337 commented 1 year ago

Hecc yeah this is great! Looking forward to the release! 👍