Skip to content

Add the ability to check online for a new release #41

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

Open
wants to merge 10 commits into
base: feature/dump
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions anvil-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version = rootProject.apiVersion
dependencies {
api bson
api configurate_core
api(gson)
api(guice + ":" + guice_version)
api hikari
api jedis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Table;
import com.google.common.reflect.TypeToken;
import org.anvilpowered.anvil.api.Tristate;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.time.ZoneId;
Expand Down Expand Up @@ -193,6 +195,11 @@ public static Map<String, Key<?>> getAll(String nameSpace) {
.name("CACHE_INVALIDATION_TIMOUT_SECONDS")
.fallback(300)
.build();
public static final Key<Tristate> CHECK_VERSIONS =
Key.builder(TypeTokens.TRISTATE)
.name("CHECK_VERSIONS")
.fallback(Tristate.TRUE)
.build();
public static final Key<Boolean> USE_SHARED_ENVIRONMENT =
Key.builder(TypeTokens.BOOLEAN)
.name("USE_SHARED_ENVIRONMENT")
Expand Down Expand Up @@ -302,6 +309,11 @@ public static Map<String, Key<?>> getAll(String nameSpace) {
.sensitive()
.build();

public static final Key<String> DUMP_PERMISSION =
Key.builder(TypeTokens.STRING)
.name("DUMP_PERMISSION")
.fallback("anvil.admin.dump")
.build();
public static final Key<String> PLUGINS_PERMISSION =
Key.builder(TypeTokens.STRING)
.name("PLUGINS_PERMISSION")
Expand All @@ -327,6 +339,7 @@ public static Map<String, Key<?>> getAll(String nameSpace) {
.register(BASE_SCAN_PACKAGE)
.register(CACHE_INVALIDATION_INTERVAL_SECONDS)
.register(CACHE_INVALIDATION_TIMOUT_SECONDS)
.register(CHECK_VERSIONS)
.register(USE_SHARED_ENVIRONMENT)
.register(USE_SHARED_CREDENTIALS)
.register(DATA_DIRECTORY)
Expand All @@ -345,6 +358,7 @@ public static Map<String, Key<?>> getAll(String nameSpace) {
.register(REDIS_USE_AUTH);

startRegistration("anvil")
.register(DUMP_PERMISSION)
.register(PLUGINS_PERMISSION)
.register(REGEDIT_PERMISSION)
.register(RELOAD_PERMISSION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.anvilpowered.anvil.api.registry;

import com.google.common.reflect.TypeToken;
import org.anvilpowered.anvil.api.Tristate;

import java.time.ZoneId;

Expand All @@ -32,5 +33,6 @@ private TypeTokens() {
public static final TypeToken<Boolean> BOOLEAN = TypeToken.of(Boolean.class);
public static final TypeToken<Integer> INTEGER = TypeToken.of(Integer.class);
public static final TypeToken<String> STRING = TypeToken.of(String.class);
public static final TypeToken<Tristate> TRISTATE = TypeToken.of(Tristate.class);
public static final TypeToken<ZoneId> ZONE_ID = TypeToken.of(ZoneId.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ protected void setOptions(@Nullable ConfigurationOptions options) {
protected void withCore() {
setName(Keys.SERVER_NAME, "server.name");
setDescription(Keys.SERVER_NAME, "\nServer name");
setName(Keys.CHECK_VERSIONS, "server.checkUpdates");
setDescription(Keys.CHECK_VERSIONS, "\nWhether Anvil should check online for a new version.");
}

private void withDataStoreCore0() {
Expand Down
31 changes: 31 additions & 0 deletions anvil-api/src/main/kotlin/org/anvilpowered/anvil/api/Tristate.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.anvilpowered.anvil.api


/**
* Represents three possible states.
*
* [TRUE] A positive setting
* [FALSE] A negative setting
* [UNDEFINED] A non-existent setting
*/
enum class Tristate(state: Boolean?) {

/**
* Represents a positive state
*/
TRUE(true),

/**
* Represents a negative state
*/
FALSE(false),

/**
* Represents a non-existent state
*/
UNDEFINED(null);

val isTrue = state == true
val isFalse = state == false
val isUndefined = state == null
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ interface PluginInfo : Named {

val organizationName: String

val sourceUrl: String

val buildDate: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Anvil - AnvilPowered
* Copyright (C) 2020-2021
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.anvilpowered.anvil.api.util

import org.anvilpowered.anvil.api.Environment

interface InfoDumpService<TCommandSource> {

/**
* Publishes the registry data for all loaded environments to anvil servers
*
* @param source User to send the URL to
*/
suspend fun publishInfo(source: TCommandSource)

/**
* Publishes the registry data for all specific environments to anvil servers
*
* @param source User to send the URL to
* @param environments Environments to query registry data from
*/
suspend fun publishInfo(source: TCommandSource, vararg environments: Environment)
}
16 changes: 13 additions & 3 deletions anvil-bungee/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,26 @@ dependencies {
implementation javasisst
implementation(kotlin_reflect + ":" + kotlin_version)
implementation(kotlin_stdlib + ":" + kotlin_version)
implementation(kotlin_stdlib7 + ":" + kotlin_version)
implementation(kotlin_stdlib8 + ":" + kotlin_version)
implementation(kotlinx_coroutines)
implementation(kotlinx_coroutines_core)
implementation(kotlinx_coroutines_jvm)
implementation(kotlinx_serialization)
implementation(ktor_cio)
implementation(ktor_core)
implementation(ktor_http)
implementation(ktor_http_jvm)
implementation(ktor_network)
implementation(ktor_network_jvm)
implementation(ktor_utils)
implementation(kyori_api)
implementation(kyori_bungee_serializer)
implementation(kyori_examination)
implementation(kyori_key)
implementation(kyori_legacy_serializer)
implementation(kyori_gson_serializer)
implementation(kyori_plain_serializer)
implementation kotlinx_coroutines
implementation kotlinx_serialization
implementation microutils_logging
implementation mongo_java_driver
implementation typesafe_config
Expand Down Expand Up @@ -59,7 +69,7 @@ shadowJar {
include dependency(kotlin_reflect)
include dependency(kotlin_stdlib)
include dependency(kotlin_stdlib8)
include dependency(kotlinx_coroutines)
include dependency(kotlinx_coroutines_core)
include dependency(kotlinx_serialization)
include dependency(kyori_api)
include dependency(kyori_examination)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.anvilpowered.anvil.bungee.command

import com.google.inject.Inject
import kotlinx.coroutines.runBlocking
import net.md_5.bungee.api.CommandSender
import net.md_5.bungee.api.ProxyServer
import net.md_5.bungee.api.plugin.Command
Expand All @@ -39,7 +40,9 @@ class BungeeSimpleCommandService : CommonSimpleCommandService<CommandSender>() {
) : Command(primaryAlias, null, *otherAliases) {
override fun execute(source: CommandSender, context: Array<String>) {
if (delegate.canExecute(source)) {
delegate.execute(source, context)
runBlocking {
delegate.execute(source, context)
}
} else {
source.sendNoPermission()
}
Expand Down
2 changes: 2 additions & 0 deletions anvil-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ dependencies {
api("net.kyori:adventure-text-serializer-legacy:4.5.0")
api("net.kyori:adventure-text-serializer-plain:4.5.0")
api(configurate_hocon)
api(ktor_core)
api(ktor_cio)
api(kotlin_reflect + ":" + kotlin_version)
api(kotlin_stdlib + ":" + kotlin_version)
api(kotlin_stdlib8 + ":" + kotlin_version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.anvilpowered.anvil.api.registry.RegistryScope;
import org.anvilpowered.anvil.common.PlatformImpl;
import org.anvilpowered.anvil.common.module.PlatformModule;
import org.anvilpowered.anvil.common.util.VersionChecker;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.ArrayList;
Expand Down Expand Up @@ -138,6 +139,7 @@ protected void configure() {
.accept(injector.getInstance(entry.getKey()));
}
Registry registry = injector.getInstance(Registry.class);
registry.whenLoaded(injector.getInstance(VersionChecker.class)::checkVersion).register();
for (Consumer<Environment> listener
: loadedListeners.get(environment.getName())) {
registry.whenLoaded(() -> listener.accept(environment)).register();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class AnvilPluginInfo implements PluginInfo {
public static final String description = "A cross-platform Minecraft plugin framework";
public static final String url = "https://github.com/AnvilPowered/Anvil";
public static final String organizationName = "AnvilPowered";
public static final String sourceUrl = url;
public static final String[] authors = {organizationName};
public static final String buildDate = "$buildDate";
public Component pluginPrefix = Component.text()
Expand Down Expand Up @@ -71,8 +72,12 @@ public String[] getAuthors() {
public String getOrganizationName() {
return organizationName;
}

@Override
public String getSourceUrl() {
return sourceUrl;
}

@Override
public String getBuildDate() {
return buildDate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.anvilpowered.anvil.common.command.regedit.CommonRegistryEditCommandNo

class CommonAnvilCommandNode<TUser, TPlayer, TCommandSource> @Inject constructor(
private val commandService: SimpleCommandService<TCommandSource>,
private val dumpCommand: CommonAnvilDumpCommand<TCommandSource>,
private val pluginsCommand: CommonAnvilPluginsCommand<TCommandSource>,
private val reloadCommand: CommonAnvilReloadCommand<TCommandSource>,
private val callbackCommand: CommonCallbackCommand<TCommandSource>,
Expand All @@ -44,6 +45,7 @@ class CommonAnvilCommandNode<TUser, TPlayer, TCommandSource> @Inject constructor
}

val CALLBACK_ALIAS = listOf("callback")
val DUMP_ALIAS = listOf("dump")
val HELP_ALIAS = listOf("help")
val PLUGINS_ALIAS = listOf("plugins")
val RELOAD_ALIAS = listOf("reload")
Expand Down Expand Up @@ -71,6 +73,7 @@ class CommonAnvilCommandNode<TUser, TPlayer, TCommandSource> @Inject constructor
private fun loadCommands() {
val subCommands = listOf(
commandService.mapTerminal(HELP_ALIAS, commandService.generateHelp { anvilMapping.subCommands }),
commandService.mapTerminal(DUMP_ALIAS, dumpCommand),
commandService.mapTerminal(PLUGINS_ALIAS, pluginsCommand),
regeditNode.regeditMapping,
commandService.mapTerminal(RELOAD_ALIAS, reloadCommand),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Anvil - AnvilPowered
* Copyright (C) 2020
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/

package org.anvilpowered.anvil.common.command

import com.google.inject.Inject
import java.util.Optional
import java.util.stream.Collectors
import kotlinx.coroutines.runBlocking
import org.anvilpowered.anvil.api.Anvil
import org.anvilpowered.anvil.api.Environment
import org.anvilpowered.anvil.api.command.SimpleCommand
import org.anvilpowered.anvil.api.misc.Named
import org.anvilpowered.anvil.api.util.InfoDumpService
import org.anvilpowered.anvil.api.util.TextService

class CommonAnvilDumpCommand<TCommandSource> : SimpleCommand<TCommandSource> {

@Inject
private lateinit var dumpService: InfoDumpService<TCommandSource>

@Inject
private lateinit var textService: TextService<TCommandSource>

override fun execute(source: TCommandSource, context: Array<String>) {
if (context.isEmpty()) {
textService.builder()
.appendPrefix()
.red().append("Plugin is required if '--all' is not set")
.sendTo(source)
return
}
if ("-a" == context[0] || "--all" == context[0]) {
runBlocking {
dumpService.publishInfo(source)
}
return
} else {
runBlocking {
dumpDirect(source, context)
}
}
}

override fun suggest(source: TCommandSource, context: Array<String>): List<String> {
val suggestions = Anvil.getEnvironmentManager()
.environments.values.stream()
.map(Named::name)
.sorted().collect(Collectors.toList())
suggestions.add("--all")
return suggestions
}

private suspend fun dumpDirect(source: TCommandSource, plugins: Array<String>): Boolean {
val optionalEnvironments: MutableList<Optional<Environment>> = mutableListOf()
for (environment in Anvil.getEnvironmentManager().environments.values) {
if (plugins.contains(environment.name)) {
optionalEnvironments.add(Optional.of(environment))
}
}
if (optionalEnvironments.isEmpty()) {
textService.builder()
.appendPrefix()
.red().append("Could not find plugin(s) ")
.gold().append(plugins.joinToString(separator = " "))
.sendTo(source)
return false
}
val environments: MutableList<Environment> = mutableListOf()
for (env in optionalEnvironments) {
environments.add(env.get())
}
dumpService.publishInfo(source, *environments.toTypedArray())
return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
*/
package org.anvilpowered.anvil.common.command

import com.google.common.base.MoreObjects
import com.google.inject.Inject
import net.kyori.adventure.text.Component
import org.anvilpowered.anvil.api.Anvil
import org.anvilpowered.anvil.api.Environment
import org.anvilpowered.anvil.api.command.CommandMapping
import org.anvilpowered.anvil.api.command.SimpleCommand
Expand Down
Loading