Fix version checker and add bstats
This commit is contained in:
parent
d77a012ca9
commit
6e90d0d3e8
11 changed files with 166 additions and 56 deletions
|
@ -11,8 +11,6 @@
|
|||
<option value="$PROJECT_DIR$/api" />
|
||||
<option value="$PROJECT_DIR$/code-gen" />
|
||||
<option value="$PROJECT_DIR$/common" />
|
||||
<option value="$PROJECT_DIR$/kotlin" />
|
||||
<option value="$PROJECT_DIR$/kotlin/kotlin-extensions-spigot" />
|
||||
<option value="$PROJECT_DIR$/platforms" />
|
||||
<option value="$PROJECT_DIR$/platforms/spigot" />
|
||||
<option value="$PROJECT_DIR$/platforms/velocity" />
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
<file type="web" url="file://$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="corretto-17" project-jdk-type="JavaSDK" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="corretto-1.8" project-jdk-type="JavaSDK" />
|
||||
</project>
|
|
@ -4,7 +4,19 @@
|
|||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="9d5d9b6f-43c8-41a4-bb42-a66ffc96c9b0" name="Changes" comment="" />
|
||||
<list default="true" id="9d5d9b6f-43c8-41a4-bb42-a66ffc96c9b0" name="Changes" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/utils/GithubUpdater.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/gradle.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/gradle.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/api/build.gradle" beforeDir="false" afterPath="$PROJECT_DIR$/api/build.gradle" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/APIConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/api/src/main/java/me/tofaa/entitylib/APIConfig.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/build.gradle" beforeDir="false" afterPath="$PROJECT_DIR$/build.gradle" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/platforms/spigot/build.gradle" beforeDir="false" afterPath="$PROJECT_DIR$/platforms/spigot/build.gradle" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/platforms/spigot/src/main/java/me/tofaa/entitylib/spigot/SpigotEntityLibPlatform.java" beforeDir="false" afterPath="$PROJECT_DIR$/platforms/spigot/src/main/java/me/tofaa/entitylib/spigot/SpigotEntityLibPlatform.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/platforms/velocity/build.gradle" beforeDir="false" afterPath="$PROJECT_DIR$/platforms/velocity/build.gradle" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/platforms/velocity/src/main/java/me/tofaa/entitylib/velocity/VelocityEntityLibPlatform.java" beforeDir="false" afterPath="$PROJECT_DIR$/platforms/velocity/src/main/java/me/tofaa/entitylib/velocity/VelocityEntityLibPlatform.java" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
|
@ -53,10 +65,9 @@
|
|||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="HighlightingSettingsPerFile">
|
||||
<setting file="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.github.retrooper.packetevents/api/2.2.1/c70f2380ee7c60be444e22a10e679577ab9f8afa/api-2.2.1-default.jar!/com/github/retrooper/packetevents/protocol/item/ItemStack.class" root0="SKIP_INSPECTION" />
|
||||
<setting file="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.github.retrooper.packetevents/api/2.2.1/c70f2380ee7c60be444e22a10e679577ab9f8afa/api-2.2.1-default.jar!/com/github/retrooper/packetevents/protocol/player/TextureProperty.class" root0="SKIP_INSPECTION" />
|
||||
<setting file="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.github.retrooper.packetevents/velocity/2.3.0/aba4fb09c29c8a071cac36acba545ed37bb80268/velocity-2.3.0-default.jar!/io/github/retrooper/packetevents/bstats/Metrics.class" root0="SKIP_INSPECTION" />
|
||||
<setting file="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.github.retrooper.packetevents/velocity/2.3.0/aba4fb09c29c8a071cac36acba545ed37bb80268/velocity-2.3.0-default.jar!/io/github/retrooper/packetevents/velocity/factory/VelocityPacketEventsBuilder.class" root0="SKIP_INSPECTION" />
|
||||
<setting file="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.google.code.gson/gson/2.8.0/c4ba5371a29ac9b2ad6129b1d39ea38750043eff/gson-2.8.0.jar!/com/google/gson/JsonArray.class" root0="SKIP_INSPECTION" />
|
||||
<setting file="jar://$USER_HOME$/.jdks/corretto-17.0.10/lib/src.zip!/java.base/java/util/List.java" root0="SKIP_INSPECTION" />
|
||||
</component>
|
||||
<component name="MarkdownSettingsMigration">
|
||||
<option name="stateVersion" value="1" />
|
||||
|
@ -73,44 +84,44 @@
|
|||
<option name="showExcludedFiles" value="false" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"Downloaded.Files.Path.Enabled": "false",
|
||||
"Gradle.Build EntityLib.executor": "Run",
|
||||
"Gradle.EntityLib [dependencies].executor": "Run",
|
||||
"Gradle.EntityLib [publish].executor": "Run",
|
||||
"Gradle.EntityLib:code-gen [:code-gen:Main.main()].executor": "Run",
|
||||
"Gradle.EntityLib:test-plugin [publish].executor": "Run",
|
||||
"Gradle.EntityLib:test-plugin [runServer].executor": "Run",
|
||||
"Gradle.EntityLib:test-plugin [shadowJar].executor": "Run",
|
||||
"Repository.Attach.Annotations": "false",
|
||||
"Repository.Attach.JavaDocs": "false",
|
||||
"Repository.Attach.Sources": "false",
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"WebServerToolWindowFactoryState": "false",
|
||||
"git-widget-placeholder": "master",
|
||||
"ignore.virus.scanning.warn.message": "true",
|
||||
"jdk.selected.JAVA_MODULE": "corretto-17",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "/mnt/sda2/Github/EntityLib",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"node.js.selected.package.tslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"project.structure.last.edited": "Project",
|
||||
"project.structure.proportion": "0.15",
|
||||
"project.structure.side.proportion": "0.2",
|
||||
"settings.editor.selected.configurable": "preferences.pluginManager",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"Downloaded.Files.Path.Enabled": "false",
|
||||
"Gradle.Build EntityLib.executor": "Run",
|
||||
"Gradle.EntityLib [dependencies].executor": "Run",
|
||||
"Gradle.EntityLib [publish].executor": "Run",
|
||||
"Gradle.EntityLib:code-gen [:code-gen:Main.main()].executor": "Run",
|
||||
"Gradle.EntityLib:test-plugin [publish].executor": "Run",
|
||||
"Gradle.EntityLib:test-plugin [runServer].executor": "Run",
|
||||
"Gradle.EntityLib:test-plugin [shadowJar].executor": "Run",
|
||||
"Repository.Attach.Annotations": "false",
|
||||
"Repository.Attach.JavaDocs": "false",
|
||||
"Repository.Attach.Sources": "false",
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"WebServerToolWindowFactoryState": "false",
|
||||
"git-widget-placeholder": "master",
|
||||
"ignore.virus.scanning.warn.message": "true",
|
||||
"jdk.selected.JAVA_MODULE": "corretto-17",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "//wsl.localhost/Ubuntu/home/tofaa/Github/EntityLib",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"node.js.selected.package.tslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"project.structure.last.edited": "Project",
|
||||
"project.structure.proportion": "0.15",
|
||||
"project.structure.side.proportion": "0.2",
|
||||
"settings.editor.selected.configurable": "preferences.editor",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
},
|
||||
"keyToStringList": {
|
||||
"kotlin-gradle-user-dirs": [
|
||||
"/home/tofaa/.gradle"
|
||||
"keyToStringList": {
|
||||
"kotlin-gradle-user-dirs": [
|
||||
"/home/tofaa/.gradle"
|
||||
]
|
||||
}
|
||||
}</component>
|
||||
}]]></component>
|
||||
<component name="RecentsManager">
|
||||
<key name="CopyFile.RECENT_KEYS">
|
||||
<recent name="D:\Github\EntityLib\api\src\main\java\me\tofaa\entitylib\extras" />
|
||||
|
@ -312,6 +323,14 @@
|
|||
<workItem from="1714477887801" duration="3618000" />
|
||||
<workItem from="1714566597065" duration="351000" />
|
||||
<workItem from="1715283453023" duration="949000" />
|
||||
<workItem from="1715621781474" duration="1673000" />
|
||||
<workItem from="1715623728886" duration="900000" />
|
||||
<workItem from="1715624837981" duration="637000" />
|
||||
<workItem from="1715625940853" duration="108000" />
|
||||
<workItem from="1715627329632" duration="41000" />
|
||||
<workItem from="1715627440179" duration="1000" />
|
||||
<workItem from="1715634060575" duration="111000" />
|
||||
<workItem from="1715634183157" duration="1468000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
|
|
|
@ -3,5 +3,5 @@ dependencies {
|
|||
api 'org.jetbrains:annotations:24.0.0'
|
||||
|
||||
compileOnlyApi(adventureDependencies)
|
||||
compileOnlyApi 'com.github.retrooper.packetevents:api:2.2.1'
|
||||
compileOnlyApi 'com.github.retrooper.packetevents:api:2.3.0'
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package me.tofaa.entitylib;
|
|||
import com.github.retrooper.packetevents.PacketEventsAPI;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonParser;
|
||||
import me.tofaa.entitylib.utils.GithubUpdater;
|
||||
import org.jetbrains.annotations.Blocking;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -20,6 +21,7 @@ public final class APIConfig {
|
|||
private boolean platformLogger = false;
|
||||
private boolean defaultCommands = false;
|
||||
private boolean platformTracking = false;
|
||||
private boolean bstats = false;
|
||||
|
||||
public APIConfig(PacketEventsAPI<?> packetEvents) {
|
||||
this.packetEvents = packetEvents;
|
||||
|
@ -28,17 +30,13 @@ public final class APIConfig {
|
|||
@Blocking
|
||||
public boolean requiresUpdate() throws IOException {
|
||||
if (!checkForUpdates) return false;
|
||||
String urlString = "https://api.github.com/repos/Tofaa2/EntityLib/releases/latest";
|
||||
String version = EntityLib.getVersion();
|
||||
GithubUpdater updater = new GithubUpdater("Tofaa2", "EntityLib", EntityLib.getVersion());
|
||||
return !updater.isLatestVersion();
|
||||
}
|
||||
|
||||
URL url = new URL(urlString);
|
||||
JsonParser json = new JsonParser();
|
||||
InputStream stream = url.openStream();
|
||||
JsonArray array = json.parse(new InputStreamReader(stream)).getAsJsonArray();
|
||||
String latest = array.get(0).getAsJsonObject().get("tag_name").getAsString();
|
||||
|
||||
stream.close();
|
||||
return !version.equalsIgnoreCase(latest);
|
||||
public @NotNull APIConfig useBstats() {
|
||||
this.bstats = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public @NotNull APIConfig usePlatformLogger() {
|
||||
|
@ -99,4 +97,8 @@ public final class APIConfig {
|
|||
return platformTracking;
|
||||
}
|
||||
|
||||
public boolean shouldUseBstats() {
|
||||
return bstats;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
package me.tofaa.entitylib.utils;
|
||||
|
||||
import com.github.retrooper.packetevents.util.adventure.AdventureSerializer;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.jetbrains.annotations.Blocking;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
public final class GithubUpdater {
|
||||
|
||||
private final String org;
|
||||
private final String repo;
|
||||
private final String currentVersion;
|
||||
|
||||
public GithubUpdater(String org, String repo, String currentVersion) {
|
||||
this.org = org;
|
||||
this.repo = repo;
|
||||
this.currentVersion = currentVersion;
|
||||
}
|
||||
|
||||
@Blocking
|
||||
public boolean isLatestVersion() {
|
||||
String latest = getLatestVersion();
|
||||
return latest != null && latest.equals(currentVersion);
|
||||
}
|
||||
|
||||
|
||||
@Blocking
|
||||
public String getLatestVersion() {
|
||||
try {
|
||||
URL url = new URL("https://api.github.com/repos/" + org + "/" + repo + "/releases/latest");
|
||||
URLConnection connection = url.openConnection();
|
||||
connection.addRequestProperty("User-Agent", "Mozilla/5.0");
|
||||
InputStreamReader isr = new InputStreamReader(connection.getInputStream());
|
||||
BufferedReader reader = new BufferedReader(isr);
|
||||
String response = reader.readLine();
|
||||
JsonObject json = AdventureSerializer.getGsonSerializer().serializer().fromJson(response, JsonObject.class);
|
||||
reader.close();
|
||||
isr.close();
|
||||
if (json.has("name")) {
|
||||
return json.get("name").getAsString();
|
||||
}
|
||||
throw new IOException("Could not find name attribute in github api fetch");
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String getCurrentVersion() {
|
||||
return currentVersion;
|
||||
}
|
||||
|
||||
public String getOrg() {
|
||||
return org;
|
||||
}
|
||||
|
||||
public String getRepo() {
|
||||
return repo;
|
||||
}
|
||||
}
|
|
@ -59,6 +59,6 @@ allprojects {
|
|||
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi 'com.github.retrooper.packetevents:spigot:2.2.0'
|
||||
compileOnlyApi 'com.github.retrooper.packetevents:spigot:2.3.0'
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
dependencies {
|
||||
api(project(":common"))
|
||||
compileOnly('com.github.retrooper.packetevents:spigot:2.0.2')
|
||||
compileOnly('com.github.retrooper.packetevents:spigot:2.3.0')
|
||||
compileOnly('org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT')
|
||||
}
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
package me.tofaa.entitylib.spigot;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEventsAPI;
|
||||
import io.github.retrooper.packetevents.bstats.Metrics;
|
||||
import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder;
|
||||
import me.tofaa.entitylib.APIConfig;
|
||||
import me.tofaa.entitylib.EntityLib;
|
||||
import me.tofaa.entitylib.TrackedEntity;
|
||||
import me.tofaa.entitylib.common.AbstractPlatform;
|
||||
import me.tofaa.entitylib.utils.ConcurrentWeakIdentityHashMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -37,6 +42,11 @@ public class SpigotEntityLibPlatform extends AbstractPlatform<JavaPlugin> {
|
|||
handle.getServer().getPluginManager().registerEvents(listener, handle);
|
||||
api.getPacketEvents().getEventManager().registerListener(listener);
|
||||
}
|
||||
if (settings.shouldUseBstats()) {
|
||||
PacketEventsAPI<Plugin> pe = (PacketEventsAPI<Plugin>)api.getPacketEvents();
|
||||
Metrics metrics = new Metrics((JavaPlugin) pe.getPlugin(), 21916);
|
||||
metrics.addCustomChart(new Metrics.SimplePie("entitylib-version", EntityLib::getVersion));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -15,6 +15,6 @@ java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
|||
|
||||
dependencies {
|
||||
api(project(":common"))
|
||||
compileOnly('com.github.retrooper.packetevents:velocity:2.0.2')
|
||||
compileOnly('com.github.retrooper.packetevents:velocity:2.3.0')
|
||||
compileOnly 'com.velocitypowered:velocity-api:3.3.0-SNAPSHOT'
|
||||
}
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
package me.tofaa.entitylib.velocity;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEventsAPI;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerBlockAction;
|
||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerBlockChange;
|
||||
import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import io.github.retrooper.packetevents.bstats.Metrics;
|
||||
import io.github.retrooper.packetevents.velocity.factory.VelocityPacketEventsBuilder;
|
||||
import me.tofaa.entitylib.APIConfig;
|
||||
import me.tofaa.entitylib.EntityLibAPI;
|
||||
import me.tofaa.entitylib.common.AbstractPlatform;
|
||||
|
@ -24,6 +31,15 @@ public class VelocityEntityLibPlatform extends AbstractPlatform<ProxyServer> {
|
|||
this.api = new VelocityEntityLibAPI(this, settings);
|
||||
this.api.onLoad();
|
||||
this.api.onEnable();
|
||||
// if (settings.shouldUseBstats()) {
|
||||
// VelocityPacketEventsBuilder
|
||||
// PacketEventsAPI<PluginContainer> pe = (PacketEventsAPI<PluginContainer>) api.getPacketEvents();
|
||||
// Metrics metrics = Metrics.createInstance(
|
||||
// plugin,
|
||||
// handle,
|
||||
// logger,
|
||||
// pe.getSettings().
|
||||
// }
|
||||
}
|
||||
|
||||
public Object getPlugin() {
|
||||
|
|
Loading…
Reference in a new issue