-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add compatibility for plugin 'HuskTowns' (#36)
* Add dependency to compatible with plugin 'HuskTowns' * Add compatibility for plugin 'HuskTowns' * Update README.md
- Loading branch information
Showing
4 changed files
with
59 additions
and
1 deletion.
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
51 changes: 51 additions & 0 deletions
51
src/main/java/io/th0rgal/protectionlib/compatibilities/HuskTownsCompat.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,51 @@ | ||
package io.th0rgal.protectionlib.compatibilities; | ||
|
||
import io.th0rgal.protectionlib.ProtectionCompatibility; | ||
import net.william278.husktowns.api.BukkitHuskTownsAPI; | ||
import net.william278.husktowns.api.HuskTownsAPI; | ||
import net.william278.husktowns.claim.Position; | ||
import net.william278.husktowns.libraries.cloplib.operation.OperationType; | ||
import net.william278.husktowns.user.OnlineUser; | ||
import org.bukkit.Location; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.Plugin; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class HuskTownsCompat extends ProtectionCompatibility { | ||
private final HuskTownsAPI commonAPI; | ||
private final BukkitHuskTownsAPI bukkitAPI; | ||
|
||
public HuskTownsCompat(JavaPlugin mainPlugin, Plugin plugin) { | ||
super(mainPlugin, plugin); | ||
commonAPI = HuskTownsAPI.getInstance(); | ||
bukkitAPI = BukkitHuskTownsAPI.getInstance(); | ||
} | ||
|
||
@Override | ||
public boolean canBuild(Player player, Location target) { | ||
return isOperationAllowed(player, target, OperationType.BLOCK_PLACE); | ||
} | ||
|
||
@Override | ||
public boolean canBreak(Player player, Location target) { | ||
return isOperationAllowed(player, target, OperationType.BLOCK_BREAK); | ||
} | ||
|
||
@Override | ||
public boolean canInteract(Player player, Location target) { | ||
OperationType type = target.getBlock().getType().isBlock() ? OperationType.BLOCK_INTERACT : OperationType.ENTITY_INTERACT; | ||
return isOperationAllowed(player, target, type); | ||
} | ||
|
||
@Override | ||
public boolean canUse(Player player, Location target) { | ||
return isOperationAllowed(player, target, OperationType.BLOCK_INTERACT); | ||
} | ||
|
||
private boolean isOperationAllowed(@NotNull Player player, @NotNull Location location, @NotNull OperationType type) { | ||
OnlineUser user = bukkitAPI.getOnlineUser(player); | ||
Position position = bukkitAPI.getPosition(location); | ||
return commonAPI.isOperationAllowed(user, type, position); | ||
} | ||
} |