Skip to content

Commit a5f8843

Browse files
committed
Fixed an issue where the plugin won't load if the "SafariNet" plugin was not installed
1 parent 0064ee7 commit a5f8843

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>me.mrmango404</groupId>
88
<artifactId>ContainerView</artifactId>
9-
<version>2.0.1</version>
9+
<version>2.0.3</version>
1010

1111
<repositories>
1212
<!-- This adds the Spigot Maven repository to the build -->

src/main/java/me/mrmango404/Main.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package me.mrmango404;
22

3+
import de.Linus122.SafariNet.API.Listener;
34
import de.Linus122.SafariNet.API.SafariNet;
45
import me.mrmango404.commands.CommandExecutor;
56
import me.mrmango404.events.*;
6-
import me.mrmango404.hooks.Safarinet;
77
import me.mrmango404.util.ClearShulker;
8+
import me.mrmango404.util.DebugManager;
89
import org.bukkit.Bukkit;
910
import org.bukkit.Location;
1011
import org.bukkit.entity.LivingEntity;
12+
import org.bukkit.plugin.Plugin;
1113
import org.bukkit.plugin.java.JavaPlugin;
1214
import org.bukkit.scheduler.BukkitTask;
1315
import org.bukkit.scoreboard.Scoreboard;
@@ -44,10 +46,19 @@ public void onEnable() {
4446
ConfigHandler.load();
4547
instance.saveDefaultConfig();
4648
scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
49+
Plugin safariPlug = Bukkit.getPluginManager().getPlugin("SafariNet");
4750

48-
if (Bukkit.getPluginManager().getPlugin("SafariNet") != null) {
49-
Safarinet safarinet = new Safarinet();
50-
SafariNet.addListener(safarinet);
51+
if (safariPlug != null) {
52+
try {
53+
Class<?> listenerClass = Class.forName("me.mrmango404.hooks.Safarinet");
54+
Listener listener = (de.Linus122.SafariNet.API.Listener) listenerClass.getDeclaredConstructor().newInstance();
55+
SafariNet.addListener(listener);
56+
DebugManager.log("SafariNet hook loaded.");
57+
} catch (Exception e) {
58+
DebugManager.log("SafariNet hook could not be loaded.");
59+
}
60+
} else {
61+
DebugManager.log("SafariNet hook could not be found.");
5162
}
5263
}
5364

0 commit comments

Comments
 (0)