Skip to content

Commit c830dad

Browse files
committed
Merge branch '2022.2' into 2022.3
2 parents 5142284 + c2ea2e3 commit c830dad

27 files changed

+754
-103
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ kotlin.code.style=official
2424
ideaVersion = 2022.3
2525
ideaVersionName = 2022.3
2626

27-
coreVersion = 1.6.6
27+
coreVersion = 1.6.7
2828
downloadIdeaSources = true
2929

3030
pluginTomlVersion = 223.7571.59

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Minecraft Development for IntelliJ
3535
</tr>
3636
</table>
3737

38-
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)
38+
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)
3939
----------------------
4040

4141
<a href="https://discord.gg/j6UNcfr"><img src="https://i.imgur.com/JXu9C1G.png" height="48px"></img></a>

src/main/kotlin/creator/PlatformVersion.kt

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ package com.demonwav.mcdev.creator
2323
import com.demonwav.mcdev.platform.PlatformType
2424
import com.demonwav.mcdev.update.PluginUtil
2525
import com.demonwav.mcdev.util.fromJson
26+
import com.demonwav.mcdev.util.mapFirstNotNull
27+
import com.demonwav.mcdev.util.withSuppressed
28+
import com.github.kittinunf.fuel.core.FuelError
2629
import com.github.kittinunf.fuel.core.FuelManager
2730
import com.github.kittinunf.fuel.core.requests.suspendable
2831
import com.github.kittinunf.fuel.coroutines.awaitString
@@ -35,8 +38,20 @@ import java.net.Proxy
3538
import java.net.URI
3639
import kotlin.reflect.KClass
3740

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

4156
val PLATFORM_VERSION_LOGGER = logger<PlatformVersion>()
4257

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

6479
suspend fun getText(path: String): String {
65-
return try {
66-
// attempt cloudflare
67-
doCall(CLOUDFLARE_BASE_URL + path)
68-
} catch (e: IOException) {
69-
PLATFORM_VERSION_LOGGER.warn("Failed to reach cloudflare URL ${CLOUDFLARE_BASE_URL + path}", e)
70-
// if that fails, attempt github
80+
var thrown: FuelError? = null
81+
return URLS.mapFirstNotNull { url ->
7182
try {
72-
doCall(GITHUB_BASE_URL + path)
73-
} catch (e: IOException) {
74-
PLATFORM_VERSION_LOGGER.warn("Failed to reach fallback GitHub URL ${GITHUB_BASE_URL + path}", e)
75-
throw e
83+
doCall(url + path)
84+
} catch (e: FuelError) {
85+
PLATFORM_VERSION_LOGGER.warn("Failed to reach URL $url$path")
86+
thrown = withSuppressed(thrown, e)
87+
null
7688
}
77-
}
89+
} ?: throw thrown!!
7890
}
7991

