Skip to content

Commit

Permalink
new stats server
Browse files Browse the repository at this point in the history
and match core deprecation tracking change
  • Loading branch information
mcmonkey4eva committed May 1, 2022
1 parent 31f7464 commit a6758e9
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 28 deletions.
Expand Up @@ -436,7 +436,7 @@ else if (javaVersion.startsWith("17")) {
@Override
public void run() {
if (Settings.canRecordStats()) {
new StatsRecord().start();
StatsRecord.trigger();
}
}
}.runTaskTimer(this, 100, 20 * 60 * 60);
Expand Down
Expand Up @@ -72,7 +72,7 @@ public String getName() {
return "InternalBukkitEvent";
}

public static Warning depFieldContext = new VerySlowWarning("The context.field_<name> special tag for 'internal bukkit event' is experimental and subject to be removed or replace in the future");
public static Warning depFieldContext = new VerySlowWarning("internalEventFieldContext", "The context.field_<name> special tag for 'internal bukkit event' is experimental and subject to be removed or replace in the future");

@Override
public ObjectTag getContext(String name) {
Expand Down
Expand Up @@ -87,7 +87,7 @@ else if (!scriptEntry.hasObject("glowing")
}
}

public static Warning GLOW_UNSTABLE_WARN = new SlowWarning("The 'glow' command is unstable, glitchy, and experimental. It is subject to a rewrite in the near future. It is recommended that you avoid it for the time being.");
public static Warning GLOW_UNSTABLE_WARN = new SlowWarning("glowCommand", "The 'glow' command is unstable, glitchy, and experimental. It is subject to a rewrite in the near future. It is recommended that you avoid it for the time being.");

