Skip to content
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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

Fly1337
Copy link
Contributor

@Fly1337 Fly1337 commented Dec 21, 2024

In this PR, I added AuraSkillsLevelRestricts functionality to the main plugin.

See this config example:

requirement:
  blocks:
  - material: diamond_ore
    allow_place: true
    allow_break: false
    requirements:
    - type: skill_level
      skill: farming
      level: 10
      message: 'You must be Farming 10'
    - type: permission
      permission: some.permission
      message: ''
    - type: excluded_world
      world: world
      message: ''
    - type: stat
      stat: strength
      value: 10
      message: 'You must have at least 10 strength'

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

Copy link
Owner

@Archy-X Archy-X left a 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

private final Material material;
private final boolean checksPlace;
private final boolean checksBreak;
private final LinkedList<RequirementNode> nodes;
Copy link
Owner

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.

Copy link
Contributor Author

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) {
Copy link
Owner

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) {
Copy link
Owner

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) {
Copy link
Owner

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) {
Copy link
Owner

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);
Copy link
Owner

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);
Copy link
Owner

Choose a reason for hiding this comment

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

Add space after if

Copy link
Contributor Author

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<>();
Copy link
Owner

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

@Fly1337 Fly1337 requested a review from Archy-X December 21, 2024 20:15
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