Skip to content

Commit

Permalink
Added bStats
Browse files Browse the repository at this point in the history
TPGamesNL committed Jan 30, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent b3956c5 commit 057ab54
Showing 10 changed files with 818 additions and 0 deletions.
733 changes: 733 additions & 0 deletions src/main/java/com/btk5h/skriptmirror/Metrics.java

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions src/main/java/com/btk5h/skriptmirror/SkriptMirror.java
Original file line number Diff line number Diff line change
@@ -2,11 +2,22 @@

import ch.njol.skript.Skript;
import ch.njol.skript.SkriptAddon;
import ch.njol.skript.util.Version;
import com.btk5h.skriptmirror.skript.CondParseLater;
import com.btk5h.skriptmirror.skript.custom.condition.CustomConditionSection;
import com.btk5h.skriptmirror.skript.custom.effect.CustomEffectSection;
import com.btk5h.skriptmirror.skript.custom.event.CustomEventSection;
import com.btk5h.skriptmirror.skript.custom.expression.CustomExpressionSection;
import com.btk5h.skriptmirror.skript.reflect.ExprJavaCall;
import com.btk5h.skriptmirror.skript.reflect.ExprProxy;
import com.btk5h.skriptmirror.skript.reflect.sections.CondSection;
import com.btk5h.skriptmirror.util.SkriptReflection;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.IOException;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;

