Skip to content

Conversation

ESEAbsolute
Copy link

Description:

Residence plugin: https://github.com/Zrips/Residence

Residence plugin can only block the vanilla operations for taking items off an armor stand, but it cannot block operations provided by ASE plugin to move armor stands out of residences or take out items from armor stand inventories. It leads to players stealing items from armor stands.

I noticed there are already several protection modules working, so I added an extra Residence protection into the plugin.


[CORE] Changes

Changes to the core of the plugin - Performance Fixes, Bug Fixes, New Features, New Permission Nodes, New Config Options etc.

New Features:

  • add residence permission check into protections

New Permission Nodes:

  • asedit.ignoreProtection.residence

[CI] Changes

Changes relating to the Continuous Integration of other Plugin APIs, Github Workflows, Issue Templates etc.


[DOC] Changes

Changes relating to plugin Documentation - See the Wiki for more info


[MISC] Changes

Changes that does not fit in the above list


  • I have tested this pull request for defects on a server.

Tested with Luminol dacd3c5, which is a fork based on Folia

By making this pull request, I represent that I have the right to waive copyright and related rights to my contribution, and agree that all copyright and related rights in my contributions are waived, and I acknowledge that the ArmorStandEditor Project Owners have the copyright to use and modify my contribution under the ArmorStandEditor License for perpetuity.


if (residence == null) return true;

Residence resInstance = Residence.getInstance();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not be better to do this first before we get the location or the claimed residence and basically return true if we cant get the instance since I see it being reused on line 28

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean to change this part to the code displayed below? I think it is a great idea

    if (!resEnabled) return true;
    if (player.isOp()) return true;
    if (player.hasPermission("asedit.ignoreProtection.residence")) return true; //Add Additional Permission

    Residence resInstance = Residence.getInstance();
    if (resInstance == null) return true;

    final Location eLocation = block.getLocation();
    final ClaimedResidence residence = resInstance.getResidenceManager().getByLoc(eLocation);

    if (residence == null) return true;

    ResidencePermissions perms = residence.getPermissions();
    boolean hasPermission = perms.playerHas(player.getName(), "build", true);
    if (!hasPermission) resInstance.msg(player, lm.Flag_Deny, Flags.build);
    return hasPermission;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah thats what I was thinking; mostly cause it saves on reuse of Residence;getinstance() everytime :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry I know what do you mean exactly now, I misunderstood some details in the code above. It should be:

public class ResidenceProtection implements Protection {
    private final boolean resEnabled;
    private final Residence resInstance;

    public ResidenceProtection() {
        resEnabled = Bukkit.getPluginManager().isPluginEnabled("Residence");
        if (Bukkit.getPluginManager().isPluginEnabled("Residence")) {
            resInstance = null;
            return;
        }
        resInstance = Residence.getInstance();
    }

    @Override
    public boolean checkPermission(Block block, Player player) {
        if (!resEnabled) return true;
        if (player.isOp()) return true;
        if (player.hasPermission("asedit.ignoreProtection.residence")) return true; //Add Additional Permission

        final Location eLocation = block.getLocation();
        final ClaimedResidence residence = resInstance.getResidenceManager().getByLoc(eLocation);
        if (residence == null) return true;

        ResidencePermissions perms = residence.getPermissions();
        boolean hasPermission = perms.playerHas(player.getName(), "build", true);
        if (!hasPermission) resInstance.msg(player, lm.Flag_Deny, Flags.build);
        return hasPermission;
    }
}

Copy link
Owner

@Wolfieheart Wolfieheart Mar 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but Minor remark,

Better reads as:

       if (Bukkit.getPluginManager().isPluginEnabled("Residence")) {
           resInstance = null;
           return;
       } else {
           resInstance = Residence.getInstance();
           return;
      }

Also, might want to add into that when cehcking the permission the following

   if (resInstance == null ) return true;

Better safe than sorry just incase.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! These suggestions are helpful

@Wolfieheart
Copy link
Owner

Note for me: Rebase this onto 1.21.4-48.2

mvn install:install-file \
  -Dfile=lib/Residence5.0.1.7.jar \
  -DgroupId=zrips.residence \
  -DartifactId=Residence \
  -Dversion=5.0.1.7 \
  -Dpackaging=jar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants