Skip to content

Commit 50225a2

Browse files
committed
1.2
- Added update check - /info now calculates world size so it's live - [Internal] changed package name
1 parent ead053e commit 50225a2

File tree

8 files changed

+107
-76
lines changed

8 files changed

+107
-76
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
.idea/
22
target/
3-
AnarchyStats.iml

pom.xml

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,26 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66

7-
<groupId>hyperdefined.anarchystats</groupId>
7+
<groupId>lol.hyper</groupId>
88
<artifactId>anarchystats</artifactId>
9-
<version>1.1</version>
9+
<version>1.2</version>
1010
<packaging>jar</packaging>
1111

1212
<name>AnarchyStats</name>
1313

1414
<properties>
15-
<java.version>1.8</java.version>
1615
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1717
</properties>
1818

19-
<build>
20-
<defaultGoal>clean package</defaultGoal>
21-
<plugins>
22-
<plugin>
23-
<groupId>org.apache.maven.plugins</groupId>
24-
<artifactId>maven-compiler-plugin</artifactId>
25-
<version>3.7.0</version>
26-
<configuration>
27-
<source>${java.version}</source>
28-
<target>${java.version}</target>
29-
</configuration>
30-
</plugin>
31-
<plugin>
32-
<groupId>org.apache.maven.plugins</groupId>
33-
<artifactId>maven-shade-plugin</artifactId>
34-
<version>3.1.0</version>
35-
<executions>
36-
<execution>
37-
<phase>package</phase>
38-
<goals>
39-
<goal>shade</goal>
40-
</goals>
41-
<configuration>
42-
<createDependencyReducedPom>false</createDependencyReducedPom>
43-
</configuration>
44-
</execution>
45-
</executions>
46-
</plugin>
47-
</plugins>
48-
<resources>
49-
<resource>
50-
<directory>src/main/resources</directory>
51-
<filtering>true</filtering>
52-
</resource>
53-
</resources>
54-
</build>
55-
5619
<repositories>
5720
<repository>
5821
<id>spigotmc-repo</id>
5922
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
6023
</repository>
6124
<repository>
62-
<id>sonatype</id>
63-
<url>https://oss.sonatype.org/content/groups/public/</url>
25+
<id>CodeMC</id>
26+
<url>https://repo.codemc.org/repository/maven-public</url>
6427
</repository>
6528
</repositories>
6629

@@ -72,4 +35,25 @@
7235
<scope>provided</scope>
7336
</dependency>
7437
</dependencies>
38+
39+
<build>
40+
<defaultGoal>clean package</defaultGoal>
41+
<plugins>
42+
<plugin>
43+
<groupId>org.apache.maven.plugins</groupId>
44+
<artifactId>maven-compiler-plugin</artifactId>
45+
<version>3.8.1</version>
46+
<configuration>
47+
<source>11</source>
48+
<target>11</target>
49+
</configuration>
50+
</plugin>
51+
</plugins>
52+
<resources>
53+
<resource>
54+
<directory>src/main/resources</directory>
55+
<filtering>true</filtering>
56+
</resource>
57+
</resources>
58+
</build>
7559
</project>

src/main/java/hyperdefined/anarchystats/AnarchyStats.java

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package lol.hyper.anarchystats;
2+
3+
import org.bukkit.plugin.java.JavaPlugin;
4+
5+
import java.util.logging.Logger;
6+
7+
public class AnarchyStats extends JavaPlugin {
8+
9+
private static AnarchyStats anarchyStats;
10+
11+
public String worldSize;
12+
13+
public static AnarchyStats getInstance() {
14+
return anarchyStats;
15+
}
16+
17+
@Override
18+
public void onEnable() {
19+
anarchyStats = this;
20+
Logger logger = this.getLogger();
21+
22+
new Updater(this, 66089).getVersion(version -> {
23+
if (this.getDescription().getVersion().equalsIgnoreCase(version)) {
24+
logger.info("There is not a new update available.");
25+
} else {
26+
logger.info("There is a new update available!");
27+
}
28+
});
29+
getWorldSize();
30+
31+
this.getCommand("info").setExecutor(new CommandStats());
32+
}
33+
34+
@Override
35+
public void onDisable() {
36+
37+
}
38+
39+
public void getWorldSize() {
40+
worldSize = WorldSize.humanReadableByteCount(WorldSize.getWorldSize(WorldSize.WORLD, WorldSize.WORLD_NETHER, WorldSize.WORLD_THE_END), false);
41+
}
42+
}

src/main/java/hyperdefined/anarchystats/CommandStats.java renamed to src/main/java/lol/hyper/anarchystats/CommandStats.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package hyperdefined.anarchystats;
1+
package lol.hyper.anarchystats;
22

33
import org.bukkit.Bukkit;
44
import org.bukkit.ChatColor;
@@ -9,7 +9,8 @@
99
public class CommandStats implements CommandExecutor {
1010
@Override
1111
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
12-
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&b-------------------------------\n&7Total Players: &b" + Bukkit.getOfflinePlayers().length + "&7.\n&7World Size: &b" + WorldSize.humanReadableByteCount(AnarchyStats.getInstance().worldSize, false) + "&7.\n&b-------------------------------"));
12+
Bukkit.getScheduler().runTaskAsynchronously(AnarchyStats.getInstance(), () -> AnarchyStats.getInstance().getWorldSize());
13+
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&b-------------------------------\n&7Total Players: &b" + Bukkit.getOfflinePlayers().length + "&7.\n&7World Size: &b" + AnarchyStats.getInstance().worldSize + "&7.\n&b-------------------------------"));
1314
return true;
1415
}
1516
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package lol.hyper.anarchystats;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.plugin.Plugin;
5+
import org.bukkit.util.Consumer;
6+
7+
import java.io.IOException;
8+
import java.io.InputStream;
9+
import java.net.URL;
10+
import java.util.Scanner;
11+
12+
public class Updater {
13+
private final Plugin plugin;
14+
private final int resourceId;
15+
16+
public Updater(Plugin plugin, int resourceId) {
17+
this.plugin = plugin;
18+
this.resourceId = resourceId;
19+
}
20+
21+
public void getVersion(final Consumer<String> consumer) {
22+
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
23+
try (InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId).openStream();
24+
Scanner scanner = new Scanner(inputStream)) {
25+
if (scanner.hasNext()) {
26+
consumer.accept(scanner.next());
27+
}
28+
} catch (IOException exception) {
29+
this.plugin.getLogger().info("Cannot look for updates: " + exception.getMessage());
30+
}
31+
});
32+
}
33+
}

src/main/java/hyperdefined/anarchystats/WorldSize.java renamed to src/main/java/lol/hyper/anarchystats/WorldSize.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package hyperdefined.anarchystats;
1+
package lol.hyper.anarchystats;
22

33
import java.io.IOException;
44
import java.nio.file.*;

src/main/resources/plugin.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: AnarchyStats
22
version: ${project.version}
3-
main: hyperdefined.anarchystats.AnarchyStats
4-
api-version: 1.15
3+
main: lol.hyper.anarchystats.AnarchyStats
4+
api-version: "1.15"
55
load: STARTUP
66
authors: [hyperdefined]
77
commands:

0 commit comments

Comments
 (0)