Moved Massive Factions to its own module

This commit is contained in:
OmerBenGera 2021-12-25 20:51:51 +02:00
parent c3fa896ed2
commit 1ebfaad641
6 changed files with 102 additions and 51 deletions

View File

@ -0,0 +1,14 @@
group 'Hook_MassiveFactions'
dependencies {
compileOnly "com.massivecraft:Factions:latest"
compileOnly "com.massivecraft:MassiveCore:latest"
compileOnly "org.spigotmc:v1_8_R3-Taco:latest"
compileOnly project(":API")
compileOnly parent
}
if (project.hasProperty('hook.compile_massivefactions') &&
!Boolean.valueOf(project.findProperty("hook.compile_massivefactions").toString())) {
project.tasks.all { task -> task.enabled = false }
}

View File

@ -7,37 +7,18 @@ plugins {
group 'WildLoaders' group 'WildLoaders'
version = "1.0.1" version = "1.0.1"
subprojects { allprojects {
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'com.github.johnrengelman.shadow'
repositories {
maven { url 'https://repo.bg-software.com/repository/nms/' }
maven { url 'https://repo.bg-software.com/repository/common/' }
}
dependencies {
compileOnly 'com.bgsoftware.common.reflection:ReflectionUtils:latest'
}
shadowJar {
archiveName = "${project.name}.jar"
destinationDir = file("../archive/")
}
build {
dependsOn shadowJar
}
}
repositories { repositories {
maven { url 'https://repo.bg-software.com/repository/nms/' } maven { url 'https://repo.bg-software.com/repository/nms/' }
maven { url 'https://repo.bg-software.com/repository/api/' } maven { url 'https://repo.bg-software.com/repository/api/' }
maven { url 'https://repo.bg-software.com/repository/public-libs/' }
maven { url 'https://repo.bg-software.com/repository/common/' } maven { url 'https://repo.bg-software.com/repository/common/' }
maven { url 'https://repo.bg-software.com/repository/public-libs/' }
String mavenUsername = project.hasProperty('mavenUsername') ? project.mavenUsername : System.getenv('mavenUsername'); String mavenUsername = System.getenv('mavenUsername') == null ? project.mavenUsername : System.getenv('mavenUsername');
String mavenPassword = project.hasProperty('mavenPassword') ? project.mavenPassword : System.getenv('mavenPassword'); String mavenPassword = System.getenv('mavenPassword') == null ? project.mavenUsername : System.getenv('mavenPassword');
if (mavenUsername != null && mavenPassword != null) { if (mavenUsername != null && mavenPassword != null) {
maven { maven {
@ -48,7 +29,22 @@ repositories {
} }
} }
} }
}
dependencies {
compileOnly "com.bgsoftware.common.reflection:ReflectionUtils:latest"
}
build {
dependsOn shadowJar
}
}
subprojects {
shadowJar {
archiveFileName = "${project.name}.jar"
destinationDirectory = file("../archive/")
}
} }
dependencies { dependencies {
@ -62,10 +58,8 @@ dependencies {
compileOnly 'org.spigotmc:v1_16_R3-Tuinity:latest' compileOnly 'org.spigotmc:v1_16_R3-Tuinity:latest'
// Plugin Hooks // Plugin Hooks
compileOnly "com.massivecraft:Factions:latest"
compileOnly "com.drtshock:FactionsUUID:latest" compileOnly "com.drtshock:FactionsUUID:latest"
compileOnly "net.prosavage:FactionsX:latest" compileOnly "net.prosavage:FactionsX:latest"
compileOnly "com.massivecraft:MassiveCore:latest"
compileOnly "com.bgsoftware:SuperiorSkyblockAPI:latest" compileOnly "com.bgsoftware:SuperiorSkyblockAPI:latest"
compileOnly "com.songoda:EpicSpawners-6:latest" compileOnly "com.songoda:EpicSpawners-6:latest"
} }

View File

@ -16,4 +16,5 @@ include 'v1_15_R1'
include 'v1_16_R3' include 'v1_16_R3'
include 'v1_17_R1' include 'v1_17_R1'
include 'v1_18_R1' include 'v1_18_R1'
include 'Hook_MassiveFactions'

View File

@ -57,7 +57,7 @@ public final class WildLoadersPlugin extends JavaPlugin implements WildLoaders {
dataHandler = new DataHandler(this); dataHandler = new DataHandler(this);
loadersHandler = new LoadersHandler(this); loadersHandler = new LoadersHandler(this);
npcHandler = new NPCHandler(this); npcHandler = new NPCHandler(this);
providersHandler = new ProvidersHandler(); providersHandler = new ProvidersHandler(this);
settingsHandler = new SettingsHandler(this); settingsHandler = new SettingsHandler(this);
getServer().getPluginManager().registerEvents(new BlocksListener(this), this); getServer().getPluginManager().registerEvents(new BlocksListener(this), this);

View File

@ -1,34 +1,49 @@
package com.bgsoftware.wildloaders.handlers; package com.bgsoftware.wildloaders.handlers;
import com.bgsoftware.wildloaders.WildLoadersPlugin;
import com.bgsoftware.wildloaders.api.hooks.ClaimsProvider; import com.bgsoftware.wildloaders.api.hooks.ClaimsProvider;
import com.bgsoftware.wildloaders.api.hooks.TickableProvider; import com.bgsoftware.wildloaders.api.hooks.TickableProvider;
import com.bgsoftware.wildloaders.api.managers.ProvidersManager; import com.bgsoftware.wildloaders.api.managers.ProvidersManager;
import com.bgsoftware.wildloaders.hooks.ClaimsProvider_FactionsUUID; import com.bgsoftware.wildloaders.hooks.ClaimsProvider_FactionsUUID;
import com.bgsoftware.wildloaders.hooks.ClaimsProvider_FactionsX; import com.bgsoftware.wildloaders.hooks.ClaimsProvider_FactionsX;
import com.bgsoftware.wildloaders.hooks.ClaimsProvider_MassiveFactions;
import com.bgsoftware.wildloaders.hooks.ClaimsProvider_SuperiorSkyblock; import com.bgsoftware.wildloaders.hooks.ClaimsProvider_SuperiorSkyblock;
import com.bgsoftware.wildloaders.hooks.TickableProvider_EpicSpawners; import com.bgsoftware.wildloaders.hooks.TickableProvider_EpicSpawners;
import com.bgsoftware.wildloaders.utils.threads.Executor; import com.bgsoftware.wildloaders.utils.threads.Executor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
public final class ProvidersHandler implements ProvidersManager { public final class ProvidersHandler implements ProvidersManager {
private final WildLoadersPlugin plugin;
private final List<ClaimsProvider> claimsProviders = new ArrayList<>(); private final List<ClaimsProvider> claimsProviders = new ArrayList<>();
private final List<TickableProvider> tickableProviders = new ArrayList<>(); private final List<TickableProvider> tickableProviders = new ArrayList<>();
public ProvidersHandler(){ public ProvidersHandler(WildLoadersPlugin plugin) {
this.plugin = plugin;
Executor.sync(() -> { Executor.sync(() -> {
loadClaimsProviders();
loadTickableProviders();
});
}
private void loadClaimsProviders() {
// Loading the claim providers // Loading the claim providers
if (Bukkit.getPluginManager().isPluginEnabled("Factions")) { if (Bukkit.getPluginManager().isPluginEnabled("Factions")) {
if(Bukkit.getPluginManager().getPlugin("Factions").getDescription().getAuthors().contains("drtshock")) if (Bukkit.getPluginManager().getPlugin("Factions").getDescription().getAuthors().contains("drtshock")) {
addClaimsProvider(new ClaimsProvider_FactionsUUID()); addClaimsProvider(new ClaimsProvider_FactionsUUID());
else }
addClaimsProvider(new ClaimsProvider_MassiveFactions()); else {
Optional<ClaimsProvider> claimsProvider = createInstance("ClaimsProvider_MassiveFactions");
claimsProvider.ifPresent(this::addClaimsProvider);
}
} }
if (Bukkit.getPluginManager().isPluginEnabled("FactionsX")) { if (Bukkit.getPluginManager().isPluginEnabled("FactionsX")) {
addClaimsProvider(new ClaimsProvider_FactionsX()); addClaimsProvider(new ClaimsProvider_FactionsX());
@ -36,12 +51,13 @@ public final class ProvidersHandler implements ProvidersManager {
if (Bukkit.getPluginManager().isPluginEnabled("SuperiorSkyblock2")) { if (Bukkit.getPluginManager().isPluginEnabled("SuperiorSkyblock2")) {
addClaimsProvider(new ClaimsProvider_SuperiorSkyblock()); addClaimsProvider(new ClaimsProvider_SuperiorSkyblock());
} }
}
private void loadTickableProviders() {
// Loading the tickable providers // Loading the tickable providers
if (Bukkit.getPluginManager().isPluginEnabled("EpicSpawners")) { if (Bukkit.getPluginManager().isPluginEnabled("EpicSpawners")) {
addTickableProvider(new TickableProvider_EpicSpawners()); addTickableProvider(new TickableProvider_EpicSpawners());
} }
});
} }
@Override @Override
@ -67,4 +83,30 @@ public final class ProvidersHandler implements ProvidersManager {
tickableProviders.forEach(tickableProvider -> tickableProvider.tick(chunks)); tickableProviders.forEach(tickableProvider -> tickableProvider.tick(chunks));
} }
private <T> Optional<T> createInstance(String className) {
try {
Class<?> clazz = Class.forName("com.bgsoftware.superiorskyblock.hooks.provider." + className);
try {
Method compatibleMethod = clazz.getDeclaredMethod("isCompatible");
if (!(boolean) compatibleMethod.invoke(null))
return Optional.empty();
} catch (Exception ignored) {
}
try {
Constructor<?> constructor = clazz.getConstructor(WildLoadersPlugin.class);
// noinspection unchecked
return Optional.of((T) constructor.newInstance(plugin));
} catch (Exception error) {
// noinspection unchecked
return Optional.of((T) clazz.newInstance());
}
} catch (ClassNotFoundException ignored) {
return Optional.empty();
} catch (Exception error) {
error.printStackTrace();
return Optional.empty();
}
}
} }