mirror of
https://github.com/Maxlego08/zKoth.git
synced 2024-06-24 10:04:42 +02:00
📝 Add zscheduler implementation
This commit is contained in:
parent
326d18f298
commit
45bc5c3845
5
pom.xml
5
pom.xml
|
@ -186,5 +186,10 @@
|
|||
<scope>system</scope>
|
||||
<systemPath>${basedir}/libs/TitleManager-2.3.6.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.Maxlego08</groupId>
|
||||
<artifactId>zSchedulers</artifactId>
|
||||
<version>1.0.5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -146,7 +146,7 @@ public class KothManager extends ZUtils implements Savable {
|
|||
this.saveKoth(koth);
|
||||
}
|
||||
|
||||
private Optional<Koth> getKoth(String name) {
|
||||
public Optional<Koth> getKoth(String name) {
|
||||
return this.koths.stream().filter(koth -> name != null && koth.getFileName().equalsIgnoreCase(name)).findFirst();
|
||||
}
|
||||
|
||||
|
@ -212,4 +212,8 @@ public class KothManager extends ZUtils implements Savable {
|
|||
|
||||
this.saveKoth(koth);
|
||||
}
|
||||
|
||||
public List<Koth> getKoths() {
|
||||
return this.koths;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,10 +7,12 @@ import fr.maxlego08.koth.hook.scoreboard.DefaultHook;
|
|||
import fr.maxlego08.koth.placeholder.LocalPlaceholder;
|
||||
import fr.maxlego08.koth.save.Config;
|
||||
import fr.maxlego08.koth.save.MessageLoader;
|
||||
import fr.maxlego08.koth.scheduler.ZkothImplementation;
|
||||
import fr.maxlego08.koth.scoreboard.ScoreBoardManager;
|
||||
import fr.maxlego08.koth.storage.StorageManager;
|
||||
import fr.maxlego08.koth.zcore.ZPlugin;
|
||||
import fr.maxlego08.koth.zcore.logger.Logger;
|
||||
import fr.maxlego08.koth.zcore.utils.plugins.Plugins;
|
||||
|
||||
/**
|
||||
* System to create your plugins very simply Projet:
|
||||
|
@ -57,6 +59,12 @@ public class KothPlugin extends ZPlugin {
|
|||
}
|
||||
this.scoreBoardManager.setScoreboard(this.kothScoreboard);
|
||||
|
||||
if (this.isEnable(Plugins.ZSCHEDULERS)) {
|
||||
Logger.info("Register zScheduler implementation", Logger.LogType.INFO);
|
||||
ZkothImplementation implementation = new ZkothImplementation(this);
|
||||
implementation.register();
|
||||
}
|
||||
|
||||
this.postEnable();
|
||||
}
|
||||
|
||||
|
|
62
src/fr/maxlego08/koth/scheduler/ZkothImplementation.java
Normal file
62
src/fr/maxlego08/koth/scheduler/ZkothImplementation.java
Normal file
|
@ -0,0 +1,62 @@
|
|||
package fr.maxlego08.koth.scheduler;
|
||||
|
||||
import fr.maxlego08.koth.KothPlugin;
|
||||
import fr.maxlego08.koth.api.Koth;
|
||||
import fr.maxlego08.koth.zcore.logger.Logger;
|
||||
import fr.maxlego08.zscheduler.api.Implementation;
|
||||
import fr.maxlego08.zscheduler.api.Scheduler;
|
||||
import fr.maxlego08.zscheduler.api.SchedulerManager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
|
||||
public class ZkothImplementation implements Implementation {
|
||||
|
||||
private final KothPlugin plugin;
|
||||
|
||||
/**
|
||||
* @param plugin
|
||||
*/
|
||||
public ZkothImplementation(KothPlugin plugin) {
|
||||
super();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
SchedulerManager schedulerManager = this.plugin.getProvider(SchedulerManager.class);
|
||||
schedulerManager.registerImplementation(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "ZKOTH";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void schedule(Scheduler scheduler) {
|
||||
String kothName = (String) scheduler.getImplementationValues().getOrDefault("koth_name", "");
|
||||
boolean startNow = (boolean) scheduler.getImplementationValues().getOrDefault("start_now", false);
|
||||
|
||||
if (kothName.equalsIgnoreCase("random")) {
|
||||
List<Koth> koths = this.plugin.getKothManager().getKoths();
|
||||
if (koths.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Koth koth = koths.get(new Random().nextInt(koths.size()));
|
||||
koth.spawn(startNow);
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<Koth> optional = this.plugin.getKothManager().getKoth(kothName);
|
||||
if (optional.isPresent()) {
|
||||
|
||||
Koth koth = optional.get();
|
||||
koth.spawn(startNow);
|
||||
|
||||
} else {
|
||||
Logger.info("Koth with name " + kothName + " was not found with scheduler " + scheduler.getName(), Logger.LogType.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -178,7 +178,7 @@ public abstract class ZPlugin extends JavaPlugin {
|
|||
* @param classz
|
||||
* @return
|
||||
*/
|
||||
protected <T> T getProvider(Class<T> classz) {
|
||||
public <T> T getProvider(Class<T> classz) {
|
||||
RegisteredServiceProvider<T> provider = getServer().getServicesManager().getRegistration(classz);
|
||||
if (provider == null) {
|
||||
log.log("Unable to retrieve the provider " + classz.toString(), Logger.LogType.WARNING);
|
||||
|
|
|
@ -9,6 +9,8 @@ public enum Plugins {
|
|||
CITIZENS("Citizens"),
|
||||
TRANSLATIONAPI("TranslationAPI"),
|
||||
ZTRANSLATOR("zTranslator"),
|
||||
|
||||
ZSCHEDULERS("zSchedulers"),
|
||||
|
||||
;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user