first commit with KotlinBukkitAPI Menu Preview \o/
No files matched your search
@@ -0,0 +1,113 @@
|
||||
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/gradle,intellij+all
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=gradle,intellij+all
|
||||
|
||||
### Intellij+all ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/artifacts
|
||||
# .idea/compiler.xml
|
||||
# .idea/jarRepositories.xml
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
### Intellij+all Patch ###
|
||||
# Ignores the whole .idea folder and all .iml files
|
||||
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
|
||||
|
||||
.idea/
|
||||
|
||||
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
|
||||
|
||||
*.iml
|
||||
modules.xml
|
||||
.idea/misc.xml
|
||||
*.ipr
|
||||
|
||||
# Sonarlint plugin
|
||||
.idea/sonarlint
|
||||
|
||||
### Gradle ###
|
||||
.gradle
|
||||
build/
|
||||
|
||||
# Ignore Gradle GUI config
|
||||
gradle-app.setting
|
||||
|
||||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||
!gradle-wrapper.jar
|
||||
|
||||
# Cache of project
|
||||
.gradletasknamecache
|
||||
|
||||
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
|
||||
# gradle/wrapper/gradle-wrapper.properties
|
||||
|
||||
### Gradle Patch ###
|
||||
**/build/
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/gradle,intellij+all
|
||||
@@ -0,0 +1,17 @@
|
||||
# KotlinBukkitAPI-Tooling [WIP]
|
||||
|
||||
The KotlinBukkitAPI Tooling adds Tooling to IntelliJ API when using [KotlinBukkitAPI](https://github.com/DevSrSouza/KotlinBukkitAPI) and [Bukkript](https://github.com/DevSrSouza/Bukkript).
|
||||
|
||||
## Features
|
||||
|
||||
- [Menu Preview](#Menu-Preview)
|
||||
|
||||
#### Future Features
|
||||
|
||||
- Tooling for Bukkript scripts.
|
||||
|
||||
## Menu Preview
|
||||
|
||||
When using KotlinBukkitAPI Menu DSL you have a good preview of how the slots are arranged in the Menu in the game.
|
||||
|
||||

|
||||
@@ -0,0 +1,46 @@
|
||||
plugins {
|
||||
id("org.jetbrains.intellij") version "0.4.21"
|
||||
java
|
||||
kotlin("jvm") version "1.3.72"
|
||||
}
|
||||
|
||||
group = "br.com.devsrsouza.kotlinbukkitapi"
|
||||
version = "0.0.1-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib-jdk8"))
|
||||
testCompile("junit", "junit", "4.12")
|
||||
}
|
||||
|
||||
// See https://github.com/JetBrains/gradle-intellij-plugin/
|
||||
intellij {
|
||||
version = "2020.1.2"
|
||||
|
||||
setPlugins("java", "org.jetbrains.kotlin:1.3.72-release-IJ2020.1-3")
|
||||
}
|
||||
configure<JavaPluginConvention> {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
tasks {
|
||||
compileKotlin {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
compileTestKotlin {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
tasks.getByName<org.jetbrains.intellij.tasks.PatchPluginXmlTask>("patchPluginXml") {
|
||||
pluginDescription("""
|
||||
The KotlinBukkitAPI Tooling adds Tooling to IntelliJ API when using <a href="https://github.com/DevSrSouza/KotlinBukkitAPI">KotlinBukkitAPI</a> and <a href="https://github.com/DevSrSouza/Bukkript">Bukkript</a>.
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
listOf("compileKotlin", "compileTestKotlin").forEach {
|
||||
tasks.getByName<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>(it) {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
kotlin.code.style=official
|
||||
@@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -0,0 +1,183 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
case $i in
|
||||
0) set -- ;;
|
||||
1) set -- "$args0" ;;
|
||||
2) set -- "$args0" "$args1" ;;
|
||||
3) set -- "$args0" "$args1" "$args2" ;;
|
||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=`save "$@"`
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
@@ -0,0 +1,100 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@@ -0,0 +1,2 @@
|
||||
rootProject.name = "KotlinBukkitAPI-Tooling"
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package br.com.devsrsouza.kotlinbukkitapi.tooling
|
||||
|
||||
import com.intellij.lang.annotation.AnnotationHolder
|
||||
import com.intellij.lang.annotation.Annotator
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager
|
||||
import com.intellij.openapi.fileEditor.TextEditorWithPreview
|
||||
import com.intellij.openapi.wm.IdeFocusManager
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
import javax.swing.SwingUtilities
|
||||
|
||||
|
||||
/*
|
||||
* This annotator if the file has menu declaration, he set the file editor
|
||||
* to the KotlinBukkitAPI one.
|
||||
*
|
||||
object TestAnnotator : Annotator {
|
||||
override fun annotate(element: PsiElement, holder: AnnotationHolder) {
|
||||
if(element is KtCallExpression && isMenuCall(element)) {
|
||||
val project = element.project
|
||||
val fileEditorManager = FileEditorManager.getInstance(project)
|
||||
|
||||
SwingUtilities.invokeLater {
|
||||
val virtualFile = element.containingFile.virtualFile
|
||||
|
||||
if(fileEditorManager.selectedEditor is TextEditorWithPreview) return@invokeLater
|
||||
|
||||
fileEditorManager.setSelectedEditor(
|
||||
virtualFile,
|
||||
MenuPreviewFileEditorProvider.ID
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
@@ -0,0 +1,14 @@
|
||||
package br.com.devsrsouza.kotlinbukkitapi.tooling
|
||||
|
||||
data class MenuDeclaration(
|
||||
val displayname: String,
|
||||
val lines: Int,
|
||||
val slots: List<MenuSlotDeclaration>
|
||||
)
|
||||
|
||||
data class MenuSlotDeclaration(
|
||||
val line: Int,
|
||||
val slot: Int,
|
||||
val itemId: Int?,
|
||||
val isSelected: Boolean = false
|
||||
)
|
||||
@@ -0,0 +1,108 @@
|
||||
package br.com.devsrsouza.kotlinbukkitapi.tooling
|
||||
|
||||
import com.intellij.util.ImageLoader
|
||||
import org.jetbrains.kotlin.utils.keysToMap
|
||||
import java.awt.*
|
||||
import javax.swing.JPanel
|
||||
|
||||
|
||||
class InventoryComponent(
|
||||
val declaration: MenuDeclaration
|
||||
) : JPanel() {
|
||||
companion object {
|
||||
val CHEST_SCALE = 2
|
||||
val CHEST_SINGLE_LINE_HEIGHT = 42
|
||||
val CHEST_LINE_DIFF = 18
|
||||
val CHEST_WIDTH = 176
|
||||
|
||||
private val minecraftFontResource = "/assets/fonts/Minecraftia-Regular.ttf"
|
||||
private val spritesFolder = "/assets/sprites"
|
||||
private val itemsSpriteFolder = "/assets/items"
|
||||
|
||||
// the selected-border is 36x36 and not 32x32
|
||||
private val selectedBorderSizeDiff = 2
|
||||
}
|
||||
|
||||
private val lines = when {
|
||||
declaration.lines > 6 -> 6
|
||||
declaration.lines < 1 -> 1
|
||||
else -> declaration.lines
|
||||
}
|
||||
|
||||
private val spriteImage = ImageLoader.loadFromResource(
|
||||
"$spritesFolder/chest-${lines}.png"
|
||||
)!!
|
||||
private val itemsImage = declaration.slots.filter {
|
||||
it.line in 1..declaration.lines && it.slot in 1..9
|
||||
}.keysToMap {
|
||||
ImageLoader.loadFromResource("$itemsSpriteFolder/${it.itemId}-0.png")
|
||||
//?.getScaledInstance(16, 16, Image.SCALE_FAST)
|
||||
}
|
||||
private val selectionImage = if(declaration.slots.any { it.isSelected })
|
||||
ImageLoader.loadFromResource("$spritesFolder/selected-border.png")
|
||||
else null
|
||||
|
||||
private val minecraftFont = Font.createFont(
|
||||
Font.TRUETYPE_FONT,
|
||||
this::class.java.getResource(minecraftFontResource).openStream()
|
||||
).deriveFont(18.5f)
|
||||
|
||||
init {
|
||||
isVisible = true
|
||||
minimumSize = calculateDimension()
|
||||
}
|
||||
override fun paintComponent(g: Graphics) {
|
||||
val g = g as Graphics2D
|
||||
val oldTransform = g.transform
|
||||
|
||||
// drawing menu
|
||||
g.scale(CHEST_SCALE.toDouble(), CHEST_SCALE.toDouble())
|
||||
g.drawImage(spriteImage, 0, 0,this)
|
||||
|
||||
g.transform = oldTransform
|
||||
|
||||
// drawing items
|
||||
for ((slot, texture) in itemsImage) {
|
||||
val (x, y) = calculateXYForSlot(slot)
|
||||
|
||||
g.drawImage(texture ?: continue, x, y, this)
|
||||
|
||||
// if is selected draw selection border
|
||||
if(slot.isSelected) {
|
||||
g.drawImage(
|
||||
selectionImage ?: continue,
|
||||
x- selectedBorderSizeDiff,
|
||||
y- selectedBorderSizeDiff,
|
||||
this
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// drawing displayname
|
||||
g.font = minecraftFont
|
||||
g.color = Color.DARK_GRAY
|
||||
g.drawString(declaration.displayname, 16, 40)
|
||||
}
|
||||
|
||||
fun calculateXYForSlot(menuSlotDeclaration: MenuSlotDeclaration): Pair<Int, Int> {
|
||||
val topXPadding = 18 * CHEST_SCALE
|
||||
val leftYPadding = 8 * CHEST_SCALE
|
||||
val itemSize = 16 * CHEST_SCALE
|
||||
val rightYPadding = 2 * CHEST_SCALE
|
||||
val bottomXPadding = 2 * CHEST_SCALE
|
||||
|
||||
val itemXPos = menuSlotDeclaration.line -1
|
||||
val itemYPos = menuSlotDeclaration.slot -1
|
||||
|
||||
val x = leftYPadding + (itemYPos * rightYPadding) + (itemYPos * itemSize)
|
||||
val y = topXPadding + (itemXPos * bottomXPadding) + (itemXPos * itemSize)
|
||||
|
||||
return x to y
|
||||
}
|
||||
|
||||
private fun calculateDimension(): Dimension {
|
||||
val height = CHEST_SINGLE_LINE_HEIGHT + (lines - 1) * CHEST_LINE_DIFF
|
||||
|
||||
return Dimension((CHEST_WIDTH * CHEST_SCALE).toInt(), (height * CHEST_SCALE).toInt())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
package br.com.devsrsouza.kotlinbukkitapi.tooling
|
||||
|
||||
import com.intellij.openapi.editor.event.CaretEvent
|
||||
import com.intellij.openapi.editor.event.CaretListener
|
||||
import com.intellij.openapi.editor.event.DocumentEvent
|
||||
import com.intellij.openapi.editor.event.DocumentListener
|
||||
import com.intellij.openapi.fileEditor.*
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.UserDataHolderBase
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.psi.util.forEachDescendantOfType
|
||||
import com.intellij.ui.components.JBScrollPane
|
||||
import com.intellij.ui.layout.panel
|
||||
import com.intellij.util.Alarm
|
||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
import java.awt.*
|
||||
import java.beans.PropertyChangeListener
|
||||
import javax.swing.*
|
||||
|
||||
class MenuPreviewFileEditor(
|
||||
private val myProject: Project,
|
||||
private val myFile: VirtualFile,
|
||||
private val mainEditor: TextEditor
|
||||
) : UserDataHolderBase(), FileEditor {
|
||||
|
||||
private val mySwingAlarm = Alarm(Alarm.ThreadToUse.SWING_THREAD, this)
|
||||
private val myDocument = FileDocumentManager.getInstance().getDocument(myFile)!!
|
||||
private val myUi = JPanel().apply {
|
||||
layout = BorderLayout()
|
||||
isVisible = true
|
||||
minimumSize = Dimension(
|
||||
InventoryComponent.CHEST_WIDTH * InventoryComponent.CHEST_SCALE + 10,
|
||||
0
|
||||
)
|
||||
}
|
||||
|
||||
private lateinit var currentScroll: JBScrollPane
|
||||
private var currentSelectedLine: Int? = null
|
||||
|
||||
init {
|
||||
rebuild(null)
|
||||
|
||||
// listen to the source code changes to rebuild the UI
|
||||
myDocument.addDocumentListener(object : DocumentListener {
|
||||
override fun beforeDocumentChange(event: DocumentEvent) {
|
||||
mySwingAlarm.cancelAllRequests()
|
||||
}
|
||||
override fun documentChanged(event: DocumentEvent) {
|
||||
mySwingAlarm.addRequest({
|
||||
rebuild(currentScroll.viewport.viewPosition)
|
||||
}, 50)
|
||||
}
|
||||
})
|
||||
|
||||
// listen to cursor changes to make a slot selectable
|
||||
mainEditor.editor.caretModel.addCaretListener(object : CaretListener {
|
||||
override fun caretPositionChanged(event: CaretEvent) {
|
||||
currentSelectedLine = event.newPosition.line
|
||||
rebuild(currentScroll.viewport.viewPosition)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun rebuild(currentViewPosition: Point?) {
|
||||
val tree = PsiDocumentManager.getInstance(myProject).getPsiFile(myDocument) ?: return
|
||||
|
||||
// clear the old UI
|
||||
myUi.removeAll()
|
||||
|
||||
// create the scroll pane with a centralized component with the inventories
|
||||
var menuCount = 0
|
||||
currentScroll = JBScrollPane(
|
||||
panel {
|
||||
tree.forEachDescendantOfType<KtCallExpression> {
|
||||
val declaration = findMenuDeclaration(
|
||||
it,
|
||||
currentSelectedLine
|
||||
)
|
||||
if (declaration != null) {
|
||||
row {
|
||||
component(
|
||||
InventoryComponent(
|
||||
declaration
|
||||
)
|
||||
)
|
||||
}
|
||||
menuCount++
|
||||
}
|
||||
}
|
||||
}.centerComponent(),
|
||||
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
|
||||
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
|
||||
).apply {
|
||||
if(currentViewPosition != null)
|
||||
viewport.viewPosition = currentViewPosition
|
||||
}
|
||||
|
||||
if(menuCount > 0) {
|
||||
// add the scroll pane to the UI
|
||||
myUi.add(
|
||||
currentScroll,
|
||||
BorderLayout.CENTER
|
||||
)
|
||||
} else {
|
||||
myUi.add(
|
||||
JLabel("Currently this source code has no menu declaration!")
|
||||
.centerComponent(),
|
||||
BorderLayout.CENTER
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun isModified(): Boolean = false
|
||||
|
||||
override fun isValid(): Boolean = true
|
||||
|
||||
override fun addPropertyChangeListener(listener: PropertyChangeListener) {
|
||||
|
||||
}
|
||||
|
||||
override fun removePropertyChangeListener(listener: PropertyChangeListener) {
|
||||
}
|
||||
|
||||
override fun getName(): String = "KotlinBukkitAPI Menu Viewer"
|
||||
|
||||
override fun setState(state: FileEditorState) {
|
||||
|
||||
}
|
||||
|
||||
override fun getComponent(): JComponent {
|
||||
return myUi
|
||||
}
|
||||
|
||||
override fun getPreferredFocusedComponent(): JComponent? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getCurrentLocation(): FileEditorLocation? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
mySwingAlarm.cancelAllRequests()
|
||||
}
|
||||
|
||||
private fun JComponent.centerComponent(): JPanel {
|
||||
return JPanel().apply {
|
||||
isVisible = true
|
||||
layout = GridBagLayout()
|
||||
|
||||
add(this@centerComponent)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package br.com.devsrsouza.kotlinbukkitapi.tooling
|
||||
|
||||
|
||||
import com.intellij.openapi.fileEditor.*
|
||||
import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
class MenuPreviewFileEditorProvider : WeighedFileEditorProvider() {
|
||||
|
||||
companion object {
|
||||
const val ID = "kotlinbukkitapi-menu-preview"
|
||||
}
|
||||
|
||||
override fun getEditorTypeId(): String =
|
||||
ID
|
||||
|
||||
override fun accept(project: Project, file: VirtualFile): Boolean {
|
||||
|
||||
val type = file.fileType
|
||||
|
||||
if(type != KotlinFileType.INSTANCE) return false
|
||||
|
||||
return true
|
||||
// return PsiManager.getInstance(project).findFile(file)?.findDescendantOfType<KtCallExpression> {
|
||||
// findMenuDeclaration(it) != null
|
||||
// } != null
|
||||
}
|
||||
|
||||
override fun createEditor(project: Project, file: VirtualFile): FileEditor {
|
||||
val editor: TextEditor = TextEditorProvider.getInstance().createEditor(project, file) as TextEditor
|
||||
val preview =
|
||||
MenuPreviewFileEditor(project, file, editor)
|
||||
|
||||
return TextEditorWithPreview(editor, preview, "KotlinBukkitAPI")
|
||||
}
|
||||
|
||||
//override fun getPolicy(): FileEditorPolicy = FileEditorPolicy.HIDE_DEFAULT_EDITOR
|
||||
override fun getPolicy(): FileEditorPolicy = FileEditorPolicy.PLACE_AFTER_DEFAULT_EDITOR
|
||||
|
||||
}
|
||||
@@ -0,0 +1,390 @@
|
||||
package br.com.devsrsouza.kotlinbukkitapi.tooling
|
||||
|
||||
enum class MinecraftItem(val id: Int) {
|
||||
AIR(0),
|
||||
STONE(1),
|
||||
GRASS(2),
|
||||
DIRT(3),
|
||||
COBBLESTONE(4),
|
||||
WOOD(5),
|
||||
SAPLING(6),
|
||||
BEDROCK(7),
|
||||
WATER(8),
|
||||
STATIONARY_WATER(9),
|
||||
LAVA(10), STATIONARY_LAVA(11),
|
||||
SAND(12),
|
||||
GRAVEL(13),
|
||||
GOLD_ORE(14),
|
||||
IRON_ORE(15),
|
||||
COAL_ORE(16),
|
||||
LOG(17),
|
||||
LEAVES(18),
|
||||
SPONGE(19),
|
||||
GLASS(20),
|
||||
LAPIS_ORE(21),
|
||||
LAPIS_BLOCK(22),
|
||||
DISPENSER(23),
|
||||
SANDSTONE(24),
|
||||
NOTE_BLOCK(25),
|
||||
BED_BLOCK(26),
|
||||
POWERED_RAIL(27),
|
||||
DETECTOR_RAIL(28),
|
||||
PISTON_STICKY_BASE(29),
|
||||
WEB(30),
|
||||
LONG_GRASS(31),
|
||||
DEAD_BUSH(32),
|
||||
PISTON_BASE(33),
|
||||
PISTON_EXTENSION(34),
|
||||
WOOL(35),
|
||||
PISTON_MOVING_PIECE(36),
|
||||
YELLOW_FLOWER(37),
|
||||
RED_ROSE(38),
|
||||
BROWN_MUSHROOM(39),
|
||||
RED_MUSHROOM(40),
|
||||
GOLD_BLOCK(41),
|
||||
IRON_BLOCK(42),
|
||||
DOUBLE_STEP(43),
|
||||
STEP(44),
|
||||
BRICK(45),
|
||||
TNT(46),
|
||||
BOOKSHELF(47),
|
||||
MOSSY_COBBLESTONE(48),
|
||||
OBSIDIAN(49),
|
||||
TORCH(50),
|
||||
FIRE(51),
|
||||
MOB_SPAWNER(52),
|
||||
WOOD_STAIRS(53),
|
||||
CHEST(54),
|
||||
REDSTONE_WIRE(55),
|
||||
DIAMOND_ORE(56),
|
||||
DIAMOND_BLOCK(57),
|
||||
WORKBENCH(58),
|
||||
CROPS(59),
|
||||
SOIL(60),
|
||||
FURNACE(61),
|
||||
BURNING_FURNACE(62),
|
||||
SIGN_POST(63),
|
||||
WOODEN_DOOR(64),
|
||||
LADDER(65),
|
||||
RAILS(66),
|
||||
COBBLESTONE_STAIRS(67),
|
||||
WALL_SIGN(68),
|
||||
LEVER(69),
|
||||
STONE_PLATE(70),
|
||||
IRON_DOOR_BLOCK(71),
|
||||
WOOD_PLATE(72),
|
||||
REDSTONE_ORE(73),
|
||||
GLOWING_REDSTONE_ORE(74),
|
||||
REDSTONE_TORCH_OFF(75),
|
||||
REDSTONE_TORCH_ON(76),
|
||||
STONE_BUTTON(77),
|
||||
SNOW(78),
|
||||
ICE(79),
|
||||
SNOW_BLOCK(80),
|
||||
CACTUS(81),
|
||||
CLAY(82),
|
||||
SUGAR_CANE_BLOCK(83),
|
||||
JUKEBOX(84),
|
||||
FENCE(85),
|
||||
PUMPKIN(86),
|
||||
NETHERRACK(87),
|
||||
SOUL_SAND(88),
|
||||
GLOWSTONE(89),
|
||||
PORTAL(90),
|
||||
JACK_O_LANTERN(91),
|
||||
CAKE_BLOCK(92),
|
||||
DIODE_BLOCK_OFF(93),
|
||||
DIODE_BLOCK_ON(94),
|
||||
STAINED_GLASS(95),
|
||||
TRAP_DOOR(96),
|
||||
MONSTER_EGGS(97),
|
||||
SMOOTH_BRICK(98),
|
||||
HUGE_MUSHROOM_1(99),
|
||||
HUGE_MUSHROOM_2(100),
|
||||
IRON_FENCE(101),
|
||||
THIN_GLASS(102),
|
||||
MELON_BLOCK(103),
|
||||
PUMPKIN_STEM(104),
|
||||
MELON_STEM(105),
|
||||
VINE(106),
|
||||
FENCE_GATE(107),
|
||||
BRICK_STAIRS(108),
|
||||
SMOOTH_STAIRS(109),
|
||||
MYCEL(110),
|
||||
WATER_LILY(111),
|
||||
NETHER_BRICK(112),
|
||||
NETHER_FENCE(113),
|
||||
NETHER_BRICK_STAIRS(114),
|
||||
NETHER_WARTS(115),
|
||||
ENCHANTMENT_TABLE(116),
|
||||
BREWING_STAND(117),
|
||||
CAULDRON(118),
|
||||
ENDER_PORTAL(119),
|
||||
ENDER_PORTAL_FRAME(120),
|
||||
ENDER_STONE(121),
|
||||
DRAGON_EGG(122),
|
||||
REDSTONE_LAMP_OFF(123),
|
||||
REDSTONE_LAMP_ON(124),
|
||||
WOOD_DOUBLE_STEP(125),
|
||||
WOOD_STEP(126),
|
||||
COCOA(127),
|
||||
SANDSTONE_STAIRS(128),
|
||||
EMERALD_ORE(129),
|
||||
ENDER_CHEST(130),
|
||||
TRIPWIRE_HOOK(131),
|
||||
TRIPWIRE(132),
|
||||
EMERALD_BLOCK(133),
|
||||
SPRUCE_WOOD_STAIRS(134),
|
||||
BIRCH_WOOD_STAIRS(135),
|
||||
JUNGLE_WOOD_STAIRS(136),
|
||||
COMMAND(137),
|
||||
BEACON(138),
|
||||
COBBLE_WALL(139),
|
||||
FLOWER_POT(140),
|
||||
CARROT(141),
|
||||
POTATO(142),
|
||||
WOOD_BUTTON(143),
|
||||
SKULL(144),
|
||||
ANVIL(145),
|
||||
TRAPPED_CHEST(146),
|
||||
GOLD_PLATE(147),
|
||||
IRON_PLATE(148),
|
||||
REDSTONE_COMPARATOR_OFF(149),
|
||||
REDSTONE_COMPARATOR_ON(150),
|
||||
DAYLIGHT_DETECTOR(151),
|
||||
REDSTONE_BLOCK(152),
|
||||
QUARTZ_ORE(153),
|
||||
HOPPER(154),
|
||||
QUARTZ_BLOCK(155),
|
||||
QUARTZ_STAIRS(156),
|
||||
ACTIVATOR_RAIL(157),
|
||||
DROPPER(158),
|
||||
STAINED_CLAY(159),
|
||||
STAINED_GLASS_PANE(160),
|
||||
LEAVES_2(161),
|
||||
LOG_2(162),
|
||||
ACACIA_STAIRS(163),
|
||||
DARK_OAK_STAIRS(164),
|
||||
SLIME_BLOCK(165),
|
||||
BARRIER(166),
|
||||
IRON_TRAPDOOR(167),
|
||||
PRISMARINE(168),
|
||||
SEA_LANTERN(169),
|
||||
HAY_BLOCK(170),
|
||||
CARPET(171),
|
||||
HARD_CLAY(172),
|
||||
COAL_BLOCK(173),
|
||||
PACKED_ICE(174),
|
||||
DOUBLE_PLANT(175),
|
||||
STANDING_BANNER(176),
|
||||
WALL_BANNER(177),
|
||||
DAYLIGHT_DETECTOR_INVERTED(178),
|
||||
RED_SANDSTONE(179),
|
||||
RED_SANDSTONE_STAIRS(180),
|
||||
DOUBLE_STONE_SLAB2(181),
|
||||
STONE_SLAB2(182),
|
||||
SPRUCE_FENCE_GATE(183),
|
||||
BIRCH_FENCE_GATE(184),
|
||||
JUNGLE_FENCE_GATE(185),
|
||||
DARK_OAK_FENCE_GATE(186),
|
||||
ACACIA_FENCE_GATE(187),
|
||||
SPRUCE_FENCE(188),
|
||||
BIRCH_FENCE(189),
|
||||
JUNGLE_FENCE(190),
|
||||
DARK_OAK_FENCE(191),
|
||||
ACACIA_FENCE(192),
|
||||
SPRUCE_DOOR(193),
|
||||
BIRCH_DOOR(194),
|
||||
JUNGLE_DOOR(195),
|
||||
ACACIA_DOOR(196),
|
||||
DARK_OAK_DOOR(197),
|
||||
|
||||
// ----- Item Separator -----
|
||||
IRON_SPADE(256),
|
||||
IRON_PICKAXE(257),
|
||||
IRON_AXE(258),
|
||||
FLINT_AND_STEEL(259),
|
||||
APPLE(260),
|
||||
BOW(261),
|
||||
ARROW(262), COAL(263),
|
||||
DIAMOND(264),
|
||||
IRON_INGOT(265),
|
||||
GOLD_INGOT(266),
|
||||
IRON_SWORD(267),
|
||||
WOOD_SWORD(268),
|
||||
WOOD_SPADE(269),
|
||||
WOOD_PICKAXE(270),
|
||||
WOOD_AXE(271),
|
||||
STONE_SWORD(272),
|
||||
STONE_SPADE(273),
|
||||
STONE_PICKAXE(274),
|
||||
STONE_AXE(275),
|
||||
DIAMOND_SWORD(276),
|
||||
DIAMOND_SPADE(277),
|
||||
DIAMOND_PICKAXE(278),
|
||||
DIAMOND_AXE(279),
|
||||
STICK(280),
|
||||
BOWL(281),
|
||||
MUSHROOM_SOUP(282),
|
||||
GOLD_SWORD(283),
|
||||
GOLD_SPADE(284),
|
||||
GOLD_PICKAXE(285),
|
||||
GOLD_AXE(286),
|
||||
STRING(287),
|
||||
FEATHER(288),
|
||||
SULPHUR(289),
|
||||
WOOD_HOE(290),
|
||||
STONE_HOE(291),
|
||||
IRON_HOE(292),
|
||||
DIAMOND_HOE(293),
|
||||
GOLD_HOE(294),
|
||||
SEEDS(295),
|
||||
WHEAT(296),
|
||||
BREAD(297),
|
||||
LEATHER_HELMET(298),
|
||||
LEATHER_CHESTPLATE(299),
|
||||
LEATHER_LEGGINGS(300),
|
||||
LEATHER_BOOTS(301),
|
||||
CHAINMAIL_HELMET(302),
|
||||
CHAINMAIL_CHESTPLATE(303),
|
||||
CHAINMAIL_LEGGINGS(304),
|
||||
CHAINMAIL_BOOTS(305),
|
||||
IRON_HELMET(306),
|
||||
IRON_CHESTPLATE(307),
|
||||
IRON_LEGGINGS(308),
|
||||
IRON_BOOTS(309),
|
||||
DIAMOND_HELMET(310),
|
||||
DIAMOND_CHESTPLATE(311),
|
||||
DIAMOND_LEGGINGS(312),
|
||||
DIAMOND_BOOTS(313),
|
||||
GOLD_HELMET(314),
|
||||
GOLD_CHESTPLATE(315),
|
||||
GOLD_LEGGINGS(316),
|
||||
GOLD_BOOTS(317),
|
||||
FLINT(318),
|
||||
PORK(319),
|
||||
GRILLED_PORK(320),
|
||||
PAINTING(321),
|
||||
GOLDEN_APPLE(322),
|
||||
SIGN(323),
|
||||
WOOD_DOOR(324),
|
||||
BUCKET(325),
|
||||
WATER_BUCKET(326),
|
||||
LAVA_BUCKET(327),
|
||||
MINECART(328),
|
||||
SADDLE(329),
|
||||
IRON_DOOR(330),
|
||||
REDSTONE(331),
|
||||
SNOW_BALL(332),
|
||||
BOAT(333),
|
||||
LEATHER(334),
|
||||
MILK_BUCKET(335),
|
||||
CLAY_BRICK(336),
|
||||
CLAY_BALL(337),
|
||||
SUGAR_CANE(338),
|
||||
PAPER(339),
|
||||
BOOK(340),
|
||||
SLIME_BALL(341),
|
||||
STORAGE_MINECART(342),
|
||||
POWERED_MINECART(343),
|
||||
EGG(344),
|
||||
COMPASS(345),
|
||||
FISHING_ROD(346),
|
||||
WATCH(347),
|
||||
GLOWSTONE_DUST(348),
|
||||
RAW_FISH(349),
|
||||
COOKED_FISH(350),
|
||||
INK_SACK(351),
|
||||
BONE(352),
|
||||
SUGAR(353),
|
||||
CAKE(354),
|
||||
BED(355),
|
||||
DIODE(356),
|
||||
COOKIE(357),
|
||||
MAP(358),
|
||||
SHEARS(359),
|
||||
MELON(360),
|
||||
PUMPKIN_SEEDS(361),
|
||||
MELON_SEEDS(362),
|
||||
RAW_BEEF(363),
|
||||
COOKED_BEEF(364),
|
||||
RAW_CHICKEN(365),
|
||||
COOKED_CHICKEN(366),
|
||||
ROTTEN_FLESH(367),
|
||||
ENDER_PEARL(368),
|
||||
BLAZE_ROD(369),
|
||||
GHAST_TEAR(370),
|
||||
GOLD_NUGGET(371),
|
||||
NETHER_STALK(372),
|
||||
|
||||
POTION(373),
|
||||
GLASS_BOTTLE(374),
|
||||
SPIDER_EYE(375),
|
||||
FERMENTED_SPIDER_EYE(376),
|
||||
BLAZE_POWDER(377),
|
||||
MAGMA_CREAM(378),
|
||||
BREWING_STAND_ITEM(379),
|
||||
CAULDRON_ITEM(380),
|
||||
EYE_OF_ENDER(381),
|
||||
SPECKLED_MELON(382),
|
||||
MONSTER_EGG(383),
|
||||
EXP_BOTTLE(384),
|
||||
FIREBALL(385),
|
||||
BOOK_AND_QUILL(386),
|
||||
WRITTEN_BOOK(387),
|
||||
EMERALD(388),
|
||||
ITEM_FRAME(389),
|
||||
FLOWER_POT_ITEM(390),
|
||||
CARROT_ITEM(391),
|
||||
POTATO_ITEM(392),
|
||||
BAKED_POTATO(393),
|
||||
POISONOUS_POTATO(394),
|
||||
EMPTY_MAP(395),
|
||||
GOLDEN_CARROT(396),
|
||||
SKULL_ITEM(397),
|
||||
CARROT_STICK(398),
|
||||
NETHER_STAR(399),
|
||||
PUMPKIN_PIE(400),
|
||||
FIREWORK(401),
|
||||
FIREWORK_CHARGE(402),
|
||||
ENCHANTED_BOOK(403),
|
||||
REDSTONE_COMPARATOR(404),
|
||||
NETHER_BRICK_ITEM(405),
|
||||
QUARTZ(406),
|
||||
EXPLOSIVE_MINECART(407),
|
||||
HOPPER_MINECART(408),
|
||||
PRISMARINE_SHARD(409),
|
||||
PRISMARINE_CRYSTALS(410),
|
||||
RABBIT(411),
|
||||
COOKED_RABBIT(412),
|
||||
RABBIT_STEW(413),
|
||||
RABBIT_FOOT(414),
|
||||
RABBIT_HIDE(415),
|
||||
ARMOR_STAND(416),
|
||||
IRON_BARDING(417),
|
||||
GOLD_BARDING(418),
|
||||
DIAMOND_BARDING(419),
|
||||
LEASH(420),
|
||||
NAME_TAG(421),
|
||||
COMMAND_MINECART(422),
|
||||
MUTTON(423),
|
||||
COOKED_MUTTON(424),
|
||||
BANNER(425),
|
||||
SPRUCE_DOOR_ITEM(427),
|
||||
BIRCH_DOOR_ITEM(428),
|
||||
JUNGLE_DOOR_ITEM(429),
|
||||
ACACIA_DOOR_ITEM(430),
|
||||
DARK_OAK_DOOR_ITEM(431),
|
||||
GOLD_RECORD(2256),
|
||||
GREEN_RECORD(2257),
|
||||
RECORD_3(2258),
|
||||
RECORD_4(2259),
|
||||
RECORD_5(2260),
|
||||
RECORD_6(2261),
|
||||
RECORD_7(2262),
|
||||
RECORD_8(2263),
|
||||
RECORD_9(2264),
|
||||
RECORD_10(2265),
|
||||
RECORD_11(2266),
|
||||
RECORD_12(2267);
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package br.com.devsrsouza.kotlinbukkitapi.tooling
|
||||
|
||||
import com.intellij.psi.util.collectDescendantsOfType
|
||||
import com.intellij.psi.util.findDescendantOfType
|
||||
import org.jetbrains.kotlin.builtins.getReceiverTypeFromFunctionType
|
||||
import org.jetbrains.kotlin.builtins.getReturnTypeFromFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
|
||||
import org.jetbrains.kotlin.idea.core.util.getLineNumber
|
||||
import org.jetbrains.kotlin.idea.debugger.sequence.psi.resolveType
|
||||
import org.jetbrains.kotlin.idea.intentions.isMethodCall
|
||||
import org.jetbrains.kotlin.idea.refactoring.fqName.fqName
|
||||
import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
||||
|
||||
fun findMenuDeclaration(
|
||||
element: KtCallExpression,
|
||||
currentSelectedLine: Int? = null
|
||||
): MenuDeclaration? {
|
||||
val menuFqName = "br.com.devsrsouza.kotlinbukkitapi.dsl.menu.menu"
|
||||
val simpleName = "menu"
|
||||
|
||||
if (!element.isCallFrom(simpleName, menuFqName)) return null
|
||||
|
||||
val menuFunction = element.findDescendantOfType<KtCallExpression> {
|
||||
isMenuCall(it)
|
||||
} ?: return null
|
||||
|
||||
// TODO: Support named parameters
|
||||
|
||||
val displayName = menuFunction.valueArguments.getOrNull(0)?.text?.replace("\"", "") ?: return null
|
||||
val lines = menuFunction.valueArguments.getOrNull(1)?.text?.toIntOrNull() ?: return null
|
||||
|
||||
val menuLambdaBlock = element.findDescendantOfType<KtLambdaExpression> {
|
||||
it.isBuilderBlockFor("br.com.devsrsouza.kotlinbukkitapi.dsl.menu.MenuDSL")
|
||||
} ?: return null
|
||||
|
||||
val slotFqName = "br.com.devsrsouza.kotlinbukkitapi.dsl.menu.slot"
|
||||
val slotSimpleName = "slot"
|
||||
|
||||
val slotCalls = menuLambdaBlock.collectDescendantsOfType<KtCallExpression> {
|
||||
it.isCallFrom(slotSimpleName, slotFqName)
|
||||
}.mapNotNull {
|
||||
|
||||
val args = it.valueArguments
|
||||
|
||||
// TODO: support named parameters
|
||||
|
||||
val line = args.getOrNull(0)?.text?.toIntOrNull() ?: return@mapNotNull null
|
||||
val slot = args.getOrNull(1)?.text?.toIntOrNull() ?: return@mapNotNull null
|
||||
|
||||
// TODO: support just slot: slot(15, item(...)) {}
|
||||
|
||||
val itemValue = args.getOrNull(2) ?: return@mapNotNull null
|
||||
val expression = itemValue.getArgumentExpression() ?: return@mapNotNull null
|
||||
|
||||
val materialExpression = expression.findDescendantOfType<KtDotQualifiedExpression> {
|
||||
it.text.startsWith("Material")
|
||||
&& it.receiverExpression.mainReference?.resolve()?.getKotlinFqName()?.asString()
|
||||
?.equals("org.bukkit.Material") == true
|
||||
} ?: return@mapNotNull null
|
||||
|
||||
val typeExpression = materialExpression.selectorExpression as? KtNameReferenceExpression ?: return@mapNotNull null
|
||||
val materialName = typeExpression.text ?: return@mapNotNull null
|
||||
|
||||
val item = runCatching { MinecraftItem.valueOf(materialName) }.getOrNull()
|
||||
|
||||
println("Slot $line, $slot using item: $materialName")
|
||||
|
||||
val isSelected = it.getLineNumber() == currentSelectedLine
|
||||
|
||||
MenuSlotDeclaration(
|
||||
line,
|
||||
slot,
|
||||
item?.id,
|
||||
isSelected
|
||||
)
|
||||
}
|
||||
|
||||
return MenuDeclaration(displayName, lines, slotCalls)
|
||||
}
|
||||
|
||||
fun isMenuCall(it: KtCallExpression) =
|
||||
it.isCallFrom("menu", "br.com.devsrsouza.kotlinbukkitapi.dsl.menu.menu")
|
||||
|
||||
fun KtLambdaExpression.isBuilderBlockFor(fqName: String): Boolean {
|
||||
val type = resolveType()
|
||||
|
||||
val extensionFunctionType = type.isExtensionFunctionType
|
||||
|
||||
if(!extensionFunctionType) return false
|
||||
|
||||
val returnTypeFromFunctionType = type.getReturnTypeFromFunctionType()
|
||||
val receiverTypeFromFunctionType = type.getReceiverTypeFromFunctionType() ?: return false
|
||||
val receiverFqName = receiverTypeFromFunctionType.fqName ?: return false
|
||||
|
||||
return returnTypeFromFunctionType.isUnit() && receiverFqName.asString().equals(fqName)
|
||||
}
|
||||
|
||||
fun KtCallExpression.isCallFrom(
|
||||
simpleName: String,
|
||||
fqName: String
|
||||
): Boolean {
|
||||
return text.startsWith(simpleName) && isMethodCall(fqName)
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<idea-plugin>
|
||||
<id>br.com.devsrsouza.kotlinbukkitapi.tooling</id>
|
||||
<name>KotlinBukkitAPI Tooling</name>
|
||||
<vendor>DevSrSouza</vendor>
|
||||
|
||||
<!-- please see https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
|
||||
on how to target different products -->
|
||||
<depends>com.intellij.modules.platform</depends>
|
||||
<depends>org.jetbrains.kotlin</depends>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<!-- Add your extensions here -->
|
||||
<fileEditorProvider implementation="br.com.devsrsouza.kotlinbukkitapi.tooling.MenuPreviewFileEditorProvider"/>
|
||||
</extensions>
|
||||
|
||||
<actions>
|
||||
<!-- Add your actions here -->
|
||||
</actions>
|
||||
</idea-plugin>
|
||||
|
After Width: | Height: | Size: 80 B |
|
After Width: | Height: | Size: 454 B |
|
After Width: | Height: | Size: 1009 B |
|
After Width: | Height: | Size: 943 B |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 593 B |
|
After Width: | Height: | Size: 180 B |
|
After Width: | Height: | Size: 908 B |
|
After Width: | Height: | Size: 172 B |
|
After Width: | Height: | Size: 172 B |
|
After Width: | Height: | Size: 222 B |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 586 B |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 209 B |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 482 B |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 558 B |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 937 B |
|
After Width: | Height: | Size: 918 B |
|
After Width: | Height: | Size: 802 B |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 328 B |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 530 B |
|
After Width: | Height: | Size: 548 B |
|
After Width: | Height: | Size: 563 B |
|
After Width: | Height: | Size: 541 B |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 981 B |
|
After Width: | Height: | Size: 412 B |
|
After Width: | Height: | Size: 432 B |
|
After Width: | Height: | Size: 449 B |
|
After Width: | Height: | Size: 433 B |
|
After Width: | Height: | Size: 997 B |
|
After Width: | Height: | Size: 802 B |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 871 B |
|
After Width: | Height: | Size: 145 B |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 707 B |
|
After Width: | Height: | Size: 491 B |
|
After Width: | Height: | Size: 974 B |
|
After Width: | Height: | Size: 561 B |
|
After Width: | Height: | Size: 634 B |
|
After Width: | Height: | Size: 518 B |
|
After Width: | Height: | Size: 320 B |
|
After Width: | Height: | Size: 187 B |
|
After Width: | Height: | Size: 422 B |
|
After Width: | Height: | Size: 726 B |
|
After Width: | Height: | Size: 934 B |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 364 B |
|
After Width: | Height: | Size: 311 B |
|
After Width: | Height: | Size: 561 B |
|
After Width: | Height: | Size: 414 B |
|
After Width: | Height: | Size: 385 B |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 233 B |
|
After Width: | Height: | Size: 796 B |