diff --git a/base/pom.xml b/base/pom.xml
index abbc5fe..aebffb1 100755
--- a/base/pom.xml
+++ b/base/pom.xml
@@ -20,13 +20,6 @@
2.3.1-SNAPSHOT
compile
-
-
- org.reflections
- reflections
- 0.9.10
- compile
-
net.techcable.spawnshield
diff --git a/base/src/main/java/net/techcable/spawnshield/SpawnShield.java b/base/src/main/java/net/techcable/spawnshield/SpawnShield.java
index f6767cc..67d2b5d 100755
--- a/base/src/main/java/net/techcable/spawnshield/SpawnShield.java
+++ b/base/src/main/java/net/techcable/spawnshield/SpawnShield.java
@@ -37,7 +37,9 @@
import com.google.common.collect.ImmutableList;
import net.techcable.spawnshield.combattag.CombatTagPlugin;
-import net.techcable.spawnshield.combattag.MultiPluginCombatTagPlugin;
+import net.techcable.spawnshield.combattag.legacy.CombatTagLegacySupport;
+import net.techcable.spawnshield.combattag.plus.CombatTagPlusSupport;
+import net.techcable.spawnshield.combattag.pvpmanager.PvPManagerSupport;
import net.techcable.spawnshield.compat.worldguard6.WorldGuard6Plugin;
import net.techcable.spawnshield.config.SpawnShieldConfig;
import net.techcable.spawnshield.config.SpawnShieldMessages;
@@ -51,7 +53,6 @@
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin;
-import org.reflections.Reflections;
@Getter
public class SpawnShield extends TechPlugin {
@@ -111,7 +112,7 @@ public int getValue() {
}
});
Metrics.Graph pluginGraph = metrics.createGraph("Combat Plugin");
- for (CombatTagPlugin plugin : getCombatTagPlugins()) { // Get all plugins, even uninstalled ones
+ for (CombatTagPlugin plugin : getCombatTagPlugins()) {
pluginGraph.addPlotter(new Metrics.Plotter(plugin.getPlugin().getName()) {
@Override
public int getValue() {
@@ -164,41 +165,19 @@ public int getValue() {
}
public CombatTagPlugin getCombatTagPlugin() {
- ImmutableList plugins = getCombatTagPlugins();
- switch (plugins.size()) {
- case 0:
- throw new IllegalStateException("No CombatTagPlugin installed!");
- case 1:
- return plugins.get(0);
- default:
- return new MultiPluginCombatTagPlugin(plugins);
- }
+ return getServer().getServicesManager().getRegistrations(CombatTagPlugin.class).stream()
+ .filter((combatService) -> combatService.getProvider().isInstalled()) // Only consider installed plugins :)
+ .max((first, second) -> first.getPriority().compareTo(second.getPriority())) // Get the highest priortiy service
+ .map(RegisteredServiceProvider::getProvider)
+ .orElseThrow(() -> new IllegalStateException("No CombatTagPlugin installed!"));
}
public ImmutableList getCombatTagPlugins() {
if (getServer().getServicesManager().getRegistrations(this).isEmpty()) {
- // Search classpath for our own impls
- String className = CombatTagPlugin.class.getName();
- String packageName = className.substring(0, className.lastIndexOf('.') - 1);
- Set> pluginTypes = new Reflections(packageName).getSubTypesOf(CombatTagPlugin.class);
- for (Class extends CombatTagPlugin> pluginType : pluginTypes) {
- if (pluginType == MultiPluginCombatTagPlugin.class) continue;
- CombatTagPlugin plugin;
- try {
- Constructor extends CombatTagPlugin> c = pluginType.getConstructor();
- c.setAccessible(true);
- plugin = c.newInstance();
- } catch (NoSuchMethodException | InstantiationException e) {
- continue;
- } catch (IllegalAccessException e) {
- throw new RuntimeException("Unable to call setAccessible() on " + pluginType.getSimpleName());
- } catch (InvocationTargetException e) {
- Throwable cause = e.getTargetException();
- throw new RuntimeException("new " + pluginType.getSimpleName() + "() threw an exception", cause);
- }
- getServer().getServicesManager().register(CombatTagPlugin.class, plugin, this, ServicePriority.Normal);
- }
+ getServer().getServicesManager().register(CombatTagPlugin.class, new CombatTagLegacySupport(), this, ServicePriority.Low);
+ getServer().getServicesManager().register(CombatTagPlugin.class, new PvPManagerSupport(), this, ServicePriority.Normal);
+ getServer().getServicesManager().register(CombatTagPlugin.class, new CombatTagPlusSupport(), this, ServicePriority.Normal);
}
return getServer().getServicesManager().getRegistrations(CombatTagPlugin.class).stream()
.map(RegisteredServiceProvider::getProvider)
diff --git a/base/src/main/java/net/techcable/spawnshield/combattag/MultiPluginCombatTagPlugin.java b/base/src/main/java/net/techcable/spawnshield/combattag/MultiPluginCombatTagPlugin.java
deleted file mode 100644
index 1d37738..0000000
--- a/base/src/main/java/net/techcable/spawnshield/combattag/MultiPluginCombatTagPlugin.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/**
- * The MIT License
- * Copyright (c) 2015 Techcable
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package net.techcable.spawnshield.combattag;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Sets;
-import lombok.RequiredArgsConstructor;
-import org.bukkit.entity.Entity;
-import org.bukkit.entity.Player;
-import org.bukkit.plugin.Plugin;
-import org.reflections.ReflectionUtils;
-import org.reflections.Reflections;
-
-import javax.annotation.Nullable;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.HashSet;
-import java.util.Set;
-
-@RequiredArgsConstructor
-public final class MultiPluginCombatTagPlugin implements CombatTagPlugin {
- private final ImmutableList plugins;
-
- @Override
- public boolean isTagged(Player player) {
- assertPluginsFound();
- for (CombatTagPlugin plugin : plugins) {
- if (plugin.isTagged(player)) return true;
- }
- return false;
- }
-
- @Override
- public long getRemainingTagTime(Player player) {
- long max = -1;
- for (CombatTagPlugin plugin : plugins) {
- long time = plugin.getRemainingTagTime(player);
- max = Math.max(max, time);
- }
- return max;
- }
-
- @Override
- public boolean isNPC(Entity entity) {
- assertPluginsFound();
- for (CombatTagPlugin plugin : plugins) {
- if (plugin.isNPC(entity)) return true;
- }
- return false;
- }
-
- @Override
- public void tag(Player player) {
- assertPluginsFound();
- for (CombatTagPlugin plugin : plugins) {
- plugin.tag(player);
- }
- }
-
- @Override
- public void unTag(Player player) {
- assertPluginsFound();
- for (CombatTagPlugin plugin : plugins) {
- plugin.unTag(player);
- }
- }
-
- @Override
- public boolean isInstalled() {
- return plugins.size() > 0;
- }
-
- @Override
- public Plugin getPlugin() {
- throw new UnsupportedOperationException();
- }
-
- private void assertPluginsFound() {
- if (plugins.size() < 1) throw new UnsupportedOperationException("No supported combat tagging plugins found");
- }
-}