Skip to content

Commit f7ccfc5

Browse files
committed
Merge branch '2020.2' into 2020.3
2 parents f75640c + f66f5ce commit f7ccfc5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1399
-521
lines changed

build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ plugins {
2020
groovy
2121
idea
2222
id("org.jetbrains.intellij") version "1.0"
23-
id("org.cadixdev.licenser") version "0.6.0"
23+
id("org.cadixdev.licenser") version "0.6.1"
2424
id("org.jlleitschuh.gradle.ktlint") version "10.0.0"
2525
}
2626

@@ -58,7 +58,7 @@ val gradleToolingExtensionJar = tasks.register<Jar>(gradleToolingExtensionSource
5858

5959
repositories {
6060
mavenCentral()
61-
maven("https://wav.jfrog.io/artifactory/mcdev/")
61+
maven("https://repo.denwav.dev/repository/maven-public/")
6262
maven("https://repo.spongepowered.org/maven")
6363
maven("https://jetbrains.bintray.com/intellij-third-party-dependencies")
6464
maven("https://repo.gradle.org/gradle/libs-releases-local/")
@@ -79,7 +79,7 @@ dependencies {
7979
implementation(libs.templateMakerFabric)
8080

8181
jflex(libs.jflex.lib)
82-
jflexSkeleton("${libs.jflex.skeleton.text()}:idea@skeleton")
82+
jflexSkeleton("${libs.jflex.skeleton.text()}@skeleton")
8383
grammarKit(libs.grammarKit)
8484

8585
testLibs(libs.test.mockJdk)

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ kotlin.code.style=official
1414
ideaVersion = 2020.3.2
1515
ideaVersionName = 2020.3
1616

17-
coreVersion = 1.5.11
17+
coreVersion = 1.5.12
1818
downloadIdeaSources = true
1919

2020
pluginTomlVersion = 0.2.140.3644-203

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ gradleToolingExtension = "com.jetbrains.intellij.gradle:gradle-tooling-extension
1818
annotations = "org.jetbrains:annotations:19.0.0"
1919

2020
# Testing
21-
test-mockJdk = "org.jetbrains.idea:mockJDK:1.7-4d76c50"
21+
test-mockJdk = "org.jetbrains.idea:mock-jdk:1.7-4d76c50"
2222
test-mixin = "org.spongepowered:mixin:0.7-SNAPSHOT"
2323
test-spongeapi = "org.spongepowered:spongeapi:7.0.0"
2424
test-nbt = "com.demonwav.mcdev:all-types-nbt:1.0"

gradle/wrapper/gradle-wrapper.jar

333 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

gradlew

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ case "`uname`" in
7272
Darwin* )
7373
darwin=true
7474
;;
75-
MINGW* )
75+
MSYS* | MINGW* )
7676
msys=true
7777
;;
7878
NONSTOP* )

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Minecraft Development for IntelliJ
4040
</tr>
4141
</table>
4242

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

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

