diff --git a/Spigot/pom.xml b/Spigot/pom.xml index d463a7d..47c7379 100644 --- a/Spigot/pom.xml +++ b/Spigot/pom.xml @@ -1,4 +1,6 @@ - + 4.0.0 net.goldtreeservers @@ -25,6 +27,12 @@ + + + org.bstats + net.goldtreeservers.worldguardextraflags.bstats + + *:* @@ -61,6 +69,10 @@ dmulloy2-repo http://repo.dmulloy2.net/nexus/repository/public/ + + CodeMC + https://repo.codemc.org/repository/maven-public + @@ -131,5 +143,11 @@ 4.5.0 provided + + org.bstats + bstats-bukkit + 1.7 + compile + \ No newline at end of file diff --git a/Spigot/src/main/java/net/goldtreeservers/worldguardextraflags/WorldGuardExtraFlagsPlugin.java b/Spigot/src/main/java/net/goldtreeservers/worldguardextraflags/WorldGuardExtraFlagsPlugin.java index e3558a8..336ec2b 100644 --- a/Spigot/src/main/java/net/goldtreeservers/worldguardextraflags/WorldGuardExtraFlagsPlugin.java +++ b/Spigot/src/main/java/net/goldtreeservers/worldguardextraflags/WorldGuardExtraFlagsPlugin.java @@ -1,7 +1,14 @@ package net.goldtreeservers.worldguardextraflags; +import java.lang.reflect.Field; 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.block.BlockState; import org.bukkit.event.entity.EntityToggleGlideEvent; @@ -10,10 +17,12 @@ import org.bukkit.plugin.Plugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.flags.Flag; import lombok.Getter; import net.goldtreeservers.worldguardextraflags.essentials.EssentialsHelper; import net.goldtreeservers.worldguardextraflags.fawe.FAWEHelper; +import net.goldtreeservers.worldguardextraflags.flags.Flags; import net.goldtreeservers.worldguardextraflags.listeners.BlockListener; import net.goldtreeservers.worldguardextraflags.listeners.EntityListener; import net.goldtreeservers.worldguardextraflags.listeners.EntityListenerOnePointNine; @@ -192,6 +201,58 @@ public class WorldGuardExtraFlagsPlugin extends AbstractWorldGuardExtraFlagsPlug { 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>() + { + private final Set> flags = WorldGuardExtraFlagsPlugin.this.getPluginFlags(); + + @Override + public Map call() throws Exception + { + Map, 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> getPluginFlags() + { + Set> 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() diff --git a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/AbstractRegionContainerWrapper.java b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/AbstractRegionContainerWrapper.java index 7ef0b95..788254d 100644 --- a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/AbstractRegionContainerWrapper.java +++ b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/AbstractRegionContainerWrapper.java @@ -1,9 +1,13 @@ package net.goldtreeservers.worldguardextraflags.wg.wrappers; +import java.util.List; + import org.bukkit.World; public abstract class AbstractRegionContainerWrapper { public abstract AbstractRegionQueryWrapper createQuery(); public abstract AbstractRegionManagerWrapper get(World world); + + public abstract List getLoaded(); } diff --git a/WG6/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v6/RegionContainerWrapper.java b/WG6/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v6/RegionContainerWrapper.java index 414cd2e..1b705ff 100644 --- a/WG6/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v6/RegionContainerWrapper.java +++ b/WG6/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v6/RegionContainerWrapper.java @@ -1,5 +1,8 @@ package net.goldtreeservers.worldguardextraflags.wg.wrappers.v6; +import java.util.List; +import java.util.stream.Collectors; + import org.bukkit.World; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; @@ -21,4 +24,10 @@ public class RegionContainerWrapper extends AbstractRegionContainerWrapper { return new RegionManagerWrapper(WorldGuardPlugin.inst().getRegionManager(world)); } + + @Override + public List getLoaded() + { + return WorldGuardPlugin.inst().getRegionContainer().getLoaded().stream().map((m) -> new RegionManagerWrapper(m)).collect(Collectors.toList()); + } } diff --git a/WG7/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v7/RegionContainerWrapper.java b/WG7/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v7/RegionContainerWrapper.java index 1c9c62d..61fcf85 100644 --- a/WG7/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v7/RegionContainerWrapper.java +++ b/WG7/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v7/RegionContainerWrapper.java @@ -1,5 +1,8 @@ package net.goldtreeservers.worldguardextraflags.wg.wrappers.v7; +import java.util.List; +import java.util.stream.Collectors; + import org.bukkit.World; import com.sk89q.worldedit.bukkit.BukkitAdapter; @@ -11,7 +14,6 @@ import net.goldtreeservers.worldguardextraflags.wg.wrappers.AbstractRegionQueryW public class RegionContainerWrapper extends AbstractRegionContainerWrapper { - @Override public AbstractRegionQueryWrapper createQuery() { @@ -23,4 +25,10 @@ public class RegionContainerWrapper extends AbstractRegionContainerWrapper { return new RegionManagerWrapper(WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world))); } + + @Override + public List getLoaded() + { + return WorldGuard.getInstance().getPlatform().getRegionContainer().getLoaded().stream().map((m) -> new RegionManagerWrapper(m)).collect(Collectors.toList()); + } }