-
Notifications
You must be signed in to change notification settings - Fork 37
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
JoaoVictor834
wants to merge
3
commits into
RoinujNosde:master
Choose a base branch
from
JoaoVictor834:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
import org.bukkit.Location; | ||
import org.bukkit.OfflinePlayer; | ||
import org.bukkit.World; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.scheduler.BukkitTask; | ||
import org.jetbrains.annotations.NotNull; | ||
|
@@ -26,6 +27,8 @@ | |
import static net.sacredlabyrinth.phaed.simpleclans.SimpleClans.debug; | ||
import static net.sacredlabyrinth.phaed.simpleclans.SimpleClans.lang; | ||
import static net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager.ConfigField.*; | ||
import static net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager.IgnoredType.LAND; | ||
import static net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager.IgnoredType.WAR; | ||
|
||
public class ProtectionManager { | ||
|
||
|
@@ -104,10 +107,22 @@ public Set<Land> getLandsOf(@NotNull OfflinePlayer player, @NotNull World world) | |
} | ||
|
||
public boolean can(@NotNull Action action, @NotNull Location location, @NotNull Player player) { | ||
return can(action, location, player, null); | ||
return can(action, location, player, null, null); | ||
} | ||
|
||
public boolean can(@NotNull Action action, @NotNull Location location, @NotNull Player player, @Nullable Player other) { | ||
/** | ||
* Checks if the specified action is allowed at the given location for the players involved. | ||
* | ||
* @param action The action to be performed. | ||
* @param location The location where the action is to be performed. | ||
* @param player The player performing the action. | ||
* @param involvedBlock the block involved in the action (can be null). | ||
* @param other The other player involved in the action (can be null). | ||
* @return true if the action is allowed, false otherwise. | ||
* @see Action | ||
*/ | ||
public boolean can(@NotNull Action action, @NotNull Location location, | ||
@NotNull Player player, @Nullable Block involvedBlock, @Nullable Player other) { | ||
for (Land land : getLandsAt(location)) { | ||
for (UUID owner : land.getOwners()) { | ||
if (owner == null) { | ||
|
@@ -119,8 +134,8 @@ public boolean can(@NotNull Action action, @NotNull Location location, @NotNull | |
} else { | ||
involved = player; | ||
} | ||
if (isWarringAndAllowed(action, owner, involved) || | ||
isSameClanAndAllowed(action, owner, involved, land.getId())) { | ||
if (isWarringAndAllowed(action, owner, involved, involvedBlock) || | ||
isSameClanAndAllowed(action, owner, involved, land.getId(), involvedBlock)) { | ||
return true; | ||
} | ||
} | ||
|
@@ -213,10 +228,12 @@ private void clearWars() { | |
} | ||
} | ||
|
||
private boolean isSameClanAndAllowed(Action action, UUID owner, Player involved, String landId) { | ||
if (!settingsManager.is(LAND_SHARING)) { | ||
private boolean isSameClanAndAllowed(Action action, UUID owner, Player involved, String landId, @Nullable Block block) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Method |
||
if (!settingsManager.is(LAND_SHARING) || | ||
block != null && settingsManager.ignoredIn(LAND, action, block)) { | ||
return false; | ||
} | ||
|
||
ClanPlayer cp = clanManager.getCreateClanPlayer(owner); | ||
Clan involvedClan = clanManager.getClanByPlayerUniqueId(involved.getUniqueId()); | ||
if (cp.getClan() == null || !cp.getClan().equals(involvedClan)) { | ||
|
@@ -225,10 +242,12 @@ private boolean isSameClanAndAllowed(Action action, UUID owner, Player involved, | |
return cp.isAllowed(action, landId); | ||
} | ||
|
||
private boolean isWarringAndAllowed(@NotNull Action action, @NotNull UUID owner, @NotNull Player involved) { | ||
if (!settingsManager.isActionAllowedInWar(action) || !settingsManager.is(ENABLE_WAR)) { | ||
private boolean isWarringAndAllowed(@NotNull Action action, @NotNull UUID owner, @NotNull Player involved, @Nullable Block block) { | ||
if (!settingsManager.isActionAllowedInWar(action) || !settingsManager.is(ENABLE_WAR) | ||
|| block != null && settingsManager.ignoredIn(WAR, action, block)) { | ||
return false; | ||
} | ||
|
||
Clan ownerClan = clanManager.getClanByPlayerUniqueId(owner); | ||
Clan involvedClan = clanManager.getClanByPlayerUniqueId(involved.getUniqueId()); | ||
if (ownerClan == null || involvedClan == null) { | ||
|
@@ -246,7 +265,7 @@ private void registerProviders() { | |
} catch (ClassNotFoundException ex) { | ||
logger.log(Level.WARNING, String.format("Provider %s not found!", className), ex); | ||
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException | | ||
IllegalAccessException ex) { | ||
IllegalAccessException ex) { | ||
logger.log(Level.WARNING, String.format("Error instantiating provider %s", className), ex); | ||
} | ||
if (instance instanceof ProtectionProvider) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/net/sacredlabyrinth/phaed/simpleclans/migrations/IgnoredListMigration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package net.sacredlabyrinth.phaed.simpleclans.migrations; | ||
|
||
import net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager; | ||
|
||
public class IgnoredListMigration extends ConfigMigration { | ||
|
||
public IgnoredListMigration(SettingsManager settingsManager) { | ||
super(settingsManager); | ||
} | ||
|
||
@Override | ||
public void migrate() { | ||
if (config.contains("war-and-protection.listeners.ignored-list")) { | ||
config.set("war-and-protection.listeners.ignored-list", null); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Method
can
has 5 arguments (exceeds 4 allowed). Consider refactoring.