-
Notifications
You must be signed in to change notification settings - Fork 32
Add residence protection #690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
||
if (residence == null) return true; | ||
|
||
Residence resInstance = Residence.getInstance(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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;
}
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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.