Skip to content

Commit 0df4bfd

Browse files
committed
neo at's
1 parent 36e530e commit 0df4bfd

File tree

3 files changed

+112
-2
lines changed

3 files changed

+112
-2
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ org.gradle.jvmargs=-Xmx1g
2323

2424
ideaVersionName = 2024.3
2525

26-
coreVersion = 1.8.7
26+
coreVersion = 1.8.8
2727

2828
# Silences a build-time warning because we are bundling our own kotlin library
2929
kotlin.stdlib.default.dependency = false
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Minecraft Development for IntelliJ
3+
*
4+
* https://mcdev.io/
5+
*
6+
* Copyright (C) 2025 minecraft-dev
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published
10+
* by the Free Software Foundation, version 3.0 only.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
package com.demonwav.mcdev.platform.mcp.actions.platform.mcp.actions
22+
23+
import com.demonwav.mcdev.platform.mcp.actions.SrgActionBase.Companion.showBalloon
24+
import com.demonwav.mcdev.platform.mcp.actions.SrgActionBase.Companion.showSuccessBalloon
25+
import com.demonwav.mcdev.util.descriptor
26+
import com.demonwav.mcdev.util.getDataFromActionEvent
27+
import com.demonwav.mcdev.util.internalName
28+
import com.intellij.openapi.actionSystem.AnAction
29+
import com.intellij.openapi.actionSystem.AnActionEvent
30+
import com.intellij.openapi.editor.Editor
31+
import com.intellij.psi.PsiClass
32+
import com.intellij.psi.PsiElement
33+
import com.intellij.psi.PsiField
34+
import com.intellij.psi.PsiIdentifier
35+
import com.intellij.psi.PsiMember
36+
import com.intellij.psi.PsiMethod
37+
import com.intellij.psi.PsiReference
38+
import java.awt.Toolkit
39+
import java.awt.datatransfer.StringSelection
40+
41+
class CopyNeoAtAction : AnAction() {
42+
43+
override fun actionPerformed(e: AnActionEvent) {
44+
val data = getDataFromActionEvent(e) ?: return showBalloon("Unknown failure", e)
45+
val editor = data.editor
46+
47+
val element = data.element
48+
if (element !is PsiIdentifier) {
49+
showBalloon("Invalid element", e)
50+
return
51+
}
52+
53+
val target = when (val parent = element.parent) {
54+
is PsiMember -> parent
55+
is PsiReference -> parent.resolve()
56+
else -> null
57+
} ?: return showBalloon("Invalid element", e)
58+
59+
doCopy(target, element, editor, e)
60+
}
61+
62+
companion object {
63+
64+
fun doCopy(target: PsiElement, element: PsiElement, editor: Editor?, e: AnActionEvent?) {
65+
when (target) {
66+
is PsiClass -> {
67+
val text = "public ${target.internalName}"
68+
val text2 = text.replace("/",".").replace(" (","(")
69+
copyToClipboard(editor, element, text2)
70+
}
71+
is PsiField -> {
72+
val containing = target.containingClass?.internalName
73+
?: return maybeShow("Could not get owner of field", e)
74+
val text = "public $containing ${target.name}"
75+
val text2 = text.replace("/",".").replace(" (","(")
76+
copyToClipboard(editor, element, text2)
77+
}
78+
is PsiMethod -> {
79+
val containing = target.containingClass?.internalName
80+
?: return maybeShow("Could not get owner of method", e)
81+
val desc = target.descriptor ?: return maybeShow("Could not get descriptor of method", e)
82+
val modifiedContaining = containing.replace("/",".");
83+
val text = "public ${modifiedContaining} ${target.internalName}$desc"
84+
copyToClipboard(editor, element, text)
85+
}
86+
else -> maybeShow("Invalid element", e)
87+
}
88+
}
89+
90+
private fun copyToClipboard(editor: Editor?, element: PsiElement, text: String) {
91+
val stringSelection = StringSelection(text)
92+
val clpbrd = Toolkit.getDefaultToolkit().systemClipboard
93+
clpbrd.setContents(stringSelection, null)
94+
if (editor != null) {
95+
showSuccessBalloon(editor, element, "Copied: \"$text\"")
96+
}
97+
}
98+
99+
private fun maybeShow(text: String, e: AnActionEvent?) {
100+
if (e != null) {
101+
showBalloon(text, e)
102+
}
103+
}
104+
}
105+
}

src/main/resources/META-INF/plugin.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1652,10 +1652,15 @@
16521652
text="Minecraft Class" description="Create skeleton classes used in Minecraft Mods">
16531653
<add-to-group group-id="NewGroup" anchor="before" relative-to-action="NewFile"/>
16541654
</action>
1655+
<action class="com.demonwav.mcdev.platform.mcp.actions.platform.mcp.actions.CopyNeoAtAction" id="CopyNeoATAction"
1656+
text="Neo AT Entry"
1657+
description="Copy the reference to clipboard in Neo Access Transformer format">
1658+
<add-to-group relative-to-action="CopyATAction" anchor="after" group-id="Copy.Paste.Special"/>
1659+
</action>
16551660
<action class="com.demonwav.mcdev.platform.mcp.actions.CopyAwAction" id="CopyAWAction"
16561661
text="AW Entry"
16571662
description="Copy the reference to clipboard in Access Widener format">
1658-
<add-to-group relative-to-action="CopyATAction" anchor="after" group-id="Copy.Paste.Special"/>
1663+
<add-to-group relative-to-action="CopyNeoATAction" anchor="after" group-id="Copy.Paste.Special"/>
16591664
</action>
16601665
</actions>
16611666
</idea-plugin>

0 commit comments

Comments
 (0)