public class SkriptMirror extends JavaPlugin {
private static SkriptMirror instance;
@@ -37,6 +48,46 @@ public void onEnable() {

// Disable *all* and/or warnings
SkriptReflection.disableAndOrWarnings();

Metrics metrics = new Metrics(this, 10157);

metrics.addCustomChart(new Metrics.DrilldownPie("skript_version", () -> {
Map<String, Map<String, Integer>> map = new HashMap<>();

Version version = Skript.getVersion();
Map<String, Integer> entry = new HashMap<>();
entry.put(version.toString(), 1);

map.put("" + version.getMajor() + "." + version.getMinor(), entry);

return map;
}));

metrics.addCustomChart(new Metrics.SimplePie("preload_enabled",
() -> "" + getConfig().getBoolean("enable-preloading")));
metrics.addCustomChart(new Metrics.SimplePie("deferred_parsing_used",
() -> "" + CondParseLater.deferredParsingUsed));

metrics.addCustomChart(new Metrics.SingleLineChart("java_calls_made", () -> {
int i = ExprJavaCall.javaCallsMade;
ExprJavaCall.javaCallsMade = 0;
return i;
}));

metrics.addCustomChart(new Metrics.SimplePie("custom_conditions_used",
() -> "" + CustomConditionSection.customConditionsUsed));
metrics.addCustomChart(new Metrics.SimplePie("custom_effects_used",
() -> "" + CustomEffectSection.customEffectsUsed));
metrics.addCustomChart(new Metrics.SimplePie("custom_events_used",
() -> "" + CustomEventSection.customEventsUsed));
metrics.addCustomChart(new Metrics.SimplePie("custom_expressions_used",
() -> "" + CustomExpressionSection.customExpressionsUsed));

metrics.addCustomChart(new Metrics.SimplePie("proxies_used",
() -> "" + ExprProxy.proxiesUsed));
metrics.addCustomChart(new Metrics.SimplePie("sections_used",
() -> "" + CondSection.sectionsUsed));

}

public static SkriptAddon getAddonInstance() {
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@
import org.bukkit.event.Event;

public class CondParseLater extends Condition {
public static boolean deferredParsingUsed = false;

static {
Skript.registerCondition(CondParseLater.class, "\\(parse[d] later\\) <.+>");
}
@@ -45,6 +47,8 @@ public String toString(Event e, boolean debug) {
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed,
SkriptParser.ParseResult parseResult) {
deferredParsingUsed = true;

if (!Consent.Feature.DEFERRED_PARSING.hasConsent(SkriptUtil.getCurrentScript())) {
Skript.error("This feature requires consent, because it is experimental.");
return false;
Original file line number Diff line number Diff line change
@@ -20,6 +20,9 @@
import java.util.stream.Collectors;

public class CustomConditionSection extends CustomSyntaxSection<ConditionSyntaxInfo> {

public static boolean customConditionsUsed = false;

static {
String[] syntax = {
"[(1¦local)] condition <.+>",
@@ -59,6 +62,8 @@ public DataTracker<ConditionSyntaxInfo> getDataTracker() {
@Override
protected boolean init(Literal<?>[] args, int matchedPattern, SkriptParser.ParseResult parseResult,
SectionNode node, boolean isPreload) {
customConditionsUsed = true;

if (!isPreloaded) {
String what;
SectionNode patterns = (SectionNode) node.get("patterns");
Original file line number Diff line number Diff line change
@@ -20,6 +20,9 @@
import java.util.function.Supplier;

public class CustomEffectSection extends CustomSyntaxSection<EffectSyntaxInfo> {

public static boolean customEffectsUsed = false;

static {
String[] syntax = {
"[(1¦local)] effect <.+>",
@@ -57,6 +60,8 @@ public DataTracker<EffectSyntaxInfo> getDataTracker() {
@Override
protected boolean init(Literal<?>[] args, int matchedPattern, SkriptParser.ParseResult parseResult,
SectionNode node, boolean isPreload) {
customEffectsUsed = true;

if (!isPreloaded) {
SectionNode patterns = (SectionNode) node.get("patterns");
File script = (parseResult.mark & 1) == 1 ? SkriptUtil.getCurrentScript() : null;
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import java.util.*;

public class CustomEventSection extends CustomSyntaxSection<EventSyntaxInfo> {
public static boolean customEventsUsed = false;

static {
String[] syntax = {
@@ -59,6 +60,8 @@ protected DataTracker<EventSyntaxInfo> getDataTracker() {
@Override
protected boolean init(Literal<?>[] args, int matchedPattern, SkriptParser.ParseResult parseResult,
SectionNode node, boolean isPreload) {
customEventsUsed = true;

if (!isPreloaded) {
File script = (parseResult.mark & 1) == 1 ? SkriptUtil.getCurrentScript() : null;

Original file line number Diff line number Diff line change
@@ -24,6 +24,8 @@
import java.util.stream.StreamSupport;

public class CustomExpressionSection extends CustomSyntaxSection<ExpressionSyntaxInfo> {
public static boolean customExpressionsUsed = false;

static {
String[] syntax = {
"[(2¦local)] [(1¦(plural|non(-|[ ])single))] expression <.+>",
@@ -75,6 +77,8 @@ protected DataTracker<ExpressionSyntaxInfo> getDataTracker() {
@Override
protected boolean init(Literal<?>[] args, int matchedPattern, SkriptParser.ParseResult parseResult,
SectionNode node, boolean isPreload) {
customExpressionsUsed = true;

if (!isPreloaded) {
String what;
SectionNode patterns = (SectionNode) node.get("patterns");
Original file line number Diff line number Diff line change
@@ -35,6 +35,8 @@
import java.util.stream.Stream;

public class ExprJavaCall<T> implements Expression<T> {
public static int javaCallsMade = 0;

private static final MethodHandles.Lookup LOOKUP = MethodHandles.publicLookup();
private static final Object[] NO_ARGS = new Object[0];
private static final Descriptor CONSTRUCTOR_DESCRIPTOR = new Descriptor(null, "<init>", null);
@@ -408,6 +410,8 @@ private Collection<MethodHandle> createCallSite(Descriptor e) {

@SuppressWarnings("unchecked")
private T invoke(Object target, Object[] arguments, Descriptor baseDescriptor) {
javaCallsMade++;

if (baseDescriptor == null) {
return null;
}
Original file line number Diff line number Diff line change
@@ -25,6 +25,9 @@
import java.util.*;

public class ExprProxy extends SimpleExpression<Object> {

public static boolean proxiesUsed = false;

static {
Skript.registerExpression(ExprProxy.class, Object.class, ExpressionType.COMBINED,
"[a] [new] proxy [instance] of %javatypes% (using|from) %objects%");
@@ -138,6 +141,8 @@ public String toString(Event e, boolean debug) {
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed,
SkriptParser.ParseResult parseResult) {

proxiesUsed = true;

interfaces = SkriptUtil.defendExpression(exprs[0]);
Expression<?> var = SkriptUtil.defendExpression(exprs[1]);

Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@

public class CondSection extends Condition {

public static boolean sectionsUsed = false;

static {
Skript.registerCondition(CondSection.class,
"create [new] section [with [arguments variables] %-objects%] (and store it|stored) in %objects%");
@@ -70,6 +72,8 @@ public String toString(@Nullable Event e, boolean debug) {

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
sectionsUsed = true;

if (!shouldInit)
return false;

0 comments on commit 057ab54

Please sign in to comment.