src/main/kotlin/creator/CreatorStep.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.intellij.openapi.application.runReadAction
2020
import com.intellij.openapi.progress.ProgressIndicator
2121
import com.intellij.openapi.project.Project
2222
import com.intellij.openapi.vfs.VirtualFile
23+
import com.intellij.psi.PsiDocumentManager
2324
import com.intellij.psi.PsiFile
2425
import com.intellij.psi.PsiManager
2526
import com.intellij.psi.SmartPsiElementPointer
@@ -46,6 +47,7 @@ interface CreatorStep {
4647
runWriteTask {
4748
for (scheduledReformat in scheduledReformats) {
4849
val file = scheduledReformat.element ?: continue
50+
PsiDocumentManager.getInstance(file.project).getDocument(file)?.setReadOnly(false)
4951
ReformatCodeProcessor(file, false).run()
5052
}
5153
}
@@ -81,6 +83,7 @@ interface CreatorStep {
8183
fun writeText(file: Path, text: String, psiManager: PsiManager? = null) {
8284
Files.write(file, text.toByteArray(Charsets.UTF_8), CREATE, TRUNCATE_EXISTING, WRITE)
8385
psiManager?.findFile(file.virtualFileOrError)?.let {
86+
PsiDocumentManager.getInstance(psiManager.project).getDocument(it)?.setReadOnly(false)
8487
ReformatCodeProcessor(it, false).run()
8588
}
8689
}

src/main/kotlin/creator/buildsystem/gradle/gradle-steps.kt

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,22 @@ class SimpleGradleSetupStep(
5353
private val project: Project,
5454
private val rootDirectory: Path,
5555
private val buildSystem: BuildSystem,
56-
private val gradleFiles: GradleFiles<String>
56+
private val gradleFiles: GradleFiles<String>,
57+
private val kotlinScript: Boolean = false
5758
) : CreatorStep {
5859

5960
override fun runStep(indicator: ProgressIndicator) {
6061
runWriteTask {
62+
if (project.isDisposed) {
63+
return@runWriteTask
64+
}
65+
6166
buildSystem.directories =
6267
DirectorySet.create(rootDirectory)
6368
val (buildGradle, gradleProp, settingsGradle) = setupGradleFiles(
6469
rootDirectory,
65-
gradleFiles
70+
gradleFiles,
71+
kotlinScript
6672
)
6773

6874
val psiManager = PsiManager.getInstance(project)
@@ -93,13 +99,18 @@ class GradleSetupStep(
9399
private val project: Project,
94100
private val rootDirectory: Path,
95101
private val buildSystem: BuildSystem,
96-
private val gradleFiles: GradleFiles<String>
102+
private val gradleFiles: GradleFiles<String>,
103+
private val kotlinScript: Boolean = false
97104
) : CreatorStep {
98105
override fun runStep(indicator: ProgressIndicator) {
99-
val (_, gradleProp, settingsGradle) = setupGradleFiles(rootDirectory, gradleFiles)
106+
val (_, gradleProp, settingsGradle) = setupGradleFiles(rootDirectory, gradleFiles, kotlinScript)
100107

101108
runWriteTask {
102-
val buildGradlePsi = addBuildGradleDependencies(project, buildSystem, gradleFiles.buildGradle)
109+
if (project.isDisposed) {
110+
return@runWriteTask
111+
}
112+
113+
val buildGradlePsi = addBuildGradleDependencies(project, buildSystem, gradleFiles.buildGradle, kotlinScript)
103114
val psiManager = PsiManager.getInstance(project)
104115
psiManager.findDirectory(rootDirectory.virtualFileOrError)?.let { dir ->
105116
dir.findFile(buildGradlePsi.name)?.delete()
@@ -123,11 +134,11 @@ data class GradleFiles<out T>(
123134
val settingsGradle: T?
124135
)
125136

126-
fun setupGradleFiles(dir: Path, givenFiles: GradleFiles<String>): GradleFiles<Path> {
137+
fun setupGradleFiles(dir: Path, givenFiles: GradleFiles<String>, kotlinScript: Boolean = false): GradleFiles<Path> {
127138
return GradleFiles(
128-
dir.resolve("build.gradle"),
139+
dir.resolve(if (kotlinScript) "build.gradle.kts" else "build.gradle"),
129140
givenFiles.gradleProperties?.let { dir.resolve("gradle.properties") },
130-
givenFiles.settingsGradle?.let { dir.resolve("settings.gradle") }
141+
givenFiles.settingsGradle?.let { dir.resolve(if (kotlinScript) "settings.gradle.kts" else "settings.gradle") },
131142
).apply {
132143
Files.deleteIfExists(buildGradle)
133144
Files.createFile(buildGradle)
@@ -136,10 +147,15 @@ fun setupGradleFiles(dir: Path, givenFiles: GradleFiles<String>): GradleFiles<Pa
136147
}
137148
}
138149

139-
fun addBuildGradleDependencies(project: Project, buildSystem: BuildSystem, text: String): PsiFile {
150+
fun addBuildGradleDependencies(
151+
project: Project,
152+
buildSystem: BuildSystem,
153+
text: String,
154+
kotlinScript: Boolean = false
155+
): PsiFile {
140156
val file = PsiFileFactory.getInstance(project).createFileFromText(GroovyLanguage, text)
141157
return file.runWriteAction {
142-
val fileName = "build.gradle"
158+
val fileName = if (kotlinScript) "build.gradle.kts" else "build.gradle"
143159
file.name = fileName
144160

145161
val groovyFile = file as GroovyFile
@@ -203,7 +219,8 @@ private fun getClosableBlockByName(element: PsiElement, name: String) =
203219
class BasicGradleFinalizerStep(
204220
private val module: Module,
205221
private val rootDirectory: Path,
206-
private val buildSystem: BuildSystem
222+
private val buildSystem: BuildSystem,
223+
private vararg val additionalRunTasks: String
207224
) : CreatorStep {
208225
private val project
209226
get() = module.project
@@ -212,7 +229,7 @@ class BasicGradleFinalizerStep(
212229
// Tell IntelliJ to import this project
213230
rootDirectory.virtualFileOrError.refresh(false, true)
214231

215-
invokeLater {
232+
invokeLater(module.disposed) {
216233
val path = rootDirectory.toAbsolutePath().toString()
217234
if (canLinkAndRefreshGradleProject(path, project, false)) {
218235
linkAndRefreshGradleProject(path, project)
@@ -222,10 +239,17 @@ class BasicGradleFinalizerStep(
222239

223240
// Set up the run config
224241
// Get the gradle external task type, this is what sets it as a gradle task
242+
addRunTaskConfiguration("build")
243+
for (tasks in additionalRunTasks) {
244+
addRunTaskConfiguration(tasks)
245+
}
246+
}
247+
248+
private fun addRunTaskConfiguration(task: String) {
225249
val gradleType = GradleExternalTaskConfigurationType.getInstance()
226250

227251
val runManager = RunManager.getInstance(project)
228-
val runConfigName = buildSystem.artifactId + " build"
252+
val runConfigName = buildSystem.artifactId + ' ' + task
229253

230254
val runConfiguration = ExternalSystemRunConfiguration(
231255
GradleConstants.SYSTEM_ID,
@@ -237,7 +261,7 @@ class BasicGradleFinalizerStep(
237261
// Set relevant gradle values
238262
runConfiguration.settings.externalProjectPath = rootDirectory.toAbsolutePath().toString()
239263
runConfiguration.settings.executionName = runConfigName
240-
runConfiguration.settings.taskNames = listOf("build")
264+
runConfiguration.settings.taskNames = listOf(task)
241265

242266
runConfiguration.isAllowRunningInParallel = false
243267

src/main/kotlin/facet/MinecraftFacet.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ class MinecraftFacet(
6666
}
6767

6868
fun refresh() {
69+
if (module.isDisposed) {
70+
return
71+
}
72+
6973
// Don't allow parent types with child types in auto detected set
7074
val allEnabled = configuration.state.run {
7175
autoDetectTypes = PlatformType.removeParents(autoDetectTypes)

src/main/kotlin/insight/PluginLineMarkerProvider.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class PluginLineMarkerProvider : LineMarkerProviderDescriptor() {
2424
override fun getName() = "Minecraft Plugin line marker"
2525

2626
override fun getLineMarkerInfo(element: PsiElement): LineMarkerInfo<*>? {
27+
if (!element.isValid) {
28+
return null
29+
}
30+
2731
val module = ModuleUtilCore.findModuleForPsiElement(element) ?: return null
2832

2933
val instance = MinecraftFacet.getInstance(module) ?: return null

src/main/kotlin/nbt/tags/TagDouble.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
package com.demonwav.mcdev.nbt.tags
1212

1313
import java.io.DataOutputStream
14+
import java.text.DecimalFormat
15+
import java.text.NumberFormat
16+
import java.util.Locale
1417

1518
class TagDouble(override val value: Double) : NbtValueTag<Double>(Double::class.java) {
1619
override val payloadSize = 8
@@ -21,4 +24,16 @@ class TagDouble(override val value: Double) : NbtValueTag<Double>(Double::class.
2124
}
2225

2326
override fun toString() = toString(StringBuilder(), 0, WriterState.COMPOUND).toString()
27+
28+
override fun toString(sb: StringBuilder, indentLevel: Int, writerState: WriterState): StringBuilder {
29+
return sb.append(FORMATTER.format(value))
30+
}
31+
32+
companion object {
33+
val FORMATTER = (NumberFormat.getInstance(Locale.ROOT) as DecimalFormat).apply {
34+
minimumFractionDigits = 1 // Default NBTT double format always uses a fraction, like in Kotlin
35+
maximumFractionDigits = 20 // Should be more than enough, but let's use 20 just in case
36+
groupingSize = 0 // Disables thousands separator
37+
}
38+
}
2439
}

src/main/kotlin/platform/BaseTemplate.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ abstract class BaseTemplate {
1717

1818
protected fun Project.applyTemplate(
1919
templateName: String,
20-
properties: Map<String, String>? = null
20+
properties: Map<String, *>? = null
2121
): String {
2222
val manager = FileTemplateManager.getInstance(this)
2323
val template = manager.getJ2eeTemplate(templateName)
2424

25-
val allProperties = manager.defaultProperties
25+
val allProperties = manager.defaultProperties.toMutableMap()
2626
properties?.let { prop -> allProperties.putAll(prop) }
2727

2828
return template.getText(allProperties)

src/main/kotlin/platform/bukkit/creator/BukkitProjectCreator.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import com.demonwav.mcdev.creator.buildsystem.maven.CommonModuleDependencyStep
2929
import com.demonwav.mcdev.creator.buildsystem.maven.MavenBuildSystem
3030
import com.demonwav.mcdev.creator.buildsystem.maven.MavenGitignoreStep
3131
import com.demonwav.mcdev.platform.PlatformType
32+
import com.demonwav.mcdev.util.MinecraftVersions
33+
import com.demonwav.mcdev.util.SemanticVersion
3234
import com.intellij.openapi.module.Module
3335
import com.intellij.openapi.progress.ProgressIndicator
3436
import com.intellij.openapi.project.Project
@@ -154,9 +156,13 @@ open class BukkitDependenciesStep(
154156
"https://papermc.io/repo/repository/maven-public/"
155157
)
156158
)
159+
val paperGroupId = when {
160+
SemanticVersion.parse(mcVersion) >= MinecraftVersions.MC1_17 -> "io.papermc.paper"
161+
else -> "com.destroystokyo.paper"
162+
}
157163
buildSystem.dependencies.add(
158164
BuildDependency(
159-
"com.destroystokyo.paper",
165+
paperGroupId,
160166
"paper-api",
161167
"$mcVersion-R0.1-SNAPSHOT",
162168
mavenScope = "provided",

src/main/kotlin/platform/mcp/actions/SrgActionBase.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ abstract class SrgActionBase : AnAction() {
4242
val mcpModule = data.instance.getModuleOfType(McpModuleType) ?: return showBalloon("No mappings found", e)
4343

4444
mcpModule.srgManager?.srgMap?.onSuccess { srgMap ->
45-
var parent = data.element.parent
45+
var parent = data.element.parent ?: return@onSuccess showBalloon("Not a valid element", e)
4646

4747
if (parent is PsiMember) {
4848
val shadowTarget = parent.findFirstShadowTarget()?.element
@@ -52,7 +52,7 @@ abstract class SrgActionBase : AnAction() {
5252
}
5353

5454
if (parent is PsiReference) {
55-
parent = parent.resolve()
55+
parent = parent.resolve() ?: return@onSuccess showBalloon("Not a valid element", e)
5656
}
5757

5858
withSrgTarget(parent, srgMap, e, data)

src/main/kotlin/platform/mcp/version/McpVersion.kt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,30 +92,30 @@ class McpVersion private constructor(private val map: Map<String, Map<String, Li
9292

9393
companion object {
9494
fun downloadData(): McpVersion? {
95-
try {
96-
val text = URL("http://export.mcpbot.bspk.rs/versions.json").readText()
97-
val map = Gson().fromJson<MutableMap<String, MutableMap<String, MutableList<Int>>>>(text)
98-
99-
val tempMappings = URL("https://assets.tterrag.com/temp_mappings.json").readText()
100-
val tempMappingsMap = Gson()
101-
.fromJson<MutableMap<String, MutableMap<String, MutableList<Int>>>>(tempMappings)
102-
103-
// Merge the temporary mappings list into the main one, temporary solution for 1.16
104-
tempMappingsMap.forEach { (mcVersion, channels) ->
105-
val existingChannels = map.getOrPut(mcVersion, ::mutableMapOf)
106-
channels.forEach { (channelName, newVersions) ->
107-
val existingVersions = existingChannels.getOrPut(channelName, ::mutableListOf)
108-
existingVersions.addAll(newVersions)
109-
}
110-
}
95+
val bspkrsMappings = try {
96+
val bspkrsText = URL("https://maven.minecraftforge.net/de/oceanlabs/mcp/versions.json").readText()
97+
Gson().fromJson<MutableMap<String, MutableMap<String, MutableList<Int>>>>(bspkrsText)
98+
} catch (ignored: IOException) {
99+
mutableMapOf()
100+
}
111101

112-
val mcpVersion = McpVersion(map)
113-
mcpVersion.versions
114-
return mcpVersion
102+
val tterragMappings = try {
103+
val tterragText = URL("https://assets.tterrag.com/temp_mappings.json").readText()
104+
Gson().fromJson<MutableMap<String, MutableMap<String, MutableList<Int>>>>(tterragText)
115105
} catch (ignored: IOException) {
106+
emptyMap()
107+
}
108+
109+
// Merge the temporary mappings list into the main one, temporary solution for 1.16
110+
tterragMappings.forEach { (mcVersion, channels) ->
111+
val existingChannels = bspkrsMappings.getOrPut(mcVersion, ::mutableMapOf)
112+
channels.forEach { (channelName, newVersions) ->
113+
val existingVersions = existingChannels.getOrPut(channelName, ::mutableListOf)
114+
existingVersions.addAll(newVersions)
115+
}
116116
}
117117

118-
return null
118+
return if (bspkrsMappings.isEmpty()) null else McpVersion(bspkrsMappings)
119119
}
120120
}
121121
}

src/main/kotlin/platform/mixin/action/GenerateOverwriteAction.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ class GenerateOverwriteAction : MixinCodeInsightAction() {
105105
.first().positionCaret(editor, true)
106106
}
107107

108+
if (!psiClass.isValid) {
109+
return
110+
}
111+
108112
// Generate needed shadows
109113
val newShadows = createShadowMembers(project, psiClass, filterNewShadows(requiredMembers, psiClass))
110114

0 commit comments

Comments
 (0)