Skip to content

Commit

Permalink
Merge pull request #38 from MCCasper/master
Browse files Browse the repository at this point in the history
relocation changes + deluxe sell wand support
  • Loading branch information
Chasewhip8 authored Feb 2, 2024
2 parents 8c796e4 + 47c3fd9 commit b2c1e68
Show file tree
Hide file tree
Showing 18 changed files with 278 additions and 72 deletions.
15 changes: 11 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ dependencies {
compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")

// Adventure
implementation("net.kyori:adventure-api:4.15.0")
compileOnly("net.kyori:adventure-api:4.15.0")
implementation("net.kyori:adventure-platform-bukkit:4.3.2")
implementation("net.kyori:adventure-text-minimessage:4.15.0")
compileOnly("net.kyori:adventure-text-minimessage:4.15.0")

// Other
implementation("co.aikar:taskchain-bukkit:3.7.2")
Expand All @@ -50,6 +50,7 @@ dependencies {
implementation("co.aikar:idb-core:1.0.0-SNAPSHOT")
implementation("com.zaxxer:HikariCP:5.1.0")
implementation("com.github.retrooper.packetevents:spigot:2.2.0")
compileOnly("com.github.N0RSKA:DeluxeSellwandsAPI:32c")
compileOnly("com.ghostchu:quickshop-api:5.2.0.8")
compileOnly("com.google.guava:guava:33.0.0-jre")
compileOnly("net.milkbowl.vault:VaultAPI:1.7")
Expand All @@ -71,16 +72,22 @@ dependencies {
tasks {
shadowJar {
archiveFileName.set("${rootProject.name}.jar")

// for some reason cache2k does not like being relocated, likely due to generative class loading & relocation not playing nice
relocate("co.aikar.locales", "net.crashcraft.crashclaim.aikarlocales")
relocate("co.aikar.commands", "net.crashcraft.crashclaim.acf")
relocate("co.aikar.idb", "net.crashcraft.crashclaim.idb")
relocate("co.aikar.taskchain", "net.crashcraft.crashclaim.taskchain")
relocate("io.papermc.lib", "net.crashcraft.crashclaim.paperlib")
relocate("it.unimi.dsi", "net.crashcraft.crashclaim.fastutil")
relocate("org.cache2k.IntCache", "net.crashcraft.crashclaim.cache2k")
relocate("com.zaxxer.hikari", "net.crashcraft.crashclaim.hikari")
relocate("com.github.retrooper.packetevents", "net.crashcraft.crashclaim.packetevents.api")
relocate("io.github.retrooper.packetevents", "net.crashcraft.crashclaim.packetevents.impl")
relocate("net.wesjd", "net.crashcraft.crashclaim.anvilgui")

exclude("/com/google/gson/**")
exclude("/org/intellij/**")
exclude("/org/jetbrains/**")
exclude("/org/slf4j/**")
}

build {
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/net/crashcraft/crashclaim/CrashClaim.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void onLoad() {

this.crashUtils = new CrashUtils(this);
this.pluginSupport = new PluginSupportManager(this); // Enable plugin support
this.pluginSupport.onLoad(); // Load all plugin support
}

@Override
Expand Down Expand Up @@ -114,7 +115,6 @@ public void onEnable() {
PacketListenerPriority.LOW);
PacketEvents.getAPI().init();


if (PaperLib.isPaper()) {
getLogger().info("Using extra protections provided by the paper api");
Bukkit.getPluginManager().registerEvents(new PaperListener(manager, visualizationManager), this);
Expand Down Expand Up @@ -266,8 +266,7 @@ public PluginSupport getPluginSupport(){
return pluginSupport.getSupportDistributor();
}

public PluginSupportManager getPluginSupportManager(){
public PluginSupportManager getPluginSupportManager() {
return pluginSupport;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.crashcraft.crashclaim.menus.list.ClaimListMenu;
import net.crashcraft.crashclaim.permissions.PermissionHelper;
import net.crashcraft.crashclaim.pluginsupport.PluginSupport;
import net.crashcraft.crashclaim.pluginsupport.PluginSupportLoader;
import org.bukkit.Location;
import org.bukkit.entity.Player;

Expand Down Expand Up @@ -166,6 +167,10 @@ public PermissionHelper getPermissionHelper(){
return PermissionHelper.getPermissionHelper();
}

public void registerHook(PluginSupportLoader pluginSupportLoader){
crashClaim.getPluginSupportManager().register(pluginSupportLoader);
}

public void registerHook(PluginSupport pluginSupport){
crashClaim.getPluginSupportManager().register(pluginSupport);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static <T> List<T> getServices(Class<T> clazz, List<T> def) {
final List<T> services = new ArrayList<>();
ServiceLoader.load(clazz).iterator().forEachRemaining(services::add);
if (services.isEmpty()) {
services.addAll(def);
return def;
}
return services;
}
Expand All @@ -46,7 +46,7 @@ public static <T> List<T> getServices(Class<T> clazz, ClassLoader loader, List<T
final List<T> services = new ArrayList<>();
ServiceLoader.load(clazz, loader).iterator().forEachRemaining(services::add);
if (services.isEmpty()) {
services.addAll(def);
return def;
}
return services;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import net.kyori.adventure.text.serializer.craftbukkit.BukkitComponentSerializer;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.chat.ComponentSerializer;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.enchantments.Enchantment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.bukkit.plugin.Plugin;

public interface PluginSupport {
boolean isUnSupportedVersion(String version);
boolean isUnsupportedVersion(String version);

boolean canLoad();

Expand All @@ -26,5 +26,7 @@ default boolean canInteract(Player player, Location location) {
return true;
}

GroupSettings getPlayerGroupSettings(Player player);
default GroupSettings getPlayerGroupSettings(Player player) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

import java.util.List;
import java.util.Set;

public class PluginSupportDistributor implements PluginSupport {
Expand All @@ -17,7 +16,7 @@ public PluginSupportDistributor(PluginSupportManager manager){
}

@Override
public boolean isUnSupportedVersion(String version) {
public boolean isUnsupportedVersion(String version) {
throw new RuntimeException("Unsupported Operation.");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package net.crashcraft.crashclaim.pluginsupport;

import org.bukkit.plugin.Plugin;

public interface PluginSupportLoader {
boolean isUnsupportedVersion(String version);

boolean canLoad();

String getPluginName();

void load(Plugin plugin);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ public PluginSupportManager(CrashClaim crashClaim) {
allSupport = new ArrayList<>();
enabledSupport = new HashSet<>();

for (PluginSupport service : ServiceUtil.getServices(PluginSupport.class)) {
supportDistributor = new PluginSupportDistributor(this);
}

public void onLoad() {
List<PluginSupportLoader> services = ServiceUtil.getServices(PluginSupportLoader.class, crashClaim.getClass().getClassLoader());

logger.info("Found " + services.size() + " plugin support services.");
for (PluginSupportLoader service : services) {
register(service);
}

supportDistributor = new PluginSupportDistributor(this);
}

public void onEnable(){
Expand All @@ -50,6 +55,23 @@ public void onDisable(){
enabledSupport.clear();
}

public void register(PluginSupportLoader pluginSupportLoader){
if (!pluginSupportLoader.canLoad()) {
logger.warning("Plugin support for " + pluginSupportLoader.getPluginName() + " is not enabled.");
return;
}

Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginSupportLoader.getPluginName());
String version = plugin.getDescription().getVersion();

if (pluginSupportLoader.isUnsupportedVersion(version)) {
logger.warning("Plugin [" + pluginSupportLoader.getPluginName() + "] was found but version " + version + ", is not supported.");
return;
}

pluginSupportLoader.load(plugin);
}

public void register(PluginSupport pluginSupport){
if (allSupport.contains(pluginSupport)) {
logger.warning("Plugin support for " + pluginSupport.getPluginName() + " is already registered.");
Expand All @@ -59,13 +81,14 @@ public void register(PluginSupport pluginSupport){
allSupport.add(pluginSupport);

if (!pluginSupport.canLoad()) {
logger.warning("Not enabling plugin support for " + pluginSupport.getPluginName() + ", plugin is not enabled.");
return;
}

Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginSupport.getPluginName());
String version = plugin.getDescription().getVersion();

if (pluginSupport.isUnSupportedVersion(version)) {
if (pluginSupport.isUnsupportedVersion(version)) {
logger.warning("Plugin [" + pluginSupport.getPluginName() + "] was found but version " + version + ", is not supported.");
return;
}
Expand Down Expand Up @@ -95,7 +118,7 @@ public void onPluginEnable(PluginEnableEvent event) {

String version = plugin.getDescription().getVersion();

if (service.isUnSupportedVersion(version)) {
if (service.isUnsupportedVersion(version)) {
logger.warning("Plugin [" + service.getPluginName() + "] was found but version " + version + ", is not supported.");
continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package net.crashcraft.crashclaim.pluginsupport.loader;

import com.google.auto.service.AutoService;
import net.crashcraft.crashclaim.CrashClaim;
import net.crashcraft.crashclaim.pluginsupport.PluginSupportLoader;
import net.crashcraft.crashclaim.pluginsupport.plugins.DeluxeSellwandSupport;
import net.crashcraft.crashclaim.pluginsupport.plugins.LuckPermsSupport;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;

@AutoService(PluginSupportLoader.class)
public class DeluxeSellwandSupportLoader implements PluginSupportLoader {

@Override
public boolean isUnsupportedVersion(String version) {
return false;
}

@Override
public boolean canLoad() {
return Bukkit.getPluginManager().getPlugin(getPluginName()) != null;
}

@Override
public String getPluginName() {
return "DeluxeSellwands";
}

@Override
public void load(Plugin plugin) {
CrashClaim.getPlugin().getPluginSupportManager().register(new DeluxeSellwandSupport());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package net.crashcraft.crashclaim.pluginsupport.loader;

import com.google.auto.service.AutoService;
import net.crashcraft.crashclaim.CrashClaim;
import net.crashcraft.crashclaim.pluginsupport.PluginSupportLoader;
import net.crashcraft.crashclaim.pluginsupport.plugins.LuckPermsSupport;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;

@AutoService(PluginSupportLoader.class)
public class LuckPermSupportLoader implements PluginSupportLoader {

@Override
public boolean isUnsupportedVersion(String version) {
return false;
}

@Override
public boolean canLoad() {
return Bukkit.getPluginManager().getPlugin(getPluginName()) != null;
}

@Override
public String getPluginName() {
return "LuckPerms";
}

@Override
public void load(Plugin plugin) {
CrashClaim.getPlugin().getPluginSupportManager().register(new LuckPermsSupport());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.crashcraft.crashclaim.pluginsupport.loader;

import com.google.auto.service.AutoService;
import net.crashcraft.crashclaim.CrashClaim;
import net.crashcraft.crashclaim.pluginsupport.PluginSupportLoader;
import net.crashcraft.crashclaim.pluginsupport.plugins.QuickShopHikariSupport;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;

@AutoService(PluginSupportLoader.class)
public class QuickShopHikariSupportLoader implements PluginSupportLoader {
@Override
public boolean isUnsupportedVersion(String version) {
return false;
}

@Override
public boolean canLoad() {
return Bukkit.getPluginManager().getPlugin(getPluginName()) != null;
}

@Override
public String getPluginName() {
return "QuickShop-Hikari";
}

@Override
public void load(Plugin plugin) {
CrashClaim.getPlugin().getPluginSupportManager().register(new QuickShopHikariSupport());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.crashcraft.crashclaim.pluginsupport.loader;

import com.google.auto.service.AutoService;
import net.crashcraft.crashclaim.CrashClaim;
import net.crashcraft.crashclaim.pluginsupport.PluginSupportLoader;
import net.crashcraft.crashclaim.pluginsupport.plugins.WorldGuardSupport;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;

@AutoService(PluginSupportLoader.class)
public class WorldGuardSupportLoader implements PluginSupportLoader {
@Override
public boolean isUnsupportedVersion(String version) {
return (int) version.charAt(0) < 7;
}

@Override
public boolean canLoad() {
return Bukkit.getPluginManager().getPlugin(getPluginName()) != null;
}

@Override
public String getPluginName() {
return "WorldGuard";
}

@Override
public void load(Plugin plugin) {
CrashClaim.getPlugin().getPluginSupportManager().register(new WorldGuardSupport());
}
}
Loading

0 comments on commit b2c1e68

Please sign in to comment.