-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
116 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package me.bryang.chatlab.hook; | ||
|
||
public interface Hook{ | ||
|
||
HookStatus install(); | ||
|
||
String errorMessage(); | ||
|
||
String pluginName(); | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
plugin/src/main/java/me/bryang/chatlab/hook/type/vault/VaultHook.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,45 @@ | ||
package me.bryang.chatlab.hook.type.vault; | ||
|
||
import me.bryang.chatlab.hook.Hook; | ||
import me.bryang.chatlab.hook.HookStatus; | ||
|
||
import javax.inject.Singleton; | ||
|
||
@Singleton | ||
public class VaultHook implements Hook { | ||
|
||
private final String pluginName = "Vault"; | ||
private String errorMessage = ""; | ||
private VaultSource vaultSource; | ||
|
||
public VaultSource get() { | ||
return vaultSource; | ||
} | ||
|
||
@Override | ||
public HookStatus install() { | ||
|
||
vaultSource = new VaultSource(); | ||
|
||
String errorMessage = vaultSource.install(); | ||
|
||
if (errorMessage.isEmpty()){ | ||
return HookStatus.SUCCESSFUL; | ||
|
||
}else{ | ||
this.errorMessage = errorMessage; | ||
return HookStatus.ERROR; | ||
} | ||
} | ||
|
||
@Override | ||
public String errorMessage(){ | ||
return errorMessage; | ||
} | ||
|
||
@Override | ||
public String pluginName() { | ||
return pluginName; | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
plugin/src/main/java/me/bryang/chatlab/service/plugin/HookService.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,60 @@ | ||
package me.bryang.chatlab.service.plugin; | ||
|
||
|
||
import me.bryang.chatlab.hook.HookStatus; | ||
import me.bryang.chatlab.hook.type.vault.VaultHook; | ||
import me.bryang.chatlab.service.Service; | ||
import org.bukkit.Bukkit; | ||
import org.slf4j.Logger; | ||
|
||
import javax.inject.Inject; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class HookService implements Service { | ||
|
||
@Inject | ||
private VaultHook vaultHook; | ||
|
||
@Inject | ||
private Logger logger; | ||
|
||
private final List<String> errorList = new ArrayList<>(); | ||
|
||
public void start(){ | ||
|
||
HookStatus hookStatus = check(); | ||
|
||
switch (hookStatus){ | ||
case SUCCESSFUL -> { | ||
logger.info("Loaded Vault hook."); | ||
return; | ||
} | ||
case DISABLED -> { | ||
return; | ||
} | ||
} | ||
|
||
if (!errorList.isEmpty()){ | ||
errorList.forEach(errorMessage -> logger.error("Error: " + errorMessage)); | ||
} | ||
} | ||
|
||
private HookStatus check() { | ||
|
||
if (!Bukkit.getPluginManager().isPluginEnabled("Vault")) { | ||
return HookStatus.DISABLED; | ||
} | ||
|
||
HookStatus hookStatus = vaultHook.install(); | ||
|
||
if (hookStatus == HookStatus.ERROR) { | ||
errorList.add(vaultHook.errorMessage()); | ||
} | ||
|
||
return hookStatus; | ||
|
||
} | ||
|
||
|
||
} |