@Override
public void execute(ScriptEntry scriptEntry) {
Expand Down
Expand Up @@ -378,10 +378,7 @@ public static String createItemScriptID(String name) {
StringBuilder colors = new StringBuilder();
colors.append(ItemScriptHashID);
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] bytes = script.getBytes(StandardCharsets.UTF_8);
md.update(bytes, 0, bytes.length);
String hash = new BigInteger(1, md.digest()).toString(16);
String hash = CoreUtilities.hash_md5(script.getBytes(StandardCharsets.UTF_8));
for (int i = 0; i < 16; i++) {
colors.append(ChatColor.COLOR_CHAR).append(hash.charAt(i));
}
Expand Down
Expand Up @@ -77,7 +77,7 @@ public boolean parse(NPCTag npc, PlayerTag player, InteractScriptContainer scrip
return parse(npc, player, script, id, null);
}

public static SlowWarning missetWarning = new SlowWarning("Trigger '{NAME}' on NPC '{NPC}' activated and used but not properly set via the 'trigger' command in 'on assignment'.");
public static SlowWarning missetWarning = new SlowWarning("npcTriggerMisset", "Trigger '{NAME}' on NPC '{NPC}' activated and used but not properly set via the 'trigger' command in 'on assignment'.");

public boolean parse(NPCTag npc, PlayerTag player, InteractScriptContainer script, String id, Map<String, ObjectTag> context) {
if (npc == null || player == null || script == null) {
Expand Down
@@ -1,8 +1,10 @@
package com.denizenscript.denizen.utilities.debugging;

import com.denizenscript.denizen.Denizen;
import com.denizenscript.denizencore.scripts.ScriptRegistry;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.Deprecations;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;

import java.io.BufferedReader;
import java.io.InputStreamReader;
Expand All @@ -12,23 +14,52 @@
import java.nio.charset.StandardCharsets;

public class StatsRecord extends Thread {

public static void trigger() {
StatsRecord recorder = new StatsRecord();
recorder.gather();
recorder.start();
}

public void gather() {
String denizenVersion = Denizen.getInstance().coreImplementation.getImplementationVersion();
// We don't need the real value of the MOTD / port, but they're useful for differentiating, so use them to generate a hash
String differentiator = CoreUtilities.hash_md5((Bukkit.getServer().getMotd() + Bukkit.getServer().getPort()).getBytes(StandardCharsets.UTF_8));
String deprecations = String.join("\n", Deprecations.firedRecently);
Deprecations.firedRecently.clear();
String mcVersion = Bukkit.getVersion();
int firstDash = mcVersion.indexOf('-');
int secondDash = firstDash == -1 ? -1 : mcVersion.indexOf('-', firstDash + 1);
int mcPart = mcVersion.indexOf("(MC: ");
int endPart = mcPart == -1 ? -1 : mcVersion.indexOf(")", mcPart);
String platform = secondDash == -1 ? "" : mcVersion.substring(firstDash + 1, secondDash);
mcVersion = (endPart == -1) ? "" : mcVersion.substring(mcPart + "(MC: ".length(), endPart);
content = "postid=pluginstats&plugin=Denizen"
+ "&differentiator=" + differentiator
+ "&pl_plugin_version=" + URLEncoder.encode(denizenVersion)
+ "&pl_platform=" + URLEncoder.encode(platform)
+ "&pl_minecraft_version=" + URLEncoder.encode(mcVersion)
+ "&pl_player_count=" + Bukkit.getOnlinePlayers().size()
+ "&pl_script_count=" + ScriptRegistry.scriptContainers.size()
+ "&pl_deprecations=" + URLEncoder.encode(deprecations);
}

public String content;

@Override
public void run() {
BufferedReader in = null;
try {
// Open a connection to the stats server
URL url = new URL("http://neo.mcmonkey.org/plugins/public_stats?plugin=Denizen&version=" + URLEncoder.encode(Denizen.getInstance().coreImplementation.getImplementationVersion()));
URL url = new URL("https://stats.mcmonkey.org/Stats/Submit");
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
uc.setDoInput(true);
uc.setDoOutput(true);
uc.setConnectTimeout(10000);
uc.connect();
// Safely connected at this point
// Create the final message pack and upload it
uc.getOutputStream().write(("postid=pluginstats&plugin_st_players=" + Bukkit.getOnlinePlayers().size()
+ "&plugin_st_server_version=" + URLEncoder.encode(Bukkit.getVersion())
+ "&plugin_st_motd=" + URLEncoder.encode(Bukkit.getServer().getMotd().replace(ChatColor.COLOR_CHAR, (char) 0x01)))
.getBytes(StandardCharsets.UTF_8));
uc.getOutputStream().write(content.getBytes(StandardCharsets.UTF_8));
// Wait for a response from the server
in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
// Record the response
Expand Down
Expand Up @@ -210,8 +210,8 @@ public boolean needsHandleArgPrefix(String prefix) {
//
// -->

public static StrongWarning invalidPlayerArg = new StrongWarning("The 'player:' arg should not be used in commands like define/flag/yaml/... just input the player directly instead.");
public static StrongWarning invalidNpcArg = new StrongWarning("The 'npc:' arg should not be used in commands like define/flag/yaml/... just input the npc directly instead.");
public static StrongWarning invalidPlayerArg = new StrongWarning("invalidPlayerArg", "The 'player:' arg should not be used in commands like define/flag/yaml/... just input the player directly instead.");
public static StrongWarning invalidNpcArg = new StrongWarning("invalidNpcArg", "The 'npc:' arg should not be used in commands like define/flag/yaml/... just input the npc directly instead.");
public static HashSet<String> invalidPlayerArgCommands = new HashSet<>(Arrays.asList("DEFINE", "FLAG", "YAML"));

@Override
Expand Down
Expand Up @@ -4,6 +4,7 @@
import com.denizenscript.denizen.nms.v1_16.impl.entities.EntityFakeArrowImpl;
import com.denizenscript.denizen.nms.v1_16.impl.entities.EntityFakePlayerImpl;
import com.denizenscript.denizen.nms.v1_16.impl.entities.EntityItemProjectileImpl;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.denizenscript.denizen.nms.NMSHandler;
Expand Down Expand Up @@ -132,10 +133,7 @@ else if (name.length() > 46) {
String teamName = "FAKE_PLAYER_TEAM_" + fullName;
String hash = null;
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] bytes = teamName.getBytes(StandardCharsets.UTF_8);
md.update(bytes, 0, bytes.length);
hash = new BigInteger(1, md.digest()).toString(16).substring(0, 16);
hash = CoreUtilities.hash_md5(teamName.getBytes(StandardCharsets.UTF_8));
}
catch (Exception e) {
Debug.echoError(e);
Expand Down
Expand Up @@ -4,6 +4,7 @@
import com.denizenscript.denizen.nms.v1_17.impl.entities.EntityFakeArrowImpl;
import com.denizenscript.denizen.nms.v1_17.impl.entities.EntityFakePlayerImpl;
import com.denizenscript.denizen.nms.v1_17.impl.entities.EntityItemProjectileImpl;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.denizenscript.denizen.nms.NMSHandler;
Expand Down Expand Up @@ -131,10 +132,7 @@ else if (name.length() > 46) {
String teamName = "FAKE_PLAYER_TEAM_" + fullName;
String hash = null;
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] bytes = teamName.getBytes(StandardCharsets.UTF_8);
md.update(bytes, 0, bytes.length);
hash = new BigInteger(1, md.digest()).toString(16).substring(0, 16);
hash = CoreUtilities.hash_md5(teamName.getBytes(StandardCharsets.UTF_8));
}
catch (Exception e) {
Debug.echoError(e);
Expand Down
Expand Up @@ -4,6 +4,7 @@
import com.denizenscript.denizen.nms.v1_18.impl.entities.EntityFakeArrowImpl;
import com.denizenscript.denizen.nms.v1_18.impl.entities.EntityFakePlayerImpl;
import com.denizenscript.denizen.nms.v1_18.impl.entities.EntityItemProjectileImpl;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.denizenscript.denizen.nms.NMSHandler;
Expand Down Expand Up @@ -134,10 +135,7 @@ else if (skin == null && !name.matches(".*[^A-Za-z0-9_].*")) {
String teamName = "FAKE_PLAYER_TEAM_" + fullName;
String hash = null;
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] bytes = teamName.getBytes(StandardCharsets.UTF_8);
md.update(bytes, 0, bytes.length);
hash = new BigInteger(1, md.digest()).toString(16).substring(0, 16);
hash = CoreUtilities.hash_md5(teamName.getBytes(StandardCharsets.UTF_8));
}
catch (Exception e) {
Debug.echoError(e);
Expand Down

0 comments on commit a6758e9

Please sign in to comment.