Skip to content

Commit

Permalink
feat: add debug and try-catch for checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed May 8, 2024
1 parent 86f553f commit fdb328c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pluginVersion=1.5.1
pluginVersion=1.5.2
37 changes: 33 additions & 4 deletions src/main/java/io/th0rgal/protectionlib/ProtectionLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public class ProtectionLib {

private final static Set<ProtectionCompatibility> compatibilities = new HashSet<>();
static boolean debug = false;

@SuppressWarnings("Convert2MethodRef")
public static void init(JavaPlugin plugin) {
Expand All @@ -27,20 +28,48 @@ public static void init(JavaPlugin plugin) {
handleCompatibility("BentoBox", plugin, (m, p) -> new BentoBoxCompat(m, p));
}

public static void setDebug(boolean debug) {
ProtectionLib.debug = debug;
}

public static boolean getDebug() {
return debug;
}

public static boolean canBuild(Player player, Location target) {
return compatibilities.stream().allMatch(compatibility -> compatibility.canBuild(player, target));
try {
return compatibilities.stream().allMatch(compatibility -> compatibility.canBuild(player, target));
} catch (Exception e) {
if (debug) e.printStackTrace();
return false;
}
}

public static boolean canBreak(Player player, Location target) {
return compatibilities.stream().allMatch(compatibility -> compatibility.canBreak(player, target));
try {
return compatibilities.stream().allMatch(compatibility -> compatibility.canBreak(player, target));
} catch (Exception e) {
if (debug) e.printStackTrace();
return false;
}
}

public static boolean canInteract(Player player, Location target) {
return compatibilities.stream().allMatch(compatibility -> compatibility.canInteract(player, target));
try {
return compatibilities.stream().allMatch(compatibility -> compatibility.canInteract(player, target));
} catch (Exception e) {
if (debug) e.printStackTrace();
return false;
}
}

public static boolean canUse(Player player, Location target) {
return compatibilities.stream().allMatch(compatibility -> compatibility.canUse(player, target));
try {
return compatibilities.stream().allMatch(compatibility -> compatibility.canUse(player, target));
} catch (Exception e) {
if (debug) e.printStackTrace();
return false;
}
}

private static void handleCompatibility(String pluginName, JavaPlugin mainPlugin, CompatibilityConstructor constructor) {
Expand Down

0 comments on commit fdb328c

Please sign in to comment.