Skip to content

Commit d662199

Browse files
committed
Track combat tag plugin with metrics
I'm watching you!!!!
1 parent 95588b2 commit d662199

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

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

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
22
* The MIT License
33
* Copyright (c) 2015 Techcable
4-
*
4+
* <p>
55
* Permission is hereby granted, free of charge, to any person obtaining a copy
66
* of this software and associated documentation files (the "Software"), to deal
77
* in the Software without restriction, including without limitation the rights
88
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
* copies of the Software, and to permit persons to whom the Software is
1010
* furnished to do so, subject to the following conditions:
11-
*
11+
* <p>
1212
* The above copyright notice and this permission notice shall be included in
1313
* all copies or substantial portions of the Software.
14-
*
14+
* <p>
1515
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -27,10 +27,12 @@
2727
import java.io.IOException;
2828
import java.lang.reflect.Constructor;
2929
import java.lang.reflect.InvocationTargetException;
30+
import java.util.List;
3031
import java.util.Set;
3132
import java.util.UUID;
3233
import java.util.logging.Level;
3334
import java.util.stream.Collector;
35+
import java.util.stream.Collectors;
3436

3537
import com.google.common.collect.ImmutableList;
3638

@@ -77,7 +79,8 @@ protected void startup() {
7779
Plugin providingPlugin = JavaPlugin.getProvidingPlugin(plugin.getClass());
7880
getLogger().info(i + ") " + plugin.getPlugin().getName());
7981
if (providingPlugin != plugin.getPlugin()) {
80-
getLogger().info("\t- this is provided by " + providingPlugin.getName() + " not implemented in " + plugin.getPlugin().getName() + " itself");;
82+
getLogger().info("\t- this is provided by " + providingPlugin.getName() + " not implemented in " + plugin.getPlugin().getName() + " itself");
83+
;
8184
getLogger().info("\t- therefore report bugs with the integration to " + Utils.getAuthors(providingPlugin) + ", not to " + Utils.getAuthors(plugin.getPlugin()));
8285
}
8386
}
@@ -104,9 +107,18 @@ public int getValue() {
104107
mode.addPlotter(new Metrics.Plotter("Teleport") {
105108
@Override
106109
public int getValue() {
107-
return getSettings().getMode() == BlockMode.KNOCKBACK ? 1 : 0;
110+
return getSettings().getMode() == BlockMode.TELEPORT ? 1 : 0;
108111
}
109112
});
113+
Metrics.Graph pluginGraph = metrics.createGraph("Combat Plugin");
114+
for (CombatTagPlugin plugin : getCombatTagPlugins()) { // Get all plugins, even uninstalled ones
115+
pluginGraph.addPlotter(new Metrics.Plotter(plugin.getPlugin().getName()) {
116+
@Override
117+
public int getValue() {
118+
return 1;
119+
}
120+
});
121+
}
110122
metrics.start();
111123
} catch (IOException e) {
112124
getLogger().warning("Unable to run metrics");
@@ -132,19 +144,19 @@ public int getValue() {
132144
}
133145
getCommand("spawnshield").setExecutor(new SpawnShieldExecutor(this));
134146
switch (settings.getMode()) {
135-
case FORCEFIELD :
147+
case FORCEFIELD:
136148
this.forceFieldListener = new ForceFieldListener(this);
137149
registerListener(forceFieldListener);
138150
break;
139-
case TELEPORT :
151+
case TELEPORT:
140152
teleportSafezoningTask = new TeleportSafezoningTask(this);
141153
teleportSafezoningTask.runTaskTimer(this, 5, 5); //Every 1/4 of a tick
142154
break;
143-
case KNOCKBACK :
155+
case KNOCKBACK:
144156
knockbackTask = new KnockbackTask(this);
145157
knockbackTask.runTaskTimer(this, 5, 5); //Every 1/4 of a tick
146158
break;
147-
default :
159+
default:
148160
getLogger().severe("[SpawnShield] Unknown Plugin Mode");
149161
setEnabled(false);
150162
return;
@@ -191,12 +203,7 @@ public ImmutableList<CombatTagPlugin> getCombatTagPlugins() {
191203
return getServer().getServicesManager().getRegistrations(CombatTagPlugin.class).stream()
192204
.map(RegisteredServiceProvider::getProvider)
193205
.filter(CombatTagPlugin::isInstalled) // Only return installed plugins :)
194-
.collect(Collector.<CombatTagPlugin, ImmutableList.Builder<CombatTagPlugin>, ImmutableList<CombatTagPlugin>>of(
195-
ImmutableList::builder,
196-
ImmutableList.Builder::add,
197-
(builder1, builder2) -> builder1.addAll(builder2.build()),
198-
ImmutableList.Builder::build
199-
));
206+
.collect(Utils.immutableListCollector());
200207
}
201208

202209
@Override

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
22
* The MIT License
33
* Copyright (c) 2015 Techcable
4-
*
4+
* <p>
55
* Permission is hereby granted, free of charge, to any person obtaining a copy
66
* of this software and associated documentation files (the "Software"), to deal
77
* in the Software without restriction, including without limitation the rights
88
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
* copies of the Software, and to permit persons to whom the Software is
1010
* furnished to do so, subject to the following conditions:
11-
*
11+
* <p>
1212
* The above copyright notice and this permission notice shall be included in
1313
* all copies or substantial portions of the Software.
14-
*
14+
* <p>
1515
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -29,13 +29,25 @@
2929
import lombok.NoArgsConstructor;
3030

3131
import java.util.List;
32+
import java.util.stream.Collector;
33+
34+
import net.techcable.spawnshield.combattag.CombatTagPlugin;
3235

3336
import org.bukkit.Bukkit;
3437
import org.bukkit.plugin.Plugin;
3538

3639
@NoArgsConstructor(access = AccessLevel.PRIVATE)
3740
public class Utils {
3841

42+
public static <T> Collector<T, ?, ImmutableList<T>> immutableListCollector() {
43+
return Collector.<T, ImmutableList.Builder<T>, ImmutableList<T>>of(
44+
ImmutableList::builder,
45+
ImmutableList.Builder::add,
46+
(builder1, builder2) -> builder1.addAll(builder2.build()),
47+
ImmutableList.Builder::build
48+
);
49+
}
50+
3951
public static String getAuthors(Plugin plugin) {
4052
List<String> authors = plugin.getDescription().getAuthors();
4153
switch (authors.size()) {

0 commit comments

Comments
 (0)