Skip to content

Commit

Permalink
2.5-RC-dev-2
Browse files Browse the repository at this point in the history
  • Loading branch information
Karlatemp committed May 10, 2021
1 parent 068ab11 commit ca086e2
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 131 deletions.
2 changes: 1 addition & 1 deletion LuckPerms
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def lpVersion = ({

def getGitVersion = { String path ->
def proc = new ProcessBuilder("git", "rev-parse", "HEAD")
.directory(new File(path))
.directory(new File(rootProject.projectDir, path))
.start()
proc.waitFor()
def line = proc.inputStream.withReader { it.readLine() }
Expand All @@ -46,7 +46,7 @@ println("GitVersion = $gitVersion")
println("LpGVersion = $gitLpVersion")

// [LP-Mirai version]-[LuckPerms version]
def lpMiraiVer = '2.5-RC-dev-1'
def lpMiraiVer = '2.5-RC-dev-2'
def ver = lpMiraiVer + '+' + lpVersion

allprojects {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
131 changes: 64 additions & 67 deletions patchs.patch
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
diff --git a/api/src/main/java/net/luckperms/api/platform/Platform.java b/api/src/main/java/net/luckperms/api/platform/Platform.java
index 9ed38bee..5e64324e 100644
--- a/api/src/main/java/net/luckperms/api/platform/Platform.java
+++ b/api/src/main/java/net/luckperms/api/platform/Platform.java
@@ -75,7 +75,8 @@ public interface Platform {
SPONGE("Sponge"),
NUKKIT("Nukkit"),
VELOCITY("Velocity"),
- FABRIC("Fabric");
+ FABRIC("Fabric"),
+ MIRAI_CONSOLE("Mirai Console");

private final String friendlyName;

diff --git a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiPlatform.java b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiPlatform.java
index d19884c7..1c5d918c 100644
--- a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiPlatform.java
Expand All @@ -13,7 +27,7 @@ index d19884c7..1c5d918c 100644
}

diff --git a/common/src/main/java/me/lucko/luckperms/common/command/CommandManager.java b/common/src/main/java/me/lucko/luckperms/common/command/CommandManager.java
index fc61cafd..f4ce4332 100644
index dbb9da18..15739672 100644
--- a/common/src/main/java/me/lucko/luckperms/common/command/CommandManager.java
+++ b/common/src/main/java/me/lucko/luckperms/common/command/CommandManager.java
@@ -84,6 +84,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -50,7 +64,7 @@ index fc61cafd..f4ce4332 100644
return this.plugin;
}

+ protected CommandResult preExecute(Sender sender, String label, List<String> arguments) {
+ protected Object preExecute(Sender sender, String label, List<String> arguments) {
+ return null;
+ }
+ protected boolean shouldRenderVersion(Sender sender, boolean hasPermAny, boolean isFirstTime) {
Expand All @@ -63,49 +77,58 @@ index fc61cafd..f4ce4332 100644
public TabCompletions getTabCompletions() {
return this.tabCompletions;
}
@@ -208,10 +223,22 @@ public class CommandManager {
@@ -207,10 +222,25 @@ public class CommandManager {
}

private CommandResult execute(Sender sender, String label, List<String> arguments) {
private void execute(Sender sender, String label, List<String> arguments) {
+ {
+ CommandResult result = preExecute(sender, label, arguments);
+ if (result != null) return result;
+ Object result = preExecute(sender, label, arguments);
+ if (result != null) return;
+ }
applyConvenienceAliases(arguments, true);

// Handle no arguments
if (arguments.isEmpty() || arguments.size() == 1 && arguments.get(0).trim().isEmpty()) {
+ boolean hasPermAny = hasPermissionForAny(sender);
+ boolean isFirstTime = false;
+ if (!hasPermAny) {
+ boolean lpm_hasAnyPermission = hasPermissionForAny(sender);
+ boolean lpm_isFirstTime = false;
+ if (!lpm_hasAnyPermission) {
+ Collection<? extends Group> groups = this.plugin.getGroupManager().getAll().values();
+ isFirstTime = groups.size() <= 1 && groups.stream().allMatch(g -> g.normalData().isEmpty());
+ if (groups.size() <= 1 && groups.stream().allMatch(g -> g.normalData().isEmpty())) {
+ lpm_isFirstTime = true;
+ }
+ }
+
+ if (shouldRenderVersion(sender, hasPermAny, isFirstTime))
+ if (shouldRenderVersion(sender, lpm_hasAnyPermission, lpm_isFirstTime)) {
+
sender.sendMessage(Message.prefixed(Component.text()
.color(NamedTextColor.DARK_GREEN)
.append(Component.text("Running "))
@@ -221,15 +248,15 @@ public class CommandManager {
@@ -220,16 +250,21 @@ public class CommandManager {
.append(Message.FULL_STOP)
));

- if (hasPermissionForAny(sender)) {
+ if (hasPermAny) {
+ }
+
+ if (lpm_hasAnyPermission) {
Message.VIEW_AVAILABLE_COMMANDS_PROMPT.send(sender, label);
return CommandResult.SUCCESS;
return;
}

- Collection<? extends Group> groups = this.plugin.getGroupManager().getAll().values();
- if (groups.size() <= 1 && groups.stream().allMatch(g -> g.normalData().isEmpty())) {
+ if (isFirstTime) {
+ if (lpm_isFirstTime) {
Message.FIRST_TIME_SETUP.send(sender, label, sender.getName());
} else {
+ if (shouldRendNoPermsForSubCommands(sender))
+ if (shouldRendNoPermsForSubCommands(sender)) {
+
Message.NO_PERMISSION_FOR_SUBCOMMANDS.send(sender);
+
+ }
}
return CommandResult.NO_PERMISSION;
@@ -292,14 +319,6 @@ public class CommandManager {
return;
}
@@ -287,14 +322,6 @@ public class CommandManager {
}

private void sendCommandUsage(Sender sender, String label) {
Expand Down Expand Up @@ -145,19 +168,33 @@ index ebf9f665..5b962955 100644
USER("/%s user <user>"),
GROUP("/%s group <group>"),
diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/EditorCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/EditorCommand.java
index c0fbbdcd..68118f6d 100644
index 3542ca1a..fa5432a3 100644
--- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/EditorCommand.java
+++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/EditorCommand.java
@@ -106,6 +106,7 @@ public class EditorCommand extends SingleCommand {
}
@@ -106,6 +106,8 @@ public class EditorCommand extends SingleCommand {

Message.EDITOR_START.send(sender);
+ sender.flush();

return WebEditorRequest.generate(holders, tracks, sender, label, plugin)
+ sender.flush();
+
WebEditorRequest.generate(holders, tracks, sender, label, plugin)
.createSession(plugin, sender);
}
diff --git a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java
index 1c4a2720..c96759bd 100644
--- a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java
+++ b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java
@@ -690,7 +690,7 @@ public final class ConfigKeys {
/**
* A list of the keys defined in this class.
*/
- private static final List<SimpleConfigKey<?>> KEYS = KeyedConfiguration.initialise(ConfigKeys.class);
+ private static List<SimpleConfigKey<?>> KEYS = KeyedConfiguration.initialise(ConfigKeys.class);

public static List<? extends ConfigKey<?>> getKeys() {
return KEYS;
diff --git a/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java b/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java
index 7cbee16a..603ad484 100644
index 7cbee16a..7f79c2ef 100644
--- a/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java
+++ b/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java
@@ -49,6 +49,7 @@ import java.util.Map;
Expand All @@ -168,56 +205,16 @@ index 7cbee16a..603ad484 100644

/**
* Loads and manages runtime dependencies for the plugin.
@@ -121,10 +122,12 @@ public class DependencyManager {
public void loadDependencies(Set<Dependency> dependencies) {
CountDownLatch latch = new CountDownLatch(dependencies.size());

+ AtomicBoolean downloading = new AtomicBoolean(false);
+
for (Dependency dependency : dependencies) {
this.plugin.getBootstrap().getScheduler().async().execute(() -> {
try {
- loadDependency(dependency);
+ loadDependency(dependency, downloading);
} catch (Throwable e) {
this.plugin.getLogger().severe("Unable to load dependency " + dependency.name() + ".", e);
} finally {
@@ -140,12 +143,12 @@ public class DependencyManager {
}
}

- private void loadDependency(Dependency dependency) throws Exception {
+ private void loadDependency(Dependency dependency, AtomicBoolean downloading) throws Exception {
if (this.loaded.containsKey(dependency)) {
return;
}

- Path file = remapDependency(dependency, downloadDependency(dependency));
+ Path file = remapDependency(dependency, downloadDependency(dependency, downloading));

this.loaded.put(dependency, file);

@@ -154,7 +157,7 @@ public class DependencyManager {
}
}

- private Path downloadDependency(Dependency dependency) throws DependencyDownloadException {
+ private Path downloadDependency(Dependency dependency, AtomicBoolean downloading) throws DependencyDownloadException {
Path file = this.cacheDirectory.resolve(dependency.getFileName() + ".jar");

// if the file already exists, don't attempt to re-download it.
@@ -167,6 +170,9 @@ public class DependencyManager {
@@ -167,6 +168,7 @@ public class DependencyManager {
// attempt to download the dependency from each repo in order.
for (DependencyRepository repo : DependencyRepository.values()) {
try {
+ if (downloading.compareAndSet(false, true)) {
+ plugin.getLogger().info("Downloading dependencies.... Please wait....");
+ }
+ plugin.getLogger().info("Downloading dependency: " + dependency + ", " + file.getFileName() + " from " + repo);
repo.download(dependency, file);
return file;
} catch (DependencyDownloadException e) {
diff --git a/common/src/main/java/me/lucko/luckperms/common/locale/Message.java b/common/src/main/java/me/lucko/luckperms/common/locale/Message.java
index dfdd8858..8f6b43a7 100644
index f6c51ae5..ddd8ab5c 100644
--- a/common/src/main/java/me/lucko/luckperms/common/locale/Message.java
+++ b/common/src/main/java/me/lucko/luckperms/common/locale/Message.java
@@ -1347,8 +1347,7 @@ public interface Message {
Expand Down
18 changes: 18 additions & 0 deletions src/main/kotlin/io/github/karlatemp/luckperms/mirai/LPMConfigs.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2018-2021 Karlatemp. All rights reserved.
* @author Karlatemp <[email protected]> <https://github.com/Karlatemp>
*
* LuckPerms-Mirai/LuckPerms-Mirai.main/LPMConfigs.kt
*
* Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link.
*
* https://github.com/Karlatemp/LuckPerms-Mirai/blob/master/LICENSE
*/

package io.github.karlatemp.luckperms.mirai

import me.lucko.luckperms.common.config.generic.key.ConfigKeyFactory.booleanKey

object LPMConfigs {
val FIX_CONTEXT_TYPO = booleanKey("luckperms-mirai.fix-old-context-typo", false)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ import io.github.karlatemp.luckperms.mirai.internal.LPPermissionService
import io.github.karlatemp.luckperms.mirai.internal.OpenApiImpl
import io.github.karlatemp.luckperms.mirai.logging.MiraiPluginLogger
import io.github.karlatemp.luckperms.mirai.openapi.internal.BackendImpl
import me.lucko.luckperms.common.config.ConfigKeys
import me.lucko.luckperms.common.config.generic.key.SimpleConfigKey
import me.lucko.luckperms.common.plugin.bootstrap.LuckPermsBootstrap
import me.lucko.luckperms.common.plugin.classpath.ClassPathAppender
import me.lucko.luckperms.common.plugin.logging.PluginLogger
import me.lucko.luckperms.common.plugin.scheduler.SchedulerAdapter
import net.luckperms.api.platform.Platform
import net.mamoe.mirai.console.MiraiConsole
import net.mamoe.mirai.console.extension.PluginComponentStorage
import net.mamoe.mirai.console.plugin.jvm.JvmPlugin
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescriptionBuilder
import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
import ninja.leaping.configurate.ConfigurationNode
Expand Down Expand Up @@ -99,7 +100,7 @@ object LPMiraiBootstrap : KotlinPlugin(
override fun getStartupTime(): Instant = startupTime0

override fun getType(): Platform.Type {
return Platform.Type.BUNGEECORD
return Platform.Type.MIRAI_CONSOLE
}

override fun getServerBrand(): String {
Expand Down Expand Up @@ -238,12 +239,15 @@ object LPMiraiBootstrap : KotlinPlugin(
}

init {
Platform.Type::class.java
.getDeclaredField("friendlyName")
.apply {
isAccessible = true
}
.set(Platform.Type.BUNGEECORD, "Mirai Console")

ConfigKeys::class.java.getDeclaredField("KEYS").let { keysField ->
keysField.isAccessible = true
val keys = ConfigKeys.getKeys().toMutableList()
var od = keys.maxOf { it.ordinal() } + 1
val additions = LPMConfigs::class.java.declaredFields.asSequence().onEach {
it.isAccessible = true
}.map { it[LPMConfigs] }.mapNotNull { it as? SimpleConfigKey<*> }.toList()
additions.forEach { it.setOrdinal(od); od++ }
keysField.set(null, keys.also { it.addAll(additions) }.toList())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import io.github.karlatemp.luckperms.mirai.internal.OpenApiImpl
import me.lucko.luckperms.common.api.LuckPermsApiProvider
import me.lucko.luckperms.common.calculator.CalculatorFactory
import me.lucko.luckperms.common.command.CommandManager
import me.lucko.luckperms.common.command.CommandResult
import me.lucko.luckperms.common.command.abstraction.Command
import me.lucko.luckperms.common.config.generic.adapter.ConfigurationAdapter
import me.lucko.luckperms.common.dependencies.Dependency
Expand Down Expand Up @@ -66,7 +65,6 @@ import java.nio.file.Path
import java.util.*
import java.util.concurrent.TimeUnit
import java.util.stream.Stream
import kotlin.collections.ArrayList

@OptIn(ConsoleExperimentalApi::class)
object LPMiraiPlugin : AbstractLuckPermsPlugin() {
Expand All @@ -93,7 +91,7 @@ object LPMiraiPlugin : AbstractLuckPermsPlugin() {
@OptIn(ExperimentalCommandDescriptors::class)
override fun registerCommands() {
val cm = object : CommandManager(this) {
override fun preExecute(sender: Sender?, label: String?, arguments: MutableList<String>?): CommandResult? {
override fun preExecute(sender: Sender?, label: String?, arguments: MutableList<String>?): Any? {
commandCaller.set((sender as WrappedLPSender).real)
return null
}
Expand Down Expand Up @@ -284,15 +282,19 @@ object LPMiraiPlugin : AbstractLuckPermsPlugin() {
}

private fun resolveConfig(): Path? {
LPMiraiBootstrap.dataFolder.mkdirs()
val path = this.bootstrap.configDirectory.resolve("luckperms.conf")
if (!Files.exists(path)) {
try {
MoreFiles.createDirectoriesIfNotExists(this.bootstrap.configDirectory)
javaClass.classLoader.getResourceAsStream("luckperms.conf")!!.use { `is` ->
Files.copy(
`is`,
path
)
val ccl = javaClass.classLoader
Files.newOutputStream(path).buffered().use { output ->
ccl.getResourceAsStream("luckperms-mirai.conf")!!.use { `is` ->
`is`.copyTo(output)
}
ccl.getResourceAsStream("luckperms.conf")!!.use { `is` ->
`is`.copyTo(output)
}
}
} catch (e: IOException) {
throw RuntimeException(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import me.lucko.luckperms.common.calculator.result.TristateResult
import me.lucko.luckperms.common.locale.TranslationManager
import me.lucko.luckperms.common.sender.Sender
import me.lucko.luckperms.common.sender.SenderFactory
import me.lucko.luckperms.common.verbose.VerboseCheckTarget
import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
Expand Down Expand Up @@ -76,7 +77,7 @@ class MiraiSenderFactory : SenderFactory<LPMiraiPlugin, Permittee>(
LPMiraiPlugin.permissionRegistry.offer(node)
if (sender is ConsoleCommandSender) {
LPMiraiPlugin.verboseHandler.offerPermissionCheckEvent(
PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK, "internal/console",
PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK, VerboseCheckTarget.internal("console"),
QueryOptions.nonContextual(), node, TristateResult.of(Tristate.TRUE)
)
return Tristate.TRUE
Expand Down
Loading

0 comments on commit ca086e2

Please sign in to comment.