Skip to content

Commit 726c378

Browse files
committed
Don't try and 'combine' CombatTagPlugins
Manually register default implementations
1 parent 6bb5188 commit 726c378

File tree

3 files changed

+12
-142
lines changed

3 files changed

+12
-142
lines changed

base/pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@
2020
<version>2.3.1-SNAPSHOT</version>
2121
<scope>compile</scope>
2222
</dependency>
23-
<!-- Classpath Scanning -->
24-
<dependency>
25-
<groupId>org.reflections</groupId>
26-
<artifactId>reflections</artifactId>
27-
<version>0.9.10</version>
28-
<scope>compile</scope>
29-
</dependency>
3023
<!-- Compatibility -->
3124
<dependency>
3225
<groupId>net.techcable.spawnshield</groupId>

base/src/main/java/net/techcable/spawnshield/SpawnShield.java

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
import com.google.common.collect.ImmutableList;
3838

3939
import net.techcable.spawnshield.combattag.CombatTagPlugin;
40-
import net.techcable.spawnshield.combattag.MultiPluginCombatTagPlugin;
40+
import net.techcable.spawnshield.combattag.legacy.CombatTagLegacySupport;
41+
import net.techcable.spawnshield.combattag.plus.CombatTagPlusSupport;
42+
import net.techcable.spawnshield.combattag.pvpmanager.PvPManagerSupport;
4143
import net.techcable.spawnshield.compat.worldguard6.WorldGuard6Plugin;
4244
import net.techcable.spawnshield.config.SpawnShieldConfig;
4345
import net.techcable.spawnshield.config.SpawnShieldMessages;
@@ -51,7 +53,6 @@
5153
import org.bukkit.plugin.RegisteredServiceProvider;
5254
import org.bukkit.plugin.ServicePriority;
5355
import org.bukkit.plugin.java.JavaPlugin;
54-
import org.reflections.Reflections;
5556

5657
@Getter
5758
public class SpawnShield extends TechPlugin<SpawnShieldPlayer> {
@@ -111,7 +112,7 @@ public int getValue() {
111112
}
112113
});
113114
Metrics.Graph pluginGraph = metrics.createGraph("Combat Plugin");
114-
for (CombatTagPlugin plugin : getCombatTagPlugins()) { // Get all plugins, even uninstalled ones
115+
for (CombatTagPlugin plugin : getCombatTagPlugins()) {
115116
pluginGraph.addPlotter(new Metrics.Plotter(plugin.getPlugin().getName()) {
116117
@Override
117118
public int getValue() {
@@ -164,41 +165,19 @@ public int getValue() {
164165
}
165166

166167
public CombatTagPlugin getCombatTagPlugin() {
167-
ImmutableList<CombatTagPlugin> plugins = getCombatTagPlugins();
168-
switch (plugins.size()) {
169-
case 0:
170-
throw new IllegalStateException("No CombatTagPlugin installed!");
171-
case 1:
172-
return plugins.get(0);
173-
default:
174-
return new MultiPluginCombatTagPlugin(plugins);
175-
}
168+
return getServer().getServicesManager().getRegistrations(CombatTagPlugin.class).stream()
169+
.filter((combatService) -> combatService.getProvider().isInstalled()) // Only consider installed plugins :)
170+
.max((first, second) -> first.getPriority().compareTo(second.getPriority())) // Get the highest priortiy service
171+
.map(RegisteredServiceProvider::getProvider)
172+
.orElseThrow(() -> new IllegalStateException("No CombatTagPlugin installed!"));
176173
}
177174

178175

179176
public ImmutableList<CombatTagPlugin> getCombatTagPlugins() {
180177
if (getServer().getServicesManager().getRegistrations(this).isEmpty()) {
181-
// Search classpath for our own impls
182-
String className = CombatTagPlugin.class.getName();
183-
String packageName = className.substring(0, className.lastIndexOf('.') - 1);
184-
Set<Class<? extends CombatTagPlugin>> pluginTypes = new Reflections(packageName).getSubTypesOf(CombatTagPlugin.class);
185-
for (Class<? extends CombatTagPlugin> pluginType : pluginTypes) {
186-
if (pluginType == MultiPluginCombatTagPlugin.class) continue;
187-
CombatTagPlugin plugin;
188-
try {
189-
Constructor<? extends CombatTagPlugin> c = pluginType.getConstructor();
190-
c.setAccessible(true);
191-
plugin = c.newInstance();
192-
} catch (NoSuchMethodException | InstantiationException e) {
193-
continue;
194-
} catch (IllegalAccessException e) {
195-
throw new RuntimeException("Unable to call setAccessible() on " + pluginType.getSimpleName());
196-
} catch (InvocationTargetException e) {
197-
Throwable cause = e.getTargetException();
198-
throw new RuntimeException("new " + pluginType.getSimpleName() + "() threw an exception", cause);
199-
}
200-
getServer().getServicesManager().register(CombatTagPlugin.class, plugin, this, ServicePriority.Normal);
201-
}
178+
getServer().getServicesManager().register(CombatTagPlugin.class, new CombatTagLegacySupport(), this, ServicePriority.Low);
179+
getServer().getServicesManager().register(CombatTagPlugin.class, new PvPManagerSupport(), this, ServicePriority.Normal);
180+
getServer().getServicesManager().register(CombatTagPlugin.class, new CombatTagPlusSupport(), this, ServicePriority.Normal);
202181
}
203182
return getServer().getServicesManager().getRegistrations(CombatTagPlugin.class).stream()
204183
.map(RegisteredServiceProvider::getProvider)

base/src/main/java/net/techcable/spawnshield/combattag/MultiPluginCombatTagPlugin.java

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)