Added bStats

This commit is contained in:
isokissa3 2020-04-24 16:55:13 +03:00
parent 3fbd10e078
commit 46cc45fc77
5 changed files with 102 additions and 2 deletions

View file

@ -1,4 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>net.goldtreeservers</groupId> <groupId>net.goldtreeservers</groupId>
@ -25,6 +27,12 @@
</execution> </execution>
</executions> </executions>
<configuration> <configuration>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>net.goldtreeservers.worldguardextraflags.bstats</shadedPattern>
</relocation>
</relocations>
<filters> <filters>
<filter> <filter>
<artifact>*:*</artifact> <artifact>*:*</artifact>
@ -61,6 +69,10 @@
<id>dmulloy2-repo</id> <id>dmulloy2-repo</id>
<url>http://repo.dmulloy2.net/nexus/repository/public/</url> <url>http://repo.dmulloy2.net/nexus/repository/public/</url>
</repository> </repository>
<repository>
<id>CodeMC</id>
<url>https://repo.codemc.org/repository/maven-public</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
@ -131,5 +143,11 @@
<version>4.5.0</version> <version>4.5.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.7</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View file

@ -1,7 +1,14 @@
package net.goldtreeservers.worldguardextraflags; package net.goldtreeservers.worldguardextraflags;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;
import org.bstats.bukkit.Metrics;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.event.entity.EntityToggleGlideEvent; import org.bukkit.event.entity.EntityToggleGlideEvent;
@ -10,10 +17,12 @@ import org.bukkit.plugin.Plugin;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.Flag;
import lombok.Getter; import lombok.Getter;
import net.goldtreeservers.worldguardextraflags.essentials.EssentialsHelper; import net.goldtreeservers.worldguardextraflags.essentials.EssentialsHelper;
import net.goldtreeservers.worldguardextraflags.fawe.FAWEHelper; import net.goldtreeservers.worldguardextraflags.fawe.FAWEHelper;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.listeners.BlockListener; import net.goldtreeservers.worldguardextraflags.listeners.BlockListener;
import net.goldtreeservers.worldguardextraflags.listeners.EntityListener; import net.goldtreeservers.worldguardextraflags.listeners.EntityListener;
import net.goldtreeservers.worldguardextraflags.listeners.EntityListenerOnePointNine; import net.goldtreeservers.worldguardextraflags.listeners.EntityListenerOnePointNine;
@ -192,6 +201,58 @@ public class WorldGuardExtraFlagsPlugin extends AbstractWorldGuardExtraFlagsPlug
{ {
this.getWorldGuardCommunicator().doUnloadChunkFlagCheck(world); this.getWorldGuardCommunicator().doUnloadChunkFlagCheck(world);
} }
this.setupMetrics();
}
private void setupMetrics()
{
final int bStatsPluginId = 7301;
Metrics metrics = new Metrics(this, bStatsPluginId);
metrics.addCustomChart(new Metrics.AdvancedPie("flags_count", new Callable<Map<String, Integer>>()
{
private final Set<Flag<?>> flags = WorldGuardExtraFlagsPlugin.this.getPluginFlags();
@Override
public Map<String, Integer> call() throws Exception
{
Map<Flag<?>, Integer> valueMap = this.flags.stream().collect(Collectors.toMap((v) -> v, (v) -> 0));
WorldGuardExtraFlagsPlugin.this.getWorldGuardCommunicator().getRegionContainer().getLoaded().forEach((m) ->
{
m.getRegions().values().forEach((r) ->
{
r.getFlags().keySet().forEach((f) ->
{
valueMap.computeIfPresent(f, (k, v) -> v + 1);
});
});
});
return valueMap.entrySet().stream().collect(Collectors.toMap((v) -> v.getKey().getName(), (v) -> v.getValue()));
}
}));
System.out.println(metrics.getPluginData().toString());
}
private Set<Flag<?>> getPluginFlags()
{
Set<Flag<?>> flags = new HashSet<>();
for (Field field : Flags.class.getFields())
{
try
{
flags.add((Flag<?>)field.get(null));
}
catch (IllegalArgumentException | IllegalAccessException e)
{
}
}
return flags;
} }
public static WorldGuardCommunicator createWorldGuardCommunicator() public static WorldGuardCommunicator createWorldGuardCommunicator()

View file

@ -1,9 +1,13 @@
package net.goldtreeservers.worldguardextraflags.wg.wrappers; package net.goldtreeservers.worldguardextraflags.wg.wrappers;
import java.util.List;
import org.bukkit.World; import org.bukkit.World;
public abstract class AbstractRegionContainerWrapper public abstract class AbstractRegionContainerWrapper
{ {
public abstract AbstractRegionQueryWrapper createQuery(); public abstract AbstractRegionQueryWrapper createQuery();
public abstract AbstractRegionManagerWrapper get(World world); public abstract AbstractRegionManagerWrapper get(World world);
public abstract List<AbstractRegionManagerWrapper> getLoaded();
} }

View file

@ -1,5 +1,8 @@
package net.goldtreeservers.worldguardextraflags.wg.wrappers.v6; package net.goldtreeservers.worldguardextraflags.wg.wrappers.v6;
import java.util.List;
import java.util.stream.Collectors;
import org.bukkit.World; import org.bukkit.World;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
@ -21,4 +24,10 @@ public class RegionContainerWrapper extends AbstractRegionContainerWrapper
{ {
return new RegionManagerWrapper(WorldGuardPlugin.inst().getRegionManager(world)); return new RegionManagerWrapper(WorldGuardPlugin.inst().getRegionManager(world));
} }
@Override
public List<AbstractRegionManagerWrapper> getLoaded()
{
return WorldGuardPlugin.inst().getRegionContainer().getLoaded().stream().map((m) -> new RegionManagerWrapper(m)).collect(Collectors.toList());
}
} }

View file

@ -1,5 +1,8 @@
package net.goldtreeservers.worldguardextraflags.wg.wrappers.v7; package net.goldtreeservers.worldguardextraflags.wg.wrappers.v7;
import java.util.List;
import java.util.stream.Collectors;
import org.bukkit.World; import org.bukkit.World;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
@ -11,7 +14,6 @@ import net.goldtreeservers.worldguardextraflags.wg.wrappers.AbstractRegionQueryW
public class RegionContainerWrapper extends AbstractRegionContainerWrapper public class RegionContainerWrapper extends AbstractRegionContainerWrapper
{ {
@Override @Override
public AbstractRegionQueryWrapper createQuery() public AbstractRegionQueryWrapper createQuery()
{ {
@ -23,4 +25,10 @@ public class RegionContainerWrapper extends AbstractRegionContainerWrapper
{ {
return new RegionManagerWrapper(WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world))); return new RegionManagerWrapper(WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world)));
} }
@Override
public List<AbstractRegionManagerWrapper> getLoaded()
{
return WorldGuard.getInstance().getPlatform().getRegionContainer().getLoaded().stream().map((m) -> new RegionManagerWrapper(m)).collect(Collectors.toList());
}
} }