Skip to content

Commit

Permalink
Add stats (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
LunarClientBot committed Sep 12, 2023
1 parent a78e00c commit 95a9a45
Show file tree
Hide file tree
Showing 10 changed files with 459 additions and 0 deletions.
9 changes: 9 additions & 0 deletions api/src/main/java/com/lunarclient/apollo/ApolloPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package com.lunarclient.apollo;

import com.lunarclient.apollo.stats.ApolloStats;
import org.jetbrains.annotations.ApiStatus;

/**
Expand All @@ -41,6 +42,14 @@ public interface ApolloPlatform {
*/
Kind getKind();

/**
* Returns the platform stats.
*
* @return the platform stats
* @since 1.0.0
*/
ApolloStats getStats();

/**
* Represents the kind of server a platform is.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* This file is part of Apollo, licensed under the MIT License.
*
* Copyright (c) 2023 Moonsworth
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.lunarclient.apollo.stats;

import java.util.List;
import lombok.Builder;
import lombok.Getter;
import lombok.ToString;

/**
* Represents a single plugin used for stats.
*
* @since 1.0.0
*/
@Getter
@Builder
@ToString // TODO: remove
public class ApolloPluginDescription {

/**
* Returns the plugin {@link String} name.
*
* @return the plugin name
* @since 1.0.0
*/
String name;

/**
* Returns the plugin {@link String} description.
*
* @return the plugin description
* @since 1.0.0
*/
String description;

/**
* Returns the plugin {@link List} of {@link String} authors.
*
* @return the plugin authors
* @since 1.0.0
*/
List<String> authors;

/**
* Returns the plugin {@link String} version.
*
* @return the plugin version
* @since 1.0.0
*/
String version;

}
85 changes: 85 additions & 0 deletions api/src/main/java/com/lunarclient/apollo/stats/ApolloStats.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* This file is part of Apollo, licensed under the MIT License.
*
* Copyright (c) 2023 Moonsworth
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.lunarclient.apollo.stats;

import java.util.List;
import org.jetbrains.annotations.ApiStatus;

/**
* Represents a player on Apollo.
*
* @since 1.0.0
*/
@ApiStatus.NonExtendable
public interface ApolloStats {

/**
* Gets the servers message of the day (MOTD).
*
* @return the servers message of the day
* @since 1.0.0
*/
String getMotd();

/**
* Gets the servers icon (Base64).
*
* @return the servers icon
* @since 1.0.0
*/
String getIcon();

/**
* Gets the servers version.
*
* @return the servers version
* @since 1.0.0
*/
String getVersion();

/**
* Gets the servers plugin list.
*
* @return the servers plugin list
* @since 1.0.0
*/
List<ApolloPluginDescription> getPlugins();

/**
* Gets the servers platform type (Bukkit, BungeeCord, Velocity...).
*
* @return the servers platform type
* @since 1.0.0
*/
String getPlatformType();

/**
* Gets the servers platform version.
*
* @return the servers platform version
* @since 1.0.0
*/
String getPlatformVersion();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* This file is part of Apollo, licensed under the MIT License.
*
* Copyright (c) 2023 Moonsworth
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.lunarclient.apollo.stats;

import com.lunarclient.apollo.Apollo;
import com.lunarclient.apollo.option.Option;
import com.lunarclient.apollo.option.SimpleOption;
import io.leangen.geantyref.TypeToken;

/**
* Manages Apollo statistics.
*
* @since 1.0.0
*/
public final class ApolloStatsManager {

private static final String CONFIG_PREFIX = "mcstats";

public static final SimpleOption<Boolean> SERVER_IP = Option.<Boolean>builder()
.comment("Set to 'true' to send your server IP address to MCStats, otherwise 'false'.")
.node(CONFIG_PREFIX + "server-address").type(TypeToken.get(Boolean.class))
.defaultValue(true).build();

/**
* Constructs the {@link ApolloStatsManager}.
*
* @since 1.0.0
*/
public ApolloStatsManager() {
this.handleServerStartStats();
}

private void handleServerStartStats() {
ApolloStats stats = Apollo.getPlatform().getStats();

// Request
System.out.println(stats.getMotd());
System.out.println(stats.getIcon());
System.out.println(stats.getVersion());
System.out.println(stats.getPlugins());
System.out.println(stats.getPlatformType());
System.out.println(stats.getPlatformVersion());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@
import com.lunarclient.apollo.module.waypoint.WaypointModule;
import com.lunarclient.apollo.module.waypoint.WaypointModuleImpl;
import com.lunarclient.apollo.player.ApolloPlayerManagerImpl;
import com.lunarclient.apollo.stats.ApolloStats;
import com.lunarclient.apollo.world.ApolloWorldManagerImpl;
import com.lunarclient.apollo.wrapper.BukkitApolloPlayer;
import com.lunarclient.apollo.wrapper.BukkitApolloStats;
import com.lunarclient.apollo.wrapper.BukkitApolloWorld;
import lombok.Getter;
import org.bukkit.entity.Player;
Expand All @@ -85,9 +87,12 @@ public final class ApolloBukkitPlatform extends JavaPlugin implements ApolloPlat

@Getter private static ApolloBukkitPlatform instance;

private ApolloStats stats;

@Override
public void onEnable() {
ApolloBukkitPlatform.instance = this;
this.stats = new BukkitApolloStats();
ApolloManager.bootstrap(this);

this.getServer().getPluginManager().registerEvents(this, this);
Expand Down Expand Up @@ -137,6 +142,11 @@ public Kind getKind() {
return Kind.SERVER;
}

@Override
public ApolloStats getStats() {
return this.stats;
}

@EventHandler
private void onWorldLoad(WorldLoadEvent event) {
((ApolloWorldManagerImpl) Apollo.getWorldManager()).addWorld(new BukkitApolloWorld(event.getWorld()));
Expand Down
Loading

0 comments on commit 95a9a45

Please sign in to comment.