-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
Adding requirements for blocks (AuraSkillsLevelRestrict) #342
base: master
Are you sure you want to change the base?
Conversation
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.
Initial review before testing requesting some minor changes
bukkit/src/main/java/dev/aurelium/auraskills/bukkit/requirement/RequirementManager.java
Show resolved
Hide resolved
private final Material material; | ||
private final boolean checksPlace; | ||
private final boolean checksBreak; | ||
private final LinkedList<RequirementNode> nodes; |
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.
Use the abstract List type here instead of LinkedList, same for all other places in this class.
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.
alr, the initial goal was to supply it with a ordered structure so whatever you added, it will be checked with the given order, allowing more specific messages
|
||
protected AuraSkills plugin; | ||
|
||
public RequirementNode(AuraSkills plugin) { |
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.
The deny message can be stored and passed in the constructor of the abstract class here. Then you only need to implement the getDenyMessage method once here and not multiple times in each requirement type.
this.message = message; | ||
} | ||
|
||
public boolean check(Player player) { |
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.
Add the Override annotation
this.message = message; | ||
} | ||
|
||
public boolean check(Player player) { |
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.
Add the Override annotation.
this.message = message; | ||
} | ||
|
||
public boolean check(Player player) { |
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.
Add the Override annotation.
@@ -163,4 +167,22 @@ private void checkItemRequirements(Player player, ItemStack item, Cancellable ev | |||
} | |||
} | |||
|
|||
private void checkBlockRequirements(Player player, Material material, Cancellable event) { | |||
BlockRequirement blockRequirement = manager.getBlocks().stream().filter(b -> b.getMaterial() == material).findFirst().orElse(null); |
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.
Using a normal for loop instead of streams is preferred for slightly better performance, especially since this method could be called frequently.
if (!node.check(player)) { | ||
event.setCancelled(true); | ||
String message = node.getDenyMessage(); | ||
if(!message.isEmpty()) player.sendMessage(message); |
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.
Add space after if
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.
.-.
boolean allowPlace = blockNode.node("allow_place").getBoolean(); | ||
boolean allowBreak = blockNode.node("allow_break").getBoolean(); | ||
List<? extends ConfigurationNode> requirementNodes = blockNode.node("requirements").childrenList(); | ||
LinkedList<RequirementNode> nodes = new LinkedList<>(); |
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.
Use an ArrayList instead of LinkedList
In this PR, I added AuraSkillsLevelRestricts functionality to the main plugin.
See this config example:
It essentially allows setting requirements for blocks to be broken as well as placed, with the options for: skill levels, permissions, excluded worlds and stat levels