Skip to content

Commit

Permalink
feat(hook): create hook-service
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanGmG committed Jan 29, 2024
1 parent 24392ba commit 1767b26
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
11 changes: 11 additions & 0 deletions plugin/src/main/java/me/bryang/chatlab/hook/Hook.java
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();

}
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;
}

}
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;

}


}

0 comments on commit 1767b26

Please sign in to comment.