Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#89: Removed relocation checking #106

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,25 @@ This repository contains the code for all Java-based Metrics classes.

## Code Generation

The recommended way to include the Metrics classes is to use a build management tool like Gradle or Maven and
shade + relocate the required classes.
### Old way (pre 1.16)

~~The recommended way to include the Metrics classes is to use a build management tool like Gradle or Maven and
shade + relocate the required classes.~~

### New way (1.16 and later)

Since API 1.16, spigot implemented new solution to make plugins lighter. In order to get this library working, just add
it to `libraries` section of `plugin.yml` file and server will automatically download the dependency from Maven Central
and link it to all plugins that uses it.

```
libraries:
- org.bstats:bstats:3.0.0
```

Reference: [Click here](https://www.spigotmc.org/wiki/plugin-yml/#optional-attributes) (scroll a bit down).

---

However, to make bStats more accessible for beginners, a single file Metrics class is automatically generated on every
release and pushed to the `single-file` branch. This file can simply be copy-and-pasted.
Expand All @@ -30,4 +47,4 @@ For the GitHub Actions to properly work, one must configure the following [encry
* `OSSRH_USERNAME`: The username used to publish the Maven Central
* `OSSRH_TOKEN`: The password used to publish to Maven Central
* `SIGNING_KEY`: The PGP private key used to sign the built artifacts (can be obtained by running `gpg --export-secret-keys -a <key-id> > key.txt`)
* `SIGNING_PASSWORD`: The passphrase that protects the private key
* `SIGNING_PASSWORD`: The passphrase that protects the private key
3 changes: 1 addition & 2 deletions base/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ java {

tasks.test {
systemProperty("metrics-version", version.toString())
systemProperty("bstats.relocatecheck", "false")
}
}
19 changes: 0 additions & 19 deletions base/src/main/java/org/bstats/MetricsBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ public MetricsBase(
this.logSentData = logSentData;
this.logResponseStatusText = logResponseStatusText;

checkRelocation();

if (enabled) { // WARNING: Removing the option to opt-out will get your plugin banned from bStats
startSubmitting();
}
Expand Down Expand Up @@ -205,23 +203,6 @@ private void sendData(JsonObjectBuilder.JsonObject data) throws Exception {
}
}

/**
* Checks that the class was properly relocated.
*/
private void checkRelocation() {
// You can use the property to disable the check in your test environment
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
// Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D
final String defaultPackage = new String(
new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's'});
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
// We want to make sure no one just copy & pastes the example and uses the wrong package names
if (MetricsBase.class.getPackage().getName().startsWith(defaultPackage) || MetricsBase.class.getPackage().getName().startsWith(examplePackage)) {
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
}
}
}

/**
* Gzips the given string.
*
Expand Down
31 changes: 0 additions & 31 deletions base/src/test/java/org/bstats/RelocateCheckTest.java

This file was deleted.