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

View File

@ -16,4 +16,5 @@ include 'v1_15_R1'
include 'v1_16_R3'
include 'v1_17_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);
loadersHandler = new LoadersHandler(this);
npcHandler = new NPCHandler(this);
providersHandler = new ProvidersHandler();
providersHandler = new ProvidersHandler(this);
settingsHandler = new SettingsHandler(this);
getServer().getPluginManager().registerEvents(new BlocksListener(this), this);

View File

@ -1,49 +1,65 @@
package com.bgsoftware.wildloaders.handlers;
import com.bgsoftware.wildloaders.WildLoadersPlugin;
import com.bgsoftware.wildloaders.api.hooks.ClaimsProvider;
import com.bgsoftware.wildloaders.api.hooks.TickableProvider;
import com.bgsoftware.wildloaders.api.managers.ProvidersManager;
import com.bgsoftware.wildloaders.hooks.ClaimsProvider_FactionsUUID;
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.TickableProvider_EpicSpawners;
import com.bgsoftware.wildloaders.utils.threads.Executor;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
public final class ProvidersHandler implements ProvidersManager {
private final WildLoadersPlugin plugin;
private final List<ClaimsProvider> claimsProviders = new ArrayList<>();
private final List<TickableProvider> tickableProviders = new ArrayList<>();
public ProvidersHandler(){
public ProvidersHandler(WildLoadersPlugin plugin) {
this.plugin = plugin;
Executor.sync(() -> {
// Loading the claim providers
if(Bukkit.getPluginManager().isPluginEnabled("Factions")){
if(Bukkit.getPluginManager().getPlugin("Factions").getDescription().getAuthors().contains("drtshock"))
addClaimsProvider(new ClaimsProvider_FactionsUUID());
else
addClaimsProvider(new ClaimsProvider_MassiveFactions());
}
if(Bukkit.getPluginManager().isPluginEnabled("FactionsX")){
addClaimsProvider(new ClaimsProvider_FactionsX());
}
if(Bukkit.getPluginManager().isPluginEnabled("SuperiorSkyblock2")){
addClaimsProvider(new ClaimsProvider_SuperiorSkyblock());
}
// Loading the tickable providers
if(Bukkit.getPluginManager().isPluginEnabled("EpicSpawners")){
addTickableProvider(new TickableProvider_EpicSpawners());
}
loadClaimsProviders();
loadTickableProviders();
});
}
private void loadClaimsProviders() {
// Loading the claim providers
if (Bukkit.getPluginManager().isPluginEnabled("Factions")) {
if (Bukkit.getPluginManager().getPlugin("Factions").getDescription().getAuthors().contains("drtshock")) {
addClaimsProvider(new ClaimsProvider_FactionsUUID());
}
else {
Optional<ClaimsProvider> claimsProvider = createInstance("ClaimsProvider_MassiveFactions");
claimsProvider.ifPresent(this::addClaimsProvider);
}
}
if (Bukkit.getPluginManager().isPluginEnabled("FactionsX")) {
addClaimsProvider(new ClaimsProvider_FactionsX());
}
if (Bukkit.getPluginManager().isPluginEnabled("SuperiorSkyblock2")) {
addClaimsProvider(new ClaimsProvider_SuperiorSkyblock());
}
}
private void loadTickableProviders() {
// Loading the tickable providers
if (Bukkit.getPluginManager().isPluginEnabled("EpicSpawners")) {
addTickableProvider(new TickableProvider_EpicSpawners());
}
}
@Override
public void addClaimsProvider(ClaimsProvider claimsProvider) {
claimsProviders.add(claimsProvider);
@ -54,8 +70,8 @@ public final class ProvidersHandler implements ProvidersManager {
tickableProviders.add(tickableProvider);
}
public boolean hasChunkAccess(UUID player, Chunk chunk){
for(ClaimsProvider claimsProvider : claimsProviders) {
public boolean hasChunkAccess(UUID player, Chunk chunk) {
for (ClaimsProvider claimsProvider : claimsProviders) {
if (claimsProvider.hasClaimAccess(player, chunk))
return true;
}
@ -63,8 +79,34 @@ public final class ProvidersHandler implements ProvidersManager {
return false;
}
public void tick(Chunk[] chunks){
public void tick(Chunk[] 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();
}
}
}