Add residence protection - #690
ESEAbsolute wants to merge 10 commits into
Conversation
|
|
||
| if (residence == null) return true; | ||
|
|
||
| Residence resInstance = Residence.getInstance(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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;There was a problem hiding this comment.
Yeah thats what I was thinking; mostly cause it saves on reuse of Residence;getinstance() everytime :)
There was a problem hiding this comment.
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;
}
}There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Thank you! These suggestions are helpful
|
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
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:
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
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.