8092
private suspend fun doCall(urlText: String): String {

src/main/kotlin/insight/ColorLineMarkerProvider.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package com.demonwav.mcdev.insight
2222

2323
import com.demonwav.mcdev.MinecraftSettings
24+
import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions
2425
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler
2526
import com.intellij.codeInsight.daemon.LineMarkerInfo
2627
import com.intellij.codeInsight.daemon.LineMarkerProvider
@@ -52,7 +53,9 @@ class ColorLineMarkerProvider : LineMarkerProvider {
5253
}
5354

5455
val identifier = element.toUElementOfType<UIdentifier>() ?: return null
55-
val info = identifier.findColor { map, chosen -> ColorInfo(element, chosen.value, map, chosen.key, identifier) }
56+
val info = runCatchingKtIdeaExceptions {
57+
identifier.findColor { map, chosen -> ColorInfo(element, chosen.value, map, chosen.key, identifier) }
58+
}
5659
if (info != null) {
5760
NavigateAction.setNavigateAction(info, "Change Color", null)
5861
}
@@ -164,6 +167,7 @@ class ColorLineMarkerProvider : LineMarkerProvider {
164167
}
165168
}
166169
}
170+
167171
is UCallExpression -> {
168172
if (workElement.methodName == "hsvLike") {
169173
val (h, s, v) = Color.RGBtoHSB(c.red, c.green, c.blue, null)

src/main/kotlin/insight/ColorUtil.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ import org.jetbrains.uast.generate.replace
4848
import org.jetbrains.uast.resolveToUElement
4949

5050
fun <T> UIdentifier.findColor(function: (Map<String, Color>, Map.Entry<String, Color>) -> T): T? {
51-
val parent = this.uastParent
52-
val expression = parent as? UReferenceExpression ?: return null
53-
return findColorFromExpression(expression, function)
51+
return runCatchingKtIdeaExceptions {
52+
val parent = this.uastParent
53+
val expression = parent as? UReferenceExpression ?: return null
54+
findColorFromExpression(expression, function)
55+
}
5456
}
5557

5658
private fun <T> findColorFromExpression(

src/main/kotlin/insight/ListenerLineMarkerProvider.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package com.demonwav.mcdev.insight
2222

2323
import com.demonwav.mcdev.MinecraftSettings
2424
import com.demonwav.mcdev.asset.GeneralAssets
25+
import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions
2526
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler
2627
import com.intellij.codeInsight.daemon.LineMarkerInfo
2728
import com.intellij.codeInsight.daemon.LineMarkerProviderDescriptor
@@ -51,19 +52,11 @@ class ListenerLineMarkerProvider : LineMarkerProviderDescriptor() {
5152
return null
5253
}
5354

54-
try {
55+
runCatchingKtIdeaExceptions {
5556
val identifier = element.toUElementOfType<UIdentifier>() ?: return null
5657
if (identifier.uastParent !is UMethod || identifier.uastEventListener == null) {
5758
return null
5859
}
59-
} catch (e: Exception) {
60-
// Kotlin plugin is buggy and can throw exceptions here
61-
// We do the check like this because we don't actually have this class on the classpath
62-
if (e.javaClass.name == "org.jetbrains.kotlin.idea.caches.resolve.KotlinIdeaResolutionException") {
63-
return null
64-
}
65-
// Don't swallow unexpected errors
66-
throw e
6760
}
6861

6962
// By this point, we can guarantee that the action of "go to declaration" will work

src/main/kotlin/platform/bukkit/BukkitModule.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import com.demonwav.mcdev.util.createVoidMethodWithParameterType
3535
import com.demonwav.mcdev.util.extendsOrImplements
3636
import com.demonwav.mcdev.util.findContainingMethod
3737
import com.demonwav.mcdev.util.nullable
38+
import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions
3839
import com.intellij.lang.jvm.JvmModifier
3940
import com.intellij.openapi.project.Project
4041
import com.intellij.psi.JavaPsiFacade
@@ -182,7 +183,7 @@ class BukkitModule<out T : AbstractModuleType<*>>(facet: MinecraftFacet, type: T
182183
val identifier = element?.toUElementOfType<UIdentifier>()
183184
?: return false
184185

185-
val psiClass = (identifier.uastParent as? UClass)?.javaPsi
186+
val psiClass = runCatchingKtIdeaExceptions { (identifier.uastParent as? UClass)?.javaPsi }
186187
?: return false
187188

188189
if (psiClass.hasModifier(JvmModifier.ABSTRACT)) {

src/main/kotlin/platform/bungeecord/BungeeCordModule.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import com.demonwav.mcdev.util.SourceType
3535
import com.demonwav.mcdev.util.addImplements
3636
import com.demonwav.mcdev.util.extendsOrImplements
3737
import com.demonwav.mcdev.util.nullable
38+
import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions
3839
import com.intellij.lang.jvm.JvmModifier
3940
import com.intellij.psi.JavaPsiFacade
4041
import com.intellij.psi.PsiClass
@@ -117,7 +118,7 @@ class BungeeCordModule<out T : AbstractModuleType<*>>(facet: MinecraftFacet, typ
117118
val identifier = element?.toUElementOfType<UIdentifier>()
118119
?: return false
119120

120-
val psiClass = (identifier.uastParent as? UClass)?.javaPsi
121+
val psiClass = runCatchingKtIdeaExceptions { (identifier.uastParent as? UClass)?.javaPsi }
121122
?: return false
122123

123124
val pluginInterface = JavaPsiFacade.getInstance(element.project)

src/main/kotlin/platform/fabric/FabricModule.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import com.demonwav.mcdev.platform.fabric.reference.EntryPointReference
2828
import com.demonwav.mcdev.platform.fabric.util.FabricConstants
2929
import com.demonwav.mcdev.util.SourceType
3030
import com.demonwav.mcdev.util.nullable
31+
import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions
3132
import com.intellij.psi.PsiClass
3233
import com.intellij.psi.PsiElement
3334
import com.intellij.psi.PsiMethod
@@ -54,7 +55,7 @@ class FabricModule internal constructor(facet: MinecraftFacet) : AbstractModule(
5455
val identifier = element?.toUElementOfType<UIdentifier>()
5556
?: return false
5657

57-
val parent = identifier.uastParent
58+
val parent = runCatchingKtIdeaExceptions { identifier.uastParent }
5859
if (parent !is UClass && parent !is UMethod) {
5960
return false
6061
}

src/main/kotlin/platform/forge/ForgeModule.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import com.demonwav.mcdev.util.SourceType
3434
import com.demonwav.mcdev.util.createVoidMethodWithParameterType
3535
import com.demonwav.mcdev.util.extendsOrImplements
3636
import com.demonwav.mcdev.util.nullable
37+
import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions
3738
import com.demonwav.mcdev.util.runWriteTaskLater
3839
import com.demonwav.mcdev.util.waitForAllSmart
3940
import com.intellij.json.JsonFileType
@@ -187,7 +188,7 @@ class ForgeModule internal constructor(facet: MinecraftFacet) : AbstractModule(f
187188
val identifier = element?.toUElementOfType<UIdentifier>()
188189
?: return false
189190

190-
val psiClass = identifier.uastParent as? UClass
191+
val psiClass = runCatchingKtIdeaExceptions { identifier.uastParent as? UClass }
191192
?: return false
192193

193194
return !psiClass.hasModifier(JvmModifier.ABSTRACT) &&

0 commit comments

Comments
 (0)