Skip to content

Commit

Permalink
Merge branch '2022.3' into 2023.1
Browse files Browse the repository at this point in the history
  • Loading branch information
RedNesto committed Jul 2, 2023
2 parents c41d412 + c830dad commit 92105c6
Show file tree
Hide file tree
Showing 27 changed files with 754 additions and 103 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ kotlin.code.style=official
ideaVersion = 2023.1
ideaVersionName = 2023.1

coreVersion = 1.6.6
coreVersion = 1.6.7
downloadIdeaSources = true

pluginTomlVersion = 231.8109.1
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Minecraft Development for IntelliJ
</tr>
</table>

Info and Documentation [![Current Release](https://img.shields.io/badge/release-1.6.6-orange.svg?style=flat-square)](https://plugins.jetbrains.com/plugin/8327)
Info and Documentation [![Current Release](https://img.shields.io/badge/release-1.6.7-orange.svg?style=flat-square)](https://plugins.jetbrains.com/plugin/8327)
----------------------

<a href="https://discord.gg/j6UNcfr"><img src="https://i.imgur.com/JXu9C1G.png" height="48px"></img></a>
Expand Down
36 changes: 24 additions & 12 deletions src/main/kotlin/creator/PlatformVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ package com.demonwav.mcdev.creator
import com.demonwav.mcdev.platform.PlatformType
import com.demonwav.mcdev.update.PluginUtil
import com.demonwav.mcdev.util.fromJson
import com.demonwav.mcdev.util.mapFirstNotNull
import com.demonwav.mcdev.util.withSuppressed
import com.github.kittinunf.fuel.core.FuelError
import com.github.kittinunf.fuel.core.FuelManager
import com.github.kittinunf.fuel.core.requests.suspendable
import com.github.kittinunf.fuel.coroutines.awaitString
Expand All @@ -35,8 +38,20 @@ import java.net.Proxy
import java.net.URI
import kotlin.reflect.KClass

private const val CLOUDFLARE_BASE_URL = "https://minecraftdev.org/versions/"
// Cloudflare and GitHub are both global CDNs
// Cloudflare is used first / preferred simply due to domain preference
private const val CLOUDFLARE_BASE_URL = "https://mcdev.io/versions/"
// Directly retrieving the file via GitHub is the second option. In some regions / networks Cloudflare is blocked,
// but we may still be able to reach GitHub
private const val GITHUB_BASE_URL = "https://raw.githubusercontent.com/minecraft-dev/minecraftdev.org/master/versions/"
// Finally, there are apparently also regions / networks where both Cloudflare and GitHub is blocked.
// Or maybe the domain `mcdev.io` (and prior to that, `minecraftdev.org`) is blocked due to weird domain
// rules (perhaps blocking on the word "minecraft"). In one last ditch effort to retrieve the version json
// we can also pull from this host, a separate host using a separate domain. This is an OVH server, not
// proxied through Cloudflare.
private const val OVH_BASE_URL = "https://versions.denwav.com/versions/"

private val URLS = listOf(CLOUDFLARE_BASE_URL, GITHUB_BASE_URL, OVH_BASE_URL)

val PLATFORM_VERSION_LOGGER = logger<PlatformVersion>()

Expand All @@ -62,19 +77,16 @@ suspend fun <T : Any> getVersionJson(path: String, type: KClass<T>): T {
}

suspend fun getText(path: String): String {
return try {
// attempt cloudflare
doCall(CLOUDFLARE_BASE_URL + path)
} catch (e: IOException) {
PLATFORM_VERSION_LOGGER.warn("Failed to reach cloudflare URL ${CLOUDFLARE_BASE_URL + path}", e)
// if that fails, attempt github
var thrown: FuelError? = null
return URLS.mapFirstNotNull { url ->
try {
doCall(GITHUB_BASE_URL + path)
} catch (e: IOException) {
PLATFORM_VERSION_LOGGER.warn("Failed to reach fallback GitHub URL ${GITHUB_BASE_URL + path}", e)
throw e
doCall(url + path)
} catch (e: FuelError) {
PLATFORM_VERSION_LOGGER.warn("Failed to reach URL $url$path")
thrown = withSuppressed(thrown, e)
null
}
}
} ?: throw thrown!!
}

private suspend fun doCall(urlText: String): String {
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/insight/ColorLineMarkerProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package com.demonwav.mcdev.insight

import com.demonwav.mcdev.MinecraftSettings
import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler
import com.intellij.codeInsight.daemon.LineMarkerInfo
import com.intellij.codeInsight.daemon.LineMarkerProvider
Expand Down Expand Up @@ -52,7 +53,9 @@ class ColorLineMarkerProvider : LineMarkerProvider {
}

val identifier = element.toUElementOfType<UIdentifier>() ?: return null
val info = identifier.findColor { map, chosen -> ColorInfo(element, chosen.value, map, chosen.key, identifier) }
val info = runCatchingKtIdeaExceptions {
identifier.findColor { map, chosen -> ColorInfo(element, chosen.value, map, chosen.key, identifier) }
}
if (info != null) {
NavigateAction.setNavigateAction(info, "Change Color", null)
}
Expand Down Expand Up @@ -164,6 +167,7 @@ class ColorLineMarkerProvider : LineMarkerProvider {
}
}
}

is UCallExpression -> {
if (workElement.methodName == "hsvLike") {
val (h, s, v) = Color.RGBtoHSB(c.red, c.green, c.blue, null)
Expand Down
8 changes: 5 additions & 3 deletions src/main/kotlin/insight/ColorUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ import org.jetbrains.uast.generate.replace
import org.jetbrains.uast.resolveToUElement

fun <T> UIdentifier.findColor(function: (Map<String, Color>, Map.Entry<String, Color>) -> T): T? {
val parent = this.uastParent
val expression = parent as? UReferenceExpression ?: return null
return findColorFromExpression(expression, function)
return runCatchingKtIdeaExceptions {
val parent = this.uastParent
val expression = parent as? UReferenceExpression ?: return null
findColorFromExpression(expression, function)
}
}

private fun <T> findColorFromExpression(
Expand Down
11 changes: 2 additions & 9 deletions src/main/kotlin/insight/ListenerLineMarkerProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package com.demonwav.mcdev.insight

import com.demonwav.mcdev.MinecraftSettings
import com.demonwav.mcdev.asset.GeneralAssets
import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler
import com.intellij.codeInsight.daemon.LineMarkerInfo
import com.intellij.codeInsight.daemon.LineMarkerProviderDescriptor
Expand Down Expand Up @@ -51,19 +52,11 @@ class ListenerLineMarkerProvider : LineMarkerProviderDescriptor() {
return null
}

try {
runCatchingKtIdeaExceptions {
val identifier = element.toUElementOfType<UIdentifier>() ?: return null
if (identifier.uastParent !is UMethod || identifier.uastEventListener == null) {
return null
}
} catch (e: Exception) {
// Kotlin plugin is buggy and can throw exceptions here
// We do the check like this because we don't actually have this class on the classpath
if (e.javaClass.name == "org.jetbrains.kotlin.idea.caches.resolve.KotlinIdeaResolutionException") {
return null
}
// Don't swallow unexpected errors
throw e
}

// By this point, we can guarantee that the action of "go to declaration" will work
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/platform/bukkit/BukkitModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.demonwav.mcdev.util.createVoidMethodWithParameterType
import com.demonwav.mcdev.util.extendsOrImplements
import com.demonwav.mcdev.util.findContainingMethod
import com.demonwav.mcdev.util.nullable
import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions
import com.intellij.lang.jvm.JvmModifier
import com.intellij.openapi.project.Project
import com.intellij.psi.JavaPsiFacade
Expand Down Expand Up @@ -182,7 +183,7 @@ class BukkitModule<out T : AbstractModuleType<*>>(facet: MinecraftFacet, type: T
val identifier = element?.toUElementOfType<UIdentifier>()
?: return false

val psiClass = (identifier.uastParent as? UClass)?.javaPsi
val psiClass = runCatchingKtIdeaExceptions { (identifier.uastParent as? UClass)?.javaPsi }
?: return false

if (psiClass.hasModifier(JvmModifier.ABSTRACT)) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/platform/bungeecord/BungeeCordModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.demonwav.mcdev.util.SourceType
import com.demonwav.mcdev.util.addImplements
import com.demonwav.mcdev.util.extendsOrImplements
import com.demonwav.mcdev.util.nullable
import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions
import com.intellij.lang.jvm.JvmModifier
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.PsiClass
Expand Down Expand Up @@ -117,7 +118,7 @@ class BungeeCordModule<out T : AbstractModuleType<*>>(facet: MinecraftFacet, typ
val identifier = element?.toUElementOfType<UIdentifier>()
?: return false

val psiClass = (identifier.uastParent as? UClass)?.javaPsi
val psiClass = runCatchingKtIdeaExceptions { (identifier.uastParent as? UClass)?.javaPsi }
?: return false

val pluginInterface = JavaPsiFacade.getInstance(element.project)
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/platform/fabric/FabricModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.demonwav.mcdev.platform.fabric.reference.EntryPointReference
import com.demonwav.mcdev.platform.fabric.util.FabricConstants
import com.demonwav.mcdev.util.SourceType
import com.demonwav.mcdev.util.nullable
import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiMethod
Expand All @@ -54,7 +55,7 @@ class FabricModule internal constructor(facet: MinecraftFacet) : AbstractModule(
val identifier = element?.toUElementOfType<UIdentifier>()
?: return false

val parent = identifier.uastParent
val parent = runCatchingKtIdeaExceptions { identifier.uastParent }
if (parent !is UClass && parent !is UMethod) {
return false
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/platform/forge/ForgeModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.demonwav.mcdev.util.SourceType
import com.demonwav.mcdev.util.createVoidMethodWithParameterType
import com.demonwav.mcdev.util.extendsOrImplements
import com.demonwav.mcdev.util.nullable
import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions
import com.demonwav.mcdev.util.runWriteTaskLater
import com.demonwav.mcdev.util.waitForAllSmart
import com.intellij.json.JsonFileType
Expand Down Expand Up @@ -187,7 +188,7 @@ class ForgeModule internal constructor(facet: MinecraftFacet) : AbstractModule(f
val identifier = element?.toUElementOfType<UIdentifier>()
?: return false

val psiClass = identifier.uastParent as? UClass
val psiClass = runCatchingKtIdeaExceptions { identifier.uastParent as? UClass }
?: return false

return !psiClass.hasModifier(JvmModifier.ABSTRACT) &&
Expand Down
12 changes: 12 additions & 0 deletions src/main/kotlin/platform/forge/creator/asset-steps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ class ForgeProjectFilesStep(parent: NewProjectWizardStep) : AbstractLongRunningA
"src/main/resources/META-INF/mods.toml" to MinecraftTemplates.MODS_TOML_TEMPLATE,
)

val configTemplate = when {
mcVersion >= MinecraftVersions.MC1_20 -> MinecraftTemplates.FG3_1_20_CONFIG_TEMPLATE
else -> null
}

if (configTemplate != null) {
assets.addTemplates(
project,
"src/main/java/${mainPackageName.replace('.', '/')}/Config.java" to configTemplate,
)
}

assets.addLicense(project)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private class NewInsnSelector(
}

private fun classToMemberReference(value: String): MemberReference? {
val fqn = value.replace('/', '.').replace('$', '.')
val fqn = value.replace('/', '.')
if (fqn.isNotEmpty() && !fqn.startsWith('.') && !fqn.endsWith('.') && !fqn.contains("..")) {
if (StringUtil.isJavaIdentifier(fqn.replace('.', '_'))) {
return MemberReference("<init>", owner = fqn)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Minecraft Development for IntelliJ
*
* https://mcdev.io/
*
* Copyright (C) 2023 minecraft-dev
*
* 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, version 3.0 only.
*
* 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 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 com.demonwav.mcdev.platform.mixin.inspection.addedMembers

import com.demonwav.mcdev.platform.mixin.handlers.MixinAnnotationHandler
import com.demonwav.mcdev.platform.mixin.inspection.MixinInspection
import com.demonwav.mcdev.platform.mixin.util.MixinConstants
import com.demonwav.mcdev.platform.mixin.util.isMixin
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.psi.JavaElementVisitor
import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.PsiField
import com.intellij.psi.PsiMethod
import com.intellij.psi.search.searches.SuperMethodsSearch

abstract class AbstractAddedMembersInspection : MixinInspection() {
abstract fun visitAddedField(holder: ProblemsHolder, field: PsiField)
abstract fun visitAddedMethod(holder: ProblemsHolder, method: PsiMethod, isInherited: Boolean)

final override fun buildVisitor(holder: ProblemsHolder): PsiElementVisitor = Visitor(holder)

private inner class Visitor(private val holder: ProblemsHolder) : JavaElementVisitor() {
override fun visitField(field: PsiField) {
if (field.containingClass?.isMixin != true) {
return
}

if (field.hasAnnotation(MixinConstants.Annotations.SHADOW)) {
return
}

visitAddedField(holder, field)
}

override fun visitMethod(method: PsiMethod) {
if (method.containingClass?.isMixin != true) {
return
}

if (method.isConstructor) {
return
}

val hasMixinAnnotation = method.annotations.any {
val fqn = it.qualifiedName ?: return@any false
fqn in ignoredMethodAnnotations || MixinAnnotationHandler.forMixinAnnotation(
fqn,
holder.project
) != null
}
if (hasMixinAnnotation) {
return
}

val superMethod = SuperMethodsSearch.search(method, null, true, false).findFirst()
visitAddedMethod(holder, method, superMethod != null)
}
}

companion object {
private val ignoredMethodAnnotations = setOf(
MixinConstants.Annotations.SHADOW,
MixinConstants.Annotations.ACCESSOR,
MixinConstants.Annotations.INVOKER,
MixinConstants.Annotations.OVERWRITE,
MixinConstants.Annotations.INTRINSIC,
MixinConstants.Annotations.SOFT_OVERRIDE,
)
}
}
Loading

0 comments on commit 92105c6

Please sign in to comment.