Skip to content

Commit 5307d1f

Browse files
committed
bStats update, new graph
bStats updated to v1.2 added graph showing which plugins are using deprecated classes
1 parent ab67f51 commit 5307d1f

File tree

5 files changed

+77
-12
lines changed

5 files changed

+77
-12
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<dependency>
3737
<groupId>org.bstats</groupId>
3838
<artifactId>bstats-bukkit</artifactId>
39-
<version>1.1</version>
39+
<version>1.2</version>
4040
</dependency>
4141
</dependencies>
4242

src/main/java/com/xxmicloxx/NoteBlockAPI/NoteBlockAPI.java

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,28 @@
44
import java.util.Collections;
55
import java.util.HashMap;
66
import java.util.Map;
7+
import java.util.Set;
78
import java.util.UUID;
89

9-
import org.bstats.Metrics;
10+
import org.bstats.bukkit.Metrics;
1011
import org.bukkit.Bukkit;
1112
import org.bukkit.entity.Player;
13+
import org.bukkit.plugin.Plugin;
1214
import org.bukkit.plugin.java.JavaPlugin;
1315

1416
import com.xxmicloxx.NoteBlockAPI.songplayer.SongPlayer;
1517

1618
public class NoteBlockAPI extends JavaPlugin {
1719

18-
public static NoteBlockAPI plugin;
20+
private static NoteBlockAPI plugin;
1921

2022
private Map<UUID, ArrayList<SongPlayer>> playingSongs =
2123
Collections.synchronizedMap(new HashMap<UUID, ArrayList<SongPlayer>>());
2224
private Map<UUID, Byte> playerVolume = Collections.synchronizedMap(new HashMap<UUID, Byte>());
2325

2426
private boolean disabling = false;
27+
28+
private HashMap<Plugin, Boolean> dependentPlugins = new HashMap<>();
2529

2630
/**
2731
* Returns true if a Player is currently receiving a song
@@ -80,7 +84,26 @@ public static void setSongPlayersByPlayer(Player player, ArrayList<SongPlayer> s
8084
@Override
8185
public void onEnable() {
8286
plugin = this;
83-
new Metrics(this);
87+
88+
for (Plugin pl : getServer().getPluginManager().getPlugins()){
89+
if (pl.getDescription().getDepend().contains("NoteBlockAPI") || pl.getDescription().getSoftDepend().contains("NoteBlockAPI")){
90+
dependentPlugins.put(pl, false);
91+
}
92+
}
93+
94+
Metrics metrics = new Metrics(this);
95+
96+
metrics.addCustomChart(new Metrics.DrilldownPie("deprecated", () -> {
97+
Map<String, Map<String, Integer>> map = new HashMap<>();
98+
for (Plugin pl : dependentPlugins.keySet()){
99+
String deprecated = dependentPlugins.get(pl) ? "yes" : "no";
100+
Map<String, Integer> entry = new HashMap<>();
101+
entry.put(pl.getDescription().getFullName(), 1);
102+
map.put(deprecated, entry);
103+
}
104+
return map;
105+
}));
106+
84107
new NoteBlockPlayerMain().onEnable();
85108
}
86109

@@ -103,4 +126,46 @@ public boolean isDisabling() {
103126
return disabling;
104127
}
105128

129+
public static NoteBlockAPI getAPI(){
130+
return plugin;
131+
}
132+
133+
protected void handleDeprecated(StackTraceElement[] ste){
134+
int pom = 1;
135+
String clazz = ste[pom].getClassName();
136+
while (clazz.startsWith("com.xxmicloxx.NoteBlockAPI")){
137+
pom++;
138+
clazz = ste[pom].getClassName();
139+
}
140+
String[] packageParts = clazz.split("\\.");
141+
ArrayList<Plugin> plugins = new ArrayList<Plugin>();
142+
plugins.addAll(dependentPlugins.keySet());
143+
144+
ArrayList<Plugin> notResult = new ArrayList<Plugin>();
145+
parts:
146+
for (int i = 0; i < packageParts.length - 1; i++){
147+
148+
for (Plugin pl : plugins){
149+
if (notResult.contains(pl)){ continue;}
150+
if (plugins.size() - notResult.size() == 1){
151+
break parts;
152+
}
153+
String[] plParts = pl.getDescription().getMain().split("\\.");
154+
if (!packageParts[i].equalsIgnoreCase(plParts[i])){
155+
notResult.add(pl);
156+
continue;
157+
}
158+
}
159+
plugins.removeAll(notResult);
160+
notResult.clear();
161+
}
162+
163+
plugins.removeAll(notResult);
164+
notResult.clear();
165+
if (plugins.size() == 1){
166+
Bukkit.getLogger().info(plugins.get(0).getName());
167+
dependentPlugins.put(plugins.get(0), true);
168+
}
169+
}
170+
106171
}

src/main/java/com/xxmicloxx/NoteBlockAPI/NoteBlockPlayerMain.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
import java.util.HashMap;
66
import java.util.Map;
77

8-
import org.bstats.Metrics;
98
import org.bukkit.Bukkit;
109
import org.bukkit.entity.Player;
11-
import org.bukkit.plugin.java.JavaPlugin;
1210

1311
/**
1412
* Main class; contains methods for playing and adjusting songs for players
@@ -81,11 +79,11 @@ public void onDisable() {
8179
}
8280

8381
public void doSync(Runnable runnable) {
84-
Bukkit.getServer().getScheduler().runTask(NoteBlockAPI.plugin, runnable);
82+
Bukkit.getServer().getScheduler().runTask(NoteBlockAPI.getAPI(), runnable);
8583
}
8684

8785
public void doAsync(Runnable runnable) {
88-
Bukkit.getServer().getScheduler().runTaskAsynchronously(NoteBlockAPI.plugin, runnable);
86+
Bukkit.getServer().getScheduler().runTaskAsynchronously(NoteBlockAPI.getAPI(), runnable);
8987
}
9088

9189
public boolean isDisabling() {

src/main/java/com/xxmicloxx/NoteBlockAPI/SongPlayer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public SongPlayer(Song song) {
5252
}
5353

5454
public SongPlayer(Song song, SoundCategory soundCategory) {
55+
NoteBlockAPI.getAPI().handleDeprecated(Thread.currentThread().getStackTrace());
56+
5557
this.song = song;
5658
this.soundCategory = soundCategory;
5759
plugin = NoteBlockPlayerMain.plugin;
@@ -232,7 +234,7 @@ private void start() {
232234
long startTime = System.currentTimeMillis();
233235
lock.lock();
234236
try {
235-
if (destroyed || NoteBlockAPI.plugin.isDisabling()){
237+
if (destroyed || NoteBlockAPI.getAPI().isDisabling()){
236238
break;
237239
}
238240

src/main/java/com/xxmicloxx/NoteBlockAPI/songplayer/SongPlayer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public SongPlayer(Song song) {
6868
public SongPlayer(Song song, SoundCategory soundCategory) {
6969
this.song = song;
7070
this.soundCategory = soundCategory;
71-
plugin = NoteBlockAPI.plugin;
71+
plugin = NoteBlockAPI.getAPI();
7272
start();
7373
}
7474

@@ -246,7 +246,7 @@ private void start() {
246246
long startTime = System.currentTimeMillis();
247247
lock.lock();
248248
try {
249-
if (destroyed || NoteBlockAPI.plugin.isDisabling()){
249+
if (destroyed || NoteBlockAPI.getAPI().isDisabling()){
250250
break;
251251
}
252252

@@ -506,7 +506,7 @@ public void setCategory(SoundCategory soundCategory) {
506506

507507
void CallUpdate(String key, Object value){
508508
try {
509-
Method m = com.xxmicloxx.NoteBlockAPI.songplayer.SongPlayer.class.getDeclaredMethod("update", String.class, Object.class);
509+
Method m = com.xxmicloxx.NoteBlockAPI.SongPlayer.class.getDeclaredMethod("update", String.class, Object.class);
510510
m.setAccessible(true);
511511
m.invoke(oldSongPlayer, key, value);
512512
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException

0 commit comments

Comments
 (0)