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

feat: add invert-ignored-list config #420

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ public LandProtection(@NotNull SimpleClans plugin) {
public void registerListeners() {
registerListener(BlockBreakEvent.class, (event, cancel) -> {
Block block = event.getBlock();
if (settingsManager.getIgnoredList(BREAK).contains(block.getType().name())) {
if (settingsManager.isIgnored(BREAK, block)) {
return;
}

if (protectionManager.can(BREAK, block.getLocation(), event.getPlayer())) {
event.setCancelled(cancel);
}
Expand Down Expand Up @@ -98,7 +99,7 @@ public void registerListeners() {
});
registerListener(BlockPlaceEvent.class, (event, cancel) -> {
Block block = event.getBlock();
if (settingsManager.getIgnoredList(PLACE).contains(block.getType().name())) {
if (settingsManager.isIgnored(PLACE, block)) {
return;
}
if (protectionManager.can(PLACE, block.getLocation(), event.getPlayer())) {
Expand All @@ -107,7 +108,7 @@ public void registerListeners() {
});
registerListener(PlayerBucketEmptyEvent.class, (event, cancel) -> {
Block block = event.getBlockClicked();
if (settingsManager.getIgnoredList(PLACE).contains(block.getType().name())) {
if (settingsManager.isIgnored(PLACE, block)) {
return;
}
if (protectionManager.can(PLACE, block.getLocation(), event.getPlayer())) {
Expand All @@ -116,7 +117,7 @@ public void registerListeners() {
});
registerListener(PlayerBucketFillEvent.class, (event, cancel) -> {
Block block = event.getBlockClicked().getRelative(event.getBlockFace());
if (settingsManager.getIgnoredList(BREAK).contains(block.getType().name())) {
if (settingsManager.isIgnored(BREAK, block)) {
return;
}
if (protectionManager.can(BREAK, block.getLocation(), event.getPlayer())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.sacredlabyrinth.phaed.simpleclans.SimpleClans;
import net.sacredlabyrinth.phaed.simpleclans.utils.ChatUtils;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.Plugin;
Expand Down Expand Up @@ -84,6 +85,11 @@ public boolean is(ConfigField field) {
return config.getBoolean(field.path, (Boolean) field.defaultValue);
}

public boolean isIgnored(ProtectionManager.Action action, Block block) {
return is(WAR_LISTENERS_INVERT_IGNORED_LIST) ? !getIgnoredList(action).contains(block.getType().name())
: getIgnoredList(action).contains(block.getType().name());
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks!
Now everything looks good, unless one small moment.

Perhaps, you noticed that war and land features are the part of one mechanism,
ignored-list will affect on both. Consequently, it means inverted-ignore-list will prevent clan members to share their lands.

To avoid this situation, I can suggest to make ignored-list separated and each action could have it's own invert option. Something like:

war-and-protection:
  listeners:
    ignored-lists:
      war:
          PLACE:
            invert: true
            blocks:
            - "PLAYER_HEAD"
      land:
          BREAK:
            invert: false
            blocks:
            - "PLAYER_HEAD"

Then it will require to migrate old config format to a new one.
You can look at the example of migration here.

If you have other ideas, or if you have problems with the implementation, feel free to ask about it.

/**
* Load the configuration
*/
Expand Down Expand Up @@ -341,6 +347,7 @@ public enum ConfigField {
LAND_SHARING("war-and-protection.land-sharing", true),
LAND_PROTECTION_PROVIDERS("war-and-protection.protection-providers"),
WAR_LISTENERS_PRIORITY("war-and-protection.listeners.priority", "HIGHEST"),
WAR_LISTENERS_INVERT_IGNORED_LIST("war-and-protection.listeners.invert-ignored-list", true),
WAR_LISTENERS_IGNORED_LIST_PLACE("war-and-protection.listeners.ignored-list.PLACE"),
WAR_LISTENERS_IGNORED_LIST_BREAK("war-and-protection.listeners.ignored-list.BREAK"),
LAND_SET_BASE_ONLY_IN_LAND("war-and-protection.set-base-only-in-land", false),
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ war-and-protection:
- GriefPreventionProvider
listeners:
priority: HIGHEST
invert-ignored-list: true
ignored-list:
PLACE:
- "PLAYER_HEAD"
Expand Down